gsd-pi 2.76.0-dev.b072ebb73 → 2.76.0-dev.fe143342a

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 (200) hide show
  1. package/dist/mcp-server.d.ts +7 -0
  2. package/dist/mcp-server.js +35 -1
  3. package/dist/resource-loader.d.ts +1 -1
  4. package/dist/resource-loader.js +2 -8
  5. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +66 -4
  6. package/dist/resources/extensions/gsd/auto/phases.js +4 -1
  7. package/dist/resources/extensions/gsd/auto/session.js +4 -0
  8. package/dist/resources/extensions/gsd/auto-model-selection.js +39 -13
  9. package/dist/resources/extensions/gsd/auto-start.js +39 -21
  10. package/dist/resources/extensions/gsd/auto.js +15 -12
  11. package/dist/resources/extensions/gsd/blocked-models.js +68 -0
  12. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +76 -0
  13. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +39 -9
  14. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +93 -0
  15. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +2 -0
  16. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +35 -0
  17. package/dist/resources/extensions/gsd/compaction-snapshot.js +121 -0
  18. package/dist/resources/extensions/gsd/complexity-classifier.js +5 -3
  19. package/dist/resources/extensions/gsd/error-classifier.js +31 -3
  20. package/dist/resources/extensions/gsd/exec-history.js +120 -0
  21. package/dist/resources/extensions/gsd/exec-sandbox.js +258 -0
  22. package/dist/resources/extensions/gsd/gsd-db.js +62 -4
  23. package/dist/resources/extensions/gsd/init-wizard.js +15 -1
  24. package/dist/resources/extensions/gsd/key-manager.js +6 -0
  25. package/dist/resources/extensions/gsd/pre-execution-checks.js +13 -3
  26. package/dist/resources/extensions/gsd/preferences-types.js +9 -0
  27. package/dist/resources/extensions/gsd/preferences-validation.js +83 -0
  28. package/dist/resources/extensions/gsd/preferences.js +17 -17
  29. package/dist/resources/extensions/gsd/prompt-loader.js +22 -7
  30. package/dist/resources/extensions/gsd/safety/file-change-validator.js +1 -1
  31. package/dist/resources/extensions/gsd/tools/exec-search-tool.js +59 -0
  32. package/dist/resources/extensions/gsd/tools/exec-tool.js +126 -0
  33. package/dist/resources/extensions/gsd/tools/resume-tool.js +23 -0
  34. package/dist/resources/extensions/gsd/workflow-mcp.js +3 -0
  35. package/dist/resources/extensions/search-the-web/command-search-provider.js +5 -4
  36. package/dist/resources/extensions/search-the-web/native-search.js +45 -13
  37. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  38. package/dist/web/standalone/.next/BUILD_ID +1 -1
  39. package/dist/web/standalone/.next/app-path-routes-manifest.json +8 -8
  40. package/dist/web/standalone/.next/build-manifest.json +2 -2
  41. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  42. package/dist/web/standalone/.next/required-server-files.json +1 -1
  43. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  44. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  50. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  51. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  52. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  53. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app/index.html +1 -1
  60. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  61. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  62. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  63. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  64. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  65. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  66. package/dist/web/standalone/.next/server/app-paths-manifest.json +8 -8
  67. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  68. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  69. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  70. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  71. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  72. package/dist/web/standalone/server.js +1 -1
  73. package/package.json +1 -1
  74. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  75. package/packages/mcp-server/dist/workflow-tools.js +64 -25
  76. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  77. package/packages/mcp-server/src/workflow-tools.test.ts +146 -1
  78. package/packages/mcp-server/src/workflow-tools.ts +84 -43
  79. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  80. package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  81. package/packages/pi-ai/dist/providers/openai-completions.js +60 -15
  82. package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
  83. package/packages/pi-ai/dist/providers/think-tag-parser.d.ts +17 -0
  84. package/packages/pi-ai/dist/providers/think-tag-parser.d.ts.map +1 -0
  85. package/packages/pi-ai/dist/providers/think-tag-parser.js +75 -0
  86. package/packages/pi-ai/dist/providers/think-tag-parser.js.map +1 -0
  87. package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts +2 -0
  88. package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts.map +1 -0
  89. package/packages/pi-ai/dist/providers/think-tag-parser.test.js +41 -0
  90. package/packages/pi-ai/dist/providers/think-tag-parser.test.js.map +1 -0
  91. package/packages/pi-ai/src/providers/openai-completions.ts +57 -16
  92. package/packages/pi-ai/src/providers/think-tag-parser.test.ts +44 -0
  93. package/packages/pi-ai/src/providers/think-tag-parser.ts +94 -0
  94. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  95. package/packages/pi-coding-agent/dist/core/model-discovery.d.ts +3 -1
  96. package/packages/pi-coding-agent/dist/core/model-discovery.d.ts.map +1 -1
  97. package/packages/pi-coding-agent/dist/core/model-discovery.js +92 -12
  98. package/packages/pi-coding-agent/dist/core/model-discovery.js.map +1 -1
  99. package/packages/pi-coding-agent/dist/core/model-discovery.test.js +16 -1
  100. package/packages/pi-coding-agent/dist/core/model-discovery.test.js.map +1 -1
  101. package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js +61 -1
  102. package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js.map +1 -1
  103. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +5 -0
  104. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  105. package/packages/pi-coding-agent/dist/core/model-registry.js +76 -10
  106. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  107. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts +2 -0
  108. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts.map +1 -0
  109. package/packages/pi-coding-agent/dist/core/redact-secrets.js +49 -0
  110. package/packages/pi-coding-agent/dist/core/redact-secrets.js.map +1 -0
  111. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts +2 -0
  112. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts.map +1 -0
  113. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js +67 -0
  114. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js.map +1 -0
  115. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  116. package/packages/pi-coding-agent/dist/core/session-manager.js +9 -5
  117. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  118. package/packages/pi-coding-agent/dist/core/session-manager.test.js +25 -1
  119. package/packages/pi-coding-agent/dist/core/session-manager.test.js.map +1 -1
  120. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +1 -1
  121. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
  122. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +5 -4
  123. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
  124. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts.map +1 -1
  125. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js +13 -7
  126. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js.map +1 -1
  127. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +7 -6
  128. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  129. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +29 -21
  130. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  131. package/packages/pi-coding-agent/src/core/model-discovery.test.ts +19 -0
  132. package/packages/pi-coding-agent/src/core/model-discovery.ts +99 -12
  133. package/packages/pi-coding-agent/src/core/model-registry-discovery.test.ts +75 -0
  134. package/packages/pi-coding-agent/src/core/model-registry.ts +86 -10
  135. package/packages/pi-coding-agent/src/core/redact-secrets.test.ts +86 -0
  136. package/packages/pi-coding-agent/src/core/redact-secrets.ts +58 -0
  137. package/packages/pi-coding-agent/src/core/session-manager.test.ts +36 -1
  138. package/packages/pi-coding-agent/src/core/session-manager.ts +9 -5
  139. package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +6 -6
  140. package/packages/pi-coding-agent/src/modes/interactive/components/provider-manager.ts +16 -7
  141. package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +36 -22
  142. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  143. package/scripts/link-workspace-packages.cjs +1 -0
  144. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +67 -4
  145. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +137 -2
  146. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
  147. package/src/resources/extensions/gsd/auto/phases.ts +4 -0
  148. package/src/resources/extensions/gsd/auto/session.ts +7 -1
  149. package/src/resources/extensions/gsd/auto-model-selection.ts +50 -12
  150. package/src/resources/extensions/gsd/auto-start.ts +40 -22
  151. package/src/resources/extensions/gsd/auto.ts +15 -12
  152. package/src/resources/extensions/gsd/blocked-models.ts +98 -0
  153. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +97 -0
  154. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +40 -9
  155. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +109 -0
  156. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +2 -0
  157. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +36 -0
  158. package/src/resources/extensions/gsd/compaction-snapshot.ts +165 -0
  159. package/src/resources/extensions/gsd/complexity-classifier.ts +5 -3
  160. package/src/resources/extensions/gsd/error-classifier.ts +36 -3
  161. package/src/resources/extensions/gsd/exec-history.ts +153 -0
  162. package/src/resources/extensions/gsd/exec-sandbox.ts +326 -0
  163. package/src/resources/extensions/gsd/gsd-db.ts +68 -4
  164. package/src/resources/extensions/gsd/init-wizard.ts +15 -1
  165. package/src/resources/extensions/gsd/key-manager.ts +6 -0
  166. package/src/resources/extensions/gsd/pre-execution-checks.ts +13 -3
  167. package/src/resources/extensions/gsd/preferences-types.ts +38 -0
  168. package/src/resources/extensions/gsd/preferences-validation.ts +79 -0
  169. package/src/resources/extensions/gsd/preferences.ts +17 -17
  170. package/src/resources/extensions/gsd/prompt-loader.ts +30 -7
  171. package/src/resources/extensions/gsd/safety/file-change-validator.ts +1 -1
  172. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +12 -0
  173. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +33 -3
  174. package/src/resources/extensions/gsd/tests/auto-thinking-restore.test.ts +38 -0
  175. package/src/resources/extensions/gsd/tests/blocked-models.test.ts +98 -0
  176. package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +123 -0
  177. package/src/resources/extensions/gsd/tests/complexity-classifier.test.ts +3 -3
  178. package/src/resources/extensions/gsd/tests/exec-history.test.ts +124 -0
  179. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +210 -0
  180. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +20 -0
  181. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +151 -0
  182. package/src/resources/extensions/gsd/tests/init-wizard.test.ts +27 -0
  183. package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +1 -1
  184. package/src/resources/extensions/gsd/tests/key-manager.test.ts +7 -0
  185. package/src/resources/extensions/gsd/tests/pre-exec-backtick-strip.test.ts +14 -0
  186. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +19 -0
  187. package/src/resources/extensions/gsd/tests/preferences.test.ts +110 -0
  188. package/src/resources/extensions/gsd/tests/prompt-loader-extension-dir.test.ts +49 -0
  189. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +91 -0
  190. package/src/resources/extensions/gsd/tests/save-gate-result-render.test.ts +95 -0
  191. package/src/resources/extensions/gsd/tests/zombie-gsd-state.test.ts +3 -1
  192. package/src/resources/extensions/gsd/tools/exec-search-tool.ts +81 -0
  193. package/src/resources/extensions/gsd/tools/exec-tool.ts +183 -0
  194. package/src/resources/extensions/gsd/tools/resume-tool.ts +40 -0
  195. package/src/resources/extensions/gsd/workflow-logger.ts +2 -1
  196. package/src/resources/extensions/gsd/workflow-mcp.ts +3 -0
  197. package/src/resources/extensions/search-the-web/command-search-provider.ts +5 -4
  198. package/src/resources/extensions/search-the-web/native-search.ts +48 -12
  199. /package/dist/web/standalone/.next/static/{pBwmOoye64ZrRp-_rf0v1 → n21VtX2hZlkpdEUO_nU4z}/_buildManifest.js +0 -0
  200. /package/dist/web/standalone/.next/static/{pBwmOoye64ZrRp-_rf0v1 → n21VtX2hZlkpdEUO_nU4z}/_ssgManifest.js +0 -0
