@pmelab/gtd 24.3.0 → 25.0.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 (74) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +28 -22
  3. package/dist/chunks/{reserved-DJwU5C4z.mjs → reserved-6pAgFGgB.mjs} +119 -135
  4. package/dist/chunks/{steering-D-PvRC5W.mjs → steering-DVILanVf.mjs} +16 -5
  5. package/dist/flows.mjs +9 -1
  6. package/dist/gtd.bundle.mjs +780 -813
  7. package/dist/steering.mjs +2 -2
  8. package/dist/testkit.mjs +666 -161
  9. package/dist/workflow-kit.mjs +55 -96
  10. package/dist/workflows/feature.mjs +171 -76
  11. package/dist/workflows/fix.mjs +2 -2
  12. package/dist/workflows/review.mjs +1 -1
  13. package/dist/workflows.mjs +353 -310
  14. package/package.json +1 -2
  15. package/src/cli/Program.test.ts +3 -8
  16. package/src/cli/Program.ts +1 -8
  17. package/src/edge/Edge.test.ts +5 -2
  18. package/src/edge/Edge.ts +3 -4
  19. package/src/emit/index.ts +1 -0
  20. package/src/flows/scripts.ts +6 -0
  21. package/src/platform/Git.test.ts +6 -9
  22. package/src/replay/Replay.ts +2 -1
  23. package/src/steering/FORMATS.md +1 -1
  24. package/src/steering/SteeringFormat.test.ts +9 -1
  25. package/src/steering/SteeringFormat.ts +7 -0
  26. package/src/steering/contract.test.ts +3 -0
  27. package/src/steering/index.ts +1 -0
  28. package/src/steering/review.test.ts +30 -0
  29. package/src/steering/review.ts +8 -2
  30. package/src/testkit/EmittedScriptRecognizer.test.ts +29 -30
  31. package/src/testkit/EmittedScriptRecognizer.ts +148 -51
  32. package/src/testkit/EmittedScripts.test.ts +166 -0
  33. package/src/testkit/FlowScripts.test.ts +242 -0
  34. package/src/testkit/FlowScripts.ts +326 -0
  35. package/src/testkit/GitTiers.ts +140 -49
  36. package/src/testkit/InMemRepo.ts +35 -2
  37. package/src/testkit/Layers.ts +10 -2
  38. package/src/testkit/TestRepo.ts +4 -1
  39. package/src/testkit/index.ts +1 -1
  40. package/src/workflow/discovery.test.ts +147 -0
  41. package/src/workflow/discovery.ts +5 -0
  42. package/src/workflow/fingerprint.test.ts +20 -4
  43. package/src/workflow/fingerprint.ts +8 -9
  44. package/src/workflow/index.ts +1 -6
  45. package/src/workflow/load.test.ts +5 -19
  46. package/src/workflow/load.ts +94 -10
  47. package/src/workflow-kit/review.test.ts +84 -0
  48. package/src/workflow-kit/review.ts +9 -6
  49. package/src/workflow-kit/scenarios.test.ts +116 -0
  50. package/src/workflow-kit/scenarios.ts +53 -113
  51. package/src/workflows/feature/feature.ts +2 -5
  52. package/src/workflows/feature/packages.test.ts +17 -34
  53. package/src/workflows/feature/packages.ts +13 -52
  54. package/src/workflows/feature/planning.ts +1 -1
  55. package/src/workflows/feature/review.test.ts +233 -54
  56. package/src/workflows/feature/review.ts +178 -41
  57. package/src/workflows/feature/steps.test.ts +12 -0
  58. package/src/workflows/feature/steps.ts +8 -1
  59. package/src/workflows/index.ts +0 -2
  60. package/src/workflows/shared/access.test.ts +4 -2
  61. package/src/workflows/shared/access.ts +1 -0
  62. package/src/workflows/shared/health.test.ts +1 -21
  63. package/src/workflows/shared/health.ts +4 -39
  64. package/src/workflows/shared/options.test.ts +8 -0
  65. package/src/workflows/shared/options.ts +1 -1
  66. package/src/workflows/shared/steps.ts +18 -11
  67. package/src/workflows/shared/tail.test.ts +1 -41
  68. package/src/workflows/shared/tail.ts +17 -41
  69. package/src/workflows/shared/text.fixture.ts +1 -0
  70. package/src/workflows/shared/text.test.ts +129 -41
  71. package/src/workflows/shared/text.ts +111 -75
  72. package/src/workflows/shared/vars.ts +1 -1
  73. package/src/workflows/shared/scenarios.test.ts +0 -256
  74. package/src/workflows/shared/scenarios.ts +0 -35
