@moritakaaz/markflow 0.0.0-stage → 0.2.0

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 (41) hide show
  1. package/README.md +32 -2
  2. package/package.json +21 -4
  3. package/src/agents.js +17 -0
  4. package/src/discover.js +188 -0
  5. package/src/doctor.js +284 -0
  6. package/src/hash.js +7 -0
  7. package/src/index.js +61 -0
  8. package/src/init.js +228 -0
  9. package/src/minimal.js +22 -0
  10. package/src/templates.js +17 -0
  11. package/src/update.js +146 -0
  12. package/src/versions.js +6 -0
  13. package/templates/AGENTS.md +26 -0
  14. package/templates/markflow/.agents/MEMORY.md +17 -0
  15. package/templates/markflow/.agents/PROMPTS.md +21 -0
  16. package/templates/markflow/.agents/RULES.md +7 -0
  17. package/templates/markflow/.agents/mcp.json +3 -0
  18. package/templates/markflow/.agents/workflows/create-feature.md +14 -0
  19. package/templates/markflow/.agents/workflows/implement-spec.md +13 -0
  20. package/templates/markflow/.agents/workflows/onboarding.md +22 -0
  21. package/templates/markflow/.agents/workflows/pre-deploy-check.md +13 -0
  22. package/templates/markflow/.agents/workflows/review-spec.md +13 -0
  23. package/templates/markflow/.agents/workflows/sync-docs.md +13 -0
  24. package/templates/markflow/CHANGELOG.md +9 -0
  25. package/templates/markflow/README.md +30 -0
  26. package/templates/markflow/TASKS.md +13 -0
  27. package/templates/markflow/docs/API.md +24 -0
  28. package/templates/markflow/docs/ARCHITECTURE.md +29 -0
  29. package/templates/markflow/docs/CODING_STANDARDS.md +40 -0
  30. package/templates/markflow/docs/DATA_MODEL.md +23 -0
  31. package/templates/markflow/docs/DEPLOY.md +23 -0
  32. package/templates/markflow/docs/GLOSSARY.md +16 -0
  33. package/templates/markflow/docs/MCP.md +19 -0
  34. package/templates/markflow/docs/PRD.md +29 -0
  35. package/templates/markflow/docs/STACK.md +19 -0
  36. package/templates/markflow/docs/TESTING.md +27 -0
  37. package/templates/markflow/docs/adr/001-initial-stack.md +25 -0
  38. package/templates/markflow/docs/adr/_template.md +27 -0
  39. package/templates/markflow/specs/_template.md +33 -0
  40. package/templates/markflow/specs/index.md +15 -0
  41. package/test/cli.test.js +590 -0
