sillyspec 3.20.2 → 3.20.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/.claude/skills/sillyspec-archive/SKILL.md +1 -5
  2. package/.claude/skills/sillyspec-auto/SKILL.md +2 -8
  3. package/.claude/skills/sillyspec-brainstorm/SKILL.md +1 -28
  4. package/.claude/skills/sillyspec-commit/SKILL.md +3 -4
  5. package/.claude/skills/sillyspec-continue/SKILL.md +4 -5
  6. package/.claude/skills/sillyspec-doctor/SKILL.md +3 -12
  7. package/.claude/skills/sillyspec-execute/SKILL.md +2 -15
  8. package/.claude/skills/sillyspec-explore/SKILL.md +1 -14
  9. package/.claude/skills/sillyspec-plan/SKILL.md +36 -5
  10. package/.claude/skills/sillyspec-propose/SKILL.md +0 -4
  11. package/.claude/skills/sillyspec-quick/SKILL.md +1 -5
  12. package/.claude/skills/sillyspec-resume/SKILL.md +66 -23
  13. package/.claude/skills/sillyspec-scan/SKILL.md +1 -5
  14. package/.claude/skills/sillyspec-state/SKILL.md +8 -8
  15. package/.claude/skills/sillyspec-status/SKILL.md +1 -5
  16. package/.claude/skills/sillyspec-verify/SKILL.md +1 -5
  17. package/.claude/skills/sillyspec-workspace/SKILL.md +3 -11
  18. package/.sillyspec/changes/archive/2026-04-08-derive-state/design.md +97 -0
  19. package/.sillyspec/changes/archive/2026-04-08-derive-state/plan.md +51 -0
  20. package/.sillyspec/changes/archive/2026-04-08-derive-state/proposal.md +29 -0
  21. package/.sillyspec/changes/archive/2026-04-08-derive-state/requirements.md +34 -0
  22. package/.sillyspec/changes/archive/2026-04-08-derive-state/tasks.md +13 -0
  23. package/.sillyspec/changes/archive/2026-04-08-derive-state/verify-result.md +43 -0
  24. package/.sillyspec/changes/auto-mode/design.md +50 -0
  25. package/.sillyspec/changes/auto-mode/proposal.md +19 -0
  26. package/.sillyspec/changes/auto-mode/requirements.md +21 -0
  27. package/.sillyspec/changes/auto-mode/tasks.md +7 -0
  28. package/.sillyspec/changes/brainstorm-archive/2026-04-05-dashboard-design.md +206 -0
  29. package/.sillyspec/changes/brainstorm-archive/2026-04-05-unified-docs-design.md +199 -0
  30. package/.sillyspec/changes/dashboard/design.md +219 -0
  31. package/.sillyspec/changes/dashboard/design.md.braindraft +206 -0
  32. package/.sillyspec/changes/run-command-design/design.md +1230 -0
  33. package/.sillyspec/changes/unified-docs-design/design.md +199 -0
  34. package/.sillyspec/docs/sillyspec/scan/.gitkeep +0 -0
  35. package/.sillyspec/knowledge/INDEX.md +8 -0
  36. package/.sillyspec/knowledge/uncategorized.md +3 -0
  37. package/.sillyspec/plans/2026-04-05-dashboard.md +737 -0
  38. package/.sillyspec/projects/sillyspec.yaml +3 -0
  39. package/README.md +11 -13
  40. package/SKILL.md +40 -44
  41. package/dist/steps/brainstorm/01-load-context.md +30 -0
  42. package/dist/steps/brainstorm/02-reuse-check.md +6 -0
  43. package/dist/steps/brainstorm/03-prototype-analysis.md +11 -0
  44. package/dist/steps/brainstorm/04-module-split.md +23 -0
  45. package/dist/steps/brainstorm/05-dialog-explore.md +8 -0
  46. package/dist/steps/brainstorm/06-propose-approaches.md +3 -0
  47. package/dist/steps/brainstorm/07-present-design.md +3 -0
  48. package/dist/steps/brainstorm/08-write-design.md +21 -0
  49. package/dist/steps/brainstorm/09-self-review.md +15 -0
  50. package/dist/steps/brainstorm/10-user-confirm.md +3 -0
  51. package/dist/steps/brainstorm/11-output-spec.md +7 -0
  52. package/dist/steps/brainstorm/manifest.yaml +26 -0
  53. package/dist/steps/execute/01-load-context.md +41 -0
  54. package/dist/steps/execute/02-scan-conventions.md +47 -0
  55. package/dist/steps/execute/03-skill-mcp.md +19 -0
  56. package/dist/steps/execute/04-assign-task.md +22 -0
  57. package/dist/steps/execute/04b-prompt-template.md +54 -0
  58. package/dist/steps/execute/05-write-test.md +7 -0
  59. package/dist/steps/execute/06-write-code.md +8 -0
  60. package/dist/steps/execute/07-run-test.md +26 -0
  61. package/dist/steps/execute/08-fix-issues.md +28 -0
  62. package/dist/steps/execute/09-next-task.md +33 -0
  63. package/dist/steps/execute/manifest.yaml +28 -0
  64. package/dist/steps/plan/01-load-context.md +22 -0
  65. package/dist/steps/plan/02-anchor-confirm.md +1 -0
  66. package/dist/steps/plan/03-expand-tasks.md +33 -0
  67. package/dist/steps/plan/04-mark-order.md +15 -0
  68. package/dist/steps/plan/05-e2e-planning.md +17 -0
  69. package/dist/steps/plan/06-self-check.md +16 -0
  70. package/dist/steps/plan/07-save.md +1 -0
  71. package/dist/steps/plan/manifest.yaml +18 -0
  72. package/dist/steps/scan/01-env-detect.md +51 -0
  73. package/dist/steps/scan/02-tech-stack.md +16 -0
  74. package/dist/steps/scan/03-conventions.md +16 -0
  75. package/dist/steps/scan/04-structure.md +19 -0
  76. package/dist/steps/scan/05-quality.md +18 -0
  77. package/dist/steps/scan/06-complete.md +49 -0
  78. package/dist/steps/scan/manifest.yaml +16 -0
  79. package/dist/steps/verify/01-load-specs.md +28 -0
  80. package/dist/steps/verify/02-check-tasks.md +1 -0
  81. package/dist/steps/verify/03-check-design.md +6 -0
  82. package/dist/steps/verify/04-run-tests.md +7 -0
  83. package/dist/steps/verify/05-e2e-tests.md +27 -0
  84. package/dist/steps/verify/05b-e2e-fix.md +33 -0
  85. package/dist/steps/verify/06-code-quality.md +25 -0
  86. package/dist/steps/verify/07-lint-check.md +27 -0
  87. package/dist/steps/verify/08-output-report.md +14 -0
  88. package/dist/steps/verify/manifest.yaml +22 -0
  89. package/package.json +1 -7
  90. package/packages/dashboard/dist/assets/{index-Bq_Z2hne.js → index-D1EVTLmc.js} +1264 -1264
  91. package/packages/dashboard/dist/assets/index-DGe8CqeP.css +1 -0
  92. package/packages/dashboard/dist/index.html +2 -2
  93. package/packages/dashboard/package-lock.json +6 -6
  94. package/packages/dashboard/server/executor.js +1 -1
  95. package/packages/dashboard/server/index.js +18 -98
  96. package/packages/dashboard/server/parser.js +71 -139
  97. package/packages/dashboard/server/watcher.js +6 -14
  98. package/packages/dashboard/src/App.vue +185 -418
  99. package/packages/dashboard/src/components/ActionBar.vue +1 -10
  100. package/packages/dashboard/src/components/CommandPalette.vue +1 -5
  101. package/packages/dashboard/src/components/DocPreview.vue +8 -105
  102. package/packages/dashboard/src/components/DocTree.vue +19 -75
  103. package/packages/dashboard/src/components/PipelineStage.vue +2 -22
  104. package/packages/dashboard/src/components/PipelineView.vue +5 -32
  105. package/packages/dashboard/src/components/ProjectOverview.vue +139 -113
  106. package/packages/dashboard/src/components/StageBadge.vue +3 -17
  107. package/packages/dashboard/src/components/StepCard.vue +2 -7
  108. package/packages/dashboard/src/composables/useDashboard.js +0 -28
  109. package/src/derive.js +147 -0
  110. package/src/index.js +40 -688
  111. package/src/init.js +63 -119
  112. package/src/migrate.js +7 -7
  113. package/src/progress.js +248 -1474
  114. package/src/run.js +302 -3008
  115. package/src/setup.js +64 -2
  116. package/src/stages/archive.js +17 -123
  117. package/src/stages/brainstorm.js +48 -454
  118. package/src/stages/doctor.js +46 -99
  119. package/src/stages/execute.js +59 -420
  120. package/src/stages/index.js +18 -12
  121. package/src/stages/plan.js +189 -492
  122. package/src/stages/propose.js +11 -70
  123. package/src/stages/quick.js +13 -52
  124. package/src/stages/scan.js +68 -485
  125. package/src/stages/status.js +1 -1
  126. package/src/stages/verify.js +16 -203
  127. package/src/step.js +543 -0
  128. package/.claude/skills/sillyspec-knowledge/SKILL.md +0 -270
  129. package/.husky/pre-push +0 -13
  130. package/CLAUDE.md +0 -18
  131. package/docs/brainstorm-plan-contract.md +0 -64
  132. package/docs/plan-execute-contract.md +0 -123
  133. package/docs/platform-scan-protocol.md +0 -298
  134. package/docs/revision-mode.md +0 -115
  135. package/docs/sillyspec/file-lifecycle/known-implementation-gaps.md +0 -99
  136. package/docs/sillyspec/file-lifecycle/platform-workflows-sync.md +0 -218
  137. package/docs/sillyspec/file-lifecycle/stage-artifacts.md +0 -167
  138. package/docs/sillyspec/file-lifecycle/storage-and-state.md +0 -148
  139. package/docs/sillyspec/file-lifecycle/worktree-and-guard.md +0 -193
  140. package/docs/sillyspec/file-lifecycle.md +0 -125
  141. package/docs/workflow-contract-regression.md +0 -106
  142. package/docs/worktree-isolation.md +0 -252
  143. package/packages/dashboard/dist/assets/index-O2W5RV4z.css +0 -1
  144. package/packages/dashboard/dist/prototype-dashboard.html +0 -836
  145. package/packages/dashboard/dist/prototype-overview.html +0 -256
  146. package/packages/dashboard/public/prototype-dashboard.html +0 -836
  147. package/packages/dashboard/public/prototype-overview.html +0 -256
  148. package/packages/dashboard/src/components/HResizeHandle.vue +0 -48
  149. package/packages/dashboard/src/components/ProjectCard.vue +0 -187
  150. package/packages/dashboard/src/components/VResizeHandle.vue +0 -61
  151. package/packages/dashboard/src/composables/useLayout.js +0 -131
  152. package/src/brainstorm-postcheck.js +0 -158
  153. package/src/change-list.js +0 -52
  154. package/src/change-risk-profile.js +0 -352
  155. package/src/classify-change.js +0 -73
  156. package/src/constants.js +0 -70
  157. package/src/contract-matrix.js +0 -278
  158. package/src/db.js +0 -201
  159. package/src/endpoint-extractor.js +0 -315
  160. package/src/hooks/claude-pre-tool-use.cjs +0 -125
  161. package/src/hooks/worktree-guard.js +0 -761
  162. package/src/knowledge-match.js +0 -130
  163. package/src/modules.js +0 -482
  164. package/src/scan-postcheck.js +0 -383
  165. package/src/stage-contract.js +0 -700
  166. package/src/stages/brainstorm-auto.js +0 -229
  167. package/src/stages/explore.js +0 -34
  168. package/src/stages/knowledge.js +0 -498
  169. package/src/stages/plan-postcheck.js +0 -513
  170. package/src/sync.js +0 -497
  171. package/src/task-review.js +0 -346
  172. package/src/workflow.js +0 -785
  173. package/src/worktree-apply.js +0 -549
  174. package/src/worktree.js +0 -932
  175. package/templates/workflows/archive-impact.yaml +0 -79
  176. package/templates/workflows/scan-docs.yaml +0 -132
  177. package/test/brainstorm-plan-contract.test.mjs +0 -273
  178. package/test/check-syntax.mjs +0 -26
  179. package/test/cli-top-level-aliases.test.mjs +0 -174
  180. package/test/contract-artifacts.test.mjs +0 -323
  181. package/test/decision-supersede.test.mjs +0 -277
  182. package/test/knowledge-match.test.mjs +0 -231
  183. package/test/plan-execute-contract.test.mjs +0 -330
  184. package/test/plan-optimization.test.mjs +0 -572
  185. package/test/platform-artifacts.test.mjs +0 -190
  186. package/test/platform-failure-samples.test.mjs +0 -199
  187. package/test/platform-recovery-chain.test.mjs +0 -179
  188. package/test/platform-recovery.test.mjs +0 -167
  189. package/test/platform-scan-p0.test.mjs +0 -175
  190. package/test/revision-v1.test.mjs +0 -1145
  191. package/test/run-sanitize-project-name.test.mjs +0 -51
  192. package/test/run-scan-postcheck-fail.test.mjs +0 -64
  193. package/test/run-scan-project-parse.test.mjs +0 -200
  194. package/test/run-tests.mjs +0 -48
  195. package/test/scan-docs-yaml-placeholders.test.mjs +0 -84
  196. package/test/scan-knowledge.test.mjs +0 -175
  197. package/test/scan-paths.test.mjs +0 -68
  198. package/test/scan-postcheck-project-priority.test.mjs +0 -85
  199. package/test/scan-postcheck.test.mjs +0 -197
  200. package/test/scan-workflow-anyfailed-block.test.mjs +0 -52
  201. package/test/spec-dir.test.mjs +0 -206
  202. package/test/stage-contract-failed-post-check.test.mjs +0 -102
  203. package/test/stage-contract.test.mjs +0 -299
  204. package/test/stage-definitions.test.mjs +0 -39
  205. package/test/wait-gates.test.mjs +0 -501
  206. package/test/workflow-spec-base.test.mjs +0 -142
  207. package/test/worktree-guard.test.mjs +0 -136
  208. package/test/worktree-native-overlay.test.mjs +0 -188
