@codyswann/lisa 4.103.3 → 4.103.5
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/all/copy-overwrite/scripts/lisa-gates.mjs +15 -811
- package/all/copy-overwrite/scripts/lisa-run-gates.mjs +21 -200
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +2 -2
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +8 -0
- package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +9 -7
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
|
@@ -69,13 +69,7 @@
|
|
|
69
69
|
*/
|
|
70
70
|
|
|
71
71
|
import { createHash } from "node:crypto";
|
|
72
|
-
import {
|
|
73
|
-
appendFileSync,
|
|
74
|
-
existsSync,
|
|
75
|
-
readdirSync,
|
|
76
|
-
readFileSync,
|
|
77
|
-
statSync,
|
|
78
|
-
} from "node:fs";
|
|
72
|
+
import { appendFileSync, existsSync, readdirSync, readFileSync } from "node:fs";
|
|
79
73
|
import { createRequire } from "node:module";
|
|
80
74
|
import { dirname, isAbsolute, join, parse, relative } from "node:path";
|
|
81
75
|
import { fileURLToPath } from "node:url";
|
|
@@ -270,7 +264,14 @@ function awaitUnkeepableReason(moment) {
|
|
|
270
264
|
*/
|
|
271
265
|
export const STATE_FAMILIES = [CONTINUOUS];
|
|
272
266
|
|
|
273
|
-
/**
|
|
267
|
+
/**
|
|
268
|
+
* Keys on a gate entry that are settings rather than moments.
|
|
269
|
+
*
|
|
270
|
+
* `reuse` is retired and ignored: the release-reuse checker that read it was
|
|
271
|
+
* removed (CodySwannGT/lisa#4794). It stays in this CLOSED allowlist because
|
|
272
|
+
* dropping it would make any host still declaring it fail validation of its
|
|
273
|
+
* whole `gates` block, silently un-configuring every gate.
|
|
274
|
+
*/
|
|
274
275
|
export const GATE_FIELDS = new Set(["run", "needs", "task", "reuse"]);
|
|
275
276
|
|
|
276
277
|
/**
|
|
@@ -3008,119 +3009,12 @@ export const INTERCEPTORS = Object.freeze({
|
|
|
3008
3009
|
"Structured formats are parsed with real parsers.",
|
|
3009
3010
|
});
|
|
3010
3011
|
|
|
3011
|
-
|
|
3012
|
-
* The shape every gate's implementation emits, whatever tool produced it.
|
|
3013
|
-
*
|
|
3014
|
-
* The task name alone is not an interface. If Lisa standardises only *how to
|
|
3015
|
-
* invoke*, the attestation records "test:cov passed" and cites nothing — true
|
|
3016
|
-
* of a scrupulous project as much as a careless one. Standardising what comes
|
|
3017
|
-
* *back* is what lets jest and vitest both satisfy `coverage-adequacy`, and
|
|
3018
|
-
* what lets the register quote a number instead of a verdict.
|
|
3019
|
-
*
|
|
3020
|
-
* Four fields, each earning its place:
|
|
3021
|
-
*
|
|
3022
|
-
* - `status` — three-valued. `unknown` is not a synonym for `fail`.
|
|
3023
|
-
* - `work` — the count that proves it RAN. `null` forces `unknown`, which is
|
|
3024
|
-
* the `passWithNoTests` hole closed structurally rather than by vigilance.
|
|
3025
|
-
* - `measures` — what an attestation actually cites.
|
|
3026
|
-
* - `prover` — which implementation produced it. Vendor-neutrality means Lisa
|
|
3027
|
-
* does not *mandate* a tool, not that it declines to *record* one; an auditor
|
|
3028
|
-
* asking "what measured this?" deserves an answer.
|
|
3029
|
-
*
|
|
3030
|
-
* `observed_at` and `max_age_minutes` exist for continuous gates. A gate tied
|
|
3031
|
-
* to a change carries inherently fresh evidence — it ran on that diff. A gate
|
|
3032
|
-
* that runs on a schedule does not, and a green from six days ago proves
|
|
3033
|
-
* nothing about today. Evidence read past its bound yields `unknown`, never
|
|
3034
|
-
* `pass`: a scheduler that quietly died must block promotion rather than let
|
|
3035
|
-
* last week's result stand in for this week's.
|
|
3036
|
-
*/
|
|
3037
|
-
export const EVIDENCE_FIELDS = Object.freeze({
|
|
3038
|
-
gate: "string",
|
|
3039
|
-
status: "pass | fail | unknown",
|
|
3040
|
-
work: "number | null",
|
|
3041
|
-
measures: "object",
|
|
3042
|
-
prover: "{ tool, version }",
|
|
3043
|
-
observed_at: "ISO-8601",
|
|
3044
|
-
max_age_minutes: "number | null",
|
|
3045
|
-
});
|
|
3046
|
-
|
|
3047
|
-
/** Verdict an evidence envelope can carry. */
|
|
3048
|
-
export const EVIDENCE_STATUS = ["pass", "fail", "unknown"];
|
|
3049
|
-
|
|
3050
|
-
/**
|
|
3051
|
-
* Read a verdict from an evidence envelope, honouring work and freshness.
|
|
3052
|
-
*
|
|
3053
|
-
* Two demotions to `unknown`, both deliberate, both cases where the naive read
|
|
3054
|
-
* is `pass`:
|
|
3055
|
-
*
|
|
3056
|
-
* - the gate declares a work count and the implementation emitted none, so
|
|
3057
|
-
* nothing shows it ran;
|
|
3058
|
-
* - the evidence is older than its own bound, so it describes a state that may
|
|
3059
|
-
* no longer exist.
|
|
3060
|
-
*
|
|
3061
|
-
* Neither is a failure and neither is a pass. Collapsing either into `pass` is
|
|
3062
|
-
* the defect this whole subsystem exists to prevent; collapsing either into
|
|
3063
|
-
* `fail` blames a project for a gap in observation.
|
|
3064
|
-
* @param {object} evidence The emitted envelope.
|
|
3065
|
-
* @param {object} [definition] Registry entry, for whether work is expected.
|
|
3066
|
-
* @param {number} [nowMs] Clock, injected for tests.
|
|
3067
|
-
* @returns {{status: string, reason: string|null}} Effective verdict.
|
|
3068
|
-
*/
|
|
3069
|
-
export function readEvidence(evidence, definition = {}, nowMs = Date.now()) {
|
|
3070
|
-
if (!evidence || !EVIDENCE_STATUS.includes(evidence.status)) {
|
|
3071
|
-
return { status: "unknown", reason: "no evidence was emitted" };
|
|
3072
|
-
}
|
|
3073
|
-
if (evidence.status !== "pass") {
|
|
3074
|
-
return { status: evidence.status, reason: null };
|
|
3075
|
-
}
|
|
3076
|
-
if (definition.work && (evidence.work ?? null) === null) {
|
|
3077
|
-
return {
|
|
3078
|
-
status: "unknown",
|
|
3079
|
-
reason: `reported pass but no ${definition.work} count, so nothing shows it ran`,
|
|
3080
|
-
};
|
|
3081
|
-
}
|
|
3082
|
-
const bound = evidence.max_age_minutes;
|
|
3083
|
-
if (bound) {
|
|
3084
|
-
const observedAtMs = Date.parse(evidence.observed_at ?? "");
|
|
3085
|
-
if (!Number.isFinite(observedAtMs)) {
|
|
3086
|
-
return {
|
|
3087
|
-
status: "unknown",
|
|
3088
|
-
reason:
|
|
3089
|
-
"freshness is bounded but observed_at is missing or invalid, so its age cannot be proved",
|
|
3090
|
-
};
|
|
3091
|
-
}
|
|
3092
|
-
const ageMinutes = (nowMs - observedAtMs) / 60000;
|
|
3093
|
-
if (ageMinutes > bound) {
|
|
3094
|
-
return {
|
|
3095
|
-
status: "unknown",
|
|
3096
|
-
reason: `evidence is ${Math.round(ageMinutes)} minutes old, past its ${bound}-minute bound`,
|
|
3097
|
-
};
|
|
3098
|
-
}
|
|
3099
|
-
}
|
|
3100
|
-
return { status: "pass", reason: null };
|
|
3101
|
-
}
|
|
3102
|
-
|
|
3103
|
-
// ─── Release evidence reuse (CodySwannGT/lisa#3013) ─────────────────────────
|
|
3012
|
+
// ─── Evidence digests ─────────────────────────────────────────────────────
|
|
3104
3013
|
//
|
|
3105
|
-
//
|
|
3106
|
-
//
|
|
3107
|
-
//
|
|
3108
|
-
//
|
|
3109
|
-
// RUN. The design, including the permission wall that shaped it, is in
|
|
3110
|
-
// `docs/design/release-evidence-reuse.md`.
|
|
3111
|
-
|
|
3112
|
-
/**
|
|
3113
|
-
* The schema token, spelled here as well as in the producer.
|
|
3114
|
-
*
|
|
3115
|
-
* This is a deliberate SECOND ADDRESS for one string, and it is forced rather
|
|
3116
|
-
* than sloppy: `.github/workflows/gates.yml` tells an old runner apart from a
|
|
3117
|
-
* current one by grepping the runner file for this literal, so the literal
|
|
3118
|
-
* cannot move out of `lisa-run-gates.mjs`. A verifier that imported it from
|
|
3119
|
-
* there would make this module depend on the runner, inverting the dependency.
|
|
3120
|
-
* `tests/unit/scripts/lisa-gates-reuse-plan.test.ts` pins the two together, so
|
|
3121
|
-
* they cannot drift even though they are written twice.
|
|
3122
|
-
*/
|
|
3123
|
-
export const EVIDENCE_SCHEMA_TOKEN = "lisa.gate-evidence/v1";
|
|
3014
|
+
// `lisa-run-gates.mjs` records `contract.gates_digest` in the gate evidence
|
|
3015
|
+
// envelope so a reader can tell which declared rule set a run was held to. The
|
|
3016
|
+
// release-reuse checker that once consumed the envelope was removed
|
|
3017
|
+
// (CodySwannGT/lisa#4794); only the digest helpers remain.
|
|
3124
3018
|
|
|
3125
3019
|
/**
|
|
3126
3020
|
* Compare strings by UTF-16 code units, independent of the host locale.
|
|
@@ -3233,581 +3127,6 @@ export function planDigest({ gates, moment, runner, scripts = null }) {
|
|
|
3233
3127
|
}
|
|
3234
3128
|
}
|
|
3235
3129
|
|
|
3236
|
-
/**
|
|
3237
|
-
* What kind of thing a gate's verdict is, which decides whether it may be
|
|
3238
|
-
* reused and for how long.
|
|
3239
|
-
*
|
|
3240
|
-
* Three values, and the default for anything not named is `never`. That
|
|
3241
|
-
* asymmetry is the whole safety posture: a gate becomes reusable only when
|
|
3242
|
-
* someone wrote down why it is, and a gate added tomorrow is not reusable by
|
|
3243
|
-
* accident.
|
|
3244
|
-
*/
|
|
3245
|
-
export const REUSE_CLASS = Object.freeze({
|
|
3246
|
-
/** Same tree + same contract ⇒ same verdict. No external state consulted. */
|
|
3247
|
-
DETERMINISTIC: "deterministic",
|
|
3248
|
-
/** Never satisfiable by evidence from another run. */
|
|
3249
|
-
NEVER: "never",
|
|
3250
|
-
/** Depends on external state that changes without the tree. Needs a window. */
|
|
3251
|
-
TIME_SENSITIVE: "time-sensitive",
|
|
3252
|
-
});
|
|
3253
|
-
|
|
3254
|
-
/** Every legal class, for validation. */
|
|
3255
|
-
export const REUSE_CLASSES = Object.freeze(Object.values(REUSE_CLASS));
|
|
3256
|
-
|
|
3257
|
-
/**
|
|
3258
|
-
* The built-in classification, one row per registry gate.
|
|
3259
|
-
*
|
|
3260
|
-
* `tests/unit/scripts/lisa-gates-reuse-plan.test.ts` derives the key set from
|
|
3261
|
-
* `REGISTRY` and fails when they disagree, so a gate cannot be added without a
|
|
3262
|
-
* stated class. Deriving the table itself is not possible — whether a verdict
|
|
3263
|
-
* depends on external state is a fact about the prover, not about the registry
|
|
3264
|
-
* entry — but requiring the row is, and that is what stops a silent default.
|
|
3265
|
-
*
|
|
3266
|
-
* A project overrides a row with `gates.<id>.reuse` in `.lisa.config.json`.
|
|
3267
|
-
*/
|
|
3268
|
-
export const GATE_REUSE_CLASS = Object.freeze({
|
|
3269
|
-
"introduced-history-credential-leakage": { class: REUSE_CLASS.NEVER },
|
|
3270
|
-
accessibility: { class: REUSE_CLASS.NEVER },
|
|
3271
|
-
// A guard whose job is to detect a stale generated artifact must not itself
|
|
3272
|
-
// be satisfied by a record of a previous run, and it costs seconds.
|
|
3273
|
-
"artifact-freshness": { class: REUSE_CLASS.NEVER },
|
|
3274
|
-
"behavior-contract": { class: REUSE_CLASS.DETERMINISTIC, diff: true },
|
|
3275
|
-
"build-integrity": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3276
|
-
"code-review": { class: REUSE_CLASS.NEVER },
|
|
3277
|
-
"code-style": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3278
|
-
"code-style-slow": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3279
|
-
"commit-conformance": { class: REUSE_CLASS.DETERMINISTIC, diff: true },
|
|
3280
|
-
"conflict-residue": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3281
|
-
"coverage-adequacy": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3282
|
-
"credential-availability": { class: REUSE_CLASS.NEVER },
|
|
3283
|
-
// ── Time-sensitive. 60 minutes throughout, stated rather than inferred: it
|
|
3284
|
-
// sits well above the observed merge→release latency (minutes) and well below
|
|
3285
|
-
// the interval over which a GIVEN lockfile's answer meaningfully changes.
|
|
3286
|
-
// Re-proving these is cheap, so a narrow window costs little.
|
|
3287
|
-
"credential-leakage": {
|
|
3288
|
-
class: REUSE_CLASS.TIME_SENSITIVE,
|
|
3289
|
-
maxAgeMinutes: 60,
|
|
3290
|
-
},
|
|
3291
|
-
"dead-code": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3292
|
-
"dependency-vulnerability": {
|
|
3293
|
-
class: REUSE_CLASS.TIME_SENSITIVE,
|
|
3294
|
-
maxAgeMinutes: 60,
|
|
3295
|
-
},
|
|
3296
|
-
"e2e-browser": { class: REUSE_CLASS.NEVER },
|
|
3297
|
-
"e2e-native": { class: REUSE_CLASS.NEVER },
|
|
3298
|
-
"environment-reseed": { class: REUSE_CLASS.NEVER },
|
|
3299
|
-
"environment-reset": { class: REUSE_CLASS.NEVER },
|
|
3300
|
-
"format-conformance": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3301
|
-
"generative-testing": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3302
|
-
"journey-coverage": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3303
|
-
"learnings-budget": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3304
|
-
"license-compliance": {
|
|
3305
|
-
class: REUSE_CLASS.TIME_SENSITIVE,
|
|
3306
|
-
maxAgeMinutes: 60,
|
|
3307
|
-
},
|
|
3308
|
-
"load-capacity": { class: REUSE_CLASS.NEVER },
|
|
3309
|
-
"migration-provenance": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3310
|
-
// Its measurement varies with runner speed, so it is not a pure function of
|
|
3311
|
-
// the tree. But the property it gates is a property of the CODE, and runner
|
|
3312
|
-
// variance is noise in both directions: rerunning it adds a second sample of
|
|
3313
|
-
// the same noise, not a second proof. A project that disagrees declares
|
|
3314
|
-
// `"reuse": { "class": "time-sensitive", "max_age_minutes": N }`.
|
|
3315
|
-
"performance-budget": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3316
|
-
"runtime-web-vulnerability": { class: REUSE_CLASS.NEVER },
|
|
3317
|
-
"security-floor-integrity": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3318
|
-
"state-classification": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3319
|
-
// The main-branch analysis is a PUBLISHING action — it updates the
|
|
3320
|
-
// server-side baseline every later pull request is measured against — not
|
|
3321
|
-
// only a proof. Skipping it would silently stop maintaining that baseline.
|
|
3322
|
-
"static-security": { class: REUSE_CLASS.NEVER },
|
|
3323
|
-
"structural-rules": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3324
|
-
"suppression-residue": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3325
|
-
"test-correctness": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3326
|
-
// Hermetic in this repository. A project whose integration suite reaches a
|
|
3327
|
-
// live service MUST override this — the built-in cannot know, and the cost of
|
|
3328
|
-
// being wrong is reusing a proof about a system that has since changed.
|
|
3329
|
-
"test-integration": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3330
|
-
"test-meaningfulness": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3331
|
-
"test-node-suites": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3332
|
-
"threshold-monotonicity": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3333
|
-
"tool-availability": { class: REUSE_CLASS.NEVER },
|
|
3334
|
-
// `pull_request`-only by its job condition, so there is nothing to reuse and
|
|
3335
|
-
// nothing to save; declaring it `never` says that rather than implying it.
|
|
3336
|
-
traceability: { class: REUSE_CLASS.NEVER },
|
|
3337
|
-
"type-correctness": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3338
|
-
"version-duplication": { class: REUSE_CLASS.DETERMINISTIC },
|
|
3339
|
-
});
|
|
3340
|
-
|
|
3341
|
-
/**
|
|
3342
|
-
* Why a gate is running rather than reusing, as a stable token.
|
|
3343
|
-
*
|
|
3344
|
-
* Tokens rather than prose because the ledger is read by a job that must
|
|
3345
|
-
* compare two sets, and by an operator who needs the same phrase to mean the
|
|
3346
|
-
* same thing across runs.
|
|
3347
|
-
*/
|
|
3348
|
-
export const REUSE_REASON = Object.freeze({
|
|
3349
|
-
CONTRACT_MISMATCH: "contract-mismatch",
|
|
3350
|
-
DERIVATIVE: "derivative",
|
|
3351
|
-
LEVEL_DOWNGRADE: "level-downgrade",
|
|
3352
|
-
MALFORMED: "malformed",
|
|
3353
|
-
NEVER_REUSABLE: "never-reusable",
|
|
3354
|
-
NOT_PROVED: "not-proved",
|
|
3355
|
-
REUSED: "reused",
|
|
3356
|
-
STALE: "stale",
|
|
3357
|
-
SUBJECT_MISMATCH: "subject-mismatch",
|
|
3358
|
-
UNATTRIBUTABLE: "unattributable",
|
|
3359
|
-
UNAVAILABLE: "unavailable",
|
|
3360
|
-
UNCLASSIFIED: "unclassified",
|
|
3361
|
-
UNCOVERED: "uncovered",
|
|
3362
|
-
});
|
|
3363
|
-
|
|
3364
|
-
/** The largest envelope the verifier will read, in bytes. */
|
|
3365
|
-
export const EVIDENCE_BYTE_BUDGET = 1024 * 1024;
|
|
3366
|
-
|
|
3367
|
-
/** How deep a caller chain may be and still be primary pull-request proof. */
|
|
3368
|
-
const PRIMARY_CALLER_CHAIN_DEPTH = 1;
|
|
3369
|
-
|
|
3370
|
-
/** How strong each level is, so evidence can never satisfy a stricter one. */
|
|
3371
|
-
const LEVEL_RANK = Object.freeze({ off: 0, optional: 1, required: 2 });
|
|
3372
|
-
|
|
3373
|
-
/**
|
|
3374
|
-
* The reuse policy for one gate: built-in row, overridden by the project.
|
|
3375
|
-
*
|
|
3376
|
-
* An unknown gate id resolves to `never`. That is the fail-closed default and
|
|
3377
|
-
* it is why the built-in table does not need to anticipate a consumer's own
|
|
3378
|
-
* gate: a gate nobody classified is a gate nobody argued was reusable.
|
|
3379
|
-
* @param {string} id Gate id.
|
|
3380
|
-
* @param {object|null} [gates] The project gates block.
|
|
3381
|
-
* @returns {{class: string, diff: boolean, known: boolean, maxAgeMinutes: number|null}} Policy.
|
|
3382
|
-
*/
|
|
3383
|
-
export function reusePolicyFor(id, gates = null) {
|
|
3384
|
-
const builtIn = GATE_REUSE_CLASS[id] ?? null;
|
|
3385
|
-
const declared = gates?.[id]?.reuse ?? null;
|
|
3386
|
-
const known = Boolean(builtIn || declared);
|
|
3387
|
-
const merged = {
|
|
3388
|
-
class: declared?.class ?? builtIn?.class ?? REUSE_CLASS.NEVER,
|
|
3389
|
-
diff: declared?.diff ?? builtIn?.diff ?? false,
|
|
3390
|
-
known,
|
|
3391
|
-
maxAgeMinutes: declared?.max_age_minutes ?? builtIn?.maxAgeMinutes ?? null,
|
|
3392
|
-
};
|
|
3393
|
-
// An unrecognised class is not a licence to guess. `validate` refuses it at
|
|
3394
|
-
// declaration time; this is the runtime arm of the same refusal.
|
|
3395
|
-
return REUSE_CLASSES.includes(merged.class)
|
|
3396
|
-
? merged
|
|
3397
|
-
: { class: REUSE_CLASS.NEVER, diff: false, known, maxAgeMinutes: null };
|
|
3398
|
-
}
|
|
3399
|
-
|
|
3400
|
-
/**
|
|
3401
|
-
* The tree this evidence is about must be the tree being released.
|
|
3402
|
-
*
|
|
3403
|
-
* `tree` rather than `commit` is the identity: two commits legitimately share a
|
|
3404
|
-
* tree after a rebase or a merge of an up-to-date branch, and that is exactly
|
|
3405
|
-
* the case where reuse is sound. A null on either side is a mismatch, not a
|
|
3406
|
-
* pass — an unknown tree is not the same tree.
|
|
3407
|
-
* @param {object} subject The envelope's subject block.
|
|
3408
|
-
* @param {object} observed Locally observed facts.
|
|
3409
|
-
* @returns {string|null} A problem, or null.
|
|
3410
|
-
*/
|
|
3411
|
-
function verifySubject(subject, observed) {
|
|
3412
|
-
if (!subject.repository || subject.repository !== observed.repository) {
|
|
3413
|
-
return `evidence is about ${JSON.stringify(subject.repository ?? null)}, not ${JSON.stringify(observed.repository ?? null)}`;
|
|
3414
|
-
}
|
|
3415
|
-
if (!subject.tree || !observed.tree || subject.tree !== observed.tree) {
|
|
3416
|
-
return `evidence is about tree ${JSON.stringify(subject.tree ?? null)}, not ${JSON.stringify(observed.tree ?? null)}`;
|
|
3417
|
-
}
|
|
3418
|
-
return null;
|
|
3419
|
-
}
|
|
3420
|
-
|
|
3421
|
-
/**
|
|
3422
|
-
* Compare two dotted versions numerically, ignoring any pre-release suffix.
|
|
3423
|
-
*
|
|
3424
|
-
* Deliberately small: the only question asked of it is "is the producer's
|
|
3425
|
-
* registry at least as new as mine", and a full semver implementation would be
|
|
3426
|
-
* a second answer to a question nothing else asks.
|
|
3427
|
-
* @param {string} left Version.
|
|
3428
|
-
* @param {string} right Version.
|
|
3429
|
-
* @returns {number} Negative, zero or positive.
|
|
3430
|
-
*/
|
|
3431
|
-
function compareVersions(left, right) {
|
|
3432
|
-
const parts = value =>
|
|
3433
|
-
String(value)
|
|
3434
|
-
.split("-")[0]
|
|
3435
|
-
.split(".")
|
|
3436
|
-
.map(part => Number.parseInt(part, 10) || 0);
|
|
3437
|
-
const a = parts(left);
|
|
3438
|
-
const b = parts(right);
|
|
3439
|
-
const width = Math.max(a.length, b.length);
|
|
3440
|
-
for (let index = 0; index < width; index += 1) {
|
|
3441
|
-
const difference = (a[index] ?? 0) - (b[index] ?? 0);
|
|
3442
|
-
if (difference !== 0) return difference;
|
|
3443
|
-
}
|
|
3444
|
-
return 0;
|
|
3445
|
-
}
|
|
3446
|
-
|
|
3447
|
-
/**
|
|
3448
|
-
* The contract that produced this evidence must be the one being planned.
|
|
3449
|
-
*
|
|
3450
|
-
* `workflow_ref` and `workflow_sha` are not redundant with the tree: consumers
|
|
3451
|
-
* call the reusable workflow at `@main`, so its contents can change with NO
|
|
3452
|
-
* change to the caller's tree, and tree identity alone would let an older,
|
|
3453
|
-
* weaker workflow's proof satisfy a stricter one. `registry_version` may be
|
|
3454
|
-
* NEWER than the local one — a stricter producer is acceptable, which is what
|
|
3455
|
-
* "same or stricter" means — but never older.
|
|
3456
|
-
* @param {object} contract The envelope's contract block.
|
|
3457
|
-
* @param {string} moment The moment being planned.
|
|
3458
|
-
* @param {object} observed Locally observed facts.
|
|
3459
|
-
* @returns {string|null} A problem, or null.
|
|
3460
|
-
*/
|
|
3461
|
-
function verifyContract(contract, moment, observed) {
|
|
3462
|
-
if (contract.moment !== moment) {
|
|
3463
|
-
return `evidence is for moment ${JSON.stringify(contract.moment ?? null)}, not ${JSON.stringify(moment)}`;
|
|
3464
|
-
}
|
|
3465
|
-
const pairs = [
|
|
3466
|
-
["gates_digest", observed.gatesDigest],
|
|
3467
|
-
["inputs_digest", observed.inputsDigest],
|
|
3468
|
-
["workflow_ref", observed.workflowRef],
|
|
3469
|
-
["workflow_sha", observed.workflowSha],
|
|
3470
|
-
];
|
|
3471
|
-
for (const [field, expected] of pairs) {
|
|
3472
|
-
if (!contract[field] || !expected || contract[field] !== expected) {
|
|
3473
|
-
return `${field} is ${JSON.stringify(contract[field] ?? null)}, not ${JSON.stringify(expected ?? null)}`;
|
|
3474
|
-
}
|
|
3475
|
-
}
|
|
3476
|
-
if (!contract.registry_version || !observed.registryVersion) {
|
|
3477
|
-
return `registry_version is ${JSON.stringify(contract.registry_version ?? null)}, and an unknown producer version cannot be shown to be same-or-stricter`;
|
|
3478
|
-
}
|
|
3479
|
-
if (
|
|
3480
|
-
compareVersions(contract.registry_version, observed.registryVersion) < 0
|
|
3481
|
-
) {
|
|
3482
|
-
return `registry_version ${contract.registry_version} is older than this run's ${observed.registryVersion}, so it may declare less or declare it more weakly`;
|
|
3483
|
-
}
|
|
3484
|
-
return null;
|
|
3485
|
-
}
|
|
3486
|
-
|
|
3487
|
-
/**
|
|
3488
|
-
* The evidence must be PRIMARY and attributable.
|
|
3489
|
-
*
|
|
3490
|
-
* `reused_gates` closes circular reuse: a run that reused evidence and then
|
|
3491
|
-
* emitted its own could otherwise be reused in turn, and the chain of proof
|
|
3492
|
-
* bottoms out on nothing. `caller_chain` closes it a second time from a
|
|
3493
|
-
* different direction — a release-path envelope is nested one level deeper than
|
|
3494
|
-
* a pull-request one — and a null chain is ineligible rather than assumed
|
|
3495
|
-
* shallow. `run_url` is what makes the ledger auditable: evidence nobody can go
|
|
3496
|
-
* and read is not evidence anyone checked.
|
|
3497
|
-
* @param {object} producer The envelope's producer block.
|
|
3498
|
-
* @returns {{detail: string, reason: string}|null} A refusal, or null.
|
|
3499
|
-
*/
|
|
3500
|
-
function verifyProducer(producer) {
|
|
3501
|
-
const reused = producer.reused_gates;
|
|
3502
|
-
if (!Array.isArray(reused)) {
|
|
3503
|
-
return {
|
|
3504
|
-
detail:
|
|
3505
|
-
"producer.reused_gates is absent or not an array, so this run cannot be shown to be primary proof",
|
|
3506
|
-
reason: REUSE_REASON.DERIVATIVE,
|
|
3507
|
-
};
|
|
3508
|
-
}
|
|
3509
|
-
if (reused.length) {
|
|
3510
|
-
return {
|
|
3511
|
-
detail: `producer reused ${reused.length} gate(s), so this is not primary proof`,
|
|
3512
|
-
reason: REUSE_REASON.DERIVATIVE,
|
|
3513
|
-
};
|
|
3514
|
-
}
|
|
3515
|
-
const chain = producer.caller_chain;
|
|
3516
|
-
if (!Array.isArray(chain) || chain.length !== PRIMARY_CALLER_CHAIN_DEPTH) {
|
|
3517
|
-
return {
|
|
3518
|
-
detail: `producer.caller_chain is ${JSON.stringify(chain ?? null)}; only a chain of depth ${PRIMARY_CALLER_CHAIN_DEPTH} is a primary pull-request path`,
|
|
3519
|
-
reason: REUSE_REASON.UNATTRIBUTABLE,
|
|
3520
|
-
};
|
|
3521
|
-
}
|
|
3522
|
-
if (!producer.run_id || !producer.run_url) {
|
|
3523
|
-
return {
|
|
3524
|
-
detail:
|
|
3525
|
-
"producer.run_id or producer.run_url is absent, so the proof cannot be read back",
|
|
3526
|
-
reason: REUSE_REASON.UNATTRIBUTABLE,
|
|
3527
|
-
};
|
|
3528
|
-
}
|
|
3529
|
-
return null;
|
|
3530
|
-
}
|
|
3531
|
-
|
|
3532
|
-
/**
|
|
3533
|
-
* Whether the envelope as a WHOLE may be used as a source of proof.
|
|
3534
|
-
*
|
|
3535
|
-
* Every check here discards the entire document, because each one says the
|
|
3536
|
-
* evidence is about a different subject, a different contract, or is not
|
|
3537
|
-
* primary. A per-gate check cannot rescue any of them.
|
|
3538
|
-
* @param {object} options Inputs.
|
|
3539
|
-
* @param {unknown} options.envelope The parsed envelope, or null.
|
|
3540
|
-
* @param {string} options.moment The moment being planned.
|
|
3541
|
-
* @param {object} options.observed Locally observed facts.
|
|
3542
|
-
* @returns {{detail: string|null, ok: boolean, reason: string|null}} Verdict.
|
|
3543
|
-
*/
|
|
3544
|
-
function verifyEnvelope({ envelope, moment, observed }) {
|
|
3545
|
-
const refuse = (reason, detail) => ({ detail, ok: false, reason });
|
|
3546
|
-
if (!envelope || typeof envelope !== "object" || Array.isArray(envelope)) {
|
|
3547
|
-
return refuse(REUSE_REASON.MALFORMED, "the envelope is not a JSON object");
|
|
3548
|
-
}
|
|
3549
|
-
if (envelope.schema !== EVIDENCE_SCHEMA_TOKEN) {
|
|
3550
|
-
return refuse(
|
|
3551
|
-
REUSE_REASON.MALFORMED,
|
|
3552
|
-
`schema is ${JSON.stringify(envelope.schema ?? null)}, not ${JSON.stringify(EVIDENCE_SCHEMA_TOKEN)}`
|
|
3553
|
-
);
|
|
3554
|
-
}
|
|
3555
|
-
if (!Array.isArray(envelope.gates)) {
|
|
3556
|
-
return refuse(REUSE_REASON.MALFORMED, "gates is not an array");
|
|
3557
|
-
}
|
|
3558
|
-
if (envelope.verdict !== "proved") {
|
|
3559
|
-
return refuse(
|
|
3560
|
-
REUSE_REASON.NOT_PROVED,
|
|
3561
|
-
`verdict is ${JSON.stringify(envelope.verdict ?? null)}, not "proved"`
|
|
3562
|
-
);
|
|
3563
|
-
}
|
|
3564
|
-
const subjectProblem = verifySubject(envelope.subject ?? {}, observed);
|
|
3565
|
-
if (subjectProblem) {
|
|
3566
|
-
return refuse(REUSE_REASON.SUBJECT_MISMATCH, subjectProblem);
|
|
3567
|
-
}
|
|
3568
|
-
const contractProblem = verifyContract(
|
|
3569
|
-
envelope.contract ?? {},
|
|
3570
|
-
moment,
|
|
3571
|
-
observed
|
|
3572
|
-
);
|
|
3573
|
-
if (contractProblem) {
|
|
3574
|
-
return refuse(REUSE_REASON.CONTRACT_MISMATCH, contractProblem);
|
|
3575
|
-
}
|
|
3576
|
-
const producerProblem = verifyProducer(envelope.producer ?? {});
|
|
3577
|
-
if (producerProblem) {
|
|
3578
|
-
return refuse(producerProblem.reason, producerProblem.detail);
|
|
3579
|
-
}
|
|
3580
|
-
return { detail: null, ok: true, reason: null };
|
|
3581
|
-
}
|
|
3582
|
-
|
|
3583
|
-
/**
|
|
3584
|
-
* The freshness bound to judge a row by: the tighter of the two, never the
|
|
3585
|
-
* looser.
|
|
3586
|
-
*
|
|
3587
|
-
* A producer that stamped its own bound and a policy that declares one are two
|
|
3588
|
-
* claims about the same question, and taking the maximum would let a generous
|
|
3589
|
-
* producer widen a window the project narrowed.
|
|
3590
|
-
* @param {object} row The evidence row.
|
|
3591
|
-
* @param {object} policy The gate's reuse policy.
|
|
3592
|
-
* @returns {number|null} The bound in minutes, or null for unbounded.
|
|
3593
|
-
*/
|
|
3594
|
-
function effectiveBound(row, policy) {
|
|
3595
|
-
const bounds = [row.max_age_minutes, policy.maxAgeMinutes].filter(
|
|
3596
|
-
value => typeof value === "number" && value > 0
|
|
3597
|
-
);
|
|
3598
|
-
return bounds.length ? Math.min(...bounds) : null;
|
|
3599
|
-
}
|
|
3600
|
-
|
|
3601
|
-
/**
|
|
3602
|
-
* Whether ONE gate's row proves what this moment requires of it.
|
|
3603
|
-
*
|
|
3604
|
-
* Row-level failures affect one gate and never leak into another's decision —
|
|
3605
|
-
* the fixtures assert exactly that, because a verifier whose failures
|
|
3606
|
-
* cross-contaminate is one nobody can reason about one dimension at a time.
|
|
3607
|
-
* @param {object} options Inputs.
|
|
3608
|
-
* @param {object} options.gate The resolved gate at this moment.
|
|
3609
|
-
* @param {number} options.nowMs Clock.
|
|
3610
|
-
* @param {object} options.observed Locally observed facts.
|
|
3611
|
-
* @param {object} options.policy Its reuse policy.
|
|
3612
|
-
* @param {object} [options.row] Its evidence row, if any.
|
|
3613
|
-
* @returns {{decision: string, detail: string|null, reason: string}} Verdict.
|
|
3614
|
-
*/
|
|
3615
|
-
function verifyRow({ gate, nowMs, observed, policy, row }) {
|
|
3616
|
-
const run = (reason, detail = null) => ({ decision: "run", detail, reason });
|
|
3617
|
-
if (policy.class === REUSE_CLASS.NEVER) {
|
|
3618
|
-
return policy.known
|
|
3619
|
-
? run(REUSE_REASON.NEVER_REUSABLE, "declared never reusable")
|
|
3620
|
-
: run(
|
|
3621
|
-
REUSE_REASON.UNCLASSIFIED,
|
|
3622
|
-
"no reuse class is declared for this gate, and the default is never"
|
|
3623
|
-
);
|
|
3624
|
-
}
|
|
3625
|
-
if (!row) {
|
|
3626
|
-
return run(REUSE_REASON.UNCOVERED, "the envelope carries no row for it");
|
|
3627
|
-
}
|
|
3628
|
-
const bound = effectiveBound(row, policy);
|
|
3629
|
-
const effective = readEvidence(
|
|
3630
|
-
{ ...row, max_age_minutes: bound },
|
|
3631
|
-
gate,
|
|
3632
|
-
nowMs
|
|
3633
|
-
);
|
|
3634
|
-
if (effective.status !== "pass") {
|
|
3635
|
-
const reason = effective.reason ?? "";
|
|
3636
|
-
const stale = reason.includes("past its") || reason.includes("observed_at");
|
|
3637
|
-
return run(
|
|
3638
|
-
stale ? REUSE_REASON.STALE : REUSE_REASON.NOT_PROVED,
|
|
3639
|
-
effective.reason
|
|
3640
|
-
);
|
|
3641
|
-
}
|
|
3642
|
-
if (policy.class === REUSE_CLASS.TIME_SENSITIVE) {
|
|
3643
|
-
if (!bound) {
|
|
3644
|
-
return run(
|
|
3645
|
-
REUSE_REASON.STALE,
|
|
3646
|
-
"time-sensitive with no declared window, so freshness was never bounded"
|
|
3647
|
-
);
|
|
3648
|
-
}
|
|
3649
|
-
if (!row.prover?.version) {
|
|
3650
|
-
return run(
|
|
3651
|
-
REUSE_REASON.UNATTRIBUTABLE,
|
|
3652
|
-
"time-sensitive and prover.version is absent, so the scanner that produced it is unknown"
|
|
3653
|
-
);
|
|
3654
|
-
}
|
|
3655
|
-
}
|
|
3656
|
-
const rank = LEVEL_RANK[row.level];
|
|
3657
|
-
const requiredRank = LEVEL_RANK[gate.level];
|
|
3658
|
-
if (rank === undefined || requiredRank === undefined || rank < requiredRank) {
|
|
3659
|
-
return run(
|
|
3660
|
-
REUSE_REASON.LEVEL_DOWNGRADE,
|
|
3661
|
-
`proved at ${JSON.stringify(row.level ?? null)} but this moment requires ${gate.level}`
|
|
3662
|
-
);
|
|
3663
|
-
}
|
|
3664
|
-
// A diff gate resolved a BASE revision, which the tree hash does not carry.
|
|
3665
|
-
// Two commits sharing a tree do not share a diff, so this sub-class binds to
|
|
3666
|
-
// the commit as well — a strictly stronger requirement than the rest.
|
|
3667
|
-
if (policy.diff && !observed.commitMatches) {
|
|
3668
|
-
return run(
|
|
3669
|
-
REUSE_REASON.SUBJECT_MISMATCH,
|
|
3670
|
-
"a diff gate is bound to the commit it diffed, and the commit differs"
|
|
3671
|
-
);
|
|
3672
|
-
}
|
|
3673
|
-
return { decision: "reuse", detail: null, reason: REUSE_REASON.REUSED };
|
|
3674
|
-
}
|
|
3675
|
-
|
|
3676
|
-
/**
|
|
3677
|
-
* Plan which gates at a moment may stand down on verified prior evidence.
|
|
3678
|
-
*
|
|
3679
|
-
* FAIL-CLOSED IS THE WHOLE CONTRACT. Every path through this function that is
|
|
3680
|
-
* not "the envelope passed every check AND this row passed every check" returns
|
|
3681
|
-
* `run`. There is no blanket switch, no `skip_jobs` equivalent, and no branch
|
|
3682
|
-
* where the ABSENCE of evidence produces anything but a full plan.
|
|
3683
|
-
* @param {object} options Inputs.
|
|
3684
|
-
* @param {unknown} options.envelope The parsed inbound envelope, or null.
|
|
3685
|
-
* @param {object|null} [options.gates] The project gates block.
|
|
3686
|
-
* @param {string} options.moment The moment being planned.
|
|
3687
|
-
* @param {number} [options.nowMs] Clock, injected for tests.
|
|
3688
|
-
* @param {object} options.observed Locally observed facts.
|
|
3689
|
-
* @param {{detail: string, reason: string}|null} [options.refusal] A refusal the caller already reached.
|
|
3690
|
-
* @param {string} [options.runner] The task-runner prefix.
|
|
3691
|
-
* @param {Record<string,string>|null} [options.scripts] Project scripts.
|
|
3692
|
-
* @returns {{decisions: object[], detail: string|null, verdict: string}} Plan.
|
|
3693
|
-
*/
|
|
3694
|
-
export function reusePlan({
|
|
3695
|
-
envelope,
|
|
3696
|
-
gates = null,
|
|
3697
|
-
moment,
|
|
3698
|
-
nowMs = Date.now(),
|
|
3699
|
-
observed,
|
|
3700
|
-
refusal = null,
|
|
3701
|
-
runner = undefined,
|
|
3702
|
-
scripts = null,
|
|
3703
|
-
}) {
|
|
3704
|
-
const resolveOptions = { gates, moment, scripts };
|
|
3705
|
-
const resolved = resolveMoment(
|
|
3706
|
-
runner === undefined ? resolveOptions : { ...resolveOptions, runner }
|
|
3707
|
-
);
|
|
3708
|
-
// A refusal the CALLER already reached outranks anything this function could
|
|
3709
|
-
// work out. "The file was not there" and "the file was there and wrong" are
|
|
3710
|
-
// different facts about the same absent proof, and only the caller that tried
|
|
3711
|
-
// to open it knows which — reporting the wrong one sends an operator looking
|
|
3712
|
-
// at the wrong thing, and the ledger compares these tokens.
|
|
3713
|
-
const envelopeVerdict = refusal
|
|
3714
|
-
? { detail: refusal.detail, ok: false, reason: refusal.reason }
|
|
3715
|
-
: verifyEnvelope({ envelope, moment, observed });
|
|
3716
|
-
const rows = new Map(
|
|
3717
|
-
envelopeVerdict.ok
|
|
3718
|
-
? envelope.gates
|
|
3719
|
-
.filter(row => row && typeof row.gate === "string")
|
|
3720
|
-
.map(row => [row.gate, row])
|
|
3721
|
-
: []
|
|
3722
|
-
);
|
|
3723
|
-
const commitMatches = Boolean(
|
|
3724
|
-
envelope?.subject?.commit &&
|
|
3725
|
-
observed.commit &&
|
|
3726
|
-
envelope.subject.commit === observed.commit
|
|
3727
|
-
);
|
|
3728
|
-
const decisions = resolved.map(gate => {
|
|
3729
|
-
const policy = reusePolicyFor(gate.id, gates);
|
|
3730
|
-
const outcome = envelopeVerdict.ok
|
|
3731
|
-
? verifyRow({
|
|
3732
|
-
gate,
|
|
3733
|
-
nowMs,
|
|
3734
|
-
observed: { ...observed, commitMatches },
|
|
3735
|
-
policy,
|
|
3736
|
-
row: rows.get(gate.id),
|
|
3737
|
-
})
|
|
3738
|
-
: {
|
|
3739
|
-
decision: "run",
|
|
3740
|
-
detail: envelopeVerdict.detail,
|
|
3741
|
-
reason: envelopeVerdict.reason,
|
|
3742
|
-
};
|
|
3743
|
-
return {
|
|
3744
|
-
class: policy.class,
|
|
3745
|
-
decision: outcome.decision,
|
|
3746
|
-
detail: outcome.detail,
|
|
3747
|
-
gate: gate.id,
|
|
3748
|
-
label: gate.label,
|
|
3749
|
-
level: gate.level,
|
|
3750
|
-
proof:
|
|
3751
|
-
outcome.decision === "reuse"
|
|
3752
|
-
? (envelope.producer?.run_url ?? null)
|
|
3753
|
-
: null,
|
|
3754
|
-
reason: outcome.reason,
|
|
3755
|
-
};
|
|
3756
|
-
});
|
|
3757
|
-
return {
|
|
3758
|
-
decisions,
|
|
3759
|
-
detail: envelopeVerdict.detail,
|
|
3760
|
-
verdict: envelopeVerdict.ok ? "verified" : envelopeVerdict.reason,
|
|
3761
|
-
};
|
|
3762
|
-
}
|
|
3763
|
-
|
|
3764
|
-
/**
|
|
3765
|
-
* Read an envelope from disk for the verifier, refusing anything it cannot
|
|
3766
|
-
* safely read.
|
|
3767
|
-
*
|
|
3768
|
-
* A read failure and a parse failure both return null plus a reason, because
|
|
3769
|
-
* the caller does the same thing with both: run everything. They carry
|
|
3770
|
-
* DIFFERENT refusal tokens, because an absent record and a corrupt one are
|
|
3771
|
-
* different things to go and fix. The byte budget lives here rather than in the
|
|
3772
|
-
* caller so every entry point shares one limit.
|
|
3773
|
-
* @param {string} path File to read.
|
|
3774
|
-
* @param {object} [io] Injected fs, for tests.
|
|
3775
|
-
* @returns {{envelope: object|null, reason: string|null, refusal: string|null}} The parsed envelope.
|
|
3776
|
-
*/
|
|
3777
|
-
export function readEvidenceFile(path, io = {}) {
|
|
3778
|
-
const { readFile = readFileSync, statFile = statSync } = io;
|
|
3779
|
-
let raw = null;
|
|
3780
|
-
try {
|
|
3781
|
-
const { size } = statFile(path);
|
|
3782
|
-
if (size > EVIDENCE_BYTE_BUDGET) {
|
|
3783
|
-
return {
|
|
3784
|
-
envelope: null,
|
|
3785
|
-
reason: `evidence at ${path} is ${size} bytes, past the ${EVIDENCE_BYTE_BUDGET}-byte budget`,
|
|
3786
|
-
refusal: REUSE_REASON.UNAVAILABLE,
|
|
3787
|
-
};
|
|
3788
|
-
}
|
|
3789
|
-
raw = readFile(path, "utf8");
|
|
3790
|
-
} catch (err) {
|
|
3791
|
-
return {
|
|
3792
|
-
envelope: null,
|
|
3793
|
-
reason: `evidence at ${path} could not be opened: ${err.message}`,
|
|
3794
|
-
refusal: REUSE_REASON.UNAVAILABLE,
|
|
3795
|
-
};
|
|
3796
|
-
}
|
|
3797
|
-
try {
|
|
3798
|
-
return { envelope: JSON.parse(raw), reason: null, refusal: null };
|
|
3799
|
-
} catch (err) {
|
|
3800
|
-
// Split from the open failure deliberately. Bytes that exist and do not
|
|
3801
|
-
// parse are a MALFORMED record; bytes that are not there are an ABSENT one.
|
|
3802
|
-
// Both run everything, and an operator needs to know which to go and fix.
|
|
3803
|
-
return {
|
|
3804
|
-
envelope: null,
|
|
3805
|
-
reason: `evidence at ${path} is not JSON: ${err.message}`,
|
|
3806
|
-
refusal: REUSE_REASON.MALFORMED,
|
|
3807
|
-
};
|
|
3808
|
-
}
|
|
3809
|
-
}
|
|
3810
|
-
|
|
3811
3130
|
/** Description phrases that grant or deny credit for an awaited signal. */
|
|
3812
3131
|
export const EVIDENCE_DEFAULTS = Object.freeze({
|
|
3813
3132
|
// Matched strictly — whole description, case-insensitive — because a match
|
|
@@ -4768,7 +4087,6 @@ function validateGate(id, gate) {
|
|
|
4768
4087
|
);
|
|
4769
4088
|
}
|
|
4770
4089
|
problems.push(...validateNeeds(id, gate));
|
|
4771
|
-
problems.push(...validateReuse(id, gate.reuse));
|
|
4772
4090
|
|
|
4773
4091
|
for (const [moment, value] of Object.entries(gate)) {
|
|
4774
4092
|
// A key that is neither a known field nor a well-formed moment is a typo,
|
|
@@ -4879,57 +4197,6 @@ function validateFailureShape(id, moment, shape) {
|
|
|
4879
4197
|
return problems;
|
|
4880
4198
|
}
|
|
4881
4199
|
|
|
4882
|
-
/**
|
|
4883
|
-
* Validate a gate's reuse declaration (#3013).
|
|
4884
|
-
*
|
|
4885
|
-
* A half-written declaration here is the dangerous kind: a `time-sensitive`
|
|
4886
|
-
* class with no window would either be unbounded — the freshness requirement
|
|
4887
|
-
* resolving against nothing, which is the failure the gate façade exists to
|
|
4888
|
-
* refuse — or silently fall back to `never`, which is safe but leaves the
|
|
4889
|
-
* author believing they configured something. Refusing at declaration time is
|
|
4890
|
-
* the only reading that tells them.
|
|
4891
|
-
*
|
|
4892
|
-
* A window on a class that does not use one is refused for the mirror reason:
|
|
4893
|
-
* it reads as a bound that is being applied, and it is not.
|
|
4894
|
-
* @param {string} id Gate id.
|
|
4895
|
-
* @param {*} reuse The declared block, if any.
|
|
4896
|
-
* @returns {string[]} Problems.
|
|
4897
|
-
*/
|
|
4898
|
-
function validateReuse(id, reuse) {
|
|
4899
|
-
if (reuse === undefined) return [];
|
|
4900
|
-
const where = `gates."${id}"."reuse"`;
|
|
4901
|
-
if (!reuse || typeof reuse !== "object" || Array.isArray(reuse)) {
|
|
4902
|
-
return [`${where} must be an object`];
|
|
4903
|
-
}
|
|
4904
|
-
const problems = [];
|
|
4905
|
-
if (!REUSE_CLASSES.includes(reuse.class)) {
|
|
4906
|
-
problems.push(
|
|
4907
|
-
`${where}.class is ${JSON.stringify(reuse.class ?? null)}; ` +
|
|
4908
|
-
`expected one of ${REUSE_CLASSES.join(", ")}.`
|
|
4909
|
-
);
|
|
4910
|
-
}
|
|
4911
|
-
const window = reuse.max_age_minutes;
|
|
4912
|
-
if (reuse.class === REUSE_CLASS.TIME_SENSITIVE) {
|
|
4913
|
-
if (!Number.isFinite(window) || window <= 0) {
|
|
4914
|
-
problems.push(
|
|
4915
|
-
`${where}.max_age_minutes is ${JSON.stringify(window ?? null)}; ` +
|
|
4916
|
-
`a time-sensitive gate depends on external state that changes ` +
|
|
4917
|
-
`without the tree, so it must say how stale an answer it accepts. ` +
|
|
4918
|
-
`An unbounded window is not freshness, it is an unmeasured claim.`
|
|
4919
|
-
);
|
|
4920
|
-
}
|
|
4921
|
-
} else if (window !== undefined) {
|
|
4922
|
-
problems.push(
|
|
4923
|
-
`${where}.max_age_minutes is declared on a "${reuse.class}" gate, ` +
|
|
4924
|
-
`where nothing reads it. Either the class is wrong or the window is.`
|
|
4925
|
-
);
|
|
4926
|
-
}
|
|
4927
|
-
if (reuse.diff !== undefined && typeof reuse.diff !== "boolean") {
|
|
4928
|
-
problems.push(`${where}.diff must be true or false`);
|
|
4929
|
-
}
|
|
4930
|
-
return problems;
|
|
4931
|
-
}
|
|
4932
|
-
|
|
4933
4200
|
/**
|
|
4934
4201
|
* Validate one moment entry on a gate.
|
|
4935
4202
|
* @param {string} id Gate id.
|
|
@@ -7000,69 +6267,6 @@ function main() {
|
|
|
7000
6267
|
return;
|
|
7001
6268
|
}
|
|
7002
6269
|
|
|
7003
|
-
// ─── reuse-plan (#3013) ────────────────────────────────────────────────
|
|
7004
|
-
// Answers ONE question: which gates at this moment may stand down because a
|
|
7005
|
-
// VERIFIED envelope already proves them for this exact tree under this exact
|
|
7006
|
-
// contract. Every ambiguity — an unreadable file, a mismatched dimension, a
|
|
7007
|
-
// gate nobody classified — resolves to `run`, so the worst this command can
|
|
7008
|
-
// do is describe today's behaviour. It never exits non-zero on a refusal: an
|
|
7009
|
-
// optimization that can redden a release is not an optimization.
|
|
7010
|
-
if (command === "reuse-plan") {
|
|
7011
|
-
const moment = flag("moment");
|
|
7012
|
-
if (!moment) {
|
|
7013
|
-
throw new Error(
|
|
7014
|
-
"usage: lisa-gates.mjs reuse-plan --moment=<moment> --evidence=<file> --repository=<o/r> --tree=<sha> [--commit=<sha>] [--workflow-ref=<ref>] [--workflow-sha=<sha>] [--inputs-digest=<sha256:…>] [--registry-version=<v>] [--json]"
|
|
7015
|
-
);
|
|
7016
|
-
}
|
|
7017
|
-
const evidencePath = flag("evidence");
|
|
7018
|
-
const read = evidencePath
|
|
7019
|
-
? readEvidenceFile(evidencePath)
|
|
7020
|
-
: {
|
|
7021
|
-
envelope: null,
|
|
7022
|
-
reason: "no --evidence path was given, so nothing was verified",
|
|
7023
|
-
refusal: REUSE_REASON.UNAVAILABLE,
|
|
7024
|
-
};
|
|
7025
|
-
const plan = reusePlan({
|
|
7026
|
-
envelope: read.envelope,
|
|
7027
|
-
gates,
|
|
7028
|
-
moment,
|
|
7029
|
-
observed: {
|
|
7030
|
-
commit: flag("commit") ?? null,
|
|
7031
|
-
gatesDigest: planDigest({ gates, moment, runner, scripts }),
|
|
7032
|
-
inputsDigest: flag("inputs-digest") ?? null,
|
|
7033
|
-
registryVersion: flag("registry-version") ?? null,
|
|
7034
|
-
repository: flag("repository") ?? null,
|
|
7035
|
-
tree: flag("tree") ?? null,
|
|
7036
|
-
workflowRef: flag("workflow-ref") ?? null,
|
|
7037
|
-
workflowSha: flag("workflow-sha") ?? null,
|
|
7038
|
-
},
|
|
7039
|
-
refusal: read.refusal
|
|
7040
|
-
? { detail: read.reason, reason: read.refusal }
|
|
7041
|
-
: null,
|
|
7042
|
-
runner,
|
|
7043
|
-
scripts,
|
|
7044
|
-
});
|
|
7045
|
-
if (rest.includes("--json")) {
|
|
7046
|
-
console.log(JSON.stringify(plan, null, 2));
|
|
7047
|
-
return;
|
|
7048
|
-
}
|
|
7049
|
-
console.log(`reuse verdict: ${plan.verdict}`);
|
|
7050
|
-
if (plan.detail) console.log(` ${plan.detail}`);
|
|
7051
|
-
for (const entry of plan.decisions) {
|
|
7052
|
-
const proof = entry.proof ? ` ← ${entry.proof}` : "";
|
|
7053
|
-
console.log(
|
|
7054
|
-
` ${entry.decision === "reuse" ? "♻️ " : "▶️ "} ${entry.gate.padEnd(28)} ${entry.reason}${proof}`
|
|
7055
|
-
);
|
|
7056
|
-
}
|
|
7057
|
-
const reused = plan.decisions.filter(
|
|
7058
|
-
entry => entry.decision === "reuse"
|
|
7059
|
-
).length;
|
|
7060
|
-
console.log(
|
|
7061
|
-
`\n${reused} of ${plan.decisions.length} gate(s) at ${moment} are proved by prior evidence.`
|
|
7062
|
-
);
|
|
7063
|
-
return;
|
|
7064
|
-
}
|
|
7065
|
-
|
|
7066
6270
|
if (command === "audit-config") {
|
|
7067
6271
|
const findings = auditConfigKeys(config);
|
|
7068
6272
|
for (const finding of findings) console.error(` ${finding.message}`);
|
|
@@ -7071,7 +6275,7 @@ function main() {
|
|
|
7071
6275
|
}
|
|
7072
6276
|
|
|
7073
6277
|
throw new Error(
|
|
7074
|
-
"usage: lisa-gates.mjs validate|list|legs|quality-plan|
|
|
6278
|
+
"usage: lisa-gates.mjs validate|list|legs|quality-plan|needs|contexts|retired-contexts|verify-contexts|skip-jobs|audit-config|inventory|unconfigured|identity|seed"
|
|
7075
6279
|
);
|
|
7076
6280
|
}
|
|
7077
6281
|
|