spec-controller 0.1.0-alpha.2 → 0.1.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/dist/cli-args.d.ts +4 -1
- package/dist/cli-args.d.ts.map +1 -1
- package/dist/cli-args.js +27 -6
- package/dist/cli-args.js.map +1 -1
- package/dist/cli-balance/cli.d.ts +18 -1
- package/dist/cli-balance/cli.d.ts.map +1 -1
- package/dist/cli-balance/cli.js +153 -151
- package/dist/cli-balance/cli.js.map +1 -1
- package/dist/cli-registry.d.ts +17 -0
- package/dist/cli-registry.d.ts.map +1 -1
- package/dist/cli-registry.js +18 -7
- package/dist/cli-registry.js.map +1 -1
- package/dist/cli.js +6 -4
- package/dist/cli.js.map +1 -1
- package/dist/corpus/cli.d.ts.map +1 -1
- package/dist/corpus/cli.js +1 -4
- package/dist/corpus/cli.js.map +1 -1
- package/dist/deferralTags.d.ts +2 -2
- package/dist/deferralTags.js +2 -2
- package/dist/host.d.ts +15 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +15 -0
- package/dist/host.js.map +1 -1
- package/dist/ingest/gherkinValidation.d.ts +6 -5
- package/dist/ingest/gherkinValidation.d.ts.map +1 -1
- package/dist/ingest/gherkinValidation.js +6 -5
- package/dist/ingest/gherkinValidation.js.map +1 -1
- package/dist/ingest/ingestQualityChecks.d.ts +0 -45
- package/dist/ingest/ingestQualityChecks.d.ts.map +1 -1
- package/dist/ingest/ingestQualityChecks.js +11 -110
- package/dist/ingest/ingestQualityChecks.js.map +1 -1
- package/dist/run-management/resolveRunInputs.d.ts +24 -11
- package/dist/run-management/resolveRunInputs.d.ts.map +1 -1
- package/dist/run-management/resolveRunInputs.js +49 -13
- package/dist/run-management/resolveRunInputs.js.map +1 -1
- package/package.json +2 -7
- package/dist/mutation-ratchet/index.d.ts +0 -46
- package/dist/mutation-ratchet/index.d.ts.map +0 -1
- package/dist/mutation-ratchet/index.js +0 -46
- package/dist/mutation-ratchet/index.js.map +0 -1
- package/dist/mutation-ratchet/record.d.ts +0 -178
- package/dist/mutation-ratchet/record.d.ts.map +0 -1
- package/dist/mutation-ratchet/record.js +0 -314
- package/dist/mutation-ratchet/record.js.map +0 -1
- package/dist/mutation-ratchet/report.d.ts +0 -109
- package/dist/mutation-ratchet/report.d.ts.map +0 -1
- package/dist/mutation-ratchet/report.js +0 -156
- package/dist/mutation-ratchet/report.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,15 +11,17 @@ Requires Node ≥ 22. ESM only.
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
13
|
```
|
|
14
|
-
npm install -g spec-controller
|
|
14
|
+
npm install -g spec-controller@alpha
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Or without installing anything:
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
npx spec-controller balance --help
|
|
20
|
+
npx spec-controller@alpha balance --help
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
+
`@alpha` is not optional until `0.1.0` publishes: a bare install resolves `latest`, which npm set to `0.1.0-alpha.1` on the first publish, and that version has neither `tags` nor `--ci-steps`.
|
|
24
|
+
|
|
23
25
|
## Your first run
|
|
24
26
|
|
|
25
27
|
Point it at your scenarios and give it nothing else:
|
|
@@ -30,6 +32,20 @@ spec-controller balance --features ./features
|
|
|
30
32
|
|
|
31
33
|
Every scenario comes back as a row whether or not any evidence exists for it, so on this first run the ones you have supplied no reports for read **missing** and the run comes back out-of-balance. That is the shape of the tool rather than a fault in your repository: the reconciliation starts from what you specified, not from what a tool happened to find, and there is no input for which the right answer is silence.
|
|
32
34
|
|
|
35
|
+
**`balance` fails your build out of the box.** An out-of-balance run exits `1`, so the first run above reds any pipeline you put it in. That is a deliberate departure from two tools it sits beside: Stryker's `thresholds.break` defaults to `null` (*"never let your build fail"*), and the Sonar scanner exits `0` whatever its quality gate says unless you set `sonar.qualitygate.wait`. Both make you opt in to gating. `balance` makes you opt out.
|
|
36
|
+
|
|
37
|
+
### Report first, gate later
|
|
38
|
+
|
|
39
|
+
To bring it into a pipeline you already have without redding it on day one, add `--exit-zero`:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
spec-controller balance --features ./features --vitest ./vitest-report.json --exit-zero
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The report is byte for byte the one the gate prints: the same rows, the same out-of-balance count, and the same headline naming the code the gate would give. Only the exit status moves. Out-of-balance (`1`) and pending under `--strict` (`3`) exit `0`. Usage (`2`), unsound (`4`) and nothing to reconcile (`5`) still fail, because each means the run could not give a verdict at all, and a flag that suppresses verdicts does not suppress that.
|
|
46
|
+
|
|
47
|
+
Work the out-of-balance rows down, then delete `--exit-zero`, and the gate is on. Don't wrap the step in `continue-on-error` or `|| true` instead: those swallow the codes that mean the run could not be trusted, and they leave nothing in the command to say the gate is off.
|
|
48
|
+
|
|
33
49
|
Now give it the evidence:
|
|
34
50
|
|
|
35
51
|
```
|
|
@@ -54,6 +70,8 @@ A scenario tagged `@unit` names an obligation — a unit test must exist and pas
|
|
|
54
70
|
|
|
55
71
|
The whole report is written before the code is set, so a failing run still tells you why.
|
|
56
72
|
|
|
73
|
+
`--exit-zero` moves `1` and `3` to `0` and leaves every other code alone: see *Report first, gate later*.
|
|
74
|
+
|
|
57
75
|
**Node's default is never one of these.** A run that cannot reconcile ends on an enumerated code of
|
|
58
76
|
its own rather than falling out of the process — a crash that exits `1` would be indistinguishable,
|
|
59
77
|
by status, from an honest disagreement. **An input the tool cannot read is part of `2`**: a mistyped
|
|
@@ -83,7 +101,7 @@ spec-controller balance --features ./features \
|
|
|
83
101
|
## Where to go next
|
|
84
102
|
|
|
85
103
|
- **Full flags, worked examples and CI wiring** — [`doc/how_to_use.md`](https://github.com/3f-consulting/spec-controller/blob/main/doc/how_to_use.md)
|
|
86
|
-
- **Bringing a check you already have under the reconciliation** — [`doc/
|
|
104
|
+
- **Bringing a check you already have under the reconciliation** — [`doc/adopting-fitness-checks.md`](https://github.com/3f-consulting/spec-controller/blob/main/doc/adopting-fitness-checks.md)
|
|
87
105
|
- **Why `0.x` promises nothing, and what changes at `1.0`** — [`doc/compatibility.md`](https://github.com/3f-consulting/spec-controller/blob/main/doc/compatibility.md)
|
|
88
106
|
- **Building your own tooling on the engine instead of running a command** — [`@3f-consulting/spec-controller-core`](https://www.npmjs.com/package/@3f-consulting/spec-controller-core), the same reconciliation logic as a pure library with no CLI and no I/O.
|
|
89
107
|
|
package/dist/cli-args.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export declare function parseArgs(argv: readonly string[]): Record<string, strin
|
|
|
51
51
|
* The dispatcher refuses such a command before this is ever reached, so the case is unreachable
|
|
52
52
|
* today and stated here so it cannot become a silent "accept everything" later.
|
|
53
53
|
*
|
|
54
|
-
* IT NAMES THE VERSION THAT REFUSED, AND THAT IS FOR THE PINNED READER (3F-3105, @SCN-
|
|
54
|
+
* IT NAMES THE VERSION THAT REFUSED, AND THAT IS FOR THE PINNED READER (3F-3105, @SCN-CLI-009).
|
|
55
55
|
* A consumer pins spec-controller and then moves their own tree; the pinned reader is handed argv
|
|
56
56
|
* it was published too early — or too late — to understand, and an unadorned "unknown flag" is
|
|
57
57
|
* indistinguishable from a typo. Naming the running version makes version skew legible from the CI
|
|
@@ -65,6 +65,9 @@ export declare function parseArgs(argv: readonly string[]): Record<string, strin
|
|
|
65
65
|
* refusal is exactly that forbidden wrapper, and no other adopter could write one either. So the
|
|
66
66
|
* refusal is the tool's own, which makes it universal rather than local.
|
|
67
67
|
*
|
|
68
|
+
* EXCEPT FOR A FLAG THE COMMAND HAS RETIRED, where the bump is false advice: `retiredFlagRefusal`
|
|
69
|
+
* below names the retirement and its replacement instead (3F-3528).
|
|
70
|
+
*
|
|
68
71
|
* THE STATUS DOES NOT MOVE. The caller still routes this to stderr and exit 2. A mistyped `--strcit`
|
|
69
72
|
* is still a usage fault, and giving skew its own status would cost every adopter the ordinary
|
|
70
73
|
* reading to serve the rarer one.
|
package/dist/cli-args.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../src/cli-args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../src/cli-args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,mBAAmB,CAAC;AAElE;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBzE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CA2Bf"}
|
package/dist/cli-args.js
CHANGED
|
@@ -67,7 +67,7 @@ export function parseArgs(argv) {
|
|
|
67
67
|
* The dispatcher refuses such a command before this is ever reached, so the case is unreachable
|
|
68
68
|
* today and stated here so it cannot become a silent "accept everything" later.
|
|
69
69
|
*
|
|
70
|
-
* IT NAMES THE VERSION THAT REFUSED, AND THAT IS FOR THE PINNED READER (3F-3105, @SCN-
|
|
70
|
+
* IT NAMES THE VERSION THAT REFUSED, AND THAT IS FOR THE PINNED READER (3F-3105, @SCN-CLI-009).
|
|
71
71
|
* A consumer pins spec-controller and then moves their own tree; the pinned reader is handed argv
|
|
72
72
|
* it was published too early — or too late — to understand, and an unadorned "unknown flag" is
|
|
73
73
|
* indistinguishable from a typo. Naming the running version makes version skew legible from the CI
|
|
@@ -81,6 +81,9 @@ export function parseArgs(argv) {
|
|
|
81
81
|
* refusal is exactly that forbidden wrapper, and no other adopter could write one either. So the
|
|
82
82
|
* refusal is the tool's own, which makes it universal rather than local.
|
|
83
83
|
*
|
|
84
|
+
* EXCEPT FOR A FLAG THE COMMAND HAS RETIRED, where the bump is false advice: `retiredFlagRefusal`
|
|
85
|
+
* below names the retirement and its replacement instead (3F-3528).
|
|
86
|
+
*
|
|
84
87
|
* THE STATUS DOES NOT MOVE. The caller still routes this to stderr and exit 2. A mistyped `--strcit`
|
|
85
88
|
* is still a usage fault, and giving skew its own status would cost every adopter the ordinary
|
|
86
89
|
* reading to serve the rarer one.
|
|
@@ -102,13 +105,31 @@ export function checkUnknownFlags(args, registry, command, toolVersion) {
|
|
|
102
105
|
// whose scope refused it — a consumer running two commands needs to know which help to open.
|
|
103
106
|
for (const key of Object.keys(args)) {
|
|
104
107
|
if (!accepted.has(key)) {
|
|
105
|
-
return (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
return (retiredFlagRefusal(entry, key, command, toolVersion) ??
|
|
109
|
+
`Unknown flag --${key} for 'spec-controller ${command}' — this is spec-controller ` +
|
|
110
|
+
`${toolVersion}, and that flag is not in its ${command} scope.\n` +
|
|
111
|
+
`If this version is pinned, the pin and the tree it is reading have drifted apart: ` +
|
|
112
|
+
`bump the pin to a version whose '${command}' accepts --${key}.\n` +
|
|
113
|
+
`Otherwise run 'spec-controller ${command} --help' to see the flags this version accepts.`);
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
return null;
|
|
113
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* THE REFUSAL FOR A FLAG THE COMMAND HAS RETIRED (@SCN-CLI-023, 3F-3528), or `undefined` when the
|
|
120
|
+
* flag is merely unregistered. The drift advice above is true of a flag newer than the pin and
|
|
121
|
+
* false of a retired one: every earlier version accepts it and no later one will, so the only pin
|
|
122
|
+
* that satisfies "bump the pin to a version that accepts it" is a downgrade back onto the route
|
|
123
|
+
* the retirement removed. So this names the retirement and the replacement, and offers no pin.
|
|
124
|
+
*/
|
|
125
|
+
function retiredFlagRefusal(entry, key, command, toolVersion) {
|
|
126
|
+
const retired = entry?.retiredFlags?.find((flag) => flag.name.replace(/^-+/, "") === key);
|
|
127
|
+
if (retired === undefined)
|
|
128
|
+
return undefined;
|
|
129
|
+
return (`Retired flag ${retired.name} for 'spec-controller ${command}' — retired in spec-controller ` +
|
|
130
|
+
`${retired.retiredIn}, and no later version accepts it (this is spec-controller ${toolVersion}).\n` +
|
|
131
|
+
`Do not pin an earlier version to get it back: that restores the route it was retired with. ` +
|
|
132
|
+
`${retired.replacement}\n` +
|
|
133
|
+
`Run 'spec-controller ${command} --help' to see the flags this version accepts.`);
|
|
134
|
+
}
|
|
114
135
|
//# sourceMappingURL=cli-args.js.map
|
package/dist/cli-args.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../src/cli-args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,SAAS,CAAC,IAAuB;IAC/C,MAAM,IAAI,GAA2B,EAAE,CAAC;IACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACvB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC1B,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACnD,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBAClB,CAAC,EAAE,CAAC;YACN,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../src/cli-args.ts"],"names":[],"mappings":"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"}
|
|
@@ -32,6 +32,23 @@ export declare function checkLegacyJson(args: Record<string, string>): string |
|
|
|
32
32
|
* explicit default.
|
|
33
33
|
*/
|
|
34
34
|
export declare function sourceTarget(args: Record<string, string>): string;
|
|
35
|
+
/**
|
|
36
|
+
* Guard the supplied input-file/dir flags at the CLI edge (@SCN-CLI-002). A
|
|
37
|
+
* mistyped `--vitest` / `--cucumber` / `--features` / `--ci` / `--package-json`
|
|
38
|
+
* pointing at a non-existent path used to reconcile silently against ZERO evidence —
|
|
39
|
+
* a terrifying false all-red report meaning "you forgot the reports", not "your code
|
|
40
|
+
* is broken" (the dogfooding fault). These flags are Examples of ONE boundary
|
|
41
|
+
* rule: a supplied-but-absent input path is a hard error, and a flag added to the set
|
|
42
|
+
* inherits it rather than restating it. Scope is existence only
|
|
43
|
+
* (readability / file-vs-dir type-correctness out of scope; `exists` covers the dir
|
|
44
|
+
* flag and the file flags alike).
|
|
45
|
+
*
|
|
46
|
+
* PURE and `@unit`-testable like `checkLegacyJson` / `sourceTarget`: reads the parsed
|
|
47
|
+
* args + an injected `exists` fn (no fs), returns the FIRST supplied-but-absent
|
|
48
|
+
* `(flag, path)` as a typed error naming both — routed to stderr + a non-zero exit by
|
|
49
|
+
* `refuseUnreadableInputs` (the shared typed-error surface) — else null. An OMITTED flag is not an
|
|
50
|
+
* error (legitimately optional: simply no evidence of that kind).
|
|
51
|
+
*/
|
|
35
52
|
export declare function checkInputsExist(args: Record<string, string>, exists: (path: string) => boolean): string | null;
|
|
36
53
|
/**
|
|
37
54
|
* Guard the READABILITY of the supplied JSON inputs at the CLI edge (@SCN-CLI-014).
|
|
@@ -44,7 +61,7 @@ export declare function checkInputsExist(args: Record<string, string>, exists: (
|
|
|
44
61
|
*
|
|
45
62
|
* PURE and `@unit`-testable like its sibling guards: reads the parsed args + an injected
|
|
46
63
|
* `read` fn (no fs), returns the FIRST supplied-but-unparseable `(flag, path, failure)` as
|
|
47
|
-
* a typed error naming all three — routed to stderr + exit 2 by `
|
|
64
|
+
* a typed error naming all three — routed to stderr + exit 2 by `refuseUnreadableInputs` — else null.
|
|
48
65
|
* An omitted flag is not an error, and an unreadable file (a race after the existence
|
|
49
66
|
* check) reports as the same input fault rather than escaping as a crash.
|
|
50
67
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli-balance/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli-balance/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgDH;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAS3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAEjE;AAqBD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAChC,MAAM,GAAG,IAAI,CAcf;AAYD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAC7B,MAAM,GAAG,IAAI,CAef;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAC7B,MAAM,GAAG,IAAI,CAcf;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAkJ/C"}
|
package/dist/cli-balance/cli.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import { existsSync, readFileSync } from "node:fs";
|
|
15
15
|
import { dirname } from "node:path";
|
|
16
|
-
import { runReconcile, readEvidenceObligations, readFeatureNames, featureCorpusParseErrors,
|
|
16
|
+
import { runReconcile, readEvidenceObligations, readFeatureNames, featureCorpusParseErrors, } from "../ingest/ingestQualityChecks.js";
|
|
17
17
|
import { planOutput } from "./emit/format.js";
|
|
18
18
|
import { writeOutputs } from "./emit/writer.js";
|
|
19
19
|
import { renderReportFromJson, isBalanced, hasPendingItems, hasBrokenEvidence, hasNothingToReconcile, } from "@3f-consulting/spec-controller-core";
|
|
@@ -72,23 +72,6 @@ export function checkLegacyJson(args) {
|
|
|
72
72
|
export function sourceTarget(args) {
|
|
73
73
|
return args["target"] ?? "unknown-target";
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Guard the supplied input-file/dir flags at the CLI edge (@SCN-CLI-002). A
|
|
77
|
-
* mistyped `--vitest` / `--cucumber` / `--features` / `--ci` / `--package-json`
|
|
78
|
-
* pointing at a non-existent path used to reconcile silently against ZERO evidence —
|
|
79
|
-
* a terrifying false all-red report meaning "you forgot the reports", not "your code
|
|
80
|
-
* is broken" (the dogfooding fault). These flags are Examples of ONE boundary
|
|
81
|
-
* rule: a supplied-but-absent input path is a hard error, and a flag added to the set
|
|
82
|
-
* inherits it rather than restating it. Scope is existence only
|
|
83
|
-
* (readability / file-vs-dir type-correctness out of scope; `exists` covers the dir
|
|
84
|
-
* flag and the file flags alike).
|
|
85
|
-
*
|
|
86
|
-
* PURE and `@unit`-testable like `checkLegacyJson` / `sourceTarget`: reads the parsed
|
|
87
|
-
* args + an injected `exists` fn (no fs), returns the FIRST supplied-but-absent
|
|
88
|
-
* `(flag, path)` as a typed error naming both — routed to stderr + a non-zero exit by
|
|
89
|
-
* `runBalance` (the shared typed-error surface) — else null. An OMITTED flag is not an
|
|
90
|
-
* error (legitimately optional: simply no evidence of that kind).
|
|
91
|
-
*/
|
|
92
75
|
/**
|
|
93
76
|
* The parsed args, as the reconciler's input paths — the one place a `--flag` name becomes a
|
|
94
77
|
* `ReconcileOptions` key.
|
|
@@ -104,16 +87,32 @@ function reconcileInputsOf(args) {
|
|
|
104
87
|
cucumber: args["cucumber"],
|
|
105
88
|
ci: args["ci"],
|
|
106
89
|
packageJson: args["package-json"],
|
|
107
|
-
measurements: args["measurements"],
|
|
108
90
|
ciSteps: args["ci-steps"],
|
|
109
91
|
};
|
|
110
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Guard the supplied input-file/dir flags at the CLI edge (@SCN-CLI-002). A
|
|
95
|
+
* mistyped `--vitest` / `--cucumber` / `--features` / `--ci` / `--package-json`
|
|
96
|
+
* pointing at a non-existent path used to reconcile silently against ZERO evidence —
|
|
97
|
+
* a terrifying false all-red report meaning "you forgot the reports", not "your code
|
|
98
|
+
* is broken" (the dogfooding fault). These flags are Examples of ONE boundary
|
|
99
|
+
* rule: a supplied-but-absent input path is a hard error, and a flag added to the set
|
|
100
|
+
* inherits it rather than restating it. Scope is existence only
|
|
101
|
+
* (readability / file-vs-dir type-correctness out of scope; `exists` covers the dir
|
|
102
|
+
* flag and the file flags alike).
|
|
103
|
+
*
|
|
104
|
+
* PURE and `@unit`-testable like `checkLegacyJson` / `sourceTarget`: reads the parsed
|
|
105
|
+
* args + an injected `exists` fn (no fs), returns the FIRST supplied-but-absent
|
|
106
|
+
* `(flag, path)` as a typed error naming both — routed to stderr + a non-zero exit by
|
|
107
|
+
* `refuseUnreadableInputs` (the shared typed-error surface) — else null. An OMITTED flag is not an
|
|
108
|
+
* error (legitimately optional: simply no evidence of that kind).
|
|
109
|
+
*/
|
|
111
110
|
export function checkInputsExist(args, exists) {
|
|
112
111
|
// The input flags in a fixed order — the FIRST supplied-but-absent one is the
|
|
113
112
|
// reported error (deterministic; the operator fixes and re-runs). Keys are the
|
|
114
113
|
// parseArgs form (the `--` stripped); the message names the flag WITH its dashes.
|
|
115
114
|
const flags = [
|
|
116
|
-
"vitest", "cucumber", "features", "ci", "package-json", "
|
|
115
|
+
"vitest", "cucumber", "features", "ci", "package-json", "ci-steps",
|
|
117
116
|
];
|
|
118
117
|
for (const flag of flags) {
|
|
119
118
|
const path = args[flag];
|
|
@@ -130,7 +129,7 @@ export function checkInputsExist(args, exists) {
|
|
|
130
129
|
* process, and on garbage both reconcile normally (verified, 3F-1742 Discovery).
|
|
131
130
|
*/
|
|
132
131
|
const JSON_INPUT_FLAGS = [
|
|
133
|
-
"vitest", "cucumber", "package-json", "
|
|
132
|
+
"vitest", "cucumber", "package-json", "ci-steps",
|
|
134
133
|
];
|
|
135
134
|
/**
|
|
136
135
|
* Guard the READABILITY of the supplied JSON inputs at the CLI edge (@SCN-CLI-014).
|
|
@@ -143,7 +142,7 @@ const JSON_INPUT_FLAGS = [
|
|
|
143
142
|
*
|
|
144
143
|
* PURE and `@unit`-testable like its sibling guards: reads the parsed args + an injected
|
|
145
144
|
* `read` fn (no fs), returns the FIRST supplied-but-unparseable `(flag, path, failure)` as
|
|
146
|
-
* a typed error naming all three — routed to stderr + exit 2 by `
|
|
145
|
+
* a typed error naming all three — routed to stderr + exit 2 by `refuseUnreadableInputs` — else null.
|
|
147
146
|
* An omitted flag is not an error, and an unreadable file (a race after the existence
|
|
148
147
|
* check) reports as the same input fault rather than escaping as a crash.
|
|
149
148
|
*/
|
|
@@ -217,13 +216,8 @@ export function runBalance(argv) {
|
|
|
217
216
|
// guard's typed error is routed to stderr + a non-zero exit, exactly as planOutput's error
|
|
218
217
|
// is below (the shared typed-error surface).
|
|
219
218
|
const legacyJsonError = checkLegacyJson(args);
|
|
220
|
-
if (legacyJsonError)
|
|
221
|
-
|
|
222
|
-
// Usage/config error → exit 2 (the enumerated usage code, @SCN-CLI-002), distinct
|
|
223
|
-
// from the out-of-balance verdict code 1 (@SCN-CLI-004): an out-of-balance run must
|
|
224
|
-
// never masquerade as a usage error, nor the reverse.
|
|
225
|
-
process.exit(2);
|
|
226
|
-
}
|
|
219
|
+
if (legacyJsonError)
|
|
220
|
+
exitUsage(legacyJsonError);
|
|
227
221
|
// Registry-bounded parse (@SCN-CLI-009): `balance` accepts ONLY the flags its registry
|
|
228
222
|
// scope LISTS. An unregistered flag — a typo `--strcit`, a stray `--bogus` — is a
|
|
229
223
|
// USAGE error: name it on stderr, set process.exitCode = 2 (the enumerated usage code,
|
|
@@ -238,97 +232,9 @@ export function runBalance(argv) {
|
|
|
238
232
|
process.exitCode = 2;
|
|
239
233
|
return;
|
|
240
234
|
}
|
|
241
|
-
|
|
242
|
-
// banked spec-reconciliation.json ALONE — no reconcile, no live inputs, no RunContext. Reads
|
|
243
|
-
// the file, JSON.parses it back into the whole-document report model, renders the markdown via
|
|
244
|
-
// renderReport, and writes it to stdout (the same trailing-newline convention as the writer's
|
|
245
|
-
// stdout path). The load-bearing proof that the JSON IS the model — returns before any reconcile.
|
|
246
|
-
// Saved-report READABILITY guard (@SCN-CLI-015). This branch RETURNS before the input
|
|
247
|
-
// guards below ever run, so it honoured NEITHER: a missing path crashed to ENOENT and a
|
|
248
|
-
// malformed file to SyntaxError, both landing on Node's default exit 1 — the
|
|
249
|
-
// out-of-balance code. The missing-path case was a live violation of @SCN-CLI-002's own
|
|
250
|
-
// shipped principle, which the CLI enforced for the five evidence flags and not for this
|
|
251
|
-
// one. The guard therefore runs INSIDE this branch, ahead of the read (3F-1764).
|
|
252
|
-
const unreadableSavedReportError = checkRenderFromJson(args, (path) => readFileSync(path, "utf8"));
|
|
253
|
-
if (unreadableSavedReportError) {
|
|
254
|
-
process.stderr.write(unreadableSavedReportError + "\n");
|
|
255
|
-
process.exit(2);
|
|
256
|
-
}
|
|
257
|
-
const rehydratePath = args["render-from-json"];
|
|
258
|
-
if (rehydratePath !== undefined) {
|
|
259
|
-
const savedReport = readFileSync(rehydratePath, "utf8");
|
|
260
|
-
process.stdout.write(renderReportFromJson(savedReport) + "\n");
|
|
235
|
+
if (renderSavedReport(args))
|
|
261
236
|
return;
|
|
262
|
-
|
|
263
|
-
// Input-existence guard (@SCN-CLI-002): a supplied input-file/dir flag pointing at a
|
|
264
|
-
// non-existent path is a HARD ERROR — halt BEFORE reconciling, with a typed message
|
|
265
|
-
// naming the flag + path, never the silent zero-evidence all-red report a mistyped
|
|
266
|
-
// path used to produce (the dogfooding fault). Routed to stderr + a non-zero exit,
|
|
267
|
-
// exactly as the legacy-`--json` guard above (the shared typed-error surface). An
|
|
268
|
-
// omitted flag is legitimately optional and passes through untouched.
|
|
269
|
-
const missingInputError = checkInputsExist(args, existsSync);
|
|
270
|
-
if (missingInputError) {
|
|
271
|
-
process.stderr.write(missingInputError + "\n");
|
|
272
|
-
// Usage/input error → exit 2 (@SCN-CLI-002), distinct from the out-of-balance
|
|
273
|
-
// verdict code 1 (@SCN-CLI-004).
|
|
274
|
-
process.exit(2);
|
|
275
|
-
}
|
|
276
|
-
// Input-READABILITY guard (@SCN-CLI-014): existence is not enough. A report that is
|
|
277
|
-
// PRESENT but UNPARSEABLE (`--vitest /dev/null`, truncated JSON, non-JSON) used to throw
|
|
278
|
-
// mid-parse inside reconcileWithCensus, uncaught — and Node's default exit code is 1, the
|
|
279
|
-
// code reserved for a genuine OUT-OF-BALANCE verdict (@SCN-CLI-004). So a tool that
|
|
280
|
-
// CRASHED before reconciling was indistinguishable, by exit code, from an honest
|
|
281
|
-
// disagreement (3F-1742). Runs immediately after the existence guard and BEFORE any
|
|
282
|
-
// reconcile, routing to the same stderr + exit 2 lane: an input the tool cannot read is a
|
|
283
|
-
// usage fault, sibling to a missing path and an unrecognised flag — never a verdict.
|
|
284
|
-
const unparseableInputError = checkInputsParse(args, (path) => readFileSync(path, "utf8"));
|
|
285
|
-
if (unparseableInputError) {
|
|
286
|
-
process.stderr.write(unparseableInputError + "\n");
|
|
287
|
-
process.exit(2);
|
|
288
|
-
}
|
|
289
|
-
// The FEATURE-CORPUS integrity checkpoint (@SCN-CLI-016, 3F-1767). The feature corpus is an
|
|
290
|
-
// input too — the ledger's DEBIT side — and it was read by a hand-rolled TAG-LINE SCAN that
|
|
291
|
-
// never consulted a parser. So a malformed tag line simply stopped being a tag line and its
|
|
292
|
-
// scenario CEASED TO EXIST: one stray character deleted a failing row and turned an
|
|
293
|
-
// out-of-balance run (exit 1) into a clean BALANCED (exit 0). A dropped scenario cannot even
|
|
294
|
-
// reconcile `missing`, because it was never RAISED to be missing — the run read cleaner than
|
|
295
|
-
// reality, the exact false-green this tool exists to prevent.
|
|
296
|
-
//
|
|
297
|
-
// Validated with the REAL Gherkin parser (cucumber's own), so a file the tool would reconcile is
|
|
298
|
-
// at least a file cucumber would RUN. A file it rejects is an input we CANNOT READ: exit 2,
|
|
299
|
-
// halting BEFORE any reconcile, naming the file and the parse failure — the same Rule as
|
|
300
|
-
// @SCN-CLI-014 and @SCN-CLI-015 ("an input the tool cannot read is a usage error, never a
|
|
301
|
-
// verdict"), now on the obligation side. Never a verdict, and never a green.
|
|
302
|
-
//
|
|
303
|
-
// The corpus is EXTRACTED from the same real AST (@SCN-LDG-020), so what the tool reconciles is
|
|
304
|
-
// what cucumber runs — Feature/Rule tag inheritance included. This guard decides whether the file
|
|
305
|
-
// can be read at all; parseScenarios then reads it exactly as cucumber would.
|
|
306
|
-
const featureParseErrors = featureCorpusParseErrors(args["features"]);
|
|
307
|
-
if (featureParseErrors.length > 0) {
|
|
308
|
-
for (const { file, message } of featureParseErrors) {
|
|
309
|
-
process.stderr.write(`The --features corpus contains a feature file that could not be parsed: ${file}\n${message}\n`);
|
|
310
|
-
}
|
|
311
|
-
process.exit(2);
|
|
312
|
-
}
|
|
313
|
-
// AMBIGUOUS-CORPUS guard (@SCN-LDG-020's guardrail, 3F-1775). An @SCN identifies exactly ONE
|
|
314
|
-
// scenario — that is the whole basis of attributing evidence to it. Tag inheritance makes a
|
|
315
|
-
// DUPLICATE reachable: an @SCN hoisted to a Feature:/Rule: is inherited by every scenario
|
|
316
|
-
// beneath it (cucumber does this, so we do). One passing test would then mark EVERY scenario
|
|
317
|
-
// sharing that id `balanced` — including scenarios nothing proves — a BALANCED-WHEN-BROKEN run
|
|
318
|
-
// at exit 0. A new silent false-green, introduced by the very fix that closed the last one.
|
|
319
|
-
//
|
|
320
|
-
// So the corpus is REFUSED, not reconciled: the tool cannot know which scenario a citing test
|
|
321
|
-
// proves, and any verdict over it would be a guess. Same Rule as @SCN-CLI-014/015/016 — an input
|
|
322
|
-
// the tool cannot read is a usage error, never a verdict.
|
|
323
|
-
const duplicateScnIds = featureCorpusDuplicateScnIds(args["features"]);
|
|
324
|
-
if (duplicateScnIds.length > 0) {
|
|
325
|
-
process.stderr.write(`The --features corpus names the same @SCN on more than one scenario: ` +
|
|
326
|
-
`${duplicateScnIds.join(", ")}.\n` +
|
|
327
|
-
`An @SCN identifies exactly one scenario — evidence citing a duplicated id cannot be ` +
|
|
328
|
-
`attributed, so no verdict over this corpus would be trustworthy. (An @SCN on a Feature: ` +
|
|
329
|
-
`or Rule: line is inherited by every scenario beneath it — name it on the scenario.)\n`);
|
|
330
|
-
process.exit(2);
|
|
331
|
-
}
|
|
237
|
+
refuseUnreadableInputs(args);
|
|
332
238
|
const inputs = reconcileInputsOf(args);
|
|
333
239
|
// Reconcile the obligation-vs-observation evidence into the Ledger. The runtime evidence-observation
|
|
334
240
|
// views (Test volume, the evidence grid) are FOLDS the renderers derive off this Ledger's posted
|
|
@@ -348,31 +254,7 @@ export function runBalance(argv) {
|
|
|
348
254
|
// — the by-feature cut's full-name labels. The 5th sibling, threaded to the MARKDOWN
|
|
349
255
|
// renderer via writeOutputs only (markdown-only; the by-feature cut isn't on JSON).
|
|
350
256
|
const featureNames = readFeatureNames(args["features"]);
|
|
351
|
-
|
|
352
|
-
// Ledger staying pure — reusing the existing runStart. The target is the
|
|
353
|
-
// operator's --target VERBATIM (unknown-target on omit; Fork A — no
|
|
354
|
-
// resolution, no basename guessing). Source SHA via the read-only target read, with
|
|
355
|
-
// --source-sha as the override (resolveSourceSha).
|
|
356
|
-
const ctx = {
|
|
357
|
-
target: sourceTarget(args),
|
|
358
|
-
inputs,
|
|
359
|
-
runStart,
|
|
360
|
-
sourceSha: resolveSourceSha({
|
|
361
|
-
sourceSha: args["source-sha"],
|
|
362
|
-
targetDir: args["features"] !== undefined ? dirname(args["features"]) : undefined,
|
|
363
|
-
}),
|
|
364
|
-
// The TARGET repo root the recorded input paths are made portable against (fixed to
|
|
365
|
-
// the target root, not the run cwd, by @SCN-RPT-016) — the SAME
|
|
366
|
-
// root readEvidenceObservations passes to countRuntimeEvidenceObservationKinds, derived from
|
|
367
|
-
// --features, so a cross-repo reconcile records inputs relative (`features`) rather
|
|
368
|
-
// than leaking the target's absolute path.
|
|
369
|
-
root: resolveTargetRoot({ features: inputs.features }),
|
|
370
|
-
// The TOOL's own identity (@SCN-RPT-026, 3F-1916) — which spec-controller produced
|
|
371
|
-
// this run, distinct from the target's sourceSha. Read from the tool's OWN dir, never
|
|
372
|
-
// cwd (which is the target). One call, spread into the ctx; the same identity feeds
|
|
373
|
-
// the run.yaml manifest.
|
|
374
|
-
...resolveToolIdentity(),
|
|
375
|
-
};
|
|
257
|
+
const ctx = runContextOf(args, inputs, runStart);
|
|
376
258
|
// Plan the outputs from the --format specs (no flag → md→stdout) and write them via
|
|
377
259
|
// the writer — the pure plan / impure writer split (@SCN-FMT-001). The plan
|
|
378
260
|
// parse+validate is pure; the writer is the only IO for the emitted report. This is
|
|
@@ -380,12 +262,8 @@ export function runBalance(argv) {
|
|
|
380
262
|
// legacy runs/<target>/<ISO>/ auto-archive was removed with @SCN-RUN-001, the
|
|
381
263
|
// caller now routes stored runs (spec-controller's run-management layer).
|
|
382
264
|
const planResult = planOutput(collectFormatSpecs(argv));
|
|
383
|
-
if (!planResult.ok)
|
|
384
|
-
|
|
385
|
-
// Usage/config error (bad --format spec) → exit 2 (@SCN-CLI-002), distinct from the
|
|
386
|
-
// out-of-balance verdict code 1 (@SCN-CLI-004).
|
|
387
|
-
process.exit(2);
|
|
388
|
-
}
|
|
265
|
+
if (!planResult.ok)
|
|
266
|
+
exitUsage(planResult.error);
|
|
389
267
|
writeOutputs(planResult.plan, { balance, ctx, evidenceObligations, withRuntimeObservations: true, withStaticChecks: true, featureNames });
|
|
390
268
|
// The CI gate (@SCN-CLI-004): `balance` is a GATE, not just a reporter. AFTER the report
|
|
391
269
|
// is written in full, map the whole-run verdict to the process exit code. Out-of-balance
|
|
@@ -449,12 +327,126 @@ export function runBalance(argv) {
|
|
|
449
327
|
// credits HAS a row — its suspense row — and is an ordinary out-of-balance report at exit 1
|
|
450
328
|
// (@SCN-CLI-020). @SCN-CLI-004/005/010/012 are BYSTANDERS: every one of their fixtures carries
|
|
451
329
|
// rows, so none reaches this branch.
|
|
452
|
-
const
|
|
330
|
+
const verdict = verdictExitCode(balance.ledger, args["strict"] !== undefined);
|
|
331
|
+
const code = args["exit-zero"] !== undefined ? exitZeroStatus(verdict) : verdict;
|
|
453
332
|
// Assigned only when NON-ZERO, so a balanced run still LEAVES process.exitCode at its default
|
|
454
333
|
// rather than writing a 0 over it — the distinction @SCN-CLI-005 and @SCN-CLI-010 both rest on.
|
|
455
334
|
if (code !== 0)
|
|
456
335
|
process.exitCode = code;
|
|
457
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* A usage or input fault: the message on stderr, then exit 2 — the enumerated usage code
|
|
339
|
+
* (@SCN-CLI-002), distinct from the out-of-balance verdict code 1 (@SCN-CLI-004). An
|
|
340
|
+
* out-of-balance run must never masquerade as a usage error, nor the reverse.
|
|
341
|
+
*/
|
|
342
|
+
function exitUsage(message) {
|
|
343
|
+
process.stderr.write(message + "\n");
|
|
344
|
+
process.exit(2);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Render-from-saved-JSON mode (@SCN-RMD-007): regenerate the human markdown from a
|
|
348
|
+
* banked spec-reconciliation.json ALONE — no reconcile, no live inputs, no RunContext. Reads
|
|
349
|
+
* the file, JSON.parses it back into the whole-document report model, renders the markdown via
|
|
350
|
+
* renderReport, and writes it to stdout (the same trailing-newline convention as the writer's
|
|
351
|
+
* stdout path). The load-bearing proof that the JSON IS the model — true when it answered the
|
|
352
|
+
* run, so `runBalance` returns before any reconcile.
|
|
353
|
+
*/
|
|
354
|
+
function renderSavedReport(args) {
|
|
355
|
+
// Saved-report READABILITY guard (@SCN-CLI-015). This mode RETURNS before
|
|
356
|
+
// `refuseUnreadableInputs` ever runs, so it honoured NEITHER of its guards: a missing path
|
|
357
|
+
// crashed to ENOENT and a malformed file to SyntaxError, both landing on Node's default exit 1
|
|
358
|
+
// — the out-of-balance code. The missing-path case was a live violation of @SCN-CLI-002's own
|
|
359
|
+
// shipped principle, which the CLI enforced for the five evidence flags and not for this
|
|
360
|
+
// one. The guard therefore runs INSIDE this mode, ahead of the read (3F-1764).
|
|
361
|
+
const unreadableSavedReportError = checkRenderFromJson(args, (path) => readFileSync(path, "utf8"));
|
|
362
|
+
if (unreadableSavedReportError)
|
|
363
|
+
exitUsage(unreadableSavedReportError);
|
|
364
|
+
const rehydratePath = args["render-from-json"];
|
|
365
|
+
if (rehydratePath === undefined)
|
|
366
|
+
return false;
|
|
367
|
+
const savedReport = readFileSync(rehydratePath, "utf8");
|
|
368
|
+
process.stdout.write(renderReportFromJson(savedReport) + "\n");
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The live-input guards, in the order they run: each halts at exit 2 BEFORE any reconcile,
|
|
373
|
+
* because an input the tool cannot read is a usage error, never a verdict.
|
|
374
|
+
*/
|
|
375
|
+
function refuseUnreadableInputs(args) {
|
|
376
|
+
// Input-existence guard (@SCN-CLI-002): a supplied input-file/dir flag pointing at a
|
|
377
|
+
// non-existent path is a HARD ERROR — halt BEFORE reconciling, with a typed message
|
|
378
|
+
// naming the flag + path, never the silent zero-evidence all-red report a mistyped
|
|
379
|
+
// path used to produce (the dogfooding fault). Routed to stderr + a non-zero exit,
|
|
380
|
+
// exactly as the legacy-`--json` guard (the shared typed-error surface). An
|
|
381
|
+
// omitted flag is legitimately optional and passes through untouched.
|
|
382
|
+
const missingInputError = checkInputsExist(args, existsSync);
|
|
383
|
+
if (missingInputError)
|
|
384
|
+
exitUsage(missingInputError);
|
|
385
|
+
// Input-READABILITY guard (@SCN-CLI-014): existence is not enough. A report that is
|
|
386
|
+
// PRESENT but UNPARSEABLE (`--vitest /dev/null`, truncated JSON, non-JSON) used to throw
|
|
387
|
+
// mid-parse inside reconcileWithCensus, uncaught — and Node's default exit code is 1, the
|
|
388
|
+
// code reserved for a genuine OUT-OF-BALANCE verdict (@SCN-CLI-004). So a tool that
|
|
389
|
+
// CRASHED before reconciling was indistinguishable, by exit code, from an honest
|
|
390
|
+
// disagreement (3F-1742). Runs immediately after the existence guard and BEFORE any
|
|
391
|
+
// reconcile, routing to the same stderr + exit 2 lane: an input the tool cannot read is a
|
|
392
|
+
// usage fault, sibling to a missing path and an unrecognised flag — never a verdict.
|
|
393
|
+
const unparseableInputError = checkInputsParse(args, (path) => readFileSync(path, "utf8"));
|
|
394
|
+
if (unparseableInputError)
|
|
395
|
+
exitUsage(unparseableInputError);
|
|
396
|
+
// The FEATURE-CORPUS integrity checkpoint (@SCN-CLI-016, 3F-1767). The feature corpus is an
|
|
397
|
+
// input too — the ledger's DEBIT side — and it was read by a hand-rolled TAG-LINE SCAN that
|
|
398
|
+
// never consulted a parser. So a malformed tag line simply stopped being a tag line and its
|
|
399
|
+
// scenario CEASED TO EXIST: one stray character deleted a failing row and turned an
|
|
400
|
+
// out-of-balance run (exit 1) into a clean BALANCED (exit 0). A dropped scenario cannot even
|
|
401
|
+
// reconcile `missing`, because it was never RAISED to be missing — the run read cleaner than
|
|
402
|
+
// reality, the exact false-green this tool exists to prevent.
|
|
403
|
+
//
|
|
404
|
+
// Validated with the REAL Gherkin parser (cucumber's own), so a file the tool would reconcile is
|
|
405
|
+
// at least a file cucumber would RUN. A file it rejects is an input we CANNOT READ: exit 2,
|
|
406
|
+
// halting BEFORE any reconcile, naming the file and the parse failure — the same Rule as
|
|
407
|
+
// @SCN-CLI-014 and @SCN-CLI-015 ("an input the tool cannot read is a usage error, never a
|
|
408
|
+
// verdict"), now on the obligation side. Never a verdict, and never a green.
|
|
409
|
+
//
|
|
410
|
+
// The corpus is EXTRACTED from the same real AST (@SCN-LDG-020), so what the tool reconciles is
|
|
411
|
+
// what cucumber runs — Feature/Rule tag inheritance included. This guard decides whether the file
|
|
412
|
+
// can be read at all; parseScenarios then reads it exactly as cucumber would.
|
|
413
|
+
const featureParseErrors = featureCorpusParseErrors(args["features"]);
|
|
414
|
+
if (featureParseErrors.length > 0) {
|
|
415
|
+
for (const { file, message } of featureParseErrors) {
|
|
416
|
+
process.stderr.write(`The --features corpus contains a feature file that could not be parsed: ${file}\n${message}\n`);
|
|
417
|
+
}
|
|
418
|
+
process.exit(2);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Build the run provenance ONCE (project design §1) — a sibling RunContext, the
|
|
423
|
+
* Ledger staying pure — reusing the existing runStart. The target is the
|
|
424
|
+
* operator's --target VERBATIM (unknown-target on omit; Fork A — no
|
|
425
|
+
* resolution, no basename guessing). Source SHA via the read-only target read, with
|
|
426
|
+
* --source-sha as the override (resolveSourceSha).
|
|
427
|
+
*/
|
|
428
|
+
function runContextOf(args, inputs, runStart) {
|
|
429
|
+
return {
|
|
430
|
+
target: sourceTarget(args),
|
|
431
|
+
inputs,
|
|
432
|
+
runStart,
|
|
433
|
+
sourceSha: resolveSourceSha({
|
|
434
|
+
sourceSha: args["source-sha"],
|
|
435
|
+
targetDir: args["features"] !== undefined ? dirname(args["features"]) : undefined,
|
|
436
|
+
}),
|
|
437
|
+
// The TARGET repo root the recorded input paths are made portable against (fixed to
|
|
438
|
+
// the target root, not the run cwd, by @SCN-RPT-016) — the SAME
|
|
439
|
+
// root readEvidenceObservations passes to countRuntimeEvidenceObservationKinds, derived from
|
|
440
|
+
// --features, so a cross-repo reconcile records inputs relative (`features`) rather
|
|
441
|
+
// than leaking the target's absolute path.
|
|
442
|
+
root: resolveTargetRoot({ features: inputs.features }),
|
|
443
|
+
// The TOOL's own identity (@SCN-RPT-026, 3F-1916) — which spec-controller produced
|
|
444
|
+
// this run, distinct from the target's sourceSha. Read from the tool's OWN dir, never
|
|
445
|
+
// cwd (which is the target). One call, spread into the ctx; the same identity feeds
|
|
446
|
+
// the run.yaml manifest.
|
|
447
|
+
...resolveToolIdentity(),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
458
450
|
/**
|
|
459
451
|
* THE DOMINANCE LADDER — the whole-run verdict as the enumerated status a consumer's CI branches
|
|
460
452
|
* on, and the ONE place the order argued for above is written down. Extracted from `runBalance`
|
|
@@ -475,6 +467,16 @@ function verdictExitCode(ledger, strict) {
|
|
|
475
467
|
return 3;
|
|
476
468
|
return 0;
|
|
477
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* The codes `--exit-zero` moves to 0 (@SCN-CLI-021, 3F-3100): the two VERDICTS on the target —
|
|
472
|
+
* out-of-balance and pending-under-`--strict`. Enumerated rather than "anything non-zero", because
|
|
473
|
+
* unsound (4) and nothing-to-reconcile (5) are not verdicts but the absence of a trustworthy one,
|
|
474
|
+
* and suppressing a verdict never suppresses that. Usage (2) exits before the ladder is reached.
|
|
475
|
+
*/
|
|
476
|
+
const VERDICT_CODES = new Set([1, 3]);
|
|
477
|
+
function exitZeroStatus(code) {
|
|
478
|
+
return VERDICT_CODES.has(code) ? 0 : code;
|
|
479
|
+
}
|
|
478
480
|
// Only run the balance command when this module is executed directly
|
|
479
481
|
// (`tsx cli-balance/cli.ts`), NOT when imported by the top-level `spec-controller`
|
|
480
482
|
// bin dispatcher or by a test that exercises the pure edge guards.
|