@@ -0,0 +1,590 @@
1
+ // Tests for the Markflow CLI.
2
+ // Run them with npm test from packages/cli.
3
+ // Each test uses its own temp dir, so tests never touch real repos.
4
+ import { describe, it } from "node:test";
5
+ import assert from "node:assert/strict";
6
+ import { spawnSync } from "node:child_process";
7
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
8
+ import { tmpdir } from "node:os";
9
+ import { dirname, join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { discover } from "../src/discover.js";
12
+ import { runDoctor } from "../src/doctor.js";
13
+ import { fillArchitecture, runInit } from "../src/init.js";
14
+ import { runUpdate } from "../src/update.js";
15
+
16
+ const CLI = join(dirname(fileURLToPath(import.meta.url)), "../src/index.js");
17
+
18
+ async function tempDir(t) {
19
+ const dir = await mkdtemp(join(tmpdir(), "markflow-test-"));
20
+ t.after(() => rm(dir, { recursive: true, force: true }));
21
+ return dir;
22
+ }
23
+
24
+ async function write(dir, rel, text) {
25
+ const full = join(dir, rel);
26
+ await mkdir(dirname(full), { recursive: true });
27
+ await writeFile(full, text);
28
+ }
29
+
30
+ function runCli(args, cwd) {
31
+ return spawnSync("node", [CLI, ...args], { cwd, encoding: "utf8" });
32
+ }
33
+
34
+ describe("discover", () => {
35
+ it("empty dir is greenfield with TBD stack", async (t) => {
36
+ const dir = await tempDir(t);
37
+ const result = await discover(dir);
38
+ assert.equal(result.mode, "greenfield");
39
+ assert.equal(result.stack, "TBD");
40
+ assert.deepEqual(result.stacks, []);
41
+ assert.equal(result.monorepo, false);
42
+ });
43
+
44
+ it("go.mod means Go with high confidence", async (t) => {
45
+ const dir = await tempDir(t);
46
+ await write(dir, "go.mod", "module demo");
47
+ const result = await discover(dir);
48
+ assert.equal(result.mode, "brownfield");
49
+ assert.equal(result.stack, "Go");
50
+ assert.equal(result.stacks[0].evidence, "go.mod");
51
+ assert.equal(result.stacks[0].confidence, "high");
52
+ });
53
+
54
+ it("two manifests at root means two stacks, not a monorepo", async (t) => {
55
+ const dir = await tempDir(t);
56
+ await write(dir, "package.json", "{}");
57
+ await write(dir, "composer.json", "{}");
58
+ const result = await discover(dir);
59
+ assert.equal(result.stacks.length, 2);
60
+ assert.equal(result.monorepo, false);
61
+ });
62
+
63
+ it("nested monorepo finds all four manifests", async (t) => {
64
+ const dir = await tempDir(t);
65
+ await write(dir, "package.json", "{}");
66
+ await write(dir, "apps/web/frontend/package.json", "{}");
67
+ await write(dir, "apps/api/package.json", "{}");
68
+ await write(dir, "packages/shared/package.json", "{}");
69
+ const result = await discover(dir);
70
+ assert.equal(result.manifests.length, 4);
71
+ assert.equal(result.monorepo, true);
72
+ });
73
+
74
+ it("workspace evidence marks a monorepo with one member", async (t) => {
75
+ const dir = await tempDir(t);
76
+ await write(dir, "package.json", '{"workspaces":["packages/*"]}');
77
+ await write(dir, "pnpm-workspace.yaml", "");
78
+ await write(dir, "packages/one/package.json", "{}");
79
+ const result = await discover(dir);
80
+ assert.equal(result.monorepo, true);
81
+ assert.equal(result.workspace.detected, true);
82
+ });
83
+
84
+ it("skips venv, target, and .next dirs", async (t) => {
85
+ const dir = await tempDir(t);
86
+ await write(dir, "package.json", "{}");
87
+ await write(dir, "venv/requirements.txt", "");
88
+ await write(dir, "target/Cargo.toml", "");
89
+ await write(dir, ".next/package.json", "{}");
90
+ const result = await discover(dir);
91
+ assert.deepEqual(
92
+ result.stacks.map((s) => s.name),
93
+ ["JavaScript"]
94
+ );
95
+ assert.deepEqual(result.manifests, ["package.json"]);
96
+ });
97
+
98
+ it("records test and CI configs", async (t) => {
99
+ const dir = await tempDir(t);
100
+ await write(dir, "vitest.config.ts", "");
101
+ await write(dir, ".github/workflows/ci.yml", "");
102
+ const result = await discover(dir);
103
+ assert.ok(result.configs.includes("vitest.config.ts"));
104
+ assert.ok(result.configs.includes(".github/workflows"));
105
+ });
106
+ });
107
+
108
+ describe("init", () => {
109
+ it("creates AGENTS.md and the markflow folder", async (t) => {
110
+ const dir = await tempDir(t);
111
+ const result = await runInit({ target: dir });
112
+ assert.equal(result.ok !== false, true);
113
+ const agents = await readFile(join(dir, "AGENTS.md"), "utf8");
114
+ assert.ok(agents.length > 0);
115
+ const marker = JSON.parse(
116
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
117
+ );
118
+ assert.equal(marker.project, dir.split("/").pop());
119
+ });
120
+
121
+ it("writes discovery into docs on a multi-stack repo", async (t) => {
122
+ const dir = await tempDir(t);
123
+ await write(dir, "package.json", "{}");
124
+ await write(dir, "composer.json", "{}");
125
+ await runInit({ target: dir });
126
+ const arch = await readFile(
127
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
128
+ "utf8"
129
+ );
130
+ assert.ok(arch.includes("Language. PHP, JavaScript") || arch.includes("Language. JavaScript, PHP"));
131
+ const stack = await readFile(join(dir, "markflow/docs/STACK.md"), "utf8");
132
+ assert.ok(stack.includes("Detected stacks"));
133
+ const marker = JSON.parse(
134
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
135
+ );
136
+ assert.equal(marker.discovery.stacks.length, 2);
137
+ });
138
+
139
+ it("never overwrites an existing agent file", async (t) => {
140
+ const dir = await tempDir(t);
141
+ await write(dir, "CLAUDE.md", "MY OWN RULES");
142
+ await runInit({ target: dir, agent: "claude" });
143
+ const text = await readFile(join(dir, "CLAUDE.md"), "utf8");
144
+ assert.equal(text, "MY OWN RULES");
145
+ });
146
+
147
+ it("rerun restores a deleted file", async (t) => {
148
+ const dir = await tempDir(t);
149
+ await runInit({ target: dir });
150
+ await rm(join(dir, "markflow/docs/STACK.md"));
151
+ await runInit({ target: dir });
152
+ const text = await readFile(join(dir, "markflow/docs/STACK.md"), "utf8");
153
+ assert.ok(text.includes("STACK.md"));
154
+ });
155
+
156
+ it("fillArchitecture fills language and evidence", () => {
157
+ const filled = fillArchitecture("- Language. TBD\n- Framework. TBD\n", {
158
+ stacks: [{ name: "Go", evidence: "go.mod", confidence: "high" }],
159
+ monorepo: false,
160
+ });
161
+ assert.ok(filled.includes("- Language. Go"));
162
+ assert.ok(filled.includes("- Evidence. go.mod (high)"));
163
+ assert.ok(filled.includes("- Monorepo. No"));
164
+ });
165
+
166
+ it("fillArchitecture throws when template lines are missing", () => {
167
+ assert.throws(
168
+ () =>
169
+ fillArchitecture("# ARCHITECTURE\n\nNo lines here.\n", {
170
+ stacks: [{ name: "Go", evidence: "go.mod", confidence: "high" }],
171
+ monorepo: false,
172
+ }),
173
+ /template changed/
174
+ );
175
+ });
176
+
177
+ it("minimal init creates only the minimal files", async (t) => {
178
+ const dir = await tempDir(t);
179
+ const result = await runInit({ target: dir, minimal: true });
180
+ assert.equal(result.minimal, true);
181
+ for (const file of [
182
+ "AGENTS.md",
183
+ "markflow/README.md",
184
+ "markflow/TASKS.md",
185
+ "markflow/docs/PRD.md",
186
+ "markflow/docs/ARCHITECTURE.md",
187
+ "markflow/specs/index.md",
188
+ "markflow/specs/_template.md",
189
+ ]) {
190
+ await readFile(join(dir, file), "utf8");
191
+ }
192
+ for (const file of [
193
+ "markflow/docs/STACK.md",
194
+ "markflow/docs/CODING_STANDARDS.md",
195
+ "markflow/CHANGELOG.md",
196
+ ]) {
197
+ await assert.rejects(readFile(join(dir, file), "utf8"));
198
+ }
199
+ const marker = JSON.parse(
200
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
201
+ );
202
+ assert.equal(marker.minimal, true);
203
+ });
204
+
205
+ it("full init upgrades a minimal project", async (t) => {
206
+ const dir = await tempDir(t);
207
+ await runInit({ target: dir, minimal: true });
208
+ const result = await runInit({ target: dir });
209
+ assert.equal(result.minimal, false);
210
+ await readFile(join(dir, "markflow/docs/STACK.md"), "utf8");
211
+ const marker = JSON.parse(
212
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
213
+ );
214
+ assert.equal(marker.minimal, false);
215
+ });
216
+
217
+ it("init suggests onboarding on first run only", async (t) => {
218
+ const dir = await tempDir(t);
219
+ const first = await runInit({ target: dir });
220
+ assert.equal(
221
+ first.nextStep,
222
+ "Open your AI tool and say: start onboarding."
223
+ );
224
+ const second = await runInit({ target: dir });
225
+ assert.equal(second.nextStep, undefined);
226
+ });
227
+
228
+ it("unknown agent fails and creates no files", async (t) => {
229
+ const dir = await tempDir(t);
230
+ const result = await runInit({ target: dir, agent: "bogus" });
231
+ assert.equal(result.ok, false);
232
+ await assert.rejects(readFile(join(dir, "AGENTS.md"), "utf8"));
233
+ });
234
+ });
235
+
236
+ describe("doctor", () => {
237
+ it("clean repo passes", async (t) => {
238
+ const dir = await tempDir(t);
239
+ await runInit({ target: dir });
240
+ const result = await runDoctor({ target: dir });
241
+ assert.equal(result.ok, true);
242
+ });
243
+
244
+ it("broken link fails", async (t) => {
245
+ const dir = await tempDir(t);
246
+ await runInit({ target: dir });
247
+ await write(dir, "markflow/docs/PRD.md", "[Missing](docs/NOPE.md)\n");
248
+ const result = await runDoctor({ target: dir });
249
+ assert.equal(result.ok, false);
250
+ });
251
+
252
+ it("unlisted spec is a warning only", async (t) => {
253
+ const dir = await tempDir(t);
254
+ await runInit({ target: dir });
255
+ await write(dir, "markflow/specs/99-new.md", "# Spec\n\nStatus\n\nDraft\n");
256
+ const result = await runDoctor({ target: dir });
257
+ assert.equal(result.ok, true);
258
+ assert.ok(result.warnings.some((w) => w.includes("99-new.md")));
259
+ });
260
+
261
+ it("warns on empty acceptance in a spec", async (t) => {
262
+ const dir = await tempDir(t);
263
+ await runInit({ target: dir });
264
+ await write(
265
+ dir,
266
+ "markflow/specs/01-test.md",
267
+ "# Test spec\n\n## Goal\n\nDo a thing.\n\n## Acceptance\n\nWrite how you will test this feature. List the main cases.\n\n## Status\n\nDraft\n"
268
+ );
269
+ const index = await readFile(
270
+ join(dir, "markflow/specs/index.md"),
271
+ "utf8"
272
+ );
273
+ await write(dir, "markflow/specs/index.md", index + "\n01-test.md\n");
274
+ const result = await runDoctor({ target: dir });
275
+ assert.equal(result.ok, true);
276
+ assert.ok(
277
+ result.warnings.some((w) => w.includes("01-test.md"))
278
+ );
279
+ });
280
+
281
+ it("warns on approved spec with TBD", async (t) => {
282
+ const dir = await tempDir(t);
283
+ await runInit({ target: dir });
284
+ await write(
285
+ dir,
286
+ "markflow/specs/01-test.md",
287
+ "# Test spec\n\n## Goal\n\nDo a thing with TBD parts.\n\n## Acceptance\n\n- The thing works.\n\n## Status\n\nApproved\n"
288
+ );
289
+ const index = await readFile(
290
+ join(dir, "markflow/specs/index.md"),
291
+ "utf8"
292
+ );
293
+ await write(dir, "markflow/specs/index.md", index + "\n01-test.md\n");
294
+ const result = await runDoctor({ target: dir });
295
+ assert.equal(result.ok, true);
296
+ assert.ok(
297
+ result.warnings.some((w) => w.includes("01-test.md"))
298
+ );
299
+ });
300
+
301
+ it("warns when PRD is still the template", async (t) => {
302
+ const dir = await tempDir(t);
303
+ await runInit({ target: dir });
304
+ const result = await runDoctor({ target: dir });
305
+ assert.equal(result.ok, true);
306
+ assert.ok(result.warnings.includes("markflow/docs/PRD.md"));
307
+ });
308
+
309
+ it("warns when instruction text is left visible", async (t) => {
310
+ const dir = await tempDir(t);
311
+ await runInit({ target: dir });
312
+ await write(
313
+ dir,
314
+ "markflow/docs/PRD.md",
315
+ "Our product.\n\nWrite one short paragraph. About the problem.\n"
316
+ );
317
+ const result = await runDoctor({ target: dir });
318
+ assert.equal(result.ok, true);
319
+ assert.ok(result.warnings.includes("markflow/docs/PRD.md"));
320
+ });
321
+
322
+ it("hidden instructions do not warn", async (t) => {
323
+ const dir = await tempDir(t);
324
+ await runInit({ target: dir });
325
+ const result = await runDoctor({ target: dir });
326
+ assert.equal(result.ok, true);
327
+ assert.equal(
328
+ result.warnings.filter((w) => w === "markflow/docs/PRD.md").length,
329
+ 1
330
+ );
331
+ });
332
+
333
+ it("template spec still warns on empty acceptance", async (t) => {
334
+ const dir = await tempDir(t);
335
+ await runInit({ target: dir });
336
+ await write(
337
+ dir,
338
+ "markflow/specs/01-test.md",
339
+ "# Test spec\n\n## Goal\n\n<!-- Write what this feature must do in one or two sentences. -->\n\n- [ ] TBD\n\n## Acceptance\n\n<!-- Write how you will test this feature. List the main cases. -->\n\n## Status\n\nDraft\n"
340
+ );
341
+ const index = await readFile(
342
+ join(dir, "markflow/specs/index.md"),
343
+ "utf8"
344
+ );
345
+ await write(dir, "markflow/specs/index.md", index + "\n01-test.md\n");
346
+ const result = await runDoctor({ target: dir });
347
+ assert.equal(result.ok, true);
348
+ assert.ok(
349
+ result.warnings.some((w) => w.includes("01-test.md"))
350
+ );
351
+ });
352
+
353
+ it("doctor passes on a minimal project", async (t) => {
354
+ const dir = await tempDir(t);
355
+ await runInit({ target: dir, minimal: true });
356
+ const result = await runDoctor({ target: dir });
357
+ assert.equal(result.ok, true);
358
+ assert.equal(result.errors.length, 0);
359
+ });
360
+
361
+ it("no PRD warning when PRD is filled", async (t) => {
362
+ const dir = await tempDir(t);
363
+ await runInit({ target: dir });
364
+ await write(dir, "markflow/docs/PRD.md", "Our own product.\n");
365
+ const result = await runDoctor({ target: dir });
366
+ assert.equal(result.ok, true);
367
+ assert.ok(!result.warnings.includes("markflow/docs/PRD.md"));
368
+ });
369
+
370
+ it("placeholder in AGENTS.md fails", async (t) => {
371
+ const dir = await tempDir(t);
372
+ await runInit({ target: dir });
373
+ await write(dir, "AGENTS.md", "{{project_name}}\n");
374
+ const result = await runDoctor({ target: dir });
375
+ assert.equal(result.ok, false);
376
+ });
377
+
378
+ it("placeholder in cursor file fails", async (t) => {
379
+ const dir = await tempDir(t);
380
+ await runInit({ target: dir, agent: "cursor" });
381
+ await write(dir, ".cursor/rules/markflow.mdc", "{{project_name}}\n");
382
+ const result = await runDoctor({ target: dir });
383
+ assert.equal(result.ok, false);
384
+ });
385
+
386
+ it("old cursorrules file is no longer checked", async (t) => {
387
+ const dir = await tempDir(t);
388
+ await runInit({ target: dir });
389
+ await write(dir, ".cursorrules", "{{project_name}}\n");
390
+ const result = await runDoctor({ target: dir });
391
+ assert.equal(result.ok, true);
392
+ });
393
+ });
394
+
395
+ describe("update", () => {
396
+ it("keeps a file the user wrote before init", async (t) => {
397
+ const dir = await tempDir(t);
398
+ await write(dir, "markflow/docs/PRD.md", "MY OWN PRD TEXT\n");
399
+ await runInit({ target: dir });
400
+ const before = await readFile(join(dir, "markflow/docs/PRD.md"), "utf8");
401
+ assert.equal(before, "MY OWN PRD TEXT\n");
402
+ const result = await runUpdate({ target: dir });
403
+ assert.equal(result.ok, true);
404
+ assert.equal(result.updated, 0);
405
+ assert.equal(result.skipped, 3);
406
+ const after = await readFile(join(dir, "markflow/docs/PRD.md"), "utf8");
407
+ assert.equal(after, "MY OWN PRD TEXT\n");
408
+ });
409
+
410
+ it("keeps filled ARCHITECTURE.md and STACK.md on update", async (t) => {
411
+ const dir = await tempDir(t);
412
+ await write(dir, "package.json", "{}");
413
+ await runInit({ target: dir });
414
+ const archBefore = await readFile(
415
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
416
+ "utf8"
417
+ );
418
+ assert.ok(archBefore.includes("- Language. JavaScript"));
419
+ const stackBefore = await readFile(
420
+ join(dir, "markflow/docs/STACK.md"),
421
+ "utf8"
422
+ );
423
+ assert.ok(stackBefore.includes("Detected stacks"));
424
+ const result = await runUpdate({ target: dir });
425
+ assert.equal(result.ok, true);
426
+ assert.equal(result.updated, 0);
427
+ assert.equal(result.skipped, 2);
428
+ const archAfter = await readFile(
429
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
430
+ "utf8"
431
+ );
432
+ assert.ok(archAfter.includes("- Language. JavaScript"));
433
+ const stackAfter = await readFile(
434
+ join(dir, "markflow/docs/STACK.md"),
435
+ "utf8"
436
+ );
437
+ assert.ok(stackAfter.includes("Detected stacks"));
438
+ });
439
+
440
+ it("restores ARCHITECTURE.md when missing", async (t) => {
441
+ const dir = await tempDir(t);
442
+ await write(dir, "package.json", "{}");
443
+ await runInit({ target: dir });
444
+ await rm(join(dir, "markflow/docs/ARCHITECTURE.md"));
445
+ const result = await runUpdate({ target: dir });
446
+ assert.equal(result.ok, true);
447
+ assert.equal(result.restored, 1);
448
+ const arch = await readFile(
449
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
450
+ "utf8"
451
+ );
452
+ assert.ok(arch.includes("- Language. TBD"));
453
+ });
454
+
455
+ it("restores a deleted file and skips a modified file", async (t) => {
456
+ const dir = await tempDir(t);
457
+ await runInit({ target: dir });
458
+ await rm(join(dir, "markflow/docs/PRD.md"));
459
+ await write(dir, "markflow/TASKS.md", "my own notes\n");
460
+ const result = await runUpdate({ target: dir });
461
+ assert.equal(result.ok, true);
462
+ assert.equal(result.restored, 1);
463
+ assert.equal(result.skipped, 3);
464
+ const tasks = await readFile(join(dir, "markflow/TASKS.md"), "utf8");
465
+ assert.equal(tasks, "my own notes\n");
466
+ });
467
+
468
+ it("update keeps a minimal project minimal", async (t) => {
469
+ const dir = await tempDir(t);
470
+ await runInit({ target: dir, minimal: true });
471
+ const result = await runUpdate({ target: dir });
472
+ assert.equal(result.ok, true);
473
+ await assert.rejects(
474
+ readFile(join(dir, "markflow/docs/STACK.md"), "utf8")
475
+ );
476
+ });
477
+
478
+ it("preview changes nothing", async (t) => {
479
+ const dir = await tempDir(t);
480
+ await runInit({ target: dir });
481
+ await rm(join(dir, "markflow/docs/PRD.md"));
482
+ const result = await runUpdate({ target: dir, preview: true });
483
+ assert.equal(result.preview, true);
484
+ await assert.rejects(readFile(join(dir, "markflow/docs/PRD.md"), "utf8"));
485
+ });
486
+
487
+ it("keeps a file that left the template", async (t) => {
488
+ const dir = await tempDir(t);
489
+ await runInit({ target: dir });
490
+ const markerPath = join(dir, "markflow/.markflow.json");
491
+ const marker = JSON.parse(await readFile(markerPath, "utf8"));
492
+ marker.files["docs/OLD.md"] = "abc123";
493
+ await writeFile(markerPath, JSON.stringify(marker, null, 2));
494
+ const result = await runUpdate({ target: dir });
495
+ assert.equal(result.kept, 1);
496
+ });
497
+
498
+ it("no marker fails", async (t) => {
499
+ const dir = await tempDir(t);
500
+ const result = await runUpdate({ target: dir });
501
+ assert.equal(result.ok, false);
502
+ });
503
+
504
+ it("restores a deleted agent file", async (t) => {
505
+ const dir = await tempDir(t);
506
+ await runInit({ target: dir, agent: "claude" });
507
+ await rm(join(dir, "CLAUDE.md"));
508
+ const result = await runUpdate({ target: dir });
509
+ assert.equal(result.restored, 1);
510
+ const text = await readFile(join(dir, "CLAUDE.md"), "utf8");
511
+ assert.ok(text.length > 0);
512
+ });
513
+ });
514
+
515
+ describe("parser", () => {
516
+ it("unknown command exits 1 and creates no files", async (t) => {
517
+ const dir = await tempDir(t);
518
+ const result = runCli(["frobnicate"], dir);
519
+ assert.equal(result.status, 1);
520
+ assert.match(result.stdout, /Unknown command/);
521
+ await assert.rejects(readFile(join(dir, "AGENTS.md"), "utf8"));
522
+ });
523
+
524
+ it("no args exits 1 and creates no files", async (t) => {
525
+ const dir = await tempDir(t);
526
+ const result = runCli([], dir);
527
+ assert.equal(result.status, 1);
528
+ await assert.rejects(readFile(join(dir, "AGENTS.md"), "utf8"));
529
+ });
530
+
531
+ it("--help exits 0", async (t) => {
532
+ const dir = await tempDir(t);
533
+ const result = runCli(["--help"], dir);
534
+ assert.equal(result.status, 0);
535
+ assert.match(result.stdout, /Usage/);
536
+ });
537
+
538
+ it("init --minimal exits 0 and marks the project minimal", async (t) => {
539
+ const dir = await tempDir(t);
540
+ const result = runCli(["init", "--minimal"], dir);
541
+ assert.equal(result.status, 0);
542
+ await assert.rejects(
543
+ readFile(join(dir, "markflow/docs/STACK.md"), "utf8")
544
+ );
545
+ const marker = JSON.parse(
546
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
547
+ );
548
+ assert.equal(marker.minimal, true);
549
+ });
550
+
551
+ it("--version prints the version", async (t) => {
552
+ const dir = await tempDir(t);
553
+ const result = runCli(["--version"], dir);
554
+ assert.equal(result.status, 0);
555
+ assert.equal(result.stdout.trim(), "0.2.0");
556
+ });
557
+ });
558
+
559
+ describe("agents", () => {
560
+ it("cursor creates the modern mdc file with frontmatter", async (t) => {
561
+ const dir = await tempDir(t);
562
+ await runInit({ target: dir, agent: "cursor" });
563
+ const text = await readFile(
564
+ join(dir, ".cursor/rules/markflow.mdc"),
565
+ "utf8"
566
+ );
567
+ assert.ok(text.startsWith("---"));
568
+ assert.ok(text.includes("alwaysApply: true"));
569
+ await assert.rejects(readFile(join(dir, ".cursorrules"), "utf8"));
570
+ });
571
+
572
+ it("copilot creates its instructions file", async (t) => {
573
+ const dir = await tempDir(t);
574
+ await runInit({ target: dir, agent: "copilot" });
575
+ const text = await readFile(
576
+ join(dir, ".github/copilot-instructions.md"),
577
+ "utf8"
578
+ );
579
+ assert.ok(text.length > 0);
580
+ });
581
+
582
+ it("codex creates no extra file", async (t) => {
583
+ const dir = await tempDir(t);
584
+ await runInit({ target: dir, agent: "codex" });
585
+ await assert.rejects(readFile(join(dir, "CLAUDE.md"), "utf8"));
586
+ await assert.rejects(
587
+ readFile(join(dir, ".github/copilot-instructions.md"), "utf8")
588
+ );
589
+ });
590
+ });