@clear-capabilities/agentic-security-scanner 0.172.1 → 0.173.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/CHANGELOG.md +15 -0
- package/bin/agentic-security.js +37 -0
- package/dist/119.index.js +197 -0
- package/dist/128.index.js +129 -0
- package/dist/1293.index.js +5689 -0
- package/dist/1351.index.js +133 -0
- package/dist/1387.index.js +271 -0
- package/dist/1437.index.js +23 -0
- package/dist/1445.index.js +110 -0
- package/dist/1505.index.js +151 -0
- package/dist/1557.index.js +293 -0
- package/dist/1621.index.js +311 -0
- package/dist/1751.index.js +160 -0
- package/dist/1765.index.js +727 -0
- package/dist/1861.index.js +690 -0
- package/dist/1898.index.js +116 -0
- package/dist/1906.index.js +433 -0
- package/dist/1920.index.js +1 -291
- package/dist/208.index.js +1631 -0
- package/dist/2199.index.js +0 -239
- package/dist/2223.index.js +159 -0
- package/dist/2530.index.js +152 -0
- package/dist/2565.index.js +116 -0
- package/dist/2574.index.js +127 -0
- package/dist/2620.index.js +345 -0
- package/dist/2773.index.js +98 -0
- package/dist/2775.index.js +32 -0
- package/dist/2966.index.js +171 -0
- package/dist/2972.index.js +87 -0
- package/dist/2991.index.js +131 -0
- package/dist/3063.index.js +833 -0
- package/dist/3075.index.js +227 -0
- package/dist/3121.index.js +297 -0
- package/dist/3314.index.js +263 -0
- package/dist/3480.index.js +1822 -0
- package/dist/3481.index.js +24 -0
- package/dist/3506.index.js +268 -0
- package/dist/3533.index.js +591 -0
- package/dist/3653.index.js +450 -0
- package/dist/3822.index.js +131 -0
- package/dist/3868.index.js +292 -0
- package/dist/3917.index.js +152 -0
- package/dist/3918.index.js +192 -0
- package/dist/4090.index.js +288 -0
- package/dist/4121.index.js +1190 -0
- package/dist/4142.index.js +0 -239
- package/dist/4336.index.js +436 -0
- package/dist/4387.index.js +532 -0
- package/dist/4413.index.js +302 -0
- package/dist/4476.index.js +4510 -0
- package/dist/4491.index.js +133 -0
- package/dist/4538.index.js +185 -0
- package/dist/4684.index.js +319 -0
- package/dist/4740.index.js +165 -0
- package/dist/4780.index.js +209 -0
- package/dist/4802.index.js +225 -0
- package/dist/4812.index.js +379 -0
- package/dist/4835.index.js +126 -0
- package/dist/494.index.js +226 -0
- package/dist/4991.index.js +549 -0
- package/dist/5199.index.js +305 -0
- package/dist/5216.index.js +109 -0
- package/dist/5439.index.js +301 -0
- package/dist/5443.index.js +97 -0
- package/dist/5496.index.js +377 -0
- package/dist/550.index.js +2 -1
- package/dist/5801.index.js +588 -0
- package/dist/5858.index.js +223 -0
- package/dist/5933.index.js +143 -0
- package/dist/601.index.js +23 -0
- package/dist/6173.index.js +273 -0
- package/dist/6291.index.js +1871 -0
- package/dist/6312.index.js +666 -0
- package/dist/634.index.js +16182 -0
- package/dist/644.index.js +87 -0
- package/dist/6508.index.js +283 -0
- package/dist/6560.index.js +645 -0
- package/dist/6576.index.js +422 -0
- package/dist/6579.index.js +271 -0
- package/dist/6745.index.js +305 -0
- package/dist/6818.index.js +21642 -0
- package/dist/6972.index.js +167 -0
- package/dist/6995.index.js +163 -0
- package/dist/7249.index.js +191 -0
- package/dist/7372.index.js +1197 -0
- package/dist/7546.index.js +541 -0
- package/dist/76.index.js +448 -0
- package/dist/7879.index.js +163 -0
- package/dist/8025.index.js +130 -0
- package/dist/8054.index.js +248 -0
- package/dist/8097.index.js +201 -0
- package/dist/8126.index.js +191 -0
- package/dist/8178.index.js +78 -0
- package/dist/818.index.js +212 -0
- package/dist/8382.index.js +93 -0
- package/dist/8408.index.js +261 -0
- package/dist/8540.index.js +174 -0
- package/dist/8635.index.js +802 -0
- package/dist/8688.index.js +410 -0
- package/dist/8699.index.js +779 -0
- package/dist/8891.index.js +457 -0
- package/dist/8916.index.js +885 -0
- package/dist/9146.index.js +170 -0
- package/dist/9168.index.js +841 -0
- package/dist/9292.index.js +369 -0
- package/dist/9382.index.js +135 -11
- package/dist/9422.index.js +866 -0
- package/dist/9440.index.js +453 -0
- package/dist/9479.index.js +152 -0
- package/dist/9481.index.js +220 -0
- package/dist/9539.index.js +100 -0
- package/dist/9547.index.js +103 -0
- package/dist/9560.index.js +41 -61
- package/dist/9692.index.js +90 -0
- package/dist/9800.index.js +213 -1
- package/dist/9899.index.js +138 -0
- package/dist/9981.index.js +206 -0
- package/dist/999.index.js +117 -0
- package/dist/agentic-security.mjs +27 -27
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/package.json +28 -3
- package/src/context-intelligence/candidates.js +2 -1
- package/src/context-intelligence/capabilities.js +2 -1
- package/src/context-intelligence/cli.js +2 -0
- package/src/context-intelligence/config.js +3 -1
- package/src/context-intelligence/controls.js +49 -1
- package/src/context-intelligence/counterexample.js +200 -0
- package/src/context-intelligence/cross-route.js +111 -0
- package/src/context-intelligence/findings.js +166 -0
- package/src/context-intelligence/invariants.js +197 -0
- package/src/context-intelligence/queue.js +6 -1
- package/src/context-intelligence/reachability.js +2 -2
- package/src/context-intelligence/review.js +68 -4
- package/src/dataflow/access-paths.js +11 -0
- package/src/dataflow/analysis-limits.js +66 -0
- package/src/dataflow/engine.js +272 -20
- package/src/dataflow/service-edges.js +174 -0
- package/src/dataflow/summaries.js +7 -1
- package/src/discovery/judge.js +2 -1
- package/src/engine.js +82 -14
- package/src/fix/apply-fix-service.js +55 -8
- package/src/fix/batch-journal.js +84 -0
- package/src/fix/exploit-replay.js +51 -0
- package/src/fix/footprint.js +65 -0
- package/src/fix/patch-policy.js +49 -0
- package/src/fix/secret-persistence.js +39 -0
- package/src/fix/test-commands.js +84 -0
- package/src/fix/verification-adapters.js +97 -0
- package/src/fix/verification-record.js +243 -0
- package/src/fix/verify-patch.js +89 -0
- package/src/ir/CLAUDE.md +5 -0
- package/src/ir/callgraph.js +23 -1
- package/src/ir/module-resolver.js +315 -0
- package/src/ir/parser-js.js +21 -2
- package/src/ir/semantic-graph.js +245 -0
- package/src/lineage/build-attested-correlation.js +63 -0
- package/src/lineage/deployment-identity.js +76 -0
- package/src/mcp/tools.js +13 -34
- package/src/pipeline/canonical-output.js +64 -0
- package/src/pipeline/detector-runner.js +7 -0
- package/src/pipeline/scan-health.js +14 -0
- package/src/pipeline/supervised-analyzers.js +125 -0
- package/src/pipeline/supervised-child.js +17 -0
- package/src/pipeline/telemetry.js +79 -0
- package/src/posture/accuracy-scorecard.js +98 -9
- package/src/posture/artifact-registry.js +5 -0
- package/src/posture/assurance/evidence-registry.js +215 -0
- package/src/posture/assurance/release-package-verify.js +135 -0
- package/src/posture/assurance/release-package.js +118 -0
- package/src/posture/assurance/release-verdict.js +94 -0
- package/src/posture/assurance/waiver.js +200 -0
- package/src/posture/compliance-truth.js +100 -0
- package/src/posture/evaluation/scan-child.js +3 -1
- package/src/posture/evaluation/why-missed.js +3 -1
- package/src/posture/exploitability-evidence.js +141 -0
- package/src/posture/fix-verify.js +4 -2
- package/src/posture/fleet/exposure-ranking.js +115 -0
- package/src/posture/fleet/service-chain-graph.js +150 -0
- package/src/posture/graph-reconciliation.js +154 -0
- package/src/posture/provenance/coverage.js +103 -0
- package/src/posture/provenance/git-evidence.js +84 -0
- package/src/posture/provenance/origin-resolver.js +7 -1
- package/src/posture/provenance/predicate-replay.js +14 -4
- package/src/posture/runtime-correlation.js +61 -15
- package/src/posture/runtime-explanation.js +116 -0
- package/src/posture/runtime-trace-ingest.js +194 -0
- package/src/posture/scan-checkpoint.js +38 -10
- package/src/posture/waf-ingest.js +7 -2
- package/src/report/index.js +4 -0
- package/src/report/oscal.js +38 -0
- package/src/report/perspectives.js +150 -0
- package/src/sast/_comment-strip.js +8 -1
- package/src/sast/ruby.js +26 -0
- package/src/util/string-memo.js +38 -0
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
export const id = 1765;
|
|
2
|
+
export const ids = [1765,8054];
|
|
3
|
+
export const modules = {
|
|
4
|
+
|
|
5
|
+
/***/ 61765:
|
|
6
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// EXPORTS
|
|
10
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
11
|
+
runInvariantsCommand: () => (/* binding */ runInvariantsCommand)
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// EXTERNAL MODULE: external "node:fs"
|
|
15
|
+
var external_node_fs_ = __webpack_require__(73024);
|
|
16
|
+
// EXTERNAL MODULE: external "node:path"
|
|
17
|
+
var external_node_path_ = __webpack_require__(76760);
|
|
18
|
+
// EXTERNAL MODULE: ./src/posture/assurance/config.js
|
|
19
|
+
var assurance_config = __webpack_require__(20622);
|
|
20
|
+
// EXTERNAL MODULE: ./src/posture/invariants/export.js
|
|
21
|
+
var invariants_export = __webpack_require__(27472);
|
|
22
|
+
// EXTERNAL MODULE: ./src/posture/invariants/coverage.js
|
|
23
|
+
var coverage = __webpack_require__(62104);
|
|
24
|
+
// EXTERNAL MODULE: ./src/posture/assurance/identity.js
|
|
25
|
+
var identity = __webpack_require__(91026);
|
|
26
|
+
// EXTERNAL MODULE: ./src/posture/assurance/schema-kit.js
|
|
27
|
+
var schema_kit = __webpack_require__(99666);
|
|
28
|
+
// EXTERNAL MODULE: ./src/posture/replay/replay.js
|
|
29
|
+
var replay = __webpack_require__(30891);
|
|
30
|
+
// EXTERNAL MODULE: ./src/posture/verification/patch-negative.js
|
|
31
|
+
var patch_negative = __webpack_require__(68054);
|
|
32
|
+
// EXTERNAL MODULE: ./src/posture/verification/repair-records.js
|
|
33
|
+
var repair_records = __webpack_require__(41458);
|
|
34
|
+
// EXTERNAL MODULE: ./src/posture/invariants/schema.js
|
|
35
|
+
var schema = __webpack_require__(11809);
|
|
36
|
+
// EXTERNAL MODULE: ./src/posture/invariants/lifecycle.js
|
|
37
|
+
var lifecycle = __webpack_require__(40828);
|
|
38
|
+
// EXTERNAL MODULE: ./src/posture/invariants/scenarios.js
|
|
39
|
+
var scenarios = __webpack_require__(91963);
|
|
40
|
+
;// CONCATENATED MODULE: ./src/posture/invariants/repair.js
|
|
41
|
+
// Verify a repair against invariants (X-406).
|
|
42
|
+
//
|
|
43
|
+
// A patch for a business-logic violation is `verified-fix` here only when ALL of this is shown by executed, receipted runs on a
|
|
44
|
+
// disposable fixture, each one pinned by a replay manifest (so by commit, fixture hash, patch hash, toolchain and oracle logic):
|
|
45
|
+
//
|
|
46
|
+
// 1. the violated contract is APPROVED (verified ledger, `lifecycle.js`). A model-proposed or code-inferred contract cannot be
|
|
47
|
+
// the ground truth a repair is judged against, so a repair of a candidate violation is never `verified-fix`;
|
|
48
|
+
// 2. the original revision reproduces the violation, and the patched revision no longer does (`verifyPatchNegative`, the same
|
|
49
|
+
// four-run discipline, promotion and repair ledger every other repair uses; this is that module with the business-state
|
|
50
|
+
// oracle as the declared behaviour check, not a second implementation of it);
|
|
51
|
+
// 3. the authorized workflows still work: the scenario's own control flow plus any workflows the requester declares are run as
|
|
52
|
+
// the behaviour check on the original (a baseline, so a wrong expectation is not blamed on the patch) and on the patched
|
|
53
|
+
// revision. A patch that blocks everyone "fixes" the violation and fails here, because the business-state oracle will not
|
|
54
|
+
// call a flow clean unless the application visibly changed durable state;
|
|
55
|
+
// 4. every OTHER approved contract on the same fixture is still not violated: its bounded scenarios run on both revisions. A
|
|
56
|
+
// violation that appears only on the patched revision is a regression and blocks; one already present on the original is
|
|
57
|
+
// reported as pre-existing and is not blamed on the patch. Proposed contracts are not required (they are advisory).
|
|
58
|
+
//
|
|
59
|
+
// Anything else blocks, with an explicit reason code from `REASON_CODES`: failed setup (a prerequisite, the harness, a rejected
|
|
60
|
+
// manifest), an unsupported or inconclusive check, a violation that is still reproduced, a broken authorized workflow, an
|
|
61
|
+
// unrelated invariant that now fails, an unapproved contract. A blocked result never reads as a pass.
|
|
62
|
+
//
|
|
63
|
+
// The regression artifact. A verified repair yields a self-contained document: the exact patch, the invariant revision and its
|
|
64
|
+
// approval evidence, the exploit scenario, and one replay manifest per leg with its expected outcome. `runRegressionArtifact`
|
|
65
|
+
// re-executes every leg from the artifact alone (no agent conversation, no in-process receipt: each leg runs again through the
|
|
66
|
+
// trust boundary) and passes only if every leg settles as recorded. It carries the fixture and patch source, so it refuses to be
|
|
67
|
+
// built if either holds a credential.
|
|
68
|
+
//
|
|
69
|
+
// Limits, stated: only the declared exploit scenario, the declared authorized workflows and the other contracts' bounded
|
|
70
|
+
// scenarios are exercised; the patch is not shown correct anywhere else. The approval evidence in the artifact is a digest and a
|
|
71
|
+
// transition id; verifying the HMAC needs the operator's key (symmetric: tamper-evidence, not third-party non-repudiation).
|
|
72
|
+
// Receipts are valid inside the verifier's process; the artifact is how a result crosses a process, by re-execution. Linux is
|
|
73
|
+
// not claimed.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
const ARTIFACT_SCHEMA = 'agentic-security/invariant-regression-artifact';
|
|
86
|
+
const REASON_CODES = Object.freeze([
|
|
87
|
+
'feature-disabled', 'bad-request', 'invariant-not-approved', 'setup-failed', 'unsupported-check', 'original-not-reproduced',
|
|
88
|
+
'violation-not-eliminated', 'authorized-workflow-broken', 'workflow-regression', 'workflow-check-inconclusive', 'workflow-baseline-invalid',
|
|
89
|
+
'invariant-regression', 'preservation-inconclusive', 'preservation-unsupported', 'patched-check-inconclusive',
|
|
90
|
+
'oracle-changed', 'environment-mismatch', 'promotion-refused', 'revision-unbound', 'artifact-refused',
|
|
91
|
+
]);
|
|
92
|
+
const REQUIRED_FEATURES = Object.freeze([scenarios/* FEATURE */.RI, 'verification-oracles', 'patch-negative-verification']);
|
|
93
|
+
const SCENARIO_SCHEMA = 'agentic-security/invariant-scenario';
|
|
94
|
+
const MAX_WORKFLOW_ITEMS = 12;
|
|
95
|
+
const EXPECT = Object.freeze({ original: 'confirmed', patched: 'refuted', workflowBaseline: 'refuted', workflow: 'refuted' });
|
|
96
|
+
|
|
97
|
+
const copy = (v) => JSON.parse(JSON.stringify(v));
|
|
98
|
+
const blocker = (code, step, reason, extra = {}) => ({ code, step, reason: String(reason).slice(0, 400), ...extra });
|
|
99
|
+
|
|
100
|
+
// patch-negative's typed failure -> the reason code a reader of an invariant repair sees
|
|
101
|
+
const CODE_OF = Object.freeze({
|
|
102
|
+
'original-not-reproduced': 'original-not-reproduced',
|
|
103
|
+
'patched-still-exploitable': 'violation-not-eliminated',
|
|
104
|
+
'patched-build-broken': 'authorized-workflow-broken',
|
|
105
|
+
'patched-negative-inconclusive': 'patched-check-inconclusive',
|
|
106
|
+
'functional-inconclusive': 'workflow-check-inconclusive',
|
|
107
|
+
'functional-regression-detected': 'workflow-regression',
|
|
108
|
+
'functional-baseline-invalid': 'workflow-baseline-invalid',
|
|
109
|
+
'functional-omitted': 'unsupported-check',
|
|
110
|
+
'prerequisite-unmet': 'setup-failed', 'harness-error': 'setup-failed', 'manifest-rejected': 'setup-failed', 'content-hash-mismatch': 'setup-failed',
|
|
111
|
+
'oracle-changed': 'oracle-changed', 'environment-mismatch': 'environment-mismatch', 'promotion-refused': 'promotion-refused', 'revision-unbound': 'revision-unbound',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/** The reason code (from `REASON_CODES`) for a patch-negative failure code; unknown ones become `setup-failed`, never a pass. */
|
|
115
|
+
function reasonCodeFor(failureCode) { return CODE_OF[failureCode] || 'setup-failed'; }
|
|
116
|
+
|
|
117
|
+
const validStep = (s, actors) => isPlainObject(s) && actors.has(s.actor) && typeof s.action === 'string' && /^[A-Za-z_$][\w$]{0,63}$/.test(s.action)
|
|
118
|
+
&& (s.args === undefined || (Array.isArray(s.args) && s.args.length <= 4));
|
|
119
|
+
|
|
120
|
+
/** The business-state inputs of the authorized-workflow check: the scenario's control flow plus declared workflows, as both phases. */
|
|
121
|
+
function workflowInputs(scenario, extra) {
|
|
122
|
+
const actors = new Set(scenario.inputs.actors.map((a) => a.id));
|
|
123
|
+
const steps = copy(scenario.inputs.control);
|
|
124
|
+
for (const wf of Array.isArray(extra) ? extra : []) {
|
|
125
|
+
if (!Array.isArray(wf) || !wf.every((s) => validStep(s, actors))) return { error: 'a declared workflow is a list of steps by declared actors, each with an action identifier' };
|
|
126
|
+
for (const s of wf) steps.push(copy(s));
|
|
127
|
+
}
|
|
128
|
+
if (steps.length > MAX_WORKFLOW_ITEMS) return { error: `the authorized workflows exceed ${MAX_WORKFLOW_ITEMS} steps` };
|
|
129
|
+
return { inputs: { ...copy(scenario.inputs), control: copy(steps), attack: steps } };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function approvalEvidence(ledger, verified, invariant) {
|
|
133
|
+
const rec = [...(ledger?.records || [])].reverse().find((r) => r.invariantId === invariant.id && r.action === 'approve');
|
|
134
|
+
const head = ledger?.records?.length ? ledger.records[ledger.records.length - 1].id : null;
|
|
135
|
+
return { state: verified.ok ? (verified.states[invariant.id] ?? 'unrecorded') : 'unverified', transitionId: rec?.id ?? null, reviewer: rec?.actor?.id ?? null, authority: rec?.policyId ?? null, ledgerHead: head, ledgerDigest: ledger ? digestOf(ledger.records) : null };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function runLeg(manifest, fixtureFiles, patchFiles, o) {
|
|
139
|
+
try {
|
|
140
|
+
return await (0,replay/* replayManifest */.TY)({ manifest, fixtureFiles, patchFiles }, { config: o.config, runOptions: o.runOptions, hostEnvironment: o.hostEnvironment });
|
|
141
|
+
} catch (e) {
|
|
142
|
+
return { status: 'rejected', executed: false, outcome: null, errors: [{ code: 'RUN_FAILED', message: String(e?.message || e).slice(0, 200) }] };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Run the bounded scenarios of one other approved contract on both revisions and judge preservation. */
|
|
147
|
+
async function preserveOther(other, ctx) {
|
|
148
|
+
const entry = { invariantId: other.id, key: other.key, revision: other.revision, status: 'preserved', legs: [], preexisting: [], blockers: [] };
|
|
149
|
+
const gen = generateScenarios(other, { fixture: ctx.fixture, config: ctx.config, bounds: ctx.bounds });
|
|
150
|
+
if (gen.status !== 'ok' || !gen.scenarios.length) {
|
|
151
|
+
entry.status = 'unsupported';
|
|
152
|
+
entry.blockers.push(blocker('preservation-unsupported', `preserve:${other.key}`, gen.reason || (gen.unsupported[0]?.reason ?? 'no scenario could be built for this contract on this fixture'), { invariant: other.id }));
|
|
153
|
+
return entry;
|
|
154
|
+
}
|
|
155
|
+
for (const s of gen.scenarios) {
|
|
156
|
+
const mk = (patchFiles) => createReplayManifest({
|
|
157
|
+
hypothesisId: s.id, commit: ctx.commit, fixtureFiles: ctx.fixture.files, patchFiles, oracleId: 'business-state', entry: s.entry, inputs: s.inputs, budgets: { timeoutMs: s.limits.timeBudgetMs },
|
|
158
|
+
});
|
|
159
|
+
const baseManifest = mk(null);
|
|
160
|
+
const patchManifest = mk(ctx.patchFiles);
|
|
161
|
+
const base = await runLeg(baseManifest, ctx.fixture.files, null, ctx);
|
|
162
|
+
const pat = await runLeg(patchManifest, ctx.fixture.files, ctx.patchFiles, ctx);
|
|
163
|
+
const where = `preserve:${other.key}:${s.kind}`;
|
|
164
|
+
const leg = { scenarioId: s.id, kind: s.kind, baseline: base.outcome ?? base.status, patched: pat.outcome ?? pat.status, baselineReceipt: base.receipt?.receiptDigest ?? null, patchedReceipt: pat.receipt?.receiptDigest ?? null };
|
|
165
|
+
entry.legs.push(leg);
|
|
166
|
+
if (base.status !== 'completed' || pat.status !== 'completed') {
|
|
167
|
+
const why = base.status !== 'completed' ? base : pat;
|
|
168
|
+
entry.blockers.push(blocker('setup-failed', where, (why.prerequisites || []).map((p) => `${p.kind} ${p.id} (${p.state})`).join('; ') || why.errors?.[0]?.message || 'the preservation run did not execute', { invariant: other.id }));
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (!['refuted', 'confirmed'].includes(base.outcome)) {
|
|
172
|
+
entry.blockers.push(blocker('preservation-inconclusive', where, `the original revision settled '${base.outcome}' for this contract, so preservation cannot be shown`, { invariant: other.id }));
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (base.outcome === 'confirmed') {
|
|
176
|
+
leg.note = 'pre-existing violation on the original revision; not blamed on the patch';
|
|
177
|
+
entry.preexisting.push({ scenarioId: s.id, kind: s.kind, patched: pat.outcome });
|
|
178
|
+
if (!['refuted', 'confirmed'].includes(pat.outcome)) entry.blockers.push(blocker('preservation-inconclusive', where, `the patched revision settled '${pat.outcome}'`, { invariant: other.id }));
|
|
179
|
+
ctx.legs.push({ role: `${where}:baseline`, patched: false, manifest: baseManifest, expected: base.outcome }, { role: `${where}:patched`, patched: true, manifest: patchManifest, expected: pat.outcome });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (pat.outcome === 'confirmed') entry.blockers.push(blocker('invariant-regression', where, `the patch makes an approved contract fail that held on the original: ${String(pat.record?.reason || '').slice(0, 200)}`, { invariant: other.id }));
|
|
183
|
+
else if (pat.outcome !== 'refuted') entry.blockers.push(blocker('preservation-inconclusive', where, `the patched revision settled '${pat.outcome}': ${String(pat.record?.reason || '').slice(0, 200)}`, { invariant: other.id }));
|
|
184
|
+
ctx.legs.push({ role: `${where}:baseline`, patched: false, manifest: baseManifest, expected: 'refuted' }, { role: `${where}:patched`, patched: true, manifest: patchManifest, expected: 'refuted' });
|
|
185
|
+
}
|
|
186
|
+
if (entry.blockers.length) entry.status = 'blocked';
|
|
187
|
+
return entry;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Verify one repair against an approved invariant, the authorized workflows and every other approved invariant. Never throws.
|
|
192
|
+
*
|
|
193
|
+
* @param {object} req
|
|
194
|
+
* @param {object} req.invariant the violated contract (a valid invariant document)
|
|
195
|
+
* @param {object} req.ledger the approval ledger; the contract must be approved in it
|
|
196
|
+
* @param {object} req.scenario a scenario that reproduces the violation (generated, or the minimized one from `shrinkScenario`)
|
|
197
|
+
* @param {{ files: object }} req.fixture the disposable fixture the scenario was generated from
|
|
198
|
+
* @param {{ files: object }} req.patch the exact diff: the new content of each changed file
|
|
199
|
+
* @param {string} req.commit exact revision the patch is proposed against
|
|
200
|
+
* @param {object[][]} [req.workflows] extra authorized workflows (lists of steps by declared actors)
|
|
201
|
+
* @param {object[]} [req.others] other invariant documents on the same fixture; the approved ones must still hold
|
|
202
|
+
* @param {object[]} [req.repairRecords] an earlier repair ledger to extend
|
|
203
|
+
* @param {object} [req.shrinkRecordId] id of the shrink record when the scenario is a minimized one (carried into the artifact)
|
|
204
|
+
* @param {object} [o] { config, runOptions, signer, bounds }
|
|
205
|
+
*/
|
|
206
|
+
async function verifyInvariantRepair(req, o = {}) {
|
|
207
|
+
const config = o.config || resolveAssuranceConfig({ env: process.env });
|
|
208
|
+
const base = { status: 'not-verified-fix', verifiedFix: false, blockers: [], patchNegative: null, preservation: [], notRequired: [], artifact: null, repairRecords: Array.isArray(req?.repairRecords) ? req.repairRecords : [], verificationRecord: null, summary: '' };
|
|
209
|
+
const done = (extra) => {
|
|
210
|
+
const r = { ...base, ...extra };
|
|
211
|
+
r.reasonCodes = [...new Set(r.blockers.map((b) => b.code))];
|
|
212
|
+
r.summary = r.verifiedFix
|
|
213
|
+
? 'verified-fix: the violation is gone on the patched revision, the authorized workflows and every other approved contract still hold. Only the declared scenario, workflows and the other contracts\' bounded scenarios were exercised.'
|
|
214
|
+
: `NOT verified-fix: ${r.blockers.map((b) => `${b.code} (${b.step})`).join('; ') || 'not reached'}`;
|
|
215
|
+
return r;
|
|
216
|
+
};
|
|
217
|
+
const stop = (status, ...blockers) => done({ status, blockers });
|
|
218
|
+
|
|
219
|
+
for (const f of REQUIRED_FEATURES) {
|
|
220
|
+
const gate = featureStatus(config, f);
|
|
221
|
+
if (gate.status !== 'ok') return stop('disabled', blocker('feature-disabled', 'feature-gate', `${f} is not available: ${gate.reason}`));
|
|
222
|
+
}
|
|
223
|
+
// ---- shape: nothing executes on a malformed request
|
|
224
|
+
const inv = req?.invariant;
|
|
225
|
+
const valid = validateInvariant(inv);
|
|
226
|
+
const scenario = req?.scenario;
|
|
227
|
+
const fixtureFiles = req?.fixture?.files;
|
|
228
|
+
const patchFiles = req?.patch?.files;
|
|
229
|
+
if (!valid.ok) return stop('rejected', blocker('bad-request', 'input-validation', 'the invariant is not valid'));
|
|
230
|
+
if (!isPlainObject(scenario) || scenario.schema !== SCENARIO_SCHEMA || scenario.invariant?.id !== inv.id) return stop('rejected', blocker('bad-request', 'input-validation', 'the scenario is missing or belongs to a different invariant'));
|
|
231
|
+
if (!isPlainObject(fixtureFiles) || digestOf(fixtureFiles) !== scenario.fixtureDigest) return stop('rejected', blocker('bad-request', 'input-validation', 'the fixture is missing or does not match the scenario\'s pinned digest'));
|
|
232
|
+
if (!isPlainObject(patchFiles) || !Object.keys(patchFiles).length) return stop('rejected', blocker('bad-request', 'input-validation', 'a repair needs a non-empty patch'));
|
|
233
|
+
if (!isCommit(req.commit)) return stop('rejected', blocker('revision-unbound', 'input-validation', 'no exact commit was given: a verdict cannot be tied to a revision'));
|
|
234
|
+
const wf = workflowInputs(scenario, req.workflows);
|
|
235
|
+
if (wf.error) return stop('rejected', blocker('bad-request', 'input-validation', wf.error));
|
|
236
|
+
|
|
237
|
+
// ---- the contract must be approved: a repair is judged against a requirement a reviewer owns, not against a guess
|
|
238
|
+
const verified = verifyLedger(req.ledger, { signer: o.signer });
|
|
239
|
+
const approval = approvalEvidence(req.ledger, verified, inv);
|
|
240
|
+
if (approval.state !== 'approved') {
|
|
241
|
+
return done({ status: 'not-verified-fix', approval, blockers: [blocker('invariant-not-approved', 'approval', approval.state === 'unverified'
|
|
242
|
+
? 'the approval ledger does not verify, so no contract counts as approved'
|
|
243
|
+
: `the contract is ${approval.state}: only a reviewer-approved contract can define a verified fix; a model- or code-derived contract does not establish its own ground truth`)] });
|
|
244
|
+
}
|
|
245
|
+
const others = (Array.isArray(req.others) ? req.others : []).filter((x) => isPlainObject(x) && x.id !== inv.id);
|
|
246
|
+
const requiredOthers = []; const notRequired = [];
|
|
247
|
+
for (const x of others) {
|
|
248
|
+
const state = verified.states[x.id];
|
|
249
|
+
if (state === 'approved' && validateInvariant(x).ok) requiredOthers.push(x);
|
|
250
|
+
else notRequired.push({ invariantId: x.id ?? null, key: x.key ?? null, state: state ?? 'unrecorded', reason: 'only approved contracts must be preserved; this one is advisory' });
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// ---- the four-run repair verification, with the authorized workflows as the declared behaviour check
|
|
254
|
+
const budgets = { timeoutMs: scenario.limits.timeBudgetMs };
|
|
255
|
+
const pn = await verifyPatchNegative({
|
|
256
|
+
hypothesisId: scenario.id, commit: req.commit, ledger: req.repairRecords,
|
|
257
|
+
original: { files: fixtureFiles, entry: scenario.entry, oracleId: 'business-state', inputs: scenario.inputs, budgets },
|
|
258
|
+
patch: { files: patchFiles },
|
|
259
|
+
functional: { oracleId: 'business-state', inputs: wf.inputs, budgets },
|
|
260
|
+
}, { config, runOptions: o.runOptions });
|
|
261
|
+
const common = { approval, patchNegative: pn, notRequired, repairRecords: pn.repairRecords, verificationRecord: pn.verificationRecord };
|
|
262
|
+
if (!pn.verifiedFix) {
|
|
263
|
+
return done({ ...common, status: pn.status === 'disabled' ? 'disabled' : 'not-verified-fix', blockers: [blocker(reasonCodeFor(pn.failureCode), pn.incompleteStep || 'verification', pn.reason || 'the repair verification did not complete', { underlying: pn.failureCode, resumable: pn.resumable === true })] });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ---- every other approved contract must still hold
|
|
267
|
+
const ctx = { fixture: { files: fixtureFiles }, patchFiles, commit: req.commit, config, runOptions: o.runOptions, bounds: o.bounds, legs: [] };
|
|
268
|
+
const preservation = [];
|
|
269
|
+
for (const x of requiredOthers) preservation.push(await preserveOther(x, ctx));
|
|
270
|
+
const blockers = preservation.flatMap((p) => p.blockers);
|
|
271
|
+
if (blockers.length) {
|
|
272
|
+
const rejected = appendRepairRecord(pn.repairRecords, { kind: 'rejected', hypothesisId: scenario.id, revision: req.commit, diffDigest: pn.patchDigest, step: 'invariant-preservation', reason: `${blockers[0].code}: ${blockers[0].reason}`.slice(0, 300) });
|
|
273
|
+
const repairRecords = rejected.ok ? rejected.records : pn.repairRecords;
|
|
274
|
+
const downgraded = pn.records?.original ? withRepairStatus(pn.records.original, verificationRepairFor(repairRecords, scenario.id, pn.patchDigest)) : pn.verificationRecord;
|
|
275
|
+
return done({ ...common, status: 'not-verified-fix', preservation, blockers, repairRecords, verificationRecord: downgraded });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const artifact = buildRegressionArtifact({
|
|
279
|
+
invariant: inv, approval, scenario, fixtureFiles, patchFiles, commit: req.commit, budgets, workflowInputs: wf.inputs, extraLegs: ctx.legs, pn, shrinkRecordId: req.shrinkRecordId ?? null, repairRecords: pn.repairRecords,
|
|
280
|
+
});
|
|
281
|
+
if (!artifact.ok) {
|
|
282
|
+
return done({ ...common, status: 'not-verified-fix', preservation, blockers: [blocker('artifact-refused', 'regression-artifact', artifact.reason)], artifactErrors: artifact.errors });
|
|
283
|
+
}
|
|
284
|
+
return done({ ...common, status: 'verified-fix', verifiedFix: true, preservation, artifact: artifact.artifact });
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ---------------------------------------------------------------- the regression artifact
|
|
288
|
+
|
|
289
|
+
function leg(role, manifest, patched, expected) { return { role, patched, expected, manifest }; }
|
|
290
|
+
|
|
291
|
+
function buildRegressionArtifact({ invariant, approval, scenario, fixtureFiles, patchFiles, commit, budgets, workflowInputs: wfi, extraLegs, pn, shrinkRecordId, repairRecords }) {
|
|
292
|
+
const secrets = [...findSecrets(fixtureFiles).map((s) => ({ ...s, where: `fixture:${s.where}` })), ...findSecrets(patchFiles).map((s) => ({ ...s, where: `patch:${s.where}` }))];
|
|
293
|
+
if (secrets.length) return { ok: false, reason: 'the fixture or the patch holds secret-looking content; a self-contained artifact would embed it', errors: secrets };
|
|
294
|
+
const mk = (spec) => createReplayManifest({ hypothesisId: scenario.id, commit, fixtureFiles, patchFiles: spec.patched ? patchFiles : null, oracleId: 'business-state', entry: scenario.entry, inputs: spec.inputs, budgets, expected: { outcome: spec.expected } });
|
|
295
|
+
const legs = [
|
|
296
|
+
leg('original-positive', mk({ patched: false, inputs: scenario.inputs, expected: EXPECT.original }), false, EXPECT.original),
|
|
297
|
+
leg('patched-negative', mk({ patched: true, inputs: scenario.inputs, expected: EXPECT.patched }), true, EXPECT.patched),
|
|
298
|
+
leg('workflow-baseline', mk({ patched: false, inputs: wfi, expected: EXPECT.workflowBaseline }), false, EXPECT.workflowBaseline),
|
|
299
|
+
leg('workflow-preserved', mk({ patched: true, inputs: wfi, expected: EXPECT.workflow }), true, EXPECT.workflow),
|
|
300
|
+
...extraLegs,
|
|
301
|
+
];
|
|
302
|
+
// the manifests rebuilt here must be the ones the verification actually ran: compare what each receipt pinned
|
|
303
|
+
const pins = [['original', legs[0]], ['patched', legs[1]], ['functionalBaseline', legs[2]], ['functional', legs[3]]];
|
|
304
|
+
for (const [role, l] of pins) {
|
|
305
|
+
const r = pn.receipts?.[role];
|
|
306
|
+
if (!r || r.request.inputsDigest !== l.manifest.inputsDigest || r.request.entry !== l.manifest.entry) return { ok: false, reason: `the ${role} manifest does not match the run the verification executed`, errors: [] };
|
|
307
|
+
}
|
|
308
|
+
const body = {
|
|
309
|
+
schema: ARTIFACT_SCHEMA, schemaVersion: SCHEMA_VERSION, hypothesisId: scenario.id, commit,
|
|
310
|
+
patch: { digest: digestOf(patchFiles), files: copy(patchFiles) },
|
|
311
|
+
fixture: { digest: digestOf(fixtureFiles), files: copy(fixtureFiles) },
|
|
312
|
+
invariant: { id: invariant.id, key: invariant.key, revision: invariant.revision, class: invariant.class, document: copy(invariant), approval },
|
|
313
|
+
scenario: { id: scenario.id, digest: digestOf(scenario), document: copy(scenario), shrinkRecordId },
|
|
314
|
+
legs,
|
|
315
|
+
repair: { diffDigest: pn.patchDigest, ledger: copy(repairRecords) },
|
|
316
|
+
scope: 'the declared exploit scenario, the declared authorized workflows and the bounded scenarios of the other approved contracts, on one disposable fixture; the patch is not shown correct anywhere else',
|
|
317
|
+
};
|
|
318
|
+
body.id = semanticId('rart', { ...body, legDigests: legs.map((l) => l.manifest.id) }, ['hypothesisId', 'commit', 'patch', 'invariant', 'legDigests']);
|
|
319
|
+
body.artifactDigest = digestOf({ ...body });
|
|
320
|
+
return { ok: true, artifact: body };
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Structural and integrity check of an artifact, without executing anything. Never throws. */
|
|
324
|
+
function validateRegressionArtifact(a) {
|
|
325
|
+
const errors = [];
|
|
326
|
+
const fail = (code, message) => errors.push({ code, message });
|
|
327
|
+
try {
|
|
328
|
+
if (!(0,schema_kit/* isPlainObject */.Qd)(a) || a.schema !== ARTIFACT_SCHEMA) return { ok: false, errors: [{ code: 'malformed', message: 'not a regression artifact' }] };
|
|
329
|
+
const { artifactDigest, ...rest } = a;
|
|
330
|
+
if ((0,identity/* digestOf */.ol)(rest) !== artifactDigest) fail('artifact-tampered', 'the artifact does not match its digest');
|
|
331
|
+
if ((0,identity/* digestOf */.ol)(a.patch?.files) !== a.patch?.digest) fail('patch-tampered', 'the patch files do not match the recorded patch digest');
|
|
332
|
+
if ((0,identity/* digestOf */.ol)(a.fixture?.files) !== a.fixture?.digest) fail('fixture-tampered', 'the fixture files do not match the recorded fixture digest');
|
|
333
|
+
if ((0,identity/* digestOf */.ol)(a.scenario?.document) !== a.scenario?.digest) fail('scenario-tampered', 'the scenario does not match its digest');
|
|
334
|
+
if (a.scenario?.document?.fixtureDigest !== a.fixture?.digest) fail('fixture-pin-mismatch', 'the scenario pins a different fixture than the artifact carries');
|
|
335
|
+
if (a.invariant?.document?.id !== a.invariant?.id) fail('invariant-mismatch', 'the invariant document does not match the recorded id');
|
|
336
|
+
if (a.invariant?.approval?.state !== 'approved') fail('not-approved', 'the artifact records an invariant that was not approved');
|
|
337
|
+
if (!Array.isArray(a.legs) || a.legs.length < 4) fail('legs-missing', 'the four required legs are not all present');
|
|
338
|
+
for (const l of a.legs || []) {
|
|
339
|
+
if (l.manifest?.repository?.commit !== a.commit) fail('leg-commit', `leg ${l.role} is pinned to a different commit`);
|
|
340
|
+
if (l.manifest?.fixture?.digest !== a.fixture?.digest) fail('leg-fixture', `leg ${l.role} pins a different fixture`);
|
|
341
|
+
const wantPatch = l.patched ? a.patch?.digest : null;
|
|
342
|
+
if ((l.manifest?.patch?.digest ?? null) !== wantPatch) fail('leg-patch', `leg ${l.role} does not carry the artifact's exact patch`);
|
|
343
|
+
}
|
|
344
|
+
const roles = (a.legs || []).map((l) => l.role);
|
|
345
|
+
for (const r of ['original-positive', 'patched-negative', 'workflow-baseline', 'workflow-preserved']) if (!roles.includes(r)) fail('leg-missing', `required leg '${r}' is absent`);
|
|
346
|
+
} catch (e) {
|
|
347
|
+
fail('malformed', `the check could not complete: ${String(e?.message || e).slice(0, 120)}`);
|
|
348
|
+
}
|
|
349
|
+
return { ok: errors.length === 0, errors };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Re-execute a regression artifact from the artifact alone. Passes only if every leg settles as recorded. Never throws.
|
|
354
|
+
* @param {object} artifact
|
|
355
|
+
* @param {object} [o] { config, runOptions, hostEnvironment }
|
|
356
|
+
* @returns {Promise<{ status: 'passed'|'failed'|'invalid'|'prerequisite-unmet'|'disabled', legs: object[], reasonCodes: string[], summary: string }>}
|
|
357
|
+
*/
|
|
358
|
+
async function runRegressionArtifact(artifact, o = {}) {
|
|
359
|
+
const check = validateRegressionArtifact(artifact);
|
|
360
|
+
if (!check.ok) return { status: 'invalid', legs: [], reasonCodes: [...new Set(check.errors.map((e) => e.code))], errors: check.errors, summary: `the artifact was not run: ${check.errors[0].message}` };
|
|
361
|
+
const config = o.config || (0,assurance_config.resolveAssuranceConfig)({ env: process.env });
|
|
362
|
+
for (const f of ['verification-oracles', scenarios/* FEATURE */.RI]) {
|
|
363
|
+
const gate = (0,assurance_config/* featureStatus */.FX)(config, f);
|
|
364
|
+
if (gate.status !== 'ok') return { status: 'disabled', legs: [], reasonCodes: ['feature-disabled'], summary: `${f} is not available: ${gate.reason}` };
|
|
365
|
+
}
|
|
366
|
+
const legs = [];
|
|
367
|
+
let blocked = false;
|
|
368
|
+
for (const l of artifact.legs) {
|
|
369
|
+
const run = await runLeg(l.manifest, artifact.fixture.files, l.patched ? artifact.patch.files : null, { config, runOptions: o.runOptions, hostEnvironment: o.hostEnvironment });
|
|
370
|
+
const awaiting = run.status === 'awaiting-prerequisites';
|
|
371
|
+
if (awaiting) blocked = true;
|
|
372
|
+
legs.push({ role: l.role, expected: l.expected, outcome: run.outcome ?? null, status: run.status, matched: run.status === 'completed' && run.outcome === l.expected, recordId: run.record?.id ?? null, receiptDigest: run.receipt?.receiptDigest ?? null, prerequisites: awaiting ? (run.prerequisites || []).map((p) => `${p.kind}:${p.id}:${p.state}`) : [] });
|
|
373
|
+
}
|
|
374
|
+
const failed = legs.filter((l) => !l.matched);
|
|
375
|
+
const status = !failed.length ? 'passed' : blocked ? 'prerequisite-unmet' : 'failed';
|
|
376
|
+
return {
|
|
377
|
+
status, legs, reasonCodes: failed.map((l) => (l.status === 'completed' ? (l.role === 'original-positive' ? 'original-not-reproduced' : l.role === 'patched-negative' ? 'violation-not-eliminated' : l.role.startsWith('preserve:') ? 'invariant-regression' : 'workflow-regression') : 'setup-failed')),
|
|
378
|
+
summary: status === 'passed' ? `all ${legs.length} legs settled as recorded` : `${failed.length} of ${legs.length} legs did not settle as recorded: ${failed.map((l) => `${l.role} (expected ${l.expected}, got ${l.outcome ?? l.status})`).join('; ')}`,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// EXTERNAL MODULE: ./src/posture/invariants/project-input.js
|
|
383
|
+
var project_input = __webpack_require__(67340);
|
|
384
|
+
;// CONCATENATED MODULE: ./src/posture/invariants/cli.js
|
|
385
|
+
// `agentic-security invariants <export|coverage|regress>` (X-405 to X-407 CLI surface).
|
|
386
|
+
//
|
|
387
|
+
// invariants export --invariant <file> --fixture <dir> [--ledger <file>] [--commit <sha>] [--seed <n>] [--output <file>] [--json]
|
|
388
|
+
// The reproducible scenario package for one contract (see export.js). Builds nothing and runs nothing when the
|
|
389
|
+
// `invariant-scenarios` feature is off. Exit 0 ok, 1 refused (disabled, rejected, unsupported, blocked), 2 usage.
|
|
390
|
+
// invariants coverage --invariant <file> | --invariants-dir <dir> [--ledger <file>] [--results <file>] [--json]
|
|
391
|
+
// The bounded business-coverage report (see coverage.js). `--results` is a JSON array of `{ invariantId, result }` where
|
|
392
|
+
// `result` is what `verifyInvariant` returned; without it the report is the static inventory with every contract's
|
|
393
|
+
// transitions listed as untested, which is the honest answer when nothing was run. Exit 0, 1 refused, 2 usage.
|
|
394
|
+
// invariants regress <artifact.json>
|
|
395
|
+
// Re-execute a regression artifact from the file alone (see repair.js). Exit 0 every leg settled as recorded, 1 a leg did
|
|
396
|
+
// not (or the artifact is invalid), 3 not run (a prerequisite is unmet or the feature is off): not-run is not a pass.
|
|
397
|
+
//
|
|
398
|
+
// The logic lives here, not in bin/, so the same functions are exercised by tests without spawning the CLI; bin/ only
|
|
399
|
+
// dispatches. Paths are the operator's own and are resolved against the working directory (the MCP tool, which takes paths from
|
|
400
|
+
// an agent, confines them to its session root instead).
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
const USAGE = [
|
|
410
|
+
'Usage: agentic-security invariants export --invariant <file> --fixture <dir> [--ledger <file>] [--commit <sha>] [--seed <n>] [--output <file>] [--json]',
|
|
411
|
+
' agentic-security invariants coverage --invariant <file> | --invariants-dir <dir> [--ledger <file>] [--results <file>] [--json]',
|
|
412
|
+
' agentic-security invariants regress <artifact.json>',
|
|
413
|
+
].join('\n');
|
|
414
|
+
|
|
415
|
+
const abs = (cwd, p) => external_node_path_.resolve(cwd, String(p));
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* @param {{ _: string[], flags: object }} args parsed arguments; `_[0]` is `invariants`, `_[1]` the sub-command
|
|
419
|
+
* @param {{ cwd?: string, out?: (s: string) => void, err?: (s: string) => void, env?: object }} [io]
|
|
420
|
+
* @returns {Promise<number>} the exit code
|
|
421
|
+
*/
|
|
422
|
+
async function runInvariantsCommand(args, io = {}) {
|
|
423
|
+
const cwd = io.cwd || process.cwd();
|
|
424
|
+
const out = io.out || ((s) => process.stdout.write(s));
|
|
425
|
+
const err = io.err || ((s) => process.stderr.write(s));
|
|
426
|
+
const sub = args._[1];
|
|
427
|
+
const flags = args.flags || {};
|
|
428
|
+
const config = (0,assurance_config.resolveAssuranceConfig)({ scanRoot: cwd, env: io.env || process.env });
|
|
429
|
+
const emit = (value, lines) => out(flags.json ? `${JSON.stringify(value, null, 2)}\n` : `${lines.join('\n')}\n`);
|
|
430
|
+
|
|
431
|
+
if (sub === 'export') {
|
|
432
|
+
if (typeof flags.invariant !== 'string' || typeof flags.fixture !== 'string') { err(`${USAGE}\n`); return 2; }
|
|
433
|
+
const r = (0,invariants_export/* exportFromFiles */.iF)({
|
|
434
|
+
invariantPath: abs(cwd, flags.invariant), fixturePath: abs(cwd, flags.fixture), ledgerPath: typeof flags.ledger === 'string' ? abs(cwd, flags.ledger) : undefined,
|
|
435
|
+
commit: typeof flags.commit === 'string' ? flags.commit : undefined, seed: flags.seed !== undefined ? Number(flags.seed) : undefined, config,
|
|
436
|
+
});
|
|
437
|
+
if (r.status !== 'ok') { err(`agentic-security invariants export: ${r.status}: ${r.reason ?? ''}\n`); return 1; }
|
|
438
|
+
const text = `${JSON.stringify(r.export, null, 2)}\n`;
|
|
439
|
+
if (typeof flags.output === 'string') {
|
|
440
|
+
external_node_fs_.writeFileSync(abs(cwd, flags.output), text);
|
|
441
|
+
out(`wrote ${r.export.scenarios.length} scenario(s) to ${flags.output}${r.withheld.length ? `; ${r.withheld.length} withheld (secret-looking content)` : ''}\n`);
|
|
442
|
+
} else out(text);
|
|
443
|
+
return 0;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (sub === 'coverage') {
|
|
447
|
+
let files = [];
|
|
448
|
+
if (typeof flags.invariant === 'string') files = [abs(cwd, flags.invariant)];
|
|
449
|
+
else if (typeof flags['invariants-dir'] === 'string') {
|
|
450
|
+
try { files = external_node_fs_.readdirSync(abs(cwd, flags['invariants-dir'])).filter((f) => f.endsWith('.json')).sort().map((f) => external_node_path_.join(abs(cwd, flags['invariants-dir']), f)); } catch { err('agentic-security invariants coverage: the invariants directory is unreadable\n'); return 1; }
|
|
451
|
+
} else { err(`${USAGE}\n`); return 2; }
|
|
452
|
+
const docs = [];
|
|
453
|
+
for (const f of files) {
|
|
454
|
+
const j = (0,project_input/* readJsonFile */.J)(f);
|
|
455
|
+
if (!j.ok) { err(`agentic-security invariants coverage: ${external_node_path_.basename(f)}: ${j.reason}\n`); return 1; }
|
|
456
|
+
docs.push(j.value);
|
|
457
|
+
}
|
|
458
|
+
let ledger; let results = [];
|
|
459
|
+
if (typeof flags.ledger === 'string') { const l = (0,project_input/* readJsonFile */.J)(abs(cwd, flags.ledger)); if (!l.ok) { err(`agentic-security invariants coverage: the ledger: ${l.reason}\n`); return 1; } ledger = l.value; }
|
|
460
|
+
if (typeof flags.results === 'string') { const rr = (0,project_input/* readJsonFile */.J)(abs(cwd, flags.results)); if (!rr.ok || !Array.isArray(rr.value)) { err('agentic-security invariants coverage: --results must be a JSON array of { invariantId, result }\n'); return 1; } results = rr.value; }
|
|
461
|
+
const byId = new Map(results.filter((x) => x && typeof x.invariantId === 'string').map((x) => [x.invariantId, x.result]));
|
|
462
|
+
const cov = (0,coverage/* businessCoverage */.Hr)({ entries: docs.map((invariant) => ({ invariant, result: byId.get(invariant.id) ?? null })), ledger });
|
|
463
|
+
emit(cov, cov.lines);
|
|
464
|
+
return 0;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (sub === 'regress') {
|
|
468
|
+
const file = args._[2];
|
|
469
|
+
if (!file) { err(`${USAGE}\n`); return 2; }
|
|
470
|
+
const a = (0,project_input/* readJsonFile */.J)(abs(cwd, file));
|
|
471
|
+
if (!a.ok) { err(`agentic-security invariants regress: ${a.reason}\n`); return 1; }
|
|
472
|
+
const r = await runRegressionArtifact(a.value, { config });
|
|
473
|
+
emit(r, [`regression artifact: ${r.status}`, r.summary, ...r.legs.map((l) => ` ${l.matched ? 'ok ' : 'FAIL'} ${l.role}: expected ${l.expected}, got ${l.outcome ?? l.status}`)]);
|
|
474
|
+
return r.status === 'passed' ? 0 : (r.status === 'prerequisite-unmet' || r.status === 'disabled') ? 3 : 1;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
err(`agentic-security invariants: unrecognized sub-command "${sub}"\n${USAGE}\n`);
|
|
478
|
+
return 2;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
/***/ }),
|
|
483
|
+
|
|
484
|
+
/***/ 68054:
|
|
485
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
486
|
+
|
|
487
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
488
|
+
/* harmony export */ verifyPatchNegative: () => (/* binding */ verifyPatchNegative)
|
|
489
|
+
/* harmony export */ });
|
|
490
|
+
/* harmony import */ var _assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(91026);
|
|
491
|
+
/* harmony import */ var _assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(99666);
|
|
492
|
+
/* harmony import */ var _assurance_config_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20622);
|
|
493
|
+
/* harmony import */ var _replay_replay_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(30891);
|
|
494
|
+
/* harmony import */ var _oracles_registry_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(45603);
|
|
495
|
+
/* harmony import */ var _patch_promotion_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(58144);
|
|
496
|
+
/* harmony import */ var _repair_records_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(41458);
|
|
497
|
+
// Patch-negative verification (X-204).
|
|
498
|
+
//
|
|
499
|
+
// A re-scan that no longer fires proves the DETECTOR went quiet; a cosmetic edit can do that. A repair is `verified-fix` here
|
|
500
|
+
// only when three things are shown, each by an executed oracle run in an equivalent disposable environment:
|
|
501
|
+
//
|
|
502
|
+
// 1. original-positive the original revision reproduces the exploit (oracle outcome: confirmed)
|
|
503
|
+
// 2. patched-negative the patched revision no longer does, same oracle (oracle outcome: refuted)
|
|
504
|
+
// 3. functional-regression declared legitimate behaviour is intact on the patched revision, with the same expectations
|
|
505
|
+
// holding on the original first (a baseline), so a wrong expectation is reported rather than blamed on the patch.
|
|
506
|
+
//
|
|
507
|
+
// All four runs (the baseline is one) go through `replayManifest`, so each is pinned by commit, fixture hash, patch hash,
|
|
508
|
+
// toolchain, oracle version and inputs, executes inside the trust boundary, and issues a verifier receipt. The result is then
|
|
509
|
+
// handed to `promotePatch`, which re-derives the diff and revision from the proposal and refuses any receipt that does not
|
|
510
|
+
// match them. `verified-fix` needs the promotion; nothing else grants it.
|
|
511
|
+
//
|
|
512
|
+
// A failure never degrades to a vague "not verified": it names the SPECIFIC step that is incomplete and a typed failure code:
|
|
513
|
+
// original-not-reproduced the original did not reproduce under the oracle (nothing to fix, or the scenario is wrong)
|
|
514
|
+
// patched-still-exploitable the exploit still works on the patched revision
|
|
515
|
+
// patched-build-broken the patched revision did not load or its benign control failed
|
|
516
|
+
// patched-negative-inconclusive the patched run decided nothing
|
|
517
|
+
// functional-omitted no functional check was supplied
|
|
518
|
+
// functional-baseline-invalid the declared expectations do not hold on the ORIGINAL revision
|
|
519
|
+
// functional-regression-detected the patched revision behaves differently from the declared expectations
|
|
520
|
+
// oracle-changed the oracle, its version or its inputs differ between the original and patched runs
|
|
521
|
+
// revision-unbound no exact commit: a verdict cannot be tied to a revision
|
|
522
|
+
// prerequisite-unmet a toolchain, feature or isolation prerequisite is missing; resumable where stated
|
|
523
|
+
// environment-mismatch the runs were not in equivalent environments
|
|
524
|
+
// promotion-refused the receipts do not match the exact proposed diff and revision
|
|
525
|
+
//
|
|
526
|
+
// The behaviour check is the functional-regression oracle by default. A requester may name `business-state` as `functional.oracleId`
|
|
527
|
+
// (X-406, `invariants/repair.js`): the same two runs and the same expectation, with an authorized-workflow scenario as the declared
|
|
528
|
+
// case, and `promotePatch` then requires the functional receipts to come from that oracle class instead.
|
|
529
|
+
//
|
|
530
|
+
// Scope, stated so no caller overclaims: the exploit scenario and the functional cases are the REQUESTER's; this verifies the
|
|
531
|
+
// declared scenario and cases, not that the patch is correct elsewhere. Linux is not claimed (the oracle platform statements
|
|
532
|
+
// stay `unverified`). Receipts are valid inside this process only (see patch-promotion.js).
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
const PATCH_NEGATIVE_FEATURE = 'patch-negative-verification';
|
|
542
|
+
const FUNCTIONAL_ORACLE = 'functional-regression';
|
|
543
|
+
// The check that behaviour is preserved is normally the functional-regression oracle. A requester may name `business-state`
|
|
544
|
+
// instead (X-406): the same two runs, the same expectation (refuted), with an authorized-workflow scenario as the declared case.
|
|
545
|
+
const FUNCTIONAL_ORACLES = Object.freeze([FUNCTIONAL_ORACLE, 'business-state']);
|
|
546
|
+
|
|
547
|
+
const STEPS = Object.freeze(['original-positive', 'patched-negative', 'functional-baseline', 'functional-regression']);
|
|
548
|
+
|
|
549
|
+
const ROLE_OF_STEP = Object.freeze({ 'original-positive': 'original', 'patched-negative': 'patched', 'functional-baseline': 'functionalBaseline', 'functional-regression': 'functional' });
|
|
550
|
+
const EXPECTED = Object.freeze({ 'original-positive': 'confirmed', 'patched-negative': 'refuted', 'functional-baseline': 'refuted', 'functional-regression': 'refuted' });
|
|
551
|
+
|
|
552
|
+
const stepResult = (step, status, extra = {}) => ({ step, status, expected: EXPECTED[step], outcome: null, code: null, reason: null, recordId: null, receiptDigest: null, ...extra });
|
|
553
|
+
|
|
554
|
+
function replayCode(run) {
|
|
555
|
+
const first = (run.errors || [])[0];
|
|
556
|
+
if (!first) return 'manifest-rejected';
|
|
557
|
+
if (first.code === 'ORACLE_MISMATCH') return 'oracle-changed';
|
|
558
|
+
if (first.code === 'HASH_MISMATCH') return 'content-hash-mismatch';
|
|
559
|
+
return 'manifest-rejected';
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function classify(step, run) {
|
|
563
|
+
if (run.status === 'rejected') return { status: 'incomplete', code: replayCode(run), reason: (run.errors || []).map((e) => e.message).join('; ').slice(0, 300) || 'the replay manifest was rejected' };
|
|
564
|
+
if (run.status === 'awaiting-prerequisites') {
|
|
565
|
+
const resumable = (run.prerequisites || []).every((p) => p.resumable);
|
|
566
|
+
return { status: 'incomplete', code: 'prerequisite-unmet', outcome: run.outcome ?? null, resumable, reason: `${(run.prerequisites || []).map((p) => `${p.kind} ${p.id} (${p.state})`).join('; ') || 'a prerequisite is unmet'}; nothing was executed${resumable ? ' (resumable)' : ''}` };
|
|
567
|
+
}
|
|
568
|
+
const outcome = run.outcome;
|
|
569
|
+
const observed = run.receipt?.observed || {};
|
|
570
|
+
// a business-state run reports its control flow under `preconditions`: a control flow that no longer works is a broken revision
|
|
571
|
+
const loadBroken = observed.targetLoaded === false || observed.benignCompleted === false || observed.preconditions?.controlRan === false || observed.preconditions?.controlDurableEffect === false;
|
|
572
|
+
if (outcome === 'error') return { status: 'incomplete', code: 'harness-error', reason: String(run.record?.reason || 'the oracle run failed').slice(0, 300), outcome };
|
|
573
|
+
if (outcome === EXPECTED[step]) return { status: 'passed', code: null, reason: run.record?.reason ?? null, outcome };
|
|
574
|
+
const reason = String(run.record?.reason || '').slice(0, 300);
|
|
575
|
+
switch (step) {
|
|
576
|
+
case 'original-positive':
|
|
577
|
+
return { status: 'failed', code: 'original-not-reproduced', reason: `the original revision did not reproduce the exploit (outcome '${outcome}'): ${reason}`, outcome };
|
|
578
|
+
case 'patched-negative':
|
|
579
|
+
if (outcome === 'confirmed') return { status: 'failed', code: 'patched-still-exploitable', reason: `the exploit still works on the patched revision: ${reason}`, outcome };
|
|
580
|
+
return loadBroken
|
|
581
|
+
? { status: 'failed', code: 'patched-build-broken', reason: `the patched revision did not load or its benign control failed: ${reason}`, outcome }
|
|
582
|
+
: { status: 'failed', code: 'patched-negative-inconclusive', reason: `the patched run decided nothing (outcome '${outcome}'): ${reason}`, outcome };
|
|
583
|
+
case 'functional-baseline':
|
|
584
|
+
return { status: 'failed', code: 'functional-baseline-invalid', reason: `the declared functional expectations do not hold on the original revision (outcome '${outcome}'): ${reason}`, outcome };
|
|
585
|
+
default:
|
|
586
|
+
if (outcome === 'confirmed') return { status: 'failed', code: 'functional-regression-detected', reason: `the patched revision behaves differently from the declared expectations: ${reason}`, outcome };
|
|
587
|
+
return loadBroken
|
|
588
|
+
? { status: 'failed', code: 'patched-build-broken', reason: `the patched revision did not load for the functional check: ${reason}`, outcome }
|
|
589
|
+
: { status: 'failed', code: 'functional-inconclusive', reason: `the functional check decided nothing (outcome '${outcome}'): ${reason}`, outcome };
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function summaryOf(steps, verified, incomplete, code) {
|
|
594
|
+
const label = (s) => ({ passed: 'PASS', failed: 'FAIL', incomplete: 'INCOMPLETE', 'not-run': 'not run' })[s.status];
|
|
595
|
+
const lines = steps.map((s) => `${s.step}: ${label(s)}${s.code ? ` (${s.code})` : ''}${s.reason && s.status !== 'passed' ? ` - ${s.reason}` : ''}`);
|
|
596
|
+
lines.push(verified
|
|
597
|
+
? 'verified-fix: the exploit reproduced on the original revision, did not reproduce on the patched revision, and the declared functional cases still hold. Only the declared scenario and cases were exercised.'
|
|
598
|
+
: `NOT verified-fix: incomplete step '${incomplete}'${code ? ` (${code})` : ''}.`);
|
|
599
|
+
return lines.join('\n');
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Run the three-part patch-negative verification for one proposed patch. Never throws.
|
|
604
|
+
*
|
|
605
|
+
* @param {object} req
|
|
606
|
+
* @param {string} req.hypothesisId the finding's stable id
|
|
607
|
+
* @param {string} req.commit exact revision the patch is proposed against (40 or 64 hex)
|
|
608
|
+
* @param {object} req.original { files, entry, oracleId, inputs, budgets? } the exploit scenario on the original files
|
|
609
|
+
* @param {object} req.patch { files } the proposed diff: the new content of each changed file
|
|
610
|
+
* @param {object} [req.patched] { oracleId?, inputs?, entry? }: must equal the original's; anything else is `oracle-changed`
|
|
611
|
+
* @param {object} [req.functional] { inputs, budgets? } for the functional-regression oracle; omitting it prevents verified-fix
|
|
612
|
+
* @param {object} [req.pinnedOracle] { id, version, logicDigest } the oracle identity the requester recorded earlier
|
|
613
|
+
* @param {object[]} [req.ledger] earlier repair records to extend
|
|
614
|
+
* @param {object} [o] { config, runOptions } config is the assurance config; runOptions go to the oracle runner (test seams)
|
|
615
|
+
*/
|
|
616
|
+
async function verifyPatchNegative(req, o = {}) {
|
|
617
|
+
const config = o.config || (0,_assurance_config_js__WEBPACK_IMPORTED_MODULE_2__.resolveAssuranceConfig)({ env: process.env });
|
|
618
|
+
const gate = (0,_assurance_config_js__WEBPACK_IMPORTED_MODULE_2__/* .featureStatus */ .FX)(config, PATCH_NEGATIVE_FEATURE);
|
|
619
|
+
const steps = STEPS.map((s) => stepResult(s, 'not-run', { reason: 'not reached' }));
|
|
620
|
+
const base = {
|
|
621
|
+
status: 'not-verified-fix', verifiedFix: false, incompleteStep: null, failureCode: null, reason: null, steps,
|
|
622
|
+
patchDigest: null, promotion: null, receipts: null, records: {}, verificationRecord: null, repairRecords: Array.isArray(req?.ledger) ? req.ledger : [], summary: '',
|
|
623
|
+
};
|
|
624
|
+
if (gate.status !== 'ok') {
|
|
625
|
+
return { ...base, status: 'disabled', incompleteStep: 'feature-gate', failureCode: gate.code || 'disabled', reason: `${PATCH_NEGATIVE_FEATURE} is not available: ${gate.reason}`, summary: `patch-negative verification did not run: ${gate.reason}` };
|
|
626
|
+
}
|
|
627
|
+
const refuse = (step, code, reason, extra = {}) => {
|
|
628
|
+
const rejected = req && (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.patch) && (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.patch.files) && Object.keys(req.patch.files).length && typeof req.hypothesisId === 'string'
|
|
629
|
+
? ledgerFor(base.repairRecords, req, base.patchDigest ?? (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(req.patch.files), { rejected: { step, code, reason } }) : { records: base.repairRecords };
|
|
630
|
+
return { ...base, ...extra, patchDigest: req?.patch?.files ? (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(req.patch.files) : null, incompleteStep: step, failureCode: code, reason, repairRecords: rejected.records, summary: summaryOf(steps, false, step, code) };
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
// ---- shape and preconditions that need no execution
|
|
634
|
+
const patchFiles = req?.patch?.files;
|
|
635
|
+
if (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req) || typeof req.hypothesisId !== 'string' || !req.hypothesisId || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.original) || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.original.files)
|
|
636
|
+
|| typeof req.original.entry !== 'string' || typeof req.original.oracleId !== 'string' || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.original.inputs)
|
|
637
|
+
|| !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(patchFiles) || Object.keys(patchFiles).length === 0) {
|
|
638
|
+
return refuse('input-validation', 'bad-request', 'a request needs a hypothesis id, the original files, entry, oracle and inputs, and a non-empty patch');
|
|
639
|
+
}
|
|
640
|
+
if (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isCommit */ .WM)(req.commit)) return refuse('input-validation', 'revision-unbound', 'no exact commit was given: a verdict cannot be tied to a revision');
|
|
641
|
+
const original = req.original;
|
|
642
|
+
const oracle = _oracles_registry_js__WEBPACK_IMPORTED_MODULE_4__.getOracle(original.oracleId);
|
|
643
|
+
if (!oracle) return refuse('input-validation', 'unknown-oracle', `the exploit oracle '${String(original.oracleId).slice(0, 60)}' is not registered`);
|
|
644
|
+
if (oracle.id === FUNCTIONAL_ORACLE) return refuse('input-validation', 'bad-request', 'the exploit oracle cannot be the functional-regression oracle');
|
|
645
|
+
const patched = (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.patched) ? req.patched : {};
|
|
646
|
+
if ((patched.oracleId !== undefined && patched.oracleId !== original.oracleId) || (patched.inputs !== undefined && (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(patched.inputs) !== (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(original.inputs)) || (patched.entry !== undefined && patched.entry !== original.entry)) {
|
|
647
|
+
return refuse('oracle-consistency', 'oracle-changed', 'the patched run names a different oracle, entry or inputs than the original run: a changed oracle cannot show the exploit is closed');
|
|
648
|
+
}
|
|
649
|
+
const pin = req.pinnedOracle;
|
|
650
|
+
if (pin !== undefined && (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(pin) || pin.id !== oracle.id || pin.version !== oracle.version || pin.logicDigest !== oracle.logicDigest)) {
|
|
651
|
+
return refuse('oracle-consistency', 'oracle-changed', 'the oracle differs from the identity the requester pinned (id, version or logic digest)');
|
|
652
|
+
}
|
|
653
|
+
const fn = req.functional;
|
|
654
|
+
if (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(fn) || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(fn.inputs)) {
|
|
655
|
+
return refuse('functional-regression', 'functional-omitted', 'no functional regression check was supplied: a patch that was never checked for behaviour cannot be a verified fix');
|
|
656
|
+
}
|
|
657
|
+
const functionalOracle = fn.oracleId === undefined ? FUNCTIONAL_ORACLE : fn.oracleId;
|
|
658
|
+
if (!FUNCTIONAL_ORACLES.includes(functionalOracle)) {
|
|
659
|
+
return refuse('input-validation', 'bad-request', `the functional check oracle must be one of ${FUNCTIONAL_ORACLES.join(', ')}`);
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const patchDigest = (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(patchFiles);
|
|
663
|
+
base.patchDigest = patchDigest;
|
|
664
|
+
let ledger = ledgerFor(base.repairRecords, req, patchDigest, {}).records; // proposed
|
|
665
|
+
const common = { hypothesisId: req.hypothesisId, commit: req.commit };
|
|
666
|
+
const plan = [
|
|
667
|
+
['original-positive', { oracleId: original.oracleId, entry: original.entry, inputs: original.inputs, patchFiles: null, budgets: original.budgets }],
|
|
668
|
+
['patched-negative', { oracleId: original.oracleId, entry: original.entry, inputs: original.inputs, patchFiles, budgets: original.budgets }],
|
|
669
|
+
['functional-baseline', { oracleId: functionalOracle, entry: original.entry, inputs: fn.inputs, patchFiles: null, budgets: fn.budgets }],
|
|
670
|
+
['functional-regression', { oracleId: functionalOracle, entry: original.entry, inputs: fn.inputs, patchFiles, budgets: fn.budgets }],
|
|
671
|
+
];
|
|
672
|
+
const runs = {};
|
|
673
|
+
let failed = null;
|
|
674
|
+
for (const [i, [step, spec]] of plan.entries()) {
|
|
675
|
+
if (failed) continue;
|
|
676
|
+
let run;
|
|
677
|
+
try {
|
|
678
|
+
const manifest = (0,_replay_replay_js__WEBPACK_IMPORTED_MODULE_3__/* .createReplayManifest */ .$A)({ ...common, fixtureFiles: original.files, patchFiles: spec.patchFiles, oracleId: spec.oracleId, entry: spec.entry, inputs: spec.inputs, budgets: spec.budgets || {}, expected: { outcome: EXPECTED[step] } });
|
|
679
|
+
run = await (0,_replay_replay_js__WEBPACK_IMPORTED_MODULE_3__/* .replayManifest */ .TY)({ manifest, fixtureFiles: original.files, patchFiles: spec.patchFiles }, { config: o.config || config, runOptions: o.runOptions });
|
|
680
|
+
} catch (e) {
|
|
681
|
+
run = { status: 'rejected', errors: [{ code: 'RUN_FAILED', message: String(e?.message || e).slice(0, 200) }] };
|
|
682
|
+
}
|
|
683
|
+
const c = classify(step, run);
|
|
684
|
+
steps[i] = stepResult(step, c.status, { ...c, recordId: run.record?.id ?? null, receiptDigest: run.receipt?.receiptDigest ?? null });
|
|
685
|
+
if (run.executed && run.receipt) runs[ROLE_OF_STEP[step]] = run;
|
|
686
|
+
if (c.status !== 'passed') failed = { step, ...c };
|
|
687
|
+
}
|
|
688
|
+
base.records = Object.fromEntries(Object.entries(runs).map(([k, r]) => [k, r.record]));
|
|
689
|
+
if (failed) {
|
|
690
|
+
ledger = ledgerFor(ledger, req, patchDigest, { rejected: { step: failed.step, code: failed.code, reason: failed.reason } }).records;
|
|
691
|
+
const original0 = base.records.original ? (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .withRepairStatus */ .m$)(base.records.original, (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .verificationRepairFor */ .Kf)(ledger, req.hypothesisId, patchDigest)) : null;
|
|
692
|
+
return { ...base, incompleteStep: failed.step, failureCode: failed.code, reason: failed.reason, resumable: failed.resumable ?? false, repairRecords: ledger, verificationRecord: original0, summary: summaryOf(steps, false, failed.step, failed.code) };
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// ---- the receipts must match the exact proposed diff and revision before anything is promoted
|
|
696
|
+
const receipts = Object.fromEntries(Object.entries(runs).map(([k, r]) => [k, r.receipt]));
|
|
697
|
+
const promotion = (0,_patch_promotion_js__WEBPACK_IMPORTED_MODULE_5__/* .promotePatch */ .l)({ proposal: { hypothesisId: req.hypothesisId, revision: req.commit, originalFiles: original.files, patchFiles, functionalOracle }, receipts });
|
|
698
|
+
if (!promotion.ok) {
|
|
699
|
+
const envBroken = promotion.reasons.some((r) => r.code === 'environment-mismatch');
|
|
700
|
+
const code = envBroken ? 'environment-mismatch' : promotion.reasons.some((r) => r.code === 'oracle-changed') ? 'oracle-changed' : 'promotion-refused';
|
|
701
|
+
const step = envBroken ? 'environment-equivalence' : code === 'oracle-changed' ? 'oracle-consistency' : 'promotion';
|
|
702
|
+
const reason = promotion.reasons.map((r) => r.message).join('; ').slice(0, 400);
|
|
703
|
+
ledger = ledgerFor(ledger, req, patchDigest, { rejected: { step, code, reason } }).records;
|
|
704
|
+
return { ...base, promotion, incompleteStep: step, failureCode: code, reason, repairRecords: ledger, verificationRecord: base.records.original ? (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .withRepairStatus */ .m$)(base.records.original, (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .verificationRepairFor */ .Kf)(ledger, req.hypothesisId, patchDigest)) : null, summary: summaryOf(steps, false, step, code) };
|
|
705
|
+
}
|
|
706
|
+
const promoted = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .recordPromotion */ .Zw)(ledger, promotion, { verificationRecordId: base.records.patched?.id ?? null });
|
|
707
|
+
ledger = promoted.records;
|
|
708
|
+
const verificationRecord = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .withRepairStatus */ .m$)(base.records.original, (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .verificationRepairFor */ .Kf)(ledger, req.hypothesisId, patchDigest, base.records.patched?.id));
|
|
709
|
+
return {
|
|
710
|
+
...base, status: 'verified-fix', verifiedFix: true, promotion, receipts, repairRecords: ledger, verificationRecord,
|
|
711
|
+
reason: 'verified', summary: summaryOf(steps, true, null, null),
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// The ledger for one verification: always starts with a `proposed` record, and records a rejection when verification stopped.
|
|
716
|
+
function ledgerFor(records, req, patchDigest, { rejected } = {}) {
|
|
717
|
+
let list = Array.isArray(records) ? records : [];
|
|
718
|
+
const fields = { hypothesisId: req.hypothesisId, revision: (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isCommit */ .WM)(req.commit) ? req.commit : null, diffDigest: patchDigest };
|
|
719
|
+
if (!list.some((r) => r.hypothesisId === fields.hypothesisId && r.diffDigest === patchDigest)) list = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .appendRepairRecord */ .f7)(list, { ...fields, kind: 'proposed', reason: 'a patch was proposed for verification' }).records;
|
|
720
|
+
if (rejected) list = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .appendRepairRecord */ .f7)(list, { ...fields, kind: 'rejected', step: rejected.step, reason: `${rejected.code}: ${String(rejected.reason || '').slice(0, 300)}` }).records;
|
|
721
|
+
return { records: list };
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
/***/ })
|
|
726
|
+
|
|
727
|
+
};
|