fix: address Copilot review round 3 (code-point truncation, a11y live status, disabled-tab wait mirroring, test unmount, concurrent-wait test)
This commit is contained in:
1 parent
ccb89fd91b
commit
70a150794b
6 files changed
+106
-19
No files matched your search
@@ -430,6 +430,31 @@ describe('AgentPtyRegistry', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('concurrent waits on one uuid: snapshot shows the latest needle, skipWait skips all', async () => {
|
||||
const registry = new AgentPtyRegistry(testShell())
|
||||
try {
|
||||
const uuid = registry.create('s1', 'concurrent', '', process.cwd(), 80, 24)
|
||||
// The bare shell never emits either needle → both waits miss the fast
|
||||
// paths and register their records (synchronously, before waitFor's
|
||||
// first poll await — the documented concurrent-wait contract).
|
||||
const first = registry.waitFor(uuid, 'NEVER_A_XYZ', 60_000)
|
||||
const second = registry.waitFor(uuid, 'NEVER_B_XYZ', 60_000)
|
||||
// The banner mirrors the LATEST wait (waits.at(-1)).
|
||||
expect(registry.list('s1')[0]?.waiting?.needle).toBe('NEVER_B_XYZ')
|
||||
expect(typeof registry.list('s1')[0]?.waiting?.since).toBe('number')
|
||||
// One skip transitions EVERY active wait on the terminal.
|
||||
expect(registry.skipWait(uuid)).toBe(2)
|
||||
expect(await first).toEqual({ kind: 'skipped', needle: 'NEVER_A_XYZ' })
|
||||
expect(await second).toEqual({ kind: 'skipped', needle: 'NEVER_B_XYZ' })
|
||||
// Both resolved → the wait state cleared from the snapshot.
|
||||
expect(registry.list('s1')[0]?.waiting).toBeUndefined()
|
||||
// Idempotent: nothing left to skip.
|
||||
expect(registry.skipWait(uuid)).toBe(0)
|
||||
} finally {
|
||||
registry.disposeAll()
|
||||
}
|
||||
})
|
||||
|
||||
it('fires change listeners when a wait starts and ends', async () => {
|
||||
const registry = new AgentPtyRegistry(testShell())
|
||||
try {
|
||||
|
||||
@@ -33,6 +33,11 @@ class FakeWebSocket {
|
||||
/** Unique per-test session ids (see the comment inside mountSidebar). */
|
||||
let sessionSeq = 0
|
||||
|
||||
/** Roots mounted by the current test; afterEach unmounts them (reverse
|
||||
* order) so React effect cleanup (store subscription, host-feed sockets,
|
||||
* debounced persistence) actually runs between tests. */
|
||||
const mounted: Array<() => void> = []
|
||||
|
||||
function mountSidebar(): { container: HTMLDivElement; store: ReturnType<typeof createSidebarStore>; service: BetterSidebarService; unmount: () => void } {
|
||||
vi.stubGlobal('WebSocket', FakeWebSocket)
|
||||
FakeWebSocket.instances = []
|
||||
@@ -66,18 +71,19 @@ function mountSidebar(): { container: HTMLDivElement; store: ReturnType<typeof c
|
||||
}
|
||||
const root: Root = createRoot(container)
|
||||
act(() => { root.render(createElement(Sidebar, { ctx: ctx as never, store })) })
|
||||
return {
|
||||
container,
|
||||
store,
|
||||
service,
|
||||
unmount: () => {
|
||||
act(() => { root.unmount() })
|
||||
container.remove()
|
||||
},
|
||||
const unmount = (): void => {
|
||||
act(() => { root.unmount() })
|
||||
container.remove()
|
||||
}
|
||||
mounted.push(unmount)
|
||||
return { container, store, service, unmount }
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
// Unmount BEFORE wiping the DOM: root.unmount() must run the shell's
|
||||
// effect cleanups (store subscription, WS close, persistence debounce);
|
||||
// document.body.innerHTML = '' alone leaves them alive into later tests.
|
||||
for (const unmount of mounted.splice(0).reverse()) unmount()
|
||||
document.body.innerHTML = ''
|
||||
// Belt and braces (same as bottom-auto-terminal): drop any persisted layout
|
||||
// a pending 200ms debounce write left behind between tests. Fully guarded —
|
||||
|
||||
Reference in new issue
Block a user