DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(dsh-tauri-worktree): 按 review 修复 .agents 继承的遗留链接与深合并
hairyfd14c1e713a5e
diff --git a/packages/dsh-tauri-worktree/src/host/service/worktree.test.ts b/packages/dsh-tauri-worktree/src/host/service/worktree.test.tsindex 7547c7c9..f899f1a4 100644--- a/packages/dsh-tauri-worktree/src/host/service/worktree.test.ts+++ b/packages/dsh-tauri-worktree/src/host/service/worktree.test.ts@@ -1,7 +1,8 @@import { execFileSync } from 'node:child_process'import { createHash } from 'node:crypto'-import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'import { tmpdir } from 'node:os'+import process from 'node:process'import { basename, join } from 'pathe'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { resetTestDshHome, testDshHome } from '../../../../.test/test-utils'@@ -172,6 +173,36 @@ describe('worktree.create', () => {expect(second.existed).toBe(true)expect(second.binding.worktreePath).toBe(expectedPath(repository, sessionId))})++ it('重复创建时把旧实现遗留的 .agents 符号链接迁移成真实拷贝', async () => {+ const repository = createRepository()+ mkdirSync(join(repository, '.agents', 'skills', 'handle'), { recursive: true })+ writeFileSync(join(repository, '.agents', 'skills', 'handle', 'SKILL.md'), '# handle\n')+ writeFileSync(join(repository, '.gitignore'), '.agents/skills/\n')+ git(repository, 'add', '.gitignore')+ git(repository, 'commit', '-m', 'ignore skills')+ const sessionId = 'legacy-link-session'++ const first = await worktree.create(repository, sessionId)+ expect(first.ok).toBe(true)+ if (!first.ok)+ return++ // 模拟旧实现留下的符号链接+ const agents = join(first.binding.worktreePath, '.agents')+ rmSync(agents, { recursive: true, force: true })+ symlinkSync(join(repository, '.agents'), agents, process.platform === 'win32' ? 'junction' : 'dir')+ expect(lstatSync(agents).isSymbolicLink()).toBe(true)++ const second = await worktree.create(repository, sessionId)+ expect(second.ok).toBe(true)+ if (!second.ok)+ return+ expect(second.log.join('\n')).toContain('Copied the agent skills directory')+ expect(lstatSync(agents).isSymbolicLink()).toBe(false)+ expect(readFileSync(join(agents, 'skills', 'handle', 'SKILL.md'), 'utf8')).toBe('# handle\n')+ expect(git(first.binding.worktreePath, 'status', '--porcelain=v1')).toBe('')+ })})describe('worktree.checkout', () => {diff --git a/packages/dsh-tauri-worktree/src/host/service/worktree.ts b/packages/dsh-tauri-worktree/src/host/service/worktree.tsindex 2ab9ff7b..c953ee71 100644--- a/packages/dsh-tauri-worktree/src/host/service/worktree.ts+++ b/packages/dsh-tauri-worktree/src/host/service/worktree.ts@@ -85,7 +85,7 @@ export const worktree = defineService({return { ok: true, binding: existing, existed: true, log: [] }const repaired: Binding = { ...existing, log: [...existing.log, ...repairedLog] }await ledger.save(sessionId, repaired)- return { ok: true, binding: repaired, existed: true, log: [] }+ return { ok: true, binding: repaired, existed: true, log: repairedLog }}}diff --git a/packages/dsh-tauri-worktree/src/host/utils/dependencies.test.ts b/packages/dsh-tauri-worktree/src/host/utils/dependencies.test.tsindex 6b3f27f0..0b1dcf8f 100644--- a/packages/dsh-tauri-worktree/src/host/utils/dependencies.test.ts+++ b/packages/dsh-tauri-worktree/src/host/utils/dependencies.test.ts@@ -1,5 +1,6 @@-import { lstat, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'+import { lstat, mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'+import process from 'node:process'import { join } from 'pathe'import { afterEach, describe, expect, it } from 'vitest'import {@@ -151,14 +152,26 @@ describe('copyMissingChildren', () => {expect(await readFile(skill, 'utf8')).toBe('# handle\n')})- it('skips entries already present in the target and keeps their content', async () => {+ it('merges missing descendants into an existing target directory and keeps its files', async () => {const { project } = await createSkillsFixture()const worktree = await temporaryRoot('dsh-deps-worktree-')await mkdir(join(worktree, '.agents', 'skills'), { recursive: true })await writeFile(join(worktree, '.agents', 'skills', 'local.md'), 'local\n')- await expect(copyMissingChildren(join(project, '.agents'), join(worktree, '.agents'))).resolves.toEqual([])+ await expect(copyMissingChildren(join(project, '.agents'), join(worktree, '.agents'))).resolves.toEqual(['skills/handle'])expect(await readFile(join(worktree, '.agents', 'skills', 'local.md'), 'utf8')).toBe('local\n')+ expect(await readFile(join(worktree, '.agents', 'skills', 'handle', 'SKILL.md'), 'utf8')).toBe('# handle\n')+ })++ it('replaces a legacy symbolic link with a real copied directory', async () => {+ const { project, skill } = await createSkillsFixture()+ const worktree = await temporaryRoot('dsh-deps-worktree-')+ await symlink(join(project, '.agents'), join(worktree, '.agents'), process.platform === 'win32' ? 'junction' : 'dir')++ await expect(copyMissingChildren(join(project, '.agents'), join(worktree, '.agents'))).resolves.toEqual(['skills'])+ expect((await lstat(join(worktree, '.agents'))).isSymbolicLink()).toBe(false)+ expect(await readFile(join(worktree, '.agents', 'skills', 'handle', 'SKILL.md'), 'utf8')).toBe('# handle\n')+ expect(await readFile(skill, 'utf8')).toBe('# handle\n')})it('returns no copies when the source is absent', async () => {diff --git a/packages/dsh-tauri-worktree/src/host/utils/dependencies.ts b/packages/dsh-tauri-worktree/src/host/utils/dependencies.tsindex dd30e113..a6e153c3 100644--- a/packages/dsh-tauri-worktree/src/host/utils/dependencies.ts+++ b/packages/dsh-tauri-worktree/src/host/utils/dependencies.ts@@ -1,4 +1,4 @@-import { existsSync, readdirSync } from 'node:fs'+import { existsSync, readdirSync, statSync } from 'node:fs'import { cp, lstat, mkdir, rm, symlink } from 'node:fs/promises'import process from 'node:process'import { filter, find, get, isEmpty, isString, map, trimEnd, uniqBy } from 'lodash-es'@@ -109,24 +109,34 @@ export async function unlinkWorktreeDependencies(/*** 把源目录里缺失的条目复制进目标目录,供 `.agents` 这类被 gitignore、`git worktree add`- * 搬不过来的内容使用。目标目录不存在时即整树复制,已存在时只补缺失子项(源仓库把- * `.agents` 的一部分提交进了索引时就是后者)。+ * 搬不过来的内容使用。两侧都有的目录会继续深合并,因此「`.agents` 一部分入库、一部分被忽略」+ * 的仓库(例如跟踪 `.agents/skills/README.md` 但有未跟踪的 `.agents/skills/handle`)+ * 也能补齐缺失的子孙,同时保留目标侧已有文件。** 这里刻意用复制而不是符号链接:POSIX 上符号链接对 git 而言是「文件」,`.agents/skills/`* 这种带尾斜杠的忽略规则匹配不到它,工作树会多出一条未跟踪记录 `?? .agents`,- * 既污染状态,又会在检出时被判为「存在未跟踪改动」而卡死。复制出的真实目录与源仓库- * 忽略语义完全一致,平台无关。+ * 既污染状态,又会在检出时被判为「存在未跟踪改动」而卡死。目标侧遗留的链接会被换成真实目录,+ * 让重复创建能把旧实现留下的工作树修回来。*/export async function copyMissingChildren(sourceDirectory: string, targetDirectory: string): Promise<string[]> {- if (!existsSync(sourceDirectory) || await isSymbolicLink(targetDirectory))+ if (!existsSync(sourceDirectory))return []+ if (await isSymbolicLink(targetDirectory))+ await rm(targetDirectory, { recursive: false, force: true })await mkdir(targetDirectory, { recursive: true })const copied: string[] = []for (const name of readdirSync(sourceDirectory)) {const source = resolve(sourceDirectory, name)const target = resolve(targetDirectory, name)- if (await pathExists(target))+ if (await isSymbolicLink(target))+ await rm(target, { recursive: false, force: true })+ if (existsSync(target)) {+ if (isDirectory(source) && isDirectory(target)) {+ const nested = await copyMissingChildren(source, target)+ copied.push(...nested.map(child => `${name}/${child}`))+ }continue+ }try {await cp(source, target, { recursive: true })copied.push(name)@@ -147,6 +157,15 @@ async function isSymbolicLink(path: string): Promise<boolean> {}}+function isDirectory(path: string): boolean {+ try {+ return statSync(path).isDirectory()+ }+ catch {+ return false+ }+}+async function pathExists(path: string): Promise<boolean> {try {await lstat(path)