DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(turnrewind): close the three legacy review debts
yingtianlan17230289a5c2
diff --git a/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js b/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.jsindex 4f4887a0..bb827147 100644--- a/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js+++ b/plugins/dsh-tauri-turnrewind/lib/core/git-snapshot.js@@ -73,17 +73,17 @@ export function runGit(repoDir, workspaceDir, args, extraEnv = {}, maxBytes = MAchild.on('close', (code, signal) => {if (settled)return- settled = true- clearTimeout(timeout)const stdout = Buffer.concat(chunks)// A clean exit is the only path that resolves (see gitExitIsClean).// Our own timeout kill already settled above, so anything unclean// here is an external kill with truncated output.if (!gitExitIsClean(code, signal)) {const detail = Buffer.concat(errors).toString('utf8').trim() || stdout.toString('utf8').trim() || (signal ? `killed by ${signal}` : `exit ${code}`)- rejectPromise(new Error(`TURNREWIND_GIT_FAILED: ${detail}`))+ fail(new Error(`TURNREWIND_GIT_FAILED: ${detail}`))return}+ settled = true+ clearTimeout(timeout)resolvePromise(stdout)})})@@ -194,7 +194,8 @@ async function ensureRepository(store) {clearTimeout(timeout)if (!gitExitIsClean(code, signal)) {const detail = Buffer.concat(errors).toString('utf8').trim() || (signal ? `killed by ${signal}` : `exit ${code}`)- rejectPromise(new Error(`TURNREWIND_GIT_FAILED: ${detail}`))+ const code1 = signal ? 'TURNREWIND_GIT_FAILED' : 'TURNREWIND_GIT_INIT'+ rejectPromise(new Error(`${code1}: ${detail}`))return}resolvePromise()diff --git a/plugins/dsh-tauri-turnrewind/lib/core/ledger.js b/plugins/dsh-tauri-turnrewind/lib/core/ledger.jsindex 6d1f1f20..d892dc77 100644--- a/plugins/dsh-tauri-turnrewind/lib/core/ledger.js+++ b/plugins/dsh-tauri-turnrewind/lib/core/ledger.js@@ -149,20 +149,6 @@ export function createPendingPlan(db, plan) {}}-export function getPendingPlan(db, planId, sessionId, workspaceKey) {- const row = db.prepare(`- SELECT * FROM pending_plans- WHERE plan_id = ? AND session_id = ? AND workspace_key = ? AND status = 'pending'- `).get(planId, sessionId, workspaceKey)- if (row === undefined)- return undefined- if (row.expires_at < new Date().toISOString()) {- db.prepare('DELETE FROM pending_plans WHERE plan_id = ? AND status = \'pending\'').run(planId)- return undefined- }- return { turnId: row.turn_id, paths: JSON.parse(row.paths_json), createdAt: row.created_at }-}-/*** Atomically move one pending plan to `applying` so concurrent confirm/cancel* calls cannot interleave: the conditional UPDATE is serialized by SQLite, so@@ -214,13 +200,6 @@ export function getPendingPlanRow(db, planId) {return { ...row, paths: JSON.parse(row.paths_json) }}-export function deletePendingPlan(db, planId, sessionId, workspaceKey) {- const result = db.prepare(`- DELETE FROM pending_plans WHERE plan_id = ? AND session_id = ? AND workspace_key = ?- `).run(planId, sessionId, workspaceKey)- return result.changes > 0-}-/** Dismissal from the ✕ button: workspace key is unknown client-side. */export function markPendingPlanCancelled(db, planId, sessionId) {const result = db.prepare(`diff --git a/plugins/dsh-tauri-turnrewind/lib/core/maintenance.js b/plugins/dsh-tauri-turnrewind/lib/core/maintenance.jsindex 8d0a97df..d6542d89 100644--- a/plugins/dsh-tauri-turnrewind/lib/core/maintenance.js+++ b/plugins/dsh-tauri-turnrewind/lib/core/maintenance.js@@ -29,12 +29,14 @@ export function purgeWorkspace(rootDir, workspaceDir) {db.exec('BEGIN')const operations = db.prepare('DELETE FROM operations WHERE target_turn_id IN (SELECT turn_id FROM turns WHERE workspace_key = ?)').run(workspaceIdentity)const notices = db.prepare('DELETE FROM rewind_notices WHERE workspace_key = ?').run(workspaceIdentity)+ const plans = db.prepare('DELETE FROM pending_plans WHERE workspace_key = ?').run(workspaceIdentity)const turns = db.prepare('DELETE FROM turns WHERE workspace_key = ?').run(workspaceIdentity)const workspaces = db.prepare('DELETE FROM workspaces WHERE workspace_key = ?').run(workspaceIdentity)db.exec('COMMIT')summary.ledger = {operations: operations.changes,notices: notices.changes,+ plans: plans.changes,turns: turns.changes,workspaces: workspaces.changes,}diff --git a/plugins/dsh-tauri-turnrewind/lib/index.js b/plugins/dsh-tauri-turnrewind/lib/index.jsindex 3945edca..76e0c53a 100644--- a/plugins/dsh-tauri-turnrewind/lib/index.js+++ b/plugins/dsh-tauri-turnrewind/lib/index.js@@ -525,8 +525,11 @@ async function executeUndoRestore(runtime, params) {let rollbackError = nulltry {// `beforeRef` is the state immediately before this operation. Restore every- // touched path from it so a mid-operation error does not leave a partial undo.- for (const path of paths) await restorePath(runtime.store, beforeRef, path)+ // path this operation actually touched - with --skip-conflicts the skipped+ // conflicted files were never written, so rolling them back here would+ // overwrite the human edits the user explicitly chose to keep.+ const rollbackPaths = skipConflicts ? entries.filter(entry => !entry.conflict).map(entry => entry.path) : paths+ for (const path of rollbackPaths) await restorePath(runtime.store, beforeRef, path)settleOperation(runtime.db, operationId, 'rolled_back', error)}catch (rollbackFailure) {diff --git a/plugins/dsh-tauri-turnrewind/test/maintenance.test.js b/plugins/dsh-tauri-turnrewind/test/maintenance.test.jsindex 1f487f39..b9fc4405 100644--- a/plugins/dsh-tauri-turnrewind/test/maintenance.test.js+++ b/plugins/dsh-tauri-turnrewind/test/maintenance.test.js@@ -5,7 +5,7 @@ import { tmpdir } from 'node:os'import { join, resolve } from 'node:path'import { it } from 'vitest'import { captureSnapshot, createSnapshotStore, workspaceHash, workspaceKey } from '../lib/core/git-snapshot.js'-import { createOperation, getTurn, insertTurn, openLedger, queueRewindNotice, registerWorkspace, settleTurn } from '../lib/core/ledger.js'+import { createOperation, createPendingPlan, getTurn, insertTurn, openLedger, queueRewindNotice, registerWorkspace, settleTurn } from '../lib/core/ledger.js'import { purgeWorkspace } from '../lib/core/maintenance.js'import { commitAll, gitOutput, initGitWorkspace } from './git-test-utils.js'@@ -46,7 +46,7 @@ it('purges ledger rows and the snapshot repository for one workspace', async ()const summary = purgeWorkspace(root, workspace)assert.equal(summary.repoExisted, true)- assert.deepEqual(summary.ledger, { operations: 1, notices: 1, turns: 1, workspaces: 1 })+ assert.deepEqual(summary.ledger, { operations: 1, notices: 1, plans: 0, turns: 1, workspaces: 1 })assert.equal(existsSync(repoDir), false)const verify = openLedger(root)@@ -62,7 +62,7 @@ it('purges ledger rows and the snapshot repository for one workspace', async ()const repeat = purgeWorkspace(root, workspace)assert.equal(repeat.repoExisted, false)- assert.deepEqual(repeat.ledger, { operations: 0, notices: 0, turns: 0, workspaces: 0 })+ assert.deepEqual(repeat.ledger, { operations: 0, notices: 0, plans: 0, turns: 0, workspaces: 0 })}finally {await rm(root, { recursive: true, force: true })@@ -101,7 +101,7 @@ it('purges only turnrewind data; the user repository and other workspaces stay iconst summary = purgeWorkspace(dataRoot, userProject)assert.equal(summary.repoExisted, true)- assert.deepEqual(summary.ledger, { operations: 0, notices: 0, turns: 1, workspaces: 1 })+ assert.deepEqual(summary.ledger, { operations: 0, notices: 0, plans: 0, turns: 1, workspaces: 1 })assert.equal(existsSync(userStore.repoDir), false)// The user's repository is completely untouched: .git directory, HEAD,@@ -127,3 +127,41 @@ it('purges only turnrewind data; the user repository and other workspaces stay iawait rm(root, { recursive: true, force: true })}})++it('purges pending plans bound to the workspace', async () => {+ const root = await mkdtemp(join(tmpdir(), 'turnrewind-purge-plans-'))+ const workspace = join(root, 'ws')+ try {+ await initGitWorkspace(workspace)+ await writeFile(join(workspace, 'a.txt'), 'a')+ const db = openLedger(root)+ createPendingPlan(db, {+ sessionId: 'session',+ workspaceKey: workspaceKey(workspace),+ turnId: 'session:1',+ paths: ['a.txt'],+ })+ createPendingPlan(db, {+ sessionId: 'session',+ workspaceKey: workspaceKey(join(root, 'other')),+ turnId: 'session:2',+ paths: ['b.txt'],+ })+ db.close()++ const summary = purgeWorkspace(root, workspace)+ assert.deepEqual(summary.ledger, { operations: 0, notices: 0, plans: 1, turns: 0, workspaces: 0 })++ const verify = openLedger(root)+ try {+ const remaining = verify.prepare('SELECT workspace_key FROM pending_plans').all().map(row => row.workspace_key)+ assert.deepEqual(remaining, [workspaceKey(join(root, 'other'))])+ }+ finally {+ verify.close()+ }+ }+ finally {+ await rm(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 300 })+ }+})