test: 按 Copilot review 修测试健壮性(localStorage try/catch、动态 uuid);记录 pinned 跨会话限制

This commit is contained in:
HuanLinOTO
2026-09-09 14:29:44 +08:00
parent 9ce3c2706a
commit 9a2c56eb42
3 changed files with 21 additions and 7 deletions
+9 -4
View File
@@ -80,10 +80,15 @@ function mountSidebar(): { container: HTMLDivElement; store: ReturnType<typeof c
afterEach(() => {
document.body.innerHTML = ''
// Belt and braces (same as bottom-auto-terminal): drop any persisted layout
// a pending 200ms debounce write left behind between tests. Guarded — some
// node/jsdom combos (node >=22 without --localstorage-file) expose no
// working localStorage and a bare access would throw in the hook.
if (typeof localStorage !== 'undefined') localStorage.clear()
// a pending 200ms debounce write left behind between tests. Fully guarded —
// some node/jsdom combos expose no working localStorage, and an opaque
// origin can define it as a THROWING accessor, so even `typeof` can throw;
// the try/catch keeps the cleanup hook itself failure-proof.
try {
if (typeof localStorage !== 'undefined') localStorage.clear()
} catch {
// Opaque origin / no storage: nothing persisted to clear.
}
vi.unstubAllGlobals()
})
+3 -2
View File
@@ -203,9 +203,10 @@ describe('agent terminal tools', () => {
it('terminal_wait_for returns skipped (schema-valid) when the registry reports a user skip', async () => {
const { captured, registry } = mount()
const tool = toolOf(captured, 'terminal_wait_for')
registry.create('s1', 'skipper', '')
// Use the uuid the registry actually minted — no coupling to its id scheme.
const uuid = registry.create('s1', 'skipper', '')
registry.nextWaitResult = { kind: 'skipped' }
const value = await tool.execute({ uuid: 'uuid-1', needle: 'BUILD_OK', timeout_ms: 1000 }, exec('s1'))
const value = await tool.execute({ uuid, needle: 'BUILD_OK', timeout_ms: 1000 }, exec('s1'))
expect(value).toEqual({ kind: 'skipped', needle: 'BUILD_OK' })
expect(validateJsonSchemaValue(tool.output.schema, value, 'value')).toEqual([])
})