diff --git a/docs/external-plugin-guide.md b/docs/external-plugin-guide.md index 27b7f5f1..facbc443 100644 --- a/docs/external-plugin-guide.md +++ b/docs/external-plugin-guide.md @@ -454,7 +454,7 @@ ctx.effect(() => { | id | order | single | hidden | 用途 | |---|---|---|---|---| | `editor` | 10 | 否(按 path 去重) | 否 | 唯一「文件窗口」(编辑/预览 + 资源管理)。chrome 恒合并形态:路径输入框 + 编辑器控件 + 可开关内嵌文件树(全局搜索 `fs.search`;状态存 `tab.meta.treeOpen/treeWidth`)。`editorExplorer`:关(默认)= 按 path 新开,无路径窗口 = 纯资源管理器;开 = 树点击/Enter 经 `updateTab` 原地切换(id/meta 不变),无路径窗口 = 带 chrome 空窗口。树右键「在新 Tab 中打开」「在侧边打开」(pane 右侧 split)。新会话 seed 空文件窗口(`title:'Files'`);旧 `explorer` tab 经 `sanitizeState` 迁移。树 listing 与文件名搜索应用 `explorerExclude` 排除模式(editor 卡片齿轮弹窗可编辑;host 侧过滤,匹配条目彻底移除且永不阻塞折叠);单目录链折叠为 `a/b/c` 面包屑行(POSIX 隐藏与排除条目不计入唯一子项判定) | -| `git` | 20 | 是 | 是(本轮文件操作数) | 「文件变动」统一 tab(id 保留 `git` 以兼容持久化布局):**Git 视角**(原 Git 面板:staged/unstaged / 提交 / 历史 / worktree·子仓库选择)+ **本轮文件视角**(原 file-trace:模型读/写/编辑实时折叠,按文件分组、类型筛选);会话事件经插件自有宿主路由 `changes.ops` 供给(live 日志优先、冷会话回放持久化记录,`afterSeq` 增量),badge 读 tab 轮询写入的同步缓存。页头复用宿主会话页的下划线 Tabs 样式(`wSkVaW_tabs/tab/tabActive`,宿主尚未公开组件;支持左右方向键与 Home/End 切换)。两视角共用底部可拖拽预览面板(`tab.meta.lens/previewH` 持久化),diff 渲染统一走 `src/client/diff/`(`DiffRows`/`DiffFiles`:mod 配对 + 行内高亮 + 语法着色 + 上下文折叠);Git 目标可展开为独立 diff tab(落进工作台的 diff 分栏) | +| `git` | 20 | 是 | 是(本轮文件操作数) | 「Git」统一 tab(id 保留 `git` 以兼容持久化布局):**Git 视角**(原 Git 面板:staged/unstaged / 提交 / 历史 / worktree·子仓库选择)+ **本轮文件视角**(原 file-trace:模型读/写/编辑实时折叠,按操作时间倒序平铺、不按文件分组,每行「操作 → 文件路径 → 大小/时间」,支持类型筛选);会话事件经插件自有宿主路由 `changes.ops` 供给(live 日志优先、冷会话回放持久化记录,`afterSeq` 增量),badge 读 tab 轮询写入的同步缓存。页头复用宿主会话页的下划线 Tabs 样式(`wSkVaW_tabs/tab/tabActive`,宿主尚未公开组件;支持左右方向键与 Home/End 切换)。两视角共用底部可拖拽预览面板(`tab.meta.lens/previewH` 持久化),diff 渲染统一走 `src/client/diff/`(`DiffRows`/`DiffFiles`:mod 配对 + 行内高亮 + 语法着色 + 上下文折叠);Git 目标可展开为独立 diff tab(落进工作台的 diff 分栏) | | `subagent` | 30 | 是 | 否 | 任务管理(工作流图/树、团队任务板、后台任务抽屉) | | `sidechat` | 35 | 否(`sidechat:`,按 `meta.threadId` 去重) | 否 | 侧边对话(每对话一 Tab):打开即建空线程(首条消息赢得标签并同步标题);线程 = 插件自建子会话(种子继承父会话上下文,进行中回合以 `interrupted` 闭合;种子带合法 `subagent/descriptor`,SubagentView 按 `Side: ` 前缀过滤),`origin:'subagent'` 隐藏于主列表;走 `/sidebar/api/sidechat.*` 路由;头部菜单切换/重开(`parkSidechatReopen` + 确定性 id),关 Tab 释放 live agent;重开经 `collectOwnEvents` 回源到种子边界;「保存为新会话」= `session.fork`(`this` 敏感)。[设计文档](plans/2026-08-20-sidechat-tab-design.md) | | `diff` | -1 | 否(按 id 去重) | 是 | 差异查看(changes tab 的预览面板「展开为独立页签」触发,同一渲染栈) | diff --git a/src/client/changes/SessionLens.tsx b/src/client/changes/SessionLens.tsx index fec7a0e4..a245bf26 100644 --- a/src/client/changes/SessionLens.tsx +++ b/src/client/changes/SessionLens.tsx @@ -1,6 +1,6 @@ /** * The session lens of the changes tab: agent truth — every file the model - * read, wrote, or edited in this session, grouped by file, newest first, + * read, wrote, or edited in this session, one operation per row, newest first, * with kind filters. Clicking an op previews it in the tab's shared bottom * pane (see {@link DiffPane}): writes and edits as line diffs, reads as a * line-numbered content view, failures as their real error text. The ops @@ -9,7 +9,7 @@ */ import { useMemo, useState } from 'react' import { relativeTime, t } from '../locales.ts' -import { groupByFile, type FileOp, type FileOpKind } from './ops.ts' +import type { FileOp, FileOpKind } from './ops.ts' import { formatBytes } from '../diff/rows.ts' import { Chip, Notice, StatusBadge } from '../ui/index.ts' import css from './changes.module.css' @@ -37,7 +37,6 @@ export function SessionLens({ ops, loadError, onPreview, selectedCallId }: Sessi () => (filter === 'all' ? ops : ops.filter(op => op.kind === filter)), [ops, filter], ) - const groups = useMemo(() => groupByFile(filteredOps), [filteredOps]) const counts = useMemo(() => { const map = new Map([['read', 0], ['write', 0], ['edit', 0]]) for (const op of ops) map.set(op.kind, (map.get(op.kind) ?? 0) + 1) @@ -79,33 +78,29 @@ export function SessionLens({ ops, loadError, onPreview, selectedCallId }: Sessi {loadError && {t('changesLoadError')}} {ops.length === 0 && !loadError && {t('changesSessionEmpty')}} {ops.length > 0 && filteredOps.length === 0 && {t('changesFilterEmpty')}} - {[...groups.entries()].map(([path, fileOps]) => ( -
-
{path}
- {fileOps.map(op => ( - - ))} -
+ )} + {relativeTime(new Date(op.time).toISOString())} + + ))} diff --git a/src/client/changes/changes.module.css b/src/client/changes/changes.module.css index c34329e1..60822af9 100644 --- a/src/client/changes/changes.module.css +++ b/src/client/changes/changes.module.css @@ -553,13 +553,11 @@ .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; } -.fileGroup { margin-bottom: 6px; } -/* The group label sits between op blocks: extra head padding separates it from - the previous file's rows, the first group starts flush. */ -.filePath { display: block; color: var(--dsw-alias-label-tertiary); font-family: var(--ds-font-family-code, monospace); font-size: 11px; padding: 6px 4px 2px; word-break: break-all; } -.fileGroup:first-child .filePath { padding-top: 2px; } +/* 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. */ +.filePath { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dsw-alias-label-tertiary); font-family: var(--ds-font-family-code, monospace); font-size: 11px; } .opRow { position: relative; display: flex; align-items: center; gap: 6px; width: 100%; min-height: 24px; border: 0; border-radius: 4px; background: transparent; color: var(--dsw-alias-label-primary); font: inherit; font-size: 11px; padding: 0 5px; cursor: pointer; text-align: left; } .opRow:hover { background: var(--dsw-alias-interactive-bg-hover); } @@ -567,7 +565,7 @@ .opRow[data-op-error='true'] { box-shadow: inset 2px 0 0 var(--dsw-alias-state-error-primary); } /* Size + relative time ride as one right-aligned cluster so the kind badges form a scannable left rail and the meta column stays flush right. */ -.opMeta { margin-left: auto; display: inline-flex; align-items: baseline; gap: 8px; flex: none; min-width: 0; } +.opMeta { margin-left: auto; display: inline-flex; align-items: baseline; gap: 8px; flex: none; min-width: 0; white-space: nowrap; } .opTime { color: var(--dsw-alias-label-tertiary); font-size: 10px; flex: none; } .opFlag { color: var(--dsw-alias-state-business-primary); font-size: 10px; flex: none; } .opFlagError { color: var(--dsw-alias-state-error-primary); font-size: 10px; flex: none; } @@ -607,7 +605,7 @@ /* Keyboard focus rings match the shared sidebar convention (the kit atoms and the tree rows carry their own). */ -.logRow:focus-visible, .logMore:focus-visible, .select:focus-visible, .dragHandle:focus-visible { +.opRow:focus-visible, .logRow:focus-visible, .logMore:focus-visible, .select:focus-visible, .dragHandle:focus-visible { outline: 2px solid var(--dsw-alias-interactive-bg-hover-accent); outline-offset: -1px; } diff --git a/src/client/changes/ops.ts b/src/client/changes/ops.ts index 9d91f266..40d514d5 100644 --- a/src/client/changes/ops.ts +++ b/src/client/changes/ops.ts @@ -183,21 +183,6 @@ export function extractFileOps(events: readonly SidebarSessionEvent[]): FileOp[] return [...byCall.values()].sort((a, b) => b.time - a.time) } -/** - * Group operations by path, newest op first per file, files ordered by their - * most recent operation. - */ -export function groupByFile(ops: readonly FileOp[]): Map { - const groups = new Map() - for (const op of ops) { - const list = groups.get(op.path) ?? [] - list.push(op) - groups.set(op.path, list) - } - const ordered = [...groups.entries()].sort((a, b) => b[1][0]!.time - a[1][0]!.time) - return new Map(ordered) -} - /** * The last content known for a path before the given operation, synthesized * from earlier ops: a write's payload is authoritative, an edit implies its diff --git a/tests/changes-ops.spec.ts b/tests/changes-ops.spec.ts index e0b80220..e4dea0d2 100644 --- a/tests/changes-ops.spec.ts +++ b/tests/changes-ops.spec.ts @@ -6,7 +6,7 @@ */ import { describe, expect, it } from 'vitest' import { createToolResultMessage, ToolCallId } from '@deepseek-ai/dsh-llm' -import { extractFileOps, groupByFile, knownContentBefore, parseReadContent, parseReadLines } from '../src/client/changes/ops.ts' +import { extractFileOps, knownContentBefore, parseReadContent, parseReadLines } from '../src/client/changes/ops.ts' import { buildChangeTree, type ChangeNode } from '../src/client/changes/change-tree.ts' import { diffLines, buildDiffSegments, coalesceInline, diffInline } from '../src/client/diff/rows.ts' import { langOfPath, scanLine } from '../src/client/diff/highlight.ts' @@ -142,13 +142,13 @@ describe('extractFileOps', () => { expect(ops.find(op => op.kind === 'read')?.errorText).toBe('cannot read "b": not found') }) - it('groups by file newest-first and recovers prior write content', () => { + it('keeps operations newest-first and recovers prior write content', () => { const ops = extractFileOps([ call(1, 'write', 'w1', { file_path: 'a.ts', content: 'first' }), call(2, 'write', 'w2', { file_path: 'a.ts', content: 'second' }), call(3, 'write', 'w3', { file_path: 'b.ts', content: 'x' }), ]) - expect([...groupByFile(ops).keys()]).toEqual(['b.ts', 'a.ts']) + expect(ops.map(op => op.callId)).toEqual(['w3', 'w2', 'w1']) expect(knownContentBefore(ops, 'a.ts', ops.find(op => op.callId === 'w2')!)).toBe('first') }) }) diff --git a/tests/changes-tab.spec.tsx b/tests/changes-tab.spec.tsx index c9eeb402..2310d8c7 100644 --- a/tests/changes-tab.spec.tsx +++ b/tests/changes-tab.spec.tsx @@ -293,7 +293,7 @@ describe('ChangesTab', () => { const sessionTab = lensTab(container, t('changesSessionLens')) await act(async () => { sessionTab!.click() }) - // Two files grouped, newest first; the write chip carries its count. + // Two operation rows, newest first; the write chip carries its count. expect(container.textContent).toContain('src/b.ts') expect(container.textContent).toContain('src/a.ts') const chips = [...container.querySelectorAll('button[aria-pressed]')] @@ -306,6 +306,77 @@ describe('ChangesTab', () => { } }) + it('lists interleaved operations without file groups and keeps filtering and previews', async () => { + mockGit([]) + const path = 'D:\\projects\\cc-switch\\test-01.txt' + vi.spyOn(api, 'changesOps').mockResolvedValue({ + events: [ + { type: 'tool/call', seq: 1, time: 1, data: { name: 'read', callId: 'r1', arguments: JSON.stringify({ file_path: path }) } }, + { type: 'tool/result', seq: 2, time: 2, data: { message: { source: { kind: 'tool', callId: 'r1' }, content: [{ type: 'text', text: '1: earlier read' }] } } }, + ...writeEvents(3, 'src/other.txt'), + { type: 'tool/call', seq: 5, time: 5, data: { name: 'edit', callId: 'e5', arguments: JSON.stringify({ file_path: path, old_string: 'old', new_string: 'x'.repeat(103) }) } }, + { type: 'tool/result', seq: 6, time: 6, data: { message: { source: { kind: 'tool', callId: 'e5' }, content: [{ type: 'text', text: 'ok' }] } } }, + { type: 'tool/call', seq: 7, time: 7, data: { name: 'read', callId: 'r7', arguments: JSON.stringify({ file_path: path }) } }, + ], + lastSeq: 7, + }) + + const container = document.createElement('div') + document.body.append(container) + const root: Root = createRoot(container) + try { + mount(root, { id: 'git', type: 'git', title: 'Changes', meta: { lens: 'session' } }) + await flushEffects() + const rows = [...container.querySelectorAll('button[data-op-kind]')] + expect(rows.map(row => row.dataset.opKind)).toEqual(['read', 'edit', 'write', 'read']) + expect(rows.map(row => row.querySelector('[title]')?.getAttribute('title'))) + .toEqual([path, path, 'src/other.txt', path]) + expect(rows[0]!.textContent).toContain(t('changesRunning')) + for (const row of rows) { + // Rows are direct siblings, not nested inside per-file wrappers. + expect(row.parentElement).toBe(rows[0]!.parentElement) + const label = row.querySelector('[data-tone]')! + const filePath = row.querySelector('[title]')! + expect(filePath.textContent).toBe(filePath.getAttribute('title')) + expect(label.compareDocumentPosition(filePath) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy() + expect(row.lastElementChild).toBe(filePath.nextElementSibling) + } + expect([...rows[0]!.parentElement!.children]).toEqual(rows) + expect(rows[1]!.lastElementChild!.firstElementChild!.textContent).toBe('103 B') + + await act(async () => { rows[1]!.click() }) + await flushEffects() + expect(rows[1]!.dataset.selected).toBe('true') + expect(container.textContent).toContain('x'.repeat(103)) + + const readChip = [...container.querySelectorAll('button[aria-pressed]')] + .find(chip => chip.textContent === t('changesRead') + '2') + expect(readChip).toBeDefined() + await act(async () => { readChip!.click() }) + const reads = [...container.querySelectorAll('button[data-op-kind]')] + expect(reads.map(row => row.dataset.opKind)).toEqual(['read', 'read']) + expect(reads.map(row => row.querySelector('[title]')?.textContent)).toEqual([path, path]) + await act(async () => { reads[1]!.click() }) + await flushEffects() + expect(reads[1]!.dataset.selected).toBe('true') + expect(container.textContent).toContain('earlier read') + } finally { + act(() => { root.unmount() }) + container.remove() + } + }) + + it('keeps operation paths and metadata on one line under width pressure', () => { + const sheet = readFileSync('src/client/changes/changes.module.css', 'utf8') + const pathRule = sheet.match(/\n\.filePath \{([^}]+)\}/)?.[1] + expect(pathRule).toContain('flex: 1') + expect(pathRule).toContain('min-width: 0') + expect(pathRule).toContain('overflow: hidden') + expect(pathRule).toContain('text-overflow: ellipsis') + expect(pathRule).toContain('white-space: nowrap') + expect(sheet.match(/\n\.opMeta \{([^}]+)\}/)?.[1]).toContain('white-space: nowrap') + }) + it('renders a .md read op in reading mode through the shared MarkdownText', async () => { mockGit([]) const md = ['# Title', '', '| A | B |', '| --- | --- |', '| 1 | 2 |', '', '![pic](./img.png)', ''].join('\n') diff --git a/tests/editor-host.spec.tsx b/tests/editor-host.spec.tsx index 1aa24620..67f19942 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,6 +88,19 @@ 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. * @@ -123,6 +136,11 @@ setupReactAct() * weakening the assertion: a tree that never lists the row still fails. * The affected `describe` raises its clock to 120s, so a genuinely missing row * still fails on the ASSERTION, never on the test clock. + * + * The 2026-10-13 red runs were a different class: `panel=ABSENT` came from a + * fixture leak (the shared session id let a later case restore `treeOpen=false` + * from the delayed store write), which the per-case session id below fixes. + * More waiting could never have repaired that. */ const RENDER_WAIT_MS = 60_000 @@ -192,7 +210,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 @@ -202,7 +220,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, @@ -224,7 +242,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: [], @@ -261,7 +279,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') @@ -627,7 +645,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')! @@ -680,7 +698,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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, @@ -710,7 +728,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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: [], @@ -754,7 +772,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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`). @@ -800,7 +818,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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 => @@ -808,10 +826,16 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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() @@ -822,7 +846,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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) @@ -854,7 +878,7 @@ describe('EditorHost native-tab context-menu actions', { timeout: 120_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'))