@@ -0,0 +1,210 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+
7
+ import { EXEC_DEFAULTS, runExecSandbox, type ExecSandboxOptions } from '../exec-sandbox.ts';
8
+ import { buildExecOptions, executeGsdExec } from '../tools/exec-tool.ts';
9
+ import { isContextModeEnabled } from '../preferences-types.ts';
10
+
11
+ function freshBase(): string {
12
+ return mkdtempSync(join(tmpdir(), 'gsd-exec-test-'));
13
+ }
14
+
15
+ function cleanup(dir: string): void {
16
+ rmSync(dir, { recursive: true, force: true });
17
+ }
18
+
19
+ function baseOpts(base: string, overrides: Partial<ExecSandboxOptions> = {}): ExecSandboxOptions {
20
+ return {
21
+ baseDir: base,
22
+ clamp_timeout_ms: EXEC_DEFAULTS.clampTimeoutMs,
23
+ default_timeout_ms: 10_000,
24
+ stdout_cap_bytes: 1_024,
25
+ stderr_cap_bytes: 1_024,
26
+ digest_chars: 120,
27
+ env_allowlist: EXEC_DEFAULTS.envAllowlist,
28
+ ...overrides,
29
+ };
30
+ }
31
+
32
+ test('runExecSandbox: captures stdout, persists artifacts, returns digest', async () => {
33
+ const base = freshBase();
34
+ try {
35
+ const result = await runExecSandbox(
36
+ { runtime: 'bash', script: 'echo hello world' },
37
+ baseOpts(base),
38
+ );
39
+ assert.equal(result.exit_code, 0);
40
+ assert.equal(result.timed_out, false);
41
+ assert.ok(result.digest.includes('hello world'), `digest should contain stdout: ${result.digest}`);
42
+ assert.ok(result.stdout_path.startsWith(join(base, '.gsd', 'exec')), 'stdout path under .gsd/exec');
43
+ assert.equal(readFileSync(result.stdout_path, 'utf-8').trim(), 'hello world');
44
+ const meta = JSON.parse(readFileSync(result.meta_path, 'utf-8')) as Record<string, unknown>;
45
+ assert.equal(meta.runtime, 'bash');
46
+ assert.equal(meta.exit_code, 0);
47
+ } finally {
48
+ cleanup(base);
49
+ }
50
+ });
51
+
52
+ test('runExecSandbox: enforces stdout cap and marks truncation', async () => {
53
+ const base = freshBase();
54
+ try {
55
+ const result = await runExecSandbox(
56
+ // Emit far more than the cap so truncation triggers.
57
+ { runtime: 'bash', script: 'head -c 8000 /dev/urandom | base64' },
58
+ baseOpts(base, { stdout_cap_bytes: 256 }),
59
+ );
60
+ assert.equal(result.stdout_truncated, true, 'should mark stdout truncated');
61
+ assert.ok(result.stdout_bytes <= 256, `stdout_bytes within cap (got ${result.stdout_bytes})`);
62
+ const stdout = readFileSync(result.stdout_path, 'utf-8');
63
+ assert.ok(stdout.endsWith('[truncated: stdout cap reached]\n'), 'truncation marker appended');
64
+ } finally {
65
+ cleanup(base);
66
+ }
67
+ });
68
+
69
+ test('runExecSandbox: enforces timeout and surfaces timed_out', async () => {
70
+ const base = freshBase();
71
+ try {
72
+ const started = Date.now();
73
+ const result = await runExecSandbox(
74
+ { runtime: 'bash', script: 'sleep 10' },
75
+ baseOpts(base, { default_timeout_ms: 150, clamp_timeout_ms: 150 }),
76
+ );
77
+ const elapsed = Date.now() - started;
78
+ assert.equal(result.timed_out, true);
79
+ assert.ok(elapsed < 5_000, `should return well before 10s (took ${elapsed}ms)`);
80
+ } finally {
81
+ cleanup(base);
82
+ }
83
+ });
84
+
85
+ test('runExecSandbox: forwards only allowlisted env vars', async () => {
86
+ const base = freshBase();
87
+ try {
88
+ const result = await runExecSandbox(
89
+ { runtime: 'bash', script: 'echo PATH=$PATH SECRET=$GSD_TEST_SECRET' },
90
+ baseOpts(base, {
91
+ env_allowlist: [],
92
+ env: { PATH: '/usr/bin:/bin', HOME: '/tmp', GSD_TEST_SECRET: 'should-be-blocked' },
93
+ }),
94
+ );
95
+ const stdout = readFileSync(result.stdout_path, 'utf-8');
96
+ assert.ok(stdout.includes('PATH=/usr/bin:/bin'), 'PATH forwarded');
97
+ assert.ok(!stdout.includes('should-be-blocked'), 'non-allowlisted var blocked');
98
+ } finally {
99
+ cleanup(base);
100
+ }
101
+ });
102
+
103
+ test('runExecSandbox: node runtime executes JS', async () => {
104
+ const base = freshBase();
105
+ try {
106
+ const result = await runExecSandbox(
107
+ { runtime: 'node', script: 'console.log("node-ok:" + (1+2))' },
108
+ baseOpts(base),
109
+ );
110
+ assert.equal(result.exit_code, 0);
111
+ assert.ok(result.digest.includes('node-ok:3'));
112
+ } finally {
113
+ cleanup(base);
114
+ }
115
+ });
116
+
117
+ // ── exec-tool executor ────────────────────────────────────────────────────
118
+
119
+ test('executeGsdExec: runs by default when context_mode is unset', async () => {
120
+ const base = freshBase();
121
+ try {
122
+ const result = await executeGsdExec(
123
+ { runtime: 'bash', script: 'echo default-on-run' },
124
+ { baseDir: base, preferences: {} },
125
+ );
126
+ assert.ok(!result.isError, 'should succeed with no preferences');
127
+ assert.equal(result.details.operation, 'gsd_exec');
128
+ assert.equal(result.details.exit_code, 0);
129
+ assert.ok(result.content[0].text.includes('default-on-run'));
130
+ } finally {
131
+ cleanup(base);
132
+ }
133
+ });
134
+
135
+ test('executeGsdExec: runs when preferences is null (fresh project)', async () => {
136
+ const base = freshBase();
137
+ try {
138
+ const result = await executeGsdExec(
139
+ { runtime: 'bash', script: 'echo null-prefs-run' },
140
+ { baseDir: base, preferences: null },
141
+ );
142
+ assert.ok(!result.isError, 'null preferences should not disable');
143
+ assert.ok(result.content[0].text.includes('null-prefs-run'));
144
+ } finally {
145
+ cleanup(base);
146
+ }
147
+ });
148
+
149
+ test('executeGsdExec: blocked only when context_mode.enabled=false', async () => {
150
+ const base = freshBase();
151
+ try {
152
+ const result = await executeGsdExec(
153
+ { runtime: 'bash', script: 'echo should-not-run' },
154
+ { baseDir: base, preferences: { context_mode: { enabled: false } } },
155
+ );
156
+ assert.equal(result.isError, true);
157
+ assert.equal((result.details as { error?: string }).error, 'context_mode_disabled');
158
+ } finally {
159
+ cleanup(base);
160
+ }
161
+ });
162
+
163
+ test('executeGsdExec: runs when enabled explicitly set to true', async () => {
164
+ const base = freshBase();
165
+ try {
166
+ const result = await executeGsdExec(
167
+ { runtime: 'bash', script: 'echo explicit-on' },
168
+ { baseDir: base, preferences: { context_mode: { enabled: true } } },
169
+ );
170
+ assert.ok(!result.isError);
171
+ assert.ok(result.content[0].text.includes('explicit-on'));
172
+ } finally {
173
+ cleanup(base);
174
+ }
175
+ });
176
+
177
+ test('executeGsdExec: rejects empty script', async () => {
178
+ const base = freshBase();
179
+ try {
180
+ const result = await executeGsdExec(
181
+ { runtime: 'bash', script: ' ' },
182
+ { baseDir: base, preferences: { context_mode: { enabled: true } } },
183
+ );
184
+ assert.equal(result.isError, true);
185
+ assert.equal((result.details as { error?: string }).error, 'invalid_params');
186
+ } finally {
187
+ cleanup(base);
188
+ }
189
+ });
190
+
191
+ test('isContextModeEnabled: defaults to true; only explicit false disables', () => {
192
+ assert.equal(isContextModeEnabled(undefined), true, 'undefined prefs → on');
193
+ assert.equal(isContextModeEnabled(null), true, 'null prefs → on');
194
+ assert.equal(isContextModeEnabled({}), true, 'empty prefs → on');
195
+ assert.equal(isContextModeEnabled({ context_mode: {} }), true, 'empty block → on');
196
+ assert.equal(isContextModeEnabled({ context_mode: { enabled: true } }), true);
197
+ assert.equal(isContextModeEnabled({ context_mode: { enabled: false } }), false);
198
+ });
199
+
200
+ test('buildExecOptions: clamps out-of-range values to safe defaults', () => {
201
+ const opts = buildExecOptions('/tmp/base', {
202
+ enabled: true,
203
+ exec_timeout_ms: 999_999_999,
204
+ exec_stdout_cap_bytes: 1,
205
+ exec_digest_chars: -20,
206
+ });
207
+ assert.equal(opts.default_timeout_ms, EXEC_DEFAULTS.clampTimeoutMs, 'timeout clamped to upper bound');
208
+ assert.equal(opts.stdout_cap_bytes, 4_096, 'stdout cap clamped to floor');
209
+ assert.equal(opts.digest_chars, 0, 'digest chars clamped to floor');
210
+ });
@@ -15,6 +15,26 @@ function git(cwd: string, ...args: string[]): string {
15
15
  }).trim();