@@ -1,136 +0,0 @@
1
- import assert from 'node:assert/strict'
2
- import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
3
- import { join } from 'node:path'
4
- import { tmpdir } from 'node:os'
5
- import { shouldBlock } from '../src/hooks/worktree-guard.js'
6
-
7
- const root = join(tmpdir(), `sillyspec-guard-test-${Date.now()}`)
8
- const changeName = '2026-06-04-guard-test'
9
- const runtimeDir = join(root, '.sillyspec', '.runtime')
10
- const registeredWorktree = join(runtimeDir, 'worktrees', changeName)
11
- const unregisteredWorktree = join(runtimeDir, 'worktrees', 'other-change')
12
-
13
- mkdirSync(registeredWorktree, { recursive: true })
14
- mkdirSync(unregisteredWorktree, { recursive: true })
15
- writeFileSync(join(runtimeDir, 'gate-status.json'), JSON.stringify({
16
- stage: 'execute',
17
- changes: [changeName],
18
- updatedAt: new Date().toISOString(),
19
- }, null, 2))
20
- writeFileSync(join(registeredWorktree, 'meta.json'), JSON.stringify({
21
- changeName,
22
- worktreePath: registeredWorktree,
23
- mode: 'worktree',
24
- }, null, 2))
25
-
26
- try {
27
- assert.equal(
28
- shouldBlock({ tool: 'Write', filePath: join(registeredWorktree, 'src', 'ok.js'), cwd: root }).blocked,
29
- false,
30
- 'registered worktree writes should be allowed'
31
- )
32
-
33
- assert.equal(
34
- shouldBlock({ tool: 'Bash', command: 'npm run build', cwd: registeredWorktree }).blocked,
35
- false,
36
- 'bash commands from a registered worktree cwd should be allowed'
37
- )
38
-
39
- assert.equal(
40
- shouldBlock({ tool: 'Write', filePath: join(unregisteredWorktree, 'src', 'blocked.js'), cwd: root }).blocked,
41
- true,
42
- 'unregistered worktree storage writes should be blocked'
43
- )
44
-
45
- assert.equal(
46
- shouldBlock({ tool: 'Write', filePath: join(root, '.sillyspec', 'docs', 'note.md'), cwd: root }).blocked,
47
- false,
48
- 'ordinary .sillyspec docs should remain writable'
49
- )
50
-
51
- writeFileSync(join(runtimeDir, 'gate-status.json'), JSON.stringify({
52
- stage: 'scan',
53
- changes: [changeName],
54
- updatedAt: new Date().toISOString(),
55
- }, null, 2))
56
- writeFileSync(join(runtimeDir, 'scan-guard.json'), JSON.stringify({
57
- sourceCommit: 'new-head',
58
- startedAt: '2026-06-16T10:00:00.000Z',
59
- forceRescan: false,
60
- }, null, 2))
61
- const scanDoc = join(root, '.sillyspec', 'docs', 'app', 'scan', 'ARCHITECTURE.md')
62
- mkdirSync(join(root, '.sillyspec', 'docs', 'app', 'scan'), { recursive: true })
63
- writeFileSync(scanDoc, [
64
- '---',
65
- 'source_commit: old-head',
66
- 'updated_at: 2026-06-16T09:00:00.000Z',
67
- '---',
68
- '# Architecture',
69
- '',
70
- ].join('\n'))
71
- assert.equal(
72
- shouldBlock({ tool: 'Write', filePath: scanDoc, cwd: root }).blocked,
73
- true,
74
- 'scan overwrite should block stale source_commit without --force-rescan'
75
- )
76
- writeFileSync(join(runtimeDir, 'scan-guard.json'), JSON.stringify({
77
- sourceCommit: 'new-head',
78
- startedAt: '2026-06-16T10:00:00.000Z',
79
- forceRescan: true,
80
- }, null, 2))
81
- assert.equal(
82
- shouldBlock({ tool: 'Write', filePath: scanDoc, cwd: root }).blocked,
83
- false,
84
- 'scan overwrite should allow stale source_commit with --force-rescan'
85
- )
86
- const externalSpec = join(root, 'external-spec')
87
- const externalScanDoc = join(externalSpec, 'docs', 'app', 'scan', 'ARCHITECTURE.md')
88
- mkdirSync(join(externalSpec, '.runtime'), { recursive: true })
89
- mkdirSync(join(externalSpec, 'docs', 'app', 'scan'), { recursive: true })
90
- writeFileSync(join(externalSpec, '.runtime', 'scan-guard.json'), JSON.stringify({
91
- sourceCommit: 'external-new-head',
92
- startedAt: '2026-06-16T10:00:00.000Z',
93
- forceRescan: false,
94
- }, null, 2))
95
- writeFileSync(externalScanDoc, [
96
- '---',
97
- 'source_commit: external-old-head',
98
- 'updated_at: 2026-06-16T09:00:00.000Z',
99
- '---',
100
- '# Architecture',
101
- '',
102
- ].join('\n'))
103
- assert.equal(
104
- shouldBlock({ tool: 'Write', filePath: externalScanDoc, cwd: root }).blocked,
105
- true,
106
- 'external specRoot scan overwrite should read specRoot/.runtime/scan-guard.json'
107
- )
108
-
109
- rmSync(join(runtimeDir, 'gate-status.json'), { force: true })
110
- writeFileSync(join(root, '.sillyspec', 'local.yaml'), [
111
- 'worktreeHook:',
112
- ' readonlyCommands:',
113
- ' - custom-read',
114
- '',
115
- ].join('\n'))
116
- assert.equal(
117
- shouldBlock({ tool: 'Bash', command: 'custom-read status', cwd: root }).blocked,
118
- false,
119
- '.sillyspec/local.yaml readonlyCommands should extend the bash whitelist'
120
- )
121
-
122
- writeFileSync(join(runtimeDir, 'gate-status.json'), JSON.stringify({
123
- stage: 'quick',
124
- changes: [changeName],
125
- updatedAt: new Date().toISOString(),
126
- }, null, 2))
127
- assert.equal(
128
- shouldBlock({ tool: 'Write', filePath: join(root, 'src', 'quick.js'), cwd: root }).blocked,
129
- false,
130
- 'quick writes should still be allowed in the main workspace'
131
- )
132
-
133
- console.log('✅ worktree guard regression checks passed')
134
- } finally {
135
- rmSync(root, { recursive: true, force: true })
136
- }
@@ -1,188 +0,0 @@
1
- /**
2
- * worktree native-worktree overlay regression tests
3
- *
4
- * 验证 Bug 1 + Bug 2 修复:
5
- * 1. worktreeBase 固定到主仓库路径,不跟着 cwd 变化
6
- * 2. 禁止 self-overlay(source === target 时)
7
- * 3. native-worktree meta 缺失时 recover,不 overlay
8
- * 4. meta 已存在时幂等返回,不重建
9
- */
10
-
11
- import fs from 'fs'
12
- import path from 'path'
13
- import os from 'os'
14
- import { execSync } from 'child_process'
15
-
16
- // ── Test 1: _resolveMainRepoRoot 在主仓库内返回 cwd ──
17
-
18
- async function test1_mainRepoRoot() {
19
- const d = fs.mkdtempSync(path.join(os.tmpdir(), 'wt-'))
20
- execSync('git init', { cwd: d, stdio: 'pipe' })
21
- execSync('git config user.email "test@test.com"', { cwd: d, stdio: 'pipe' })
22
- execSync('git config user.name "test"', { cwd: d, stdio: 'pipe' })
23
- execSync('git commit --allow-empty -m "init"', { cwd: d, stdio: 'pipe' })
24
-
25
- // Add .gitignore to allow worktreeBase path
26
- fs.mkdirSync(path.join(d, '.sillyspec'), { recursive: true })
27
- fs.writeFileSync(path.join(d, '.gitignore'), '.sillyspec/\n')
28
-
29
- const { WorktreeManager } = await import('../src/worktree.js')
30
- const wm = new WorktreeManager({ cwd: d })
31
- const root = wm._resolveMainRepoRoot()
32
- console.assert(root === d, `Test 1 FAIL: expected ${d}, got ${root}`)
33
- console.log('✅ Test 1: main repo root resolves to cwd')
34
-
35
- fs.rmSync(d, { recursive: true })
36
- }
37
-
38
- // ── Test 2: native-worktree 检测 + 幂等守卫 ──
39
-
40
- async function test2_nativeWorktreeIdempotent() {
41
- const d = fs.mkdtempSync(path.join(os.tmpdir(), 'wt-'))
42
- execSync('git init', { cwd: d, stdio: 'pipe' })
43
- execSync('git config user.email "test@test.com"', { cwd: d, stdio: 'pipe' })
44
- execSync('git config user.name "test"', { cwd: d, stdio: 'pipe' })
45
- execSync('git commit --allow-empty -m "init"', { cwd: d, stdio: 'pipe' })
46
-
47
- const wtDir = path.join(d, 'wt')
48
- execSync(`git worktree add ${wtDir} -b test-branch`, { cwd: d, stdio: 'pipe' })
49
-
50
- // wtDir is a linked worktree
51
- const { WorktreeManager } = await import('../src/worktree.js')
52
-
53
- // First: create meta from inside worktree (simulating native-worktree mode)
54
- const wm1 = new WorktreeManager({ cwd: wtDir })
55
- // This simulates what happens when Claude Code runs in the worktree
56
- // and SillySpec calls create() — detectIsolation should return inWorktree=true
57
- // and meta should be written to main repo's worktreeBase, not worktree's
58
-
59
- // Verify worktreeBase points to main repo
60
- const expectedBase = path.join(d, '.sillyspec', '.runtime', 'worktrees')
61
- console.assert(wm1.worktreeBase === expectedBase, `Test 2 FAIL: worktreeBase=${wm1.worktreeBase}, expected=${expectedBase}`)
62
- console.log('✅ Test 2: worktreeBase fixed to main repo path')
63
-
64
- fs.rmSync(d, { recursive: true })
65
- }
66
-
67
- // ── Test 3: self-overlay 禁止 ──
68
-
69
- async function test3_selfOverlayBlocked() {
70
- const d = fs.mkdtempSync(path.join(os.tmpdir(), 'wt-'))
71
- execSync('git init', { cwd: d, stdio: 'pipe' })
72
- execSync('git config user.email "test@test.com"', { cwd: d, stdio: 'pipe' })
73
- execSync('git config user.name "test"', { cwd: d, stdio: 'pipe' })
74
- execSync('git commit --allow-empty -m "init"', { cwd: d, stdio: 'pipe' })
75
- fs.mkdirSync(path.join(d, '.sillyspec'), { recursive: true })
76
- fs.writeFileSync(path.join(d, '.gitignore'), '.sillyspec/\n')
77
-
78
- const { WorktreeManager } = await import('../src/worktree.js')
79
- const wm = new WorktreeManager({ cwd: d })
80
-
81
- // Create with in-place-fallback mode (source === target)
82
- const result = wm._createInPlaceMeta('test-change', {
83
- worktreePath: d,
84
- branch: 'test-branch',
85
- mode: 'in-place-fallback',
86
- })
87
-
88
- console.assert(result.mode === 'in-place-fallback', `Test 3 FAIL: mode=${result.mode}`)
89
- // 返回值不包含 baselineFiles(是简化的返回结构),验证 meta 文件本身
90
- const meta3 = wm.getMeta('test-change')
91
- console.assert(meta3 && meta3.baselineFiles.length === 0, `Test 3 FAIL: meta baselineFiles should be empty`)
92
- console.log('✅ Test 3: self-overlay blocked, baselineFiles empty')
93
-
94
- fs.rmSync(d, { recursive: true })
95
- }
96
-
97
- // ── Test 4: meta 幂等,不重复 overlay ──
98
-
99
- async function test4_metaIdempotent() {
100
- const d = fs.mkdtempSync(path.join(os.tmpdir(), 'wt-'))
101
- execSync('git init', { cwd: d, stdio: 'pipe' })
102
- execSync('git config user.email "test@test.com"', { cwd: d, stdio: 'pipe' })
103
- execSync('git config user.name "test"', { cwd: d, stdio: 'pipe' })
104
- execSync('git commit --allow-empty -m "init"', { cwd: d, stdio: 'pipe' })
105
- fs.mkdirSync(path.join(d, '.sillyspec'), { recursive: true })
106
- fs.writeFileSync(path.join(d, '.gitignore'), '.sillyspec/\n')
107
-
108
- const { WorktreeManager } = await import('../src/worktree.js')
109
- const wm = new WorktreeManager({ cwd: d })
110
-
111
- // First create
112
- const r1 = wm._createInPlaceMeta('test-change', {
113
- worktreePath: d,
114
- branch: 'test-branch',
115
- mode: 'in-place-fallback',
116
- })
117
-
118
- // Second create (should return existing, not re-overlay)
119
- const r2 = wm._createInPlaceMeta('test-change', {
120
- worktreePath: d,
121
- branch: 'test-branch',
122
- mode: 'in-place-fallback',
123
- })
124
-
125
- console.assert(r1.baseHash === r2.baseHash, `Test 4 FAIL: hashes differ`)
126
- console.log('✅ Test 4: _createInPlaceMeta idempotent')
127
-
128
- fs.rmSync(d, { recursive: true })
129
- }
130
-
131
- // ── Test 5: native-worktree meta 恢复 ──
132
-
133
- async function test5_nativeRecovery() {
134
- const d = fs.mkdtempSync(path.join(os.tmpdir(), 'wt-'))
135
- execSync('git init', { cwd: d, stdio: 'pipe' })
136
- execSync('git config user.email "test@test.com"', { cwd: d, stdio: 'pipe' })
137
- execSync('git config user.name "test"', { cwd: d, stdio: 'pipe' })
138
- execSync('git commit --allow-empty -m "init"', { cwd: d, stdio: 'pipe' })
139
-
140
- const wtDir = path.join(d, 'wt')
141
- execSync(`git worktree add ${wtDir} -b test-branch`, { cwd: d, stdio: 'pipe' })
142
-
143
- const { WorktreeManager } = await import('../src/worktree.js')
144
- const wm = new WorktreeManager({ cwd: wtDir })
145
-
146
- // Simulate meta missing in native-worktree (should recover, not overlay)
147
- const result = wm._recoverNativeWorktreeMeta('test-change', {
148
- worktreePath: wtDir,
149
- branch: 'test-branch',
150
- })
151
-
152
- console.assert(result.mode === 'native-worktree', `Test 5 FAIL: mode=${result.mode}`)
153
- // 返回值不包含 baselineFiles,验证 meta 文件本身
154
- const meta5 = wm.getMeta('test-change')
155
- console.assert(meta5 && meta5.baselineFiles.length === 0, `Test 5 FAIL: meta baselineFiles should be empty`)
156
-
157
- // Verify meta is readable now
158
- const meta = wm.getMeta('test-change')
159
- console.assert(meta !== null, `Test 5 FAIL: meta should exist after recovery`)
160
- console.assert(meta.mode === 'native-worktree', `Test 5 FAIL: meta.mode=${meta.mode}`)
161
- console.log('✅ Test 5: native-worktree meta recovery without overlay')
162
-
163
- fs.rmSync(d, { recursive: true })
164
- }
165
-
166
- // ── Run all ──
167
-
168
- const tests = [
169
- ['main repo root', test1_mainRepoRoot],
170
- ['native worktree worktreeBase', test2_nativeWorktreeIdempotent],
171
- ['self-overlay blocked', test3_selfOverlayBlocked],
172
- ['meta idempotent', test4_metaIdempotent],
173
- ['native recovery', test5_nativeRecovery],
174
- ]
175
-
176
- let passed = 0, failed = 0
177
- for (const [name, fn] of tests) {
178
- try {
179
- await fn()
180
- passed++
181
- } catch (e) {
182
- console.log(`❌ ${name}: ${e.message}`)
183
- failed++
184
- }
185
- }
186
-
187
- console.log(`\n${passed}/${tests.length} passed`)
188
- if (failed) process.exit(1)