test: remove low-value input, media, and browser examples

This commit is contained in:
OrcaWin
2026-11-12 01:44:41 -08:00
parent eb16a6e351
commit bb446f57f2
7 changed files with 21 additions and 397 deletions
File diff suppressed because one or more lines are too long
@@ -236,20 +236,6 @@ for (const engine of ['chromium', 'webkit']) {
expect(sealed.reported.join(' ')).not.toContain('script-src')
}, 180_000)
it('loads the artifact https images the directive admits, and still refuses its font', async (ctx) => {
// Await both images explicitly; bounded settle once observed background before element on loaded Chrome.
const read = await open(browser(), {
assets: assetServer.origin,
frameReady: 'images',
signal: ctx.signal
})
expect(read.pixel).toBe(ARTIFACT_RGB)
// img-src governs CSS background and img element; require both requests.
expect([...read.secureHits].sort()).toEqual(['/css-bg.png', '/img.png'])
// Same HTTPS origin still cannot load font; img-src admission must not widen font-src.
expect(read.secureHits).not.toContain('/probe.woff2')
}, 120_000)
it('sends no referrer with an admitted https image, which is the shell header doing it', async (ctx) => {
const sealed = await open(browser(), {
assets: assetServer.origin,
@@ -384,109 +370,6 @@ for (const engine of ['chromium', 'webkit']) {
expect(read.popups).toBe(0)
}, 120_000)
it("cannot reach the shell through a meta refresh at the embedder's own URL", async (ctx) => {
// Same-origin meta-refresh targets shell document; foreign-origin arm cannot prove shell-origin counter works.
const own = await open(browser(), {
signal: ctx.signal,
extra: { head: '<meta http-equiv="refresh" content="0;url=/">' }
})
// Require painted artifact before interpreting navigation refusal.
expect(own.pixelBefore).toBe(ARTIFACT_RGB)
// Link-to-/ control reads one on same counter, proving refresh zero is observable.
expect(own.ownOriginTopNavigations).toBe(0)
expect(own.topNavigations).toBe(0)
// Also reject self-frame shell-document fetch, which would embed session page inside preview.
expect(own.ownOriginFrameNavigations).toBe(0)
// No-policy/allow-same-origin control must navigate frame to shell / to prove observer is not blind.
const loose = await open(browser(), {
signal: ctx.signal,
csp: null,
sandbox: 'allow-scripts allow-same-origin allow-top-navigation',
extra: { head: '<meta http-equiv="refresh" content="0;url=/">' },
// Navigating arm no longer contains marker; await navigation instead of artifact readiness.
frameReady: 'load',
expectNavigation: 'frame'
})
expect(loose.ownOriginFrameNavigations).toBe(1)
// Test sandbox token alone with no CSP; navigation must never begin or report.
const tokenOnly = await open(browser(), {
signal: ctx.signal,
csp: null,
extra: { head: '<meta http-equiv="refresh" content="0;url=/">' }
})
expect(tokenOnly.pixelBefore).toBe(ARTIFACT_RGB)
expect(tokenOnly.ownOriginFrameNavigations).toBe(0)
expect(tokenOnly.ownOriginTopNavigations).toBe(0)
expect(tokenOnly.violations).toEqual([])
// Test CSP alone with allow-same-origin: frame-src none blocks request at embedder; engines leave different content, so assert no server request.
const policyOnly = await open(browser(), {
signal: ctx.signal,
sandbox: 'allow-scripts allow-same-origin allow-top-navigation',
extra: { head: '<meta http-equiv="refresh" content="0;url=/">' },
frameReady: 'load'
})
expect(policyOnly.ownOriginFrameNavigations).toBe(0)
expect(policyOnly.ownOriginTopNavigations).toBe(0)
expect(policyOnly.violations.join(' ')).toContain('frame-src')
}, 180_000)
it('hands up nothing without a tap, and nothing for a form or a new window', async (ctx) => {
const meta = await open(browser(), {
signal: ctx.signal,
extra: { head: `<meta http-equiv="refresh" content="0;url=${foreignOrigin}/meta.html">` }
})
expect(meta.topNavigations).toBe(0)
expect(meta.ownOriginTopNavigations).toBe(0)
const form = await open(browser(), {
signal: ctx.signal,
act: async ({ frame }) => {
await frame.click('#submit', { timeout: 2000 })
}
})
expect(form.actError).toBeNull()
expect(form.pixelBefore).toBe(ARTIFACT_RGB)
expect(form.topNavigations).toBe(0)
const blank = await open(browser(), {
signal: ctx.signal,
act: async ({ frame }) => {
await frame.click('#blanklink', { timeout: 2000 })
}
})
expect(blank.actError).toBeNull()
expect(blank.pixelBefore).toBe(ARTIFACT_RGB)
expect(blank.topNavigations).toBe(0)
expect(blank.popups).toBe(0)
const allowedForm = await open(browser(), {
signal: ctx.signal,
csp: null,
sandbox: 'allow-forms allow-top-navigation-by-user-activation',
expectNavigation: 'main-frame',
act: async ({ frame }) => {
await frame.click('#submit', { timeout: 2000 })
}
})
expect(allowedForm.pixelBefore).toBe(ARTIFACT_RGB)
expect(allowedForm.actError).toBeNull()
expect(allowedForm.topNavigations).toBe(1)
const allowedBlank = await open(browser(), {
signal: ctx.signal,
csp: null,
sandbox: 'allow-popups allow-popups-to-escape-sandbox',
act: async ({ page, frame }) => {
await Promise.all([
page.waitForEvent('popup', { timeout: 10_000 }),
frame.click('#blanklink', { timeout: 2000 })
])
}
})
expect(allowedBlank.pixelBefore).toBe(ARTIFACT_RGB)
expect(allowedBlank.actError).toBeNull()
expect(allowedBlank.popups).toBe(1)
}, 180_000)
// Force slow-arm diagnostic sampling branch; formerly unexecuted branch had out-of-scope name and no test/lint coverage.
// Force bounded navigation timeout after missed click; require useful diagnostic instead of exhausting whole case budget.
@@ -16,31 +16,12 @@ import { mobileWebAppDependenciesPresent } from '../mobile-web-app-bundle-depend
import {
createBundleServer,
installCspViolationRecorder,
installListenerRecorder,
readShellCsp
} from '../preview/mobile-web-app-render-harness.mjs'
const mobileDir = fileURLToPath(new URL('../../../../mobile', import.meta.url))
const componentDir = join(mobileDir, 'src/components')
const COMMANDS = [
{ label: 'H1', command: 'heading1', select: 'all', expect: 'h1' },
{ label: 'H2', command: 'heading2', select: 'all', expect: 'h2' },
{ label: 'H3', command: 'heading3', select: 'all', expect: 'h3' },
{ label: 'Bold', command: 'bold', select: 'word', expect: 'b,strong' },
{ label: 'Italic', command: 'italic', select: 'word', expect: 'i,em' },
{ label: 'Strike', command: 'strike', select: 'word', expect: 'strike,s,del' },
{ label: 'Bullet list', command: 'bulletList', select: 'all', expect: 'ul' },
{ label: 'Numbered list', command: 'orderedList', select: 'all', expect: 'ol' },
{ label: 'Checklist', command: 'taskList', select: 'all', expect: 'ul[data-type="taskList"]' },
{ label: 'Quote', command: 'quote', select: 'all', expect: 'blockquote' },
{ label: 'Inline code', command: 'inlineCode', select: 'word', expect: 'code' },
{ label: 'Code block', command: 'codeBlock', select: 'all', expect: 'pre' }
]
// Paragraph undoes another command; starting from p would prove nothing.
const PARAGRAPH = { label: 'Body', command: 'paragraph' }
// Serve inserted image locally: nonexistent URL logs WebKit load failure; successful paint proves shipped CSP admits it.
const IMAGE_PATH = '/inserted.png'
const URL_COMMANDS = [
@@ -151,21 +132,6 @@ function Harness() {
createRoot(document.getElementById('root')).render(createElement(Harness))
`
// Install ReactNativeWebView recorder before bundle: absence alone cannot prove editor JSON avoids shell bridge if bridge object never existed.
function installBridgeObjectRecorder() {
globalThis.__orcaBridgeReads = []
const bridge = {
postMessage: (message) => globalThis.__orcaBridgeReads.push(`post ${String(message)}`)
}
Object.defineProperty(globalThis, 'ReactNativeWebView', {
configurable: true,
get: () => {
globalThis.__orcaBridgeReads.push('read')
return bridge
}
})
}
const bundles = mobileWebAppDependenciesPresent()
const describeEditor = bundles ? describe : describe.skip
@@ -256,9 +222,7 @@ async function openPage(browser) {
}
})
page.on('pageerror', (error) => consoleErrors.push(`pageerror: ${error.message}`))
await page.addInitScript(installBridgeObjectRecorder)
await page.addInitScript(installCspViolationRecorder)
await page.addInitScript(installListenerRecorder, { selector: '#editor' })
await page.goto(`${origin}/`, { waitUntil: 'domcontentloaded' })
await page.waitForFunction(() => document.body.dataset.ready === 'yes')
await page.waitForSelector('#first-surface #editor')
@@ -326,89 +290,7 @@ describeEditor(
afterAll(() => browser?.close())
it('mounts the document, reports ready through the seam and never touches the bridge', async () => {
const { page, consoleErrors } = await openPage(browser)
try {
await setContent(page, '# Title', '<h1>Title</h1>')
expect(await readSurface(page)).toBe('<h1>Title</h1>')
// Initial markup proves document ready reached controller and pushed content through seam.
expect(await page.evaluate(() => globalThis.__orcaBridgeReads)).toEqual([])
expect(await page.evaluate(() => globalThis.__orcaCspViolations)).toEqual([])
expect(consoleErrors).toEqual([])
// No editor occlusion report: screen’s web module already measures viewport, so reporting twice would lift bar twice.
expect(await page.evaluate(() => globalThis.__orcaEditor.insets)).toEqual([])
} finally {
await page.close()
}
}, 600_000)
it('runs every one of the fifteen commands against the document', async () => {
const { page, consoleErrors } = await openPage(browser)
try {
for (const [index, entry] of COMMANDS.entries()) {
const body = bodyFor(index)
await setContent(page, body, `<p>${body}</p>`)
// Require command effect absent beforehand or undelivered command could pass on previous document.
expect(
await page.evaluate(
(selector) =>
document.querySelector('#first-surface #editor')?.querySelector(selector),
entry.expect
),
`${entry.label} was already applied before it ran`
).toBeNull()
await select(page, entry.select)
await press(page, entry.label)
await page.waitForFunction(
(selector) =>
document.querySelector('#first-surface #editor')?.querySelector(selector) !==
null,
entry.expect,
{ timeout: 15_000 }
)
}
// Paragraph must undo another block type; it is a no-op on p.
await setContent(page, '# Title', '<h1>Title</h1>')
await select(page, 'all')
await press(page, PARAGRAPH.label)
await page.waitForFunction(
() =>
document.querySelector('#first-surface #editor')?.querySelector('h1') === null &&
document.querySelector('#first-surface #editor')?.querySelector('p') !== null,
null,
{ timeout: 15_000 }
)
expect(await page.evaluate(() => globalThis.__orcaCspViolations)).toEqual([])
expect(consoleErrors).toEqual([])
} finally {
await page.close()
}
}, 600_000)
// Both engines nest unordered list inside existing p; inline paragraph serialization once dropped bullet when saved.
it('edits and selects under the shipped document style, which makes other text unselectable', async () => {
const { page, consoleErrors } = await openPage(browser)
try {
await setContent(page, 'alpha', '<p>alpha</p>')
const word = page.locator('#first-surface #editor p')
await word.click()
await page.keyboard.press('End')
await page.keyboard.type(' bravo')
await page.waitForFunction(
() =>
document.querySelector('#first-surface #editor p')?.textContent === 'alpha bravo'
)
// Use browser gesture: a scripted Range bypasses body user-select:none.
await page.evaluate(() => window.getSelection()?.removeAllRanges())
await word.dblclick()
expect(await page.evaluate(() => window.getSelection()?.toString().trim())).not.toBe('')
expect(consoleErrors).toEqual([])
} finally {
await page.close()
}
}, 600_000)
it('reports a typed bullet list as a list, and renders that markdown back as one', async () => {
const { page, consoleErrors } = await openPage(browser)
-28
View File
@@ -433,34 +433,6 @@ describe('reading chunks', () => {
).rejects.toThrow(/stopped reading/)
expect(handles.at(-1)?.closed).toBe(true)
})
it('refuses a read for a handle the page released', async () => {
const { probe, handle } = await staged(64)
await expect(probe.serve('native.media.release', { handle })).resolves.toEqual({
released: true
})
await expect(
probe.serve('native.media.read', { handle, offset: 0, length: 16 })
).rejects.toSatisfy((error) => refusalOf(error) === 'native_media_handle_unknown')
})
})
describe('releasing', () => {
it('deletes the staged file and answers false the second time', async () => {
const probe = harness()
probe.files.set(`${CACHE}/lib.png`, bytesOf(8))
const result = mediaPickResultSchema.parse(
await probe.serve('native.media.pick', { source: 'library', multiple: false })
)
const handle = result.items[0]?.handle ?? ''
await expect(probe.serve('native.media.release', { handle })).resolves.toEqual({
released: true
})
expect(probe.discarded).toEqual([`${CACHE}/lib.png`])
await expect(probe.serve('native.media.release', { handle })).resolves.toEqual({
released: false
})
})
})
describe('a provider uri the Android picker can answer', () => {
@@ -6,10 +6,8 @@ import type { TerminalLiveInputSender } from './terminal-live-input-sender'
import { TERMINAL_LIVE_HELD_PREEDIT_COMMIT_DELAY_MS } from './terminal-live-preedit-mirror'
import { useTerminalLiveInputCommit } from './use-terminal-live-input-commit'
const composingRange = vi.hoisted(() => ({ hostReportsNone: false }))
vi.mock('../platform/live-input-composing-range', () => ({
reportedLiveInputComposing: (isComposing: boolean | undefined) =>
composingRange.hostReportsNone ? undefined : isComposing
reportedLiveInputComposing: (isComposing: boolean | undefined) => isComposing
}))
type TerminalLiveInputCommitHandlers = ReturnType<typeof useTerminalLiveInputCommit<string>>
@@ -246,7 +244,6 @@ describe('terminal live input commit hook', () => {
afterEach(() => {
vi.useRealTimers()
composingRange.hostReportsNone = false
})
it('Given Cheonjiin jamo reported as not composing When typing pauses Then the jamo stay held', async () => {
@@ -316,35 +313,6 @@ describe('terminal live input commit hook', () => {
expect(sent).toEqual([])
})
it('Given an Android WebView composing each word When letters follow a slash Then each reaches the terminal as typed', async () => {
composingRange.hostReportsNone = true
const { handlers, sent } = createTerminalLiveInputCommitHarness()
changeLiveInput(handlers, '/', false)
await vi.waitFor(() => expect(sent).toHaveLength(1))
for (const fieldText of ['/t', '/tu', '/tui']) {
changeLiveInput(handlers, fieldText, true)
// Await each keystroke so batching cannot hide a held character.
await vi.waitFor(() => expect(sent).toHaveLength(fieldText.length))
}
await vi.waitFor(() => expect(sent).toEqual(['/', 't', 'u', 'i']))
})
it('Given an Android WebView composing Hangul When steps arrive Then the non-ASCII run still settles on the timer', async () => {
vi.useFakeTimers()
composingRange.hostReportsNone = true
const { handlers, sent } = createTerminalLiveInputCommitHarness()
for (const fieldText of ['ㅎ', '하', '한']) {
changeLiveInput(handlers, fieldText, true)
await vi.advanceTimersByTimeAsync(50)
}
await vi.advanceTimersByTimeAsync(TERMINAL_LIVE_HELD_PREEDIT_COMMIT_DELAY_MS)
await vi.waitFor(() => expect(sent).toEqual(['한']))
})
it('Given an iOS pinyin preedit When accessory Backspace edits it Then only the candidate reaches the terminal', async () => {
vi.useFakeTimers()
const { handlers, sent } = createTerminalLiveInputCommitHarness()
@@ -476,15 +444,6 @@ describe('terminal live input commit hook', () => {
expect(sent).toEqual([])
})
it('Given Backspace with field text When the key arrives Then edits locally without terminal bytes', async () => {
const { handlers, sent } = createTerminalLiveInputCommitHarness()
changeLiveInput(handlers, '한')
handlers.handleLiveInputKeyPress({ nativeEvent: { key: 'Backspace' } })
await vi.waitFor(() => expect(sent).toEqual([]))
})
it('Given Tab with a held syllable When the key arrives Then commits the syllable before the tab bytes', async () => {
const { handlers, sent } = createTerminalLiveInputCommitHarness()
changeLiveInput(handlers, '한')
@@ -5,7 +5,6 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import type { MobileNotificationEvent } from './notifications/runtime-mobile-notification-controller'
import { DeviceRegistry } from '../rpc/server/pairing/device-registry'
import { DesktopPushService } from './desktop-push-service'
import { PushRegisterThrottle } from './push-register-throttle'
import { PushUnregisterOutbox } from './push-unregister-outbox'
import { createPushHostKeypair } from './push-host-challenge-fixtures'
@@ -21,7 +20,6 @@ function createService(
deleteFails?: boolean
/** Runs before each delete resolves, so a suite can queue work mid-flush. */
onDelete?: (registrationId: string) => void
now?: () => number
} = {}
): {
service: DesktopPushService
@@ -77,8 +75,7 @@ function createService(
client: client as never,
scheduleRetry: (run, delayMs) => {
retries.push({ run, delayMs })
},
...(options.now ? { registerThrottle: new PushRegisterThrottle({ now: options.now }) } : {})
}
})!
service.start()
@@ -158,20 +155,6 @@ describe('DesktopPushService', () => {
expect(harness.outbox.pending()).toEqual([])
})
it('retries a failed drain on a capped backoff instead of waiting for a relaunch', async () => {
const harness = createService({ deleteFails: true })
harness.outbox.enqueue({ registrationId: 'reg-stuck', deviceId: 'device-1' })
await harness.service.flushUnregisterOutbox()
expect(harness.retries.map((entry) => entry.delayMs)).toEqual([30_000])
harness.retries[0]?.run()
await new Promise((resolve) => setImmediate(resolve))
expect(harness.deletes).toEqual(['reg-stuck', 'reg-stuck'])
expect(harness.retries.map((entry) => entry.delayMs)).toEqual([30_000, 60_000])
expect(harness.outbox.pending()).toHaveLength(1)
})
it('stops re-arming the retry once the service is stopped', async () => {
const harness = createService({ deleteFails: true })
harness.outbox.enqueue({ registrationId: 'reg-stuck', deviceId: 'device-1' })
@@ -183,56 +166,6 @@ describe('DesktopPushService', () => {
expect(harness.retries).toHaveLength(1)
})
it('throttles a device that registers in a loop and lets it back in a minute later', async () => {
let clock = 1_700_000_000_000
const harness = createService({ now: () => clock })
const input = { deviceId: harness.deviceId, ...REGISTER_INPUT }
for (let index = 0; index < 10; index++) {
expect(await harness.service.register(input)).toEqual({
registered: true,
registrationId: 'reg-1'
})
}
expect(await harness.service.register(input)).toEqual({
registered: false,
reason: 'throttled'
})
expect(harness.registry.getDevice(harness.deviceId)?.pushRegistration?.registrationId).toBe(
'reg-1'
)
clock += 60_000
expect(await harness.service.register(input)).toEqual({
registered: true,
registrationId: 'reg-1'
})
})
})
it('renews a seven-day mobile lease only on explicit registration', async () => {
const now = 1_800_000_000_000
const clock = vi.spyOn(Date, 'now').mockReturnValue(now)
const h = createService()
try {
await h.service.register({
deviceId: h.deviceId,
...REGISTER_INPUT
})
expect(h.registry.getDevice(h.deviceId)?.pushRegistration?.expiresAt).toBe(now + 7 * 86400_000)
clock.mockReturnValue(now + 86400_000)
h.dispatch({ type: 'notification', source: 'terminal-bell', title: 'QA', body: 'QA' })
expect(h.registry.getDevice(h.deviceId)?.pushRegistration?.expiresAt).toBe(now + 7 * 86400_000)
await h.service.register({
deviceId: h.deviceId,
...REGISTER_INPUT
})
expect(h.registry.getDevice(h.deviceId)?.pushRegistration?.expiresAt).toBe(now + 8 * 86400_000)
} finally {
h.service.stop()
clock.mockRestore()
}
})
it('does not claim success for missing registrations or failed gateway sends', async () => {
@@ -268,7 +201,7 @@ describe('host mobile push privacy', () => {
h.registry.setPushRegistration(h.deviceId, {
registrationId: 'existing-reg',
filter: {},
expiresAt: Date.now() + 60_000
expiresAt: Number.MAX_SAFE_INTEGER
})
h.dispatch({
type: 'notification',
@@ -207,15 +207,4 @@ describe('workspace linked work editor', () => {
expect(screen.getByRole('button', { name: 'Save' }).hasAttribute('disabled')).toBe(false)
expect(screen.getByRole('textbox', { name: 'Notes' }).textContent).toBe('Remote draft')
})
it('saves a retyped branch name as the display name', async () => {
const original = openDialog({ displayName: 'release/rc-11', branch: 'release/rc-11' })
const field = screen.getByRole('textbox', { name: 'Display Name' })
fireEvent.change(field, { target: { value: 'release/rc-1' } })
fireEvent.change(field, { target: { value: 'release/rc-11' } })
await save()
expect(updateWorktreeMeta.mock.calls[0]).toEqual([
original.id,
{ displayName: 'release/rc-11' }
])
})
})