16
16
  }
17
17
 
18
+ test("validateFileChanges works on repos with a single commit (no HEAD~1)", (t) => {
19
+ const base = mkdtempSync(join(tmpdir(), "gsd-file-change-validator-"));
20
+ t.after(() => rmSync(base, { recursive: true, force: true }));
21
+
22
+ git(base, "init");
23
+ git(base, "config", "user.email", "test@example.com");
24
+ git(base, "config", "user.name", "Test User");
25
+
26
+ writeFileSync(join(base, "foo.ts"), "export const x = 1;\n");
27
+ git(base, "add", ".");
28
+ git(base, "commit", "-m", "initial");
29
+
30
+ // With only one commit, HEAD~1 doesn't exist — this must not throw
31
+ const audit = validateFileChanges(base, ["foo.ts"], []);
32
+
33
+ assert.ok(audit, "audit should be produced for single-commit repo");
34
+ assert.deepEqual(audit.unexpectedFiles, []);
35
+ assert.deepEqual(audit.missingFiles, []);
36
+ });
37
+
18
38
  test("validateFileChanges ignores inline descriptions in expected output paths", (t) => {
19
39
  const base = mkdtempSync(join(tmpdir(), "gsd-file-change-validator-"));
20
40
  t.after(() => rmSync(base, { recursive: true, force: true }));
@@ -3,12 +3,14 @@ import assert from 'node:assert/strict';
3
3
  import * as fs from 'node:fs';
4
4
  import * as path from 'node:path';
5
5
  import * as os from 'node:os';
6
+ import { createRequire } from 'node:module';
6
7
  import {
7
8
  openDatabase,
8
9
  closeDatabase,
9
10
  isDbAvailable,
10
11
  wasDbOpenAttempted,
11
12
  getDbProvider,
13
+ getDbStatus,
12
14
  insertDecision,
13
15
  getDecisionById,
14
16
  insertRequirement,
@@ -26,6 +28,8 @@ import {
26
28
  checkpointDatabase,
27
29
  } from '../gsd-db.ts';
28
30
 
31
+ const _require = createRequire(import.meta.url);
32
+
29
33
  // ═══════════════════════════════════════════════════════════════════════════
30
34
  // Helper: create a temp file path for file-backed DB tests
31
35
  // ═══════════════════════════════════════════════════════════════════════════
@@ -59,6 +63,20 @@ function withPlatform<T>(platform: NodeJS.Platform, fn: () => T): T {
59
63
  }
60
64
  }
61
65
 
66
+ function openRawSqliteForTest(dbPath: string): { exec(sql: string): void; close(): void } {
67
+ try {
68
+ const mod = _require('node:sqlite') as { DatabaseSync: new (path: string) => { exec(sql: string): void; close(): void } };
69
+ return new mod.DatabaseSync(dbPath);
70
+ } catch {
71
+ type SqliteCtor = new (path: string) => { exec(sql: string): void; close(): void };
72
+ const mod = _require('better-sqlite3') as
73
+ | SqliteCtor
74
+ | { default: SqliteCtor };
75
+ const DatabaseCtor: SqliteCtor = typeof mod === 'function' ? mod : mod.default;
76
+ return new DatabaseCtor(dbPath);
77
+ }
78
+ }
79
+
62
80
  // ═══════════════════════════════════════════════════════════════════════════
63
81
  // gsd-db tests
64
82
  // ═══════════════════════════════════════════════════════════════════════════
@@ -404,6 +422,53 @@ describe('gsd-db', () => {
404
422
  cleanup(dbPath);
405
423
  });
406
424
 
425
+ test('gsd-db: legacy DB missing memories.scope opens and bootstraps index columns', () => {
426
+ const dbPath = tempDbPath();
427
+ const legacyDb = openRawSqliteForTest(dbPath);
428
+ legacyDb.exec(`
429
+ CREATE TABLE schema_version (
430
+ version INTEGER NOT NULL,
431
+ applied_at TEXT NOT NULL
432
+ );
433
+ INSERT INTO schema_version(version, applied_at) VALUES (17, '2026-04-20T00:00:00.000Z');
434
+ CREATE TABLE memories (
435
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
436
+ id TEXT NOT NULL UNIQUE,
437
+ category TEXT NOT NULL,
438
+ content TEXT NOT NULL,
439
+ confidence REAL NOT NULL DEFAULT 0.8,
440
+ source_unit_type TEXT,
441
+ source_unit_id TEXT,
442
+ created_at TEXT NOT NULL,
443
+ updated_at TEXT NOT NULL,
444
+ superseded_by TEXT DEFAULT NULL,
445
+ hit_count INTEGER NOT NULL DEFAULT 0
446
+ );
447
+ INSERT INTO memories(id, category, content, created_at, updated_at)
448
+ VALUES ('legacy-memory', 'note', 'legacy row', '2026-04-20T00:00:00.000Z', '2026-04-20T00:00:00.000Z');
449
+ `);
450
+ legacyDb.close();
451
+
452
+ assert.equal(openDatabase(dbPath), true, 'openDatabase should succeed for legacy DB missing memories.scope');
453
+
454
+ const adapter = _getAdapter()!;
455
+ const columns = adapter.prepare('PRAGMA table_info(memories)').all();
456
+ const names = columns.map((row) => row['name']);
457
+ assert.ok(names.includes('scope'), 'memories.scope should be added during bootstrap');
458
+ assert.ok(names.includes('tags'), 'memories.tags should be added during bootstrap');
459
+
460
+ const row = adapter.prepare(`SELECT scope, tags FROM memories WHERE id = 'legacy-memory'`).get();
461
+ assert.equal(row?.['scope'], 'project', 'legacy rows should receive default scope');
462
+ assert.equal(row?.['tags'], '[]', 'legacy rows should receive default tags');
463
+
464
+ const index = adapter.prepare(
465
+ "SELECT name FROM sqlite_master WHERE type = 'index' AND name = 'idx_memories_scope'",
466
+ ).get();
467
+ assert.equal(index?.['name'], 'idx_memories_scope', 'scope index should be created after bootstrap columns are present');
468
+
469
+ cleanup(dbPath);
470
+ });
471
+
407
472
  test('gsd-db: rowToTask tolerates legacy comma-separated task arrays', () => {
408
473
  openDatabase(':memory:');
409
474
 
@@ -561,6 +626,92 @@ describe('gsd-db', () => {
561
626
  });
562
627
  });
563
628
 
629
+ // ─── getDbStatus ───────────────────────────────────────────────────────────
630
+
631
+ describe('getDbStatus', () => {
632
+ test('getDbStatus: initial state before any open', () => {
633
+ closeDatabase();
634
+ const status = getDbStatus();
635
+ assert.strictEqual(status.available, false, 'available false before open');
636
+ assert.strictEqual(status.attempted, false, 'attempted false before open');
637
+ assert.strictEqual(status.lastError, null, 'lastError null before open');
638
+ assert.strictEqual(status.lastPhase, null, 'lastPhase null before open');
639
+ });
640
+
641
+ test('getDbStatus: available after successful open', () => {
642
+ openDatabase(':memory:');
643
+ const status = getDbStatus();
644
+ assert.strictEqual(status.available, true, 'available true after open');
645
+ assert.strictEqual(status.attempted, true, 'attempted true after open');
646
+ assert.ok(status.provider !== null, 'provider set after open');
647
+ assert.strictEqual(status.lastError, null, 'lastError null on success');
648
+ assert.strictEqual(status.lastPhase, null, 'lastPhase null on success');
649
+ closeDatabase();
650
+ });
651
+
652
+ test('getDbStatus: resets lastError/lastPhase after closeDatabase', () => {
653
+ // Simulate a failed open to set error state
654
+ const corruptPath = path.join(os.tmpdir(), `gsd-corrupt-${Date.now()}.db`);
655
+ fs.writeFileSync(corruptPath, Buffer.from('not a sqlite file at all!!!!!'));
656
+ try {
657
+ openDatabase(corruptPath);
658
+ } catch {
659
+ // expected
660
+ }
661
+ assert.ok(getDbStatus().lastError !== null, 'lastError set after failed open');
662
+
663
+ // closeDatabase should clear it even though no DB was opened
664
+ closeDatabase();
665
+ const status = getDbStatus();
666
+ assert.strictEqual(status.lastError, null, 'lastError cleared by closeDatabase');
667
+ assert.strictEqual(status.lastPhase, null, 'lastPhase cleared by closeDatabase');
668
+ assert.strictEqual(status.attempted, false, 'attempted reset by closeDatabase');
669
+ fs.unlinkSync(corruptPath);
670
+ });
671
+
672
+ test('getDbStatus: captures open-phase error on corrupt file', () => {
673
+ closeDatabase();
674
+ const corruptPath = path.join(os.tmpdir(), `gsd-corrupt-${Date.now()}.db`);
675
+ fs.writeFileSync(corruptPath, Buffer.from('not a sqlite file at all!!!!!'));
676
+ try {
677
+ openDatabase(corruptPath);
678
+ } catch {
679
+ // expected — both providers should reject a non-SQLite file
680
+ }
681
+ const status = getDbStatus();
682
+ if (!status.available) {
683
+ // open failed (expected in most environments)
684
+ assert.strictEqual(status.attempted, true, 'attempted true after failed open');
685
+ // provider may reject at raw-open level ("open") or at SQL init level ("initSchema")
686
+ assert.ok(
687
+ status.lastPhase === 'open' || status.lastPhase === 'initSchema',
688
+ `lastPhase should be "open" or "initSchema", got: ${status.lastPhase}`,
689
+ );
690
+ assert.ok(status.lastError instanceof Error, 'lastError is an Error');
691
+ }
692
+ // If somehow it succeeded (unlikely with garbage content), that's also fine
693
+ closeDatabase();
694
+ try { fs.unlinkSync(corruptPath); } catch { /* best effort */ }
695
+ });
696
+
697
+ test('getDbStatus: error state resets on next successful open', () => {
698
+ closeDatabase();
699
+ const corruptPath = path.join(os.tmpdir(), `gsd-corrupt-${Date.now()}.db`);
700
+ fs.writeFileSync(corruptPath, Buffer.from('not a sqlite file at all!!!!!'));
701
+ try { openDatabase(corruptPath); } catch { /* expected */ }
702
+ assert.ok(!getDbStatus().available, 'DB unavailable after corrupt open');
703
+
704
+ // Now open a valid in-memory DB — error state should clear
705
+ openDatabase(':memory:');
706
+ const status = getDbStatus();
707
+ assert.strictEqual(status.available, true, 'available after valid open');
708
+ assert.strictEqual(status.lastError, null, 'lastError cleared on successful open');
709
+ assert.strictEqual(status.lastPhase, null, 'lastPhase cleared on successful open');
710
+ closeDatabase();
711
+ try { fs.unlinkSync(corruptPath); } catch { /* best effort */ }
712
+ });
713
+ });
714
+
564
715
  // ─── Final Report ──────────────────────────────────────────────────────────
565
716
 
566
717
  });
