diff --git a/src/client/changes/changes.module.css b/src/client/changes/changes.module.css index 1766b2d3..648cf565 100644 --- a/src/client/changes/changes.module.css +++ b/src/client/changes/changes.module.css @@ -550,7 +550,7 @@ .session { flex: 1; min-height: 0; display: flex; flex-direction: column; } .filterRow { flex: none; display: flex; gap: 4px; padding: 6px 12px; flex-wrap: wrap; } -.sessionList { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 10px; } +.sessionList { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 10px; gap: 4px; display: flex; flex-direction: column; margin-top: 4px; } /* Every op carries its own path between the badge and trailing meta. Long paths truncate inside the row; the title keeps the full path available on hover. */ diff --git a/tests/editor-host.spec.tsx b/tests/editor-host.spec.tsx index 180baf96..4ce524f0 100644 --- a/tests/editor-host.spec.tsx +++ b/tests/editor-host.spec.tsx @@ -9,7 +9,7 @@ * only, no editor chrome); file tabs keep the full chrome in both modes. */ // @vitest-environment jsdom -import { describe, expect, it, vi } from 'vitest' +import { beforeEach, describe, expect, it, vi } from 'vitest' import { createElement, useEffect, type ReactNode } from 'react' import { createRoot } from 'react-dom/client' import { act } from 'react-dom/test-utils' @@ -29,12 +29,12 @@ const treeAnswers = (): { calls: number; landedAt: number[] } => /** * Test script for the tree seam, used by the dropped-answer case below: - * `slow` lists the 1-based call numbers that answer only after a beat (so a + * `slow` lists the 1-based call numbers held until `release` is called (so a * refresh tick can land while they are in flight) and `hang` those that never * answer at all. On `globalThis` for the same hoisting reason as `treeAnswers`. */ -const treeScript = (): { slow: number[]; hang: number[] } => - ((globalThis as unknown as { __treeScript?: { slow: number[]; hang: number[] } }).__treeScript ??= { slow: [], hang: [] }) +const treeScript = (): { slow: number[]; hang: number[]; release?: () => void } => + ((globalThis as unknown as { __treeScript?: { slow: number[]; hang: number[]; release?: () => void } }).__treeScript ??= { slow: [], hang: [] }) // The tree mounts inside EditorHost in these scenarios, so the api seam must // answer without a host (the sibling FileTree specs mock it the same way). @@ -47,7 +47,7 @@ vi.mock('../src/client/api.ts', () => ({ // The call index must be read BEFORE any await: `calls` keeps moving. const index = answers.calls const script = treeScript() - if (script.slow.includes(index)) await new Promise(resolve => { setTimeout(resolve, 300) }) + if (script.slow.includes(index)) await new Promise(resolve => { script.release = resolve }) if (script.hang.includes(index)) await new Promise(() => {}) const answer = { levels: paths.map(path => ({ @@ -88,34 +88,24 @@ const fsRead = vi.fn() import { setupReactAct } from './test-utils.ts' setupReactAct() +let sessionSeq = 0 +let sessionId: string +beforeEach(() => { + // Each store persists after 200ms; another test must never restore its tabs. + sessionId = `editor-home-session-${++sessionSeq}` + treeAnswers().calls = 0 + treeAnswers().landedAt = [] + treeScript().slow = [] + treeScript().hang = [] + treeScript().release = undefined + fsRead.mockReset() +}) + /** - * How long a rendered CONDITION may take to appear on a loaded runner. - * - * `vi.waitFor` defaults to 1000ms, which is INDEPENDENT of this suite's - * `testTimeout` (15s — raised for the Windows lane, where real child processes - * are slow to start). On a saturated 2-core ubuntu runner this file runs in - * parallel with 184 others and the tree's async level load can miss that first - * second: the lane failed here at ~1026ms, i.e. exactly the waitFor budget, - * with the tree still on its loading row. - * - * This is still a CONDITION wait, not the "bigger fixed slice of time" the - * note below warns against: it returns the moment the row renders, and a tree - * that can never list it still fails the case — just after the budget instead - * of after 1s. - * - * Two raises so far, both the same cause: the ubuntu `ci` lane runs the whole - * suite in parallel, and a worker can be starved for many seconds while the - * wall clock keeps moving. - * - 1s → 10s: 2026-10-08, the lane failed at 1026ms with the tree still on - * its loading row (the macrotask boundary below came out of that one). - * - 10s → 20s: 2026-10-12, three separate runs burned the WHOLE 10s — the - * assertion read `expected false to be true` at 10008/10025ms while this - * file takes ~1s locally. Same class that day: `tests/fs-watch.spec.ts` - * hit the SUITE clock (15s, a real `fs.watch` + 150ms debounce) in a local - * run under heap pressure — i.e. the worker, not the wait, ran out of - * runway. The suite's own clock is now 30s (`vitest.config.ts`). - * The affected `describe` raises its clock to 35s, so a genuinely missing row - * still fails on the ASSERTION, never on the test clock. + * Keep the existing condition-wait budget for loaded runners. A missing row + * still fails the assertion. The 2026-10-13 CI failures had panel=ABSENT: + * previous stores persisted tabs under the shared session id, so a deduped + * open restored treeOpen=false. More waiting cannot repair that fixture leak. */ const RENDER_WAIT_MS = 20_000 @@ -185,7 +175,7 @@ function setup(): { const service = createBetterSidebarService(store) // The openTab path needs a registered editor descriptor (dedupe by path). service.registerTab({ id: 'editor', title: 'Editor', dedupeKey: (tab) => tab.path, component: () => null }) - store.setSession('editor-home-session') + store.setSession(sessionId) // The workbench seeds EMPTY (the right panel that used to carry the default // files window is DSH's native Sidebar now), so these editor-host scenarios // open the path-less files window explicitly — exactly what the shell does @@ -195,7 +185,7 @@ function setup(): { allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) .find(tab => tab.type === 'editor' && tab.path === undefined)! // openSidebarFile reads the session cwd from ctx.sessions. - const sessionsSnapshot = { byId: { 'editor-home-session': { cwd: '/tmp' } }, current: 'editor-home-session' } + const sessionsSnapshot = { byId: { [sessionId]: { cwd: '/tmp' } }, current: sessionId } const ctx = { betterSidebar: service, get: (name: string) => name === 'betterSidebar' ? service : undefined, @@ -217,7 +207,7 @@ function mountHost(ctx: Context, store: ReturnType, t root.render(createElement(EditorHost, { ctx, store, - scope: { sessionId: 'editor-home-session' }, + scope: { sessionId }, tab: tab(), expanded: [], revealed: [], @@ -254,7 +244,7 @@ async function mountHostWithTreeWithCwd(ctx: Context, store: ReturnType { typeAndCommit(container.querySelector('input[placeholder^="File path"]')!, '/tmp/board.drawio') // The claiming type received the file's session-scoped address… expect(resources).toHaveLength(1) - expect(resources[0]).toContain('editor-home-session') + expect(resources[0]).toContain(sessionId) expect(resources[0]).toContain('board.drawio') // …and the editor tab was NOT switched in place (its file is unchanged). expect(fileTab().path).toBe('/tmp/a.ts') @@ -620,7 +610,7 @@ describe('EditorHost (files window)', () => { path: '/work/src', id: 'editor:/work/src', meta: { dir: true }, - }, { sessionId: 'editor-home-session' }) + }, { sessionId }) const dirTab = (): SidebarTab => allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) .find(tab => tab.path === '/work/src')! @@ -673,7 +663,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = /** The fake client ctx (service + session feed); cwd matches api.fsTree. */ function fakeCtx(service: ReturnType): Context { - const sessionsSnapshot = { byId: { 'editor-home-session': { cwd: '/tmp' } }, current: 'editor-home-session' } + const sessionsSnapshot = { byId: { [sessionId]: { cwd: '/tmp' } }, current: sessionId } return { betterSidebar: service, get: (name: string) => name === 'betterSidebar' ? service : undefined, @@ -703,7 +693,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = ctx, store, // The tree needs a root: the real seat hands the session cwd in scope. - scope: { sessionId: 'editor-home-session', cwd: '/tmp' }, + scope: { sessionId, cwd: '/tmp' }, visible: true, tab: nativeTab, expanded: [], @@ -747,7 +737,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = const store = createSidebarStore() const { service, opens } = spyService(store) service.registerTab({ id: 'editor', title: 'Editor', dedupeKey: (tab) => tab.path, component: () => null }) - store.setSession('editor-home-session') + store.setSession(sessionId) // A native surface is what makes the service native-hosted at all: the // fake records what the service asks of the host (the real one forwards to // `ctx.sidebarRight`). @@ -793,7 +783,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = const store = createSidebarStore() const { service } = spyService(store) service.registerTab({ id: 'editor', title: 'Editor', dedupeKey: (tab) => tab.path, component: () => null }) - store.setSession('editor-home-session') + store.setSession(sessionId) store.setPrefs({ ...store.getPrefs(), editorExplorer: false }) service.openTab({ type: 'editor', title: 'a.ts', path: '/tmp/a.ts', id: 'editor:/tmp/a.ts', meta: { treeOpen: true } }) const fileTab = (): SidebarTab => @@ -801,10 +791,16 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = .find(tab => tab.path === '/tmp/a.ts')! const { container, unmount } = await mountHostWithTreeWithCwd(fakeCtx(service) as unknown as Context, store, fileTab) try { - // The real trigger: TreePanel bumps its refresh tick on a window focus. + // Hold the first answer until focus has started the forced re-list. + expect(treeAnswers().calls).toBe(1) await act(async () => { window.dispatchEvent(new Event('focus')) }) + expect(treeAnswers().calls).toBe(2) + await act(async () => { script.release!() }) await waitForTreeRow(container, 'a.ts') + expect(treeAnswers().calls).toBe(3) + expect(treeAnswers().landedAt).toHaveLength(2) } finally { + script.release?.() script.slow = [] script.hang = [] unmount() @@ -815,7 +811,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = const store = createSidebarStore() const { service } = spyService(store) service.registerTab({ id: 'editor', title: 'Editor', dedupeKey: (tab) => tab.path, component: () => null }) - store.setSession('editor-home-session') + store.setSession(sessionId) const ctx = fakeCtx(service) const opens: Array<{ target?: string }> = [] const real = service.openTab.bind(service) @@ -847,7 +843,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 35_000 }, () = const store = createSidebarStore() const { service } = spyService(store) service.registerTab({ id: 'editor', title: 'Editor', dedupeKey: (tab) => tab.path, component: () => null }) - store.setSession('editor-home-session') + store.setSession(sessionId) const ctx = fakeCtx(service) // The failure the host route now reports when EVERY opener branch dies. vi.mocked(api.openExternal).mockRejectedValueOnce(new Error('spawn cmd.exe ENOENT'))