@moritakaaz/markflow 0.1.0 → 0.3.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.
package/test/cli.test.js CHANGED
@@ -10,7 +10,7 @@ import { dirname, join } from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
11
  import { discover } from "../src/discover.js";
12
12
  import { runDoctor } from "../src/doctor.js";
13
- import { runInit } from "../src/init.js";
13
+ import { fillArchitecture, runInit } from "../src/init.js";
14
14
  import { runUpdate } from "../src/update.js";
15
15
 
16
16
  const CLI = join(dirname(fileURLToPath(import.meta.url)), "../src/index.js");
@@ -81,6 +81,63 @@ describe("discover", () => {
81
81
  assert.equal(result.workspace.detected, true);
82
82
  });
83
83
 
84
+ it("detects dependencies from package.json", async (t) => {
85
+ const dir = await tempDir(t);
86
+ await write(
87
+ dir,
88
+ "package.json",
89
+ JSON.stringify({
90
+ dependencies: { alpha: "^1.0.0", beta: "^2.0.0" },
91
+ devDependencies: { gamma: "^3.0.0" },
92
+ })
93
+ );
94
+ const result = await discover(dir);
95
+ assert.deepEqual(
96
+ result.dependencies.map((d) => d.name),
97
+ ["alpha", "beta", "gamma"]
98
+ );
99
+ assert.equal(result.dependencies[0].confidence, "detected");
100
+ assert.equal(result.dependencies[0].evidence, "package.json");
101
+ });
102
+
103
+ it("detects dependencies from requirements.txt", async (t) => {
104
+ const dir = await tempDir(t);
105
+ await write(dir, "requirements.txt", "alpha==1.0\nbeta>=2.0\n");
106
+ const result = await discover(dir);
107
+ assert.deepEqual(
108
+ result.dependencies.map((d) => d.name),
109
+ ["alpha", "beta"]
110
+ );
111
+ });
112
+
113
+ it("detects dependencies from go.mod", async (t) => {
114
+ const dir = await tempDir(t);
115
+ await write(
116
+ dir,
117
+ "go.mod",
118
+ "module example.com/demo\n\ngo 1.21\n\nrequire (\n\tgithub.com/example/alpha v1.0.0\n\tgithub.com/example/beta/v4 v4.0.0\n)\n"
119
+ );
120
+ const result = await discover(dir);
121
+ assert.deepEqual(
122
+ result.dependencies.map((d) => d.name),
123
+ ["alpha", "beta"]
124
+ );
125
+ });
126
+
127
+ it("skips venv, target, and .next dirs", async (t) => {
128
+ const dir = await tempDir(t);
129
+ await write(dir, "package.json", "{}");
130
+ await write(dir, "venv/requirements.txt", "");
131
+ await write(dir, "target/Cargo.toml", "");
132
+ await write(dir, ".next/package.json", "{}");
133
+ const result = await discover(dir);
134
+ assert.deepEqual(
135
+ result.stacks.map((s) => s.name),
136
+ ["JavaScript"]
137
+ );
138
+ assert.deepEqual(result.manifests, ["package.json"]);
139
+ });
140
+
84
141
  it("records test and CI configs", async (t) => {
85
142
  const dir = await tempDir(t);
86
143
  await write(dir, "vitest.config.ts", "");
@@ -139,6 +196,114 @@ describe("init", () => {
139
196
  assert.ok(text.includes("STACK.md"));
140
197
  });
141
198
 
199
+ it("fillArchitecture fills language and evidence", () => {
200
+ const filled = fillArchitecture("- Language. TBD\n- Framework. TBD\n", {
201
+ stacks: [{ name: "Go", evidence: "go.mod", confidence: "high" }],
202
+ monorepo: false,
203
+ });
204
+ assert.ok(filled.includes("- Language. Go"));
205
+ assert.ok(filled.includes("- Evidence. go.mod (high)"));
206
+ assert.ok(filled.includes("- Monorepo. No"));
207
+ });
208
+
209
+ it("fillArchitecture leaves framework as TBD", () => {
210
+ const filled = fillArchitecture("- Language. TBD\n- Framework. TBD\n", {
211
+ stacks: [{ name: "JavaScript", evidence: "package.json", confidence: "high" }],
212
+ monorepo: false,
213
+ });
214
+ assert.ok(filled.includes("- Framework. TBD"));
215
+ });
216
+
217
+ it("writes detected dependencies into docs", async (t) => {
218
+ const dir = await tempDir(t);
219
+ await write(
220
+ dir,
221
+ "package.json",
222
+ JSON.stringify({ dependencies: { alpha: "^1.0.0" } })
223
+ );
224
+ await runInit({ target: dir });
225
+ const arch = await readFile(
226
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
227
+ "utf8"
228
+ );
229
+ assert.ok(arch.includes("- Framework. TBD"));
230
+ const stack = await readFile(
231
+ join(dir, "markflow/docs/STACK.md"),
232
+ "utf8"
233
+ );
234
+ assert.ok(stack.includes("## Detected dependencies"));
235
+ assert.ok(stack.includes("- alpha from package.json, detected"));
236
+ });
237
+
238
+ it("fillArchitecture throws when template lines are missing", () => {
239
+ assert.throws(
240
+ () =>
241
+ fillArchitecture("# ARCHITECTURE\n\nNo lines here.\n", {
242
+ stacks: [{ name: "Go", evidence: "go.mod", confidence: "high" }],
243
+ monorepo: false,
244
+ }),
245
+ /template changed/
246
+ );
247
+ });
248
+
249
+ it("minimal init creates only the minimal files", async (t) => {
250
+ const dir = await tempDir(t);
251
+ const result = await runInit({ target: dir, minimal: true });
252
+ assert.equal(result.minimal, true);
253
+ for (const file of [
254
+ "AGENTS.md",
255
+ "markflow/README.md",
256
+ "markflow/TASKS.md",
257
+ "markflow/docs/PRD.md",
258
+ "markflow/docs/ARCHITECTURE.md",
259
+ "markflow/specs/index.md",
260
+ "markflow/specs/_template.md",
261
+ ]) {
262
+ await readFile(join(dir, file), "utf8");
263
+ }
264
+ for (const file of [
265
+ "markflow/docs/STACK.md",
266
+ "markflow/docs/CODING_STANDARDS.md",
267
+ "markflow/CHANGELOG.md",
268
+ ]) {
269
+ await assert.rejects(readFile(join(dir, file), "utf8"));
270
+ }
271
+ const marker = JSON.parse(
272
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
273
+ );
274
+ assert.equal(marker.minimal, true);
275
+ });
276
+
277
+ it("full init upgrades a minimal project", async (t) => {
278
+ const dir = await tempDir(t);
279
+ await runInit({ target: dir, minimal: true });
280
+ const result = await runInit({ target: dir });
281
+ assert.equal(result.minimal, false);
282
+ await readFile(join(dir, "markflow/docs/STACK.md"), "utf8");
283
+ const marker = JSON.parse(
284
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
285
+ );
286
+ assert.equal(marker.minimal, false);
287
+ });
288
+
289
+ it("created AGENTS.md points to onboarding", async (t) => {
290
+ const dir = await tempDir(t);
291
+ await runInit({ target: dir });
292
+ const text = await readFile(join(dir, "AGENTS.md"), "utf8");
293
+ assert.ok(text.includes("markflow/.agents/workflows/onboarding.md"));
294
+ });
295
+
296
+ it("init suggests onboarding on first run only", async (t) => {
297
+ const dir = await tempDir(t);
298
+ const first = await runInit({ target: dir });
299
+ assert.equal(
300
+ first.nextStep,
301
+ "Open your AI tool and say: start onboarding."
302
+ );
303
+ const second = await runInit({ target: dir });
304
+ assert.equal(second.nextStep, undefined);
305
+ });
306
+
142
307
  it("unknown agent fails and creates no files", async (t) => {
143
308
  const dir = await tempDir(t);
144
309
  const result = await runInit({ target: dir, agent: "bogus" });
@@ -169,7 +334,194 @@ describe("doctor", () => {
169
334
  await write(dir, "markflow/specs/99-new.md", "# Spec\n\nStatus\n\nDraft\n");
170
335
  const result = await runDoctor({ target: dir });
171
336
  assert.equal(result.ok, true);
172
- assert.equal(result.warnings.length, 1);
337
+ assert.ok(result.warnings.some((w) => w.includes("99-new.md")));
338
+ });
339
+
340
+ it("spec listed by file name in index passes", async (t) => {
341
+ const dir = await tempDir(t);
342
+ await runInit({ target: dir });
343
+ const index = await readFile(
344
+ join(dir, "markflow/specs/index.md"),
345
+ "utf8"
346
+ );
347
+ assert.ok(index.includes("| ID | File | Title | Status |"));
348
+ assert.ok(index.includes("Write the file name in the File column."));
349
+ await write(
350
+ dir,
351
+ "markflow/specs/01-record-a-sale.md",
352
+ "# Record a sale\n\n## Goal\n\nRecord one sale.\n\n## Acceptance\n\n- The sale is saved.\n\n## Status\n\nDraft\n"
353
+ );
354
+ await write(
355
+ dir,
356
+ "markflow/specs/index.md",
357
+ index.replace(
358
+ "| 01 | TBD | TBD | Draft |",
359
+ "| 01 | 01-record-a-sale.md | Record a sale | Draft |"
360
+ )
361
+ );
362
+ const result = await runDoctor({ target: dir });
363
+ assert.equal(result.ok, true);
364
+ assert.ok(
365
+ !result.warnings.some((w) => w.includes("01-record-a-sale.md"))
366
+ );
367
+ });
368
+
369
+ it("spec listed by title only still warns", async (t) => {
370
+ const dir = await tempDir(t);
371
+ await runInit({ target: dir });
372
+ const index = await readFile(
373
+ join(dir, "markflow/specs/index.md"),
374
+ "utf8"
375
+ );
376
+ await write(
377
+ dir,
378
+ "markflow/specs/01-record-a-sale.md",
379
+ "# Record a sale\n\n## Goal\n\nRecord one sale.\n\n## Acceptance\n\n- The sale is saved.\n\n## Status\n\nDraft\n"
380
+ );
381
+ await write(
382
+ dir,
383
+ "markflow/specs/index.md",
384
+ index.replace(
385
+ "| 01 | TBD | TBD | Draft |",
386
+ "| 01 | TBD | Record a sale | Draft |"
387
+ )
388
+ );
389
+ const result = await runDoctor({ target: dir });
390
+ assert.equal(result.ok, true);
391
+ assert.ok(
392
+ result.warnings.some((w) => w.includes("01-record-a-sale.md"))
393
+ );
394
+ });
395
+
396
+ it("warns on empty acceptance in a spec", async (t) => {
397
+ const dir = await tempDir(t);
398
+ await runInit({ target: dir });
399
+ await write(
400
+ dir,
401
+ "markflow/specs/01-test.md",
402
+ "# 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"
403
+ );
404
+ const index = await readFile(
405
+ join(dir, "markflow/specs/index.md"),
406
+ "utf8"
407
+ );
408
+ await write(dir, "markflow/specs/index.md", index + "\n01-test.md\n");
409
+ const result = await runDoctor({ target: dir });
410
+ assert.equal(result.ok, true);
411
+ assert.ok(
412
+ result.warnings.some((w) => w.includes("01-test.md"))
413
+ );
414
+ });
415
+
416
+ it("warns on approved spec with TBD", async (t) => {
417
+ const dir = await tempDir(t);
418
+ await runInit({ target: dir });
419
+ await write(
420
+ dir,
421
+ "markflow/specs/01-test.md",
422
+ "# 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"
423
+ );
424
+ const index = await readFile(
425
+ join(dir, "markflow/specs/index.md"),
426
+ "utf8"
427
+ );
428
+ await write(dir, "markflow/specs/index.md", index + "\n01-test.md\n");
429
+ const result = await runDoctor({ target: dir });
430
+ assert.equal(result.ok, true);
431
+ assert.ok(
432
+ result.warnings.some((w) => w.includes("01-test.md"))
433
+ );
434
+ });
435
+
436
+ it("warns when PRD is still the template", async (t) => {
437
+ const dir = await tempDir(t);
438
+ await runInit({ target: dir });
439
+ const result = await runDoctor({ target: dir });
440
+ assert.equal(result.ok, true);
441
+ assert.ok(result.warnings.includes("markflow/docs/PRD.md"));
442
+ });
443
+
444
+ it("warns when instruction text is left visible", async (t) => {
445
+ const dir = await tempDir(t);
446
+ await runInit({ target: dir });
447
+ await write(
448
+ dir,
449
+ "markflow/docs/PRD.md",
450
+ "Our product.\n\nWrite one short paragraph. About the problem.\n"
451
+ );
452
+ const result = await runDoctor({ target: dir });
453
+ assert.equal(result.ok, true);
454
+ assert.ok(result.warnings.includes("markflow/docs/PRD.md"));
455
+ });
456
+
457
+ it("hidden instructions do not warn", async (t) => {
458
+ const dir = await tempDir(t);
459
+ await runInit({ target: dir });
460
+ const result = await runDoctor({ target: dir });
461
+ assert.equal(result.ok, true);
462
+ assert.equal(
463
+ result.warnings.filter((w) => w === "markflow/docs/PRD.md").length,
464
+ 1
465
+ );
466
+ });
467
+
468
+ it("template spec still warns on empty acceptance", async (t) => {
469
+ const dir = await tempDir(t);
470
+ await runInit({ target: dir });
471
+ await write(
472
+ dir,
473
+ "markflow/specs/01-test.md",
474
+ "# 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"
475
+ );
476
+ const index = await readFile(
477
+ join(dir, "markflow/specs/index.md"),
478
+ "utf8"
479
+ );
480
+ await write(dir, "markflow/specs/index.md", index + "\n01-test.md\n");
481
+ const result = await runDoctor({ target: dir });
482
+ assert.equal(result.ok, true);
483
+ assert.ok(
484
+ result.warnings.some((w) => w.includes("01-test.md"))
485
+ );
486
+ });
487
+
488
+ it("doctor passes on a minimal project", async (t) => {
489
+ const dir = await tempDir(t);
490
+ await runInit({ target: dir, minimal: true });
491
+ const result = await runDoctor({ target: dir });
492
+ assert.equal(result.ok, true);
493
+ assert.equal(result.errors.length, 0);
494
+ });
495
+
496
+ it("warns when ARCHITECTURE and TASKS are still the template", async (t) => {
497
+ const dir = await tempDir(t);
498
+ await runInit({ target: dir });
499
+ const result = await runDoctor({ target: dir });
500
+ assert.equal(result.ok, true);
501
+ assert.ok(result.warnings.includes("markflow/docs/ARCHITECTURE.md"));
502
+ assert.ok(result.warnings.includes("markflow/TASKS.md"));
503
+ });
504
+
505
+ it("no template warnings when all three are filled", async (t) => {
506
+ const dir = await tempDir(t);
507
+ await runInit({ target: dir });
508
+ await write(dir, "markflow/docs/PRD.md", "Our own product.\n");
509
+ await write(dir, "markflow/docs/ARCHITECTURE.md", "Our own stack.\n");
510
+ await write(dir, "markflow/TASKS.md", "Our own tasks.\n");
511
+ const result = await runDoctor({ target: dir });
512
+ assert.equal(result.ok, true);
513
+ assert.ok(!result.warnings.includes("markflow/docs/PRD.md"));
514
+ assert.ok(!result.warnings.includes("markflow/docs/ARCHITECTURE.md"));
515
+ assert.ok(!result.warnings.includes("markflow/TASKS.md"));
516
+ });
517
+
518
+ it("no PRD warning when PRD is filled", async (t) => {
519
+ const dir = await tempDir(t);
520
+ await runInit({ target: dir });
521
+ await write(dir, "markflow/docs/PRD.md", "Our own product.\n");
522
+ const result = await runDoctor({ target: dir });
523
+ assert.equal(result.ok, true);
524
+ assert.ok(!result.warnings.includes("markflow/docs/PRD.md"));
173
525
  });
174
526
 
175
527
  it("placeholder in AGENTS.md fails", async (t) => {
@@ -179,9 +531,84 @@ describe("doctor", () => {
179
531
  const result = await runDoctor({ target: dir });
180
532
  assert.equal(result.ok, false);
181
533
  });
534
+
535
+ it("placeholder in cursor file fails", async (t) => {
536
+ const dir = await tempDir(t);
537
+ await runInit({ target: dir, agent: "cursor" });
538
+ await write(dir, ".cursor/rules/markflow.mdc", "{{project_name}}\n");
539
+ const result = await runDoctor({ target: dir });
540
+ assert.equal(result.ok, false);
541
+ });
542
+
543
+ it("old cursorrules file is no longer checked", async (t) => {
544
+ const dir = await tempDir(t);
545
+ await runInit({ target: dir });
546
+ await write(dir, ".cursorrules", "{{project_name}}\n");
547
+ const result = await runDoctor({ target: dir });
548
+ assert.equal(result.ok, true);
549
+ });
182
550
  });
183
551
 
184
552
  describe("update", () => {
553
+ it("keeps a file the user wrote before init", async (t) => {
554
+ const dir = await tempDir(t);
555
+ await write(dir, "markflow/docs/PRD.md", "MY OWN PRD TEXT\n");
556
+ await runInit({ target: dir });
557
+ const before = await readFile(join(dir, "markflow/docs/PRD.md"), "utf8");
558
+ assert.equal(before, "MY OWN PRD TEXT\n");
559
+ const result = await runUpdate({ target: dir });
560
+ assert.equal(result.ok, true);
561
+ assert.equal(result.updated, 0);
562
+ assert.equal(result.skipped, 3);
563
+ const after = await readFile(join(dir, "markflow/docs/PRD.md"), "utf8");
564
+ assert.equal(after, "MY OWN PRD TEXT\n");
565
+ });
566
+
567
+ it("keeps filled ARCHITECTURE.md and STACK.md on update", async (t) => {
568
+ const dir = await tempDir(t);
569
+ await write(dir, "package.json", "{}");
570
+ await runInit({ target: dir });
571
+ const archBefore = await readFile(
572
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
573
+ "utf8"
574
+ );
575
+ assert.ok(archBefore.includes("- Language. JavaScript"));
576
+ const stackBefore = await readFile(
577
+ join(dir, "markflow/docs/STACK.md"),
578
+ "utf8"
579
+ );
580
+ assert.ok(stackBefore.includes("Detected stacks"));
581
+ const result = await runUpdate({ target: dir });
582
+ assert.equal(result.ok, true);
583
+ assert.equal(result.updated, 0);
584
+ assert.equal(result.skipped, 2);
585
+ const archAfter = await readFile(
586
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
587
+ "utf8"
588
+ );
589
+ assert.ok(archAfter.includes("- Language. JavaScript"));
590
+ const stackAfter = await readFile(
591
+ join(dir, "markflow/docs/STACK.md"),
592
+ "utf8"
593
+ );
594
+ assert.ok(stackAfter.includes("Detected stacks"));
595
+ });
596
+
597
+ it("restores ARCHITECTURE.md when missing", async (t) => {
598
+ const dir = await tempDir(t);
599
+ await write(dir, "package.json", "{}");
600
+ await runInit({ target: dir });
601
+ await rm(join(dir, "markflow/docs/ARCHITECTURE.md"));
602
+ const result = await runUpdate({ target: dir });
603
+ assert.equal(result.ok, true);
604
+ assert.equal(result.restored, 1);
605
+ const arch = await readFile(
606
+ join(dir, "markflow/docs/ARCHITECTURE.md"),
607
+ "utf8"
608
+ );
609
+ assert.ok(arch.includes("- Language. TBD"));
610
+ });
611
+
185
612
  it("restores a deleted file and skips a modified file", async (t) => {
186
613
  const dir = await tempDir(t);
187
614
  await runInit({ target: dir });
@@ -190,11 +617,21 @@ describe("update", () => {
190
617
  const result = await runUpdate({ target: dir });
191
618
  assert.equal(result.ok, true);
192
619
  assert.equal(result.restored, 1);
193
- assert.equal(result.skipped, 1);
620
+ assert.equal(result.skipped, 3);
194
621
  const tasks = await readFile(join(dir, "markflow/TASKS.md"), "utf8");
195
622
  assert.equal(tasks, "my own notes\n");
196
623
  });
197
624
 
625
+ it("update keeps a minimal project minimal", async (t) => {
626
+ const dir = await tempDir(t);
627
+ await runInit({ target: dir, minimal: true });
628
+ const result = await runUpdate({ target: dir });
629
+ assert.equal(result.ok, true);
630
+ await assert.rejects(
631
+ readFile(join(dir, "markflow/docs/STACK.md"), "utf8")
632
+ );
633
+ });
634
+
198
635
  it("preview changes nothing", async (t) => {
199
636
  const dir = await tempDir(t);
200
637
  await runInit({ target: dir });
@@ -255,11 +692,24 @@ describe("parser", () => {
255
692
  assert.match(result.stdout, /Usage/);
256
693
  });
257
694
 
695
+ it("init --minimal exits 0 and marks the project minimal", async (t) => {
696
+ const dir = await tempDir(t);
697
+ const result = runCli(["init", "--minimal"], dir);
698
+ assert.equal(result.status, 0);
699
+ await assert.rejects(
700
+ readFile(join(dir, "markflow/docs/STACK.md"), "utf8")
701
+ );
702
+ const marker = JSON.parse(
703
+ await readFile(join(dir, "markflow/.markflow.json"), "utf8")
704
+ );
705
+ assert.equal(marker.minimal, true);
706
+ });
707
+
258
708
  it("--version prints the version", async (t) => {
259
709
  const dir = await tempDir(t);
260
710
  const result = runCli(["--version"], dir);
261
711
  assert.equal(result.status, 0);
262
- assert.equal(result.stdout.trim(), "0.1.0");
712
+ assert.equal(result.stdout.trim(), "0.3.0");
263
713
  });
264
714
  });
265
715