Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
test(task-copy): 真实 Git 的 worktree 用例归入 git-integration 层
Dash12a30965d623
diff --git a/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.ts b/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.tsindex fdbaa096cf..0a8e38f986 100644--- a/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.ts+++ b/apps/desktop/src/main/task-migration/__tests__/estimateWorkspace.test.ts@@ -2,9 +2,25 @@ import { expect, it, vi } from 'vitest';import fs from 'node:fs/promises';import os from 'node:os';import path from 'node:path';-import { execFileSync } from 'node:child_process';import { estimateWorkspace } from '../workspace';+// Real Git (registered worktrees) is covered in workspace.git-integration.test.ts; here every+// root is a plain directory, so the repository probe answers "not a git repository".+vi.mock('../../worktree/gitExec', async (original) => {+ const actual = await original<typeof import('../../worktree/gitExec')>();+ return {+ ...actual,+ gitExec: async (args: string[]) => {+ throw new actual.GitExecError({+ args,+ exitCode: 128,+ stderr: 'fatal: not a git repository',+ stdout: '',+ });+ },+ };+});+it('counts hidden and nested files, skips root Git metadata and does not count directories', async () => {const root = await fs.mkdtemp(path.join(os.tmpdir(), 'copy-estimate-'));try {@@ -24,42 +40,6 @@ it('counts hidden and nested files, skips root Git metadata and does not count d}});-it("skips only other tasks' registered worktrees, never other content of those folders", async () => {- const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'copy-estimate-')));- const git = (...args: string[]) =>- execFileSync('git', [- '-c',- 'user.name=t',- '-c',- 'user.email=t@localhost',- '-c',- 'commit.gpgsign=false',- '-C',- root,- ...args,- ]);- try {- await fs.writeFile(path.join(root, 'a'), 'a');- await fs.mkdir(path.join(root, '.cindy-worktrees', 'notes'), { recursive: true });- await fs.writeFile(path.join(root, '.cindy-worktrees', 'notes', 'n'), 'xy');- await fs.mkdir(path.join(root, '.xdt-worktrees', 'stale'), { recursive: true });- await fs.writeFile(path.join(root, '.xdt-worktrees', 'stale', 'old'), 'zzz');- // A plain directory excludes nothing, even with stray `.git` metadata at its root.- await fs.mkdir(path.join(root, '.git'));- expect(await estimateWorkspace(root, () => {})).toEqual({ fileCount: 3, bytes: 6 });- await fs.rm(path.join(root, '.git'), { recursive: true });- git('init', '-q');- git('add', 'a');- git('commit', '-q', '-m', 'fixture');- git('worktree', 'add', '-q', '-b', 'other', path.join('.cindy-worktrees', 'other-task'));- // Only the registered worktree is skipped; user folders beside it and an unregistered- // folder in a managed container are still project content.- expect(await estimateWorkspace(root, () => {})).toEqual({ fileCount: 3, bytes: 6 });- } finally {- await fs.rm(root, { recursive: true, force: true });- }-});-it('stops an oversized directory before statting its entries', async () => {const root = await fs.mkdtemp(path.join(os.tmpdir(), 'copy-estimate-'));const lstat = vi.spyOn(fs, 'lstat');diff --git a/apps/desktop/src/main/task-migration/__tests__/service.test.ts b/apps/desktop/src/main/task-migration/__tests__/service.test.tsindex b48f6ff2d7..de45440be2 100644--- a/apps/desktop/src/main/task-migration/__tests__/service.test.ts+++ b/apps/desktop/src/main/task-migration/__tests__/service.test.ts@@ -2,7 +2,6 @@ vi.mock('../../mcp-integrations/moveSession', () => ({ moveSessionProjectFromHosimport { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import fs from 'node:fs/promises';import syncFs from 'node:fs';-import { execFileSync } from 'node:child_process';import path from 'node:path';import os from 'node:os';import { createHash } from 'node:crypto';@@ -43,6 +42,7 @@ const state = vi.hoisted(() => ({workers: [] as string[],estimateLimits: [] as number[],timeoutAction: '' as string,+ exclusions: [] as string[],}));vi.mock('../../localDb/ipc/sessionCreatedBroadcast', () => ({emitSessionCreated: (id: string) => state.created(id),@@ -209,8 +209,7 @@ vi.mock('../../session-share/sessionShareImport', () => ({vi.mock('../workspace', async (original) => ({isExcludedFromWorkspace: (await original<typeof import('../workspace')>()).isExcludedFromWorkspace,- managedWorktreeExclusions: (await original<typeof import('../workspace')>())- .managedWorktreeExclusions,+ managedWorktreeExclusions: async () => state.exclusions,estimateWorkspace: async (_root: string, check: () => void, maxFiles: number) => {state.estimateLimits.push(maxFiles);check();@@ -273,6 +272,7 @@ describe('resumable cross-computer copy', () => {state.workers = [];state.estimateLimits = [];state.timeoutAction = '';+ state.exclusions = [];const cwd = path.join(state.root, 'shared');await fs.mkdir(cwd);await fs.writeFile(path.join(cwd, 'draft'), 'original');@@ -531,23 +531,10 @@ describe('resumable cross-computer copy', () => {it('ignores tasks running in other registered worktrees under the copied root', async () => {const rows = state.rows.get('A')!;const cwd = rows.get('fork')!.workingDir as string;- const git = (...args: string[]) =>- execFileSync('git', [- '-c',- 'user.name=t',- '-c',- 'user.email=t@localhost',- '-c',- 'commit.gpgsign=false',- '-C',- cwd,- ...args,- ]);- git('init', '-q');- git('add', 'draft');- git('commit', '-q', '-m', 'fixture');const managed = path.join(cwd, '.cindy-worktrees', 'other');- git('worktree', 'add', '-q', '-b', 'other', managed);+ await fs.mkdir(managed, { recursive: true });+ // Git's worktree registry is covered by the integration tier; inject its verdict here.+ state.exclusions = [path.join('.cindy-worktrees', 'other')];rows.get('sibling')!.workingDir = managed;state.siblingRunning = true;await start();diff --git a/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts b/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.tsindex 8bca69cd65..d27b5c6274 100644--- a/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts+++ b/apps/desktop/src/main/task-migration/__tests__/workspace.git-integration.test.ts@@ -33,7 +33,12 @@ vi.mock('../../worktree/gitExec', async (original) => {}),};});-import { snapshotWorkspace, restoreWorkspace, validateWorkspaceEntries } from '../workspace';+import {+ estimateWorkspace,+ snapshotWorkspace,+ restoreWorkspace,+ validateWorkspaceEntries,+} from '../workspace';import { inventoryWorktree } from '../../worktree/recoveryArchiveIO';const exec = promisify(execFile);@@ -142,6 +147,33 @@ describe('cross-machine project snapshots', () => {await fs.readFile(path.join(source, '.cindy-worktrees', 'other-task', 'file'), 'utf8'),).toBe('not mine\n');});+ it("counts only project content, not other tasks' registered worktrees", async () => {+ await fs.writeFile(path.join(source, 'a'), 'a');+ await fs.mkdir(path.join(source, '.cindy-worktrees', 'notes'), { recursive: true });+ await fs.writeFile(path.join(source, '.cindy-worktrees', 'notes', 'n'), 'xy');+ await fs.mkdir(path.join(source, '.xdt-worktrees', 'stale'), { recursive: true });+ await fs.writeFile(path.join(source, '.xdt-worktrees', 'stale', 'old'), 'zzz');+ // A plain directory excludes nothing, even with stray `.git` metadata at its root.+ await fs.mkdir(path.join(source, '.git'));+ expect(await estimateWorkspace(source, () => {})).toEqual({ fileCount: 3, bytes: 6 });+ await fs.rm(path.join(source, '.git'), { recursive: true });+ await git(source, 'init', '-b', 'main');+ await git(source, 'config', 'user.name', 'Migration test');+ await git(source, 'config', 'user.email', 'migration@localhost');+ await git(source, 'add', 'a');+ await git(source, 'commit', '-m', 'fixture');+ await git(+ source,+ 'worktree',+ 'add',+ '-b',+ 'other',+ path.join('.cindy-worktrees', 'other-task'),+ );+ // Only the registered worktree is skipped; user folders beside it and an unregistered+ // folder in a managed container are still project content.+ expect(await estimateWorkspace(source, () => {})).toEqual({ fileCount: 3, bytes: 6 });+ });it('keeps same-named folders of a plain directory', async () => {await fs.mkdir(path.join(source, '.cindy-worktrees'));await fs.writeFile(path.join(source, '.cindy-worktrees', 'notes'), 'user file\n');diff --git a/docs/product-rules/task-device-migration.md b/docs/product-rules/task-device-migration.mdindex 77f23d7273..57f3c1cb44 100644--- a/docs/product-rules/task-device-migration.md+++ b/docs/product-rules/task-device-migration.md@@ -28,7 +28,7 @@5. 确认页使用接收电脑名称或“本机”,展示项目文件数量与复制前估算大小(含隐藏/忽略文件,整组共享目录去重)。Git 历史、任务对话与附件另行复制,不计入项目文件统计;统计完成前不能开始复制。`copyEstimate` 能力存在时才调用 `estimate`;旧源端无法统计时明确提示连接/版本检查,不开始复制。- 统计在任务所在电脑上按 3 分钟截止(本机任务同样适用),超时时提示项目文件过多,不提示连接/版本;项目文件超过 50 万个时提前停止统计,+ 统计在任务所在电脑上按 3 分钟截止(本机任务同样适用;文件系统调用本身卡住时无法中断,属已知边界),超时时提示项目文件过多,不提示连接/版本;项目文件超过 50 万个时提前停止统计,提示改为复制文件更少的项目,不开始复制。该上限只是确认页的准入检查,复制本身仍不设总量上限。6. 复制全程保留弹窗,不提供隐藏到后台的入口;准备阶段显示不定进度,发送阶段显示本机上传字节进度及平均速度,明确接收尚未完成。OSS 进度计 HTTP 请求体已提交字节(可能仍在缓冲),peer 计分段确认字节,不作为接收完成凭据。