feat(sidebar): 打开方式双源并存 + 多选压缩下载 + 文件变动层级树

用户追加三条需求,全部落地:

1) 打开方式 = 宿主探测应用 + 插件自研 open-with(并存)
- 逐字恢复 src/client/open-with.ts / open-with-settings.tsx / plugin-settings.ts /
  src/open-external.ts / open.external 路由 / api.openExternal / editor descriptor
  的 settings.render,以及 20 个 openWith* 词条(19 份词典从 main 取回原文)
- 恢复 menu-flip.ts + layout.css 子菜单翻转规则(子菜单回来了)
- FileTree 菜单段(无标题行):宿主行 → 分隔线 → 插件 pinned + 「在应用中打开 >」
  子菜单(图钉 / SSH 后缀原样)→ 分隔线 → 宿主 reveal;宿主可用时过滤插件
  explorer 目标,宿主不可用时插件行照旧(SSH 远端场景保持可用)
- 死键清理:菜单去掉标题行后 openInApp 词条无引用,已从 21 份词典删除

2) 文件页多选右键「压缩并打包下载」
- 新增 src/zip.ts(自研 ZIP:方法 0/8 按收益二选一、UTF-8 bit 11、目录条目、
  自实现 CRC32、无第三方依赖)+ src/archive-route.ts(名净化 + 递归收集)+
  GET /sidebar/archive(同一道 workspace fence、目录递归跳过符号链接、
  10000 条目 / 256 MiB 上限)+ api.archiveUrl
- FileTree:多选 ≥2 项或单选目录时出现;fetch → blob → objectURL 下载,
  路由错误(超限 / fence / 非 GET)以 zipFailed 显示在错误条
- 修掉真实缺陷:central directory 只写 MS-DOS 位而 version-made-by 声称 Unix,
  Info-ZIP 会把每个文件解成 mode 000;改为 Unix 语义(0o100644 * 0x10000,
  << 16 会溢出 int32)。系统 unzip 复验:mode 644/755、unzip -t 无错

3) 文件变动页层级树 + 视觉打磨
- 新增 src/client/changes/change-tree.ts:单子目录链压缩成一行、目录先于文件、
  大小写不敏感排序、文件带 GitFileStatus、目录带下级变更数
- GitLens 两组各自渲染树:折叠状态按「组+路径」独立、默认展开;分组头吸顶 +
  计数胶囊;Stage all/Unstage all 改为带 aria-label 的 IconButton;选中 =
  interactive-bg-active + 2px 内嵌强调条;12px/级缩进 + l1 参考线;
  历史行 hash 徽标 / ref 胶囊 / 作者·时间右对齐

验证:typecheck / lint / test(134 文件 1422 通过)/ build 全绿;
DSH_CMD='npx -y --package @deepseek-ai/dsh@0.1.7-rc.1 dsh' pnpm test:mount 7/7 通过;
真实宿主截图确认三条需求(多选+双源菜单+zip 项、变动页树形层级)
This commit is contained in:
Menghuan1918 committed 2026-09-28 18:08:21 +08:00
1 parent 36fbc5ac7e
commit b011be1e98
56 files changed
+4468 -194

No files matched your search

