@izkac/forgekit 0.3.11 → 0.3.13
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.
- package/bin/forge.mjs +107 -107
- package/bin/forgekit.mjs +83 -83
- package/bin/review.mjs +81 -81
- package/package.json +1 -1
- package/scripts/prepack.mjs +78 -78
- package/scripts/run-tests.mjs +50 -50
- package/src/adr.mjs +236 -236
- package/src/adr.test.mjs +170 -170
- package/src/change.mjs +327 -234
- package/src/change.test.mjs +145 -83
- package/src/cleanup-sessions.mjs +84 -84
- package/src/config.mjs +103 -103
- package/src/defer.mjs +75 -75
- package/src/doctor.mjs +350 -341
- package/src/doctor.test.mjs +114 -114
- package/src/init.mjs +680 -621
- package/src/install.mjs +815 -815
- package/src/install.test.mjs +180 -180
- package/src/integrity-check.mjs +60 -60
- package/src/integrity.mjs +682 -682
- package/src/integrity.test.mjs +566 -566
- package/src/lib.mjs +143 -143
- package/src/models.defaults.json +41 -41
- package/src/new-session.mjs +99 -99
- package/src/openspec-overlays/README.md +19 -19
- package/src/openspec-overlays/openspec-apply-change-footer.md +14 -14
- package/src/openspec-overlays/opsx-apply-completion-step.md +1 -1
- package/src/openspec-overlays/opsx-apply-implement-step.md +11 -11
- package/src/paths.mjs +92 -92
- package/src/plan-engine.mjs +321 -278
- package/src/plan-engine.test.mjs +447 -283
- package/src/preferences.defaults.json +78 -78
- package/src/preferences.mjs +438 -438
- package/src/preferences.test.mjs +174 -174
- package/src/record-evidence.mjs +204 -204
- package/src/resolve-model.mjs +312 -312
- package/src/resolve-model.test.mjs +194 -194
- package/src/review/cli.test.mjs +117 -117
- package/src/review/export.mjs +172 -172
- package/src/review/export.test.mjs +197 -197
- package/src/review/fixtures/valid-review.json +42 -42
- package/src/review/lib.mjs +894 -894
- package/src/review/lib.test.mjs +266 -266
- package/src/review/schema.json +196 -196
- package/src/review/signals.test.mjs +62 -62
- package/src/score-cli.mjs +68 -68
- package/src/score.mjs +568 -566
- package/src/score.test.mjs +366 -340
- package/src/session-reminder.mjs +207 -207
- package/src/session-status.mjs +70 -70
- package/src/set-models.mjs +186 -186
- package/src/set-phase.mjs +205 -205
- package/src/set-prefs.mjs +294 -294
- package/src/specs-sync.mjs +234 -0
- package/src/specs-sync.test.mjs +114 -0
- package/src/spine.mjs +93 -93
- package/src/triage-prompt.mjs +175 -175
- package/src/triage-prompt.test.mjs +50 -50
- package/src/vendor-openspec-overlays.mjs +176 -176
- package/src/vendor-openspec-overlays.test.mjs +62 -62
- package/vendor/skills/archive-to-adr/SKILL.md +149 -149
- package/vendor/skills/forge/SKILL.md +136 -136
- package/vendor/skills/forge/docs/forge.md +650 -647
- package/vendor/skills/forge/phases/brainstorm.md +23 -23
- package/vendor/skills/forge/phases/finish.md +90 -87
- package/vendor/skills/forge/phases/implement.md +77 -77
- package/vendor/skills/forge/phases/plan-openspec.md +60 -60
- package/vendor/skills/forge/phases/plan-specs.md +163 -117
- package/vendor/skills/forge/phases/review.md +25 -25
- package/vendor/skills/forge/phases/verify.md +124 -124
- package/vendor/skills/forge/references/forge-layout.md +85 -85
- package/vendor/skills/forge/references/pace.md +115 -115
- package/vendor/skills/forge/references/plan-routing.md +52 -51
- package/vendor/skills/forge/references/runtime-integrity.md +232 -225
- package/vendor/skills/forge/references/substantial-work.md +37 -37
- package/vendor/skills/forge/references/test-evidence.md +30 -30
- package/vendor/skills/forge/references/test-strategy.md +68 -68
- package/vendor/skills/forge/skills/subagent-driven-development/SKILL.md +87 -87
- package/vendor/skills/forge/subagents/final-reviewer-prompt.md +56 -56
- package/vendor/skills/forge/subagents/implementer-prompt.md +38 -38
- package/vendor/skills/git-resolve-adr-conflict/SKILL.md +132 -132
- package/vendor/skills/thorough-code-review/SKILL.md +290 -290
- package/vendor/skills/thorough-code-review/examples.md +133 -133
- package/vendor/skills/thorough-code-review/reference/accepted-risks.md +26 -26
- package/vendor/skills/thorough-code-review/reference/lenses.md +96 -96
- package/vendor/skills/thorough-code-review/reference/phase1-scout.md +62 -62
- package/vendor/skills/thorough-code-review/reference/phase2-skeptic.md +105 -105
- package/vendor/skills/thorough-code-review/reference/report-schema.json +222 -222
- package/vendor/skills/thorough-code-review/reference/report-template.md +115 -115
- package/vendor/skills/thorough-code-review/reference/severity-rubric.md +49 -49
- package/vendor/skills/thorough-code-review/reference/signals-preflight.md +55 -55
- package/vendor/templates/adr/README.md +7 -7
- package/vendor/templates/adr/decisions.md +141 -141
- package/vendor/templates/adr/hooks/check-pending-adrs.mjs +74 -74
- package/vendor/templates/adr/hooks/check-pending-adrs.sh +3 -3
- package/vendor/templates/adr/hooks/openspec-archive-agent-message.mjs +52 -52
- package/vendor/templates/adr/hooks/openspec-archive-agent-message.sh +3 -3
- package/vendor/templates/project/claude/commands/forge-apply.md +75 -75
- package/vendor/templates/project/claude/commands/forge-brainstorm.md +7 -7
- package/vendor/templates/project/claude/commands/forge-build.md +17 -17
- package/vendor/templates/project/claude/commands/forge-plan.md +12 -12
- package/vendor/templates/project/claude/commands/forge-skip.md +14 -14
- package/vendor/templates/project/claude/commands/forge-status.md +16 -16
- package/vendor/templates/project/claude/commands/forge.md +16 -16
- package/vendor/templates/project/claude/hooks/forge-prompt-hook.mjs +73 -73
- package/vendor/templates/project/claude/hooks/forge-session-start.mjs +19 -19
- package/vendor/templates/project/claude/hooks/forge-triage-hook.mjs +77 -77
- package/vendor/templates/project/cursor/commands/forge-apply.md +75 -75
- package/vendor/templates/project/cursor/commands/forge-brainstorm.md +10 -10
- package/vendor/templates/project/cursor/commands/forge-build.md +17 -17
- package/vendor/templates/project/cursor/commands/forge-plan.md +15 -15
- package/vendor/templates/project/cursor/commands/forge-skip.md +14 -14
- package/vendor/templates/project/cursor/commands/forge-status.md +16 -16
- package/vendor/templates/project/cursor/commands/forge.md +16 -16
- package/vendor/templates/project/cursor/hooks/forge-session-start.mjs +30 -30
- package/vendor/templates/project/cursor/hooks/forge-session-start.sh +3 -3
package/src/plan-engine.test.mjs
CHANGED
|
@@ -1,283 +1,447 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import {
|
|
7
|
-
DEFAULT_SPECS_DIR,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
writeProjectPlanConfig(cwd, { engine: '
|
|
58
|
-
|
|
59
|
-
assert.equal(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
assert.equal(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
assert.equal(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
assert.equal(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
assert.
|
|
223
|
-
assert.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
assert.equal(
|
|
238
|
-
assert.
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_SPECS_DIR,
|
|
8
|
+
DEFAULT_OPENSPEC_DIR,
|
|
9
|
+
PLAN_ENGINES,
|
|
10
|
+
hasOpenSpecConfig,
|
|
11
|
+
loadUserPlanEngine,
|
|
12
|
+
normalizePlanDir,
|
|
13
|
+
resolveProjectPlanEngine,
|
|
14
|
+
saveUserPlanEngine,
|
|
15
|
+
scaffoldSpecs,
|
|
16
|
+
setupOpenSpec,
|
|
17
|
+
toOpenSpecToolIds,
|
|
18
|
+
writeProjectPlanConfig,
|
|
19
|
+
} from './plan-engine.mjs';
|
|
20
|
+
import { loadProjectConfig, loadUserConfig, saveUserConfig } from './adr.mjs';
|
|
21
|
+
import { parseArgs as parseInstallArgs } from './install.mjs';
|
|
22
|
+
import {
|
|
23
|
+
parseArgs as parseInitArgs,
|
|
24
|
+
initProject,
|
|
25
|
+
resolveInitPlanEngine,
|
|
26
|
+
} from './init.mjs';
|
|
27
|
+
import { runDoctorChecks } from './doctor.mjs';
|
|
28
|
+
|
|
29
|
+
function tmpdir(prefix) {
|
|
30
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
test('user plan engine round-trip preserves adr config', () => {
|
|
34
|
+
const home = tmpdir('forgekit-plan-user-');
|
|
35
|
+
try {
|
|
36
|
+
saveUserConfig({ adr: { enabled: true, dir: 'docs/adr' } }, home);
|
|
37
|
+
saveUserPlanEngine('specs', home);
|
|
38
|
+
assert.equal(loadUserPlanEngine(home), 'specs');
|
|
39
|
+
assert.equal(loadUserConfig(home).adr.enabled, true);
|
|
40
|
+
saveUserPlanEngine('openspec', home);
|
|
41
|
+
assert.equal(loadUserPlanEngine(home), 'openspec');
|
|
42
|
+
assert.throws(() => saveUserPlanEngine('bogus', home), /Unknown plan engine/);
|
|
43
|
+
} finally {
|
|
44
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('writeProjectPlanConfig preserves adr block and sets dir for specs', () => {
|
|
49
|
+
const cwd = tmpdir('forgekit-plan-proj-');
|
|
50
|
+
try {
|
|
51
|
+
fs.mkdirSync(path.join(cwd, '.forge'), { recursive: true });
|
|
52
|
+
fs.writeFileSync(
|
|
53
|
+
path.join(cwd, '.forge', 'config.json'),
|
|
54
|
+
JSON.stringify({ adr: { enabled: true, dir: 'docs/adr' } }),
|
|
55
|
+
'utf8',
|
|
56
|
+
);
|
|
57
|
+
writeProjectPlanConfig(cwd, { engine: 'specs' });
|
|
58
|
+
const cfg = loadProjectConfig(cwd);
|
|
59
|
+
assert.equal(cfg.plan.engine, 'specs');
|
|
60
|
+
assert.equal(cfg.plan.dir, DEFAULT_SPECS_DIR);
|
|
61
|
+
assert.equal(cfg.adr.enabled, true);
|
|
62
|
+
|
|
63
|
+
writeProjectPlanConfig(cwd, { engine: 'openspec' });
|
|
64
|
+
assert.equal(loadProjectConfig(cwd).plan.engine, 'openspec');
|
|
65
|
+
assert.equal(loadProjectConfig(cwd).plan.dir, undefined);
|
|
66
|
+
} finally {
|
|
67
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('resolveProjectPlanEngine precedence: project > detection > user > default', () => {
|
|
72
|
+
const cwd = tmpdir('forgekit-plan-res-');
|
|
73
|
+
const home = tmpdir('forgekit-plan-res-home-');
|
|
74
|
+
try {
|
|
75
|
+
// default
|
|
76
|
+
assert.equal(
|
|
77
|
+
resolveProjectPlanEngine(cwd, { home }).engine,
|
|
78
|
+
'openspec',
|
|
79
|
+
);
|
|
80
|
+
assert.equal(resolveProjectPlanEngine(cwd, { home }).dir, DEFAULT_OPENSPEC_DIR);
|
|
81
|
+
assert.equal(resolveProjectPlanEngine(cwd, { home }).source, 'default');
|
|
82
|
+
|
|
83
|
+
// user default
|
|
84
|
+
saveUserPlanEngine('specs', home);
|
|
85
|
+
const viaUser = resolveProjectPlanEngine(cwd, { home });
|
|
86
|
+
assert.equal(viaUser.engine, 'specs');
|
|
87
|
+
assert.equal(viaUser.dir, DEFAULT_SPECS_DIR);
|
|
88
|
+
assert.equal(viaUser.source, 'user');
|
|
89
|
+
|
|
90
|
+
// useUserDefault=false ignores user config
|
|
91
|
+
assert.equal(
|
|
92
|
+
resolveProjectPlanEngine(cwd, { home, useUserDefault: false }).source,
|
|
93
|
+
'default',
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// openspec detection beats user default
|
|
97
|
+
fs.mkdirSync(path.join(cwd, 'openspec'), { recursive: true });
|
|
98
|
+
fs.writeFileSync(path.join(cwd, 'openspec', 'config.yaml'), 'name: x\n', 'utf8');
|
|
99
|
+
assert.equal(hasOpenSpecConfig(cwd), true);
|
|
100
|
+
const detected = resolveProjectPlanEngine(cwd, { home });
|
|
101
|
+
assert.equal(detected.engine, 'openspec');
|
|
102
|
+
assert.equal(detected.dir, DEFAULT_OPENSPEC_DIR);
|
|
103
|
+
assert.equal(detected.source, 'detected');
|
|
104
|
+
|
|
105
|
+
// project config beats detection
|
|
106
|
+
writeProjectPlanConfig(cwd, { engine: 'specs', dir: 'specs' });
|
|
107
|
+
const viaProject = resolveProjectPlanEngine(cwd, { home });
|
|
108
|
+
assert.equal(viaProject.engine, 'specs');
|
|
109
|
+
assert.equal(viaProject.source, 'project');
|
|
110
|
+
} finally {
|
|
111
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
112
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('normalizePlanDir rejects absolute and parent paths', () => {
|
|
117
|
+
assert.equal(normalizePlanDir('openspec'), 'openspec');
|
|
118
|
+
assert.equal(normalizePlanDir('./specs/'), 'specs');
|
|
119
|
+
assert.throws(() => normalizePlanDir('/tmp/x'), /relative/);
|
|
120
|
+
assert.throws(() => normalizePlanDir('../x'), /relative/);
|
|
121
|
+
assert.throws(() => normalizePlanDir(''), /non-empty/);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('scaffoldSpecs writes README + changes/archive + main specs catalog', () => {
|
|
125
|
+
const cwd = tmpdir('forgekit-specs-scaffold-');
|
|
126
|
+
try {
|
|
127
|
+
const result = scaffoldSpecs(cwd, { force: true });
|
|
128
|
+
assert.equal(result.dir, DEFAULT_SPECS_DIR);
|
|
129
|
+
assert.ok(fs.existsSync(path.join(cwd, 'specs', 'README.md')));
|
|
130
|
+
assert.ok(fs.existsSync(path.join(cwd, 'specs', 'changes', 'archive')));
|
|
131
|
+
assert.ok(fs.existsSync(path.join(cwd, 'specs', 'specs', '.gitkeep')));
|
|
132
|
+
const readme = fs.readFileSync(path.join(cwd, 'specs', 'README.md'), 'utf8');
|
|
133
|
+
assert.match(readme, /changes\/<change-name>/);
|
|
134
|
+
assert.match(readme, /tasks\.md/);
|
|
135
|
+
assert.match(readme, /ADDED \/ MODIFIED \/ REMOVED/);
|
|
136
|
+
|
|
137
|
+
// second run without force skips
|
|
138
|
+
const again = scaffoldSpecs(cwd);
|
|
139
|
+
assert.ok(again.files.some((f) => f.status === 'skipped'));
|
|
140
|
+
} finally {
|
|
141
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('scaffoldSpecs + init honor custom plan.dir (e.g. openspec)', () => {
|
|
146
|
+
const cwd = tmpdir('forgekit-plan-dir-');
|
|
147
|
+
try {
|
|
148
|
+
const report = initProject(['codex'], {
|
|
149
|
+
cwd,
|
|
150
|
+
force: true,
|
|
151
|
+
planEngine: 'specs',
|
|
152
|
+
planDir: 'openspec',
|
|
153
|
+
});
|
|
154
|
+
assert.equal(report.plan.engine, 'specs');
|
|
155
|
+
assert.equal(report.plan.dir, 'openspec');
|
|
156
|
+
assert.equal(loadProjectConfig(cwd).plan.dir, 'openspec');
|
|
157
|
+
assert.ok(fs.existsSync(path.join(cwd, 'openspec', 'changes')));
|
|
158
|
+
assert.ok(fs.existsSync(path.join(cwd, 'openspec', 'specs')));
|
|
159
|
+
} finally {
|
|
160
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('init parseArgs --plan-dir', () => {
|
|
165
|
+
assert.equal(parseInitArgs(['--plan-dir', 'openspec']).planDir, 'openspec');
|
|
166
|
+
assert.equal(parseInitArgs([]).planDir, null);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('setupOpenSpec runs install + init via injected runner', () => {
|
|
170
|
+
const cwd = tmpdir('forgekit-openspec-setup-');
|
|
171
|
+
try {
|
|
172
|
+
/** @type {string[]} */
|
|
173
|
+
const calls = [];
|
|
174
|
+
const runCommand = (cmd, args) => {
|
|
175
|
+
const line = [cmd, ...args].join(' ');
|
|
176
|
+
calls.push(line);
|
|
177
|
+
if (line === 'openspec --version') return { status: 1, stdout: '' };
|
|
178
|
+
if (line.startsWith('npm install -g')) return { status: 0, stdout: '' };
|
|
179
|
+
if (line === 'openspec init') {
|
|
180
|
+
fs.mkdirSync(path.join(cwd, 'openspec'), { recursive: true });
|
|
181
|
+
fs.writeFileSync(path.join(cwd, 'openspec', 'config.yaml'), 'x: 1\n', 'utf8');
|
|
182
|
+
return { status: 0, stdout: '' };
|
|
183
|
+
}
|
|
184
|
+
return { status: 1, stdout: '' };
|
|
185
|
+
};
|
|
186
|
+
const result = setupOpenSpec(cwd, { runCommand });
|
|
187
|
+
assert.equal(result.ok, true);
|
|
188
|
+
assert.ok(calls.some((c) => c.startsWith('npm install -g')));
|
|
189
|
+
assert.ok(calls.includes('openspec init'));
|
|
190
|
+
} finally {
|
|
191
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('toOpenSpecToolIds maps copilot → github-copilot, else identity', () => {
|
|
196
|
+
assert.deepEqual(
|
|
197
|
+
toOpenSpecToolIds(['claude', 'cursor', 'codex', 'opencode', 'copilot', 'gemini', 'windsurf']),
|
|
198
|
+
['claude', 'cursor', 'codex', 'opencode', 'github-copilot', 'gemini', 'windsurf'],
|
|
199
|
+
);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('setupOpenSpec passes selected tools to `openspec init --tools`', () => {
|
|
203
|
+
const cwd = tmpdir('forgekit-openspec-tools-');
|
|
204
|
+
try {
|
|
205
|
+
/** @type {string[]} */
|
|
206
|
+
const calls = [];
|
|
207
|
+
const runCommand = (cmd, args) => {
|
|
208
|
+
const line = [cmd, ...args].join(' ');
|
|
209
|
+
calls.push(line);
|
|
210
|
+
if (line === 'openspec --version') return { status: 0, stdout: '1.0.0' };
|
|
211
|
+
if (line.startsWith('openspec init')) {
|
|
212
|
+
fs.mkdirSync(path.join(cwd, 'openspec'), { recursive: true });
|
|
213
|
+
fs.writeFileSync(path.join(cwd, 'openspec', 'config.yaml'), 'x: 1\n', 'utf8');
|
|
214
|
+
return { status: 0, stdout: '' };
|
|
215
|
+
}
|
|
216
|
+
return { status: 1, stdout: '' };
|
|
217
|
+
};
|
|
218
|
+
const result = setupOpenSpec(cwd, {
|
|
219
|
+
runCommand,
|
|
220
|
+
tools: ['claude', 'cursor', 'codex', 'copilot'],
|
|
221
|
+
});
|
|
222
|
+
assert.equal(result.ok, true);
|
|
223
|
+
assert.ok(
|
|
224
|
+
calls.includes('openspec init --tools claude,cursor,codex,github-copilot'),
|
|
225
|
+
`expected --tools call, got: ${calls.join(' | ')}`,
|
|
226
|
+
);
|
|
227
|
+
} finally {
|
|
228
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('setupOpenSpec reports failure when install fails', () => {
|
|
233
|
+
const cwd = tmpdir('forgekit-openspec-fail-');
|
|
234
|
+
try {
|
|
235
|
+
const runCommand = () => ({ status: 1, stdout: '' });
|
|
236
|
+
const result = setupOpenSpec(cwd, { runCommand });
|
|
237
|
+
assert.equal(result.ok, false);
|
|
238
|
+
assert.ok(result.steps.some((s) => !s.ok));
|
|
239
|
+
} finally {
|
|
240
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('install parseArgs --openspec / --no-openspec', () => {
|
|
245
|
+
assert.equal(parseInstallArgs(['--openspec']).openspec, true);
|
|
246
|
+
assert.equal(parseInstallArgs(['--no-openspec']).openspec, false);
|
|
247
|
+
assert.equal(parseInstallArgs([]).openspec, null);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('init parseArgs --openspec / --no-openspec', () => {
|
|
251
|
+
assert.equal(parseInitArgs(['--openspec']).openspec, true);
|
|
252
|
+
assert.equal(parseInitArgs(['--no-openspec']).openspec, false);
|
|
253
|
+
assert.equal(parseInitArgs([]).openspec, null);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test('initProject planEngine=specs scaffolds and writes config', () => {
|
|
257
|
+
const cwd = tmpdir('forgekit-init-specs-');
|
|
258
|
+
try {
|
|
259
|
+
const report = initProject(['codex'], {
|
|
260
|
+
cwd,
|
|
261
|
+
force: true,
|
|
262
|
+
planEngine: 'specs',
|
|
263
|
+
});
|
|
264
|
+
assert.equal(report.plan.engine, 'specs');
|
|
265
|
+
assert.ok(fs.existsSync(path.join(cwd, 'specs', 'README.md')));
|
|
266
|
+
assert.equal(loadProjectConfig(cwd).plan.engine, 'specs');
|
|
267
|
+
} finally {
|
|
268
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('initProject planEngine=openspec records engine without scaffolding specs', () => {
|
|
273
|
+
const cwd = tmpdir('forgekit-init-os-');
|
|
274
|
+
try {
|
|
275
|
+
const report = initProject(['codex'], {
|
|
276
|
+
cwd,
|
|
277
|
+
force: true,
|
|
278
|
+
planEngine: 'openspec',
|
|
279
|
+
});
|
|
280
|
+
assert.equal(report.plan.engine, 'openspec');
|
|
281
|
+
assert.equal(report.plan.configured, false);
|
|
282
|
+
assert.ok(!fs.existsSync(path.join(cwd, 'specs')));
|
|
283
|
+
assert.equal(loadProjectConfig(cwd).plan.engine, 'openspec');
|
|
284
|
+
} finally {
|
|
285
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('resolveInitPlanEngine: setup failure keeps openspec (no specs fallback)', async () => {
|
|
290
|
+
const cwd = tmpdir('forgekit-resolve-fail-');
|
|
291
|
+
try {
|
|
292
|
+
const engine = await resolveInitPlanEngine({
|
|
293
|
+
cwd,
|
|
294
|
+
openspec: null,
|
|
295
|
+
isTTY: true,
|
|
296
|
+
loadUser: () => 'openspec',
|
|
297
|
+
confirmSetup: async () => true,
|
|
298
|
+
setup: () => ({
|
|
299
|
+
ok: false,
|
|
300
|
+
steps: [{ step: 'openspec init', ok: false, detail: 'exit 1' }],
|
|
301
|
+
}),
|
|
302
|
+
});
|
|
303
|
+
assert.equal(engine, 'openspec');
|
|
304
|
+
} finally {
|
|
305
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test('resolveInitPlanEngine: declining setup keeps openspec when user default is openspec', async () => {
|
|
310
|
+
const cwd = tmpdir('forgekit-resolve-decline-');
|
|
311
|
+
try {
|
|
312
|
+
const engine = await resolveInitPlanEngine({
|
|
313
|
+
cwd,
|
|
314
|
+
openspec: null,
|
|
315
|
+
isTTY: true,
|
|
316
|
+
loadUser: () => 'openspec',
|
|
317
|
+
confirmSetup: async () => false,
|
|
318
|
+
setup: () => {
|
|
319
|
+
throw new Error('setup should not run when declined');
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
assert.equal(engine, 'openspec');
|
|
323
|
+
} finally {
|
|
324
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test('resolveInitPlanEngine: --openspec keeps openspec even when setup fails', async () => {
|
|
329
|
+
const cwd = tmpdir('forgekit-resolve-flag-');
|
|
330
|
+
try {
|
|
331
|
+
const engine = await resolveInitPlanEngine({
|
|
332
|
+
cwd,
|
|
333
|
+
openspec: true,
|
|
334
|
+
isTTY: true,
|
|
335
|
+
setup: () => ({
|
|
336
|
+
ok: false,
|
|
337
|
+
steps: [{ step: 'openspec init', ok: false }],
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
assert.equal(engine, 'openspec');
|
|
341
|
+
} finally {
|
|
342
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('resolveInitPlanEngine: interactive engine pick openspec survives setup failure', async () => {
|
|
347
|
+
const cwd = tmpdir('forgekit-resolve-pick-');
|
|
348
|
+
try {
|
|
349
|
+
const engine = await resolveInitPlanEngine({
|
|
350
|
+
cwd,
|
|
351
|
+
openspec: null,
|
|
352
|
+
isTTY: true,
|
|
353
|
+
loadUser: () => null,
|
|
354
|
+
promptEngine: async () => true,
|
|
355
|
+
confirmSetup: async () => true,
|
|
356
|
+
setup: () => ({
|
|
357
|
+
ok: false,
|
|
358
|
+
steps: [{ step: 'openspec init', ok: false }],
|
|
359
|
+
}),
|
|
360
|
+
});
|
|
361
|
+
assert.equal(engine, 'openspec');
|
|
362
|
+
} finally {
|
|
363
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test('resolveInitPlanEngine: interactive engine pick specs skips setup', async () => {
|
|
368
|
+
const cwd = tmpdir('forgekit-resolve-specs-pick-');
|
|
369
|
+
try {
|
|
370
|
+
const engine = await resolveInitPlanEngine({
|
|
371
|
+
cwd,
|
|
372
|
+
openspec: null,
|
|
373
|
+
isTTY: true,
|
|
374
|
+
loadUser: () => null,
|
|
375
|
+
promptEngine: async () => false,
|
|
376
|
+
setup: () => {
|
|
377
|
+
throw new Error('setup should not run for specs');
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
assert.equal(engine, 'specs');
|
|
381
|
+
} finally {
|
|
382
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test('resolveInitPlanEngine: --no-openspec and user specs default', async () => {
|
|
387
|
+
const cwd = tmpdir('forgekit-resolve-no-');
|
|
388
|
+
try {
|
|
389
|
+
assert.equal(
|
|
390
|
+
await resolveInitPlanEngine({ cwd, openspec: false, isTTY: true }),
|
|
391
|
+
'specs',
|
|
392
|
+
);
|
|
393
|
+
assert.equal(
|
|
394
|
+
await resolveInitPlanEngine({
|
|
395
|
+
cwd,
|
|
396
|
+
openspec: null,
|
|
397
|
+
isTTY: true,
|
|
398
|
+
loadUser: () => 'specs',
|
|
399
|
+
promptEngine: async () => {
|
|
400
|
+
throw new Error('should not ask when user default is specs');
|
|
401
|
+
},
|
|
402
|
+
}),
|
|
403
|
+
'specs',
|
|
404
|
+
);
|
|
405
|
+
} finally {
|
|
406
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test('doctor: specs engine checks specs layout instead of OpenSpec CLI', () => {
|
|
411
|
+
const cwd = tmpdir('forgekit-doctor-specs-');
|
|
412
|
+
try {
|
|
413
|
+
writeProjectPlanConfig(cwd, { engine: 'specs' });
|
|
414
|
+
|
|
415
|
+
const missing = runDoctorChecks({ cwd });
|
|
416
|
+
assert.equal(missing.engine, 'specs');
|
|
417
|
+
assert.equal(missing.ok, false);
|
|
418
|
+
assert.match(missing.checks.project.message, /specs\/changes/);
|
|
419
|
+
assert.equal(missing.checks.cli.ok, true);
|
|
420
|
+
assert.equal(missing.checks.cli.skipped, true);
|
|
421
|
+
|
|
422
|
+
scaffoldSpecs(cwd);
|
|
423
|
+
const present = runDoctorChecks({ cwd });
|
|
424
|
+
assert.equal(present.ok, true);
|
|
425
|
+
} finally {
|
|
426
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test('doctor: openspec engine unchanged for openspec projects', () => {
|
|
431
|
+
const cwd = tmpdir('forgekit-doctor-os-');
|
|
432
|
+
try {
|
|
433
|
+
const report = runDoctorChecks({
|
|
434
|
+
cwd,
|
|
435
|
+
existsSync: () => true,
|
|
436
|
+
runCommand: () => ({ status: 0, stdout: '1.0.0', stderr: '' }),
|
|
437
|
+
});
|
|
438
|
+
assert.equal(report.engine, 'openspec');
|
|
439
|
+
assert.equal(report.ok, true);
|
|
440
|
+
} finally {
|
|
441
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test('PLAN_ENGINES is the closed engine set', () => {
|
|
446
|
+
assert.deepEqual([...PLAN_ENGINES], ['openspec', 'specs']);
|
|
447
|
+
});
|