@gate-forge/cli 0.7.1 → 0.9.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.
- package/README.md +91 -704
- package/dist/adapter-audit.d.ts +208 -0
- package/dist/adapter-audit.d.ts.map +1 -0
- package/dist/adapter-audit.js +579 -0
- package/dist/adapter-audit.js.map +1 -0
- package/dist/adapter-scaffold.d.ts +91 -0
- package/dist/adapter-scaffold.d.ts.map +1 -0
- package/dist/adapter-scaffold.js +474 -0
- package/dist/adapter-scaffold.js.map +1 -0
- package/dist/adopted-baseline.d.ts +10 -0
- package/dist/adopted-baseline.d.ts.map +1 -1
- package/dist/adopted-baseline.js +18 -1
- package/dist/adopted-baseline.js.map +1 -1
- package/dist/args.d.ts +15 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +61 -2
- package/dist/args.js.map +1 -1
- package/dist/behavior-setup.d.ts +239 -0
- package/dist/behavior-setup.d.ts.map +1 -0
- package/dist/behavior-setup.js +751 -0
- package/dist/behavior-setup.js.map +1 -0
- package/dist/broker.d.ts.map +1 -1
- package/dist/broker.js +28 -2
- package/dist/broker.js.map +1 -1
- package/dist/cache-exclusions.d.ts +45 -0
- package/dist/cache-exclusions.d.ts.map +1 -0
- package/dist/cache-exclusions.js +205 -0
- package/dist/cache-exclusions.js.map +1 -0
- package/dist/candidate-tree.d.ts +86 -14
- package/dist/candidate-tree.d.ts.map +1 -1
- package/dist/candidate-tree.js +236 -62
- package/dist/candidate-tree.js.map +1 -1
- package/dist/ci-witnessed-template.d.ts +43 -0
- package/dist/ci-witnessed-template.d.ts.map +1 -0
- package/dist/ci-witnessed-template.js +283 -0
- package/dist/ci-witnessed-template.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +31 -4
- package/dist/cli.js.map +1 -1
- package/dist/commands/adapters.d.ts +15 -0
- package/dist/commands/adapters.d.ts.map +1 -0
- package/dist/commands/adapters.js +355 -0
- package/dist/commands/adapters.js.map +1 -0
- package/dist/commands/adopt.d.ts +7 -0
- package/dist/commands/adopt.d.ts.map +1 -1
- package/dist/commands/adopt.js +44 -2
- package/dist/commands/adopt.js.map +1 -1
- package/dist/commands/baseline.d.ts.map +1 -1
- package/dist/commands/baseline.js +42 -1
- package/dist/commands/baseline.js.map +1 -1
- package/dist/commands/blocking.d.ts +105 -2
- package/dist/commands/blocking.d.ts.map +1 -1
- package/dist/commands/blocking.js +395 -53
- package/dist/commands/blocking.js.map +1 -1
- package/dist/commands/check.d.ts +36 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +1068 -64
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/classify.d.ts +2 -1
- package/dist/commands/classify.d.ts.map +1 -1
- package/dist/commands/classify.js +188 -5
- package/dist/commands/classify.js.map +1 -1
- package/dist/commands/enforce.d.ts +4 -4
- package/dist/commands/enforce.d.ts.map +1 -1
- package/dist/commands/enforce.js +41 -9
- package/dist/commands/enforce.js.map +1 -1
- package/dist/commands/enforcement.d.ts +13 -1
- package/dist/commands/enforcement.d.ts.map +1 -1
- package/dist/commands/enforcement.js +880 -33
- package/dist/commands/enforcement.js.map +1 -1
- package/dist/commands/explain.d.ts +1 -1
- package/dist/commands/explain.d.ts.map +1 -1
- package/dist/commands/explain.js +162 -3
- package/dist/commands/explain.js.map +1 -1
- package/dist/commands/history.d.ts +12 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +45 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/init-presets.d.ts +155 -0
- package/dist/commands/init-presets.d.ts.map +1 -0
- package/dist/commands/init-presets.js +203 -0
- package/dist/commands/init-presets.js.map +1 -0
- package/dist/commands/init.d.ts +7 -12
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +987 -99
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +29 -13
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +846 -19
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/pre-commit.d.ts +25 -0
- package/dist/commands/pre-commit.d.ts.map +1 -1
- package/dist/commands/pre-commit.js +91 -6
- package/dist/commands/pre-commit.js.map +1 -1
- package/dist/commands/quarantine.d.ts +16 -0
- package/dist/commands/quarantine.d.ts.map +1 -0
- package/dist/commands/quarantine.js +213 -0
- package/dist/commands/quarantine.js.map +1 -0
- package/dist/commands/run.d.ts +39 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +196 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/commands/test-gates.d.ts +284 -2
- package/dist/commands/test-gates.d.ts.map +1 -1
- package/dist/commands/test-gates.js +3620 -187
- package/dist/commands/test-gates.js.map +1 -1
- package/dist/commands/tests.d.ts +1 -1
- package/dist/commands/tests.d.ts.map +1 -1
- package/dist/commands/tests.js +264 -29
- package/dist/commands/tests.js.map +1 -1
- package/dist/docs-exclusions.d.ts.map +1 -1
- package/dist/docs-exclusions.js +18 -3
- package/dist/docs-exclusions.js.map +1 -1
- package/dist/endpoint-compiler.d.ts.map +1 -1
- package/dist/endpoint-compiler.js +78 -9
- package/dist/endpoint-compiler.js.map +1 -1
- package/dist/engine-browser.d.ts +183 -0
- package/dist/engine-browser.d.ts.map +1 -0
- package/dist/engine-browser.js +381 -0
- package/dist/engine-browser.js.map +1 -0
- package/dist/engine-identity.d.ts +100 -0
- package/dist/engine-identity.d.ts.map +1 -0
- package/dist/engine-identity.js +182 -0
- package/dist/engine-identity.js.map +1 -0
- package/dist/evaluate.d.ts +105 -1
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +149 -18
- package/dist/evaluate.js.map +1 -1
- package/dist/execution.d.ts +253 -9
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +309 -12
- package/dist/execution.js.map +1 -1
- package/dist/gateforge-owned.d.ts +78 -0
- package/dist/gateforge-owned.d.ts.map +1 -0
- package/dist/gateforge-owned.js +254 -0
- package/dist/gateforge-owned.js.map +1 -0
- package/dist/git-hooks.d.ts +35 -0
- package/dist/git-hooks.d.ts.map +1 -1
- package/dist/git-hooks.js +140 -1
- package/dist/git-hooks.js.map +1 -1
- package/dist/git-ignored.d.ts +27 -0
- package/dist/git-ignored.d.ts.map +1 -0
- package/dist/git-ignored.js +102 -0
- package/dist/git-ignored.js.map +1 -0
- package/dist/git-objects.d.ts +60 -0
- package/dist/git-objects.d.ts.map +1 -0
- package/dist/git-objects.js +152 -0
- package/dist/git-objects.js.map +1 -0
- package/dist/glob.d.ts +33 -14
- package/dist/glob.d.ts.map +1 -1
- package/dist/glob.js +96 -5
- package/dist/glob.js.map +1 -1
- package/dist/history.d.ts +52 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +116 -0
- package/dist/history.js.map +1 -0
- package/dist/host-load.d.ts +49 -0
- package/dist/host-load.d.ts.map +1 -0
- package/dist/host-load.js +78 -0
- package/dist/host-load.js.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/input-snapshot.d.ts +63 -9
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +195 -17
- package/dist/input-snapshot.js.map +1 -1
- package/dist/io.d.ts +49 -0
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +22 -0
- package/dist/io.js.map +1 -1
- package/dist/mapping.d.ts +84 -1
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +276 -5
- package/dist/mapping.js.map +1 -1
- package/dist/native-freeze.d.ts +217 -0
- package/dist/native-freeze.d.ts.map +1 -0
- package/dist/native-freeze.js +332 -0
- package/dist/native-freeze.js.map +1 -0
- package/dist/pipeline.d.ts +67 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +164 -6
- package/dist/pipeline.js.map +1 -1
- package/dist/planes-inference.d.ts +12 -5
- package/dist/planes-inference.d.ts.map +1 -1
- package/dist/planes-inference.js +13 -15
- package/dist/planes-inference.js.map +1 -1
- package/dist/playwright-browsers.d.ts +210 -0
- package/dist/playwright-browsers.d.ts.map +1 -0
- package/dist/playwright-browsers.js +364 -0
- package/dist/playwright-browsers.js.map +1 -0
- package/dist/plugins.d.ts +15 -5
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +59 -9
- package/dist/plugins.js.map +1 -1
- package/dist/progress.d.ts +148 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +263 -0
- package/dist/progress.js.map +1 -0
- package/dist/providers.d.ts +26 -1
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +39 -0
- package/dist/providers.js.map +1 -1
- package/dist/receipts.d.ts +1 -0
- package/dist/receipts.d.ts.map +1 -1
- package/dist/receipts.js +35 -7
- package/dist/receipts.js.map +1 -1
- package/dist/repo-scan.d.ts +15 -1
- package/dist/repo-scan.d.ts.map +1 -1
- package/dist/repo-scan.js +329 -34
- package/dist/repo-scan.js.map +1 -1
- package/dist/reseal-chain.d.ts +184 -0
- package/dist/reseal-chain.d.ts.map +1 -0
- package/dist/reseal-chain.js +735 -0
- package/dist/reseal-chain.js.map +1 -0
- package/dist/reseal-evidence.d.ts +241 -0
- package/dist/reseal-evidence.d.ts.map +1 -0
- package/dist/reseal-evidence.js +319 -0
- package/dist/reseal-evidence.js.map +1 -0
- package/dist/reseal.d.ts +181 -0
- package/dist/reseal.d.ts.map +1 -0
- package/dist/reseal.js +1620 -0
- package/dist/reseal.js.map +1 -0
- package/dist/response-field-guidance.d.ts +82 -0
- package/dist/response-field-guidance.d.ts.map +1 -0
- package/dist/response-field-guidance.js +184 -0
- package/dist/response-field-guidance.js.map +1 -0
- package/dist/route-plane-proposals.d.ts +100 -0
- package/dist/route-plane-proposals.d.ts.map +1 -0
- package/dist/route-plane-proposals.js +213 -0
- package/dist/route-plane-proposals.js.map +1 -0
- package/dist/run-cache.d.ts +260 -0
- package/dist/run-cache.d.ts.map +1 -0
- package/dist/run-cache.js +771 -0
- package/dist/run-cache.js.map +1 -0
- package/dist/run-preflight.d.ts +77 -0
- package/dist/run-preflight.d.ts.map +1 -0
- package/dist/run-preflight.js +774 -0
- package/dist/run-preflight.js.map +1 -0
- package/dist/run-recipe.d.ts +107 -0
- package/dist/run-recipe.d.ts.map +1 -0
- package/dist/run-recipe.js +295 -0
- package/dist/run-recipe.js.map +1 -0
- package/dist/run-reliability.d.ts +126 -0
- package/dist/run-reliability.d.ts.map +1 -0
- package/dist/run-reliability.js +221 -0
- package/dist/run-reliability.js.map +1 -0
- package/dist/runtime.d.ts +15 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +11 -1
- package/dist/runtime.js.map +1 -1
- package/dist/scope.d.ts +20 -0
- package/dist/scope.d.ts.map +1 -1
- package/dist/scope.js +26 -5
- package/dist/scope.js.map +1 -1
- package/dist/secret-guard.d.ts +36 -0
- package/dist/secret-guard.d.ts.map +1 -0
- package/dist/secret-guard.js +63 -0
- package/dist/secret-guard.js.map +1 -0
- package/dist/singleton-guidance.d.ts +82 -0
- package/dist/singleton-guidance.d.ts.map +1 -0
- package/dist/singleton-guidance.js +138 -0
- package/dist/singleton-guidance.js.map +1 -0
- package/dist/staged-candidate.d.ts +17 -0
- package/dist/staged-candidate.d.ts.map +1 -1
- package/dist/staged-candidate.js +50 -0
- package/dist/staged-candidate.js.map +1 -1
- package/dist/state-artifacts.d.ts +70 -0
- package/dist/state-artifacts.d.ts.map +1 -0
- package/dist/state-artifacts.js +215 -0
- package/dist/state-artifacts.js.map +1 -0
- package/dist/state.d.ts +170 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +248 -8
- package/dist/state.js.map +1 -1
- package/dist/unmatched-routes.d.ts +60 -0
- package/dist/unmatched-routes.d.ts.map +1 -0
- package/dist/unmatched-routes.js +131 -0
- package/dist/unmatched-routes.js.map +1 -0
- package/dist/verifier-keys.d.ts +33 -2
- package/dist/verifier-keys.d.ts.map +1 -1
- package/dist/verifier-keys.js +95 -9
- package/dist/verifier-keys.js.map +1 -1
- package/guides/CONNECT-YOUR-PROJECT.md +425 -0
- package/guides/QUICKSTART.md +306 -26
- package/guides/REFERENCE.md +1710 -0
- package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
- package/guides/TEST-ENVIRONMENT.md +1044 -6
- package/guides/UPGRADE-0.6-to-0.7.md +3 -3
- package/guides/UPGRADE-0.7-to-0.8.md +114 -0
- package/guides/UPGRADE-0.8-to-0.9.md +104 -0
- package/package.json +10 -9
package/dist/commands/check.js
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
+
/** No `ui.action` anchor to pair with: the observe channel's record is its own anchor. */
|
|
2
|
+
const OBSERVE_ANCHORS = [null];
|
|
3
|
+
/**
|
|
4
|
+
* The two adapter advisories a run reports, neither of which blocks:
|
|
5
|
+
*
|
|
6
|
+
* - ADAPTER_CANNOT_WITNESS: a create obligation whose adapter can
|
|
7
|
+
* neither list the collection nor bind a natural key. The engine
|
|
8
|
+
* cannot prove such a create — a row that is absent from a partial
|
|
9
|
+
* or missing list proves nothing (E4). A finding, not a new blocking
|
|
10
|
+
* default: the obligation still fails on its own evidence.
|
|
11
|
+
* - ADAPTER_VOLATILE_FIELD_SKIPPED: the exact-value echo skipped a
|
|
12
|
+
* field the adapter DECLARES server-computed (E18a). Either evidence
|
|
13
|
+
* channel qualifies: the browser channel's `ui.action` entered input,
|
|
14
|
+
* or the observe channel's witness-observed request fields (a
|
|
15
|
+
* `persistence.observed` record has no `ui.action` anchor). Only keys
|
|
16
|
+
* the journey actually sent are reported. The owner must see every
|
|
17
|
+
* skip, so it is reported rather than silently honoured.
|
|
18
|
+
*
|
|
19
|
+
* Args:
|
|
20
|
+
* cwd: repo root (the adapters directory lives under it).
|
|
21
|
+
* pipeline: the completed pipeline run.
|
|
22
|
+
* verdicts: the evaluated verdicts (for the volatile skips).
|
|
23
|
+
* stateDir: run-state directory holding the sealed records.
|
|
24
|
+
*
|
|
25
|
+
* Returns:
|
|
26
|
+
* Promise<BlockingEntry[]>: non-blocking report entries, sorted.
|
|
27
|
+
*/
|
|
28
|
+
async function adapterAdvisories(cwd, pipeline, verdicts, stateDir) {
|
|
29
|
+
const entries = [];
|
|
30
|
+
const adaptersDir = join(cwd, '.gateforge/adapters');
|
|
31
|
+
const reports = await auditAdapters(adaptersDir);
|
|
32
|
+
const byName = new Map(reports.map((report) => [report.name, report]));
|
|
33
|
+
for (const verdict of verdicts) {
|
|
34
|
+
if (verdict.verdict === 'satisfied')
|
|
35
|
+
continue;
|
|
36
|
+
if (verdict.obligation.contract !== 'persistence:create')
|
|
37
|
+
continue;
|
|
38
|
+
const resourceId = verdict.obligation.resourceId;
|
|
39
|
+
const report = byName.get(resourceId);
|
|
40
|
+
if (report === undefined || !report.ok)
|
|
41
|
+
continue;
|
|
42
|
+
if (report.declares.list || report.declares.naturalKey)
|
|
43
|
+
continue;
|
|
44
|
+
if (verdict.reason !== null && !verdict.reason.includes('no witnessed'))
|
|
45
|
+
continue;
|
|
46
|
+
entries.push({
|
|
47
|
+
kind: 'finding',
|
|
48
|
+
resourceId,
|
|
49
|
+
name: null,
|
|
50
|
+
detail: `create for '${resourceId}' cannot be witnessed by adapter '${report.name}': it can neither ` +
|
|
51
|
+
'list the collection nor bind a natural key, so a created row could never be shown to have ' +
|
|
52
|
+
'been absent before and present after (a partial list proves nothing)',
|
|
53
|
+
location: null,
|
|
54
|
+
cause: 'ADAPTER_CANNOT_WITNESS',
|
|
55
|
+
nextAction: CAUSE_NEXT_ACTIONS.ADAPTER_CANNOT_WITNESS,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// The run's own witnessed records, as sealed: a declared skip is read
|
|
59
|
+
// from the evidence itself, never from a suite-declared expectation.
|
|
60
|
+
const byId = new Map();
|
|
61
|
+
try {
|
|
62
|
+
const raw = JSON.parse(readFileSync(join(stateDir, 'records.json'), 'utf8'));
|
|
63
|
+
if (Array.isArray(raw)) {
|
|
64
|
+
for (const record of raw) {
|
|
65
|
+
if (typeof record !== 'object' || record === null)
|
|
66
|
+
continue;
|
|
67
|
+
const id = record.recordId;
|
|
68
|
+
if (typeof id === 'string')
|
|
69
|
+
byId.set(id, record);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// No sealed records (a static run): nothing to report a skip about.
|
|
75
|
+
}
|
|
76
|
+
for (const verdict of verdicts) {
|
|
77
|
+
if (verdict.verdict !== 'satisfied')
|
|
78
|
+
continue;
|
|
79
|
+
const used = verdict.recordIds.map((id) => byId.get(id) ?? null);
|
|
80
|
+
const actions = used.filter((record) => record !== null && record['kind'] === 'ui.action');
|
|
81
|
+
const skipped = [];
|
|
82
|
+
for (const record of used) {
|
|
83
|
+
if (record === null)
|
|
84
|
+
continue;
|
|
85
|
+
// The browser channel declares the entered values on its ui.action
|
|
86
|
+
// anchor; an observe persistence record has no anchor and carries
|
|
87
|
+
// the witness-observed request fields itself.
|
|
88
|
+
const anchors = actions.length > 0 ? actions : OBSERVE_ANCHORS;
|
|
89
|
+
for (const anchor of anchors) {
|
|
90
|
+
for (const skip of volatileEchoSkips(anchor, record)) {
|
|
91
|
+
if (!skipped.includes(skip.field))
|
|
92
|
+
skipped.push(skip.field);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (skipped.length === 0)
|
|
97
|
+
continue;
|
|
98
|
+
entries.push({
|
|
99
|
+
kind: 'finding',
|
|
100
|
+
resourceId: verdict.obligation.resourceId,
|
|
101
|
+
name: null,
|
|
102
|
+
detail: `the exact-value echo skipped ${skipped.length} field(s) the adapter declares ` +
|
|
103
|
+
`server-computed: ${skipped.sort().join(', ')} — the entered values were not compared with the ` +
|
|
104
|
+
'persisted state, and the engine-observed values are what the app stored',
|
|
105
|
+
location: null,
|
|
106
|
+
cause: 'ADAPTER_VOLATILE_FIELD_SKIPPED',
|
|
107
|
+
nextAction: CAUSE_NEXT_ACTIONS.ADAPTER_VOLATILE_FIELD_SKIPPED,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return entries;
|
|
111
|
+
}
|
|
1
112
|
/**
|
|
2
113
|
* `gateforge check`: the full gate — discover → obligations → claims →
|
|
3
114
|
* verdicts → report, with exit codes per architecture contract 4
|
|
@@ -14,36 +125,308 @@
|
|
|
14
125
|
* produce identical resource-change sets for identical repos).
|
|
15
126
|
*
|
|
16
127
|
* Current claim declarations come from `.gateforge/test-map.yml` and,
|
|
17
|
-
* when available, a verified receipt for the current input digest.
|
|
18
|
-
*
|
|
128
|
+
* when available, a verified receipt for the current input digest. Static
|
|
129
|
+
* annotations are compared with generated sidecar entries but are not direct
|
|
130
|
+
* check bindings; raw `claims.json` is never a declaration source.
|
|
19
131
|
*/
|
|
20
|
-
import { cpSync, existsSync, mkdirSync } from 'node:fs';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
132
|
+
import { cpSync, existsSync, lstatSync, mkdirSync, readFileSync } from 'node:fs';
|
|
133
|
+
import { spawnSync } from 'node:child_process';
|
|
134
|
+
import { createHash } from 'node:crypto';
|
|
135
|
+
import { join } from 'node:path';
|
|
136
|
+
import { performance } from 'node:perf_hooks';
|
|
137
|
+
import { BLOCKING_VERDICTS, decideStrictness, loadQuarantines, QUARANTINE_DIR, resolveStrictnessMode, strictnessSummaryLine, CAUSE_NEXT_ACTIONS, canonicalJson, ENGINE_UPGRADE_REFUSAL_PREFIX, volatileEchoSkips, engineBundleDigestOf, executionBoundaryDigestOf, GateReceiptSchema, humanMessage, LOCAL_UNISOLATED_BOUNDARY, renderRun, runExitCode, } from '@gate-forge/core';
|
|
138
|
+
import { discoverTestCatalog, findPlaywrightConfig, scanTestFiles, untrustedEnv, } from '@gate-forge/pack-playwright';
|
|
23
139
|
import { parseArgs, stringFlag } from '../args.js';
|
|
24
140
|
import { resolveAdoptedBaseline } from '../adopted-baseline.js';
|
|
25
141
|
import { UsageError } from '../errors.js';
|
|
26
142
|
import { writeLine } from '../io.js';
|
|
27
143
|
import { trustedPolicyDigestForConfig } from '../execution.js';
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
144
|
+
import { gateforgeOwnedInputs } from '../gateforge-owned.js';
|
|
145
|
+
import { obligationFingerprint, evaluateRun, scopeBlocking } from '../evaluate.js';
|
|
146
|
+
import { auditAdapters } from '../adapter-audit.js';
|
|
147
|
+
import { singletonPerTenantAdvisories } from '../singleton-guidance.js';
|
|
148
|
+
import { responseFieldAdvisories } from '../response-field-guidance.js';
|
|
149
|
+
import { unmatchedRouteBannerLines } from '../unmatched-routes.js';
|
|
150
|
+
import { annotationMapSyncAdvisories, findRunnerConfigPath, loadOptionalTestMap, mappedCoverageFrom, mappingBlocking, nativeInventoryBlocking, resolveRepositoryMappings, TEST_MAP_RELATIVE } from '../mapping.js';
|
|
30
151
|
import { collectInputFiles, computeInputSnapshot, diffInputFiles, SnapshotUnavailableError, UnsupportedSnapshotError, } from '../input-snapshot.js';
|
|
31
152
|
import { runPipeline, resolveRepoPath, sourcesByResourceId } from '../pipeline.js';
|
|
153
|
+
import { digestPytestInputs, interpreterIdentity, pytestCacheKey, readPytestCache, resolveCacheControl, writePytestCache, } from '../run-cache.js';
|
|
32
154
|
import { RuntimeBlockError, loadRuntimeConfigAt, prepareRuntime } from '../runtime.js';
|
|
33
155
|
import { digestRuntimeReuseMounts } from '../runtime-reuse.js';
|
|
34
156
|
import { authenticatedChangedInputs, loadReceiptFor, receiptGateBlocking, scopedReceiptCoverageBlocking, } from '../receipts.js';
|
|
35
|
-
import {
|
|
157
|
+
import { resealChainBlocking, retainedCarriedEvidence } from '../reseal-chain.js';
|
|
158
|
+
import { mergeRequestScopePreflight, resolveProvider } from '../providers.js';
|
|
36
159
|
import { computeEvaluationScope, detectStagedWorkingTreeMismatches, } from '../scope.js';
|
|
37
|
-
import { assertRuntimeReuseOwnerApproval, freezeStagedCandidate, materializeStagedCandidate, recheckStagedCandidate, releaseStagedCandidate, StagedCandidateBlockError, } from '../staged-candidate.js';
|
|
38
|
-
import { httpRoutesView, resolveStateDir } from '../state.js';
|
|
160
|
+
import { assertRuntimeReuseOwnerApproval, freezeCommitCandidate, freezeStagedCandidate, materializeStagedCandidate, recheckStagedCandidate, releaseStagedCandidate, StagedCandidateBlockError, } from '../staged-candidate.js';
|
|
161
|
+
import { httpRoutesView, readCandidateTreeEntries, readStateDocument, resolveStateDir } from '../state.js';
|
|
162
|
+
import { engineGeneratedStateFileFilter } from '../state-artifacts.js';
|
|
39
163
|
import { assertReceiptApprovedPolicy, evaluateApprovedPolicy, resolveApprovedPolicyDigest, } from '../trusted-policy.js';
|
|
40
164
|
import { loadConfigAt, parseRunFormat, rejectUnknownFlags, VERSION } from './common.js';
|
|
41
165
|
import { resolveVerifierKeyring } from '../verifier-keys.js';
|
|
42
166
|
import { renderEndpointInventory } from '../endpoint-report.js';
|
|
43
|
-
import {
|
|
167
|
+
import { computeCandidateTreeSnapshot, resolveGitDir, sanitizedAuthorityEnv } from '../candidate-tree.js';
|
|
44
168
|
import { DOCS_EXCLUSIONS_GUARANTEE, loadDocsExclusions } from '../docs-exclusions.js';
|
|
45
|
-
|
|
46
|
-
|
|
169
|
+
import { CACHE_EXCLUSIONS_GUARANTEE, loadCacheExclusions } from '../cache-exclusions.js';
|
|
170
|
+
import { engineIdentity, reportEngineLine } from '../engine-identity.js';
|
|
171
|
+
/**
|
|
172
|
+
* Compares sealed candidate entries with the current tree and explains the files behind a mismatch.
|
|
173
|
+
*
|
|
174
|
+
* Args:
|
|
175
|
+
* sealed: entries persisted with the receipt.
|
|
176
|
+
* current: entries from the current candidate-tree walk.
|
|
177
|
+
* workspace: absolute repository root.
|
|
178
|
+
* stateDir: absolute run-state directory containing the receipt.
|
|
179
|
+
* env: sanitized process environment for Git ignore checks.
|
|
180
|
+
*
|
|
181
|
+
* Returns:
|
|
182
|
+
* string: actionable file-level mismatch details, or an empty string when unavailable or unchanged.
|
|
183
|
+
*/
|
|
184
|
+
function candidateTreeMismatchSummary(sealed, current, workspace, stateDir, env) {
|
|
185
|
+
const sealedByPath = new Map(sealed.map((entry) => [entry.path, entry]));
|
|
186
|
+
const currentByPath = new Map(current.map((entry) => [entry.path, entry]));
|
|
187
|
+
const changes = [];
|
|
188
|
+
for (const [path, entry] of currentByPath) {
|
|
189
|
+
const before = sealedByPath.get(path);
|
|
190
|
+
if (before === undefined)
|
|
191
|
+
changes.push({ kind: 'added', path });
|
|
192
|
+
else if (before.mode !== entry.mode || before.sha !== entry.sha)
|
|
193
|
+
changes.push({ kind: 'changed', path });
|
|
194
|
+
}
|
|
195
|
+
for (const path of sealedByPath.keys()) {
|
|
196
|
+
if (!currentByPath.has(path))
|
|
197
|
+
changes.push({ kind: 'removed', path });
|
|
198
|
+
}
|
|
199
|
+
changes.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
200
|
+
if (changes.length === 0)
|
|
201
|
+
return '';
|
|
202
|
+
const lines = changes.slice(0, 20).map(({ kind, path }) => {
|
|
203
|
+
const ignored = spawnSync('git', ['--no-replace-objects', 'check-ignore', '--quiet', '--', path], {
|
|
204
|
+
cwd: workspace,
|
|
205
|
+
env: sanitizedAuthorityEnv(env),
|
|
206
|
+
stdio: 'ignore',
|
|
207
|
+
}).status === 0;
|
|
208
|
+
return ` ${kind} ${JSON.stringify(path)}${ignored ? ' (ignored by git but part of the tested tree)' : ''}`;
|
|
209
|
+
});
|
|
210
|
+
if (changes.length > lines.length)
|
|
211
|
+
lines.push(` ... ${changes.length - lines.length} additional path changes`);
|
|
212
|
+
let postSealHint = '';
|
|
213
|
+
try {
|
|
214
|
+
// Filesystem mtimes advance in coarse clock ticks (milliseconds), so a
|
|
215
|
+
// quick edit right after sealing can carry the receipt's exact mtime;
|
|
216
|
+
// a tie therefore counts as "after the seal".
|
|
217
|
+
const receiptTime = lstatSync(join(stateDir, 'receipt.json')).mtimeMs;
|
|
218
|
+
const allChangedAfterSeal = changes.every(({ path }) => lstatSync(join(workspace, path)).mtimeMs >= receiptTime);
|
|
219
|
+
if (allChangedAfterSeal) {
|
|
220
|
+
postSealHint =
|
|
221
|
+
' these paths changed after the run was sealed — often another pre-commit hook or a build step; ' +
|
|
222
|
+
'run those before the suite or make them non-mutating.';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// Missing paths or receipt timestamps cannot support a post-seal claim.
|
|
227
|
+
}
|
|
228
|
+
const docsOnly = changes.every(({ path }) => /^(?:docs?|guides?)\//i.test(path) || /\.(?:md|mdx|rst)$/i.test(path));
|
|
229
|
+
const docsHint = docsOnly
|
|
230
|
+
? ' Only documentation paths changed; if these are approved documentation folders, run `gateforge init --docs-exclude <folders>`.'
|
|
231
|
+
: '';
|
|
232
|
+
return ` candidate tree files:\n${lines.join('\n')}${postSealHint}${docsHint}`;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Returns an authenticated receipt for a candidate base, distinguishing a
|
|
236
|
+
* matching tree from an authenticated stale-tree binding. With owner-approved
|
|
237
|
+
* docs/cache exclusions the comparison uses the FILTERED snapshot identity
|
|
238
|
+
* (the same one the full gate seals): the raw candidate tree carries excluded
|
|
239
|
+
* bytes the receipt deliberately ignores, so an exact raw-tree match is
|
|
240
|
+
* impossible and the filtered tree id decides instead.
|
|
241
|
+
*
|
|
242
|
+
* Args:
|
|
243
|
+
* io: process context.
|
|
244
|
+
* checkoutDir: isolated checkout of the immutable candidate.
|
|
245
|
+
* candidate: frozen commit identity and tree.
|
|
246
|
+
* options: receipt key and optional policy pin.
|
|
247
|
+
*
|
|
248
|
+
* Returns:
|
|
249
|
+
* VerifiedCandidateFastPath | null: authenticated clean receipt, or null
|
|
250
|
+
* to use the full path.
|
|
251
|
+
*/
|
|
252
|
+
function verifiedCandidateFastPathReceipt(io, checkoutDir, candidate, options) {
|
|
253
|
+
try {
|
|
254
|
+
const config = loadConfigAt(checkoutDir);
|
|
255
|
+
const receiptDocument = readStateDocument(resolveStateDir(io.cwd), 'receipt.json');
|
|
256
|
+
const parsed = GateReceiptSchema.safeParse(receiptDocument);
|
|
257
|
+
if (!parsed.success || config.enforcement?.receiptStage === undefined)
|
|
258
|
+
return null;
|
|
259
|
+
const docsExclusions = loadDocsExclusions(checkoutDir, config);
|
|
260
|
+
const cacheExclusions = loadCacheExclusions(checkoutDir, config);
|
|
261
|
+
const hasOwnerExclusions = docsExclusions.length > 0 || cacheExclusions.length > 0;
|
|
262
|
+
const receipt = parsed.data;
|
|
263
|
+
const currentEngine = engineIdentity();
|
|
264
|
+
const currentPolicyDigest = trustedPolicyDigestForConfig(checkoutDir, config);
|
|
265
|
+
const resolution = resolveApprovedPolicyDigest({
|
|
266
|
+
flag: options.approvedPolicyDigest,
|
|
267
|
+
env: io.env,
|
|
268
|
+
candidateCwd: checkoutDir,
|
|
269
|
+
candidateConfig: config,
|
|
270
|
+
});
|
|
271
|
+
// Owner exclusions raise the ownership bar exactly like the full gate:
|
|
272
|
+
// without the external pin the exclusions (and this fast path) fail closed.
|
|
273
|
+
const policyGate = evaluateApprovedPolicy(resolution, currentPolicyDigest, config.enforcement.strictE2E === true || hasOwnerExclusions);
|
|
274
|
+
if (policyGate.status !== 'enforced' ||
|
|
275
|
+
receipt.trustedPolicyDigest !== currentPolicyDigest ||
|
|
276
|
+
receipt.engine === undefined ||
|
|
277
|
+
receipt.engine.version !== currentEngine.version ||
|
|
278
|
+
receipt.engine.source !== currentEngine.source ||
|
|
279
|
+
receipt.engine.unpublished !== currentEngine.unpublished ||
|
|
280
|
+
receipt.engineBundleDigest !== engineBundleDigestOf(currentEngine.version, currentPolicyDigest) ||
|
|
281
|
+
receipt.receiptStage !== config.enforcement.receiptStage ||
|
|
282
|
+
receipt.verdictSummary.blocking !== 0 ||
|
|
283
|
+
(receipt.scope !== undefined && receipt.scope !== 'full')) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
const firstParent = candidate.parentShas[0] ?? null;
|
|
287
|
+
let priorParent = null;
|
|
288
|
+
if (firstParent !== null) {
|
|
289
|
+
const parentResult = spawnSync('git', ['rev-parse', '--verify', `${firstParent}^`], {
|
|
290
|
+
cwd: io.cwd,
|
|
291
|
+
env: sanitizedAuthorityEnv(io.env),
|
|
292
|
+
encoding: 'utf8',
|
|
293
|
+
});
|
|
294
|
+
const value = (parentResult.stdout ?? '').trim();
|
|
295
|
+
if (parentResult.error === undefined && parentResult.status === 0 && /^[0-9a-f]{40}$/.test(value)) {
|
|
296
|
+
priorParent = value;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const baseMatches = (receipt.gitSha === candidate.headSha && receipt.parentSha === firstParent) ||
|
|
300
|
+
(receipt.gitSha === firstParent && receipt.parentSha === priorParent);
|
|
301
|
+
if (!baseMatches)
|
|
302
|
+
return null;
|
|
303
|
+
const currentBoundary = executionBoundaryDigestOf(io.env['GATEFORGE_AUTHORITY_BOUNDARY']?.trim() || LOCAL_UNISOLATED_BOUNDARY);
|
|
304
|
+
const verified = loadReceiptFor(resolveStateDir(io.cwd), options.verifierKeyring, {
|
|
305
|
+
inputDigest: receipt.inputDigest,
|
|
306
|
+
trustedPolicyDigest: currentPolicyDigest,
|
|
307
|
+
executionBoundaryDigest: currentBoundary,
|
|
308
|
+
scope: 'full',
|
|
309
|
+
});
|
|
310
|
+
if (verified.status !== 'ok')
|
|
311
|
+
return null;
|
|
312
|
+
const approvedBinding = assertReceiptApprovedPolicy(verified.receipt, policyGate.approved);
|
|
313
|
+
if (!approvedBinding.ok)
|
|
314
|
+
return null;
|
|
315
|
+
// Currency check: the receipt binds the tree identity the full gate would
|
|
316
|
+
// have sealed. With exclusions that is the FILTERED tree of the checkout
|
|
317
|
+
// (docs/cache bytes excluded), recomputed here from the candidate bytes.
|
|
318
|
+
let expectedTreeId = candidate.treeId;
|
|
319
|
+
if (hasOwnerExclusions) {
|
|
320
|
+
const gitDir = resolveGitDir(checkoutDir, io.env);
|
|
321
|
+
expectedTreeId =
|
|
322
|
+
gitDir === null
|
|
323
|
+
? null
|
|
324
|
+
: computeCandidateTreeSnapshot(gitDir, checkoutDir, io.env, resolveStateDir(checkoutDir), 'record', [], docsExclusions, cacheExclusions).treeId;
|
|
325
|
+
}
|
|
326
|
+
if (expectedTreeId === null)
|
|
327
|
+
return null;
|
|
328
|
+
return { receipt: verified.receipt, treeMatches: verified.receipt.candidateTreeId === expectedTreeId, expectedTreeId };
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Renders the signed summary used when discovery is safely skipped.
|
|
336
|
+
*
|
|
337
|
+
* Args:
|
|
338
|
+
* format: text or JSON output requested by the caller.
|
|
339
|
+
* receipt: authenticated full-scope receipt.
|
|
340
|
+
* candidateTreeId: frozen candidate tree identity.
|
|
341
|
+
*
|
|
342
|
+
* Returns:
|
|
343
|
+
* string: auditable fast-path result.
|
|
344
|
+
*/
|
|
345
|
+
function renderFastPathReceipt(format, receipt, candidateTreeId) {
|
|
346
|
+
const diagnosticContext = {
|
|
347
|
+
scope: 'full',
|
|
348
|
+
candidateTreeId,
|
|
349
|
+
inputDigest: receipt.inputDigest,
|
|
350
|
+
evidenceState: 'receipt-verified-fast-path',
|
|
351
|
+
authority: 'authoritative',
|
|
352
|
+
};
|
|
353
|
+
if (format === 'json') {
|
|
354
|
+
return canonicalJson({
|
|
355
|
+
fastPath: true,
|
|
356
|
+
receiptStage: receipt.receiptStage ?? null,
|
|
357
|
+
engine: receipt.engine ?? null,
|
|
358
|
+
summary: receipt.verdictSummary,
|
|
359
|
+
blocking: [],
|
|
360
|
+
diagnosticContext,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
const summary = receipt.verdictSummary;
|
|
364
|
+
return [
|
|
365
|
+
`gateforge run: ${String(summary.total)} obligation(s) — ${String(summary.satisfied)} satisfied, ${String(summary.waived)} waived, 0 blocking`,
|
|
366
|
+
'receipt: verified for the exact candidate tree; discovery and test execution were not started (fast path)',
|
|
367
|
+
`diagnostic context: scope=full candidateTreeId=${candidateTreeId} inputDigest=${receipt.inputDigest} evidence=receipt-verified-fast-path authority=authoritative`,
|
|
368
|
+
].join('\n');
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Finds endpoints whose only statically matched tests intercept their route.
|
|
372
|
+
*
|
|
373
|
+
* Args:
|
|
374
|
+
* endpoints: compiled endpoint identities.
|
|
375
|
+
* tests: statically discovered tests and their route-interception facts.
|
|
376
|
+
*
|
|
377
|
+
* Returns:
|
|
378
|
+
* BlockingEntry[]: non-blocking report entries for mocked-only routes.
|
|
379
|
+
*/
|
|
380
|
+
function mockedOnlyEndpointAdvisories(endpoints, tests) {
|
|
381
|
+
/**
|
|
382
|
+
* Compiles a Playwright-style route glob for a full-path comparison.
|
|
383
|
+
*
|
|
384
|
+
* Args:
|
|
385
|
+
* pattern: statically discovered route glob.
|
|
386
|
+
*
|
|
387
|
+
* Returns:
|
|
388
|
+
* RegExp: matcher for one candidate URL or canonical path.
|
|
389
|
+
*/
|
|
390
|
+
const routeRegex = (pattern) => {
|
|
391
|
+
/**
|
|
392
|
+
* Escapes ordinary glob text for use in the route regular expression.
|
|
393
|
+
*
|
|
394
|
+
* Args:
|
|
395
|
+
* value: text between wildcard markers.
|
|
396
|
+
*
|
|
397
|
+
* Returns:
|
|
398
|
+
* string: escaped regular-expression source.
|
|
399
|
+
*/
|
|
400
|
+
const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
401
|
+
return new RegExp(`^${pattern
|
|
402
|
+
.split('**')
|
|
403
|
+
.map((part) => part.split('*').map(escape).join('[^/]*'))
|
|
404
|
+
.join('.*')}$`);
|
|
405
|
+
};
|
|
406
|
+
const entries = [];
|
|
407
|
+
for (const endpoint of endpoints) {
|
|
408
|
+
const targetPath = endpoint.canonicalPath;
|
|
409
|
+
const matchingTests = tests.filter((test) => (test.facts.pageRouteTargets ?? []).some((pattern) => {
|
|
410
|
+
const matches = routeRegex(pattern);
|
|
411
|
+
return matches.test(targetPath) || matches.test(`http://gateforge.invalid${targetPath}`);
|
|
412
|
+
}));
|
|
413
|
+
if (matchingTests.length === 0 || matchingTests.some((test) => test.facts.pageRoute === null))
|
|
414
|
+
continue;
|
|
415
|
+
const testNames = matchingTests.map((test) => `${test.file} (${test.title})`).sort();
|
|
416
|
+
entries.push({
|
|
417
|
+
kind: 'finding',
|
|
418
|
+
resourceId: null,
|
|
419
|
+
name: null,
|
|
420
|
+
detail: `only mocked tests reach ${endpoint.method} ${targetPath}: ${testNames.join(', ')}`,
|
|
421
|
+
location: null,
|
|
422
|
+
cause: null,
|
|
423
|
+
nextAction: 'Add a witnessed test that reaches the server instead of intercepting this route.',
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
return entries;
|
|
427
|
+
}
|
|
428
|
+
export const CHECK_USAGE = 'usage: gateforge check [--changed] [--staged] [--candidate-commit <sha>] [--require-e2e] [--format text|json|sarif]\n' +
|
|
429
|
+
' [--approved-policy-digest <hex64>] [--timing] [--no-cache]\n' +
|
|
47
430
|
' verifier key: GATEFORGE_WITNESS_VERIFIER_KEY or GATEFORGE_WITNESS_VERIFIER_KEY_FILE\n' +
|
|
48
431
|
' approved policy digest: the OWNER-APPROVED policy revision pin. Never sourced from\n' +
|
|
49
432
|
' candidate-controlled files in strict mode — provision it via the protected\n' +
|
|
@@ -66,16 +449,34 @@ export async function checkCommand(io, argv) {
|
|
|
66
449
|
writeLine(io.stdout, CHECK_USAGE);
|
|
67
450
|
return 0;
|
|
68
451
|
}
|
|
69
|
-
rejectUnknownFlags(options, ['changed', 'staged', 'require-e2e', 'format', 'approved-policy-digest', 'help'], CHECK_USAGE);
|
|
452
|
+
rejectUnknownFlags(options, ['changed', 'staged', 'candidate-commit', 'require-e2e', 'format', 'approved-policy-digest', 'timing', 'no-cache', 'help'], CHECK_USAGE);
|
|
70
453
|
if (options['staged'] === true && options['changed'] === true) {
|
|
71
454
|
throw new UsageError('check: --staged already scopes the run to the staged candidate; --changed cannot be combined');
|
|
72
455
|
}
|
|
73
456
|
const format = parseRunFormat(stringFlag(options, 'format') ?? 'text');
|
|
74
457
|
const requireE2E = options['require-e2e'] === true;
|
|
75
458
|
const approvedPolicyDigest = stringFlag(options, 'approved-policy-digest');
|
|
459
|
+
const timing = options['timing'] === true;
|
|
460
|
+
const noCache = options['no-cache'] === true;
|
|
76
461
|
const verifierKeyring = resolveVerifierKeyring(io.cwd, io.env, [resolveStateDir(io.cwd)]);
|
|
462
|
+
const candidateCommitSha = stringFlag(options, 'candidate-commit');
|
|
463
|
+
if (options['staged'] === true && candidateCommitSha !== undefined) {
|
|
464
|
+
throw new UsageError('check: --candidate-commit cannot be combined with --staged');
|
|
465
|
+
}
|
|
466
|
+
if (candidateCommitSha !== undefined) {
|
|
467
|
+
return stagedCheckCommand(io, {
|
|
468
|
+
candidateCommitSha,
|
|
469
|
+
diffScoped: options['changed'] === true,
|
|
470
|
+
requireE2E,
|
|
471
|
+
format,
|
|
472
|
+
approvedPolicyDigest,
|
|
473
|
+
verifierKeyring,
|
|
474
|
+
timing,
|
|
475
|
+
noCache,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
77
478
|
if (options['staged'] === true) {
|
|
78
|
-
return stagedCheckCommand(io, { requireE2E, format, approvedPolicyDigest, verifierKeyring });
|
|
479
|
+
return stagedCheckCommand(io, { diffScoped: true, requireE2E, format, approvedPolicyDigest, verifierKeyring, timing, noCache });
|
|
79
480
|
}
|
|
80
481
|
return runCheckGate(io, {
|
|
81
482
|
diffScoped: options['changed'] === true,
|
|
@@ -83,6 +484,8 @@ export async function checkCommand(io, argv) {
|
|
|
83
484
|
format,
|
|
84
485
|
approvedPolicyDigest,
|
|
85
486
|
verifierKeyring,
|
|
487
|
+
timing,
|
|
488
|
+
noCache,
|
|
86
489
|
});
|
|
87
490
|
}
|
|
88
491
|
/**
|
|
@@ -111,7 +514,10 @@ export async function checkCommand(io, argv) {
|
|
|
111
514
|
async function stagedCheckCommand(io, options) {
|
|
112
515
|
let frozen;
|
|
113
516
|
try {
|
|
114
|
-
frozen =
|
|
517
|
+
frozen =
|
|
518
|
+
options.candidateCommitSha === undefined
|
|
519
|
+
? freezeStagedCandidate(io.cwd, io.env)
|
|
520
|
+
: freezeCommitCandidate(io.cwd, io.env, options.candidateCommitSha);
|
|
115
521
|
}
|
|
116
522
|
catch (error) {
|
|
117
523
|
if (error instanceof StagedCandidateBlockError) {
|
|
@@ -133,10 +539,11 @@ async function stagedCheckCommand(io, options) {
|
|
|
133
539
|
// staged tree; only the marker-relevant empty dirs are mirrored).
|
|
134
540
|
const checkoutConfig = loadConfigAt(checkoutDir);
|
|
135
541
|
const docsExclusions = loadDocsExclusions(checkoutDir, checkoutConfig);
|
|
542
|
+
const cacheExclusions = loadCacheExclusions(checkoutDir, checkoutConfig);
|
|
136
543
|
for (const dir of [checkoutConfig.adapters, checkoutConfig.waivers]) {
|
|
137
544
|
const userDir = resolveRepoPath(io.cwd, dir);
|
|
138
545
|
const checkoutPath = resolveRepoPath(checkoutDir, dir);
|
|
139
|
-
if (existsSync(userDir) && !existsSync(checkoutPath)) {
|
|
546
|
+
if (options.candidateCommitSha === undefined && existsSync(userDir) && !existsSync(checkoutPath)) {
|
|
140
547
|
mkdirSync(checkoutPath, { recursive: true });
|
|
141
548
|
}
|
|
142
549
|
}
|
|
@@ -157,11 +564,46 @@ async function stagedCheckCommand(io, options) {
|
|
|
157
564
|
env: io.env,
|
|
158
565
|
candidateCwd: checkoutDir,
|
|
159
566
|
candidateConfig: checkoutConfig,
|
|
160
|
-
}), candidatePolicyDigest, checkoutConfig.enforcement?.strictE2E === true || docsExclusions.length > 0);
|
|
567
|
+
}), candidatePolicyDigest, checkoutConfig.enforcement?.strictE2E === true || docsExclusions.length > 0 || cacheExclusions.length > 0);
|
|
161
568
|
if (policyGate.status === 'blocked') {
|
|
162
569
|
releaseStagedCandidate(frozen);
|
|
163
570
|
return renderStagedBlock(io, policyGate.cause, policyGate.detail, policyGate.nextAction);
|
|
164
571
|
}
|
|
572
|
+
if (options.candidateCommitSha !== undefined &&
|
|
573
|
+
options.requireE2E &&
|
|
574
|
+
options.format !== 'sarif') {
|
|
575
|
+
const fastPathReceipt = verifiedCandidateFastPathReceipt(io, checkoutDir, frozen, {
|
|
576
|
+
approvedPolicyDigest: options.approvedPolicyDigest,
|
|
577
|
+
verifierKeyring: options.verifierKeyring,
|
|
578
|
+
});
|
|
579
|
+
if (fastPathReceipt !== null) {
|
|
580
|
+
if (!fastPathReceipt.treeMatches) {
|
|
581
|
+
const stateDir = resolveStateDir(io.cwd);
|
|
582
|
+
const sealedEntries = readCandidateTreeEntries(stateDir);
|
|
583
|
+
const gitDir = resolveGitDir(checkoutDir, io.env);
|
|
584
|
+
const snapshot = sealedEntries === null || gitDir === null
|
|
585
|
+
? null
|
|
586
|
+
: computeCandidateTreeSnapshot(gitDir, checkoutDir, io.env, resolveStateDir(checkoutDir), 'record', [], docsExclusions, cacheExclusions);
|
|
587
|
+
const treeDiff = sealedEntries === null || snapshot === null
|
|
588
|
+
? ''
|
|
589
|
+
: candidateTreeMismatchSummary(sealedEntries, snapshot.entries, checkoutDir, stateDir, io.env);
|
|
590
|
+
const nextAction = CAUSE_NEXT_ACTIONS.EVIDENCE_STALE;
|
|
591
|
+
const detail = humanMessage({
|
|
592
|
+
cause: 'EVIDENCE_STALE',
|
|
593
|
+
detail: `require-e2e: authenticated receipt is bound to candidate tree ${fastPathReceipt.receipt.candidateTreeId ?? '<unavailable>'}, ` +
|
|
594
|
+
`not ${fastPathReceipt.expectedTreeId ?? '<unavailable>'}.${treeDiff}`,
|
|
595
|
+
// The detail names the command that re-seals this candidate;
|
|
596
|
+
// the block's own `next action:` line keeps the cause prose.
|
|
597
|
+
nextAction: 'gateforge test-gates --changed',
|
|
598
|
+
});
|
|
599
|
+
releaseStagedCandidate(frozen);
|
|
600
|
+
return renderStagedBlock(io, 'EVIDENCE_STALE', detail, nextAction);
|
|
601
|
+
}
|
|
602
|
+
writeLine(io.stdout, renderFastPathReceipt(options.format === 'json' ? 'json' : 'text', fastPathReceipt.receipt, fastPathReceipt.expectedTreeId ?? frozen.treeId));
|
|
603
|
+
releaseStagedCandidate(frozen);
|
|
604
|
+
return 0;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
165
607
|
const runtimeDoc = loadRuntimeConfigAt(checkoutDir, checkoutConfig.runtime);
|
|
166
608
|
if (runtimeDoc !== null) {
|
|
167
609
|
assertRuntimeReuseOwnerApproval(frozen.approvedReusePaths, runtimeDoc.prepare?.reuse ?? []);
|
|
@@ -197,20 +639,26 @@ async function stagedCheckCommand(io, options) {
|
|
|
197
639
|
cpSync(userState, resolveStateDir(checkoutDir), { recursive: true });
|
|
198
640
|
}
|
|
199
641
|
const code = await runCheckGate({ ...io, cwd: checkoutDir }, {
|
|
200
|
-
diffScoped:
|
|
642
|
+
diffScoped: options.diffScoped,
|
|
201
643
|
requireE2E: options.requireE2E,
|
|
202
644
|
format: options.format,
|
|
203
645
|
approvedPolicyDigest: options.approvedPolicyDigest,
|
|
204
646
|
verifierKeyring: options.verifierKeyring,
|
|
205
|
-
|
|
647
|
+
fixedCandidateTreeId: frozen.treeId,
|
|
648
|
+
...(options.diffScoped ? { fixedChangedFiles: frozen.changedPaths } : {}),
|
|
206
649
|
runtimeReuseDigest,
|
|
207
650
|
runtimeReuseMounts,
|
|
208
651
|
runtimeReuseCheck: () => digestRuntimeReuseMounts(runtimeReuseMounts),
|
|
652
|
+
...(options.timing === true ? { timing: true } : {}),
|
|
653
|
+
// The scratch checkout's state dir is thrown away — the cache lives
|
|
654
|
+
// in the USER's persistent run-state dir (same repo, content keys).
|
|
655
|
+
...(options.noCache === true ? { noCache: true } : { cacheStateDir: resolveStateDir(io.cwd) }),
|
|
209
656
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
657
|
+
if (options.candidateCommitSha === undefined) {
|
|
658
|
+
const recheck = recheckStagedCandidate(io.cwd, io.env, frozen);
|
|
659
|
+
if (!recheck.ok) {
|
|
660
|
+
return renderStagedBlock(io, 'ENFORCEMENT_UNTRUSTED', recheck.detail, 'Re-run the gate for the current staged candidate.');
|
|
661
|
+
}
|
|
214
662
|
}
|
|
215
663
|
return code;
|
|
216
664
|
}
|
|
@@ -246,6 +694,74 @@ function renderStagedBlock(io, cause, detail, nextAction) {
|
|
|
246
694
|
writeLine(io.stdout, `next action: ${nextAction}`);
|
|
247
695
|
return 1;
|
|
248
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* Names the report's exit-code line for what it is when a non-blocking
|
|
699
|
+
* mode softened the run's exit code.
|
|
700
|
+
*
|
|
701
|
+
* The text report always carries the STRICT result's exit code. In
|
|
702
|
+
* `strict` mode that is the code the process exits with, so the line is
|
|
703
|
+
* left byte-identical. When a mode softens it, the same bare
|
|
704
|
+
* `exit code: 1` would contradict `EXIT=0` in a CI log and to an agent
|
|
705
|
+
* reading the report, so it is relabelled as the value a blocking mode
|
|
706
|
+
* would have produced. Nothing is invented: a report without that line
|
|
707
|
+
* is returned untouched.
|
|
708
|
+
*
|
|
709
|
+
* Args:
|
|
710
|
+
* report: the rendered text report.
|
|
711
|
+
* strictExitCode: the exit code the strict result maps to.
|
|
712
|
+
* exitCode: the exit code this run actually exits with.
|
|
713
|
+
*
|
|
714
|
+
* Returns:
|
|
715
|
+
* string: the report with its exit-code line relabelled when softened.
|
|
716
|
+
*/
|
|
717
|
+
export function labelSoftenedExitCode(report, strictExitCode, exitCode) {
|
|
718
|
+
if (strictExitCode === exitCode)
|
|
719
|
+
return report;
|
|
720
|
+
const lines = report.split('\n');
|
|
721
|
+
// The LAST such line is the report's own verdict; a fixture or a
|
|
722
|
+
// quoted payload earlier in the text is never relabelled.
|
|
723
|
+
let index = -1;
|
|
724
|
+
for (let at = lines.length - 1; at >= 0; at -= 1) {
|
|
725
|
+
if (/^exit code: \d+$/.test(lines[at] ?? '')) {
|
|
726
|
+
index = at;
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (index < 0)
|
|
731
|
+
return report;
|
|
732
|
+
lines[index] = `would exit ${String(strictExitCode)} in blocking mode`;
|
|
733
|
+
return lines.join('\n');
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Validates persisted pytest collection data before it can bypass a child run.
|
|
737
|
+
*
|
|
738
|
+
* Args:
|
|
739
|
+
* value: parsed cache payload.
|
|
740
|
+
*
|
|
741
|
+
* Returns:
|
|
742
|
+
* boolean: true only for a complete collection result with valid fields.
|
|
743
|
+
*/
|
|
744
|
+
function isPytestCollectionResult(value) {
|
|
745
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
746
|
+
return false;
|
|
747
|
+
const result = value;
|
|
748
|
+
if ((result['status'] !== 'discovered' && result['status'] !== 'unavailable') ||
|
|
749
|
+
typeof result['detail'] !== 'string' ||
|
|
750
|
+
!Array.isArray(result['cases']) ||
|
|
751
|
+
!Array.isArray(result['collectionErrors']) ||
|
|
752
|
+
(result['exitCode'] !== null && typeof result['exitCode'] !== 'number')) {
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
return (result['cases'].every((testCase) => {
|
|
756
|
+
if (typeof testCase !== 'object' || testCase === null || Array.isArray(testCase))
|
|
757
|
+
return false;
|
|
758
|
+
const row = testCase;
|
|
759
|
+
return (typeof row['nodeId'] === 'string' &&
|
|
760
|
+
typeof row['file'] === 'string' &&
|
|
761
|
+
Array.isArray(row['titlePath']) &&
|
|
762
|
+
row['titlePath'].every((title) => typeof title === 'string'));
|
|
763
|
+
}) && result['collectionErrors'].every((error) => typeof error === 'string'));
|
|
764
|
+
}
|
|
249
765
|
/**
|
|
250
766
|
* The gate body shared by `check`, `check --changed`, and the Phase 5
|
|
251
767
|
* `check --staged` candidate run (via a scratch checkout cwd).
|
|
@@ -259,6 +775,7 @@ function renderStagedBlock(io, cause, detail, nextAction) {
|
|
|
259
775
|
* @throws fail-closed errors (exit 2) from config/plugin/pipeline layers.
|
|
260
776
|
*/
|
|
261
777
|
export async function runCheckGate(io, options) {
|
|
778
|
+
const gateStartedAtMs = performance.now();
|
|
262
779
|
const { diffScoped, requireE2E, format } = options;
|
|
263
780
|
const fixedChangedFiles = options.fixedChangedFiles;
|
|
264
781
|
const runtimeReuseDigest = options.runtimeReuseDigest;
|
|
@@ -272,9 +789,29 @@ export async function runCheckGate(io, options) {
|
|
|
272
789
|
// fails closed. Legacy v1 `recordIdsMac` never authorizes, even when
|
|
273
790
|
// it verifies.
|
|
274
791
|
const config = loadConfigAt(io.cwd);
|
|
792
|
+
// A merge-request pipeline with no base commit would resolve `auto` to
|
|
793
|
+
// the local staged diff — zero changed files in a CI job, and a gate
|
|
794
|
+
// that fails an hour later on debt nobody changed. Refuse in seconds.
|
|
795
|
+
if (diffScoped) {
|
|
796
|
+
const refusal = mergeRequestScopePreflight(config, io.env);
|
|
797
|
+
if (refusal !== null)
|
|
798
|
+
throw new UsageError(refusal);
|
|
799
|
+
}
|
|
800
|
+
// Owner-chosen strictness. A missing key
|
|
801
|
+
// resolves to `strict`, which is byte-for-byte today's behavior: the
|
|
802
|
+
// decision below is a pure mapping of an ALREADY-COMPUTED strict
|
|
803
|
+
// result, so no mode can change what was evaluated, only what the
|
|
804
|
+
// process returns. `changed` needs the diff machinery, so it reuses
|
|
805
|
+
// the `--changed` path (provider + scope expansion) for its decision
|
|
806
|
+
// while the full debt still reaches the report.
|
|
807
|
+
const gateMode = resolveStrictnessMode(config);
|
|
808
|
+
const gateModeChanged = gateMode === 'changed' && !diffScoped && fixedChangedFiles === undefined;
|
|
809
|
+
const scopeAwareRun = diffScoped || gateModeChanged;
|
|
275
810
|
const docsExclusions = loadDocsExclusions(io.cwd, config);
|
|
276
|
-
const
|
|
277
|
-
const
|
|
811
|
+
const cacheExclusions = loadCacheExclusions(io.cwd, config);
|
|
812
|
+
const hasOwnerExclusions = docsExclusions.length > 0 || cacheExclusions.length > 0;
|
|
813
|
+
const docsApprovalDigest = hasOwnerExclusions ? trustedPolicyDigestForConfig(io.cwd, config) : null;
|
|
814
|
+
const docsApprovalResolution = !hasOwnerExclusions
|
|
278
815
|
? null
|
|
279
816
|
: resolveApprovedPolicyDigest({
|
|
280
817
|
flag: options.approvedPolicyDigest,
|
|
@@ -293,7 +830,7 @@ export async function runCheckGate(io, options) {
|
|
|
293
830
|
: 'mismatch';
|
|
294
831
|
const providerIdentity = fixedChangedFiles !== undefined
|
|
295
832
|
? 'local-staged'
|
|
296
|
-
:
|
|
833
|
+
: scopeAwareRun
|
|
297
834
|
? resolveProvider(config.changed.provider, io.cwd, io.env).provider
|
|
298
835
|
: 'all-files';
|
|
299
836
|
const stateDir = resolveStateDir(io.cwd);
|
|
@@ -306,8 +843,12 @@ export async function runCheckGate(io, options) {
|
|
|
306
843
|
// unsafe --out overlap fails closed before any evaluation.
|
|
307
844
|
let preFiles = null;
|
|
308
845
|
let snapshotUnavailable = false;
|
|
846
|
+
// Content-addressed run cache: lives in
|
|
847
|
+
// the EXCLUDED run-state dir (never in the input digest), forced off by
|
|
848
|
+
// --no-cache / GATEFORGE_NO_CACHE / CI. A speed-up, never proof.
|
|
849
|
+
const cacheControl = resolveCacheControl(io.env, options.cacheStateDir ?? stateDir, options.noCache === true);
|
|
309
850
|
try {
|
|
310
|
-
preFiles = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions);
|
|
851
|
+
preFiles = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions, cacheExclusions);
|
|
311
852
|
}
|
|
312
853
|
catch (error) {
|
|
313
854
|
if (error instanceof SnapshotUnavailableError) {
|
|
@@ -327,7 +868,27 @@ export async function runCheckGate(io, options) {
|
|
|
327
868
|
provider: providerIdentity,
|
|
328
869
|
stateDir,
|
|
329
870
|
...(fixedChangedFiles !== undefined ? { changedFilesOverride: fixedChangedFiles } : {}),
|
|
871
|
+
pluginCache: cacheControl,
|
|
330
872
|
});
|
|
873
|
+
// Owner quarantine population: check is
|
|
874
|
+
// the debt view, so an owner-quarantined test is reported here too —
|
|
875
|
+
// loaded against the INJECTED run clock, never the wall clock. It is
|
|
876
|
+
// only reported when the population exists, so a repository that never
|
|
877
|
+
// quarantined anything gets exactly the document it had before.
|
|
878
|
+
const quarantines = loadQuarantines(join(io.cwd, ...QUARANTINE_DIR.split('/')), {
|
|
879
|
+
now: pipeline.now,
|
|
880
|
+
});
|
|
881
|
+
for (const notice of pipeline.alembicNotices) {
|
|
882
|
+
writeLine(io.stdout, `alembic: ${notice}`);
|
|
883
|
+
}
|
|
884
|
+
if (diffScoped && format === 'text') {
|
|
885
|
+
const base = providerIdentity === 'github-pr'
|
|
886
|
+
? io.env['GITHUB_BASE_REF'] ?? '<missing GITHUB_BASE_REF>'
|
|
887
|
+
: providerIdentity === 'gitlab-mr'
|
|
888
|
+
? io.env['CI_MERGE_REQUEST_DIFF_BASE_SHA'] ?? '<missing merge-request base>'
|
|
889
|
+
: 'staged index vs HEAD';
|
|
890
|
+
writeLine(io.stdout, `changed files: ${pipeline.changedFiles.length} (${providerIdentity}, ${base})`);
|
|
891
|
+
}
|
|
331
892
|
if (options.runtimeReuseCheck !== undefined) {
|
|
332
893
|
let currentReuseDigest;
|
|
333
894
|
try {
|
|
@@ -353,7 +914,7 @@ export async function runCheckGate(io, options) {
|
|
|
353
914
|
let diagnosticEvidenceState = 'not-required';
|
|
354
915
|
if (!snapshotUnavailable) {
|
|
355
916
|
try {
|
|
356
|
-
const postFiles = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions);
|
|
917
|
+
const postFiles = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions, cacheExclusions);
|
|
357
918
|
if (preFiles !== null && diffInputFiles(preFiles, postFiles).length > 0) {
|
|
358
919
|
changedInputs = true;
|
|
359
920
|
}
|
|
@@ -372,6 +933,7 @@ export async function runCheckGate(io, options) {
|
|
|
372
933
|
runtimeReuseDigest,
|
|
373
934
|
runtimeReuseMounts,
|
|
374
935
|
docsExclusions,
|
|
936
|
+
cacheExclusions,
|
|
375
937
|
});
|
|
376
938
|
expectedDigest = currentSnapshot.inputDigest;
|
|
377
939
|
}
|
|
@@ -422,19 +984,35 @@ export async function runCheckGate(io, options) {
|
|
|
422
984
|
// entry (E15) unless a resolved mapping covers it. The provider
|
|
423
985
|
// identity is preserved throughout — an expanded run never stamps
|
|
424
986
|
// `all-files` as the diff provider.
|
|
425
|
-
let scopeDecision = {
|
|
987
|
+
let scopeDecision = {
|
|
988
|
+
mode: 'all',
|
|
989
|
+
changedFiles: [],
|
|
990
|
+
expandedBecause: [],
|
|
991
|
+
unmappedFiles: [],
|
|
992
|
+
policyInputs: [],
|
|
993
|
+
policyInputsOnly: false,
|
|
994
|
+
};
|
|
426
995
|
let mismatchBlocking = [];
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
//
|
|
430
|
-
//
|
|
996
|
+
let scopeDiscoveryTimings;
|
|
997
|
+
if (scopeAwareRun) {
|
|
998
|
+
// Phase 4 expansion inputs (E15): the test inventory is loaded only
|
|
999
|
+
// when test infrastructure exists for the CONFIGURED runner (`runner:`
|
|
1000
|
+
// in `.gateforge.yml`; an absent key means playwright, so a repository
|
|
1001
|
+
// without it keeps the exact historical behavior) or a mapping
|
|
1002
|
+
// sidecar.
|
|
431
1003
|
const sidecar = loadOptionalTestMap(io.cwd);
|
|
432
|
-
const runnerConfig =
|
|
1004
|
+
const runnerConfig = findRunnerConfigPath(io.cwd, config.runner);
|
|
433
1005
|
let testFiles = [];
|
|
434
1006
|
if (runnerConfig !== null) {
|
|
435
1007
|
try {
|
|
436
|
-
|
|
437
|
-
|
|
1008
|
+
const scopeDiscovery = await discoverTestCatalog({
|
|
1009
|
+
cwd: io.cwd,
|
|
1010
|
+
config,
|
|
1011
|
+
excludeFile: engineGeneratedStateFileFilter(io.cwd, stateDir),
|
|
1012
|
+
});
|
|
1013
|
+
scopeDiscoveryTimings = scopeDiscovery.timings;
|
|
1014
|
+
testFiles = scopeDiscovery.catalog.entries
|
|
1015
|
+
.filter((entry) => entry.runner === config.runner)
|
|
438
1016
|
.map((entry) => entry.file);
|
|
439
1017
|
}
|
|
440
1018
|
catch {
|
|
@@ -446,6 +1024,11 @@ export async function runCheckGate(io, options) {
|
|
|
446
1024
|
const knownSourceFiles = [
|
|
447
1025
|
...new Set(pipeline.graph.resources.flatMap((resource) => resource.id === null ? [] : sourcesByResourceId(pipeline.graph, pipeline.behaviorCatalog).get(resource.id) ?? [])),
|
|
448
1026
|
];
|
|
1027
|
+
// 0.9.0 D2: the Gateforge-owned policy inputs of this change set are
|
|
1028
|
+
// classified here (check owns the candidate checkout; `scope.ts` stays
|
|
1029
|
+
// pure) so they never become unmapped product changes and their change
|
|
1030
|
+
// set can be recognized as product-behavior-neutral.
|
|
1031
|
+
const ownedInputs = gateforgeOwnedInputs(io.cwd, pipeline.changedFiles, config);
|
|
449
1032
|
scopeDecision = computeEvaluationScope({
|
|
450
1033
|
config,
|
|
451
1034
|
changedFiles: pipeline.changedFiles,
|
|
@@ -454,6 +1037,7 @@ export async function runCheckGate(io, options) {
|
|
|
454
1037
|
mappingSidecar: sidecar !== null,
|
|
455
1038
|
knownSourceFiles,
|
|
456
1039
|
strictE2E: config.enforcement?.strictE2E === true,
|
|
1040
|
+
policyInputs: [...ownedInputs.keys()],
|
|
457
1041
|
});
|
|
458
1042
|
// CHANGE_UNMAPPED (plan §5.4, E15): strict mode blocks unclassified
|
|
459
1043
|
// changes unless a resolved mapping covers the file (journey
|
|
@@ -469,7 +1053,14 @@ export async function runCheckGate(io, options) {
|
|
|
469
1053
|
'stay visible and blocking until mapped (strict E2E mode)',
|
|
470
1054
|
location: { file, line: 1, col: 0 },
|
|
471
1055
|
cause: 'CHANGE_UNMAPPED',
|
|
472
|
-
|
|
1056
|
+
// 0.9.0 problem 26: the remediation names the step that actually
|
|
1057
|
+
// attributes the file. `gateforge explain <file>` prints what the file
|
|
1058
|
+
// is and what governs it (a discovered resource, a gate input, or an
|
|
1059
|
+
// unclassified change) so the owner can map, declare or detect it.
|
|
1060
|
+
nextAction: `Attributing '${file}' starts with \`gateforge explain ${file}\`, which prints what the file is ` +
|
|
1061
|
+
'and what governs it: map the detected resource, declare documentation folders with ' +
|
|
1062
|
+
'`gateforge init --docs-exclude <folders>`, or add the detection that owns the file. ' +
|
|
1063
|
+
'Never weaken the policy.',
|
|
473
1064
|
}));
|
|
474
1065
|
mismatchBlocking = [...mismatchBlocking, ...unmappedBlocking];
|
|
475
1066
|
// The local-staged provider lists index changes, but discovery reads
|
|
@@ -488,6 +1079,8 @@ export async function runCheckGate(io, options) {
|
|
|
488
1079
|
changedFiles: scopeDecision.changedFiles,
|
|
489
1080
|
expandedBecause: scopeDecision.expandedBecause,
|
|
490
1081
|
unmappedFiles: scopeDecision.unmappedFiles,
|
|
1082
|
+
policyInputs: scopeDecision.policyInputs,
|
|
1083
|
+
policyInputsOnly: scopeDecision.policyInputsOnly,
|
|
491
1084
|
};
|
|
492
1085
|
mismatchBlocking = [
|
|
493
1086
|
...mismatchBlocking,
|
|
@@ -504,24 +1097,119 @@ export async function runCheckGate(io, options) {
|
|
|
504
1097
|
}
|
|
505
1098
|
}
|
|
506
1099
|
}
|
|
507
|
-
//
|
|
508
|
-
//
|
|
509
|
-
//
|
|
1100
|
+
// 0.9.0 D2: the adopted baseline is a recorded, shrink-only statement of
|
|
1101
|
+
// pre-existing debt, not an owner risk acceptance, so it survives the
|
|
1102
|
+
// strict-E2E re-grade while a change set is provably product-behavior-
|
|
1103
|
+
// neutral: Gateforge-owned policy inputs only (the scope for those files is
|
|
1104
|
+
// unchanged — they keep expanding as gate-defining inputs exactly as
|
|
1105
|
+
// today). The forgiveness is granted only when the owner has pinned the
|
|
1106
|
+
// policy revision that governs those files: a mismatching pin still blocks
|
|
1107
|
+
// on its own, and with no pin today's reporting stays (adopted debt is
|
|
1108
|
+
// re-graded as blocking). An owner waiver is never forgiveness here.
|
|
1109
|
+
const adoptedBaselineSurvivesStrictE2E = diffScoped &&
|
|
1110
|
+
scopeDecision.policyInputsOnly &&
|
|
1111
|
+
evaluateApprovedPolicy(docsApprovalResolution ??
|
|
1112
|
+
resolveApprovedPolicyDigest({
|
|
1113
|
+
flag: options.approvedPolicyDigest,
|
|
1114
|
+
env: io.env,
|
|
1115
|
+
candidateCwd: io.cwd,
|
|
1116
|
+
candidateConfig: config,
|
|
1117
|
+
}), docsApprovalDigest ?? trustedPolicyDigestForConfig(io.cwd, config), config.enforcement?.strictE2E === true || hasOwnerExclusions).status === 'enforced';
|
|
1118
|
+
// Static annotations are compared with generated sidecar entries. The
|
|
1119
|
+
// advisory is deliberately separate from blockers for this warning-only
|
|
1120
|
+
// release period; only the tracked sidecar and a verified receipt bind
|
|
1121
|
+
// claims during check.
|
|
1122
|
+
// Environment-dependent registration warnings are stderr advisories;
|
|
1123
|
+
// they never declare claims or alter the gate result.
|
|
1124
|
+
const currentTestMap = loadOptionalTestMap(io.cwd);
|
|
1125
|
+
const annotationScanStartedAtMs = performance.now();
|
|
1126
|
+
const annotationScan = scanTestFiles({
|
|
1127
|
+
cwd: io.cwd,
|
|
1128
|
+
include: config.project.paths.include,
|
|
1129
|
+
exclude: config.project.paths.exclude,
|
|
1130
|
+
excludeFile: engineGeneratedStateFileFilter(io.cwd, stateDir),
|
|
1131
|
+
});
|
|
1132
|
+
const tsScanMs = performance.now() - annotationScanStartedAtMs;
|
|
1133
|
+
for (const warning of annotationScan.registrationWarnings) {
|
|
1134
|
+
writeLine(io.stderr, `check: registration warning ${warning.file}:${String(warning.location.line)}: ` +
|
|
1135
|
+
`${warning.titlePath.join(' > ')} is conditional on ${warning.environmentVariable}; ` +
|
|
1136
|
+
'keep test registration independent of Gateforge run variables');
|
|
1137
|
+
}
|
|
1138
|
+
const annotationAdvisories = annotationMapSyncAdvisories(annotationScan, currentTestMap);
|
|
1139
|
+
const mockedOnlyAdvisories = mockedOnlyEndpointAdvisories(pipeline.endpointInventory.endpoints, annotationScan.entries);
|
|
510
1140
|
let claimInventory = claimBindings;
|
|
511
1141
|
let mappingBlockers = [];
|
|
512
1142
|
let mappedCoverage = [];
|
|
513
|
-
|
|
1143
|
+
let mappingDiscoveryTimings;
|
|
1144
|
+
const pytestCacheCounts = { hits: 0, misses: 0 };
|
|
1145
|
+
const pytestCollection = async (suite, suiteCwd, collectorArgv, collect) => {
|
|
1146
|
+
if (cacheControl.disabled)
|
|
1147
|
+
return collect();
|
|
1148
|
+
const inputDigest = digestPytestInputs(io.cwd, stateDir, cacheControl.stateDir);
|
|
1149
|
+
const collectorEnv = { ...untrustedEnv(io.env), PYTHONDONTWRITEBYTECODE: '1' };
|
|
1150
|
+
const collectorInterpreter = interpreterIdentity(collectorArgv[0] ?? '', collectorEnv);
|
|
1151
|
+
if (inputDigest === null || collectorInterpreter === null) {
|
|
1152
|
+
pytestCacheCounts.misses += 1;
|
|
1153
|
+
return collect();
|
|
1154
|
+
}
|
|
1155
|
+
const environmentDigest = createHash('sha256')
|
|
1156
|
+
.update(JSON.stringify(Object.entries(collectorEnv).sort(([a], [b]) => a.localeCompare(b))))
|
|
1157
|
+
.digest('hex');
|
|
1158
|
+
const key = pytestCacheKey({
|
|
1159
|
+
name: suite.name,
|
|
1160
|
+
cwd: suiteCwd,
|
|
1161
|
+
argv: suite.argv,
|
|
1162
|
+
collectorArgv,
|
|
1163
|
+
testPaths: suite.testPaths,
|
|
1164
|
+
timeoutMs: suite.timeoutMs,
|
|
1165
|
+
}, inputDigest, collectorInterpreter, environmentDigest);
|
|
1166
|
+
let cached = null;
|
|
1167
|
+
try {
|
|
1168
|
+
cached = readPytestCache(cacheControl.stateDir, key);
|
|
1169
|
+
}
|
|
1170
|
+
catch {
|
|
1171
|
+
cached = null;
|
|
1172
|
+
}
|
|
1173
|
+
if (isPytestCollectionResult(cached)) {
|
|
1174
|
+
pytestCacheCounts.hits += 1;
|
|
1175
|
+
return cached;
|
|
1176
|
+
}
|
|
1177
|
+
pytestCacheCounts.misses += 1;
|
|
1178
|
+
const result = await collect();
|
|
1179
|
+
if (result.status === 'discovered' && result.exitCode === 0) {
|
|
1180
|
+
try {
|
|
1181
|
+
writePytestCache(cacheControl.stateDir, key, result);
|
|
1182
|
+
}
|
|
1183
|
+
catch {
|
|
1184
|
+
// Storage failure costs only a future miss; collection is authoritative.
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return result;
|
|
1188
|
+
};
|
|
1189
|
+
if (currentTestMap !== null) {
|
|
514
1190
|
const mapped = await resolveRepositoryMappings({
|
|
515
1191
|
cwd: io.cwd,
|
|
516
1192
|
config,
|
|
1193
|
+
stateDir,
|
|
517
1194
|
obligations: pipeline.policy.obligations,
|
|
518
1195
|
claimBindings,
|
|
519
1196
|
behaviorCatalog: pipeline.behaviorCatalog,
|
|
1197
|
+
pytestCollection,
|
|
520
1198
|
});
|
|
1199
|
+
mappingDiscoveryTimings = mapped.discoveryTimings;
|
|
521
1200
|
claimInventory = mapped.claimInventory;
|
|
522
|
-
mappingBlockers =
|
|
1201
|
+
mappingBlockers = [
|
|
1202
|
+
...mappingBlocking(mapped.resolution.problems),
|
|
1203
|
+
...nativeInventoryBlocking(mapped.nativeLoadProblem),
|
|
1204
|
+
];
|
|
523
1205
|
mappedCoverage = mappedCoverageFrom(mapped.resolution, pipeline.policy.obligations, pipeline.graph);
|
|
524
1206
|
}
|
|
1207
|
+
const adoptedBaseline = resolveAdoptedBaseline(io.cwd, config.baselines);
|
|
1208
|
+
// A re-sealed run grades the evidence UNION: this run's own records
|
|
1209
|
+
// plus the parent's carried ones, authenticated by the retained
|
|
1210
|
+
// parent envelope. `resealChainBlocking` below is what recomputes the
|
|
1211
|
+
// whole chain and fails closed on any difference.
|
|
1212
|
+
const carriedEvidence = retainedCarriedEvidence(stateDir);
|
|
525
1213
|
const evaluated = evaluateRun({
|
|
526
1214
|
cwd: io.cwd,
|
|
527
1215
|
config,
|
|
@@ -534,15 +1222,23 @@ export async function runCheckGate(io, options) {
|
|
|
534
1222
|
blocking: [...pipeline.policy.blocking, ...mismatchBlocking, ...mappingBlockers],
|
|
535
1223
|
stateDir,
|
|
536
1224
|
now: pipeline.now,
|
|
1225
|
+
engineAlembicRecords: pipeline.engineAlembicRecords,
|
|
537
1226
|
// One effective scope (§12.2), decided before grading: an expanded
|
|
538
1227
|
// (gate-defining) diff evaluates everything — obligations AND
|
|
539
1228
|
// blockers — exactly like the unrestricted run.
|
|
540
|
-
|
|
1229
|
+
// Only an EXPLICIT `--changed` narrows what gets graded. `mode:
|
|
1230
|
+
// changed` reuses the same scope computation for its DECISION while
|
|
1231
|
+
// the full debt stays in the report — that is the whole difference
|
|
1232
|
+
// between the two.
|
|
1233
|
+
changedFiles: diffScoped && scopeDecision.mode !== 'all' ? scopeDecision.changedFiles : null,
|
|
541
1234
|
claimInventory,
|
|
542
1235
|
mappedCoverage,
|
|
543
1236
|
witnessVerifierKey,
|
|
544
1237
|
witnessVerifierKeys: verifierKeyring?.keys.map((entry) => entry.key),
|
|
545
|
-
|
|
1238
|
+
...(carriedEvidence === null ? {} : { carriedEvidence }),
|
|
1239
|
+
baseline: adoptedBaseline,
|
|
1240
|
+
// 0.9.0 D2: see `adoptedBaselineSurvivesStrictE2E` above.
|
|
1241
|
+
adoptedBaselineSurvivesStrictE2E,
|
|
546
1242
|
evidenceContext: {
|
|
547
1243
|
expectedInputDigest: expectedDigest,
|
|
548
1244
|
snapshotUnavailable,
|
|
@@ -550,6 +1246,59 @@ export async function runCheckGate(io, options) {
|
|
|
550
1246
|
changedInputs,
|
|
551
1247
|
},
|
|
552
1248
|
});
|
|
1249
|
+
const baselineReport = adoptedBaseline === null
|
|
1250
|
+
? undefined
|
|
1251
|
+
: {
|
|
1252
|
+
obligations: evaluated.baselined?.obligations ?? 0,
|
|
1253
|
+
blockingEntries: evaluated.baselined?.blockingEntries ?? 0,
|
|
1254
|
+
...(evaluated.baselined?.classificationBlocked !== undefined
|
|
1255
|
+
? { classificationBlocked: evaluated.baselined.classificationBlocked }
|
|
1256
|
+
: {}),
|
|
1257
|
+
adoptedAt: adoptedBaseline.adoptedAt,
|
|
1258
|
+
ageDays: Math.max(0, Math.floor((Date.parse(pipeline.now) - Date.parse(adoptedBaseline.adoptedAt)) / 86_400_000)),
|
|
1259
|
+
neverWitnessed: evaluated.baselined?.neverWitnessed ?? 0,
|
|
1260
|
+
};
|
|
1261
|
+
const baselineDriftAdvisories = [];
|
|
1262
|
+
if (scopeDecision.mode === 'changed' &&
|
|
1263
|
+
adoptedBaseline?.obligationFingerprintsById !== undefined &&
|
|
1264
|
+
adoptedBaseline.obligationSourcesById !== undefined) {
|
|
1265
|
+
const currentSources = sourcesByResourceId(pipeline.graph, pipeline.behaviorCatalog);
|
|
1266
|
+
const currentFingerprints = new Map(pipeline.policy.obligations.map((obligation) => [
|
|
1267
|
+
obligation.id,
|
|
1268
|
+
obligationFingerprint(obligation),
|
|
1269
|
+
]));
|
|
1270
|
+
const lostByFile = new Map();
|
|
1271
|
+
for (const [id, oldFingerprint] of adoptedBaseline.obligationFingerprintsById) {
|
|
1272
|
+
const currentFingerprint = currentFingerprints.get(id);
|
|
1273
|
+
if (currentFingerprint === undefined ||
|
|
1274
|
+
currentFingerprint === oldFingerprint ||
|
|
1275
|
+
!adoptedBaseline.fingerprints.has(oldFingerprint)) {
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
const sourcePaths = new Set([
|
|
1279
|
+
...(adoptedBaseline.obligationSourcesById.get(id) ?? []),
|
|
1280
|
+
...(currentSources.get(id) ?? []),
|
|
1281
|
+
]);
|
|
1282
|
+
for (const file of scopeDecision.changedFiles) {
|
|
1283
|
+
if (!sourcePaths.has(file))
|
|
1284
|
+
continue;
|
|
1285
|
+
const obligations = lostByFile.get(file) ?? new Set();
|
|
1286
|
+
obligations.add(id);
|
|
1287
|
+
lostByFile.set(file, obligations);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
for (const [file, obligations] of [...lostByFile].sort(([a], [b]) => a.localeCompare(b))) {
|
|
1291
|
+
baselineDriftAdvisories.push({
|
|
1292
|
+
kind: 'finding',
|
|
1293
|
+
resourceId: null,
|
|
1294
|
+
name: null,
|
|
1295
|
+
detail: `${obligations.size} adopted baseline obligation(s) lost their baseline because ${file} changed`,
|
|
1296
|
+
location: null,
|
|
1297
|
+
cause: null,
|
|
1298
|
+
nextAction: 'Compare baseline files with `gateforge baseline diff <before> <after>`.',
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
553
1302
|
// `--require-e2e` (plan Phase 4 item 5, ADR 0005 D3): the strict
|
|
554
1303
|
// saved-state gate. Without a valid, non-stale receipt for the CURRENT
|
|
555
1304
|
// input digest the run blocks — missing receipt (RUN_INCOMPLETE),
|
|
@@ -616,7 +1365,7 @@ export async function runCheckGate(io, options) {
|
|
|
616
1365
|
candidateCwd: io.cwd,
|
|
617
1366
|
candidateConfig: config,
|
|
618
1367
|
});
|
|
619
|
-
const gate = evaluateApprovedPolicy(resolution, candidatePolicyDigest, config.enforcement?.strictE2E === true ||
|
|
1368
|
+
const gate = evaluateApprovedPolicy(resolution, candidatePolicyDigest, config.enforcement?.strictE2E === true || hasOwnerExclusions);
|
|
620
1369
|
if (gate.status === 'blocked') {
|
|
621
1370
|
diagnosticEvidenceState = 'owner-policy-blocked';
|
|
622
1371
|
receiptBlocking = [
|
|
@@ -633,11 +1382,12 @@ export async function runCheckGate(io, options) {
|
|
|
633
1382
|
}
|
|
634
1383
|
else {
|
|
635
1384
|
const gitDir = resolveGitDir(io.cwd, io.env);
|
|
636
|
-
const
|
|
637
|
-
?
|
|
638
|
-
: gitDir
|
|
639
|
-
|
|
640
|
-
|
|
1385
|
+
const candidateTreeSnapshot = gitDir === null
|
|
1386
|
+
? null
|
|
1387
|
+
: computeCandidateTreeSnapshot(gitDir, io.cwd, io.env, stateDir, 'record', runtimeReuseMounts, docsExclusions, cacheExclusions);
|
|
1388
|
+
const candidateTreeId = docsExclusions.length > 0 || cacheExclusions.length > 0
|
|
1389
|
+
? (candidateTreeSnapshot?.treeId ?? null)
|
|
1390
|
+
: (options.fixedCandidateTreeId ?? candidateTreeSnapshot?.treeId ?? null);
|
|
641
1391
|
diagnosticCandidateTreeId = candidateTreeId;
|
|
642
1392
|
const load = loadReceiptFor(stateDir, verifierKeyring, {
|
|
643
1393
|
inputDigest: expectedDigest,
|
|
@@ -653,11 +1403,31 @@ export async function runCheckGate(io, options) {
|
|
|
653
1403
|
});
|
|
654
1404
|
diagnosticEvidenceState = load.status === 'ok' ? 'receipt-verified' : `receipt-${load.status}`;
|
|
655
1405
|
if (load.status === 'ok') {
|
|
1406
|
+
if (load.receipt.engine !== undefined &&
|
|
1407
|
+
load.receipt.engine.version !== engineIdentity().version) {
|
|
1408
|
+
const detail = `require-e2e: receipt engine version '${load.receipt.engine.version}' differs from ` +
|
|
1409
|
+
`installed version '${engineIdentity().version}'`;
|
|
1410
|
+
receiptBlocking = [
|
|
1411
|
+
{
|
|
1412
|
+
kind: 'finding',
|
|
1413
|
+
resourceId: null,
|
|
1414
|
+
name: null,
|
|
1415
|
+
detail: humanMessage({
|
|
1416
|
+
cause: 'ENFORCEMENT_UNTRUSTED',
|
|
1417
|
+
detail,
|
|
1418
|
+
nextAction: 'gateforge test-gates --changed',
|
|
1419
|
+
}),
|
|
1420
|
+
location: null,
|
|
1421
|
+
cause: 'ENFORCEMENT_UNTRUSTED',
|
|
1422
|
+
nextAction: 'gateforge test-gates --changed',
|
|
1423
|
+
},
|
|
1424
|
+
];
|
|
1425
|
+
}
|
|
656
1426
|
// A provisioned pin binds the receipt too: a receipt sealed
|
|
657
1427
|
// under a since-revoked/different approved revision is a typed
|
|
658
1428
|
// reject, and under a pin the binding must be present. When the
|
|
659
1429
|
// binding decides, the coverage check below is skipped.
|
|
660
|
-
if (gate.status === 'enforced') {
|
|
1430
|
+
if (receiptBlocking.length === 0 && gate.status === 'enforced') {
|
|
661
1431
|
const binding = assertReceiptApprovedPolicy(load.receipt, gate.approved);
|
|
662
1432
|
if (!binding.ok) {
|
|
663
1433
|
receiptBlocking = [
|
|
@@ -678,6 +1448,25 @@ export async function runCheckGate(io, options) {
|
|
|
678
1448
|
// changed-scope receipt must cover every obligation this
|
|
679
1449
|
// evaluation demands or the typed blocker names the gap.
|
|
680
1450
|
receiptBlocking = scopedReceiptCoverageBlocking(load.receipt, requiredCoverage());
|
|
1451
|
+
// Re-seal recomputation (plan phase 3): a `test-only`
|
|
1452
|
+
// receipt is a claim. The chain it names is authenticated
|
|
1453
|
+
// with THIS keyring, the two sealed trees are re-diffed
|
|
1454
|
+
// with THIS engine, the change set is re-classified and
|
|
1455
|
+
// the affected set recomputed — any difference is a typed
|
|
1456
|
+
// EVIDENCE_STALE naming the exact mismatch.
|
|
1457
|
+
if (receiptBlocking.length === 0 && load.receipt.resealedFrom !== undefined) {
|
|
1458
|
+
receiptBlocking = resealChainBlocking({
|
|
1459
|
+
stateDir,
|
|
1460
|
+
receipt: load.receipt,
|
|
1461
|
+
verifierKeyring,
|
|
1462
|
+
gitDir,
|
|
1463
|
+
cwd: io.cwd,
|
|
1464
|
+
env: io.env,
|
|
1465
|
+
...(config.enforcement?.resealRuntimeFiles !== undefined
|
|
1466
|
+
? { runtimeFileGlobs: config.enforcement.resealRuntimeFiles }
|
|
1467
|
+
: {}),
|
|
1468
|
+
}).map((entry) => ({ ...entry, detail: `require-e2e: ${entry.detail}` }));
|
|
1469
|
+
}
|
|
681
1470
|
}
|
|
682
1471
|
if (receiptBlocking.length > 0)
|
|
683
1472
|
diagnosticEvidenceState = 'receipt-verified-with-blocking-entry';
|
|
@@ -686,31 +1475,99 @@ export async function runCheckGate(io, options) {
|
|
|
686
1475
|
receiptBlocking = receiptGateBlocking(load);
|
|
687
1476
|
if (load.status === 'stale') {
|
|
688
1477
|
const changedPaths = authenticatedChangedInputs(stateDir, verifierKeyring, currentSnapshot);
|
|
1478
|
+
const docsOnly = changedPaths.length > 0 && changedPaths.every((path) => /^(?:docs?|guides?)\//i.test(path) || /\.(?:md|mdx|rst|txt)$/i.test(path));
|
|
689
1479
|
const changedSummary = changedPaths.length > 0
|
|
690
|
-
? ` changed inputs: ${changedPaths.join(', ')}.`
|
|
1480
|
+
? ` changed inputs: ${changedPaths.join(', ')}.` +
|
|
1481
|
+
(docsOnly
|
|
1482
|
+
? ' Only documentation paths changed; if these are approved documentation folders, run `gateforge init --docs-exclude <folders>`.'
|
|
1483
|
+
: '')
|
|
691
1484
|
: ' the saved input inventory is unavailable or the change is in gate context rather than file bytes.';
|
|
692
|
-
const
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
1485
|
+
const sealedTreeEntries = readCandidateTreeEntries(stateDir);
|
|
1486
|
+
const treeDiff = load.detail.toLowerCase().includes('candidate tree') &&
|
|
1487
|
+
candidateTreeSnapshot !== null &&
|
|
1488
|
+
sealedTreeEntries !== null
|
|
1489
|
+
? candidateTreeMismatchSummary(sealedTreeEntries, candidateTreeSnapshot.entries, io.cwd, stateDir, io.env)
|
|
1490
|
+
: '';
|
|
1491
|
+
// The engine-upgrade refusal is already one complete sentence
|
|
1492
|
+
// naming the cause and the fix; the changed-input summary
|
|
1493
|
+
// belongs to the digest line beside it. Both name the same one
|
|
1494
|
+
// command that re-seals.
|
|
1495
|
+
receiptBlocking = receiptBlocking.map((entry) => entry.detail.startsWith(ENGINE_UPGRADE_REFUSAL_PREFIX)
|
|
1496
|
+
? entry
|
|
1497
|
+
: {
|
|
1498
|
+
...entry,
|
|
1499
|
+
detail: `${entry.detail}${changedSummary}${treeDiff}`,
|
|
1500
|
+
nextAction: 'gateforge test-gates --changed',
|
|
1501
|
+
});
|
|
698
1502
|
}
|
|
699
1503
|
}
|
|
700
1504
|
}
|
|
701
1505
|
}
|
|
702
1506
|
}
|
|
1507
|
+
const inScopeSourcePaths = diffScoped && scopeDecision.mode === 'changed'
|
|
1508
|
+
? sourcesByResourceId(pipeline.graph, pipeline.behaviorCatalog)
|
|
1509
|
+
: null;
|
|
1510
|
+
const changedSourcePaths = new Set(scopeDecision.changedFiles);
|
|
1511
|
+
// Scope metadata stays exactly as a non-diff run reports it unless the
|
|
1512
|
+
// caller actually asked for `--changed`.
|
|
1513
|
+
const reportScope = {
|
|
1514
|
+
mode: diffScoped ? scopeDecision.mode : 'all',
|
|
1515
|
+
expandedBecause: diffScoped ? scopeDecision.expandedBecause : [],
|
|
1516
|
+
};
|
|
1517
|
+
const reportVerdicts = inScopeSourcePaths === null
|
|
1518
|
+
? evaluated.verdicts
|
|
1519
|
+
: evaluated.verdicts.map((verdict) => ({
|
|
1520
|
+
...verdict,
|
|
1521
|
+
inScopeBecause: [
|
|
1522
|
+
...new Set(inScopeSourcePaths.get(verdict.obligation.resourceId) ?? []),
|
|
1523
|
+
]
|
|
1524
|
+
.filter((file) => changedSourcePaths.has(file))
|
|
1525
|
+
.sort(),
|
|
1526
|
+
}));
|
|
703
1527
|
const evaluatedBlocking = [...evaluated.blocking, ...receiptBlocking];
|
|
704
|
-
const
|
|
1528
|
+
const newDebt = diffScoped
|
|
1529
|
+
? reportVerdicts
|
|
1530
|
+
.filter((verdict) => BLOCKING_VERDICTS.includes(verdict.verdict))
|
|
1531
|
+
.map((verdict) => verdict.obligation.id)
|
|
1532
|
+
.sort()
|
|
1533
|
+
: null;
|
|
1534
|
+
const adapterFindings = await adapterAdvisories(io.cwd, pipeline, evaluated.verdicts, stateDir);
|
|
1535
|
+
// Per-tenant singletons (plan Phase 4b item 3): one advisory per tagged
|
|
1536
|
+
// resource that owes a create. Absent the tag this is an empty list, so
|
|
1537
|
+
// a repo without one is byte-identical.
|
|
1538
|
+
const singletonFindings = singletonPerTenantAdvisories(pipeline.graph.resources, new Set(evaluated.verdicts
|
|
1539
|
+
.filter((verdict) => verdict.obligation.contract === 'persistence:create')
|
|
1540
|
+
.map((verdict) => verdict.obligation.resourceId)));
|
|
1541
|
+
let report = renderRun(reportVerdicts, {
|
|
705
1542
|
format,
|
|
706
1543
|
blocking: evaluatedBlocking,
|
|
1544
|
+
advisories: [
|
|
1545
|
+
...annotationAdvisories,
|
|
1546
|
+
...mockedOnlyAdvisories,
|
|
1547
|
+
...baselineDriftAdvisories,
|
|
1548
|
+
...adapterFindings,
|
|
1549
|
+
...singletonFindings,
|
|
1550
|
+
// Frontend reads a response field the model does not declare (plan
|
|
1551
|
+
// Phase 4b item 5). One non-blocking advisory per gap; empty unless
|
|
1552
|
+
// a joined endpoint pairs a proven response model with a read, so
|
|
1553
|
+
// a repository without both packs renders byte-identically.
|
|
1554
|
+
...responseFieldAdvisories(pipeline.endpointInventory.endpoints),
|
|
1555
|
+
// Unmatched by-id routes the owner graded as advisory (0.9.0,
|
|
1556
|
+
// owner decision D7). Same code, advisory channel, never blocking:
|
|
1557
|
+
// the entries are already out of `pipeline.policy.blocking`, so
|
|
1558
|
+
// the exit code and `check --changed` are untouched.
|
|
1559
|
+
...pipeline.unmatchedRouteAdvisories,
|
|
1560
|
+
],
|
|
707
1561
|
waiverCounts: evaluated.waiverCounts,
|
|
708
|
-
baseline:
|
|
1562
|
+
baseline: baselineReport,
|
|
709
1563
|
run: pipeline.manifest,
|
|
710
1564
|
toolVersion: VERSION,
|
|
711
|
-
|
|
1565
|
+
engine: engineIdentity(),
|
|
1566
|
+
engineLine: reportEngineLine(),
|
|
1567
|
+
lifecycleDerivation: pipeline.lifecycleDerivation,
|
|
1568
|
+
scope: reportScope,
|
|
712
1569
|
diagnosticContext: {
|
|
713
|
-
scope:
|
|
1570
|
+
scope: reportScope.mode === 'changed' ? 'changed' : 'full',
|
|
714
1571
|
candidateTreeId: diagnosticCandidateTreeId,
|
|
715
1572
|
inputDigest: expectedDigest,
|
|
716
1573
|
evidenceState: diagnosticEvidenceState,
|
|
@@ -725,8 +1582,155 @@ export async function runCheckGate(io, options) {
|
|
|
725
1582
|
guarantee: DOCS_EXCLUSIONS_GUARANTEE,
|
|
726
1583
|
},
|
|
727
1584
|
}),
|
|
1585
|
+
...(cacheExclusions.length === 0
|
|
1586
|
+
? {}
|
|
1587
|
+
: {
|
|
1588
|
+
cacheExclusions: {
|
|
1589
|
+
files: cacheExclusions,
|
|
1590
|
+
approvalDigest: docsApprovalResolution?.status === 'ok' ? docsApprovalResolution.digest : null,
|
|
1591
|
+
approvalStatus: docsApprovalStatus ?? 'missing',
|
|
1592
|
+
guarantee: CACHE_EXCLUSIONS_GUARANTEE,
|
|
1593
|
+
},
|
|
1594
|
+
}),
|
|
728
1595
|
},
|
|
729
1596
|
});
|
|
1597
|
+
// Unmatched by-id routes the owner graded as advisory (0.9.0, owner
|
|
1598
|
+
// decision D7): loud at the TOP of the text report, not buried in the
|
|
1599
|
+
// advisory tail, because a demoted finding must be impossible to miss.
|
|
1600
|
+
// The JSON document keeps them in `advisories` under the same code.
|
|
1601
|
+
if (format === 'text') {
|
|
1602
|
+
const banner = unmatchedRouteBannerLines(pipeline.unmatchedRouteAdvisories, pipeline.unmatchedRoutesMode);
|
|
1603
|
+
if (banner.length > 0)
|
|
1604
|
+
report = `${banner.join('\n')}\n${report}`;
|
|
1605
|
+
}
|
|
1606
|
+
if (newDebt !== null) {
|
|
1607
|
+
if (format === 'json') {
|
|
1608
|
+
const document = JSON.parse(report);
|
|
1609
|
+
report = canonicalJson({ ...document, newDebt: { count: newDebt.length, obligationIds: newDebt } });
|
|
1610
|
+
}
|
|
1611
|
+
else if (format === 'text') {
|
|
1612
|
+
const debtLine = humanMessage({
|
|
1613
|
+
detail: `this change adds ${String(newDebt.length)} unproven obligations: ${newDebt.join(', ') || '<none>'}`,
|
|
1614
|
+
type: 'new-debt',
|
|
1615
|
+
nextAction: 'gateforge test-gates --changed',
|
|
1616
|
+
});
|
|
1617
|
+
report = `${report}\n${debtLine}`;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
if (options.timing === true) {
|
|
1621
|
+
// Per-step wall-clock timings: additive
|
|
1622
|
+
// observability behind `--timing`, never an input to any verdict.
|
|
1623
|
+
const collectionMs = (scopeDiscoveryTimings?.totalMs ?? 0) + (mappingDiscoveryTimings?.totalMs ?? 0);
|
|
1624
|
+
const timing = {
|
|
1625
|
+
detectorsMs: Math.round(pipeline.timings.pluginsMs),
|
|
1626
|
+
collectionMs: Math.round(collectionMs),
|
|
1627
|
+
tsScanMs: Math.round(tsScanMs),
|
|
1628
|
+
planningMs: Math.round(pipeline.timings.totalMs - pipeline.timings.pluginsMs),
|
|
1629
|
+
totalMs: Math.round(performance.now() - gateStartedAtMs),
|
|
1630
|
+
};
|
|
1631
|
+
if (format === 'json') {
|
|
1632
|
+
const document = JSON.parse(report);
|
|
1633
|
+
report = canonicalJson({ ...document, timing });
|
|
1634
|
+
}
|
|
1635
|
+
else if (format === 'text') {
|
|
1636
|
+
report =
|
|
1637
|
+
`${report}\ntiming: detectors=${String(timing.detectorsMs)}ms collection=${String(timing.collectionMs)}ms ` +
|
|
1638
|
+
`tsScan=${String(timing.tsScanMs)}ms planning=${String(timing.planningMs)}ms total=${String(timing.totalMs)}ms`;
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
{
|
|
1642
|
+
// Cache accounting (additive `cache` key): how
|
|
1643
|
+
// many detector/pytest results were reused vs recomputed. Never an
|
|
1644
|
+
// input to any verdict.
|
|
1645
|
+
const cacheCounts = {
|
|
1646
|
+
hits: pipeline.cache.hits + pytestCacheCounts.hits,
|
|
1647
|
+
misses: pipeline.cache.misses + pytestCacheCounts.misses,
|
|
1648
|
+
};
|
|
1649
|
+
if (format === 'json') {
|
|
1650
|
+
const document = JSON.parse(report);
|
|
1651
|
+
report = canonicalJson({ ...document, cache: { hits: cacheCounts.hits, misses: cacheCounts.misses } });
|
|
1652
|
+
}
|
|
1653
|
+
else if (format === 'text' && cacheCounts.hits + cacheCounts.misses > 0) {
|
|
1654
|
+
report = `${report}\ncache: ${String(cacheCounts.hits)} hit(s), ${String(cacheCounts.misses)} miss(es)`;
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
// Owner-chosen strictness: the decision
|
|
1658
|
+
// is a pure mapping of the strict result that was ALREADY computed, so
|
|
1659
|
+
// no mode can change what was evaluated. Exit 2 (config/usage) keeps
|
|
1660
|
+
// its meaning; only the debt exit 1 is ever softened.
|
|
1661
|
+
const strictExit = runExitCode({ verdicts: evaluated.verdicts, blocking: evaluatedBlocking });
|
|
1662
|
+
const blockingTotal = evaluated.verdicts.filter((verdict) => BLOCKING_VERDICTS.includes(verdict.verdict)).length +
|
|
1663
|
+
evaluatedBlocking.length;
|
|
1664
|
+
const sourcePaths = sourcesByResourceId(pipeline.graph, pipeline.behaviorCatalog);
|
|
1665
|
+
const decision = decideStrictness({
|
|
1666
|
+
mode: gateMode,
|
|
1667
|
+
strictExitCode: strictExit,
|
|
1668
|
+
blockingTotal,
|
|
1669
|
+
// An expanded scope (a gate-defining input changed) is full scope:
|
|
1670
|
+
// the change owns all of the debt, exactly like `--changed` says.
|
|
1671
|
+
...(gateMode === 'changed'
|
|
1672
|
+
? {
|
|
1673
|
+
changed: {
|
|
1674
|
+
active: true,
|
|
1675
|
+
blockingInScope: scopeDecision.mode === 'changed'
|
|
1676
|
+
? evaluated.verdicts.filter((verdict) => BLOCKING_VERDICTS.includes(verdict.verdict) &&
|
|
1677
|
+
(sourcePaths.get(verdict.obligation.resourceId) ?? []).some((file) => changedSourcePaths.has(file))).length +
|
|
1678
|
+
scopeBlocking(evaluatedBlocking, changedSourcePaths, sourcePaths).length
|
|
1679
|
+
: blockingTotal,
|
|
1680
|
+
},
|
|
1681
|
+
}
|
|
1682
|
+
: {}),
|
|
1683
|
+
});
|
|
1684
|
+
if (decision.wouldBlock && decision.exitCode !== decision.strictExitCode) {
|
|
1685
|
+
// The softened decision is announced on stderr too: a CI log that
|
|
1686
|
+
// only keeps stdout must not read as "nothing was wrong".
|
|
1687
|
+
writeLine(io.stderr, `check: ${strictnessSummaryLine(decision)} — the gate exits 0 in mode '${decision.mode}', ` +
|
|
1688
|
+
`strict mode would exit ${String(decision.strictExitCode)}`);
|
|
1689
|
+
}
|
|
1690
|
+
const quarantineLine = quarantines.active.length === 0
|
|
1691
|
+
? ''
|
|
1692
|
+
: `quarantined: ${String(quarantines.active.length)} (expires ${quarantines.active
|
|
1693
|
+
.map((entry) => `${entry.quarantine.testKey} @ ${entry.quarantine.expiresAt}`)
|
|
1694
|
+
.join(', ')})`;
|
|
1695
|
+
if (format === 'json') {
|
|
1696
|
+
if (gateMode !== 'strict' || quarantines.active.length > 0) {
|
|
1697
|
+
const document = JSON.parse(report);
|
|
1698
|
+
report = canonicalJson({
|
|
1699
|
+
...document,
|
|
1700
|
+
...(gateMode === 'strict'
|
|
1701
|
+
? {}
|
|
1702
|
+
: {
|
|
1703
|
+
strictness: {
|
|
1704
|
+
mode: decision.mode,
|
|
1705
|
+
wouldBlock: decision.wouldBlock,
|
|
1706
|
+
blockingInScope: decision.blockingInScope,
|
|
1707
|
+
blockingTotal: decision.blockingTotal,
|
|
1708
|
+
},
|
|
1709
|
+
}),
|
|
1710
|
+
...(quarantines.active.length === 0
|
|
1711
|
+
? {}
|
|
1712
|
+
: {
|
|
1713
|
+
quarantine: {
|
|
1714
|
+
count: quarantines.active.length,
|
|
1715
|
+
tests: quarantines.active.map((entry) => ({
|
|
1716
|
+
testKey: entry.quarantine.testKey,
|
|
1717
|
+
expiresAt: entry.quarantine.expiresAt,
|
|
1718
|
+
owner: entry.quarantine.owner,
|
|
1719
|
+
})),
|
|
1720
|
+
},
|
|
1721
|
+
}),
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
else if (format === 'text') {
|
|
1726
|
+
// Text only: SARIF must stay machine-parseable JSON, and the json
|
|
1727
|
+
// document carries the structured blocks above. The report's own
|
|
1728
|
+
// `exit code:` line always carries the strict result; when this mode
|
|
1729
|
+
// softened it, the line is labelled as the value a blocking mode
|
|
1730
|
+
// would have produced, so it can never contradict the code the
|
|
1731
|
+
// process actually exits with.
|
|
1732
|
+
report = `${labelSoftenedExitCode(report, decision.strictExitCode, decision.exitCode)}\n${strictnessSummaryLine(decision)}${quarantineLine === '' ? '' : `\n${quarantineLine}`}`;
|
|
1733
|
+
}
|
|
730
1734
|
if (format === 'text') {
|
|
731
1735
|
// Plan phase 7: the endpoint inventory rides the text report —
|
|
732
1736
|
// totals, unmatched calls, unconsumed routes, and ambiguous joins
|
|
@@ -739,6 +1743,6 @@ export async function runCheckGate(io, options) {
|
|
|
739
1743
|
'plus a provenanced claimed ui anchor (see ADR 0004 D7/D8).');
|
|
740
1744
|
}
|
|
741
1745
|
writeLine(io.stdout, report);
|
|
742
|
-
return
|
|
1746
|
+
return decision.exitCode;
|
|
743
1747
|
}
|
|
744
1748
|
//# sourceMappingURL=check.js.map
|