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,184 @@
1
+ # Exploring before you know what to write
2
+
3
+ When you do not yet know what the system does, and so cannot say what a
4
+ step should demand or return. Everything here runs through `nuka do`,
5
+ whose records are working records rather than evidence, which is exactly
6
+ what makes them the right place to be wrong in.
7
+
8
+ ## Seeing the raw thing
9
+
10
+ A step's `returns` is a contract, and a contract is a filter: what it does
11
+ not name is not recorded. That is right for a step a scenario relies on,
12
+ and wrong for the first look at a system nobody has described yet.
13
+
14
+ Write one probe step for the looking. Give it no `pattern`, so it can
15
+ never become a line in a feature, and a `returns` of `z.unknown()`, so
16
+ nothing is filtered out:
17
+
18
+ ```ts
19
+ import { defineStep, z } from "nukadoko";
20
+
21
+ export default defineStep({
22
+ description: "Send one request and return the whole response, for looking at",
23
+ args: z.object({
24
+ path: z.string().describe("Path under baseURL"),
25
+ }),
26
+ returns: z.unknown(),
27
+ mutates: false,
28
+ async run({ request }, args) {
29
+ const res = await request.get(args.path);
30
+ return { status: res.status(), body: await res.json() };
31
+ },
32
+ });
33
+ ```
34
+
35
+ `nuka do probe --args '{"path":"/accounts/1"}'` then prints the whole
36
+ thing, because `do` writes the step record to stdout. One probe lasts a
37
+ project; write it once and stop guessing at shapes.
38
+
39
+ A permissive `returns` is deliberate here and stays confined to the probe.
40
+ The moment you know the shape, the step that a scenario will name declares
41
+ it properly. A probe that drifts into being relied on is a contract that
42
+ stopped saying anything.
43
+
44
+ ## Seeing what happened in between
45
+
46
+ Once an operation has more than one move, make each move a part and let
47
+ the calling step compose them. The calling step's record then carries a
48
+ `calls` entry per part, each with the args it was handed and the result it
49
+ returned:
50
+
51
+ ```
52
+ $ nuka do quote-net --args '{"sku":"S-1"}'
53
+ {
54
+ "result": { "net": 1104 },
55
+ "calls": [
56
+ { "step": "fetch-quote", "args": {"sku":"S-1"},
57
+ "result": {"sku":"S-1","gross":1200,"tax":96,"currency":"JPY"} },
58
+ { "step": "net-of-tax", "args": {"gross":1200,"tax":96},
59
+ "result": {"net":1104} }
60
+ ]
61
+ }
62
+ ```
63
+
64
+ That is where the next move comes from. The composite returned only `net`,
65
+ and the record still shows that the quote carried a currency nobody has
66
+ used yet. Reading `calls` is how you find the field you did not know to
67
+ ask for.
68
+
69
+ Each part also runs alone (`nuka do fetch-quote --args ...`), so a half
70
+ that misbehaves can be worked on without the rest.
71
+
72
+ ## What continues, and what does not
73
+
74
+ Inside one execution, the parts share everything: one browser, one page,
75
+ one request context. A part sees the page where the part before it left
76
+ off, which is what makes a browser flow expressible as parts at all.
77
+
78
+ Across `nuka do` calls, nothing continues by default. Every call builds
79
+ its own browser on a fresh page, with no login state carried over: a step
80
+ that needs it gets it from a fixture. Values still move forward with `--use <step-record-id>`, which
81
+ fills the `from` keys of the next step from a record you already have.
82
+ A claim step's `events` keys take a record the same way:
83
+ `nuka do nothing-was-written --use <place-score's record id>` counts the
84
+ execution events that record kept (`references/program.md`). Before
85
+ `nuka do` stops its world, it waits up to 10 s for the step's own events
86
+ to be whole, so the lines of a job that performs after the response are
87
+ there for that count.
88
+ A `files` key takes one the same way, and reads the files that record's
89
+ `runCommand` processes changed (`references/parts.md`).
90
+
91
+ So one shape of an exploration is: keep the unit of a single `do` call
92
+ small enough to see what you need, and grow it by adding parts rather
93
+ than by chaining `do` calls through a browser. The cost of growing a
94
+ composite that way is that each `do` runs it from the start, which is
95
+ free for reads and fine for anything repeatable.
96
+
97
+ ## Exploring state that cannot be repeated
98
+
99
+ For work that cannot be repeated, an account that opens once or an
100
+ invoice that would be issued twice, running from the start is not an
101
+ option. Explore that in a browser app through the host's Playwright MCP
102
+ server instead of `nuka do`: its tools drive one browser that stays open
103
+ between calls, so each call lands where the last one left off.
104
+
105
+ The server is connected when its tools are in your tool list
106
+ (`browser_navigate`, `browser_snapshot`, `browser_click`, and the rest,
107
+ under the server's name, usually `playwright`). When they are not there,
108
+ ask the person to add it; do not add it yourself. In Claude Code the
109
+ command, from the `@playwright/mcp` README, is:
110
+
111
+ ```sh
112
+ claude mcp add playwright npx @playwright/mcp@latest
113
+ ```
114
+
115
+ It takes effect in a new session. To start the browser from a saved
116
+ login, the server's `--isolated --storage-state=<file>` options load a
117
+ Playwright storageState file, such as the one `browserContext.storageState`
118
+ names in `nukadoko.config.ts`.
119
+
120
+ Say before the first call that the browser acts on the real application
121
+ with whatever login it holds. A click that submits a form there is the
122
+ same as a `mutates: true` step: it needs a go-ahead first.
123
+
124
+ A world many calls deep is not reproducible, by anyone, and nothing the
125
+ MCP server did is a step record. What you found counts once it is a
126
+ scenario: write the steps it needs, write the scenario from what you did
127
+ ("Then fix what you found" below), and run `nuka check` on it, then
128
+ `nuka run` from nothing.
129
+
130
+ ## Records left behind
131
+
132
+ A step record has a lifetime without anyone cleaning: `nuka run` keeps the
133
+ newest `retention.runs` runs (default 20) and a record no run owns, which
134
+ is what a `nuka do` record is, for `retention.adHocDays` days (default 7),
135
+ both set in `nukadoko.config.ts`. A `--use <id>` whose
136
+ record aged out is refused with those numbers in the message, so an id
137
+ that resolved last week and does not today is that, not a typo. Chain
138
+ within the window, or raise `adHocDays` for a longer exploration.
139
+
140
+ `nuka clean [--dry-run]` is the wider
141
+ version of the same idea, once you are done exploring rather than mid-way
142
+ through it: it removes every step record and run directory at once, and
143
+ under `export/` only the files a run's manifest names and the contents of
144
+ `allure-results/`,
145
+ all disposable by design (see "Artifacts" in `docs/spec.md`). `--dry-run`
146
+ prints the same plan the real run would act on without removing anything.
147
+ `export/allure-history.jsonl` survives regardless: it sits beside
148
+ `allure-results/`, not inside it, and is the one export artifact no
149
+ re-run can reproduce.
150
+
151
+ ## Then fix what you found
152
+
153
+ Once the path works, write the scenario from the calls you made. You
154
+ already know each step, its args, and which result fed the next one,
155
+ because you made each call. Write it the way a reader needs it:
156
+
157
+ - One line per step that is part of the story, in the order they ran,
158
+ worded to match that step's pattern. Leave out every probe: exploring
159
+ means running things that turned out not to matter.
160
+ - Pick `Given`, `When`, or `Then` by what that line tells the person
161
+ reading the scenario, not by what the code did.
162
+ - Keep a value an earlier step produced off the line. The step's `from`
163
+ supplies it at run time, as `--use` did during the exploration; a
164
+ literal id from one run passes against that server and fails against a
165
+ fresh one.
166
+ - Name the `Feature:` and the `Scenario:` for the behavior being claimed.
167
+ Two paths are two scenarios.
168
+ - A call that failed because it reproduced a bug becomes a red scenario.
169
+ It goes green when the behavior changes, and the pull request's run
170
+ summary shows it.
171
+
172
+ Keep record ids out of the file. They point into the state directory,
173
+ which is safe to delete, so a committed feature that named them would
174
+ point at nothing.
175
+
176
+ Then run `nuka check` on the file, which is step 3 of the loop in
177
+ `SKILL.md`. It reads each line back against the vocabulary before
178
+ anything runs, and names a line no step matches, a line two steps match,
179
+ and a required key that nothing supplies.
180
+
181
+ The probe step stays behind: it has no pattern, so it was never going to
182
+ appear in a scenario, and nothing you learned through it is lost, because
183
+ what you learned is now written into the contracts of the steps that
184
+ replaced it.
@@ -0,0 +1,198 @@
1
+ # Fixtures: shared setup, cleanup, and waiting
2
+
3
+ When a scenario needs a project resource a step merely borrows (a tenant, a
4
+ seeded database row, an uploaded file), don't write its teardown inside the
5
+ step: that puts something in the feature file that is not itself an
6
+ acceptance condition. Declare it as a fixture instead, under
7
+ `nukadoko.config.ts`'s own `fixtures`, using `defineFixtures` (from the
8
+ `nukadoko` package).
9
+
10
+ ## Declaring a fixture
11
+
12
+ ```ts
13
+ export default defineConfig({
14
+ fixtures: {
15
+ tenant: async ({ request }, use) => {
16
+ const t = await createTenant(request);
17
+ await use(t);
18
+ await destroyTenant(request, t);
19
+ },
20
+ },
21
+ });
22
+
23
+ declare module "nukadoko" {
24
+ interface StepFixtures {
25
+ tenant: Tenant;
26
+ }
27
+ }
28
+ ```
29
+
30
+ `tsc` needs the `declare module` block: without it, a step that
31
+ destructures `tenant` fails with `Property 'tenant' does not exist on type
32
+ 'FixtureBag'`. `nuka check` does not need it, because it reads fixture
33
+ names from the source text. Write the block in `nukadoko.config.ts`, next
34
+ to the fixture, with the type the fixture passes to `use()`.
35
+
36
+ A step reaches it the same way it reaches `page` or `request`, by
37
+ destructuring the name: `async ({ tenant }, args) => {...}`. Setup runs the
38
+ first time a step names it; teardown runs after that step's scenario
39
+ finishes, in reverse build order, whether the scenario passed or failed.
40
+ What a fixture leaves (a signed-in context) belongs to the `gives` of the
41
+ step that builds it; a state every scenario starts with is required by no
42
+ step (`states.md`).
43
+ A setup that exceeds its timeout still fails the scenario, and the report
44
+ names the fixture and the phase. The fixture keeps running. If it calls
45
+ `use()` after that, the call resolves as `"failed"` and the teardown
46
+ written after `use()` still runs, on the teardown budget. That late
47
+ teardown runs when `use()` is reached. The timed-out setup produced no
48
+ instance, so the reverse-order pass has nothing to include for it. A
49
+ failure there is written to stderr. The scenario record may already be
50
+ sealed, and stderr is the announcement that still reaches the operator.
51
+ A teardown that finishes cleanly writes nothing.
52
+ Teardown still runs if `nuka run` or `nuka do` is stopped with SIGINT, SIGTERM, or SIGHUP, and under `nuka run --concurrency` too, in every worker, even when the parent itself is killed.
53
+ `use()`'s own return value tells the fixture which, so it can decide for
54
+ itself whether to keep what it built (for inspection) or tear it down;
55
+ `{ scope: "process" }` in a second, options element of the tuple form
56
+ builds it once for the whole `nuka run` invocation instead of once per
57
+ scenario, for something genuinely shared across scenarios rather than owned
58
+ by one (not for something that must happen exactly once in the world
59
+ regardless of process count, like seeding a database: `process` is one
60
+ address space, not one invocation). A fixture that never calls `use()`
61
+ fails its step by name rather than hanging the run. A second `use()` call
62
+ throws at that call, which is in teardown, so it is reported as
63
+ `fixture-teardown-failed` and leaves the scenario's status as it was; `nuka
64
+ check` catches a dependency cycle among fixtures, a `process`-scope
65
+ fixture depending on a `scenario`-scope one, and a fixture that destructures
66
+ `call` (only a step's `run` can use that) before anything runs.
67
+ `nuka check` also reports `fixture-structural-violation` when a config
68
+ fixture's own destructuring cannot be read, or names a fixture nukadoko
69
+ does not know. The finding names the fixture.
70
+
71
+ The program under test is not a fixture: the program in `nukadoko.config.ts` builds it,
72
+ starts it once per world on a port of its own, and stops it after the
73
+ scenarios (`program.md`). A fixture that starts a server in-process
74
+ gives a run no record of which program answered. A fixture that connects
75
+ an MCP client to the program passes the transport through `measureMcp`,
76
+ so each call a step sends is in its record (`evidence.md`).
77
+
78
+
79
+ ## Temporary directories
80
+
81
+ Don't declare a fixture for a temporary directory: `scratch` is a builtin.
82
+ `scratch.dir(prefix?)` returns a new empty directory, and
83
+ `scratch.copy(source)` returns a new directory holding a copy of `source`
84
+ (relative to the project root), so a scenario that writes never touches
85
+ the repository's own files. Every directory is removed when the scenario
86
+ ends, pass or fail, and the step record lists each path under
87
+ `evidence.scratch`. A project that already declares its own `scratch`
88
+ fixture keeps it: its fixture and its `StepFixtures` declaration both win
89
+ over the builtin, so delete them only when the builtin's shape is enough.
90
+
91
+ ## Waiting for an external effect
92
+
93
+ A step that writes to a system whose effect lands elsewhere asynchronously
94
+ isn't finished when the write is accepted, it's finished once that effect
95
+ is visible to whatever runs next. Wait for it there, with the `poll`
96
+ fixture, `poll(fn, { description, timeout, interval })`; give `description`
97
+ a value and the step record's `polls` carries `attempts`, `waited_ms`, and
98
+ `outcome` beside it. `timeout` is a budget for that whole call, including
99
+ the attempt in flight: the call ends when the budget ends, and a value
100
+ that arrives later is not returned. `timeout` and `interval` must be finite
101
+ and greater than zero. Anything else is refused before the first attempt.
102
+ Omitting either one keeps its default. That is what separates a wait that actually waited
103
+ from one that returned on its first attempt: the second means the
104
+ condition was never the late one, and something else is, which is a
105
+ different problem with a different fix.
106
+
107
+ Don't put the wait in a later step that merely reads the effect: that
108
+ step's wait then only covers scenarios passing through it, so a sibling
109
+ scenario reaching the same state another way fails for no reason that looks
110
+ like its own. A green run is no proof the wait sits in the right place, the
111
+ value may just have been supplied by that later step's own wait. Only a
112
+ route skipping that step can show where the wait actually belongs.
113
+
114
+ What `fn` waits for matters as much as where the wait lives. It can't be
115
+ the thing you're about to observe: when that observation's correct answer
116
+ is sometimes absence, waiting for it to appear means it can never come back
117
+ absent on purpose, because "not there yet" and "not there" look identical
118
+ to the wait. Wait instead for whatever tells you the observation is safe to
119
+ make at all (a loading flag going false, a count leaving `undefined`), and
120
+ only then read the thing you actually care about. And when that read comes
121
+ back absent, return proof the read was valid alongside it, not the absence
122
+ alone: a bare `false` can't tell whoever reads the step record later
123
+ whether the target really isn't there or the page just wasn't ready to
124
+ say.
125
+
126
+ ## Reading a required environment variable
127
+
128
+ Reach for `requireEnv(name)` over reading `env[name]` directly whenever a
129
+ step needs a value it cannot run without: `requireEnv` throws the moment
130
+ the key is missing or empty, rather than letting an `undefined` fail later
131
+ doing something the missing key had nothing to do with. Read `env` itself
132
+ only when a step wants several keys at once, or treats absence as a case
133
+ to branch on rather than a config mistake worth refusing over. `env` is a
134
+ frozen copy of that merged map. Assigning a property throws, so a write in
135
+ one step is not there for a later step or a later scenario. A configured
136
+ key still reads back as the loaded value.
137
+
138
+ The two also differ in what a step record shows afterward. Every name
139
+ `requireEnv` is called with, found or not, lands on that step's own
140
+ `required_env`, in the order it was read; a value taken straight off `env`
141
+ leaves no trace there. Neither ever records the value itself, only the
142
+ name it was read by: both draw from the project's configured `envFiles`
143
+ (the top-level list, then whatever the running environment's own
144
+ `envFiles` appends after it), which is exactly where a secret is most
145
+ likely to live. Git classifies those files. A tracked env file stays plain
146
+ only while its working tree matches HEAD. Uncommitted edits are redacted.
147
+ `nuka check` reports what that classification makes risky: a tracked env
148
+ file that holds a secret-looking key (`tracked-secret-looking-key`), and a
149
+ redacted value too short to redact safely (`secrets-redact-key-too-short`). A path in that list that is not
150
+ on disk contributes nothing, and `nuka check` warns (`env-file-missing`,
151
+ or `environment-env-file-missing` for one environment's own list). A path
152
+ that is present but cannot be read, or a directory at that path, is
153
+ refused before the step runs (`env-file-unreadable`). The refusal names the configured path and
154
+ the errno. `requireEnv` runs only after those files have been read, and
155
+ its message names the missing key.
156
+
157
+ Those files are `KEY=VALUE` text. A `#` comment, an optional `export`
158
+ prefix, single quotes, double quotes, and backticks are read, including a
159
+ value that spans lines. Double quotes expand `\n` and `\r`. The separator
160
+ is `=`. `$NAME` is not expanded. The full rules are in docs/spec.md under
161
+ "Environments and secrets". A line that is not a blank, a comment,
162
+ or a binding is `env-file-skipped-line` from `nuka check`.
163
+
164
+ ## Driving the app through another runner's session
165
+
166
+ A project already on e2e (`tester-army/e2e`) keeps its engines: its
167
+ `e2e/runner` exports `openHost`, which opens e2e sessions inside another
168
+ runner. Open the host in a process fixture and one session per scenario;
169
+ nukadoko gains no dependency, since the project already has `e2e`.
170
+
171
+ ```ts
172
+ e2eHost: [async ({ baseURL }, use) => {
173
+ const host = await openHost({ config: { targets: [
174
+ { name: "web", engine: web(), app: { url: baseURL } }] } });
175
+ try { await use(host); } finally { await host.close(); }
176
+ }, { scope: "process" }],
177
+ e2e: async ({ e2eHost }, use) => {
178
+ const session = await e2eHost.openSession({ name: "scenario" });
179
+ try { await use(session); } finally { await session.close(); }
180
+ },
181
+ ```
182
+
183
+ A step reads `e2e.fixtures.app`, `screen`, and `agent`. Then:
184
+
185
+ - **A Then claims what `screen` reads**, never `agent.assert`: its
186
+ `observe` returns the text or count, and a claim compares it; a model's
187
+ judgment is not a value the scenario stated (S1). `agent.act` can be a
188
+ Given or a When; declare `mutates` for what it submits.
189
+ - **Fold the error into one line.** In a Given or a When, e2e's first line names only the
190
+ matcher (`expect.toHaveText failed`) and `nuka run` prints the first
191
+ line (S11). Catch, and rethrow
192
+ `message.replaceAll("\n", "; ")` with the error as `cause`.
193
+ - **Attach what the session did.** `ctx.page()`'s screenshot, trace, and
194
+ HTTP log do not cover e2e's browser. Attach
195
+ `JSON.stringify(e2e.steps())` from the step, in a `finally`; the
196
+ session writes `trace.md` under `.e2e/results/host/` on close.
197
+ - One hosted session per process: `--concurrency` runs processes, so it
198
+ still works.
@@ -0,0 +1,51 @@
1
+ # From prose to requirements
2
+
3
+ Nothing in this stage runs a `nuka` command; a ticket, a request, or a
4
+ conversation isn't vocabulary yet, so there is nothing here for the CLI to
5
+ check. What this stage produces is text: a set of requirement statements,
6
+ each either complete or carrying a named question for the person who can
7
+ answer it.
8
+
9
+ Read the prose against the five EARS patterns as a checklist for what a
10
+ requirement needs to say to be actionable, not as a template to generate
11
+ polished-sounding wording from. A pattern's slots come from the prose
12
+ itself; a slot the prose doesn't state is a question, never a guess:
13
+
14
+ - **Ubiquitous**: "The `<system>` shall `<response>`." Always true, no
15
+ trigger and no condition.
16
+ - **Event-driven**: "When `<trigger>`, the `<system>` shall `<response>`."
17
+ - **State-driven**: "While `<state>`, the `<system>` shall `<response>`."
18
+ - **Unwanted behaviour**: "If `<trigger or condition>`, then the
19
+ `<system>` shall `<response>`."
20
+ - **Optional feature**: "Where `<feature is present>`, the `<system>`
21
+ shall `<response>`."
22
+
23
+ For each requirement-shaped statement in the prose:
24
+
25
+ 1. Decide which pattern fits, or notice the sentence is actually several
26
+ requirements compounded into one and split it first: a sentence with
27
+ "and" joining two different responses, or an implicit "unless," is
28
+ usually more than one requirement wearing one sentence.
29
+ 2. Fill each slot only with words the prose actually supports.
30
+ 3. Anything a slot needs that the prose doesn't state stays open: write it
31
+ as a question addressed to whoever can answer it, and leave the slot
32
+ unfilled rather than choosing a plausible value to move forward.
33
+ 4. Keep each requirement's own open questions attached to that
34
+ requirement, never pooled into one list, so a reader can see which
35
+ sentence is still unanswered rather than which set is.
36
+
37
+ For example, a ticket that says "the export should fail gracefully if the
38
+ file is too large" reads as an unwanted-behaviour candidate: "If `<file too
39
+ large>`, then the system shall `<fail gracefully>`." Both slots are
40
+ actually open. "Too large" names no threshold: what size, or what resource
41
+ limit, triggers it? "Fail gracefully" names no response: does the user see
42
+ a message, is the upload retried, is partial output cleaned up? Neither
43
+ gets a value invented to fill the pattern; both become questions back to
44
+ whoever wrote the ticket.
45
+
46
+ Once a requirement's slots are all filled from stated fact, and every open
47
+ slot has been resolved into an answered question, it is ready for
48
+ `references/writing-the-feature.md` ("From requirements to scenarios"). A
49
+ model drafting this classification is fine; the discipline lives in
50
+ refusing to fill a slot the source didn't support, not in refusing to
51
+ draft at all.
@@ -0,0 +1,95 @@
1
+ # Judgments
2
+
3
+ Some criteria no compare can decide: a greeting that is "friendly to a
4
+ first-time visitor", an error that "tells the reader what to do next", a
5
+ page that "reads as finished". A Then that states one asks for a
6
+ judgment. The run reads the value and judges nothing; a judge reads it
7
+ after the run and records `meets` or `misses` with one sentence; the next
8
+ run checks, exactly, that the value it read is the one judged.
9
+
10
+ Reach for this last. A criterion a compare can state (a text, a field, a
11
+ role and a name, a count) takes the compare: it holds on every run with
12
+ no one reading it. A judgment covers only the value it cites, so every
13
+ change to that value asks for a new one.
14
+
15
+ ## Writing the Then
16
+
17
+ The claim is `judged-as`. Its actual is the value to judge, its expected
18
+ the quality the sentence names, from a capture or the pattern's own words:
19
+
20
+ ```ts
21
+ export default defineStep({
22
+ pattern: "the greeting reads as {quality:string}",
23
+ args: z.object({ quality: z.string(), stdout: runGreet.returns.shape.stdout }),
24
+ from: { stdout: [runGreet, "stdout"] },
25
+ claims: [{ actual: "stdout", view: "text", compare: "judged-as", expected: "quality" }],
26
+ });
27
+ ```
28
+
29
+ - The value has to be one nukadoko measured: a response, a process's
30
+ output, a file, read through `view` and `at`. A value your step code
31
+ computed is `uncitable`, since a judge of it would judge your code.
32
+ - On a page, return the locator or the page from `observe`: the value is
33
+ its ARIA snapshot, so a change only to how it looks keeps the judgment,
34
+ and the judged view (`seen`: a screenshot and the ARIA file) is what the
35
+ judge looks at beside it. `nuka check` asks for `poll` there; a judged
36
+ value settles the poll only when two readings in a row agree.
37
+ - Not inside `each`, not with `count`, no expected from `from` or
38
+ `observe`, no `expected_view`: `defineStep` refuses each.
39
+ - Keep a judged Then to one quality. A Then that compares something and
40
+ asks for a judgment is two Thens.
41
+
42
+ ## The run
43
+
44
+ A row whose head passed and read a value gets a `judgment` column beside
45
+ its verdict; the verdict never changes. Its states:
46
+
47
+ - `pending`: no judgment cites the value. Get one judged (below).
48
+ - `stale`: the judgments cite a value this run did not read; the reason
49
+ names the first difference. Judge the new value; do not edit the file.
50
+ - `misses`: a judge said the value misses the sentence. Change the
51
+ program, not the sentence or the judgment, then run and judge again.
52
+ - `uncitable`: the step reads a value no channel holds. Fix the step.
53
+ - `judged`: each value has a `meets` judgment. The run summary lists the
54
+ row under "Held on a judgment".
55
+
56
+ Anything but `judged` fails the run with a `judgment-<state>` finding,
57
+ whose `do:` is the `nuka judge` line to run.
58
+
59
+ ## Judging
60
+
61
+ The judge is not the agent that wrote the change. You read the sentence
62
+ while you wrote the code, so your reading of the value is the reading the
63
+ code was written to pass. Hand it to a person, or to a fresh agent (a
64
+ subagent with nothing of this session) given only:
65
+
66
+ 1. the scenario's sentence and the quality,
67
+ 2. the value, and the `seen` files for a page,
68
+
69
+ from `nuka judge <feature>:<line> --run <run-id>`, which shows them and
70
+ records nothing. Give the judge no code, no diff, and no hint of the
71
+ answer you want. The judge answers `meets` or `misses` and one sentence
72
+ why; record it, with the judge's own name:
73
+
74
+ ```sh
75
+ npx nuka judge features/greeting.feature:3 --run <run-id> \
76
+ --meets --by "reviewer agent" --because "It welcomes the visitor and asks nothing of them."
77
+ ```
78
+
79
+ It writes `judgments/<feature path>.json` at the project root. Commit it
80
+ with the change: the commit and its review are the record of who judged,
81
+ since `--by` is only a name. Never write or edit that file by hand, never
82
+ judge a value yourself, and never pass `--by` a name that did not judge.
83
+ `nuka judge` refuses a value whose step record no longer has the digest
84
+ run.json recorded: run again and judge what the new run reads.
85
+
86
+ A `misses` is an answer, not an obstacle: report it to the person with
87
+ the judge's sentence, and do not look for another judge who says `meets`.
88
+
89
+ ## Under --base
90
+
91
+ A new or changed criterion whose Thens only ask for judgments is `held`,
92
+ never `unproven` (no base can break a claim that compares nothing), and
93
+ its judgment decides it. The summary names the judgment files the change
94
+ brings ("A judgment file changed since the base"), so the person reviews
95
+ each judgment with the feature.
@@ -0,0 +1,97 @@
1
+ # Keeping the vocabulary healthy over time
2
+
3
+ ## When the notes appear, and what to do with them
4
+
5
+ `nuka check` with no target reports errors, warnings, and notes. Its errors
6
+ answer whether the next run can proceed. Its notes answer a different
7
+ question: whether the vocabulary and the records behind it are rotting. A
8
+ step nothing binds any more, a fixture nothing names, a field no
9
+ description explains: none of that stops a run, so a note never changes the
10
+ exit code, and acting on one is not a step of the acceptance loop.
11
+
12
+ A `nuka check` with targets, and the check `nuka run` runs before it
13
+ executes, print no notes: whether a step is bound depends on every feature
14
+ the project scans, so only the whole-project check can say.
15
+
16
+ A step file that failed to import is an error, `step-file-import-failed`,
17
+ and the notes count only the steps that imported, so they leave that
18
+ file's steps out. Fix that import first; the notes are not complete until
19
+ it is. When the finding ends with `; <path>.js stands for
20
+ <path>.ts, which does not exist; update the import in <file>`, a step file was
21
+ renamed or deleted under an import that still names it: point the import
22
+ in the file it names at the new file, or remove it.
23
+
24
+ Report what the notes say and stop there. A note on a step you are
25
+ writing or rewriting anyway falls under the rules for writing it
26
+ (`checking-steps.md`): a `schema-field-undescribed` field gets its
27
+ `.describe()`. Every other note is about something the user chose, so
28
+ acting on one without being asked replaces their choice with yours. Two shapes come up often enough to name here; the rest of
29
+ this file is what each note actually means. A step nothing binds any
30
+ more is usually a deletion someone forgot to finish, and a fixture
31
+ nothing names is usually setup that outlived the scenario that needed it.
32
+ Say which notes you would act on and what each would change, then
33
+ wait. Nothing here is urgent; a note that has waited a week can wait
34
+ for an answer.
35
+
36
+ ## What it reports
37
+
38
+ A note is something a project is allowed to carry rather than something
39
+ blocking, so notes alone exit 0. A job that must block on one passes
40
+ `nuka check --fail-on <code>` (for instance `pattern-unbound`); the finding
41
+ stays a note in the output, and only that invocation's exit code turns to
42
+ 1. Notes come from a check with no target, and a note code with targets
43
+ is refused (`fail-on-note-with-targets`). The code to pass is the one printed beside each note, or one from
44
+ `nuka check --codes`, which lists every code with its severity and a
45
+ one-line meaning before any of them has fired. Each note also names a file
46
+ and a `fix:` line: what to open, and the change to make if the note calls
47
+ for one.
48
+
49
+ Every whole-project check reports every note, `schema-field-undescribed` (a
50
+ field with no `.describe()`) included. A gate that acts on some notes and
51
+ not others filters the `--json` envelope's `findings` by `severity` and
52
+ `code`, or passes `--fail-on` for each code it acts on.
53
+
54
+ `step-description-todo` names a typed step whose description is still
55
+ the `TODO: describe <name>` that `nuka scaffold` wrote without
56
+ `--description`. The step runs, so nothing else says so, but `nuka steps`
57
+ and `nuka describe` show that TODO to whoever picks a step. Write what the
58
+ step does in its place.
59
+
60
+ `nuka run` ends with a `repeated-scenario-prefix` note when scenarios of
61
+ that run shared the same opening steps; the note never changes the run's
62
+ exit code. It shows the measured time for that opening and its share of
63
+ the run's summed scenario time. An opening ends
64
+ before the first When, and two steps share it only when their docstring
65
+ or table is the same too. The note names the same opening on every run:
66
+ the one that covers the most step executions, not the slowest. It names a
67
+ process-scope fixture only when every shared step declares
68
+ `mutates: false`. Otherwise it names the first step that may write: an
69
+ opening that creates the record each scenario then reads by id stays in
70
+ each scenario (`scenario-rules.md`, S8, and `examples/http-api.md`). A
71
+ step that keeps the default `mutates: true` but writes nothing a later
72
+ scenario reads is the one case to judge yourself.
73
+
74
+ Once a feature has moved into `featuresDir` (see "The loop" in
75
+ `SKILL.md`, step 6), `nuka run` picks it up on every future commit, and each of
76
+ those runs writes its own run summary. A feature kept outside
77
+ `featuresDir` and listed in `additionalFeatureDirs` still counts for the
78
+ steps it binds, so `pattern-unbound` and `fixture-unused` do not report
79
+ its steps as dead, but nothing runs it unattended.
80
+
81
+ ## What runs keep not showing
82
+
83
+ Each run.json's `limits` lists what that run does not show, by `kind`
84
+ (docs/spec.md "Records"), and the summary lists the same entries under
85
+ "What this run does not show". A gap that comes back run after run is the
86
+ next thing to fix: a criterion whose control never fails at a Then, a step
87
+ nukadoko cannot measure. Rank them across the runs you have, each counted
88
+ once per run:
89
+
90
+ ```sh
91
+ jq -s 'map([.limits[]? | {kind, at: (if .feature then "\(.feature):\(.line)" else (.environment // "run") end)}] | unique)
92
+ | add // [] | group_by(.) | map(.[0] + {runs: length}) | sort_by(-.runs) | .[:10]' .nukadoko/runs/*/run.json
93
+ ```
94
+
95
+ `retention` deletes old run directories, so a longer window reads the
96
+ run.json files CI kept as artifacts. Fix the top entry with its `fix` or
97
+ `do`, and the next runs show whether it stayed closed.