DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
test(turnrewind): legacy-schema migration replay, darwin case-fold, CI matrix job
yingtianlanc75acd665494
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 92fc3205..87a2981c 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -69,6 +69,40 @@ jobs:- name: Unit testrun: pnpm run test -- --run+ # turnrewind 插件(packages/dsh-tauri-turnrewind-ts):测试自包含(mock 宿主),+ # 可以在三个发布平台上原生运行——POSIX mode 恢复、symlink/junction、大小写+ # 折叠这些分支只有对应 OS 才真正执行到。+ turnrewind:+ name: Turn rewind plugin (${{ matrix.os }})+ needs: pre_job+ if: ${{ needs.pre_job.outputs.should_skip != 'true' }}+ strategy:+ fail-fast: false+ matrix:+ os: [windows-latest, ubuntu-latest, macos-latest]+ runs-on: ${{ matrix.os }}+ steps:+ - name: Checkout repository+ uses: actions/checkout@v7++ - name: Setup Node.js and pnpm+ uses: ./.github/actions/setup-node-pnpm++ - name: Install dependencies+ run: pnpm install --frozen-lockfile++ - name: Type check+ run: pnpm --filter dsh-tauri-turnrewind typecheck++ - name: Lint+ run: pnpm --filter dsh-tauri-turnrewind exec eslint src test++ - name: Unit test+ run: pnpm --filter dsh-tauri-turnrewind test++ - name: Build+ run: pnpm --filter dsh-tauri-turnrewind build+# Rust 单元测试(应用主体逻辑):# 这是 CI 此前完全缺失的部分。仓库里存在大量 #[cfg(windows)] 的 Windows 专属# 代码(win_spawn / win_inspector / cli shim / path / MSI 版本处理),只能在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 b75f95ff..bac1f93c 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@@ -346,12 +346,13 @@ function assertSafePath(workspaceDir: string, path: string): string {/*** Canonical workspace identity shared by the ledger key, the snapshot repo- * hash and maintenance purges: case-folded only on case-insensitive platforms,- * so Unix paths differing in case stay distinct while Windows paths unify.+ * hash and maintenance purges: case-folded on case-insensitive platforms+ * (Windows NTFS, macOS APFS default) so one directory cannot spawn two+ * snapshot domains; Linux stays byte-exact. `platform` is injectable for tests.*/-export function workspaceKey(workspaceDir: string): string {+export function workspaceKey(workspaceDir: string, platform: string = process.platform): string {const normalized = resolve(workspaceDir)- return process.platform === 'win32' ? normalized.toLowerCase() : normalized+ return platform === 'win32' || platform === 'darwin' ? normalized.toLowerCase() : normalized}export function workspaceHash(workspaceDir: string): string {diff --git a/packages/dsh-tauri-turnrewind-ts/src/host/service/ledger.ts b/packages/dsh-tauri-turnrewind-ts/src/host/service/ledger.tsindex df0d8e70..d9e3e5ad 100644--- a/packages/dsh-tauri-turnrewind-ts/src/host/service/ledger.ts+++ b/packages/dsh-tauri-turnrewind-ts/src/host/service/ledger.ts@@ -339,7 +339,11 @@ export function claimRewindNotices(db: Ledger, sessionId: string, workspaceKey:}))}catch (error) {- db.exec('ROLLBACK')+ // ROLLBACK 自身失败(如 BEGIN 未生效)不能掩盖原始错误。+ try {+ db.exec('ROLLBACK')+ }+ catch { /* no active transaction */ }throw error}}diff --git a/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.js b/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.jsindex 846e2931..c8e9f06c 100644--- a/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.js+++ b/packages/dsh-tauri-turnrewind-ts/test/git-snapshot.test.js@@ -3,7 +3,7 @@ import { chmod, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from 'nimport { tmpdir } from 'node:os'import { join } from 'pathe'import { it } from 'vitest'-import { captureSnapshot, classifyPathChange, createSnapshotStore, currentState, diffAgainstDisk, gitAvailable, probeWorkspace, restorePath, snapshotDiff, snapshotFileDiff, stateAt } from '../src/host/service/git-snapshot'+import { captureSnapshot, classifyPathChange, createSnapshotStore, currentState, diffAgainstDisk, gitAvailable, probeWorkspace, restorePath, snapshotDiff, snapshotFileDiff, stateAt, workspaceKey } from '../src/host/service/git-snapshot'import { completeUndoTransaction, createOperation, getLatestTurn, insertTurn, openLedger, settleInterruptedTurn, settleTurn } from '../src/host/service/ledger'import { initGitWorkspace } from './git-test-utils.js'@@ -404,3 +404,11 @@ it('probes git availability once per process', async () => {assert.equal(first, second)assert.equal(typeof first, 'boolean')})++it('folds path case on case-insensitive platforms only', () => {+ // Windows and macOS (APFS default) treat the two spellings as one+ // workspace; Linux keeps them distinct.+ assert.equal(workspaceKey('C:\Proj\One', 'win32'), workspaceKey('c:\proj\one', 'win32'))+ assert.equal(workspaceKey('/Users/dev/Proj', 'darwin'), workspaceKey('/Users/dev/proj', 'darwin'))+ assert.notEqual(workspaceKey('/home/dev/Proj', 'linux'), workspaceKey('/home/dev/proj', 'linux'))+})diff --git a/packages/dsh-tauri-turnrewind-ts/test/migration.test.js b/packages/dsh-tauri-turnrewind-ts/test/migration.test.jsnew file mode 100644index 00000000..c589b40d--- /dev/null+++ b/packages/dsh-tauri-turnrewind-ts/test/migration.test.js@@ -0,0 +1,132 @@+import assert from 'node:assert/strict'+import { mkdtemp, rm } from 'node:fs/promises'+import { tmpdir } from 'node:os'+import { DatabaseSync } from 'node:sqlite'+import { join } from 'pathe'+import { it } from 'vitest'+import { claimRewindNotices, createPendingPlan, getPendingPlanStatus, hasNeedsRecoveryWorkspace, openLedger } from '../src/host/service/ledger'++/**+ * 迁移重放:用 git 历史上最早的账本 schema(pending_plans 无+ * status/result_text/before_ref/after_ref/paths_digest,rewind_notices 无+ * turns_json/kind/reason,operations 无 after_ref)构造一个"老版本遗物",+ * openLedger 必须 idempotent 地补列并让遗留数据继续工作。+ */+const LEGACY_SCHEMA = `+ CREATE TABLE workspaces (+ workspace_key TEXT PRIMARY KEY,+ workspace_path TEXT NOT NULL,+ snapshot_repo TEXT NOT NULL,+ created_at TEXT NOT NULL+ );+ CREATE TABLE turns (+ turn_id TEXT PRIMARY KEY,+ session_id TEXT NOT NULL,+ parent_turn_id TEXT,+ workspace_key TEXT NOT NULL,+ status TEXT NOT NULL,+ started_at TEXT NOT NULL,+ settled_at TEXT,+ before_ref TEXT,+ after_ref TEXT,+ reversible INTEGER NOT NULL DEFAULT 0,+ error TEXT+ );+ CREATE TABLE operations (+ operation_id TEXT PRIMARY KEY,+ kind TEXT NOT NULL,+ target_turn_id TEXT NOT NULL,+ requested_at TEXT NOT NULL,+ settled_at TEXT,+ outcome TEXT,+ before_ref TEXT,+ error TEXT+ );+ CREATE TABLE rewind_notices (+ notice_id TEXT PRIMARY KEY,+ session_id TEXT NOT NULL,+ workspace_key TEXT NOT NULL,+ target_turn_id TEXT,+ paths_json TEXT NOT NULL DEFAULT '[]',+ status TEXT NOT NULL DEFAULT 'pending',+ created_at TEXT NOT NULL,+ claimed_at TEXT+ );+ CREATE TABLE pending_plans (+ plan_id TEXT PRIMARY KEY,+ session_id TEXT NOT NULL,+ workspace_key TEXT NOT NULL,+ turn_id TEXT NOT NULL,+ paths_json TEXT NOT NULL,+ created_at TEXT NOT NULL,+ expires_at TEXT NOT NULL+ );+ CREATE INDEX turns_session_idx ON turns(session_id, started_at);+`++/** Windows may hold freshly closed sqlite sidecar files briefly: retry, then give up quietly. */+async function cleanupDir(root) {+ for (let attempt = 0; ; attempt += 1) {+ try {+ await rm(root, { recursive: true, force: true })+ return+ }+ catch (error) {+ if (attempt >= 4 || !['EBUSY', 'EPERM', 'ENOTEMPTY'].includes(error.code))+ return+ await new Promise(resolve => setTimeout(resolve, 150))+ }+ }+}++it('upgrades a legacy ledger in place and keeps every row working', async () => {+ const root = await mkdtemp(join(tmpdir(), 'turnrewind-migration-'))+ try {+ // Build the pre-migration database with representative rows.+ const legacy = new DatabaseSync(join(root, 'ledger.sqlite'))+ legacy.exec(LEGACY_SCHEMA)+ legacy.exec(`+ INSERT INTO workspaces VALUES ('c:\\legacy', 'C:\\Legacy', 'repo.git', '2026-01-01T00:00:00.000Z');+ INSERT INTO turns VALUES ('session:1', 'session', NULL, 'c:\\legacy', 'settled', '2026-01-01T00:00:00.000Z', '2026-01-01T00:01:00.000Z', 'refs/turnrewind/turn-1-before', 'refs/turnrewind/turn-1-after', 1, NULL);+ INSERT INTO operations VALUES ('op-legacy', 'undo', 'session:1', '2026-01-01T00:02:00.000Z', NULL, 'applying', 'refs/turnrewind/op-before', NULL);+ INSERT INTO rewind_notices VALUES ('notice-legacy', 'session', 'c:\\legacy', 'session:1', '[]', 'pending', '2026-01-01T00:03:00.000Z', NULL);+ INSERT INTO pending_plans VALUES ('plan-legacy', 'session', 'c:\\legacy', 'session:1', '["a.txt"]', '2026-01-01T00:04:00.000Z', '2026-01-01T00:09:00.000Z');+ `)+ legacy.close()++ // Reopening runs the idempotent migrations plus the reopen sweeps.+ const db = openLedger(root)++ // The legacy applying operation is fenced exactly like a modern crash,+ // and the legacy turn is still there for the recovery panel to describe.+ assert.equal(hasNeedsRecoveryWorkspace(db, 'c:\\legacy'), true)++ // The legacy plan row survives; its past TTL is archived as expired and+ // the status poll answers from the migrated columns.+ const status = getPendingPlanStatus(db, 'plan-legacy', 'session')+ assert.equal(status?.status, 'expired')++ // A brand-new plan (with preview binding columns) writes fine.+ const freshPlan = createPendingPlan(db, {+ sessionId: 'session',+ workspaceKey: 'c:\\legacy',+ turnId: 'session:1',+ paths: ['a.txt'],+ beforeRef: 'refs/turnrewind/turn-1-before',+ afterRef: 'refs/turnrewind/turn-1-after',+ })+ assert.notEqual(freshPlan, undefined)++ // The legacy notice claims cleanly: turns_json was added with an empty+ // default and parses, paths come through verbatim.+ const notices = claimRewindNotices(db, 'session', 'c:\\legacy')+ assert.equal(notices.length, 1)+ assert.equal(notices[0].notice_id, 'notice-legacy')+ assert.deepEqual(notices[0].turns, [])+ assert.deepEqual(notices[0].paths, [])+ db.close()+ }+ finally {+ await cleanupDir(root)+ }+})