DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): rmdirSync for the empty-directory restore branch, pin root/dir refusals in tests
yingtianlanc6db40512654
diff --git a/packages/dsh-tauri-turnrewind-ts/src/host/service/git-snapshot.ts b/packages/dsh-tauri-turnrewind-ts/src/host/service/git-snapshot.tsindex 26118a12..8edfbf77 100644--- a/packages/dsh-tauri-turnrewind-ts/src/host/service/git-snapshot.ts+++ b/packages/dsh-tauri-turnrewind-ts/src/host/service/git-snapshot.ts@@ -32,6 +32,7 @@ import {readdirSync,readFileSync,renameSync,+ rmdirSync,rmSync,writeFileSync,} from 'node:fs'@@ -702,7 +703,10 @@ export async function restorePath(store: SnapshotStore, commit: string, path: stif (contents.length > 0)throw new Error(`TURNREWIND_UNSUPPORTED_TARGET: ${path} is now a non-empty directory; undo will not recursively delete it (remove it manually if intended)`)assertSafePath(store.workspaceDir, path)- rmSync(target, { force: true })+ // rmdirSync only succeeds on an empty directory: rmSync without+ // recursive throws ERR_FS_EISDIR, and with recursive a file planted+ // between readdir and the delete would be destroyed with the tree.+ rmdirSync(target)}else {assertSafePath(store.workspaceDir, path)diff --git a/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.js b/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.jsindex 8ea8c698..9c79ea79 100644--- a/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.js+++ b/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.js@@ -275,6 +275,56 @@ it('rejects paths outside the workspace', async () => {}})+it('refuses to restore or inspect the workspace root itself', async () => {+ const root = await mkdtemp(join(tmpdir(), 'turnrewind-root-test-'))+ const workspace = join(root, 'workspace')+ try {+ await initGitWorkspace(workspace)+ await writeFile(join(workspace, 'a.txt'), 'one')+ const store = createSnapshotStore(join(root, 'data'), workspace)+ const snapshot = await captureSnapshot(store, 'refs/turnrewind/root-ref', 'snap')++ // '.' normalizes to the workspace root; a restore there would delete the+ // whole workspace including .git. Both disk-touching entries must refuse.+ await assert.rejects(restorePath(store, snapshot.commit, '.'), /TURNREWIND_PATH_ESCAPE/)+ assert.throws(() => currentState(workspace, '.'), /TURNREWIND_PATH_ESCAPE/)+ assert.equal(await readFile(join(workspace, 'a.txt'), 'utf8'), 'one')+ }+ finally {+ await rm(root, { recursive: true, force: true })+ }+})++it('refuses a non-empty directory at an absent path and removes an empty one', async () => {+ const root = await mkdtemp(join(tmpdir(), 'turnrewind-dir-test-'))+ const workspace = join(root, 'workspace')+ try {+ await initGitWorkspace(workspace)+ await writeFile(join(workspace, 'a.txt'), 'one')+ const store = createSnapshotStore(join(root, 'data'), workspace)+ const before = await captureSnapshot(store, 'refs/turnrewind/dir-before', 'before')++ // The turn created a file that the human later replaced by a directory+ // holding unrelated files: undo must not recursively delete that tree.+ await mkdir(join(workspace, 'foo'))+ await writeFile(join(workspace, 'foo', 'user-file.txt'), 'keep me')+ await assert.rejects(+ restorePath(store, before.commit, 'foo'),+ /TURNREWIND_UNSUPPORTED_TARGET.*non-empty directory/u,+ )+ assert.equal(await readFile(join(workspace, 'foo', 'user-file.txt'), 'utf8'), 'keep me')++ // An empty directory holds nothing to lose: the restore removes it+ // (regression pin — rmSync without directory semantics throws EISDIR).+ await mkdir(join(workspace, 'bar'))+ assert.deepEqual(await restorePath(store, before.commit, 'bar'), { path: 'bar', result: 'removed' })+ await assert.rejects(stat(join(workspace, 'bar')), { code: 'ENOENT' })+ }+ finally {+ await rm(root, { recursive: true, force: true })+ }+})+it('accepts Git worktrees and rejects ordinary directories', async () => {const root = await mkdtemp(join(tmpdir(), 'turnrewind-probe-'))const workspace = join(root, 'ws')