chore: establish YCode replication baseline and TODO

This commit is contained in:
xiaohan.yuan committed 2026-10-17 02:43:49 +08:00
commit 6dc59f89ba
1118 files changed
+196002

No files matched your search

@@ -0,0 +1,38 @@
import fs from 'node:fs/promises'
import path from 'node:path'
import assert from 'node:assert/strict'
import { pathToFileURL } from 'node:url'
const directory = await fs.mkdtemp(path.resolve('.tmp/rea-probe-budget-'))
const file = path.join(directory, 'index.html'); await fs.writeFile(file, '<!doctype html>Own fixture')
const { captureElectronVisuals } = await import(pathToFileURL(path.resolve('.tmp/rea-css-runtime/dist/browser/CdpElectronVisuals.js')))
const frame = { id: 'budget-fixture', url: pathToFileURL(file).href }
const frames = [{ frame_id: frame.id, file_path: file }]
const png = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jKXcAAAAASUVORK5CYII='
const original = AbortSignal.timeout, controllers = []
AbortSignal.timeout = milliseconds => { const controller = new AbortController(); controllers.push({ controller, milliseconds }); return controller.signal }
let shots = 0, keys = 0, cancelCaller = false, caller = new AbortController()
const context = { sessionId: 'own-session', signal: caller.signal, input: { include_visuals: true, visual_probe: { actions: [{ kind: 'key', key: 'Escape', step_id: 'escape', frames: 1 }], track_selectors: [] } }, connection: { async send(method, params, session, signal) {
if (signal?.aborted) throw Error('cancelled fixture request')
if (method === 'Page.getLayoutMetrics') return { cssLayoutViewport: { clientWidth: 100, clientHeight: 100 } }
if (method === 'CSS.getMediaQueries') return { medias: [] }
if (method === 'DOMSnapshot.captureSnapshot') return { strings: [], documents: [] }
if (method === 'Page.getFrameTree') return { frameTree: { frame } }
if (method === 'Input.dispatchKeyEvent') { keys++; return {} }
if (method === 'Page.captureScreenshot') { if (++shots === 1) { controllers[0].controller.abort(); if (cancelCaller) caller.abort() }; return { data: png } }
return {}
} } }
try {
const result = await captureElectronVisuals(context, frames)
assert.equal(result.probe.status, 'completed')
assert.equal(result.probe.steps[0].status, 'completed')
assert.equal(keys, 2)
assert.equal(shots, 2)
assert.ok(controllers[0].controller.signal.aborted)
assert.equal(controllers[1].milliseconds, 30000)
assert.equal(controllers[1].controller.signal.aborted, false)
// A fresh scenario budget never revives a cancelled caller operation.
controllers.length = 0; shots = 0; keys = 0; cancelCaller = true; caller = new AbortController(); context.signal = caller.signal
await assert.rejects(captureElectronVisuals(context, frames), /cancelled fixture request/)
assert.equal(keys, 0)
console.log(JSON.stringify({ result: 'PASS', checks: 9, directory, scope: 'Own fixture, expired baseline budget and inherited caller cancellation; no target access' }))
} finally { AbortSignal.timeout = original }