rungate 0.8.0 → 0.8.2
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/gates/.gate-salt +1 -0
- package/gates/SCHEMA-GUIDE.md +485 -0
- package/gates/ac-quality.test.ts +106 -0
- package/gates/adversarial.test.ts +283 -0
- package/gates/brief-assembler.test.ts +487 -0
- package/gates/brief-assembler.ts +448 -0
- package/gates/bunfig.toml +2 -0
- package/gates/chain.test.ts +91 -0
- package/gates/e2e-smoke.test.ts +234 -0
- package/gates/error-classifier.test.ts +250 -0
- package/gates/error-classifier.ts +99 -0
- package/gates/gate-executor.ts +3071 -0
- package/gates/orchestrator.test.ts +968 -0
- package/gates/orchestrator.ts +827 -0
- package/gates/preload.ts +89 -0
- package/gates/prompts/ac-adversary.md +20 -0
- package/gates/prompts/evidence-validator.md +22 -0
- package/gates/prompts/prove-reproducer.md +53 -0
- package/gates/prompts.sha256 +3 -0
- package/gates/prove.test.ts +164 -0
- package/gates/rook-state.test.ts +108 -0
- package/gates/run-attribution.ts +290 -0
- package/gates/run-gate.ts +163 -0
- package/gates/schema-parity.test.ts +378 -0
- package/gates/schema.ts +1209 -0
- package/gates/self-heal.test.ts +511 -0
- package/gates/self-heal.ts +125 -0
- package/gates/ship-orchestrator.test.ts +399 -0
- package/gates/ship-orchestrator.ts +384 -0
- package/gates/spec-compliance-probe.ts +159 -0
- package/gates/test-fixtures/broken-no-environments.json +110 -0
- package/gates/test-fixtures/consumer-directory-layout.json +90 -0
- package/gates/test-fixtures/valid-standard.json +91 -0
- package/gates/test-utils.ts +43 -0
- package/gates/typecheck-gate.ts +111 -0
- package/gates/witness.ts +349 -0
- package/gates/workflow.test.ts +2018 -0
- package/hooks/BashWriteGuard.hook.ts +19 -0
- package/hooks/GateResultProtection.hook.ts +27 -1
- package/hooks/VerifyPhaseLock.hook.ts +51 -11
- package/hooks/WorkflowStateGuard.hook.ts +24 -0
- package/lib/ai-review-rounds.ts +462 -0
- package/lib/bash-file-read.ts +17 -3
- package/lib/bash-write-guard.ts +1285 -50
- package/lib/distribution-standing.ts +75 -4
- package/lib/failure-intake.ts +12 -4
- package/lib/file-extensions.ts +81 -0
- package/lib/finding-arbiter.ts +1015 -0
- package/lib/finding-jury.ts +537 -0
- package/lib/gate-enforcement.ts +171 -43
- package/lib/gate-result-protection.ts +12 -2
- package/lib/generators/code-map.ts +55 -4
- package/lib/generators/types.ts +27 -1
- package/lib/github.ts +55 -0
- package/lib/interpreters.ts +64 -0
- package/lib/issue-create-override.ts +69 -8
- package/lib/issue-filing-gate.ts +605 -0
- package/lib/js-top-level-code.ts +20 -2
- package/lib/junit-checks.ts +239 -1
- package/lib/package-closure.ts +114 -0
- package/lib/publish-window.ts +287 -0
- package/lib/scaffold/ai-review-findings.ts +142 -3
- package/lib/scaffold/ai-review-step.ts +1012 -18
- package/lib/scaffold/managed-workflow.ts +163 -4
- package/lib/scaffold/steps.ts +498 -22
- package/lib/scanner.ts +13 -4
- package/lib/ticked-sc-symbols.ts +361 -0
- package/lib/transcript-checker.ts +6 -0
- package/lib/workflow-actions.ts +18 -0
- package/package.json +3 -1
- package/scripts/arbitrate-finding.ts +224 -0
- package/scripts/generate-code-map.ts +18 -10
- package/scripts/sync-sc-status.ts +82 -8
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { test, expect, describe } from "bun:test";
|
|
2
|
+
import { readdirSync, readFileSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
import { THRESHOLD_OPS, EVIDENCE_METHOD_TYPES, SUITE_MEASUREMENT_FIELDS } from "./schema";
|
|
5
|
+
import { parseTestResults } from "./run-gate";
|
|
6
|
+
import { stripJsComments } from "../lib/strip-js-comments";
|
|
7
|
+
|
|
8
|
+
const GATES_DIR = __dirname;
|
|
9
|
+
const V2_SCHEMA_PATH = join(GATES_DIR, "..", "config", "workflow-schema.json");
|
|
10
|
+
const V3_SCHEMA_PATH = join(GATES_DIR, "schema.ts");
|
|
11
|
+
|
|
12
|
+
function extractJsonSchemaPaths(obj: any, prefix = ""): string[] {
|
|
13
|
+
const paths: string[] = [];
|
|
14
|
+
if (!obj || typeof obj !== "object") return paths;
|
|
15
|
+
|
|
16
|
+
if (obj.properties) {
|
|
17
|
+
for (const [key, val] of Object.entries(obj.properties)) {
|
|
18
|
+
const path = prefix ? `${prefix}.${key}` : key;
|
|
19
|
+
paths.push(path);
|
|
20
|
+
if ((val as any).properties) {
|
|
21
|
+
paths.push(...extractJsonSchemaPaths(val, path));
|
|
22
|
+
}
|
|
23
|
+
if ((val as any).items?.properties) {
|
|
24
|
+
paths.push(...extractJsonSchemaPaths((val as any).items, `${path}[]`));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return paths;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function extractZodFields(source: string): string[] {
|
|
32
|
+
const fields: string[] = [];
|
|
33
|
+
const patterns = [
|
|
34
|
+
/(\w+):\s*z\./g,
|
|
35
|
+
/(\w+):\s*(?:Agent|Environment|GateResult|SourceSpec|Threshold|EvidenceMethod|Evidence|ContextFile|Changelog|PhaseTiming)/g,
|
|
36
|
+
];
|
|
37
|
+
for (const p of patterns) {
|
|
38
|
+
for (const m of source.matchAll(p)) {
|
|
39
|
+
fields.push(m[1]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return [...new Set(fields)];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
describe("schema parity: v2 JSON Schema vs v3 Zod", () => {
|
|
46
|
+
const v2 = JSON.parse(readFileSync(V2_SCHEMA_PATH, "utf-8"));
|
|
47
|
+
const v3Source = readFileSync(V3_SCHEMA_PATH, "utf-8");
|
|
48
|
+
|
|
49
|
+
const v2Paths = extractJsonSchemaPaths(v2);
|
|
50
|
+
const v3Fields = extractZodFields(v3Source);
|
|
51
|
+
|
|
52
|
+
const V2_TOP_LEVEL = [
|
|
53
|
+
"schemaVersion", "issue", "repo", "issueRepo", "projectRoot", "slug", "phase",
|
|
54
|
+
"issueGoal", "sourceSpecs", "sizing", "acs", "agents", "environments", "gates",
|
|
55
|
+
"iterationCount", "startTs", "updatedTs", "phaseTimings",
|
|
56
|
+
"gateContract", "changelog",
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
for (const field of V2_TOP_LEVEL) {
|
|
60
|
+
test(`v2 top-level field "${field}" exists in v3 Zod schema`, () => {
|
|
61
|
+
expect(v3Source).toContain(field);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const V2_SIZING = ["predicted", "ceremonyTier", "actualFiles", "actualMinutes"];
|
|
66
|
+
for (const field of V2_SIZING) {
|
|
67
|
+
test(`v2 sizing.${field} exists in v3`, () => {
|
|
68
|
+
expect(v3Source).toContain(field);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const V2_AC_FIELDS = ["id", "type", "statement", "specElement", "threshold", "evidenceMethod", "contextFiles", "evidence", "verdict"];
|
|
73
|
+
for (const field of V2_AC_FIELDS) {
|
|
74
|
+
test(`v2 acs[].${field} exists in v3 ACSchema`, () => {
|
|
75
|
+
expect(v3Source).toContain(field);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const V2_AGENT_FIELDS = ["spawned", "verdict", "branch", "iterations", "comparedToSpec", "screenshots", "findings"];
|
|
80
|
+
for (const field of V2_AGENT_FIELDS) {
|
|
81
|
+
test(`v2 agents.*.${field} exists in v3 AgentSchema`, () => {
|
|
82
|
+
expect(v3Source).toContain(field);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const V2_ENV_LOCAL = ["api", "apiSkipReason", "ui", "uiSkipReason", "tests"];
|
|
87
|
+
for (const field of V2_ENV_LOCAL) {
|
|
88
|
+
test(`v2 environments.local.${field} exists in v3`, () => {
|
|
89
|
+
expect(v3Source).toContain(field);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const V2_ENV_PROD = ["rebuild", "rebuildSkipReason", "smoke", "smokeSkipReason", "quinn", "quinnSkipReason", "quinnSpot", "quinnSpotSkipReason"];
|
|
94
|
+
for (const field of V2_ENV_PROD) {
|
|
95
|
+
test(`v2 environments.prod.${field} exists in v3`, () => {
|
|
96
|
+
expect(v3Source).toContain(field);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const V2_GATE = ["result", "attempt", "failures", "ts"];
|
|
101
|
+
for (const field of V2_GATE) {
|
|
102
|
+
test(`v2 gates.*.${field} exists in v3 GateResultSchema`, () => {
|
|
103
|
+
expect(v3Source).toContain(field);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const V2_EVIDENCE_METHOD_TYPES = ["GREP_CHECK", "FILE_EXISTS", "CURL_CHECK", "BUN_TEST", "SCREENSHOT", "PLAYWRIGHT", "COMMAND", "MANUAL"];
|
|
108
|
+
for (const t of V2_EVIDENCE_METHOD_TYPES) {
|
|
109
|
+
test(`v2 evidenceMethod.type "${t}" in v3 enum`, () => {
|
|
110
|
+
expect(v3Source).toContain(t);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const V2_THRESHOLD_OPS = ["==", ">=", "<=", ">", "<", "!=", "contains", "exists"];
|
|
115
|
+
for (const op of V2_THRESHOLD_OPS) {
|
|
116
|
+
test(`v2 threshold.op "${op}" in v3 enum`, () => {
|
|
117
|
+
expect(v3Source).toContain(`"${op}"`);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
test("v2 phase CIRCUIT_BREAK in v3 enum", () => {
|
|
122
|
+
expect(v3Source).toContain("CIRCUIT_BREAK");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("v2 verdict PENDING in v3 ACSchema", () => {
|
|
126
|
+
expect(v3Source).toContain("PENDING");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
const V2_BASELINES = ["testBaseline", "tscBaseline"];
|
|
130
|
+
for (const field of V2_BASELINES) {
|
|
131
|
+
test(`v2 gateContract.baselines.${field} exists in v3`, () => {
|
|
132
|
+
expect(v3Source).toContain(field);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const V2_CHANGELOG = ["event", "detail", "actor"];
|
|
137
|
+
for (const field of V2_CHANGELOG) {
|
|
138
|
+
test(`v2 changelog[].${field} exists in v3`, () => {
|
|
139
|
+
expect(v3Source).toContain(field);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
test("v2 phaseTimings entry fields in v3", () => {
|
|
144
|
+
expect(v3Source).toContain("enteredTs");
|
|
145
|
+
expect(v3Source).toContain("exitedTs");
|
|
146
|
+
expect(v3Source).toContain("iteration");
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const v3SourceForSuite = readFileSync(V3_SCHEMA_PATH, "utf-8");
|
|
151
|
+
|
|
152
|
+
describe("#224: suiteMeasurement — schema and SCHEMA-GUIDE.md describe the same shape", () => {
|
|
153
|
+
const guide = readFileSync(join(GATES_DIR, "SCHEMA-GUIDE.md"), "utf-8");
|
|
154
|
+
|
|
155
|
+
/** The field names in the guide's `## suiteMeasurement` table. */
|
|
156
|
+
const documented = (() => {
|
|
157
|
+
const start = guide.indexOf("## suiteMeasurement");
|
|
158
|
+
const body = start === -1 ? "" : guide.slice(start, guide.indexOf("\n## ", start + 1));
|
|
159
|
+
return body
|
|
160
|
+
.split("\n")
|
|
161
|
+
.filter(line => /^\|\s*`/.test(line))
|
|
162
|
+
.map(line => line.match(/^\|\s*`([^`]+)`/)![1]);
|
|
163
|
+
})();
|
|
164
|
+
|
|
165
|
+
test("the guide has a suiteMeasurement section with a field table", () => {
|
|
166
|
+
expect(guide).toContain("## suiteMeasurement");
|
|
167
|
+
expect(documented.length, "no `field` rows found under ## suiteMeasurement").toBeGreaterThan(0);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Both directions. A field added to the Zod schema and left undocumented
|
|
171
|
+
// turns the first list red; a field documented but never implemented turns
|
|
172
|
+
// the second red. One direction alone is a check that passes because of
|
|
173
|
+
// what it never looked at.
|
|
174
|
+
test("every schema field is documented", () => {
|
|
175
|
+
expect([...SUITE_MEASUREMENT_FIELDS].sort()).toEqual([...documented].sort());
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("the guide states the rule the schema enforces: absent means UNMEASURED", () => {
|
|
179
|
+
expect(guide).toContain("UNMEASURED");
|
|
180
|
+
expect(guide).toMatch(/measuredSha/);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("the v3 Zod schema carries the measurement on the workflow state", () => {
|
|
184
|
+
expect(v3SourceForSuite).toContain("suiteMeasurement: SuiteMeasurementSchema");
|
|
185
|
+
// UNMEASURED is the reader's answer to an absent record, not a writable
|
|
186
|
+
// verdict — a schema that accepted it would give a caller a way to park an
|
|
187
|
+
// unmeasured run in the field that proves the suite ran.
|
|
188
|
+
// PARTIAL joined it in #673 and is not a third result: it says the
|
|
189
|
+
// reading was taken over less than the suite, and readSuiteMeasurement
|
|
190
|
+
// turns it into UNMEASURED for every consumer.
|
|
191
|
+
expect(v3SourceForSuite).toContain('verdict: z.enum(["PASS", "FAIL", "PARTIAL"])');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("GI-1: gate failure detail includes Zod error paths", () => {
|
|
196
|
+
// Fixture corrected 2026-10-11 (#314). It previously placed the Zod errors
|
|
197
|
+
// AFTER the `(fail)` line, which is not how bun prints: the source excerpt,
|
|
198
|
+
// error and stack all precede their own marker. Probed against bun 1.3.14.
|
|
199
|
+
// The test's intent is unchanged and still the point — the detail must carry
|
|
200
|
+
// the Zod path, not the literal string "failed". Only the ordering was wrong,
|
|
201
|
+
// and it was wrong in the same direction as the parser it was testing, so the
|
|
202
|
+
// two agreed with each other and not with bun.
|
|
203
|
+
test("parseTestResults captures a failure's own Zod error paths as its detail", () => {
|
|
204
|
+
const bunOutput = [
|
|
205
|
+
"(pass) schema validation > acs-exist: at least one AC",
|
|
206
|
+
" acs.0.threshold.op: Invalid enum value. Expected '==' | '>=' | '<=' | '>' | '<' | '!=' | 'contains' | 'exists', received 'equals'",
|
|
207
|
+
" acs.1.statement: AC-2: statement too short (3 words, min 5)",
|
|
208
|
+
"(fail) schema validation > workflow-state.json validates (includes threshold + behavioral superRefine)",
|
|
209
|
+
"(pass) scope checks > sizing-declared",
|
|
210
|
+
].join("\n");
|
|
211
|
+
const results = parseTestResults(bunOutput);
|
|
212
|
+
const fail = results.find(r => r.result === "FAIL");
|
|
213
|
+
expect(fail).toBeTruthy();
|
|
214
|
+
expect(fail!.detail).toContain("Invalid enum value");
|
|
215
|
+
expect(fail!.detail).toContain("acs.0.threshold.op");
|
|
216
|
+
expect(fail!.detail).not.toBe("failed");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("SC-1860: a failure the parser cannot explain says so, and names the parser", () => {
|
|
220
|
+
// Revised from "falls back to 'failed'" (#550). That case documented the
|
|
221
|
+
// fallback as acceptable, and it is not: `detail: "failed"` is a refusal
|
|
222
|
+
// with no reason, in the field a heal prompt reads. It also reads like
|
|
223
|
+
// data the runner produced rather than like the parser giving up, which
|
|
224
|
+
// is the distinction that sent #530's first pass to the wrong file.
|
|
225
|
+
//
|
|
226
|
+
// The behaviour is unchanged — the parser still has nothing to say here.
|
|
227
|
+
// What changed is that it says which component had nothing to say.
|
|
228
|
+
const bunOutput = [
|
|
229
|
+
"(fail) some-check",
|
|
230
|
+
"(pass) another-check",
|
|
231
|
+
].join("\n");
|
|
232
|
+
const results = parseTestResults(bunOutput);
|
|
233
|
+
const fail = results.find(r => r.result === "FAIL");
|
|
234
|
+
expect(fail!.detail, "a bare 'failed' is a refusal with no reason").not.toBe("failed");
|
|
235
|
+
expect(fail!.detail).toContain("parseTestResults");
|
|
236
|
+
// Named so a reader goes to the parser rather than to the check.
|
|
237
|
+
expect(fail!.detail).toContain("no explanation");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// ── #550: bun prints a timeout's reason AFTER its marker ──────────────────
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Covers SC-1858, SC-1859 (HARNESS-STANDARD.md), #550.
|
|
245
|
+
*
|
|
246
|
+
* Every other failure bun prints puts its excerpt, error and stack BEFORE the
|
|
247
|
+
* `(fail)` line, which is why #314 made the detail scan backward. A TIMEOUT
|
|
248
|
+
* is the exception: the marker comes first and the explanation follows it. So
|
|
249
|
+
* the backward scan from the NEXT failure walks straight over it, and the
|
|
250
|
+
* timed-out test is left with nothing.
|
|
251
|
+
*
|
|
252
|
+
* Observed on `/Users/jhorn/.rungate/.../workflow-state.json`: `tsc-pass`
|
|
253
|
+
* recorded `detail: "failed"` while the following check's detail OPENED with
|
|
254
|
+
* `^ this test timed out after 5000ms.` — a diagnosis of a different check,
|
|
255
|
+
* which is how it was first read.
|
|
256
|
+
*/
|
|
257
|
+
describe("#550: a timed-out failure keeps its own explanation", () => {
|
|
258
|
+
// CAPTURED, not imagined. Run on bun 1.3.14 over a file with one test given
|
|
259
|
+
// a 300ms budget and a 2000ms body, followed by an ordinary failure. The
|
|
260
|
+
// literal below is that run's output with the temp paths shortened; the
|
|
261
|
+
// ORDER — marker, timeout line, then the next failure's excerpt — is the
|
|
262
|
+
// whole subject and is reproduced exactly.
|
|
263
|
+
const CAPTURED = [
|
|
264
|
+
"bun test v1.3.14 (d1632b29)",
|
|
265
|
+
"",
|
|
266
|
+
"x.test.ts:",
|
|
267
|
+
"(fail) a slow one [302.03ms]",
|
|
268
|
+
" ^ this test timed out after 300ms.",
|
|
269
|
+
'1 | import { test, expect } from "bun:test";',
|
|
270
|
+
'2 | test("a slow one", async () => { await new Promise(r => setTimeout(r, 2000)); }, 300);',
|
|
271
|
+
'3 | test("an ordinary failure", () => { expect(1).toBe(2); });',
|
|
272
|
+
" ^",
|
|
273
|
+
"error: expect(received).toBe(expected)",
|
|
274
|
+
"",
|
|
275
|
+
"Expected: 2",
|
|
276
|
+
"Received: 1",
|
|
277
|
+
"",
|
|
278
|
+
" at <anonymous> (/tmp/x.test.ts:3:47)",
|
|
279
|
+
"(fail) an ordinary failure [0.47ms]",
|
|
280
|
+
].join("\n");
|
|
281
|
+
|
|
282
|
+
test("SC-1858: the timed-out test's detail is its own timeout line", () => {
|
|
283
|
+
const results = parseTestResults(CAPTURED);
|
|
284
|
+
const timedOut = results.find(r => r.check === "a slow one");
|
|
285
|
+
expect(timedOut, "the timed-out failure was not parsed at all").toBeTruthy();
|
|
286
|
+
expect(timedOut!.result).toBe("FAIL");
|
|
287
|
+
expect(timedOut!.detail, "the timed-out check still records a refusal with no reason")
|
|
288
|
+
.toContain("timed out after 300ms");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("SC-1859: the following failure does not acquire it", () => {
|
|
292
|
+
// The half that cost the time. A detail opening with another check's
|
|
293
|
+
// timeout reads like a diagnosis of this one.
|
|
294
|
+
const results = parseTestResults(CAPTURED);
|
|
295
|
+
const next = results.find(r => r.check === "an ordinary failure");
|
|
296
|
+
expect(next, "the following failure was not parsed").toBeTruthy();
|
|
297
|
+
expect(next!.detail, "the next failure inherited the previous one's timeout line")
|
|
298
|
+
.not.toContain("timed out after");
|
|
299
|
+
// And it keeps its own, so the fix is a reattribution rather than a
|
|
300
|
+
// deletion — without this a parser that dropped every timeout line
|
|
301
|
+
// satisfies the assertion above.
|
|
302
|
+
expect(next!.detail).toContain("expect(received).toBe(expected)");
|
|
303
|
+
expect(next!.detail).toContain("Expected: 2");
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("SC-1863: no other producer assigns a bare failed as a detail", () => {
|
|
307
|
+
// SC-1860 is about the one producer this repo has today. This is the
|
|
308
|
+
// reintroduction guard: a second place writing `detail: "failed"` would
|
|
309
|
+
// put a reasonless refusal back in the state file while SC-1860 stayed
|
|
310
|
+
// green, because SC-1860 only ever drives `parseTestResults`.
|
|
311
|
+
//
|
|
312
|
+
// Comments are stripped first — this file and gate-executor.ts both
|
|
313
|
+
// DISCUSS the old string on purpose, and a comment reciting what was
|
|
314
|
+
// removed is not evidence it is still there.
|
|
315
|
+
// THIS FILE is the one exclusion, and it is not an exemption list: the
|
|
316
|
+
// instrument below has to quote the forbidden string to prove the
|
|
317
|
+
// pattern still matches, and on the first run the check caught itself
|
|
318
|
+
// doing so. The exclusion is one named file — the scanner — rather than
|
|
319
|
+
// a list anybody can add to, and `workflow.test.ts` and every other
|
|
320
|
+
// file in gates/ stay in scope.
|
|
321
|
+
const SELF = "schema-parity.test.ts";
|
|
322
|
+
const offenders: string[] = [];
|
|
323
|
+
for (const name of readdirSync(GATES_DIR).filter(f => f.endsWith(".ts") && f !== SELF)) {
|
|
324
|
+
const code = stripJsComments(readFileSync(join(GATES_DIR, name), "utf-8"));
|
|
325
|
+
code.split("\n").forEach((line, i) => {
|
|
326
|
+
if (/\bdetail:\s*["'`]failed["'`]/.test(line)) offenders.push(`${name}:${i + 1}: ${line.trim()}`);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
expect(offenders, `a reasonless refusal detail is back:\n${offenders.join("\n")}`).toEqual([]);
|
|
330
|
+
|
|
331
|
+
// The instrument, twice over: the pattern matches when the string is
|
|
332
|
+
// there, and the scan really did read the files rather than skipping
|
|
333
|
+
// them all.
|
|
334
|
+
expect(/\bdetail:\s*["'`]failed["'`]/.test(' results.push({ detail: "failed" })')).toBe(true);
|
|
335
|
+
expect(
|
|
336
|
+
readdirSync(GATES_DIR).filter(f => f.endsWith(".ts") && f !== SELF).length,
|
|
337
|
+
"the scan found no files to read",
|
|
338
|
+
).toBeGreaterThan(3);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
test("SC-1861: an ordinary failure's backward scan is unchanged", () => {
|
|
342
|
+
// The control for the control. The timeout line is a new stopping
|
|
343
|
+
// condition in the backward scan, and a stopping condition that fires too
|
|
344
|
+
// eagerly truncates every ordinary detail — which would be invisible,
|
|
345
|
+
// because a shorter detail is still a detail.
|
|
346
|
+
const ordinary = [
|
|
347
|
+
"(pass) first-check",
|
|
348
|
+
" acs.0.threshold.op: Invalid enum value",
|
|
349
|
+
" acs.1.statement: AC-2: statement too short",
|
|
350
|
+
"(fail) second-check",
|
|
351
|
+
].join("\n");
|
|
352
|
+
const fail = parseTestResults(ordinary).find(r => r.result === "FAIL");
|
|
353
|
+
expect(fail!.detail).toContain("Invalid enum value");
|
|
354
|
+
expect(fail!.detail).toContain("statement too short");
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe("GI-5: DISCOVERY_SCHEMA enum parity with schema.ts", () => {
|
|
359
|
+
const shipSource = readFileSync(join(GATES_DIR, "..", "workflows", "ship.js"), "utf-8");
|
|
360
|
+
|
|
361
|
+
test("DISCOVERY_SCHEMA threshold.op has enum matching THRESHOLD_OPS", () => {
|
|
362
|
+
const opEnumMatch = shipSource.match(/op:\s*\{\s*type:\s*'string'\s*,\s*enum:\s*\[([^\]]+)\]/);
|
|
363
|
+
expect(opEnumMatch, "threshold.op must have enum constraint in DISCOVERY_SCHEMA").toBeTruthy();
|
|
364
|
+
const ops = opEnumMatch![1].split(",").map(s => s.trim().replace(/'/g, ""));
|
|
365
|
+
expect(ops.sort()).toEqual([...THRESHOLD_OPS].sort());
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test("DISCOVERY_SCHEMA evidenceMethod.type has enum matching EVIDENCE_METHOD_TYPES", () => {
|
|
369
|
+
const discoveryBlock = shipSource.slice(
|
|
370
|
+
shipSource.indexOf("const DISCOVERY_SCHEMA"),
|
|
371
|
+
shipSource.indexOf("const DISCOVERY_SCHEMA") + 3000
|
|
372
|
+
);
|
|
373
|
+
const evidenceMethodMatch = discoveryBlock.match(/evidenceMethod:\s*\{[^}]*properties:\s*\{[^}]*type:\s*\{\s*type:\s*'string'\s*,\s*enum:\s*\[([^\]]+)\]/s);
|
|
374
|
+
expect(evidenceMethodMatch, "evidenceMethod.type must have enum constraint in DISCOVERY_SCHEMA").toBeTruthy();
|
|
375
|
+
const types = evidenceMethodMatch![1].split(",").map(s => s.trim().replace(/'/g, ""));
|
|
376
|
+
expect(types.sort()).toEqual([...EVIDENCE_METHOD_TYPES].sort());
|
|
377
|
+
});
|
|
378
|
+
});
|