@@ -178,6 +178,33 @@ test("init-wizard: multiple project files detected together", (t) => {
178
178
  }
179
179
  });
180
180
 
181
+ // ─── Git init + initial commit regression (#4530) ───────────────────────────
182
+
183
+ import { execFileSync } from "node:child_process";
184
+ import { nativeInit, nativeAddAll, nativeCommit } from "../native-git-bridge.ts";
185
+
186
+ test("init-wizard: nativeInit + nativeAddAll + nativeCommit produces a reachable HEAD (#4530)", (t) => {
187
+ // Regression: showProjectInit called nativeInit but never committed, leaving
188
+ // the branch unborn. git log and git worktree add both fail on zero-commit repos.
189
+ const dir = makeTempDir("git-init-commit");
190
+ t.after(() => { cleanup(dir); });
191
+
192
+ nativeInit(dir, "main");
193
+ execFileSync("git", ["config", "user.email", "test@test.com"], { cwd: dir });
194
+ execFileSync("git", ["config", "user.name", "Test"], { cwd: dir });
195
+ writeFileSync(join(dir, ".gitignore"), "*.log\n", "utf-8");
196
+
197
+ nativeAddAll(dir);
198
+ nativeCommit(dir, "chore: init project");
199
+
200
+ // git log must succeed (was: fatal: your current branch 'main' does not have any commits yet)
201
+ const subject = execFileSync("git", ["log", "-1", "--format=%s"], {
202
+ cwd: dir,
203
+ encoding: "utf-8",
204
+ }).trim();
205
+ assert.equal(subject, "chore: init project");
206
+ });
207
+
181
208
  test("init-wizard: v1 with both .planning/ and .gsd/ prioritizes v2", (t) => {
182
209
  const dir = makeTempDir("both-v1-v2");
183
210
  try {
@@ -42,7 +42,7 @@ describe('isolation:none stale branch guard (#3675)', () => {
42
42
  });
43
43
 
44
44
  test('guard is conditional on isolation mode "none"', () => {
45
- assert.match(source, /getIsolationMode\(\)\s*===\s*["']none["']/,
45
+ assert.match(source, /getIsolationMode\([^)]*\)\s*===\s*["']none["']/,
46
46
  'guard should only activate when isolation mode is "none"');
47
47
  });
48
48
 
@@ -143,6 +143,13 @@ test("PROVIDER_REGISTRY includes all major LLM providers", () => {
143
143
  assert.ok(ids.includes("groq"));
144
144
  });
145
145
 
146
+ test("PROVIDER_REGISTRY includes claude-code as a first-class LLM provider (#4541)", () => {
147
+ const entry = PROVIDER_REGISTRY.find((p) => p.id === "claude-code");
148
+ assert.ok(entry, "claude-code must be in PROVIDER_REGISTRY");
149
+ assert.equal(entry!.category, "llm");
150
+ assert.ok(entry!.hasOAuth, "claude-code uses OAuth (CLI auth)");
151
+ });
152
+
146
153
  test("PROVIDER_REGISTRY includes all tool/search providers", () => {
147
154
  const ids = PROVIDER_REGISTRY.map((p) => p.id);
148
155
  assert.ok(ids.includes("tavily"));
@@ -30,6 +30,20 @@ describe('normalizeFilePath backtick stripping (#3649)', () => {
30
30
  assert.equal(normalizeFilePath('``src/foo.ts`` (current state)'), 'src/foo.ts')
31
31
  })
32
32
 
33
+ it('strips stray backticks from dash-annotated bare paths (#4550)', () => {
34
+ assert.equal(
35
+ normalizeFilePath('.gsd/KNOWLEDGE.md` — append-only S05 lessons section'),
36
+ '.gsd/KNOWLEDGE.md',
37
+ )
38
+ })
39
+
40
+ it('prefers a backticked path inside a dash-annotated prefix (#4550)', () => {
41
+ assert.equal(
42
+ normalizeFilePath('Input `src/foo.ts` — current state'),
43
+ 'src/foo.ts',
44
+ )
45
+ })
46
+
33
47
  it('strips backticks even when mixed with other normalization', () => {
34
48
  assert.equal(normalizeFilePath('`./src//bar.ts`'), 'src/bar.ts')
35
49
  })
@@ -140,6 +140,25 @@ import type { Request } from 'express';
140
140
  assert.ok(packages.includes("typescript"));
141
141
  assert.ok(!packages.includes("-D"));
142
142
  });
143
+
144
+ // Regression tests for #4388: prose containing `from "..."` must not produce false-positive packages
145
+ test("does not treat prose 'from \"What's Next\"' as a package name (#4388)", () => {
146
+ const desc = 'Build the feature described from "What\'s Next" in the roadmap';
147
+ const packages = extractPackageReferences(desc);
148
+ assert.deepEqual(packages, [], `prose 'from "What\\'s Next"' must not produce package names, got: ${JSON.stringify(packages)}`);
149
+ });
150
+
151
+ test("does not treat prose \"from 'master'\" as a package name (#4388)", () => {
152
+ const desc = "Review changes from 'master' branch before merging";
153
+ const packages = extractPackageReferences(desc);
154
+ assert.deepEqual(packages, [], `prose "from 'master'" must not produce package names, got: ${JSON.stringify(packages)}`);
155
+ });
156
+
157
+ test("still extracts import statements in code blocks after #4388 fix", () => {
158
+ const desc = "```typescript\nimport express from 'express';\nimport { Router } from 'express';\n```";
159
+ const packages = extractPackageReferences(desc);
160
+ assert.ok(packages.includes("express"), "import...from in code blocks must still be recognized");
161
+ });
143
162
  });
144
163
 
145
164
  // ─── File Path Consistency Tests ─────────────────────────────────────────────
@@ -186,6 +186,45 @@ test("flat_rate_providers is a recognized preference key (no warning)", () => {
186
186
  );
187
187
  });
188
188
 
189
+ test("slice_parallel preferences validate and pass through", () => {
190
+ const { preferences, errors, warnings } = validatePreferences({
191
+ slice_parallel: { enabled: true, max_workers: 8 },
192
+ });
193
+
194
+ assert.equal(errors.length, 0);
195
+ assert.equal(warnings.filter(w => w.includes("slice_parallel")).length, 0);
196
+ assert.deepEqual(preferences.slice_parallel, { enabled: true, max_workers: 8 });
197
+ });
198
+
199
+ test("slice_parallel rejects invalid values and warns on unknown keys", () => {
200
+ const { preferences, errors, warnings } = validatePreferences({
201
+ slice_parallel: {
202
+ enabled: "yes",
203
+ max_workers: 9,
204
+ future_mode: true,
205
+ },
206
+ } as any);
207
+
208
+ assert.ok(errors.some(e => e.includes("slice_parallel.enabled")), "should reject non-boolean enabled");
209
+ assert.ok(errors.some(e => e.includes("slice_parallel.max_workers")), "should reject max_workers outside 1..8");
210
+ assert.ok(warnings.some(w => w.includes('unknown slice_parallel key "future_mode"')));
211
+ assert.equal(preferences.slice_parallel, undefined);
212
+ });
213
+
214
+ test("slice_parallel numeric max_workers is bounded to 1..8", () => {
215
+ const low = validatePreferences({ slice_parallel: { max_workers: 1 } });
216
+ const high = validatePreferences({ slice_parallel: { max_workers: 8 } });
217
+ const tooLow = validatePreferences({ slice_parallel: { max_workers: 0 } });
218
+ const tooHigh = validatePreferences({ slice_parallel: { max_workers: 9 } });
219
+
220
+ assert.equal(low.errors.length, 0);
221
+ assert.equal(low.preferences.slice_parallel?.max_workers, 1);
222
+ assert.equal(high.errors.length, 0);
223
+ assert.equal(high.preferences.slice_parallel?.max_workers, 8);
224
+ assert.ok(tooLow.errors.some(e => e.includes("slice_parallel.max_workers")));
225
+ assert.ok(tooHigh.errors.some(e => e.includes("slice_parallel.max_workers")));
226
+ });
227
+
189
228
  test("valid values pass through correctly", () => {
190
229
  const { preferences: p1 } = validatePreferences({ budget_enforcement: "halt" });
191
230
  assert.equal(p1.budget_enforcement, "halt");
@@ -606,6 +645,44 @@ test("loadEffectiveGSDPreferences preserves experimental prefs across global+pro
606
645
  }
607
646
  });
608
647
 
648
+ test("loadEffectiveGSDPreferences exposes slice_parallel prefs to runtime callers", () => {
649
+ const originalCwd = process.cwd();
650
+ const originalGsdHome = process.env.GSD_HOME;
651
+ const tempProject = mkdtempSync(join(tmpdir(), "gsd-slice-parallel-project-"));
652
+ const tempGsdHome = mkdtempSync(join(tmpdir(), "gsd-slice-parallel-home-"));
653
+
654
+ try {
655
+ mkdirSync(join(tempProject, ".gsd"), { recursive: true });
656
+
657
+ writeFileSync(
658
+ join(tempProject, ".gsd", "PREFERENCES.md"),
659
+ [
660
+ "---",
661
+ "version: 1",
662
+ "slice_parallel:",
663
+ " enabled: true",
664
+ " max_workers: 3",
665
+ "---",
666
+ ].join("\n"),
667
+ "utf-8",
668
+ );
669
+
670
+ process.env.GSD_HOME = tempGsdHome;
671
+ process.chdir(tempProject);
672
+
673
+ const loaded = loadEffectiveGSDPreferences();
674
+ assert.notEqual(loaded, null);
675
+ assert.equal(loaded!.preferences.slice_parallel?.enabled, true);
676
+ assert.equal(loaded!.preferences.slice_parallel?.max_workers, 3);
677
+ } finally {
678
+ process.chdir(originalCwd);
679
+ if (originalGsdHome === undefined) delete process.env.GSD_HOME;
680
+ else process.env.GSD_HOME = originalGsdHome;
681
+ rmSync(tempProject, { recursive: true, force: true });
682
+ rmSync(tempGsdHome, { recursive: true, force: true });
683
+ }
684
+ });
685
+
609
686
  test("preferences paths use canonical uppercase filenames", () => {
610
687
  const originalCwd = process.cwd();
611
688
  const originalGsdHome = process.env.GSD_HOME;
@@ -632,6 +709,39 @@ test("preferences paths use canonical uppercase filenames", () => {
632
709
  }
633
710
  });
634
711
 
712
+ test("explicit base path preference loading survives a deleted cwd (#4498)", (t) => {
713
+ const originalCwd = process.cwd();
714
+ const originalGsdHome = process.env.GSD_HOME;
715
+ const tempProject = mkdtempSync(join(tmpdir(), "gsd-prefs-base-project-"));
716
+ const tempGsdHome = mkdtempSync(join(tmpdir(), "gsd-prefs-base-home-"));
717
+ const deletedCwd = mkdtempSync(join(tmpdir(), "gsd-prefs-deleted-cwd-"));
718
+
719
+ t.after(() => {
720
+ process.chdir(originalCwd);
721
+ if (originalGsdHome === undefined) delete process.env.GSD_HOME;
722
+ else process.env.GSD_HOME = originalGsdHome;
723
+ rmSync(tempProject, { recursive: true, force: true });
724
+ rmSync(tempGsdHome, { recursive: true, force: true });
725
+ rmSync(deletedCwd, { recursive: true, force: true });
726
+ });
727
+
728
+ mkdirSync(join(tempProject, ".gsd"), { recursive: true });
729
+ writeFileSync(
730
+ join(tempProject, ".gsd", "PREFERENCES.md"),
731
+ "---\nversion: 1\nlanguage: Swedish\ngit:\n isolation: worktree\n---\n",
732
+ "utf-8",
733
+ );
734
+
735
+ process.env.GSD_HOME = tempGsdHome;
736
+ process.chdir(deletedCwd);
737
+ rmSync(deletedCwd, { recursive: true, force: true });
738
+
739
+ const loaded = loadEffectiveGSDPreferences(tempProject);
740
+ assert.notEqual(loaded, null);
741
+ assert.equal(loaded!.preferences.language, "Swedish");
742
+ assert.equal(getIsolationMode(tempProject), "worktree");
743
+ });
744
+
635
745
  test("uppercase PREFERENCES.md wins over legacy lowercase preferences.md", () => {
636
746
  const originalCwd = process.cwd();
637
747
  const originalGsdHome = process.env.GSD_HOME;