mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 11:42:17 +00:00
test(browser): prove dialogs and navigation never wait for a wake frame
This commit is contained in:
parent
bd46fe5006
commit
eaa844d9bb
2 changed files with 33 additions and 9 deletions
|
|
@ -42,16 +42,38 @@ test("overlapping commands await the same first frame", async () => {
|
|||
second[Symbol.dispose]()
|
||||
})
|
||||
|
||||
test("a missing frame never prevents acting; dialog and navigation bypass even a pending wake", async () => {
|
||||
test("idle past the deadline with a dialog open, the dialog command un-throttles without waiting for a frame", () => {
|
||||
const timers: (() => void)[] = []
|
||||
const throttles: boolean[] = []
|
||||
|
||||
const render = agentRendering(new AbortController().signal, value => throttles.push(value), (_, run) => {
|
||||
timers.push(run)
|
||||
|
||||
return () => {}
|
||||
})
|
||||
|
||||
render.hold()[Symbol.dispose]()
|
||||
timers.forEach(run => run())
|
||||
expect(throttles).toEqual([false, true])
|
||||
|
||||
// An open alert pauses the page's animation frames, so no command waits for one, including the one that answers it.
|
||||
for (const method of ["dialog", "snapshot", "click", "navigate"] as const) expect(needsWakeFrame(method, true, true)).toBe(false)
|
||||
|
||||
const answer = render.hold(needsWakeFrame("dialog", true, true) ? () => new Promise(() => {}) : undefined)
|
||||
expect(answer.painted).toBeUndefined()
|
||||
expect(throttles).toEqual([false, true, false])
|
||||
})
|
||||
|
||||
test("a renderer that never paints neither blocks navigation nor fails the command that waited for it", async () => {
|
||||
const render = agentRendering(new AbortController().signal, () => {}, () => () => {})
|
||||
const frame = Promise.withResolvers<void>()
|
||||
const shot = render.hold(() => frame.promise)
|
||||
expect(needsWakeFrame("dialog", true, true)).toBe(false)
|
||||
expect(needsWakeFrame("navigate", true, false)).toBe(false)
|
||||
expect(needsWakeFrame("click", true, true)).toBe(false)
|
||||
const snapshot = render.hold(needsWakeFrame("snapshot", true, false) ? () => frame.promise : undefined)
|
||||
expect(snapshot.painted).toBeDefined()
|
||||
|
||||
for (const method of ["navigate", "reload", "stop", "back", "dialog", "tabs.close"] as const) expect(needsWakeFrame(method, true, false)).toBe(false)
|
||||
expect(needsWakeFrame("snapshot", false, false)).toBe(false)
|
||||
expect(needsWakeFrame("evaluate", true, false)).toBe(true)
|
||||
expect(render.hold().painted).toBeUndefined()
|
||||
expect(render.hold(needsWakeFrame("navigate", true, false) ? () => frame.promise : undefined).painted).toBeUndefined()
|
||||
// The capture deadline rejects the wake; the snapshot then proceeds as it would without one.
|
||||
frame.reject(new Error("no frame"))
|
||||
await expect(shot.painted).resolves.toBeUndefined()
|
||||
await expect(snapshot.painted).resolves.toBeUndefined()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ import type { Browser } from "@opencode/plugin-browser/rpc"
|
|||
|
||||
/** A paused page cannot paint the frame that its dialog or a recovery navigation would unblock. */
|
||||
export function needsWakeFrame(method: Browser.Method, loaded: boolean, dialog: boolean) {
|
||||
return loaded && !dialog && ["snapshot", "find", "wait", "evaluate", "click", "check", "fill", "fill_form", "select", "press", "type", "hover", "drag", "scroll", "screenshot"].includes(method)
|
||||
const painting: Browser.Method[] = ["snapshot", "find", "wait", "evaluate", "click", "check", "fill", "fill_form", "select", "press", "hover", "drag", "scroll", "screenshot"]
|
||||
|
||||
return loaded && !dialog && painting.includes(method)
|
||||
}
|
||||
|
||||
// Long enough to cover thinking between a snapshot and its follow-up; a forgotten tab doesn't animate indefinitely.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue