@gate-forge/cli 0.6.3 → 0.7.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 +117 -20
- package/dist/args.js +1 -1
- package/dist/args.js.map +1 -1
- package/dist/broker.d.ts.map +1 -1
- package/dist/broker.js +19 -10
- package/dist/broker.js.map +1 -1
- package/dist/candidate-tree.d.ts +2 -1
- package/dist/candidate-tree.d.ts.map +1 -1
- package/dist/candidate-tree.js +66 -4
- package/dist/candidate-tree.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/blocking.d.ts +7 -4
- package/dist/commands/blocking.d.ts.map +1 -1
- package/dist/commands/blocking.js +116 -40
- package/dist/commands/blocking.js.map +1 -1
- package/dist/commands/check.d.ts +10 -0
- package/dist/commands/check.d.ts.map +1 -1
- package/dist/commands/check.js +146 -33
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/common.d.ts +4 -2
- package/dist/commands/common.d.ts.map +1 -1
- package/dist/commands/common.js +4 -2
- package/dist/commands/common.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +105 -165
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/keys.d.ts +6 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +72 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +23 -21
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/pre-commit.d.ts.map +1 -1
- package/dist/commands/pre-commit.js +21 -8
- package/dist/commands/pre-commit.js.map +1 -1
- package/dist/commands/test-gates.d.ts +12 -4
- package/dist/commands/test-gates.d.ts.map +1 -1
- package/dist/commands/test-gates.js +357 -75
- 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 +37 -3
- package/dist/commands/tests.js.map +1 -1
- package/dist/docs-exclusions.d.ts +12 -0
- package/dist/docs-exclusions.d.ts.map +1 -0
- package/dist/docs-exclusions.js +211 -0
- package/dist/docs-exclusions.js.map +1 -0
- package/dist/evaluate.d.ts +8 -12
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +53 -11
- package/dist/evaluate.js.map +1 -1
- package/dist/execution.d.ts +7 -3
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js +9 -2
- package/dist/execution.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/input-snapshot.d.ts +30 -6
- package/dist/input-snapshot.d.ts.map +1 -1
- package/dist/input-snapshot.js +58 -21
- package/dist/input-snapshot.js.map +1 -1
- package/dist/mapping.d.ts +18 -30
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +75 -51
- package/dist/mapping.js.map +1 -1
- package/dist/package-compatibility.d.ts +27 -0
- package/dist/package-compatibility.d.ts.map +1 -0
- package/dist/package-compatibility.js +112 -0
- package/dist/package-compatibility.js.map +1 -0
- package/dist/receipts.d.ts +13 -2
- package/dist/receipts.d.ts.map +1 -1
- package/dist/receipts.js +58 -4
- package/dist/receipts.js.map +1 -1
- package/dist/runtime-reuse.d.ts +24 -0
- package/dist/runtime-reuse.d.ts.map +1 -0
- package/dist/runtime-reuse.js +168 -0
- package/dist/runtime-reuse.js.map +1 -0
- package/dist/runtime.d.ts +2 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +118 -108
- package/dist/runtime.js.map +1 -1
- package/dist/staged-candidate.d.ts +4 -0
- package/dist/staged-candidate.d.ts.map +1 -1
- package/dist/staged-candidate.js +57 -11
- package/dist/staged-candidate.js.map +1 -1
- package/dist/state.d.ts +3 -0
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +4 -0
- package/dist/state.js.map +1 -1
- package/dist/verifier-keys.d.ts +59 -0
- package/dist/verifier-keys.d.ts.map +1 -0
- package/dist/verifier-keys.js +339 -0
- package/dist/verifier-keys.js.map +1 -0
- package/package.json +12 -9
|
@@ -55,8 +55,9 @@
|
|
|
55
55
|
*/
|
|
56
56
|
import { spawn, spawnSync } from 'node:child_process';
|
|
57
57
|
import { randomUUID } from 'node:crypto';
|
|
58
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
59
|
-
import {
|
|
58
|
+
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
59
|
+
import { tmpdir } from 'node:os';
|
|
60
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
60
61
|
import { AttestationSchema, BEHAVIOR_CASE_KIND, BehaviorCasePayloadSchema, CAUSE_NEXT_ACTIONS, canonicalJson, caseExecutionDigestOf, EMPTY_BEHAVIOR_CATALOG_DIGEST, engineBundleDigestOf, EvidenceRecordSchema, executionBoundaryDigestOf, LOCAL_UNISOLATED_BOUNDARY, isWitnessedRecord, renderRun, requiredCaseSetDigestOf, runExitCode, sha256Canonical, selectionDigestOf, targetArtifactDigestOf, verifyAttestationMac, } from '@gate-forge/core';
|
|
61
62
|
import { buildWitnessedPytestChildEnv, discoverTestCatalog, listNativePlaywrightTests, PlaywrightAdapter, readRunnerOutcomes, startSupervisorSpoolDrain, startWitnessProcess, SupervisorClient, TestDiscoveryError, } from '@gate-forge/pack-playwright';
|
|
62
63
|
import { parseArgs, stringFlag } from '../args.js';
|
|
@@ -66,6 +67,8 @@ import { writeLine } from '../io.js';
|
|
|
66
67
|
import { runDiagnosticSuites, runWitnessedPytestSuites } from '../diagnostics.js';
|
|
67
68
|
import { claimInjectionsFor, planScopedExpectedSet, trustedPolicyDigestForConfig, issueGateReceipt, parentSha, planExpectedSet, sealExecutionResult, supervisionBlocking, SUPERVISED_INVOCATION, } from '../execution.js';
|
|
68
69
|
import { evaluateRun } from '../evaluate.js';
|
|
70
|
+
import { installedPlaywrightCompatibilityError } from '../package-compatibility.js';
|
|
71
|
+
import { DOCS_EXCLUSIONS_GUARANTEE, loadDocsExclusions } from '../docs-exclusions.js';
|
|
69
72
|
import { collectInputFiles, computeInputSnapshot, diffInputFiles, SnapshotUnavailableError, UnsupportedSnapshotError, } from '../input-snapshot.js';
|
|
70
73
|
import { mappingBlocking, mappedCoverageFrom, observeObligationIds, resolveRepositoryMappings, serverE2eObligationIds, TEST_MAP_RELATIVE } from '../mapping.js';
|
|
71
74
|
import { runPipeline } from '../pipeline.js';
|
|
@@ -73,15 +76,18 @@ import { tryReuseReceipt } from '../receipts.js';
|
|
|
73
76
|
import { computeCandidateTreeId, resolveGitDir } from '../candidate-tree.js';
|
|
74
77
|
import { resolveProvider } from '../providers.js';
|
|
75
78
|
import { assertReceiptApprovedPolicy, evaluateApprovedPolicy, resolveApprovedPolicyDigest } from '../trusted-policy.js';
|
|
76
|
-
import { clearGateReceipt, httpRoutesView, readJsonArray, resolveStateDir, stateObligations, writeClaimInjections, writeClassificationsView, writeEnv, writeExecutionResult, writeGateReceipt, writeHttpRoutesView, writeManifest, writeObligations, writeReport, } from '../state.js';
|
|
77
|
-
import { loadConfigAt, parseRunFormat, rejectUnknownFlags, VERIFIER_KEY_ENV, VERSION } from './common.js';
|
|
79
|
+
import { clearGateReceipt, httpRoutesView, readJsonArray, resolveStateDir, stateObligations, writeClaimInjections, writeClassificationsView, writeEnv, writeExecutionResult, writeGateReceipt, writeHttpRoutesView, writeInputSnapshot, writeManifest, writeObligations, writeReport, } from '../state.js';
|
|
80
|
+
import { loadConfigAt, parseRunFormat, rejectUnknownFlags, VERIFIER_KEY_ENV, VERIFIER_KEY_FILE_ENV, VERSION, } from './common.js';
|
|
81
|
+
import { resolveVerifierKeyring } from '../verifier-keys.js';
|
|
78
82
|
export const TEST_GATES_USAGE = 'usage: gateforge test-gates [--changed] [--scope full|changed] [--suite <command>] [--out <dir>] ' +
|
|
79
|
-
'[--format text|json|sarif] [--witness-url <url>] [--run-token <token>] ' +
|
|
83
|
+
'[--result-only] [--format text|json|sarif] [--witness-url <url>] [--run-token <token>] ' +
|
|
80
84
|
'[--run-timeout-min <minutes>] ' +
|
|
81
|
-
|
|
85
|
+
`(verifier key via ${VERIFIER_KEY_ENV} or ${VERIFIER_KEY_FILE_ENV})\n` +
|
|
82
86
|
' --scope changed (supervised --changed only): plan, execute, and seal only the slice of tests\n' +
|
|
83
87
|
' claiming obligations affected by the resolved changed-file set; an affected obligation with no\n' +
|
|
84
|
-
' testable declared mapping blocks (EVIDENCE_SCOPE_INCOMPLETE) — narrower selection is never guessed'
|
|
88
|
+
' testable declared mapping blocks (EVIDENCE_SCOPE_INCOMPLETE) — narrower selection is never guessed\n' +
|
|
89
|
+
' --result-only (requires --changed --scope changed): report selected results without gate authority or receipt changes; ' +
|
|
90
|
+
'external witnesses require a separate --out directory and --run-token';
|
|
85
91
|
/**
|
|
86
92
|
* Runs the test-gates subcommand.
|
|
87
93
|
*
|
|
@@ -100,12 +106,18 @@ export async function testGatesCommand(io, argv) {
|
|
|
100
106
|
writeLine(io.stdout, TEST_GATES_USAGE);
|
|
101
107
|
return 0;
|
|
102
108
|
}
|
|
103
|
-
rejectUnknownFlags(options, ['suite', 'out', 'format', 'witness-url', 'run-token', 'run-timeout-min', 'changed', 'scope', 'help'], TEST_GATES_USAGE);
|
|
109
|
+
rejectUnknownFlags(options, ['suite', 'out', 'format', 'witness-url', 'run-token', 'run-timeout-min', 'changed', 'scope', 'result-only', 'help'], TEST_GATES_USAGE);
|
|
110
|
+
const compatibilityError = installedPlaywrightCompatibilityError();
|
|
111
|
+
if (compatibilityError !== null) {
|
|
112
|
+
writeLine(io.stderr, compatibilityError);
|
|
113
|
+
return 2;
|
|
114
|
+
}
|
|
104
115
|
const suite = stringFlag(options, 'suite');
|
|
105
116
|
const out = stringFlag(options, 'out');
|
|
106
117
|
const format = parseRunFormat(stringFlag(options, 'format') ?? 'text');
|
|
107
118
|
const witnessUrl = stringFlag(options, 'witness-url');
|
|
108
119
|
const changed = options['changed'] === true;
|
|
120
|
+
const resultOnly = options['result-only'] === true;
|
|
109
121
|
if (changed && suite !== undefined) {
|
|
110
122
|
throw new UsageError('test-gates: --changed runs the configured suite through the supervised adapter; ' +
|
|
111
123
|
'--suite is the legacy escape hatch and cannot be combined');
|
|
@@ -125,17 +137,83 @@ export async function testGatesCommand(io, argv) {
|
|
|
125
137
|
}
|
|
126
138
|
scope = scopeFlag;
|
|
127
139
|
}
|
|
140
|
+
if (resultOnly && (!changed || scope !== 'changed' || suite !== undefined)) {
|
|
141
|
+
throw new UsageError('test-gates: --result-only requires --changed --scope changed and cannot be combined with --suite');
|
|
142
|
+
}
|
|
143
|
+
if (resultOnly && witnessUrl === undefined && out !== undefined) {
|
|
144
|
+
throw new UsageError('test-gates: --result-only accepts --out only with --witness-url; without an external witness it owns a private temporary state directory');
|
|
145
|
+
}
|
|
146
|
+
if (resultOnly && witnessUrl !== undefined) {
|
|
147
|
+
if (out === undefined) {
|
|
148
|
+
throw new UsageError('test-gates: --result-only with --witness-url requires --out <dir> shared with the external witness; ' +
|
|
149
|
+
'use a separate non-authoritative state directory, not the configured gate state directory');
|
|
150
|
+
}
|
|
151
|
+
if (stringFlag(options, 'run-token') === undefined) {
|
|
152
|
+
throw new UsageError('test-gates: --result-only with --witness-url requires --run-token <token>');
|
|
153
|
+
}
|
|
154
|
+
const externalStateDir = canonicalizeStateDir(resolveStateDir(io.cwd, out));
|
|
155
|
+
const authoritativeStateDir = canonicalizeStateDir(resolveStateDir(io.cwd));
|
|
156
|
+
const relativeOut = relative(authoritativeStateDir, externalStateDir);
|
|
157
|
+
if (relativeOut === '' ||
|
|
158
|
+
(relativeOut !== '..' && !relativeOut.startsWith(`..${sep}`) && !isAbsolute(relativeOut))) {
|
|
159
|
+
throw new UsageError(`test-gates: --result-only --out '${out}' must be a separate non-authoritative state directory, ` +
|
|
160
|
+
`not the configured authoritative state directory '${resolveStateDir(io.cwd)}'`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const verifierKeyring = resolveVerifierKeyring(io.cwd, io.env, [resolveStateDir(io.cwd, out)]);
|
|
128
164
|
if (changed) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
165
|
+
const isolatedStateDir = resultOnly && witnessUrl === undefined ? mkdtempSync(join(tmpdir(), 'gateforge-selected-result-')) : undefined;
|
|
166
|
+
try {
|
|
167
|
+
return await runSupervisedTestGates(io, {
|
|
168
|
+
out: isolatedStateDir ?? out,
|
|
169
|
+
format,
|
|
170
|
+
witnessUrl,
|
|
171
|
+
runToken: stringFlag(options, 'run-token'),
|
|
172
|
+
runTimeoutMs: parseRunTimeoutMin(stringFlag(options, 'run-timeout-min')),
|
|
173
|
+
scope,
|
|
174
|
+
resultOnly,
|
|
175
|
+
verifierKeyring,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
if (isolatedStateDir !== undefined)
|
|
180
|
+
rmSync(isolatedStateDir, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return legacyTestGates(io, {
|
|
184
|
+
suite,
|
|
185
|
+
out,
|
|
186
|
+
format,
|
|
187
|
+
witnessUrl,
|
|
188
|
+
runToken: stringFlag(options, 'run-token'),
|
|
189
|
+
verifierKeyring,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Resolves a path through existing symlinks and appends a not-yet-existing
|
|
194
|
+
* suffix so state-directory comparisons cannot be bypassed with aliases.
|
|
195
|
+
*
|
|
196
|
+
* Args:
|
|
197
|
+
* path: absolute or relative state-directory path.
|
|
198
|
+
*
|
|
199
|
+
* Returns:
|
|
200
|
+
* string: canonical absolute path.
|
|
201
|
+
*/
|
|
202
|
+
function canonicalizeStateDir(path) {
|
|
203
|
+
let cursor = resolve(path);
|
|
204
|
+
const suffix = [];
|
|
205
|
+
while (true) {
|
|
206
|
+
try {
|
|
207
|
+
return resolve(realpathSync(cursor), ...suffix.reverse());
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
const parent = dirname(cursor);
|
|
211
|
+
if (parent === cursor)
|
|
212
|
+
return resolve(path);
|
|
213
|
+
suffix.push(cursor.slice(parent.length + (parent.endsWith(sep) ? 0 : 1)));
|
|
214
|
+
cursor = parent;
|
|
215
|
+
}
|
|
137
216
|
}
|
|
138
|
-
return legacyTestGates(io, { suite, out, format, witnessUrl, runToken: stringFlag(options, 'run-token') });
|
|
139
217
|
}
|
|
140
218
|
/**
|
|
141
219
|
* Parses `--run-timeout-min` into a whole-run wall-clock bound.
|
|
@@ -184,14 +262,10 @@ async function legacyTestGates(io, options) {
|
|
|
184
262
|
// already holds its own token; the CLI must adopt it or every
|
|
185
263
|
// fixture call answers 401 (x-gateforge-run mismatch).
|
|
186
264
|
const runToken = options.runToken;
|
|
187
|
-
// Verifier key for the attestation surface (GF-23, audit round 3):
|
|
188
|
-
// read from the environment — never argv, whose /proc cmdline is
|
|
189
|
-
// world-readable. Shared by the orchestrator with the witness and
|
|
190
|
-
// this CLI, never with the suite; without it no suite-writable
|
|
191
|
-
// artifact can prove issuance and the gate fails closed.
|
|
192
|
-
const witnessVerifierKey = io.env[VERIFIER_KEY_ENV];
|
|
193
265
|
const config = loadConfigAt(io.cwd);
|
|
194
266
|
const stateDir = resolveStateDir(io.cwd, out);
|
|
267
|
+
const verifierKeyring = options.verifierKeyring ?? resolveVerifierKeyring(io.cwd, io.env, [stateDir]);
|
|
268
|
+
const witnessVerifierKey = verifierKeyring?.active.key;
|
|
195
269
|
// 1. Inventory/hash inputs BEFORE discovery (plan §11.5). Only file
|
|
196
270
|
// bytes exist yet; the gate context joins after discovery. Unsafe
|
|
197
271
|
// --out overlap and uncapturable inputs fail closed (exit 2) before
|
|
@@ -338,7 +412,12 @@ async function legacyTestGates(io, options) {
|
|
|
338
412
|
cwd: io.cwd,
|
|
339
413
|
// The verifier key must NEVER reach the suite: strip it from the
|
|
340
414
|
// ambient env the child inherits (audit round 3).
|
|
341
|
-
env: {
|
|
415
|
+
env: {
|
|
416
|
+
...io.env,
|
|
417
|
+
[VERIFIER_KEY_ENV]: undefined,
|
|
418
|
+
[VERIFIER_KEY_FILE_ENV]: undefined,
|
|
419
|
+
...suiteEnv,
|
|
420
|
+
},
|
|
342
421
|
});
|
|
343
422
|
suiteFailed = suiteStatus !== 0;
|
|
344
423
|
if (suiteFailed) {
|
|
@@ -389,6 +468,7 @@ async function legacyTestGates(io, options) {
|
|
|
389
468
|
now: pipeline.now,
|
|
390
469
|
changedFiles: null,
|
|
391
470
|
witnessVerifierKey,
|
|
471
|
+
witnessVerifierKeys: verifierKeyring?.keys.map((entry) => entry.key),
|
|
392
472
|
witnessAttestation: liveAttestation,
|
|
393
473
|
evidenceContext: {
|
|
394
474
|
expectedInputDigest: expectedDigest,
|
|
@@ -423,10 +503,10 @@ async function legacyTestGates(io, options) {
|
|
|
423
503
|
* independent `playwright --list` child (scrubbed env, finite timeout) →
|
|
424
504
|
* execute through the adapter under the supervisor spool drain → enforce
|
|
425
505
|
* planned vs executed + the witness-side session trace → seal the
|
|
426
|
-
* execution result → run diagnostics (separate, advisory) → evaluate
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
506
|
+
* execution result → run diagnostics (separate, advisory) → evaluate.
|
|
507
|
+
* Normal gate mode issues a receipt only on complete success and may
|
|
508
|
+
* reuse an identical prior receipt; `--result-only` only reports the
|
|
509
|
+
* selected scope and never reads, creates, replaces, or clears receipts.
|
|
430
510
|
*
|
|
431
511
|
* Args:
|
|
432
512
|
* io: process context.
|
|
@@ -440,9 +520,12 @@ async function legacyTestGates(io, options) {
|
|
|
440
520
|
export async function runSupervisedTestGates(io, options) {
|
|
441
521
|
const { out, format, witnessUrl, runTimeoutMs } = options;
|
|
442
522
|
const runtimeReuseDigest = options.runtimeReuseDigest;
|
|
443
|
-
const
|
|
523
|
+
const runtimeReuseMounts = options.runtimeReuseMounts ?? [];
|
|
444
524
|
const config = loadConfigAt(io.cwd);
|
|
525
|
+
const docsExclusions = loadDocsExclusions(io.cwd, config);
|
|
445
526
|
const stateDir = resolveStateDir(io.cwd, out);
|
|
527
|
+
const verifierKeyring = options.verifierKeyring ?? resolveVerifierKeyring(io.cwd, io.env, [stateDir]);
|
|
528
|
+
const witnessVerifierKey = verifierKeyring?.active.key;
|
|
446
529
|
const executionBoundary = io.env['GATEFORGE_AUTHORITY_BOUNDARY']?.trim() || LOCAL_UNISOLATED_BOUNDARY;
|
|
447
530
|
const executionBoundaryDigest = executionBoundaryDigestOf(executionBoundary);
|
|
448
531
|
// Scoped sealing (Goal 2): resolve the changed-file basis through the
|
|
@@ -459,7 +542,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
459
542
|
let preFiles = null;
|
|
460
543
|
let snapshotUnavailable = false;
|
|
461
544
|
try {
|
|
462
|
-
preFiles = collectInputFiles(io.cwd, config, stateDir);
|
|
545
|
+
preFiles = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions);
|
|
463
546
|
}
|
|
464
547
|
catch (error) {
|
|
465
548
|
if (error instanceof SnapshotUnavailableError)
|
|
@@ -487,14 +570,15 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
487
570
|
: null;
|
|
488
571
|
const httpRoutes = httpRoutesView(pipeline.graph);
|
|
489
572
|
let expectedDigest = null;
|
|
573
|
+
let inputSnapshot = null;
|
|
490
574
|
if (!snapshotUnavailable) {
|
|
491
|
-
const postDiscovery = collectInputFiles(io.cwd, config, stateDir);
|
|
575
|
+
const postDiscovery = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions);
|
|
492
576
|
const drift = preFiles === null ? [] : diffInputFiles(preFiles, postDiscovery);
|
|
493
577
|
if (drift.length > 0) {
|
|
494
578
|
throw new UsageError(`input tree changed around discovery (${drift.slice(0, 3).join('; ')}${drift.length > 3 ? '; …' : ''}); ` +
|
|
495
579
|
'no reliable digest can be established — refusing the run');
|
|
496
580
|
}
|
|
497
|
-
|
|
581
|
+
inputSnapshot = computeInputSnapshot({
|
|
498
582
|
cwd: io.cwd,
|
|
499
583
|
config,
|
|
500
584
|
stateDir,
|
|
@@ -503,7 +587,25 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
503
587
|
httpRoutes,
|
|
504
588
|
plugins: pipeline.manifest.plugins.map((plugin) => ({ id: plugin.id, version: plugin.version })),
|
|
505
589
|
runtimeReuseDigest,
|
|
506
|
-
|
|
590
|
+
runtimeReuseMounts,
|
|
591
|
+
docsExclusions,
|
|
592
|
+
});
|
|
593
|
+
expectedDigest = inputSnapshot.evidenceInputDigest;
|
|
594
|
+
}
|
|
595
|
+
if (options.runtimeReuseCheck !== undefined) {
|
|
596
|
+
let currentReuseDigest;
|
|
597
|
+
try {
|
|
598
|
+
currentReuseDigest = options.runtimeReuseCheck();
|
|
599
|
+
}
|
|
600
|
+
catch {
|
|
601
|
+
currentReuseDigest = null;
|
|
602
|
+
}
|
|
603
|
+
if (currentReuseDigest !== runtimeReuseDigest) {
|
|
604
|
+
if (!options.resultOnly)
|
|
605
|
+
clearGateReceipt(stateDir);
|
|
606
|
+
writeLine(io.stderr, 'test-gates: reused dependency bytes changed during discovery; refusing the run');
|
|
607
|
+
return 1;
|
|
608
|
+
}
|
|
507
609
|
}
|
|
508
610
|
const invocationId = randomUUID();
|
|
509
611
|
// Phase 3 freeze (immutable candidate): the tree and parent the run
|
|
@@ -512,13 +614,16 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
512
614
|
// explicit drift block, never a mixed-bytes seal.
|
|
513
615
|
const freezeGitDir = resolveGitDir(io.cwd, io.env);
|
|
514
616
|
const frozenTreeId = options.fixedCandidateTreeId ??
|
|
515
|
-
(freezeGitDir === null
|
|
617
|
+
(freezeGitDir === null
|
|
618
|
+
? null
|
|
619
|
+
: computeCandidateTreeId(freezeGitDir, io.cwd, io.env, stateDir, 'record', runtimeReuseMounts, docsExclusions));
|
|
516
620
|
const frozenParentSha = options.fixedParentSha !== undefined ? options.fixedParentSha : parentSha(io.cwd);
|
|
517
621
|
// 2. Catalog + mappings (Phase 3 resolver) → expected set + claim
|
|
518
622
|
// injections + typed mapping blockers. A failed discovery blocks the
|
|
519
623
|
// gate (E16) — never an empty-success fallback.
|
|
520
624
|
let discoveryError = null;
|
|
521
625
|
let catalog = null;
|
|
626
|
+
let nativeClaims = [];
|
|
522
627
|
try {
|
|
523
628
|
// collectPytest is REQUIRED here (GAP 1 fix, server-witnessed
|
|
524
629
|
// channel): the supervised run's expected set, mapping resolution,
|
|
@@ -529,7 +634,9 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
529
634
|
// failure is honest data: the suite's runner summary turns
|
|
530
635
|
// `unavailable`, `inventoryComplete` goes false, and the gate blocks
|
|
531
636
|
// TEST_INVENTORY_INCOMPLETE — never a silently narrower inventory.
|
|
532
|
-
|
|
637
|
+
const discovered = await discoverTestCatalog({ cwd: io.cwd, config, collectPytest: true });
|
|
638
|
+
catalog = discovered.catalog;
|
|
639
|
+
nativeClaims = discovered.nativeClaims;
|
|
533
640
|
}
|
|
534
641
|
catch (error) {
|
|
535
642
|
discoveryError = error instanceof TestDiscoveryError ? error.message : error.message;
|
|
@@ -542,9 +649,10 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
542
649
|
// reuse, or suite execution. A provisioned pin binds EVERY run here;
|
|
543
650
|
// strict mode without a pin fails closed; a candidate whose revision
|
|
544
651
|
// is not the approved one never reaches the runner.
|
|
545
|
-
const policyGate = evaluateApprovedPolicy(resolveApprovedPolicyDigest({ env: io.env, candidateCwd: io.cwd, candidateConfig: config }), trustedPolicy, config.enforcement?.strictE2E === true);
|
|
652
|
+
const policyGate = evaluateApprovedPolicy(resolveApprovedPolicyDigest({ env: io.env, candidateCwd: io.cwd, candidateConfig: config }), trustedPolicy, config.enforcement?.strictE2E === true || docsExclusions.length > 0);
|
|
546
653
|
if (policyGate.status === 'blocked') {
|
|
547
|
-
|
|
654
|
+
if (!options.resultOnly)
|
|
655
|
+
clearGateReceipt(stateDir);
|
|
548
656
|
writeLine(io.stderr, `test-gates: ${policyGate.cause}: ${policyGate.detail}`);
|
|
549
657
|
writeLine(io.stderr, `next action: ${policyGate.nextAction}`);
|
|
550
658
|
return 1;
|
|
@@ -566,6 +674,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
566
674
|
// blocked as uncovered even when mapped — phantom findings over an
|
|
567
675
|
// honest gate).
|
|
568
676
|
let mappedCoverage = [];
|
|
677
|
+
let claimInventory = [];
|
|
569
678
|
// Server-e2e obligations (server-witnessed persistence channel): the
|
|
570
679
|
// trusted mapping resolution decides which obligations may stamp
|
|
571
680
|
// `channel: 'server'` evidence — the drain registers exactly this set
|
|
@@ -580,12 +689,13 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
580
689
|
const mapped = await resolveRepositoryMappings({
|
|
581
690
|
cwd: io.cwd,
|
|
582
691
|
config,
|
|
583
|
-
stateDir,
|
|
584
692
|
obligations: pipeline.policy.obligations,
|
|
585
693
|
catalog,
|
|
694
|
+
nativeClaims,
|
|
586
695
|
behaviorCatalog: pipeline.behaviorCatalog,
|
|
587
696
|
});
|
|
588
697
|
mappingBlockers = mappingBlocking(mapped.resolution.problems);
|
|
698
|
+
claimInventory = mapped.claimInventory;
|
|
589
699
|
plannedRows = planExpectedSet(catalog);
|
|
590
700
|
injections = claimInjectionsFor(mapped.resolution, catalog);
|
|
591
701
|
mappedCoverage = mappedCoverageFrom(mapped.resolution, pipeline.policy.obligations, pipeline.graph);
|
|
@@ -654,22 +764,26 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
654
764
|
};
|
|
655
765
|
const selectionDigest = selectionDigestOf(selection);
|
|
656
766
|
const catalogDigest = catalog === null ? NO_CATALOG_DIGEST : sha256Canonical(catalog);
|
|
657
|
-
// 3. Cache reuse
|
|
658
|
-
//
|
|
767
|
+
// 3. Cache reuse: identical evidence inputs, exact candidate tree, and
|
|
768
|
+
// complete result only. No changed path is presumed inert.
|
|
659
769
|
// The scope axis is part of the identity: a full run demands a
|
|
660
770
|
// full-scope (or legacy unscoped) receipt, a scoped run demands a
|
|
661
771
|
// changed-scope receipt sealing the IDENTICAL covered set — a slice
|
|
662
772
|
// never reuses as a whole-suite seal or vice versa.
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
773
|
+
const reuseCandidate = options.resultOnly
|
|
774
|
+
? { reuse: false }
|
|
775
|
+
: tryReuseReceipt(stateDir, verifierKeyring, {
|
|
776
|
+
inputDigest: expectedDigest ?? NO_DIGEST,
|
|
777
|
+
trustedPolicyDigest: trustedPolicy,
|
|
778
|
+
selectionDigest,
|
|
779
|
+
executionBoundaryDigest,
|
|
780
|
+
...behaviorReceiptBindings(pipeline.behaviorCatalog),
|
|
781
|
+
scope: options.scope === 'changed' ? 'changed' : 'full',
|
|
782
|
+
...(options.scope === 'changed' ? { coveredObligationFingerprints: coveredFingerprints } : {}),
|
|
783
|
+
});
|
|
784
|
+
const reuse = reuseCandidate.reuse && frozenTreeId !== null && reuseCandidate.receipt.candidateTreeId === frozenTreeId
|
|
785
|
+
? reuseCandidate
|
|
786
|
+
: { reuse: false };
|
|
673
787
|
if (reuse.reuse) {
|
|
674
788
|
// Under a provisioned pin the reused receipt must bind the CURRENT
|
|
675
789
|
// approved revision (policy revision changed after sealing → rerun).
|
|
@@ -681,7 +795,6 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
681
795
|
return 1;
|
|
682
796
|
}
|
|
683
797
|
}
|
|
684
|
-
writeLine(io.stderr, `reused receipt ${reuse.receipt.receiptId} (identical authenticated inputs; complete result)`);
|
|
685
798
|
// Witnessed suites are part of the SEALED supervised run: a reused
|
|
686
799
|
// receipt means nothing re-executed (the identical-input contract
|
|
687
800
|
// already pins the pytest bytes), so they are never re-run here —
|
|
@@ -703,7 +816,9 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
703
816
|
// contract above already pinned scope + covered set); full reuse
|
|
704
817
|
// stays unscoped. A scoped run without the flag never happens.
|
|
705
818
|
changedFiles: scopeChangedFiles,
|
|
819
|
+
claimInventory,
|
|
706
820
|
witnessVerifierKey,
|
|
821
|
+
witnessVerifierKeys: verifierKeyring?.keys.map((entry) => entry.key),
|
|
707
822
|
// Goal 1: the reused gate grades through the SAME adopted-baseline
|
|
708
823
|
// seam as check — baselined obligations waive (loudly) instead of
|
|
709
824
|
// blocking the reused evaluation.
|
|
@@ -722,9 +837,28 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
722
837
|
waiverCounts: evaluated.waiverCounts,
|
|
723
838
|
run: { ...pipeline.manifest, invocationId, inputDigest: expectedDigest ?? undefined },
|
|
724
839
|
toolVersion: VERSION,
|
|
840
|
+
diagnosticContext: {
|
|
841
|
+
scope: options.scope ?? 'full',
|
|
842
|
+
candidateTreeId: frozenTreeId,
|
|
843
|
+
inputDigest: expectedDigest,
|
|
844
|
+
evidenceState: 'receipt-reused',
|
|
845
|
+
authority: 'authoritative',
|
|
846
|
+
...(docsExclusions.length === 0
|
|
847
|
+
? {}
|
|
848
|
+
: {
|
|
849
|
+
docsExclusions: {
|
|
850
|
+
folders: docsExclusions,
|
|
851
|
+
approvalDigest: approvedPolicyDigest ?? trustedPolicy,
|
|
852
|
+
approvalStatus: 'matched',
|
|
853
|
+
guarantee: DOCS_EXCLUSIONS_GUARANTEE,
|
|
854
|
+
},
|
|
855
|
+
}),
|
|
856
|
+
},
|
|
725
857
|
});
|
|
726
858
|
writeLine(io.stdout, report);
|
|
727
|
-
|
|
859
|
+
const gateCode = runExitCode({ verdicts: evaluated.verdicts, blocking: evaluated.blocking });
|
|
860
|
+
writeLine(io.stderr, `reused receipt ${reuse.receipt.receiptId} (identical authenticated inputs; complete result)`);
|
|
861
|
+
return gateCode;
|
|
728
862
|
}
|
|
729
863
|
// 3.5 Scoped empty-slice fast-fail (Goal 2): when the changed set maps
|
|
730
864
|
// to no testable slice there is nothing to run and nothing to seal —
|
|
@@ -734,7 +868,8 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
734
868
|
// slice receipt over nothing is ever minted, and the previous receipt
|
|
735
869
|
// is invalidated (E07 discipline).
|
|
736
870
|
if (options.scope === 'changed' && plannedRows.length === 0) {
|
|
737
|
-
|
|
871
|
+
if (!options.resultOnly)
|
|
872
|
+
clearGateReceipt(stateDir);
|
|
738
873
|
const emptySliceBlocking = inventoryBlocking.length > 0
|
|
739
874
|
? // A failed/incomplete discovery already explains the block.
|
|
740
875
|
[]
|
|
@@ -768,7 +903,9 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
768
903
|
stateDir,
|
|
769
904
|
now: pipeline.now,
|
|
770
905
|
changedFiles: scopeChangedFiles,
|
|
906
|
+
claimInventory,
|
|
771
907
|
witnessVerifierKey,
|
|
908
|
+
witnessVerifierKeys: verifierKeyring?.keys.map((entry) => entry.key),
|
|
772
909
|
baseline: resolveAdoptedBaseline(io.cwd, config.baselines),
|
|
773
910
|
mappedCoverage,
|
|
774
911
|
evidenceContext: {
|
|
@@ -798,6 +935,8 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
798
935
|
// is rewritten after adoption below; the views are content-stable.)
|
|
799
936
|
let manifest = pipeline.manifest;
|
|
800
937
|
writeManifest(stateDir, manifest);
|
|
938
|
+
if (inputSnapshot !== null)
|
|
939
|
+
writeInputSnapshot(stateDir, inputSnapshot);
|
|
801
940
|
writeObligations(stateDir, stateObligations(pipeline.policy.obligations, pipeline.graph));
|
|
802
941
|
writeHttpRoutesView(stateDir, httpRoutes);
|
|
803
942
|
writeClassificationsView(stateDir, pipeline.classificationsView);
|
|
@@ -879,7 +1018,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
879
1018
|
if (spawnedWitness !== null) {
|
|
880
1019
|
await stopWitnessProcess(spawnedWitness);
|
|
881
1020
|
}
|
|
882
|
-
throw new UsageError(
|
|
1021
|
+
throw new UsageError(`test-gates --changed requires ${VERIFIER_KEY_ENV} or ${VERIFIER_KEY_FILE_ENV} in the orchestrating environment: ` +
|
|
883
1022
|
'the witness supervisor surface (expected set, session lifecycle, execution trace) is ' +
|
|
884
1023
|
'verifier-key authenticated and the key never reaches the suite or the runner child');
|
|
885
1024
|
}
|
|
@@ -927,6 +1066,8 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
927
1066
|
config,
|
|
928
1067
|
run: {
|
|
929
1068
|
testFiles: plannedRows.map((row) => row.planned.file),
|
|
1069
|
+
...(io.env['GATEFORGE_APP_BASE_URL'] ? { appBaseUrl: io.env['GATEFORGE_APP_BASE_URL'] } : {}),
|
|
1070
|
+
...(io.env['GATEFORGE_SESSION_STATE'] ? { storageState: io.env['GATEFORGE_SESSION_STATE'] } : {}),
|
|
930
1071
|
projects: [
|
|
931
1072
|
...new Set(plannedRows.map((row) => row.planned.project).filter((project) => project !== null)),
|
|
932
1073
|
],
|
|
@@ -938,6 +1079,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
938
1079
|
});
|
|
939
1080
|
const suiteEnv = {
|
|
940
1081
|
GATEFORGE_RUN_TOKEN: envRecord.GATEFORGE_RUN_TOKEN,
|
|
1082
|
+
GATEFORGE_CLI_VERSION: VERSION,
|
|
941
1083
|
};
|
|
942
1084
|
if (envRecord.GATEFORGE_WITNESS_URL !== null) {
|
|
943
1085
|
suiteEnv['GATEFORGE_WITNESS_URL'] = envRecord.GATEFORGE_WITNESS_URL;
|
|
@@ -1061,9 +1203,16 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1061
1203
|
}
|
|
1062
1204
|
}
|
|
1063
1205
|
if (options.runtimeReuseCheck !== undefined) {
|
|
1064
|
-
|
|
1206
|
+
let currentReuseDigest;
|
|
1207
|
+
try {
|
|
1208
|
+
currentReuseDigest = options.runtimeReuseCheck();
|
|
1209
|
+
}
|
|
1210
|
+
catch {
|
|
1211
|
+
currentReuseDigest = null;
|
|
1212
|
+
}
|
|
1065
1213
|
if (currentReuseDigest !== runtimeReuseDigest) {
|
|
1066
|
-
|
|
1214
|
+
if (!options.resultOnly)
|
|
1215
|
+
clearGateReceipt(stateDir);
|
|
1067
1216
|
writeLine(io.stderr, 'test-gates: reused dependency bytes changed during the run; no receipt is sealed over mixed runtime inputs');
|
|
1068
1217
|
return 1;
|
|
1069
1218
|
}
|
|
@@ -1081,6 +1230,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1081
1230
|
...(options.scope === 'changed' ? { mode: 'mapped-selection' } : {}),
|
|
1082
1231
|
logicalKeys: selection.logicalKeys,
|
|
1083
1232
|
catalog: catalog ?? EMPTY_CATALOG,
|
|
1233
|
+
claimInventory: nativeClaims,
|
|
1084
1234
|
plannedRows,
|
|
1085
1235
|
envelope,
|
|
1086
1236
|
outcomesDoc,
|
|
@@ -1094,7 +1244,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1094
1244
|
let changedInputs = false;
|
|
1095
1245
|
if (!snapshotUnavailable && preFiles !== null) {
|
|
1096
1246
|
try {
|
|
1097
|
-
const postSuite = collectInputFiles(io.cwd, config, stateDir);
|
|
1247
|
+
const postSuite = collectInputFiles(io.cwd, config, stateDir, runtimeReuseMounts, docsExclusions);
|
|
1098
1248
|
changedInputs = diffInputFiles(preFiles, postSuite).length > 0;
|
|
1099
1249
|
}
|
|
1100
1250
|
catch {
|
|
@@ -1141,7 +1291,12 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1141
1291
|
cause: 'RUN_INCOMPLETE',
|
|
1142
1292
|
nextAction: CAUSE_NEXT_ACTIONS['RUN_INCOMPLETE'],
|
|
1143
1293
|
}));
|
|
1144
|
-
const
|
|
1294
|
+
const repositoryBlocking = [
|
|
1295
|
+
...pipeline.policy.blocking,
|
|
1296
|
+
...mappingBlockers,
|
|
1297
|
+
...inventoryBlocking,
|
|
1298
|
+
];
|
|
1299
|
+
const evaluationInput = {
|
|
1145
1300
|
cwd: io.cwd,
|
|
1146
1301
|
config,
|
|
1147
1302
|
graph: pipeline.graph,
|
|
@@ -1149,9 +1304,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1149
1304
|
behaviorAuthorityProfileDigest: pipeline.behaviorCatalog === null ? null : engineBundleDigestOf(VERSION, trustedPolicy),
|
|
1150
1305
|
obligations: pipeline.policy.obligations,
|
|
1151
1306
|
blocking: [
|
|
1152
|
-
...
|
|
1153
|
-
...mappingBlockers,
|
|
1154
|
-
...inventoryBlocking,
|
|
1307
|
+
...repositoryBlocking,
|
|
1155
1308
|
// Scoped planning gaps (Goal 2): affected obligations no declared,
|
|
1156
1309
|
// catalog-live claim covers. Fail closed — never diff-scoped away,
|
|
1157
1310
|
// never waived, and they alone prevent the receipt.
|
|
@@ -1172,7 +1325,9 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1172
1325
|
// obligations are exactly the covered set the receipt seals. Full
|
|
1173
1326
|
// mode stays unscoped (changedFiles: null), byte-identical.
|
|
1174
1327
|
changedFiles: scopeChangedFiles,
|
|
1328
|
+
claimInventory,
|
|
1175
1329
|
witnessVerifierKey,
|
|
1330
|
+
witnessVerifierKeys: verifierKeyring?.keys.map((entry) => entry.key),
|
|
1176
1331
|
witnessAttestation: liveAttestation,
|
|
1177
1332
|
// Goal 1: the supervised gate honors the adopted baseline through the
|
|
1178
1333
|
// SAME fail-closed seam as `check` (no adoption record → nothing is
|
|
@@ -1187,13 +1342,56 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1187
1342
|
requireInvocationId: true,
|
|
1188
1343
|
changedInputs,
|
|
1189
1344
|
},
|
|
1345
|
+
};
|
|
1346
|
+
const evaluated = evaluateRun(evaluationInput);
|
|
1347
|
+
const repositoryEvaluation = evaluateRun({
|
|
1348
|
+
...evaluationInput,
|
|
1349
|
+
blocking: repositoryBlocking,
|
|
1350
|
+
changedFiles: null,
|
|
1351
|
+
});
|
|
1352
|
+
const executionSummary = runExecutionSummaryOf({
|
|
1353
|
+
executionResult: sealed.result,
|
|
1354
|
+
mode: 'executed',
|
|
1355
|
+
scope: options.scope === 'changed' ? 'changed' : 'full',
|
|
1356
|
+
selectedVerdicts: evaluated.verdicts,
|
|
1357
|
+
selectedBlocking: evaluated.blocking,
|
|
1358
|
+
repositoryVerdicts: repositoryEvaluation.verdicts,
|
|
1359
|
+
repositoryBlocking: repositoryEvaluation.blocking,
|
|
1360
|
+
unclaimed: countUnclaimedObligations(stateDir, pipeline.policy.obligations),
|
|
1190
1361
|
});
|
|
1362
|
+
const diagnosticContext = {
|
|
1363
|
+
scope: options.scope,
|
|
1364
|
+
candidateTreeId: frozenTreeId,
|
|
1365
|
+
inputDigest: expectedDigest,
|
|
1366
|
+
evidenceState: snapshotUnavailable
|
|
1367
|
+
? 'snapshot-unavailable'
|
|
1368
|
+
: changedInputs
|
|
1369
|
+
? 'inputs-changed-during-run'
|
|
1370
|
+
: !sealed.result.complete
|
|
1371
|
+
? 'execution-incomplete'
|
|
1372
|
+
: liveAttestation === null
|
|
1373
|
+
? 'witness-attestation-unavailable'
|
|
1374
|
+
: 'attested',
|
|
1375
|
+
authority: options.resultOnly ? 'non-authoritative' : 'authoritative',
|
|
1376
|
+
...(docsExclusions.length === 0
|
|
1377
|
+
? {}
|
|
1378
|
+
: {
|
|
1379
|
+
docsExclusions: {
|
|
1380
|
+
folders: docsExclusions,
|
|
1381
|
+
approvalDigest: approvedPolicyDigest ?? trustedPolicy,
|
|
1382
|
+
approvalStatus: 'matched',
|
|
1383
|
+
guarantee: DOCS_EXCLUSIONS_GUARANTEE,
|
|
1384
|
+
},
|
|
1385
|
+
}),
|
|
1386
|
+
};
|
|
1191
1387
|
const report = renderRun(evaluated.verdicts, {
|
|
1192
1388
|
format,
|
|
1193
1389
|
blocking: evaluated.blocking,
|
|
1194
1390
|
waiverCounts: evaluated.waiverCounts,
|
|
1195
1391
|
run: manifest,
|
|
1196
1392
|
toolVersion: VERSION,
|
|
1393
|
+
execution: executionSummary,
|
|
1394
|
+
diagnosticContext,
|
|
1197
1395
|
});
|
|
1198
1396
|
writeLine(io.stdout, report);
|
|
1199
1397
|
writeReport(stateDir, renderRun(evaluated.verdicts, {
|
|
@@ -1202,19 +1400,41 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1202
1400
|
waiverCounts: evaluated.waiverCounts,
|
|
1203
1401
|
run: manifest,
|
|
1204
1402
|
toolVersion: VERSION,
|
|
1403
|
+
execution: executionSummary,
|
|
1404
|
+
diagnosticContext,
|
|
1205
1405
|
}));
|
|
1206
|
-
// 10.
|
|
1207
|
-
//
|
|
1208
|
-
// receipt (E07 — a later failing run blocks a subsequent check too).
|
|
1406
|
+
// 10. Only authoritative gate mode invalidates a previous receipt on
|
|
1407
|
+
// failure. Result-only reporting never creates, replaces, or clears one.
|
|
1209
1408
|
const gateCode = runExitCode({ verdicts: evaluated.verdicts, blocking: evaluated.blocking });
|
|
1210
1409
|
if (gateCode !== 0 || !sealed.result.complete || changedInputs || snapshotUnavailable || expectedDigest === null) {
|
|
1211
|
-
|
|
1410
|
+
if (!options.resultOnly)
|
|
1411
|
+
clearGateReceipt(stateDir);
|
|
1212
1412
|
return gateCode === 0 ? 1 : gateCode;
|
|
1213
1413
|
}
|
|
1414
|
+
// The result-only selection uses either a private temporary state dir or
|
|
1415
|
+
// the external witness's separate caller-provided state dir. It never
|
|
1416
|
+
// reads, writes, or clears the configured authoritative receipt.
|
|
1417
|
+
// Confirm the same candidate-tree drift check before returning a
|
|
1418
|
+
// descriptive pass.
|
|
1419
|
+
const resultGitDir = resolveGitDir(io.cwd, io.env);
|
|
1420
|
+
const resultTreeId = resultGitDir === null
|
|
1421
|
+
? null
|
|
1422
|
+
: computeCandidateTreeId(resultGitDir, io.cwd, io.env, stateDir, 'record', runtimeReuseMounts, docsExclusions);
|
|
1423
|
+
if (resultTreeId !== frozenTreeId) {
|
|
1424
|
+
writeLine(io.stderr, 'test-gates: the workspace changed during the run ' +
|
|
1425
|
+
`(${frozenTreeId ?? 'unborn'} → ${resultTreeId ?? 'unborn'}); ` +
|
|
1426
|
+
'no result is reported for mixed bytes (fail closed)');
|
|
1427
|
+
return 1;
|
|
1428
|
+
}
|
|
1429
|
+
if (options.resultOnly) {
|
|
1430
|
+
writeLine(io.stderr, 'selected result passed; this result is non-authoritative and did not create a gate receipt');
|
|
1431
|
+
return 0;
|
|
1432
|
+
}
|
|
1214
1433
|
if (witnessVerifierKey === undefined) {
|
|
1215
1434
|
// No verifier key: the receipt cannot be signed by the same
|
|
1216
1435
|
// authority as witness records — never mint an unverifiable one.
|
|
1217
|
-
|
|
1436
|
+
if (!options.resultOnly)
|
|
1437
|
+
clearGateReceipt(stateDir);
|
|
1218
1438
|
writeLine(io.stderr, 'test-gates: no witness verifier key — no gate receipt can be sealed (require-e2e consumers will block)');
|
|
1219
1439
|
return gateCode;
|
|
1220
1440
|
}
|
|
@@ -1223,15 +1443,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1223
1443
|
// Phase 3 drift gate: the tree at seal time must equal the frozen
|
|
1224
1444
|
// evaluation tree — a live-workspace edit mid-run blocks explicitly
|
|
1225
1445
|
// instead of sealing mixed bytes.
|
|
1226
|
-
const
|
|
1227
|
-
const sealTreeId = sealGitDir === null ? null : computeCandidateTreeId(sealGitDir, io.cwd, io.env, stateDir, 'record');
|
|
1228
|
-
if (sealTreeId !== frozenTreeId) {
|
|
1229
|
-
clearGateReceipt(stateDir);
|
|
1230
|
-
writeLine(io.stderr, 'test-gates: the workspace changed during the run ' +
|
|
1231
|
-
`(${frozenTreeId ?? 'unborn'} → ${sealTreeId ?? 'unborn'}); ` +
|
|
1232
|
-
'no receipt is sealed over mixed bytes — rerun the gate for the exact candidate (fail closed)');
|
|
1233
|
-
return 1;
|
|
1234
|
-
}
|
|
1446
|
+
const sealTreeId = resultTreeId;
|
|
1235
1447
|
// Phase 3 v2 bindings: the immutable candidate tree actually tested
|
|
1236
1448
|
// (the drift-checked seal-time value, equal to the frozen evaluation tree),
|
|
1237
1449
|
// the behavior catalog + required case set, authenticated executed
|
|
@@ -1241,6 +1453,7 @@ export async function runSupervisedTestGates(io, options) {
|
|
|
1241
1453
|
const behaviorBindings = behaviorReceiptBindings(pipeline.behaviorCatalog);
|
|
1242
1454
|
const receipt = issueGateReceipt({
|
|
1243
1455
|
verifierKey: witnessVerifierKey,
|
|
1456
|
+
verifierKeyId: verifierKeyring?.active.keyId,
|
|
1244
1457
|
runId: manifest.runId,
|
|
1245
1458
|
invocationId,
|
|
1246
1459
|
inputDigest: expectedDigest,
|
|
@@ -1392,6 +1605,75 @@ export function executedBehaviorCaseDigest(stateDir, runId, behaviorCatalog, ver
|
|
|
1392
1605
|
}
|
|
1393
1606
|
return caseExecutionDigestOf(executedCaseIds);
|
|
1394
1607
|
}
|
|
1608
|
+
/** Counts obligations with no claim row in the selected run state.
|
|
1609
|
+
*
|
|
1610
|
+
* Args:
|
|
1611
|
+
* stateDir: run-state directory containing the claim registry.
|
|
1612
|
+
* obligations: complete policy obligation set.
|
|
1613
|
+
*
|
|
1614
|
+
* Returns:
|
|
1615
|
+
* number: unique obligations with no claim row.
|
|
1616
|
+
*/
|
|
1617
|
+
function countUnclaimedObligations(stateDir, obligations) {
|
|
1618
|
+
const claimed = new Set();
|
|
1619
|
+
for (const raw of readJsonArray(stateDir, 'claims.json')) {
|
|
1620
|
+
if (typeof raw !== 'object' || raw === null || !('obligationId' in raw))
|
|
1621
|
+
continue;
|
|
1622
|
+
const obligationId = raw.obligationId;
|
|
1623
|
+
if (typeof obligationId === 'string')
|
|
1624
|
+
claimed.add(obligationId);
|
|
1625
|
+
}
|
|
1626
|
+
return obligations.filter((obligation) => !claimed.has(obligation.id)).length;
|
|
1627
|
+
}
|
|
1628
|
+
/** Builds the report counts from trusted execution and full-scope evaluation.
|
|
1629
|
+
*
|
|
1630
|
+
* Args:
|
|
1631
|
+
* input: execution result, selected result, full repository result, and scope.
|
|
1632
|
+
*
|
|
1633
|
+
* Returns:
|
|
1634
|
+
* RunExecutionSummary: descriptive counts that never authorize a gate.
|
|
1635
|
+
*/
|
|
1636
|
+
function runExecutionSummaryOf(input) {
|
|
1637
|
+
const latestOutcomes = new Map();
|
|
1638
|
+
for (const outcome of input.executionResult.outcomes) {
|
|
1639
|
+
const previous = latestOutcomes.get(outcome.logicalKey);
|
|
1640
|
+
if (previous === undefined || outcome.attempt >= previous.attempt)
|
|
1641
|
+
latestOutcomes.set(outcome.logicalKey, outcome);
|
|
1642
|
+
}
|
|
1643
|
+
const finalOutcomes = [...latestOutcomes.values()];
|
|
1644
|
+
const performed = finalOutcomes.filter((outcome) => outcome.status !== 'skipped' && outcome.status !== 'fixme').length;
|
|
1645
|
+
const passed = finalOutcomes.filter((outcome) => outcome.status === 'passed' && !outcome.expectedFailure).length;
|
|
1646
|
+
const skipped = finalOutcomes.filter((outcome) => outcome.status === 'skipped' || outcome.status === 'fixme').length;
|
|
1647
|
+
const expectedFailures = finalOutcomes.filter((outcome) => outcome.status === 'failed' && outcome.expectedFailure).length;
|
|
1648
|
+
const selected = input.executionResult.planned.length;
|
|
1649
|
+
const blockingSelected = input.selectedVerdicts.filter((verdict) => verdict.verdict !== 'satisfied' && verdict.verdict !== 'waived').length;
|
|
1650
|
+
const blockingRepository = input.repositoryVerdicts.filter((verdict) => verdict.verdict !== 'satisfied' && verdict.verdict !== 'waived').length;
|
|
1651
|
+
return {
|
|
1652
|
+
scope: input.scope,
|
|
1653
|
+
mode: input.mode,
|
|
1654
|
+
testsPerformedThisInvocation: input.mode === 'executed' ? performed : 0,
|
|
1655
|
+
selectedTests: {
|
|
1656
|
+
selected,
|
|
1657
|
+
passed,
|
|
1658
|
+
failed: Math.max(0, selected - passed - skipped - expectedFailures),
|
|
1659
|
+
skipped,
|
|
1660
|
+
expectedFailures,
|
|
1661
|
+
},
|
|
1662
|
+
selectedClaims: {
|
|
1663
|
+
selected: input.selectedVerdicts.length,
|
|
1664
|
+
satisfied: input.selectedVerdicts.filter((verdict) => verdict.verdict === 'satisfied').length,
|
|
1665
|
+
blocking: blockingSelected,
|
|
1666
|
+
blockingEntries: input.selectedBlocking.length,
|
|
1667
|
+
waived: input.selectedVerdicts.filter((verdict) => verdict.verdict === 'waived').length,
|
|
1668
|
+
},
|
|
1669
|
+
repositoryDebt: {
|
|
1670
|
+
obligations: input.repositoryVerdicts.length,
|
|
1671
|
+
blocking: blockingRepository + input.repositoryBlocking.length,
|
|
1672
|
+
blockingEntries: input.repositoryBlocking.length,
|
|
1673
|
+
unclaimed: input.unclaimed,
|
|
1674
|
+
},
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1395
1677
|
/** A schema-valid empty catalog (used only when discovery itself failed). */
|
|
1396
1678
|
const EMPTY_CATALOG = {
|
|
1397
1679
|
schemaVersion: 1,
|