+133
View File
@@ -421,3 +421,136 @@ describe('GitLens (changes tab, git lens) linked-worktree consistency', () => {
}
})
})
describe('GitLens (changes tab, git lens) change tree', () => {
/** Mount with one changed-file inventory; every test picks its own entries. */
async function mountTree(
container: HTMLElement,
root: Root,
entries: Array<{ path: string; xy: string }>,
): Promise<void> {
const changes = entries.filter(row => row.xy !== ' ').length
vi.spyOn(api, 'gitWorktrees').mockResolvedValue([{ path: MAIN, branch: 'main', current: true, changes }])
vi.spyOn(api, 'gitStatus').mockResolvedValue({ isRepo: true, branch: 'main', entries })
vi.spyOn(api, 'gitBranch').mockResolvedValue({ current: 'main', names: ['main'] })
vi.spyOn(api, 'gitLog').mockResolvedValue([])
mountGit(root)
await flushEffects()
}
function makeRoot(): { container: HTMLDivElement; root: Root } {
const container = document.createElement('div')
document.body.append(container)
return { container, root: createRoot(container) }
}
it('folds a directory row per group, independently of the same path on the other side', async () => {
const { container, root } = makeRoot()
try {
await mountTree(container, root, [
{ path: 'src/a.ts', xy: ' M' }, // unstaged side
{ path: 'src/b.ts', xy: 'M ' }, // staged side
])
const dirs = () => [...container.querySelectorAll<HTMLButtonElement>('button[data-dir="src"]')]
// One 'src' row per group: a path with changes on both sides appears in
// both trees.
expect(dirs()).toHaveLength(2)
expect(dirs()[0]!.getAttribute('aria-expanded')).toBe('true')
expect(dirs()[0]!.querySelector('svg')).not.toBeNull()
expect(container.querySelector('button[data-path="src/a.ts"]')).not.toBeNull()
expect(container.querySelector('button[data-path="src/a.ts"]')!.querySelector('svg')).not.toBeNull()
await act(async () => { dirs()[0]!.click() })
// Folded: the unstaged subtree is gone...
expect(dirs()[0]!.getAttribute('aria-expanded')).toBe('false')
expect(container.querySelector('button[data-path="src/a.ts"]')).toBeNull()
// ...while the staged group's own 'src' row stays open and keeps its file.
expect(dirs()[1]!.getAttribute('aria-expanded')).toBe('true')
expect(container.querySelector('button[data-path="src/b.ts"]')).not.toBeNull()
await act(async () => { dirs()[0]!.click() })
expect(container.querySelector('button[data-path="src/a.ts"]')).not.toBeNull()
} finally {
act(() => { root.unmount() })
container.remove()
}
})
it('compresses a single-child directory chain into one labelled row', async () => {
const { container, root } = makeRoot()
try {
await mountTree(container, root, [
{ path: 'src/client/changes/a.ts', xy: ' M' },
{ path: 'src/client/changes/b.ts', xy: ' M' },
])
// Three levels, one child each: one row, one label, two changes.
const row = container.querySelector<HTMLButtonElement>('button[data-dir="src/client/changes"]')
expect(row).not.toBeNull()
expect(row!.textContent).toContain('src/client/changes')
expect(container.querySelector('[data-group="unstaged"] [data-count]')?.textContent).toBe('2')
// Both files hang under that one row.
expect(container.querySelector('button[data-path="src/client/changes/a.ts"]')).not.toBeNull()
expect(container.querySelector('button[data-path="src/client/changes/b.ts"]')).not.toBeNull()
// Nothing on the staged side: only the empty band, no tree rows.
expect(container.querySelectorAll('[data-group="staged"] [data-path]')).toHaveLength(0)
} finally {
act(() => { root.unmount() })
container.remove()
}
})
it('stages a file from a nested tree row and re-reads the shared status', async () => {
const { container, root } = makeRoot()
try {
await mountTree(container, root, [{ path: 'src/deep/a.ts', xy: ' M' }])
const stage = vi.spyOn(api, 'gitStage').mockResolvedValue({ ok: true })
const statusSpy = vi.mocked(api.gitStatus)
const statusCallsBefore = statusSpy.mock.calls.length
const action = container.querySelector<HTMLButtonElement>(`button[aria-label="${t('stage')}"]`)
expect(action).not.toBeNull()
await act(async () => { action!.click() })
await flushEffects()
// The auto-selected primary checkout rides along as the worktree target.
expect(stage).toHaveBeenCalledWith(expect.objectContaining({ sessionId: 'session' }), 'src/deep/a.ts', MAIN)
expect(statusSpy.mock.calls.length).toBeGreaterThan(statusCallsBefore)
} finally {
act(() => { root.unmount() })
container.remove()
}
})
it('bands each group with its count and a labelled stage-all action', async () => {
const { container, root } = makeRoot()
try {
await mountTree(container, root, [
{ path: 'src/a.ts', xy: ' M' },
{ path: 'docs/b.md', xy: ' M' },
{ path: 'src/c.ts', xy: 'M ' },
])
const unstaged = container.querySelector<HTMLElement>('[data-group="unstaged"]')!
const staged = container.querySelector<HTMLElement>('[data-group="staged"]')!
expect(unstaged.textContent).toContain(t('unstaged'))
expect(unstaged.querySelector('[data-count]')?.textContent).toBe('2')
expect(staged.querySelector('[data-count]')?.textContent).toBe('1')
const stageAll = unstaged.querySelector<HTMLButtonElement>(`button[aria-label="${t('stageAll')}"]`)
const unstageAll = staged.querySelector<HTMLButtonElement>(`button[aria-label="${t('unstageAll')}"]`)
expect(stageAll).not.toBeNull()
expect(unstageAll).not.toBeNull()
const stage = vi.spyOn(api, 'gitStage').mockResolvedValue({ ok: true })
await act(async () => { stageAll!.click() })
await flushEffects()
// "Stage all" stages the whole worktree: no path argument.
expect(stage).toHaveBeenCalledWith(expect.objectContaining({ sessionId: 'session' }), undefined, MAIN)
} finally {
act(() => { root.unmount() })
container.remove()
}
})
})