nukadoko 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.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +417 -0
  3. data/README.ja.md +62 -7
  4. data/README.md +19 -5
  5. data/exe/nuka +8 -0
  6. data/lib/nukadoko/aria_snapshot.rb +1008 -0
  7. data/lib/nukadoko/aria_tree.rb +150 -0
  8. data/lib/nukadoko/base.rb +294 -0
  9. data/lib/nukadoko/check.rb +669 -22
  10. data/lib/nukadoko/claim_check.rb +177 -0
  11. data/lib/nukadoko/claim_check_run.rb +293 -0
  12. data/lib/nukadoko/claim_line.rb +381 -0
  13. data/lib/nukadoko/claim_rules.rb +519 -0
  14. data/lib/nukadoko/claim_sides.rb +469 -0
  15. data/lib/nukadoko/claims.rb +576 -37
  16. data/lib/nukadoko/cli.rb +814 -22
  17. data/lib/nukadoko/codes.json +947 -0
  18. data/lib/nukadoko/codes.rb +19 -0
  19. data/lib/nukadoko/command.rb +214 -12
  20. data/lib/nukadoko/criteria.rb +172 -0
  21. data/lib/nukadoko/definition.rb +33 -41
  22. data/lib/nukadoko/env_check.rb +88 -0
  23. data/lib/nukadoko/features.rb +80 -10
  24. data/lib/nukadoko/fixtures.rb +329 -11
  25. data/lib/nukadoko/http_recording.rb +68 -0
  26. data/lib/nukadoko/init.rb +129 -0
  27. data/lib/nukadoko/js_json.rb +274 -0
  28. data/lib/nukadoko/js_pattern.rb +531 -0
  29. data/lib/nukadoko/judge.rb +221 -0
  30. data/lib/nukadoko/judgment_file.rb +78 -0
  31. data/lib/nukadoko/judgments.rb +256 -0
  32. data/lib/nukadoko/literal.rb +129 -0
  33. data/lib/nukadoko/measured.rb +105 -0
  34. data/lib/nukadoko/order.rb +84 -0
  35. data/lib/nukadoko/parts.rb +43 -22
  36. data/lib/nukadoko/pattern.rb +73 -3
  37. data/lib/nukadoko/poll.rb +21 -8
  38. data/lib/nukadoko/program.rb +105 -17
  39. data/lib/nukadoko/project_files.rb +17 -0
  40. data/lib/nukadoko/project_fixtures.rb +17 -2
  41. data/lib/nukadoko/project_program.rb +119 -0
  42. data/lib/nukadoko/report_allure.rb +751 -0
  43. data/lib/nukadoko/report_messages.rb +167 -0
  44. data/lib/nukadoko/report_run.rb +169 -0
  45. data/lib/nukadoko/run.rb +898 -91
  46. data/lib/nukadoko/run_record.rb +535 -0
  47. data/lib/nukadoko/scaffold.rb +1015 -0
  48. data/lib/nukadoko/schema.rb +120 -21
  49. data/lib/nukadoko/secrets.rb +375 -0
  50. data/lib/nukadoko/selection.rb +163 -0
  51. data/lib/nukadoko/signature.rb +4 -1
  52. data/lib/nukadoko/skill.rb +36 -0
  53. data/lib/nukadoko/spaces.rb +28 -0
  54. data/lib/nukadoko/step.rb +68 -21
  55. data/lib/nukadoko/summary.rb +662 -0
  56. data/lib/nukadoko/table.rb +34 -2
  57. data/lib/nukadoko/text_fit.rb +179 -0
  58. data/lib/nukadoko/trace.rb +244 -0
  59. data/lib/nukadoko/trace_actions.rb +116 -0
  60. data/lib/nukadoko/tree_passes.rb +122 -0
  61. data/lib/nukadoko/verdict.rb +128 -0
  62. data/lib/nukadoko/version.rb +2 -1
  63. data/lib/nukadoko/vocabulary.rb +6 -0
  64. data/lib/nukadoko/walk.rb +305 -0
  65. data/lib/nukadoko/walk_files.rb +473 -0
  66. data/lib/nukadoko/walk_step.rb +149 -0
  67. data/lib/nukadoko.rb +60 -2
  68. data/llms.txt +297 -0
  69. data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
  70. data/sig/generated/nukadoko/aria_tree.rbs +142 -0
  71. data/sig/generated/nukadoko/base.rbs +142 -0
  72. data/sig/generated/nukadoko/check.rbs +255 -0
  73. data/sig/generated/nukadoko/claim_check.rbs +118 -0
  74. data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
  75. data/sig/generated/nukadoko/claim_line.rbs +158 -0
  76. data/sig/generated/nukadoko/claim_rules.rbs +172 -0
  77. data/sig/generated/nukadoko/claim_sides.rbs +207 -0
  78. data/sig/generated/nukadoko/claims.rbs +208 -0
  79. data/sig/generated/nukadoko/cli.rbs +182 -0
  80. data/sig/generated/nukadoko/codes.rbs +16 -0
  81. data/sig/generated/nukadoko/command.rbs +109 -0
  82. data/sig/generated/nukadoko/criteria.rbs +83 -0
  83. data/sig/generated/nukadoko/definition.rbs +30 -0
  84. data/sig/generated/nukadoko/env_check.rbs +34 -0
  85. data/sig/generated/nukadoko/features.rbs +101 -0
  86. data/sig/generated/nukadoko/fixtures.rbs +175 -0
  87. data/sig/generated/nukadoko/http_recording.rbs +29 -0
  88. data/sig/generated/nukadoko/init.rbs +64 -0
  89. data/sig/generated/nukadoko/js_json.rbs +109 -0
  90. data/sig/generated/nukadoko/js_pattern.rbs +194 -0
  91. data/sig/generated/nukadoko/judge.rbs +64 -0
  92. data/sig/generated/nukadoko/judgment_file.rbs +39 -0
  93. data/sig/generated/nukadoko/judgments.rbs +120 -0
  94. data/sig/generated/nukadoko/literal.rbs +71 -0
  95. data/sig/generated/nukadoko/measured.rbs +42 -0
  96. data/sig/generated/nukadoko/order.rbs +54 -0
  97. data/sig/generated/nukadoko/parts.rbs +35 -0
  98. data/sig/generated/nukadoko/pattern.rbs +62 -0
  99. data/sig/generated/nukadoko/poll.rbs +41 -0
  100. data/sig/generated/nukadoko/program.rbs +101 -0
  101. data/sig/generated/nukadoko/project_files.rbs +19 -0
  102. data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
  103. data/sig/generated/nukadoko/project_program.rbs +55 -0
  104. data/sig/generated/nukadoko/report_allure.rbs +268 -0
  105. data/sig/generated/nukadoko/report_messages.rbs +68 -0
  106. data/sig/generated/nukadoko/report_run.rbs +102 -0
  107. data/sig/generated/nukadoko/run.rbs +264 -0
  108. data/sig/generated/nukadoko/run_record.rbs +175 -0
  109. data/sig/generated/nukadoko/scaffold.rbs +328 -0
  110. data/sig/generated/nukadoko/schema.rbs +155 -0
  111. data/sig/generated/nukadoko/secrets.rbs +172 -0
  112. data/sig/generated/nukadoko/selection.rbs +73 -0
  113. data/sig/generated/nukadoko/signature.rbs +17 -0
  114. data/sig/generated/nukadoko/skill.rbs +20 -0
  115. data/sig/generated/nukadoko/spaces.rbs +31 -0
  116. data/sig/generated/nukadoko/step.rbs +115 -0
  117. data/sig/generated/nukadoko/summary.rbs +204 -0
  118. data/sig/generated/nukadoko/table.rbs +43 -0
  119. data/sig/generated/nukadoko/text_fit.rbs +70 -0
  120. data/sig/generated/nukadoko/trace.rbs +127 -0
  121. data/sig/generated/nukadoko/trace_actions.rbs +40 -0
  122. data/sig/generated/nukadoko/tree_passes.rbs +48 -0
  123. data/sig/generated/nukadoko/verdict.rbs +56 -0
  124. data/sig/generated/nukadoko/version.rbs +5 -0
  125. data/sig/generated/nukadoko/vocabulary.rbs +25 -0
  126. data/sig/generated/nukadoko/walk.rbs +139 -0
  127. data/sig/generated/nukadoko/walk_files.rbs +189 -0
  128. data/sig/generated/nukadoko/walk_step.rbs +50 -0
  129. data/sig/generated/nukadoko.rbs +26 -0
  130. data/sig/nukadoko.rbs +5 -48
  131. data/skills/nukadoko/SKILL.md +120 -0
  132. data/skills/nukadoko/references/checking-steps.md +200 -0
  133. data/skills/nukadoko/references/diagnosing.md +200 -0
  134. data/skills/nukadoko/references/done.md +99 -0
  135. data/skills/nukadoko/references/evidence.md +124 -0
  136. data/skills/nukadoko/references/examples/cli.md +230 -0
  137. data/skills/nukadoko/references/examples/http-api.md +342 -0
  138. data/skills/nukadoko/references/examples/workflow.md +173 -0
  139. data/skills/nukadoko/references/exploring.md +184 -0
  140. data/skills/nukadoko/references/fixtures.md +198 -0
  141. data/skills/nukadoko/references/from-prose.md +51 -0
  142. data/skills/nukadoko/references/judgments.md +95 -0
  143. data/skills/nukadoko/references/maintenance.md +97 -0
  144. data/skills/nukadoko/references/merge-risk.md +74 -0
  145. data/skills/nukadoko/references/parts.md +152 -0
  146. data/skills/nukadoko/references/perturbed-worlds.md +109 -0
  147. data/skills/nukadoko/references/program.md +200 -0
  148. data/skills/nukadoko/references/reviewing.md +200 -0
  149. data/skills/nukadoko/references/running.md +200 -0
  150. data/skills/nukadoko/references/scenario-rules.md +188 -0
  151. data/skills/nukadoko/references/states.md +66 -0
  152. data/skills/nukadoko/references/step-files.md +200 -0
  153. data/skills/nukadoko/references/verdicts.md +200 -0
  154. data/skills/nukadoko/references/writing-steps.md +200 -0
  155. data/skills/nukadoko/references/writing-the-feature.md +165 -0
  156. data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
  157. data/skills/nukadoko/scripts/merge-risk.jq +56 -0
  158. data/skills/nukadoko-verification/SKILL.md +263 -0
  159. metadata +133 -1