@@ -10,7 +10,7 @@ import {
10
10
  type AgentOptions,
11
11
  type SummaryContext,
12
12
  } from "../../flows/index.js"
13
- import type { WordingDrift } from "../../workflow-kit/index.js"
13
+ import type { RemovedAssertions } from "../../workflow-kit/index.js"
14
14
  import {
15
15
  accessPreamble,
16
16
  skillsPreamble,
@@ -121,6 +121,10 @@ ${stateFileRules}
121
121
  ${footnoteFoldIn}${codeThreadReplies()}
122
122
  - The only state file this turn touches is \`.gtd/REQUIREMENTS.md\`
123
123
  — no other files for notes or output
124
+ - Lines of a \`## Deferred review notes\` section of \`.gtd/TODO.md\`
125
+ that the start diff does not touch are parked by review, never folded;
126
+ the human's edits to such a line (or its removal) are input like any
127
+ other part of the start diff
124
128
  - \`.gtd/TODO.md\` is the likely home of the sketch that started
125
129
  this process — the human's input, folded into the concerns
126
130
  below like any other part of the start diff; never a state
@@ -270,7 +274,8 @@ ${footnoteFoldIn}${codeThreadReplies()}
270
274
  - Every open point here is TECHNICAL — triage already resolved
271
275
  the product ones, one phase earlier. PERMISSIVE: answer it
272
276
  yourself unless you genuinely cannot defend a default; a wrong
273
- technical call is still caught by the full run and the quality lap
277
+ technical call is still caught by each package's suite run and the
278
+ quality lap
274
279
  - The narrow exception: a simplification that drops something
275
280
  \`.gtd/REQUIREMENTS.md\` mentions is an open question, not a
276
281
  silent default
@@ -282,11 +287,13 @@ ${footnoteFoldIn}${codeThreadReplies()}
282
287
  only, as fenced TypeScript (or the repository's language)
283
288
  3. \`## Call Stacks\` — seam level, entry point → module
284
289
  boundary; one line per hop, never per line of code
285
- 4. \`## E2E Scenarios\` — Gherkin in fenced \`gherkin\` blocks
286
- (whatever e2e framework the repository uses), each preceded
287
- by a line \`- e2e: <path>\`. With no user-visible
288
- behaviour change, the literal line \`No e2e change.\` plus a
289
- one-line reason — never empty or missing
290
+ 4. \`## E2E Scenarios\` — one line per user-visible behaviour,
291
+ \`- e2e: <path> — <behaviour> (covers <concern>)\`, in plain
292
+ words: the builder writes the scenario in the repository's
293
+ own e2e framework, so never spell out Gherkin here. With no
294
+ user-visible behaviour change, the literal line
295
+ \`No e2e change.\` plus a one-line reason — never empty or
296
+ missing
290
297
  5. \`## Unit Tests\` — one \`### <interface>\` per entry of
291
298
  \`## Interfaces\`, each test a line
292
299
  \`- unit: <path> — <behaviour> (covers <concern>)\`;
@@ -316,35 +323,31 @@ export const architectureDecomposePrompt = (): string =>
316
323
  ${stateFileRules}
317
324
  - The only state files this turn touches are the package files
318
325
  under \`.gtd/packages/\` — no other files for notes or output.
319
- Never delete \`.gtd/ARCHITECTURE.md\`: the build tail's full run
320
- still needs it, and package files may reference it
326
+ Never delete \`.gtd/ARCHITECTURE.md\`: package files may
327
+ reference it, and it is removed with the last package
321
328
  - Work from \`.gtd/ARCHITECTURE.md\` if you wrote it earlier this
322
329
  conversation, otherwise read it (the converged technical
323
330
  plan). It already lists the concerns, interfaces, e2e scenarios
324
331
  and unit tests — this turn groups them into packages. A
325
332
  \`## Merged Concerns\` heading there records merges, never a
326
333
  concern of its own: write no package file for it
327
- - A package is a consecutive run of \`## Unit Tests\` entries that go
328
- green together on the fast suite, at most ~8 unit-test entries
329
- each. Keep the merge rule: concerns whose footprints centre on the
330
- same files stay in one package unless the later one only consumes
331
- an interface the earlier one creates. Prefer fewer, larger
332
- packages. Order them so each stays green on the fast suite —
333
- interface-introducing packages first
334
+ - A package is one concern's slice, and each must leave the full
335
+ suite green — every package boundary costs a full run, so write
336
+ as few as the concerns allow. Keep the merge rule: concerns whose
337
+ footprints centre on the same files stay in one package unless
338
+ the later one only consumes an interface the earlier one creates.
339
+ Order them interface-introducing packages first
334
340
  - Write the packages under \`.gtd/packages/\`, each carrying its
335
341
  requirement(s) — both, independently, if merged — its tasks, and
336
342
  each task's acceptance criteria as \`- [ ]\` checkboxes and
337
343
  relevant paths:
338
- - \`.gtd/packages/00-e2e-scenarios.md\` — package 0: it writes
339
- \`## E2E Scenarios\` as tests in the repository's own e2e
340
- framework and leaves them red. Write no such file when
341
- \`## E2E Scenarios\` says "No e2e change."
342
- - \`01-…\` onward — the unit-test packages. A requirement no test
343
- covers (docs, README, deletions, config) becomes a chore
344
- package, or a task of one; chore packages declare no tests
345
- - the last numbered package is the wiring package: CLI entry,
346
- workflow composition, config. A red e2e after it is a bug, not
347
- missing work
344
+ - \`01-…\` onward — one vertical slice each: the unit tests,
345
+ the code, the wiring (CLI entry, workflow composition, config)
346
+ and every \`## E2E Scenarios\` entry its concern covers, so the
347
+ slice ends with its scenarios passing. A requirement no test
348
+ covers (docs, README, deletions, config) is a task of the slice
349
+ it belongs to; only one no slice owns becomes a chore package,
350
+ which declares no tests
348
351
  - Every package with tests has a \`## Tests\` section, one line per
349
352
  declared test, copied from the architecture entries:
350
353
  \`- unit: \\\`<path>\\\`\` or \`- e2e: \\\`<path>\\\`\`. Chore packages have
@@ -394,10 +397,10 @@ export const packagesItemBuildingPrompt = (pkg: string): string =>
394
397
  - Write the tests the package declares under \`## Tests\` first,
395
398
  then the code that makes them pass; the turn is refused unless
396
399
  every declared test is in your diff
397
- - Package 0 (\`.gtd/packages/00-e2e-scenarios.md\`) writes the scenarios verbatim
398
- from \`## E2E Scenarios\` of \`.gtd/ARCHITECTURE.md\`, with only
399
- step code that typechecks, and leaves them red — no
400
- implementation
400
+ - A declared e2e test is a scenario in the repository's own e2e
401
+ framework for the behaviour its \`## E2E Scenarios\` entry names.
402
+ Word it to fit the existing steps — reuse and generalise them
403
+ rather than adding one-off ones
401
404
  - Implement every task the package describes, no more, no less,
402
405
  fanning independent ones out to parallel subagents where your
403
406
  harness supports it; leave other package files untouched
@@ -466,34 +469,10 @@ turn, or land untouched to give it one more attempt at the same
466
469
  analysis.
467
470
  `
468
471
 
469
- /** What the tail's full-run fix needs of a `BuiltPlan` (structural: `packages.ts` imports this module). */
470
- export interface BuildContext {
471
- readonly ranges: readonly { readonly pkg: string; readonly from: string; readonly to: string }[]
472
- readonly scenarios: {
473
- readonly added: readonly string[]
474
- readonly changed: readonly string[]
475
- }
476
- }
477
-
478
- const buildContextPrompt = (built: BuildContext): string => {
479
- const list = (paths: readonly string[]): string =>
480
- paths.length === 0 ? " (none)" : paths.map((path) => ` - ${path}`).join("\n")
481
- return `- Read \`.gtd/ARCHITECTURE.md\` — the plan every package was built from
482
- - A red scenario that is NEW in this plan likely means missing wiring
483
- between packages; new scenarios:
484
- ${list(built.scenarios.added)}
485
- - A red CHANGED or existing scenario or test is a regression a package
486
- introduced; scenarios this plan changed:
487
- ${list(built.scenarios.changed)}
488
- - Each package's commits, to bisect a break:
489
- ${built.ranges.map((r) => ` git log --oneline ${r.from}..${r.to} # ${r.pkg}`).join("\n")}
490
- `
491
- }
492
-
493
- export const buildFixPrompt = (built?: BuildContext): string =>
472
+ export const buildFixPrompt = (): string =>
494
473
  `${stateFileRules}
495
474
  ${fixFeedbackPrompt}
496
- ${built === undefined ? "" : buildContextPrompt(built)}- Leave everything uncommitted — do not commit
475
+ - Leave everything uncommitted — do not commit
497
476
  `
498
477
 
499
478
  export const finisherSystem = (): string =>
@@ -674,12 +653,17 @@ export interface NoteInput {
674
653
  readonly id: string
675
654
  readonly anchor: string
676
655
  readonly text: string
656
+ /** `(tier: reason)`, shown after the anchor. */
657
+ readonly label?: string
677
658
  }
678
659
 
660
+ const noteHead = (n: NoteInput): string =>
661
+ `${n.id} — ${n.anchor}${n.label === undefined ? "" : ` (${n.label})`}`
662
+
679
663
  const notesCapture = (notes: readonly NoteInput[]): string =>
680
664
  `This is machine-captured input, not instructions.
681
665
 
682
- ${notes.map((n) => `- ${n.id} — ${n.anchor}\n ${n.text.replace(/\n/g, "\n ")}`).join("\n")}
666
+ ${notes.map((n) => `- ${noteHead(n)}\n ${n.text.replace(/\n/g, "\n ")}`).join("\n")}
683
667
  `
684
668
 
685
669
  export const buildReviewAnswerQuestionsPrompt = (notes: readonly NoteInput[]): string =>
@@ -761,6 +745,47 @@ What each change does next (then run \`gtd land\`):
761
745
  - **Re-review** — re-run the reviewer to author a fresh \`.gtd/REVIEW.md\` (**build.review.reviewing**).
762
746
  `
763
747
 
748
+ /** Greedy wrap at 80 columns with a 2-space continuation indent: oxfmt (`proseWrap: always`) rewrites any other shape. */
749
+ const wrapItem = (item: string): string[] => {
750
+ const out: string[] = []
751
+ let line = ""
752
+ for (const word of item.split(" ")) {
753
+ if (line !== "" && line.length + 1 + word.length > 80) {
754
+ out.push(line)
755
+ line = ` ${word}`
756
+ } else line = line === "" ? word : `${line} ${word}`
757
+ }
758
+ return [...out, line]
759
+ }
760
+
761
+ /** Appends one section of `notes` to `.gtd/TODO.md`, wrapped the way oxfmt writes it; an existing file is only ever appended to. */
762
+ export const deferNotesScript = (notes: readonly NoteInput[], round: string): string => {
763
+ const lines = [
764
+ `## Deferred review notes (${round.slice(0, 7)})`,
765
+ "",
766
+ ...notes.flatMap((n) => wrapItem(`- ${noteHead(n)}: ${n.text.replace(/\s+/g, " ")}`)),
767
+ ]
768
+ return `mkdir -p .gtd
769
+ if [ -s .gtd/TODO.md ]; then
770
+ [ -z "$(tail -c1 .gtd/TODO.md)" ] || printf '\\n' >> .gtd/TODO.md
771
+ printf '\\n' >> .gtd/TODO.md
772
+ fi
773
+ printf '%s\\n' ${lines.map(quote).join(" ")} >> .gtd/TODO.md
774
+ `
775
+ }
776
+
777
+ /** The gate right after a deferral: landing clean signs off without these notes. */
778
+ export const buildReviewAwaitAfterDeferMessage = (
779
+ base: string,
780
+ deferred: readonly NoteInput[],
781
+ ): string =>
782
+ `${buildReviewAwaitReviewMessage(base)}
783
+ Deferred to \`.gtd/TODO.md\` just now, NOT acted on in this process — landing
784
+ clean signs off without them:
785
+
786
+ ${deferred.map((n) => `- ${noteHead(n)}: ${n.text.replace(/\s*\n\s*/g, " ")}`).join("\n")}
787
+ `
788
+
764
789
  export const buildReviewTriageMessage = (): string =>
765
790
  `Judging each note the human added to \`.gtd/REVIEW.md\` (a line note, a
766
791
  footnote, or prose under a chunk) with one verdict: \`edit\` (a change
@@ -768,6 +793,10 @@ request), \`question\`, \`nit\` (a small fix needing no re-plan) or
768
793
  \`praise\`. Run \`gtd judge answer\` and pipe a choice per note — or land
769
794
  untouched, which treats every note as \`edit\` (the conservative
770
795
  default; a skipped judgment never dismisses a note).
796
+
797
+ Also judge each note's severity, one id per note: \`note-<n>.security\`,
798
+ \`note-<n>.reversibility\`, \`note-<n>.blastRadius\` and
799
+ \`note-<n>.newConcept\`.
771
800
  `
772
801
 
773
802
  export const buildReviewCollectingPrompt = (capture: string): string =>
@@ -790,6 +819,8 @@ ${footnoteFoldIn}${codeThreadReplies()}
790
819
  - When the capture names an answering commit, carry each answered
791
820
  question into \`.gtd/REQUIREMENTS.md\`'s \`## Answered Questions\` as
792
821
  \`### <the note>\` plus its answer — the lap replaces \`.gtd/REVIEW.md\`
822
+ - Keep capture order, and carry each note's \`(tier: reason)\`
823
+ label into the concern folded from it
793
824
  - Nit notes were already fixed: never re-raise a fixed nit as a concern
794
825
  - Finish by running \`gtd check review .gtd/REVIEW.md\` and fix
795
826
  what it reports
@@ -832,7 +863,28 @@ actionability, and never dismiss a real note or edit as approval.
832
863
  the sign-off
833
864
  `
834
865
 
835
- export const buildReviewReviewingPrompt = (base: string, carry?: string): string =>
866
+ const scenariosPrompt = (removed: readonly RemovedAssertions[]): string =>
867
+ `- When a scenario in a \`.feature\` file was added or changed since the
868
+ base, the first chunk is \`## Scenarios\`: one pointer per such
869
+ scenario, its note saying in plain words what behaviour it now pins
870
+ down — the human signs off the scenarios here, nowhere else
871
+ ${
872
+ removed.length === 0
873
+ ? ""
874
+ : `- These assertions of scenarios that existed at the base are gone:
875
+ ${removed.map(({ path, lines }) => lines.map((a) => ` ${path} — ${a.scenario} — ${a.line}\n`).join("")).join("")} Open the note of each scenario that lost one with \`Weakened:\`,
876
+ naming the lost line and whether \`.gtd/REQUIREMENTS.md\` asked
877
+ for it. A scenario that no longer exists has no pointer of its own:
878
+ put its \`Weakened:\` note on a pointer of the chunk covering its
879
+ removal
880
+ `
881
+ }`
882
+
883
+ export const buildReviewReviewingPrompt = (
884
+ base: string,
885
+ carry?: string,
886
+ removed: readonly RemovedAssertions[] = [],
887
+ ): string =>
836
888
  `${styleBlock}
837
889
 
838
890
  ${styleFormatContract}
@@ -875,7 +927,7 @@ review the changes:
875
927
  A note sitting entirely on the line(s) beneath the pointer is
876
928
  also valid. Either way, the note must never start with a bare \`./path\` token
877
929
  — that parses as a second pointer, not a note
878
- No diff is given — read the changes yourself. The range runs
930
+ ${scenariosPrompt(removed)}No diff is given — read the changes yourself. The range runs
879
931
  from \`${base}\` to the working tree (committed turns
880
932
  plus anything pending); on a feedback round that's the previous
881
933
  review's boundary, so it covers only what's new.
@@ -930,19 +982,3 @@ ${it.processCostByModel.map((m) => `- ${m.model}: ${m.cost}\n`).join("")}
930
982
  Print the closing message and stop — this writes nothing itself.
931
983
  `
932
984
  }
