nukadoko 0.1.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +291 -0
- data/README.ja.md +58 -5
- data/README.md +15 -3
- data/exe/nuka +8 -0
- data/lib/nukadoko/aria_snapshot.rb +1008 -0
- data/lib/nukadoko/aria_tree.rb +150 -0
- data/lib/nukadoko/base.rb +274 -0
- data/lib/nukadoko/check.rb +669 -22
- data/lib/nukadoko/claim_check.rb +177 -0
- data/lib/nukadoko/claim_check_run.rb +293 -0
- data/lib/nukadoko/claim_line.rb +381 -0
- data/lib/nukadoko/claim_rules.rb +519 -0
- data/lib/nukadoko/claims.rb +407 -30
- data/lib/nukadoko/cli.rb +802 -19
- data/lib/nukadoko/codes.json +942 -0
- data/lib/nukadoko/codes.rb +19 -0
- data/lib/nukadoko/command.rb +214 -12
- data/lib/nukadoko/criteria.rb +172 -0
- data/lib/nukadoko/definition.rb +33 -41
- data/lib/nukadoko/env_check.rb +90 -0
- data/lib/nukadoko/features.rb +80 -10
- data/lib/nukadoko/fixtures.rb +296 -10
- data/lib/nukadoko/http_recording.rb +68 -0
- data/lib/nukadoko/init.rb +130 -0
- data/lib/nukadoko/judge.rb +221 -0
- data/lib/nukadoko/judgment_file.rb +78 -0
- data/lib/nukadoko/judgments.rb +256 -0
- data/lib/nukadoko/literal.rb +129 -0
- data/lib/nukadoko/measured.rb +105 -0
- data/lib/nukadoko/order.rb +84 -0
- data/lib/nukadoko/parts.rb +42 -21
- data/lib/nukadoko/pattern.rb +11 -1
- data/lib/nukadoko/poll.rb +17 -6
- data/lib/nukadoko/program.rb +105 -17
- data/lib/nukadoko/project_fixtures.rb +17 -2
- data/lib/nukadoko/report_allure.rb +751 -0
- data/lib/nukadoko/report_messages.rb +167 -0
- data/lib/nukadoko/report_run.rb +169 -0
- data/lib/nukadoko/run.rb +865 -88
- data/lib/nukadoko/run_record.rb +532 -0
- data/lib/nukadoko/scaffold.rb +1015 -0
- data/lib/nukadoko/schema.rb +61 -4
- data/lib/nukadoko/secrets.rb +359 -0
- data/lib/nukadoko/selection.rb +163 -0
- data/lib/nukadoko/signature.rb +4 -1
- data/lib/nukadoko/skill.rb +36 -0
- data/lib/nukadoko/step.rb +62 -21
- data/lib/nukadoko/summary.rb +662 -0
- data/lib/nukadoko/table.rb +34 -2
- data/lib/nukadoko/text_fit.rb +179 -0
- data/lib/nukadoko/trace.rb +244 -0
- data/lib/nukadoko/trace_actions.rb +116 -0
- data/lib/nukadoko/tree_passes.rb +119 -0
- data/lib/nukadoko/verdict.rb +128 -0
- data/lib/nukadoko/version.rb +2 -1
- data/lib/nukadoko/vocabulary.rb +6 -0
- data/lib/nukadoko/walk.rb +305 -0
- data/lib/nukadoko/walk_files.rb +473 -0
- data/lib/nukadoko/walk_step.rb +149 -0
- data/lib/nukadoko.rb +36 -0
- data/llms.txt +296 -0
- data/sig/generated/nukadoko/aria_snapshot.rbs +331 -0
- data/sig/generated/nukadoko/aria_tree.rbs +142 -0
- data/sig/generated/nukadoko/base.rbs +136 -0
- data/sig/generated/nukadoko/check.rbs +255 -0
- data/sig/generated/nukadoko/claim_check.rbs +118 -0
- data/sig/generated/nukadoko/claim_check_run.rbs +88 -0
- data/sig/generated/nukadoko/claim_line.rbs +158 -0
- data/sig/generated/nukadoko/claim_rules.rbs +172 -0
- data/sig/generated/nukadoko/claims.rbs +165 -0
- data/sig/generated/nukadoko/cli.rbs +182 -0
- data/sig/generated/nukadoko/codes.rbs +16 -0
- data/sig/generated/nukadoko/command.rbs +109 -0
- data/sig/generated/nukadoko/criteria.rbs +83 -0
- data/sig/generated/nukadoko/definition.rbs +30 -0
- data/sig/generated/nukadoko/env_check.rbs +38 -0
- data/sig/generated/nukadoko/features.rbs +101 -0
- data/sig/generated/nukadoko/fixtures.rbs +152 -0
- data/sig/generated/nukadoko/http_recording.rbs +29 -0
- data/sig/generated/nukadoko/init.rbs +66 -0
- data/sig/generated/nukadoko/judge.rbs +64 -0
- data/sig/generated/nukadoko/judgment_file.rbs +39 -0
- data/sig/generated/nukadoko/judgments.rbs +120 -0
- data/sig/generated/nukadoko/literal.rbs +71 -0
- data/sig/generated/nukadoko/measured.rbs +42 -0
- data/sig/generated/nukadoko/order.rbs +54 -0
- data/sig/generated/nukadoko/parts.rbs +35 -0
- data/sig/generated/nukadoko/pattern.rbs +28 -0
- data/sig/generated/nukadoko/poll.rbs +40 -0
- data/sig/generated/nukadoko/program.rbs +101 -0
- data/sig/generated/nukadoko/project_fixtures.rbs +57 -0
- data/sig/generated/nukadoko/report_allure.rbs +268 -0
- data/sig/generated/nukadoko/report_messages.rbs +68 -0
- data/sig/generated/nukadoko/report_run.rbs +102 -0
- data/sig/generated/nukadoko/run.rbs +257 -0
- data/sig/generated/nukadoko/run_record.rbs +174 -0
- data/sig/generated/nukadoko/scaffold.rbs +328 -0
- data/sig/generated/nukadoko/schema.rbs +137 -0
- data/sig/generated/nukadoko/secrets.rbs +157 -0
- data/sig/generated/nukadoko/selection.rbs +73 -0
- data/sig/generated/nukadoko/signature.rbs +17 -0
- data/sig/generated/nukadoko/skill.rbs +20 -0
- data/sig/generated/nukadoko/step.rbs +115 -0
- data/sig/generated/nukadoko/summary.rbs +204 -0
- data/sig/generated/nukadoko/table.rbs +43 -0
- data/sig/generated/nukadoko/text_fit.rbs +70 -0
- data/sig/generated/nukadoko/trace.rbs +127 -0
- data/sig/generated/nukadoko/trace_actions.rbs +40 -0
- data/sig/generated/nukadoko/tree_passes.rbs +48 -0
- data/sig/generated/nukadoko/verdict.rbs +56 -0
- data/sig/generated/nukadoko/version.rbs +5 -0
- data/sig/generated/nukadoko/vocabulary.rbs +25 -0
- data/sig/generated/nukadoko/walk.rbs +139 -0
- data/sig/generated/nukadoko/walk_files.rbs +189 -0
- data/sig/generated/nukadoko/walk_step.rbs +50 -0
- data/sig/generated/nukadoko.rbs +15 -0
- data/sig/nukadoko.rbs +5 -48
- data/skills/nukadoko/SKILL.md +120 -0
- data/skills/nukadoko/references/checking-steps.md +200 -0
- data/skills/nukadoko/references/diagnosing.md +200 -0
- data/skills/nukadoko/references/done.md +99 -0
- data/skills/nukadoko/references/evidence.md +124 -0
- data/skills/nukadoko/references/examples/cli.md +230 -0
- data/skills/nukadoko/references/examples/http-api.md +339 -0
- data/skills/nukadoko/references/examples/workflow.md +173 -0
- data/skills/nukadoko/references/exploring.md +184 -0
- data/skills/nukadoko/references/fixtures.md +198 -0
- data/skills/nukadoko/references/from-prose.md +51 -0
- data/skills/nukadoko/references/judgments.md +95 -0
- data/skills/nukadoko/references/maintenance.md +97 -0
- data/skills/nukadoko/references/merge-risk.md +74 -0
- data/skills/nukadoko/references/parts.md +152 -0
- data/skills/nukadoko/references/perturbed-worlds.md +107 -0
- data/skills/nukadoko/references/program.md +200 -0
- data/skills/nukadoko/references/reviewing.md +200 -0
- data/skills/nukadoko/references/running.md +200 -0
- data/skills/nukadoko/references/scenario-rules.md +188 -0
- data/skills/nukadoko/references/states.md +66 -0
- data/skills/nukadoko/references/step-files.md +200 -0
- data/skills/nukadoko/references/verdicts.md +200 -0
- data/skills/nukadoko/references/writing-steps.md +200 -0
- data/skills/nukadoko/references/writing-the-feature.md +165 -0
- data/skills/nukadoko/scripts/claude-code-verdict-hook.mjs +99 -0
- data/skills/nukadoko/scripts/merge-risk.jq +56 -0
- data/skills/nukadoko-verification/SKILL.md +263 -0
- metadata +121 -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,107 @@
|
|
|
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 file
|
|
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 { defineProgram } 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 defineProgram({
|
|
40
|
+
serve: { command: "node src/server.ts", ready: "/health" },
|
|
41
|
+
env: { PORT: "{port}", TZ: "{condition.tz}", NOW: "{condition.now}" },
|
|
42
|
+
environments,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- **Tag no scenario with these conditions.** An untagged scenario is
|
|
47
|
+
required in every environment, which is the claim: it holds in each
|
|
48
|
+
zone. `@with:tz=UTC` would make the Tokyo cell a control, and a control
|
|
49
|
+
never turns the run red.
|
|
50
|
+
- **The clock is the program's seam, not nukadoko's.** nukadoko cannot
|
|
51
|
+
move a program's clock. The program reads "now" from one place that
|
|
52
|
+
honours a variable (`NOW` above), or a library does it for it:
|
|
53
|
+
libfaketime under any process, Timecop in Ruby. `TZ` needs no seam:
|
|
54
|
+
Node, Ruby, and the C library read it at start.
|
|
55
|
+
- **A condition value holds no whitespace and no `@`**, where a Gherkin
|
|
56
|
+
tag would end. libfaketime's absolute form, `@2026-03-10 23:30:00`,
|
|
57
|
+
cannot be one: use its relative form (`+14h`) or a seam that reads an
|
|
58
|
+
ISO time.
|
|
59
|
+
- **The world's `env` reaches the step's process too** (`process.env`
|
|
60
|
+
during the run), and Node switches zones when `process.env.TZ` changes.
|
|
61
|
+
A step that computes its expected date from its own clock or zone moves
|
|
62
|
+
the same way the program does, and hides the defect. Write the input
|
|
63
|
+
time and the expected date as literals in the sentence: `When an order
|
|
64
|
+
is placed at "2026-03-10T23:30:00Z"`, `Then its business day is
|
|
65
|
+
"2026-03-10"`.
|
|
66
|
+
|
|
67
|
+
## Reading the result
|
|
68
|
+
|
|
69
|
+
The column headings carry each environment's conditions, so the red
|
|
70
|
+
columns line up on `tz` or on `now`. A red row's reason names where it
|
|
71
|
+
broke and where it held:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
| failed | `features/orders.feature:3` an order placed late in the UTC day keeps that day | pass | pass | fail@5 | fail@5 |
|
|
75
|
+
- ...: a claim broke at line 5 in tokyo-midmonth, tokyo-monthend, and passes in utc-midmonth, utc-monthend, where it is required too
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The reason names no cause: the environments can differ in more than their
|
|
79
|
+
conditions. Rerun one world with the finding's `do:` line, which names it
|
|
80
|
+
with `--env`.
|
|
81
|
+
|
|
82
|
+
## Under `--base`
|
|
83
|
+
|
|
84
|
+
A fix for a zone defect proves itself only in a world that shows the
|
|
85
|
+
defect. A new criterion for a business-day fix, run with UTC worlds alone,
|
|
86
|
+
was `unproven` (`base utc: pass`); with a Tokyo world beside it, the base
|
|
87
|
+
cell there was `fail@13 (2 runs)` and the row was `proven`. Keep these
|
|
88
|
+
environments in the run CI posts with `--base`.
|
|
89
|
+
|
|
90
|
+
## The cost
|
|
91
|
+
|
|
92
|
+
Every environment is a world: two zones by two clocks runs each scenario
|
|
93
|
+
four times, and so does the base world under `--base`. With switch
|
|
94
|
+
environments already there (`checkout-v1`, `checkout-v2`), write the
|
|
95
|
+
cross product by hand, each entry declaring the switch and the zone; the
|
|
96
|
+
switch's tags keep working, since each entry still declares its side.
|
|
97
|
+
`defaultEnvironments` keeps a run without `--env` on a few of them; then
|
|
98
|
+
say in the pull request which worlds CI runs, since a local green and a
|
|
99
|
+
CI red can disagree, and the column headings say which world was which.
|
|
100
|
+
|
|
101
|
+
## What stays out of reach
|
|
102
|
+
|
|
103
|
+
Only the values an environment declares are tried. A defect at a moment
|
|
104
|
+
no clock pins (a daylight-saving change, a leap day, a year end) or in a
|
|
105
|
+
zone none names stays invisible, and a reading of the real clock that
|
|
106
|
+
bypasses the program's seam is not pinned at all. Pick the values from where the
|
|
107
|
+
criteria say the boundary is.
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# The program under test
|
|
2
|
+
|
|
3
|
+
## The program file
|
|
4
|
+
|
|
5
|
+
The config holds the criteria. `nukadoko.program.ts`, beside it, holds how a run
|
|
6
|
+
gets the program the scenarios talk to: how to build it, prepare its state,
|
|
7
|
+
start it, and the env its processes get. `nuka init` does not write it; write it
|
|
8
|
+
from what the project's README or CI script already runs.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { defineProgram } from "nukadoko";
|
|
12
|
+
|
|
13
|
+
export default defineProgram({
|
|
14
|
+
build: ["npm run build"], // once per run, in the tree's root
|
|
15
|
+
prepare: ["node dist/migrate.js"], // once per world, with env below
|
|
16
|
+
serve: { command: "node dist/server.js", ready: "/health" },
|
|
17
|
+
env: { PORT: "{port}", DATABASE_PATH: "{dir}/app.sqlite3" },
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`nuka run` starts one world per environment: it runs `build` and
|
|
22
|
+
`prepare`, starts `serve` on a free port, waits until `ready` answers
|
|
23
|
+
2xx, runs the scenarios against that URL (the base URL of `page`,
|
|
24
|
+
`request`, and the `baseURL` fixture), and stops the program after the
|
|
25
|
+
AfterAll hooks. `nuka do` does the same for its one execution. No
|
|
26
|
+
terminal has to keep a server running, and no fixture starts one.
|
|
27
|
+
|
|
28
|
+
A command is an argv array, or a string split on whitespace. Neither goes
|
|
29
|
+
through a shell; write `["sh", "-c", "a && b"]` when one is needed. The program
|
|
30
|
+
learns its port only from `{port}`, in the command or in `env`. `ready` is a
|
|
31
|
+
path on the program's own server, and only a 2xx answer counts: a redirect is
|
|
32
|
+
not followed, so name a path that answers 200 with no login (`/up`, `/health`).
|
|
33
|
+
`url` is an `http:` or `https:` URL with no user or password in it.
|
|
34
|
+
|
|
35
|
+
| Placeholder | Its value |
|
|
36
|
+
| --- | --- |
|
|
37
|
+
| `{port}`, `{url}` | the world's port (the one `serve` got, or the `url`'s, 443 or 80 when it names none) and URL |
|
|
38
|
+
| `{dir}` | the world's own directory under the run: its database, its pid file |
|
|
39
|
+
| `{root}` | the tree's root, the one placeholder `build` may name |
|
|
40
|
+
| `{world}` | the environment's name |
|
|
41
|
+
| `{token}` | random per world, redacted as `{{secret.WORLD_TOKEN}}` in every record |
|
|
42
|
+
| `{events}` | a private empty file a world nukadoko serves gets for its program's execution events |
|
|
43
|
+
| `{condition.<name>}` | the value the environment declares for that condition: `true`, `false`, or the string |
|
|
44
|
+
A placeholder a world has no value for (`{port}` or `{url}` with neither `serve`
|
|
45
|
+
nor `url`, `{events}` without `serve`, `{condition.<name>}` where the
|
|
46
|
+
environment does not declare it, anything but `{root}` in `build`) is
|
|
47
|
+
`program-placeholder-unfilled`: `nuka check` reports it for the worlds a `nuka
|
|
48
|
+
run` with the same `--env` flags would start, and `nuka run` and `nuka do`
|
|
49
|
+
refuse it before any command runs.
|
|
50
|
+
|
|
51
|
+
One world serves every scenario of an environment, so what one scenario
|
|
52
|
+
writes is there for the next: a scenario creates what it reads and claims
|
|
53
|
+
only on that (`scenario-rules.md`, S8, and `examples/http-api.md`).
|
|
54
|
+
|
|
55
|
+
A step reads the same `env`: in `process.env` during the run and in the
|
|
56
|
+
`env` fixture, after the config's env files. `setup(world)` runs once per
|
|
57
|
+
world before the first scenario, to seed data; what it prints reaches
|
|
58
|
+
stderr and `program.log` redacted. A `setup` or `url` function past its
|
|
59
|
+
limit is abandoned and its `signal` aborted: it stops only if it honours it.
|
|
60
|
+
|
|
61
|
+
Every phase has a limit: 600 s for each `build` or `prepare` command, 60 s for
|
|
62
|
+
`serve` to answer `ready`, `setup`, and a `url` function. Write `{ command,
|
|
63
|
+
timeout_ms }` for a command, `serve.timeout_ms`, `setup: { run, timeout_ms }`,
|
|
64
|
+
or `url: { resolve, timeout_ms }` for another, in whole milliseconds up to
|
|
65
|
+
2147483647, the longest delay a Node.js timer keeps. Each phase prints `world
|
|
66
|
+
<name>: <phase> started` on stderr, so a long wait names what it waits on. A
|
|
67
|
+
`build` or `prepare` command's process group is killed when the command exits:
|
|
68
|
+
a service that has to outlive `prepare`, such as a database, starts with
|
|
69
|
+
`setsid`, as a daemon does. `serve.command` stays in the foreground: one that
|
|
70
|
+
daemonizes, as `rails server -d` does, exits before `ready` answers and fails
|
|
71
|
+
the world, and the daemon keeps running, out of nukadoko's reach.
|
|
72
|
+
|
|
73
|
+
## When it does not start
|
|
74
|
+
|
|
75
|
+
A world that does not start fails the run with `program-start-failed`,
|
|
76
|
+
which names the command, how it ended (a phase past its limit included),
|
|
77
|
+
and the end of the world's `program.log`: read that file first, at
|
|
78
|
+
`.nukadoko/runs/<run_id>/worlds/<environment>/program.log`. No scenario
|
|
79
|
+
runs in that environment. A fixed `port` something else already answers
|
|
80
|
+
on is refused the same way, since every request would reach a server
|
|
81
|
+
nukadoko did not start. `program-exited` (a warning) says the program
|
|
82
|
+
died during the run, which the failed steps alone would not.
|
|
83
|
+
|
|
84
|
+
`run.json`'s `worlds` names what each world ran, its URL, its timings,
|
|
85
|
+
and its log; each step record names its world in `world_name`.
|
|
86
|
+
|
|
87
|
+
## Each step's lines of the program's log
|
|
88
|
+
|
|
89
|
+
Every request a step sends to the world's origin (through `fetch`, `node:http`,
|
|
90
|
+
`request`, and a Chromium page) carries a W3C `traceparent` with the step's own
|
|
91
|
+
trace id. A request that sets its own keeps it. When the program writes the
|
|
92
|
+
trace id into its log lines, each step record gets the lines that carry its
|
|
93
|
+
trace id in `program-log.txt` beside it, counted in `observed.program_log`
|
|
94
|
+
(`{ trace_id, lines, file, stamped }`). Read that file first when a step against
|
|
95
|
+
the program fails: it holds what the server did for that step. A line that
|
|
96
|
+
arrived after the step ended is still that step's, in `program-log-late.txt`
|
|
97
|
+
beside the record; the run summary names it on the step's `after-record` entry.
|
|
98
|
+
|
|
99
|
+
`lines: 0` with `stamped` above 0 says only that no line carried the
|
|
100
|
+
step's trace id by the time its record was written. Read the world's
|
|
101
|
+
`unrecorded-log` entry in the summary, decided from the whole log once the
|
|
102
|
+
world stopped: "carries no trace ids" means the program does not tag its
|
|
103
|
+
lines; a late line is on its step's `after-record` entry. When the world's
|
|
104
|
+
entry says none came in time, output buffered on a pipe is a
|
|
105
|
+
possible cause: `STDOUT.sync = true` fixes it in Ruby and
|
|
106
|
+
`PYTHONUNBUFFERED=1` in Python. For Rails, send the test log to stdout
|
|
107
|
+
and tag it, in `config/environments/test.rb`:
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
config.logger = ActiveSupport::TaggedLogging.logger($stdout) if ENV["RAILS_LOG_TO_STDOUT"].present?
|
|
111
|
+
config.log_tags = [ ->(request) { request.headers["traceparent"] } ]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
with `RAILS_LOG_TO_STDOUT: "1"` in the program file's `env`. A Node
|
|
115
|
+
server prints `req.headers.traceparent` at the start of each line it
|
|
116
|
+
writes for a request. A world at a `url` has no log nukadoko reads:
|
|
117
|
+
`observed.program_log` is `null`, and the server's own log finds a
|
|
118
|
+
step's requests by the `traceparent` on its `http.jsonl` lines, each
|
|
119
|
+
with `traceparent_sent_to`, the origins that received it.
|
|
120
|
+
|
|
121
|
+
## Each step's execution events
|
|
122
|
+
|
|
123
|
+
A program can also write one JSON line per operation it ends (a request, a
|
|
124
|
+
statement, a transaction, a job, an outgoing call, a flag, an error) to the file
|
|
125
|
+
`{events}` names, in the format of docs/execution-events.md:
|
|
126
|
+
`env: { EXECUTION_EVENTS: "{events}" }`. Each line carries the request's
|
|
127
|
+
`traceparent`, a job's the one that enqueued it, so the lines of every process
|
|
128
|
+
the program runs reach the step that caused them. Each step record gets its
|
|
129
|
+
lines, redacted, in `events.jsonl` beside it, counted in `observed.events`
|
|
130
|
+
(`{ trace_id, lines, file, kinds, stamped, stamped_spans, unreadable, unowned,
|
|
131
|
+
process_spans, process_requests, whole, open }`, and `mcp_spans` after an MCP
|
|
132
|
+
call). A `runCommand` process gets the step's trace context as `TRACEPARENT`,
|
|
133
|
+
an MCP call through `measureMcp` in `params._meta.traceparent`
|
|
134
|
+
(`references/evidence.md`); a tool or a stdio server that copies it into its
|
|
135
|
+
requests' `traceparent` header makes their lines the step's (`process_requests`
|
|
136
|
+
counts a tool's). Only the program gets the variable that names `{events}`,
|
|
137
|
+
never a step or a process it starts, so no line a step writes reads as the
|
|
138
|
+
program's. Read it to see what the program did inside a step: which tables it
|
|
139
|
+
read and wrote, which jobs it enqueued and ran.
|
|
140
|
+
|
|
141
|
+
`whole: true` says every request the step stamped has its `request` line, every
|
|
142
|
+
job it enqueued performed, each `runCommand` process it ran ended with its
|
|
143
|
+
process group, and each MCP call went to the world over HTTP. `whole: false`
|
|
144
|
+
never says nothing more happened: `open` names why, one word each: `no-requests`
|
|
145
|
+
(no stamped request, `runCommand` process, or MCP call, such as a Then that only
|
|
146
|
+
reads the page), `processes-unbounded` (a process it ran still runs, left its
|
|
147
|
+
group running, or ran on Windows), `mcp-unbounded` (an MCP call went over stdio
|
|
148
|
+
or to another origin), `no-lines` (no writer, or a wrong variable),
|
|
149
|
+
`request-unreported`, `jobs-pending` (with `job_ids`), `unreadable` (a line
|
|
150
|
+
spliced or cut), `truncated`, `file-replaced`. A line that arrived later is in
|
|
151
|
+
`events-late.jsonl`, and the run summary names it. The whole file, redacted, is
|
|
152
|
+
in `worlds/<environment>/events.jsonl`; a world at a `url` has none, and
|
|
153
|
+
`observed.events` is `null` there. run.json's step gets `path`, what its trace
|
|
154
|
+
did, late lines included (writes, jobs, requests, flags; no reads); its flags
|
|
155
|
+
and requests make run.json's `flags` and `routes`, and `lists` (docs/spec.md
|
|
156
|
+
"Lists") names those no step reached (`references/verdicts.md`).
|
|
157
|
+
|
|
158
|
+
## Claiming what the program did
|
|
159
|
+
|
|
160
|
+
A Then counts an earlier step's events: `events: { writes: { of: placeScore,
|
|
161
|
+
count: { kind: "db", op: ["insert", "update", "delete", "other"], committed:
|
|
162
|
+
true } } }` beside a claim on `actual: "writes"` and a number. It waits while
|
|
163
|
+
they may still be `whole` (the step's `timeout`, else 10 s), and is `unjudged`,
|
|
164
|
+
naming the gap, while the count is a range: an absence holds on a whole reading
|
|
165
|
+
only. Its line and `events_read` name what it `counted`, and what a `db` count
|
|
166
|
+
with no `table` left out on tables `lists.tables` marks (`left_out`,
|
|
167
|
+
`references/diagnosing.md`); a line after the claim makes the cell `broke`.
|
|
168
|
+
`events-inlet-missing` and `events-unread` name a world that reads none (a
|
|
169
|
+
`--base` ref without `{events}` still runs).
|
|
170
|
+
|
|
171
|
+
## Environments and programs nukadoko does not start
|
|
172
|
+
|
|
173
|
+
An entry of `environments` overrides any field above (`env` merges by
|
|
174
|
+
key). A feature behind a switch gets one environment per side, each
|
|
175
|
+
naming its side in `conditions`:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
env: { CHECKOUT_V2: "{condition.checkout_v2}" },
|
|
179
|
+
environments: {
|
|
180
|
+
"checkout-v1": { conditions: { checkout_v2: false } },
|
|
181
|
+
"checkout-v2": { conditions: { checkout_v2: true } },
|
|
182
|
+
},
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
`conditions` sets nothing, and nukadoko does not check it against the program;
|
|
186
|
+
`{condition.checkout_v2}` hands the program the declared side, so the two
|
|
187
|
+
cannot disagree. It says which side the environment is on for a scenario's
|
|
188
|
+
`@with:checkout_v2` or `@without:checkout_v2` tag (`references/verdicts.md`).
|
|
189
|
+
`nuka run` without `--env` runs every environment that declares `conditions`,
|
|
190
|
+
or the ones a top-level `defaultEnvironments` names, so a deployment target can
|
|
191
|
+
declare its switches and stay out. `url` in place of `serve` names a program
|
|
192
|
+
that runs elsewhere, such as a staging server, and starts nothing: give it
|
|
193
|
+
`build: []` and `prepare: []` when the top level has them, and
|
|
194
|
+
`policy: "read-only"` when the data there belongs to someone else. Under
|
|
195
|
+
`nuka run --base`, a `url` function receives `tree` and branches on it: one
|
|
196
|
+
that answers the base world with head's URL leaves that world not run.
|
|
197
|
+
|
|
198
|
+
A tree with no program file starts no world, which suits a command-line
|
|
199
|
+
tool whose steps run commands with `runCommand`. "Program" in
|
|
200
|
+
docs/spec.md has every field.
|