@@ -0,0 +1,74 @@
1
+ # Answering a reviewer's merge-risk questions from a run
2
+
3
+ Use this when a person, or a review tool, asks how risky a change is
4
+ before they merge it. A common rubric asks five questions: is the change
5
+ verified, does it do only what it says, what does it touch, how hard is
6
+ it to undo, and will its failures be seen. A model that scores those
7
+ questions from the diff guesses. `nuka run --base` already measured most
8
+ of the answers, so read them from its run.json and say plainly which
9
+ parts it did not measure.
10
+
11
+ ## 1. Run against the base
12
+
13
+ ```sh
14
+ npx nuka run --base origin/main
15
+ jq -r --argjson sensitive '["payments", "/admin/:id"]' \
16
+ -f node_modules/nukadoko/skills/nukadoko/scripts/merge-risk.jq \
17
+ .nukadoko/runs/<run_id>/run.json
18
+ ```
19
+
20
+ Every answer below except Verification is a difference between the base
21
+ world and head, so a run without `--base` gives no answer. The script says
22
+ so and stops.
23
+
24
+ `sensitive` lists the tables and routes this project treats as sensitive:
25
+ auth, permissions, billing. Take the list from the project (its
26
+ CODEOWNERS, its docs, or the person), not from table names. A list you
27
+ made up is a guess the output then repeats as a fact. Leave it out when
28
+ there is none, and the output says no list was given.
29
+
30
+ ## 2. Read each answer
31
+
32
+ The script prints one section for each question. Each line is a fact the
33
+ run measured, or a line that names what it did not measure.
34
+
35
+ **Verification.** Each criterion's verdict from the table
36
+ (`references/verdicts.md`). A `held` verdict on a criterion that judges no
37
+ claim proves no outcome, so the script names it. `failed` and `unproven`
38
+ rows are not risk to weigh: fix them before the change goes to review.
39
+
40
+ **Alignment.** Each INTENT.md row and its result (`references/done.md`),
41
+ then each difference that no row, no sentence, and no new or changed
42
+ criterion explains. A line under "declared nowhere" is a change the
43
+ author did not say they meant: a fix in passing, or a side effect. When the
44
+ change has an INTENT.md, the run already fails on it as
45
+ `intent-unintended`. Remove the change or declare it.
46
+
47
+ **Impact.** The tables and routes that head touches differently from the
48
+ base, and the sensitive ones among them. This section reads every
49
+ difference, including those a criterion explains: a new criterion that
50
+ deletes rows explains its own difference, but the delete is still what a
51
+ reviewer wants to see first.
52
+
53
+ **Rollback cost.** The deletes and updates that are new at head. Data the
54
+ change removes or overwrites is harder to restore than a row it adds. The
55
+ run does not see schema changes, backfills, or anything outside the
56
+ program's execution events, and the script says so on every run. Read the
57
+ migration files yourself for those, and say that you read them.
58
+
59
+ **Error detection.** Unexpected failures (`references/verdicts.md`), the
60
+ unhandled errors new at head, and the errors the program caught and
61
+ passed over that are new at head. Execution events have no field that
62
+ says an error reached monitoring, so for a caught error the run cannot
63
+ tell a swallowed error from a reported one. Say that, and point the
64
+ reviewer at the place in the code that catches it.
65
+
66
+ ## 3. Report it
67
+
68
+ Give the person the script's output as it printed it, then one sentence
69
+ for each section that names what to look at first. Do not turn it into a
70
+ score. A number adds nothing the lines do not say, and it hides which
71
+ parts were measured and which were not.
72
+
73
+ When a review tool reads the output, pass it the lines, not your summary
74
+ of them.
@@ -0,0 +1,152 @@
1
+ # Helpers, parts, and splitting a step
2
+
3
+ ## Helper, part, or step?
4
+
5
+ Because a chained value can only come from a step, `from` pushes an
6
+ operation toward "one step, one responsibility," and that can leave a
7
+ scenario with a line that exists only to move a value from one step to the
8
+ next, never to record anything the feature's reader cares about (say, "And
9
+ the project's billing page is fetched"). A feature file is written for
10
+ someone who is not necessarily an engineer; a line like that is a cost to
11
+ that reader, not information.
12
+
13
+ Ask two questions, in order. Does the operation mean something to the
14
+ person reading the scenario, not to the code moving data between steps?
15
+
16
+ - Yes: make it a step. The run gains a step record for it, and the run
17
+ summary a line.
18
+ - No: ask the second question.
19
+
20
+ After a failure, what should be knowable about it?
21
+
22
+ - Its inputs and its result, under a contract worth stating: make it a
23
+ **part**. Define it with `defineStep` and no `pattern`, list it in the
24
+ calling step's `parts`, and run it with `await call(thePart, {...})`.
25
+ Destructure `call` in that step's `run`, not in a fixture: `nuka check`
26
+ reports a fixture that names it.
27
+ Its args and its result are validated exactly as a step's are, and the
28
+ call is recorded under `calls` on the calling step's own step record.
29
+ - Nothing a schema would help with: write an ordinary function under
30
+ `features/steps/lib/` and call it directly. What is given up is that
31
+ helper's own entry in the record; the HTTP it performs is still counted
32
+ in the calling step's `observed`, and the `section` fixture can still
33
+ mark how far execution got while running it. A function that formats a
34
+ payload or picks a fixture file belongs here. Making it a part would
35
+ buy a schema to maintain and nothing else.
36
+ A helper that runs the CLI under test calls `runCommand` from
37
+ `nukadoko` instead of `spawnSync` or `execFileSync`: it returns
38
+ `{ exitCode, signal, stdout, stderr, files }` without throwing on a nonzero
39
+ exit, so a step that needs the command to succeed checks `exitCode`
40
+ itself, and each process it starts is listed in the calling step's
41
+ `observed.processes`, so a failure record shows the command, its working
42
+ directory, its exit code, and the files it changed. A Then that claims
43
+ what the command wrote reads those files from the record, through a
44
+ claim step's `files`, never from a list the step returns:
45
+ `files: { written: { of: runBuild, change: ["added", "changed"], under: "src" } }`
46
+ with `{ actual: "written", compare: "equal", expected: { literal: [] } }`
47
+ for "changed no file under src/" (`has-item` a captured path, or
48
+ `has-same-items` the docstring with `expected_view: "lines"`). The claim
49
+ is `unjudged` when the producer ran no `runCommand`, or a walk was not
50
+ made: a list nukadoko never measured is not an empty one. A process
51
+ started through `spawnSync` or `execFileSync` instead is only named in
52
+ `observed.unmeasured`, with nothing of what it printed or changed. A secret the step holds itself and passes
53
+ as an argument goes in `redact: { NAME: value }`, so the record shows
54
+ `{{secret.NAME}}` instead of the value.
55
+
56
+ A part is a step, not a new kind of thing. That is what makes the split
57
+ below cost the feature file nothing.
58
+
59
+ A part's `gives` and `ends` say nothing about the scenario on their own:
60
+ the line runs the composite. When a part signs someone in, put the state
61
+ in the composite's own `gives` too. A composite that names no state its
62
+ parts give or end leaves that state unknown, and `nuka check` judges no
63
+ line that requires it after this one (`states.md`).
64
+
65
+ ## Splitting a step a second scenario needs half of
66
+
67
+ The original step keeps its pattern, its `args`, and its `returns`. Only
68
+ its body moves.
69
+
70
+ 1. Move each half into its own file under `features/steps/`, defined with
71
+ `defineStep`, with no `pattern`. Give each one the `args` and `returns`
72
+ it actually demands, not the ones its current caller happens to have.
73
+ 2. List them in the original step's `parts`, and replace the moved code
74
+ with `await call(thatPart, {...})`.
75
+ 3. Run `nuka check`. A part the caller did not list is refused at the
76
+ call, and a step declaring `mutates: false` while listing a part that
77
+ declares `mutates: true` is an error: the composite's own flag has to
78
+ account for what it may call.
79
+ 4. Run the original scenario. Its feature file did not change, so a
80
+ reviewer who approved that sentence has nothing new to read.
81
+
82
+ `parts` takes the imported step objects themselves, never their names,
83
+ the same way `from` names its producer:
84
+
85
+ ```ts
86
+ import openAccount from "./open-account.ts";
87
+ import sendWelcomeMail from "./send-welcome-mail.ts";
88
+
89
+ export default defineStep({
90
+ // pattern, description, args and returns are exactly what they were
91
+ pattern: "a customer {email:string} is onboarded on the {plan:string} plan",
92
+ args: z.object({ email: z.string(), plan: z.string() }),
93
+ returns: z.object({ accountId: z.string(), mailId: z.string() }),
94
+ parts: [openAccount, sendWelcomeMail],
95
+ async run({ call }, args) {
96
+ const { accountId } = await call(openAccount, {
97
+ email: args.email,
98
+ plan: args.plan,
99
+ });
100
+ const { mailId } = await call(sendWelcomeMail, { email: args.email });
101
+ return { accountId, mailId };
102
+ },
103
+ });
104
+ ```
105
+
106
+ Get each part right on its own before wiring the composite back together.
107
+ A part with no `pattern` is still vocabulary, so it runs alone like any
108
+ other step: `nuka do open-account --args '{"email":"ada@example.com",
109
+ "plan":"team"}'`.
110
+
111
+ When the second scenario wants to name one half as a line of its own,
112
+ give that part a `pattern`. It stays callable from the composite at the
113
+ same time, so both granularities exist at once and neither scenario is
114
+ rewritten for the other.
115
+
116
+ Fixtures follow the parts: a composite whose part destructures `page` gets
117
+ a browser even though the composite itself never names `page`. That is why
118
+ `parts` is declared rather than read out of the body, and why a `call` to
119
+ a step the caller did not list is refused instead of run.
120
+
121
+ A read-only environment refuses a `mutates: true` part before it runs,
122
+ whatever the composite declared about itself. Splitting a step never moves
123
+ a mutation out of that policy's reach.
124
+
125
+ Everything measured stays on the calling step. `observed`, `sections`,
126
+ `used`, `required_env`, the evidence directory, and the trace are the
127
+ composite's, and they count the parts' work inside their totals. A part
128
+ shares its caller's `ctx`. `from` is never consulted for a call: the
129
+ caller passes every key itself.
130
+
131
+ ## Generalizing a step that is too concrete
132
+
133
+ A step can sit at the right granularity for its scenario and still
134
+ hardcode a value the next scenario needs to vary. Add the `args` key,
135
+ describe it, and capture it in the pattern. `nuka check` refuses the
136
+ mismatch either way round, a required key nothing fills or a capture no
137
+ args key accepts, so the refactor is judged before anything runs.
138
+
139
+ This refactor does change the sentence in the feature file, which the
140
+ split above does not. Treat it as needing the same agreement that sentence
141
+ had in the first place: the changed line shows up in the pull request's
142
+ diff, and a person reads it again before approving. Prefer it anyway
143
+ when the hardcoded value is one the feature's reader should have been able
144
+ to see. Reach for the split instead when what varies is not a value, but
145
+ which half of the step the next scenario wants.
146
+
147
+ Nothing upstream ever runs on nukadoko's own initiative. If a step's `from`
148
+ key names a producer that never appears in the scenario, that is a `nuka
149
+ check` / `nuka run` error to fix in the feature file, never something
150
+ nukadoko inserts quietly to make the run succeed. A feature that doesn't
151
+ name everything that ran stops being the record this whole loop exists to
152
+ leave.
@@ -0,0 +1,109 @@
1
+ # Worlds that differ in what no criterion may depend on
2
+
3
+ A criterion such as "an order placed late in the UTC day keeps that day"
4
+ should hold whatever time zone the server runs in and whatever day the
5
+ run happens on. One run shows it in one zone on one day, so a defect of
6
+ the zone or the clock is missing from the run and from its summary
7
+ (docs/spec.md, "Out of scope"). Declare the worlds that would show it,
8
+ and the verdict table turns the defect red.
9
+
10
+ Four axes, and where each one lives:
11
+
12
+ - **Order**: `nuka run <feature> --order shuffled`; a red rerun of the
13
+ `do:` line is an order dependence (`references/running.md`).
14
+ - **The same world again**: `nuka run <feature>:<line> --repeat <n>`;
15
+ runs that disagree are `flaky@<line>`, which is red.
16
+ - **Time zone and clock** (and a random seed): one environment per value,
17
+ below. The program reads each value from its environment variables, so
18
+ nothing new is needed in nukadoko.
19
+
20
+ ## The program
21
+
22
+ Each environment declares its zone and its clock as `conditions`, and
23
+ `env` hands the same values to the program through `{condition.<name>}`,
24
+ so the column heading and the program cannot disagree:
25
+
26
+ ```ts
27
+ import { defineConfig } from "nukadoko";
28
+
29
+ // Two zones by two pinned clocks. A combination left out is not run, and
30
+ // nothing reports it, so the cross product is written once, here.
31
+ const zones = { utc: "UTC", tokyo: "Asia/Tokyo" };
32
+ const clocks = { midmonth: "2026-03-10T12:00:00Z", monthend: "2026-01-31T12:00:00Z" };
33
+ const environments = Object.fromEntries(
34
+ Object.entries(zones).flatMap(([zone, tz]) =>
35
+ Object.entries(clocks).map(([clock, now]) => [`${zone}-${clock}`, { conditions: { tz, now } }]),
36
+ ),
37
+ );
38
+
39
+ export default defineConfig({
40
+ program: () => ({
41
+ serve: { command: "node src/server.ts", ready: "/health" },
42
+ env: { PORT: "{port}", TZ: "{condition.tz}", NOW: "{condition.now}" },
43
+ environments,
44
+ }),
45
+ });
46
+ ```
47
+
48
+ - **Tag no scenario with these conditions.** An untagged scenario is
49
+ required in every environment, which is the claim: it holds in each
50
+ zone. `@with:tz=UTC` would make the Tokyo cell a control, and a control
51
+ never turns the run red.
52
+ - **The clock is the program's seam, not nukadoko's.** nukadoko cannot
53
+ move a program's clock. The program reads "now" from one place that
54
+ honours a variable (`NOW` above), or a library does it for it:
55
+ libfaketime under any process, Timecop in Ruby. `TZ` needs no seam:
56
+ Node, Ruby, and the C library read it at start.
57
+ - **A condition value holds no whitespace and no `@`**, where a Gherkin
58
+ tag would end. libfaketime's absolute form, `@2026-03-10 23:30:00`,
59
+ cannot be one: use its relative form (`+14h`) or a seam that reads an
60
+ ISO time.
61
+ - **The world's `env` reaches the step's process too** (`process.env`
62
+ during the run), and Node switches zones when `process.env.TZ` changes.
63
+ A step that computes its expected date from its own clock or zone moves
64
+ the same way the program does, and hides the defect. Write the input
65
+ time and the expected date as literals in the sentence: `When an order
66
+ is placed at "2026-03-10T23:30:00Z"`, `Then its business day is
67
+ "2026-03-10"`.
68
+
69
+ ## Reading the result
70
+
71
+ The column headings carry each environment's conditions, so the red
72
+ columns line up on `tz` or on `now`. A red row's reason names where it
73
+ broke and where it held:
74
+
75
+ ```text
76
+ | failed | `features/orders.feature:3` an order placed late in the UTC day keeps that day | pass | pass | fail@5 | fail@5 |
77
+ - ...: a claim broke at line 5 in tokyo-midmonth, tokyo-monthend, and passes in utc-midmonth, utc-monthend, where it is required too
78
+ ```
79
+
80
+ The reason names no cause: the environments can differ in more than their
81
+ conditions. Rerun one world with the finding's `do:` line, which names it
82
+ with `--env`.
83
+
84
+ ## Under `--base`
85
+
86
+ A fix for a zone defect proves itself only in a world that shows the
87
+ defect. A new criterion for a business-day fix, run with UTC worlds alone,
88
+ was `unproven` (`base utc: pass`); with a Tokyo world beside it, the base
89
+ cell there was `fail@13 (2 runs)` and the row was `proven`. Keep these
90
+ environments in the run CI posts with `--base`.
91
+
92
+ ## The cost
93
+
94
+ Every environment is a world: two zones by two clocks runs each scenario
95
+ four times, and so does the base world under `--base`. With switch
96
+ environments already there (`checkout-v1`, `checkout-v2`), write the
97
+ cross product by hand, each entry declaring the switch and the zone; the
98
+ switch's tags keep working, since each entry still declares its side.
99
+ `defaultEnvironments` keeps a run without `--env` on a few of them; then
100
+ say in the pull request which worlds CI runs, since a local green and a
101
+ CI red can disagree, and the column headings say which world was which.
102
+
103
+ ## What stays out of reach
104
+
105
+ Only the values an environment declares are tried. A defect at a moment
106
+ no clock pins (a daylight-saving change, a leap day, a year end) or in a
107
+ zone none names stays invisible, and a reading of the real clock that
108
+ bypasses the program's seam is not pinned at all. Pick the values from where the
109
+ criteria say the boundary is.
@@ -0,0 +1,200 @@
1
+ # The program under test
2
+
3
+ ## The program
4
+
5
+ The config holds the criteria, and its `program` holds how a run gets the
6
+ program the scenarios talk to: how to build it, prepare its state, start it,
7
+ and the env its processes get. `nuka init` does not write it: write it from
8
+ what the README or CI script already runs.
9
+
10
+ ```ts
11
+ import { defineConfig } from "nukadoko";
12
+
13
+ export default defineConfig({
14
+ program: () => ({
15
+ build: ["npm run build"], // once per run, in the tree's root
16
+ prepare: ["node dist/migrate.js"], // once per world, with env below
17
+ serve: { command: "node dist/server.js", ready: "/health" },
18
+ env: { PORT: "{port}", DATABASE_PATH: "{dir}/app.sqlite3" },
19
+ }),
20
+ });
21
+ ```
22
+
23
+ `nuka run` starts one world per environment: it runs `build` and
24
+ `prepare`, starts `serve` on a free port, waits until `ready` answers
25
+ 2xx, runs the scenarios against that URL (the base URL of `page`,
26
+ `request`, and the `baseURL` fixture), and stops the program after the
27
+ AfterAll hooks. `nuka do` does the same for its one execution. No
28
+ terminal has to keep a server running, and no fixture starts one.
29
+
30
+ A command is an argv array, or a string split on whitespace. Neither goes
31
+ through a shell; write `["sh", "-c", "a && b"]` when one is needed. The program
32
+ learns its port only from `{port}`, in the command or in `env`. `ready` is a
33
+ path on the program's own server, and only a 2xx answer counts: a redirect is
34
+ not followed, so name a path that answers 200 with no login (`/up`, `/health`).
35
+ `url` is an `http:` or `https:` URL with no user or password in it.
36
+
37
+ | Placeholder | Its value |
38
+ | --- | --- |
39
+ | `{port}`, `{url}` | the world's port (the one `serve` got, or the `url`'s, 443 or 80 when it names none) and URL |
40
+ | `{dir}` | the world's own directory under the run: its database, its pid file |
41
+ | `{root}` | the tree's root, the one placeholder `build` may name |
42
+ | `{world}` | the environment's name |
43
+ | `{token}` | random per world, redacted as `{{secret.WORLD_TOKEN}}` in every record |
44
+ | `{events}` | a private empty file a world nukadoko serves gets for its program's execution events |
45
+ | `{condition.<name>}` | the value the environment declares for that condition: `true`, `false`, or the string |
46
+ A placeholder a world has no value for (`{port}` or `{url}` with neither `serve`
47
+ nor `url`, `{events}` without `serve`, `{condition.<name>}` where the
48
+ environment does not declare it, anything but `{root}` in `build`) is
49
+ `program-placeholder-unfilled`: `nuka check` reports it for the worlds a `nuka
50
+ run` with the same `--env` flags would start, and `nuka run` and `nuka do`
51
+ refuse it before any command runs.
52
+
53
+ One world serves every scenario of an environment, so what one scenario
54
+ writes is there for the next: a scenario creates what it reads and claims
55
+ only on that (`scenario-rules.md`, S8, and `examples/http-api.md`).
56
+
57
+ A step reads the same `env`: in `process.env` during the run and in the
58
+ `env` fixture, after the config's env files. `setup(world)` runs once per
59
+ world before the first scenario, to seed data; what it prints reaches
60
+ stderr and `program.log` redacted. A `setup` or `url` function past its
61
+ limit is abandoned and its `signal` aborted: it stops only if it honours it.
62
+
63
+ Every phase has a limit: 600 s for each `build` or `prepare` command, 60 s for
64
+ `serve` to answer `ready`, `setup`, and a `url` function. Write `{ command,
65
+ timeout_ms }` for a command, `serve.timeout_ms`, `setup: { run, timeout_ms }`,
66
+ or `url: { resolve, timeout_ms }` for another, in whole milliseconds up to
67
+ 2147483647, the longest delay a Node.js timer keeps. Each phase prints `world
68
+ <name>: <phase> started` on stderr, so a long wait names what it waits on. A
69
+ `build` or `prepare` command's process group is killed when the command exits:
70
+ a service that has to outlive `prepare`, such as a database, starts with
71
+ `setsid`, as a daemon does. `serve.command` stays in the foreground: one that
72
+ daemonizes, as `rails server -d` does, exits before `ready` answers and fails
73
+ the world, and the daemon keeps running, out of nukadoko's reach.
74
+
75
+ ## When it does not start
76
+
77
+ A world that does not start fails the run with `program-start-failed`,
78
+ which names the command, how it ended (a phase past its limit included),
79
+ and the end of the world's `program.log`: read that file first, at
80
+ `.nukadoko/runs/<run_id>/worlds/<environment>/program.log`. No scenario
81
+ runs in that environment. A fixed `port` something else already answers
82
+ on is refused the same way, since every request would reach a server
83
+ nukadoko did not start. `program-exited` (a warning) says the program
84
+ died during the run, which the failed steps alone would not.
85
+
86
+ `run.json`'s `worlds` names what each world ran, its URL, its timings,
87
+ and its log; each step record names its world in `world_name`.
88
+
89
+ ## Each step's lines of the program's log
90
+
91
+ Every request a step sends to the world's origin (through `fetch`, `node:http`,
92
+ `request`, and a Chromium page) carries a W3C `traceparent` with the step's own
93
+ trace id. A request that sets its own keeps it. When the program writes the
94
+ trace id into its log lines, each step record gets the lines that carry its
95
+ trace id in `program-log.txt` beside it, counted in `observed.program_log`
96
+ (`{ trace_id, lines, file, stamped }`). Read that file first when a step against
97
+ the program fails: it holds what the server did for that step. A line that
98
+ arrived after the step ended is still that step's, in `program-log-late.txt`
99
+ beside the record; the run summary names it on the step's `after-record` entry.
100
+
101
+ `lines: 0` with `stamped` above 0 says only that no line carried the
102
+ step's trace id by the time its record was written. Read the world's
103
+ `unrecorded-log` entry in the summary, decided from the whole log once the
104
+ world stopped: "carries no trace ids" means the program does not tag its
105
+ lines; a late line is on its step's `after-record` entry. When the world's
106
+ entry says none came in time, output buffered on a pipe is a possible cause:
107
+ `STDOUT.sync = true` fixes it in Ruby and `PYTHONUNBUFFERED=1` in Python.
108
+ For Rails, send the test log to stdout and tag it, in `config/environments/test.rb`:
109
+
110
+ ```ruby
111
+ config.logger = ActiveSupport::TaggedLogging.logger($stdout) if ENV["RAILS_LOG_TO_STDOUT"].present?
112
+ config.log_tags = [ ->(request) { request.headers["traceparent"] } ]
113
+ ```
114
+
115
+ with `RAILS_LOG_TO_STDOUT: "1"` in the program's `env`. A Node
116
+ server prints `req.headers.traceparent` at the start of each line it
117
+ writes for a request. A world at a `url` has no log nukadoko reads:
118
+ `observed.program_log` is `null`, and the server's own log finds a
119
+ step's requests by the `traceparent` on its `http.jsonl` lines, each
120
+ with `traceparent_sent_to`, the origins that received it.
121
+
122
+ ## Each step's execution events
123
+
124
+ A program can also write one JSON line per operation it ends (a request, a
125
+ statement, a transaction, a job, an outgoing call, a flag, an error) to the file
126
+ `{events}` names, in the format of docs/execution-events.md:
127
+ `env: { EXECUTION_EVENTS: "{events}" }`. Each line carries the request's
128
+ `traceparent`, a job's the one that enqueued it, so the lines of every process
129
+ the program runs reach the step that caused them. Each step record gets its
130
+ lines, redacted, in `events.jsonl` beside it, counted in `observed.events`
131
+ (`{ trace_id, lines, file, kinds, stamped, stamped_spans, unreadable, unowned,
132
+ process_spans, process_requests, whole, open }`, and `mcp_spans` after an MCP
133
+ call). A `runCommand` process gets the step's trace context as `TRACEPARENT`,
134
+ an MCP call through `measureMcp` in `params._meta.traceparent`
135
+ (`references/evidence.md`); a tool or a stdio server that copies it into its
136
+ requests' `traceparent` header makes their lines the step's (`process_requests`
137
+ counts a tool's). Only the program gets the variable that names `{events}`,
138
+ never a step or a process it starts, so no line a step writes reads as the
139
+ program's. Read it to see what the program did inside a step: which tables it
140
+ read and wrote, which jobs it enqueued and ran.
141
+
142
+ `whole: true` says every request the step stamped has its `request` line, every
143
+ job it enqueued performed, each `runCommand` process it ran ended with its
144
+ process group, and each MCP call went to the world over HTTP. `whole: false`
145
+ never says nothing more happened: `open` names why, one word each: `no-requests`
146
+ (no stamped request, `runCommand` process, or MCP call, such as a Then that only
147
+ reads the page), `processes-unbounded` (a process it ran still runs, left its
148
+ group running, or ran on Windows), `mcp-unbounded` (an MCP call went over stdio
149
+ or to another origin), `no-lines` (no writer, or a wrong variable),
150
+ `request-unreported`, `jobs-pending` (with `job_ids`), `unreadable` (a line
151
+ spliced or cut), `truncated`, `file-replaced`. A line that arrived later is in
152
+ `events-late.jsonl`, and the run summary names it. The whole file, redacted, is
153
+ in `worlds/<environment>/events.jsonl`; a world at a `url` has none, and
154
+ `observed.events` is `null` there. run.json's step gets `path`, what its trace
155
+ did, late lines included (writes, jobs, requests, flags; no reads); its flags
156
+ and requests make run.json's `flags` and `routes`, and `lists` (docs/spec.md
157
+ "Lists") names those no step reached (`references/verdicts.md`).
158
+
159
+ ## Claiming what the program did
160
+
161
+ A Then counts an earlier step's events: `events: { writes: { of: placeScore,
162
+ count: { kind: "db", op: ["insert", "update", "delete", "other"], committed:
163
+ true } } }` beside a claim on `actual: "writes"` and a number. It waits while
164
+ they may still be `whole` (the step's `timeout`, else 10 s), and is `unjudged`,
165
+ naming the gap, while the count is a range: an absence holds on a whole reading
166
+ only. Its line and `events_read` name what it `counted`, and what a `db` count
167
+ with no `table` left out on tables `lists.tables` marks (`left_out`,
168
+ `references/diagnosing.md`); a line after the claim makes the cell `broke`.
169
+ `events-inlet-missing` and `events-unread` name a world that reads none (a
170
+ `--base` ref without `{events}` still runs).
171
+
172
+ ## Environments and programs nukadoko does not start
173
+
174
+ An entry of `environments` overrides any field above (`env` merges by
175
+ key). A feature behind a switch gets one environment per side, each
176
+ naming its side in `conditions`:
177
+
178
+ ```ts
179
+ env: { CHECKOUT_V2: "{condition.checkout_v2}" },
180
+ environments: {
181
+ "checkout-v1": { conditions: { checkout_v2: false } },
182
+ "checkout-v2": { conditions: { checkout_v2: true } },
183
+ },
184
+ ```
185
+
186
+ `conditions` sets nothing, and nukadoko does not check it against the program;
187
+ `{condition.checkout_v2}` hands the program the declared side, so the two
188
+ cannot disagree. It says which side the environment is on for a scenario's
189
+ `@with:checkout_v2` or `@without:checkout_v2` tag (`references/verdicts.md`).
190
+ `nuka run` without `--env` runs every environment that declares `conditions`,
191
+ or the ones a top-level `defaultEnvironments` names, so a deployment target can
192
+ declare its switches and stay out. `url` in place of `serve` names a program
193
+ that runs elsewhere, such as a staging server, and starts nothing: give it
194
+ `build: []` and `prepare: []` when the top level has them, and
195
+ `policy: "read-only"` when the data there belongs to someone else. Under
196
+ `nuka run --base`, a `url` function receives `tree` and branches on it: one
197
+ that answers the base world with head's URL leaves that world not run.
198
+
199
+ A tree with no program starts no world, which suits a command-line tool whose
200
+ steps run commands with `runCommand`. "Program" in docs/spec.md has every field.