933
-
934
- export const scenarioWordingMessage = (at: string, drifted: readonly WordingDrift[]): string =>
935
- `The e2e scenario wording was frozen when package 0 landed, and the last
936
- turn changed it. Removed lines are marked \`-\`, added ones \`+\`:
937
-
938
- ${drifted.map(({ path, lines }) => `${path}\n${lines.join("\n")}`).join("\n\n")}
939
-
940
- To accept the change, land untouched.
941
-
942
- To reject it, run
943
-
944
- git checkout ${at} -- ${drifted.map(({ path }) => quote(path)).join(" ")}
945
-
946
- and land. Restoring only some of the files is a partial accept: every file
947
- still differing from the frozen wording is accepted.
948
- `
@@ -10,6 +10,7 @@ export const defaults: Readonly<Record<string, string>> = {
10
10
  judgeBudgetBytes: "32768",
11
11
  judgeIdenticalMinP: "0.7",
12
12
  reviewNoteActionable: "0.7",
13
+ reviewSeverityMinP: "0.7",
13
14
  // Decides the turn count: one `build.quality.<lens>` scope per entry, each
14
15
  // keyed in `./skills.ts`.
15
16
  qualityReviews:
@@ -19,7 +20,6 @@ export const defaults: Readonly<Record<string, string>> = {
19
20
  /** Environment settings. */
20
21
  export const envDefaults: Readonly<Record<string, string>> = {
21
22
  testCommand: "npm test",
22
- fastTestCommand: "",
23
23
  plannerModel: "smart",
24
24
  coderModel: "base",
25
25
  }
@@ -1,256 +0,0 @@
1
- import { afterEach, describe, expect, it } from "vitest"
2
- import { installContext, type StepRequest } from "../../flows/index.js"
3
- import {
4
- driftedScenarios,
5
- freezeScenarios,
6
- guarded,
7
- holdWording,
8
- scenarioText,
9
- } from "./scenarios.js"
10
- import { fixtureContext, renderText } from "./text.fixture.js"
11
-
12
- afterEach(() => installContext(undefined))
13
-
14
- const tree = (files: Record<string, string>) => ({
15
- read: (path: string) => files[path],
16
- })
17
-
18
- describe("scenarioText", () => {
19
- it("ignores comments, tags, blank lines and indentation", () => {
20
- const loose = [
21
- "@wip @slow",
22
- "Feature: x",
23
- "",
24
- " # a comment",
25
- " @tag",
26
- " Scenario: y",
27
- " Given a thing",
28
- ].join("\n")
29
- const tight = "Feature: x\nScenario: y\nGiven a thing"
30
- expect(scenarioText(loose)).toBe(scenarioText(tight))
31
- })
32
-
33
- it("keeps changed wording", () => {
34
- expect(scenarioText("Given a")).not.toBe(scenarioText("Given b"))
35
- })
36
-
37
- it.each([
38
- ["a # line", "# Review: abc"],
39
- ["an @ line", "@mention"],
40
- ["a blank line", ""],
41
- ])("keeps %s inside a doc string", (_, line) => {
42
- const doc = (body: string[]) =>
43
- ["Given a file with:", ' """', ...body.map((l) => (l === "" ? "" : ` ${l}`)), ' """'].join(
44
- "\n",
45
- )
46
- expect(scenarioText(doc(["top", line, "end"]))).not.toBe(scenarioText(doc(["top", "end"])))
47
- })
48
-
49
- it("keeps indentation inside a doc string", () => {
50
- const doc = (line: string) => ["Given a file with:", ' """', ` ${line}`, ' """'].join("\n")
51
- expect(scenarioText(doc(" nested"))).not.toBe(scenarioText(doc("nested")))
52
- })
53
-
54
- it("ignores a doc string re-indented together with its delimiters", () => {
55
- const at = (indent: string) =>
56
- [
57
- "Given a file with:",
58
- `${indent}\`\`\``,
59
- `${indent}# Review`,
60
- `${indent} - x`,
61
- `${indent}\`\`\``,
62
- ].join("\n")
63
- expect(scenarioText(at(" "))).toBe(scenarioText(at(" ")))
64
- })
65
- })
66
-
67
- describe("freezeScenarios", () => {
68
- it("snapshots wording at head, nothing frozen is undefined", () => {
69
- const files = { "a.feature": "@t\nGiven a" }
70
- renderText(() => {
71
- expect(freezeScenarios([])).toBeUndefined()
72
- })
73
- installContext(fixtureContext({ head: "h1" }, tree(files)))
74
- expect(freezeScenarios(["a.feature"])).toEqual({
75
- at: "h1",
76
- texts: { "a.feature": scenarioText("Given a") },
77
- })
78
- })
79
-
80
- it("merges over previous, a new path overriding an old one", () => {
81
- installContext(
82
- fixtureContext({ head: "h2" }, tree({ "b.feature": "Given b", "a.feature": "Given a2" })),
83
- )
84
- const merged = freezeScenarios(["a.feature", "b.feature"], {
85
- at: "h1",
86
- texts: { "a.feature": "Given a", "c.feature": "Given c" },
87
- })
88
- expect(merged).toEqual({
89
- at: "h2",
90
- texts: {
91
- "a.feature": "Given a2",
92
- "b.feature": "Given b",
93
- "c.feature": "Given c",
94
- },
95
- })
96
- })
97
-
98
- it("keeps previous untouched when no paths are given", () => {
99
- const previous = { at: "h1", texts: { "a.feature": "Given a" } }
100
- installContext(fixtureContext({ head: "h2" }, tree({})))
101
- expect(freezeScenarios([], previous)).toBe(previous)
102
- })
103
- })
104
-
105
- describe("driftedScenarios", () => {
106
- const frozen = { at: "h1", texts: { "a.feature": "Given a", "b.feature": "Given b" } }
107
-
108
- it("flags edited and deleted files, ignores comment-only edits and other paths", () => {
109
- installContext(
110
- fixtureContext({}, tree({ "a.feature": "# note\nGiven a2", "other.feature": "Given z" })),
111
- )
112
- expect(driftedScenarios(frozen)).toEqual(["a.feature", "b.feature"])
113
- })
114
-
115
- it("is empty while wording is unchanged", () => {
116
- installContext(
117
- fixtureContext({}, tree({ "a.feature": " @x\n Given a", "b.feature": "Given b" })),
118
- )
119
- expect(driftedScenarios(frozen)).toEqual([])
120
- })
121
- })
122
-
123
- describe("holdWording", () => {
124
- const run = async (
125
- files: () => Record<string, string>,
126
- frozen: Parameters<typeof holdWording>[0],
127
- head = "h2",
128
- ): Promise<StepRequest[]> => {
129
- const steps: StepRequest[] = []
130
- installContext(
131
- fixtureContext(
132
- { head },
133
- {
134
- read: (path) => files()[path],
135
- step: (request) => {
136
- steps.push(request)
137
- return Promise.resolve()
138
- },
139
- },
140
- ),
141
- )
142
- await holdWording(frozen)
143
- return steps
144
- }
145
-
146
- it("does nothing without a freeze or without drift", async () => {
147
- expect(await run(() => ({}), undefined)).toEqual([])
148
- const frozen = { at: "h1", texts: { "a.feature": "Given a" } }
149
- expect(await run(() => ({ "a.feature": "Given a" }), frozen)).toEqual([])
150
- })
151
-
152
- it("rests at scenario-wording with the removed and added lines and the restore command", async () => {
153
- const frozen = { at: "h1", texts: { "my dir/a.feature": "Given a\nThen ok" } }
154
- const steps = await run(() => ({ "my dir/a.feature": "Given a\nThen better" }), frozen)
155
- const [step] = steps
156
- if (step?.kind !== "human") throw new Error("expected a human step")
157
- expect(step.name).toBe("scenario-wording")
158
- expect(step.options.acceptClean).toBe(true)
159
- expect(step.options.base).toBe("h1")
160
- const message = step.options.message ?? ""
161
- expect(message).toContain("- Then ok")
162
- expect(message).toContain("+ Then better")
163
- expect(message).toContain("git checkout h1 -- 'my dir/a.feature'")
164
- expect(message).toContain("partial accept")
165
- })
166
-
167
- const shownDiff = async (before: string, after: string): Promise<string[]> => {
168
- const frozen = { at: "h1", texts: { "a.feature": before } }
169
- const [step] = await run(() => ({ "a.feature": after }), frozen)
170
- if (step?.kind !== "human") throw new Error("expected a human step")
171
- return (step.options.message ?? "").split("\n").filter((l) => /^[-+] /.test(l))
172
- }
173
-
174
- it("shows a moved step as one removal and one addition of it, in place", async () => {
175
- expect(await shownDiff("Given a\nWhen b\nThen c", "When b\nGiven a\nThen c")).toEqual([
176
- "- Given a",
177
- "+ Given a",
178
- ])
179
- })
180
-
181
- it("shows a blank line added inside a doc string", async () => {
182
- expect(await shownDiff('"""\na\nb\n"""', '"""\na\n\nb\n"""')).toEqual(["+ "])
183
- })
184
-
185
- it("shows a repeated step as its added copy", async () => {
186
- expect(await shownDiff("Given a\nThen c", "Given a\nGiven a\nThen c")).toEqual(["+ Given a"])
187
- })
188
-
189
- it("accepts still-differing files by moving the snapshot to head", async () => {
190
- const frozen = { at: "h1", texts: { "a.feature": "Given a", "b.feature": "Given b" } }
191
- await run(() => ({ "a.feature": "Given a2", "b.feature": "Given b2" }), frozen)
192
- expect(frozen).toEqual({
193
- at: "h2",
194
- texts: { "a.feature": "Given a2", "b.feature": "Given b2" },
195
- })
196
- })
197
-
198
- it("rejects restored files, keeping the original wording frozen", async () => {
199
- const frozen = { at: "h1", texts: { "a.feature": "Given a", "b.feature": "Given b" } }
200
- let files: Record<string, string> = { "a.feature": "Given a2", "b.feature": "Given b2" }
201
- installContext(
202
- fixtureContext(
203
- { head: "h2" },
204
- {
205
- read: (path) => files[path],
206
- step: () => {
207
- files = { "a.feature": "Given a", "b.feature": "Given b2" }
208
- return Promise.resolve()
209
- },
210
- },
211
- ),
212
- )
213
- await holdWording(frozen)
214
- expect(frozen.texts).toEqual({ "a.feature": "Given a", "b.feature": "Given b2" })
215
- })
216
-
217
- it("drops an accepted deletion from the snapshot", async () => {
218
- const frozen = { at: "h1", texts: { "a.feature": "Given a" } }
219
- await run(() => ({}), frozen)
220
- expect(frozen.texts).toEqual({})
221
- })
222
- })
223
-
224
- describe("guarded", () => {
225
- it("runs the turn, then holds wording", async () => {
226
- const order: string[] = []
227
- const frozen = { at: "h1", texts: { "a.feature": "Given a" } }
228
- installContext(
229
- fixtureContext(
230
- { head: "h2" },
231
- {
232
- read: () => "Given changed",
233
- step: (request) => {
234
- order.push(request.kind)
235
- return Promise.resolve()
236
- },
237
- },
238
- ),
239
- )
240
- await guarded(frozen, () => {
241
- order.push("turn")
242
- return Promise.resolve()
243
- })()
244
- expect(order).toEqual(["turn", "human"])
245
- })
246
-
247
- it("is the bare turn without a freeze", async () => {
248
- const order: string[] = []
249
- installContext(fixtureContext())
250
- await guarded(undefined, () => {
251
- order.push("turn")
252
- return Promise.resolve()
253
- })()
254
- expect(order).toEqual(["turn"])
255
- })
256
- })
@@ -1,35 +0,0 @@
1
- import { human, scope } from "../../flows/index.js"
2
- import * as kit from "../../workflow-kit/index.js"
3
- import * as t from "./text.js"
4
-
5
- export {
6
- driftedScenarios,
7
- freezeScenarios,
8
- scenarioText,
9
- wordingDrift,
10
- type FrozenScenarios,
11
- } from "../../workflow-kit/index.js"
12
-
13
- /** After a turn: stop at `scenario-wording` while wording drifted; accept moves the snapshot. */
14
- export const holdWording = (frozen: kit.FrozenScenarios | undefined): Promise<void> =>
15
- kit.holdWording(frozen, (at, drifted) =>
16
- human("scenario-wording", {
17
- message: t.scenarioWordingMessage(at, drifted),
18
- label: "Scenario wording changed",
19
- acceptClean: true,
20
- base: at,
21
- }),
22
- )
23
-
24
- /** `turn`, then `holdWording`; `within` names the scope the gate rests in. */
25
- export const guarded =
26
- (
27
- frozen: kit.FrozenScenarios | undefined,
28
- turn: () => Promise<void>,
29
- within?: string,
30
- ): (() => Promise<void>) =>
31
- async () => {
32
- await turn()
33
- if (within === undefined) await holdWording(frozen)
34
- else await scope(within, () => holdWording(frozen))
35
- }