@boyingliu01/xp-gate 0.31.4 → 0.32.1
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/adapters/java.sh +256 -4
- package/adapters/powershell.sh +45 -6
- package/bin/xp-gate.js +8 -2
- package/build-integrity/__tests__/gate-10.test.ts +88 -1
- package/build-integrity/gate-10.ts +51 -16
- package/dsh.bundle.patch.yml +15 -0
- package/gate-13-compiler-strictness.sh +1031 -0
- package/gate-3.sh +65 -16
- package/hooks/gate-13-compiler-strictness.sh +1031 -0
- package/hooks/gate-3.sh +65 -16
- package/hooks/lib/coverage-total.sh +18 -2
- package/hooks/lib/java-test-selection.sh +251 -0
- package/hooks/lib/jscpd-run.sh +101 -0
- package/hooks/lib/validate-code-walkthrough.cjs +186 -29
- package/hooks/pre-commit +259 -57
- package/lib/__tests__/detect-deps-dsh-profile.test.js +106 -0
- package/lib/__tests__/doctor-tui-skill-freshness.test.js +140 -0
- package/lib/__tests__/gate-runner.test.js +29 -2
- package/lib/__tests__/issue-586-principles-cmdline.test.js +35 -0
- package/lib/__tests__/issue-618-gate-not-run.test.js +100 -0
- package/lib/__tests__/shared-utils.test.js +21 -0
- package/lib/check.js +6 -2
- package/lib/detect-deps.js +42 -10
- package/lib/doctor-tui.js +111 -21
- package/lib/gate-runner.js +111 -37
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/principles.js +48 -6
- package/lib/shared-utils.js +8 -0
- package/mock-policy/AGENTS.md +3 -3
- package/mock-policy/gate-m3.ts +57 -23
- package/mutation/AGENTS.md +3 -3
- package/mutation/__tests__/pitest-gradle-availability.test.ts +74 -0
- package/mutation/__tests__/test-filter-parity.test.ts +5 -2
- package/mutation/gate-m.ts +30 -24
- package/mutation/runners/mutmut-runner.ts +80 -30
- package/mutation/runners/pitest-runner.ts +60 -42
- package/package.json +14 -2
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +3 -3
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +3 -3
- package/plugins/dsh/lib/command.d.ts +38 -0
- package/plugins/dsh/lib/command.d.ts.map +1 -0
- package/plugins/dsh/lib/command.js +87 -0
- package/plugins/dsh/lib/credentials.d.ts +39 -0
- package/plugins/dsh/lib/credentials.d.ts.map +1 -0
- package/plugins/dsh/lib/credentials.js +57 -0
- package/plugins/dsh/lib/delphi-config.d.ts +129 -0
- package/plugins/dsh/lib/delphi-config.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-config.js +369 -0
- package/plugins/dsh/lib/delphi-run.d.ts +24 -0
- package/plugins/dsh/lib/delphi-run.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi-run.js +113 -0
- package/plugins/dsh/lib/delphi.d.ts +94 -0
- package/plugins/dsh/lib/delphi.d.ts.map +1 -0
- package/plugins/dsh/lib/delphi.js +207 -0
- package/plugins/dsh/lib/dialect.d.ts +24 -0
- package/plugins/dsh/lib/dialect.d.ts.map +1 -0
- package/plugins/dsh/lib/dialect.js +36 -0
- package/plugins/dsh/lib/evidence.d.ts +70 -0
- package/plugins/dsh/lib/evidence.d.ts.map +1 -0
- package/plugins/dsh/lib/evidence.js +92 -0
- package/plugins/dsh/lib/gate-runner.d.ts +49 -0
- package/plugins/dsh/lib/gate-runner.d.ts.map +1 -0
- package/plugins/dsh/lib/gate-runner.js +95 -0
- package/plugins/dsh/lib/git-context.d.ts +26 -0
- package/plugins/dsh/lib/git-context.d.ts.map +1 -0
- package/plugins/dsh/lib/git-context.js +30 -0
- package/plugins/dsh/lib/hooks.d.ts +42 -0
- package/plugins/dsh/lib/hooks.d.ts.map +1 -0
- package/plugins/dsh/lib/hooks.js +113 -0
- package/plugins/dsh/lib/index.d.ts +20 -0
- package/plugins/dsh/lib/index.d.ts.map +1 -0
- package/plugins/dsh/lib/index.js +430 -0
- package/plugins/dsh/lib/skill-provider.d.ts +15 -0
- package/plugins/dsh/lib/skill-provider.d.ts.map +1 -0
- package/plugins/dsh/lib/skill-provider.js +205 -0
- package/plugins/dsh/lib/sprint.d.ts +60 -0
- package/plugins/dsh/lib/sprint.d.ts.map +1 -0
- package/plugins/dsh/lib/sprint.js +92 -0
- package/plugins/dsh/package.json +14 -8
- package/plugins/dsh/scripts/verify-skill-provider.mjs +113 -0
- package/plugins/dsh/skills/delphi-review/AGENTS.md +3 -3
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +3 -3
- package/plugins/dsh/src/command-single-form.test.ts +67 -0
- package/plugins/dsh/src/command.test.ts +21 -17
- package/plugins/dsh/src/command.ts +19 -21
- package/plugins/dsh/src/compat.test.ts +200 -0
- package/plugins/dsh/src/contract.test.ts +7 -1
- package/plugins/dsh/src/credentials.test.ts +93 -0
- package/plugins/dsh/src/credentials.ts +71 -0
- package/plugins/dsh/src/delphi-cancellation.test.ts +71 -0
- package/plugins/dsh/src/delphi-config-apikey-override.test.ts +94 -0
- package/plugins/dsh/src/delphi-config-credential-refs.test.ts +75 -0
- package/plugins/dsh/src/delphi-config.ts +146 -53
- package/plugins/dsh/src/delphi-run.ts +27 -4
- package/plugins/dsh/src/delphi.ts +133 -65
- package/plugins/dsh/src/evidence.test.ts +74 -0
- package/plugins/dsh/src/evidence.ts +141 -0
- package/plugins/dsh/src/gate-runner.test.ts +14 -6
- package/plugins/dsh/src/gate-runner.ts +68 -5
- package/plugins/dsh/src/git-context.test.ts +39 -0
- package/plugins/dsh/src/git-context.ts +38 -0
- package/plugins/dsh/src/hooks.test.ts +87 -0
- package/plugins/dsh/src/hooks.ts +126 -0
- package/plugins/dsh/src/index.test.ts +63 -6
- package/plugins/dsh/src/index.ts +340 -13
- package/plugins/dsh/src/skill-provider.test.ts +194 -0
- package/plugins/dsh/src/skill-provider.ts +231 -0
- package/plugins/dsh/src/sprint.test.ts +64 -0
- package/plugins/dsh/src/sprint.ts +122 -0
- package/plugins/dsh/src/tri-state.test.ts +123 -0
- package/plugins/opencode/index.ts +192 -58
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +3 -3
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +3 -3
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +3 -3
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +3 -3
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +3 -3
- package/principles/AGENTS.md +3 -3
- package/principles/__tests__/analyze-read-failure.test.ts +70 -0
- package/principles/__tests__/baseline-prune.test.ts +61 -0
- package/principles/__tests__/cli-files-separators.test.ts +69 -0
- package/principles/__tests__/config-merge-warnings.test.ts +148 -0
- package/principles/adapters/java.ts +22 -3
- package/principles/adapters/typescript.ts +70 -29
- package/principles/analyzer.ts +36 -3
- package/principles/baseline-prune.ts +19 -7
- package/principles/config.ts +56 -35
- package/principles/index.ts +122 -40
- package/principles/rules/clean-code/deep-nesting.ts +36 -22
- package/principles/rules/clean-code/unused-imports.ts +30 -19
- package/principles/rules/solid/dip.ts +30 -20
- package/principles/rules/solid/lsp.ts +17 -2
- package/principles/rules/solid/ocp.ts +33 -23
- package/principles/rules/solid/srp.ts +65 -23
- package/scripts/delphi-external-review.cjs +25 -2
- package/scripts/sync-package-content.js +28 -1
- package/skills/delphi-review/AGENTS.md +3 -3
- package/skills/sprint-flow/AGENTS.md +3 -3
- package/skills/test-specification-alignment/AGENTS.md +3 -3
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
const fs = require('node:fs');
|
|
5
5
|
const path = require('node:path');
|
|
6
|
+
const os = require('node:os');
|
|
6
7
|
|
|
7
8
|
const REQUIRED_ROLES = ['architecture', 'technical', 'feasibility'];
|
|
8
9
|
const VALIDITY_MS = 60 * 60 * 1000;
|
|
@@ -45,25 +46,31 @@ function parseTimestamp(value, field) {
|
|
|
45
46
|
: null;
|
|
46
47
|
if (!match) fail(`${field} must be a canonical UTC ISO-8601 timestamp.`);
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const minute =
|
|
54
|
-
const
|
|
55
|
-
const milliseconds = Number((fractionText || '').padEnd(3, '0') || 0);
|
|
49
|
+
// Groups 1..6 are year, month, day, hour, minute, second; group 7 is the
|
|
50
|
+
// optional millisecond fraction. Keeping them as arrays means the "build the
|
|
51
|
+
// date" and "verify round-trip" steps share one ordered definition instead of
|
|
52
|
+
// repeating seven hand-numbered comparisons.
|
|
53
|
+
const parts = match.slice(1, 7).map(Number);
|
|
54
|
+
const [year, month, day, hour, minute, second] = parts;
|
|
55
|
+
const milliseconds = Number((match[7] || '').padEnd(3, '0') || 0);
|
|
56
56
|
const date = new Date(0);
|
|
57
57
|
date.setUTCFullYear(year, month - 1, day);
|
|
58
58
|
date.setUTCHours(hour, minute, second, milliseconds);
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
// A date silently rolls over ("2026-02-30" becomes March 2), so the only way
|
|
61
|
+
// to know the input was a real calendar instant is to read it back and compare
|
|
62
|
+
// every field.
|
|
63
|
+
const expected = [...parts, milliseconds];
|
|
64
|
+
const readBack = [
|
|
65
|
+
date.getUTCFullYear(),
|
|
66
|
+
date.getUTCMonth() + 1,
|
|
67
|
+
date.getUTCDate(),
|
|
68
|
+
date.getUTCHours(),
|
|
69
|
+
date.getUTCMinutes(),
|
|
70
|
+
date.getUTCSeconds(),
|
|
71
|
+
date.getUTCMilliseconds(),
|
|
72
|
+
];
|
|
73
|
+
if (!readBack.every((actual, i) => actual === expected[i])) {
|
|
67
74
|
fail(`${field} must contain a valid UTC calendar date and time.`);
|
|
68
75
|
}
|
|
69
76
|
return date.getTime();
|
|
@@ -142,6 +149,19 @@ function resolveBindingSeats(config) {
|
|
|
142
149
|
return seatsFromExperts(profiles[active].experts);
|
|
143
150
|
}
|
|
144
151
|
|
|
152
|
+
/**
|
|
153
|
+
* Machine-wide Delphi config path: `$XDG_CONFIG_HOME/xp-gate/` or
|
|
154
|
+
* `~/.config/xp-gate/`. Mirrors `defaultGlobalConfigPath()` in
|
|
155
|
+
* `plugins/dsh/src/delphi-config.ts` so the gate and the tool that produces the
|
|
156
|
+
* evidence agree on where seats come from. XDG_CONFIG_HOME is honoured because
|
|
157
|
+
* the plugin honours it — a gate reading a different file than the reviewer
|
|
158
|
+
* used would bind against seats nobody actually ran.
|
|
159
|
+
*/
|
|
160
|
+
function globalConfigPath(env = process.env) {
|
|
161
|
+
const base = env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');
|
|
162
|
+
return path.join(base, 'xp-gate', DELPHI_CONFIG_FILE);
|
|
163
|
+
}
|
|
164
|
+
|
|
145
165
|
/**
|
|
146
166
|
* Read the binding seats for the project rooted at `projectRoot`.
|
|
147
167
|
*
|
|
@@ -152,23 +172,88 @@ function resolveBindingSeats(config) {
|
|
|
152
172
|
* fixture to xp-gate's seats. The gate's subject is the repository being
|
|
153
173
|
* pushed, so that is what must be named.
|
|
154
174
|
*
|
|
175
|
+
* ## Global fallback (2026-10-27)
|
|
176
|
+
*
|
|
177
|
+
* A project file still WINS, so a repo can override seats deliberately. When
|
|
178
|
+
* the project has none, the machine-wide config is used instead of returning
|
|
179
|
+
* null — and this is load-bearing, not a convenience:
|
|
180
|
+
*
|
|
181
|
+
* Before this fallback existed, DELETING a project-level config silently
|
|
182
|
+
* disabled the entire #574 seat check, because `bindingSeats === null`
|
|
183
|
+
* short-circuits `validateRequestedModel`. The gate kept reporting PASS while
|
|
184
|
+
* any three distinct gateway models — including the expensive overseas ones
|
|
185
|
+
* #574 exists to catch — could satisfy it, with no message anywhere. A user
|
|
186
|
+
* consolidating onto one global config to stop maintaining a copy per repo
|
|
187
|
+
* would have unknowingly traded that protection away.
|
|
188
|
+
*
|
|
189
|
+
* Only ENOENT triggers the fallback: an unreadable project config
|
|
190
|
+
* (EACCES/EISDIR) must surface rather than silently routing this run to a
|
|
191
|
+
* different file. Same semantics as `loadDelphiConfig()` in the DSH plugin.
|
|
192
|
+
*
|
|
193
|
+
* ## No config anywhere is now FAIL-CLOSED (2026-10-27)
|
|
194
|
+
*
|
|
195
|
+
* Returning null when both locations are absent re-opened the exact hole #574
|
|
196
|
+
* closed: measured, `b-claude-4.8-opus` / `gpt-5.5` / `gemini-3-pro` pass the
|
|
197
|
+
* validator when no config exists. That was tolerable while a config shipped
|
|
198
|
+
* inside every repo (deleting one looked like opting out); once the machine-wide
|
|
199
|
+
* file is the single source of truth, "no config" becomes the normal state of a
|
|
200
|
+
* fresh machine or a bare CI runner — i.e. the bypass is the default path.
|
|
201
|
+
*
|
|
202
|
+
* The caller distinguishes two cases it already knows:
|
|
203
|
+
* - no project context at all (no root argument) -> unbound, #423 behaviour;
|
|
204
|
+
* - a real repo with evidence but no config anywhere -> refuse.
|
|
205
|
+
* This function therefore throws rather than returning null for the second
|
|
206
|
+
* case; `main()` only reaches it when a project root was named.
|
|
207
|
+
*
|
|
155
208
|
* @param {string} projectRoot repository root whose config binds the evidence
|
|
156
|
-
* @
|
|
209
|
+
* @param {NodeJS.ProcessEnv} env environment for the global-path lookup
|
|
210
|
+
* @returns {Map<string, string>} seats; never null
|
|
211
|
+
* @throws exits via fail() when neither location has a config
|
|
157
212
|
*/
|
|
158
|
-
function loadBindingSeats(projectRoot) {
|
|
159
|
-
const
|
|
213
|
+
function loadBindingSeats(projectRoot, env = process.env) {
|
|
214
|
+
const projectPath = path.join(projectRoot, DELPHI_CONFIG_FILE);
|
|
215
|
+
const fallbackPath = globalConfigPath(env);
|
|
216
|
+
|
|
160
217
|
let raw;
|
|
218
|
+
let source = projectPath;
|
|
219
|
+
let projectMissing = false;
|
|
161
220
|
try {
|
|
162
|
-
raw = fs.readFileSync(
|
|
163
|
-
} catch (
|
|
164
|
-
if (
|
|
165
|
-
|
|
221
|
+
raw = fs.readFileSync(projectPath, 'utf8');
|
|
222
|
+
} catch (projectError) {
|
|
223
|
+
if (projectError && projectError.code === 'ENOENT') {
|
|
224
|
+
projectMissing = true;
|
|
225
|
+
try {
|
|
226
|
+
raw = fs.readFileSync(fallbackPath, 'utf8');
|
|
227
|
+
source = fallbackPath;
|
|
228
|
+
} catch (globalError) {
|
|
229
|
+
if (globalError && globalError.code === 'ENOENT') {
|
|
230
|
+
// Both absent: this repo has walkthrough evidence but nothing binds
|
|
231
|
+
// it to seats. Fail closed and say exactly where we looked.
|
|
232
|
+
fail(
|
|
233
|
+
`no ${DELPHI_CONFIG_FILE} found, so the reviewer seats cannot be verified. `
|
|
234
|
+
+ `Looked in: ${projectPath}, ${fallbackPath}. `
|
|
235
|
+
+ `Create the machine-wide config or add one to the repository.`
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
fail(
|
|
239
|
+
`cannot read ${DELPHI_CONFIG_FILE}: ${globalError && globalError.message
|
|
240
|
+
? globalError.message
|
|
241
|
+
: String(globalError)}`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
fail(
|
|
246
|
+
`cannot read ${DELPHI_CONFIG_FILE}: ${projectError && projectError.message
|
|
247
|
+
? projectError.message
|
|
248
|
+
: String(projectError)}`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
166
251
|
}
|
|
167
252
|
let parsed;
|
|
168
253
|
try {
|
|
169
254
|
parsed = JSON.parse(raw);
|
|
170
255
|
} catch (error) {
|
|
171
|
-
fail(`${
|
|
256
|
+
fail(`${source} is not valid JSON: ${error.message}`);
|
|
172
257
|
}
|
|
173
258
|
const seats = resolveBindingSeats(parsed);
|
|
174
259
|
for (const role of REQUIRED_ROLES) {
|
|
@@ -176,9 +261,60 @@ function loadBindingSeats(projectRoot) {
|
|
|
176
261
|
fail(`${DELPHI_CONFIG_FILE} declares no seat for the ${role} role; all three roles must be configured.`);
|
|
177
262
|
}
|
|
178
263
|
}
|
|
264
|
+
// A repo-local copy that disagrees with the machine-wide one is exactly how
|
|
265
|
+
// the 2026-10-27 incident happened: a stale per-repo file silently won and the
|
|
266
|
+
// review kept using a seat that had been retired. Winning is still allowed
|
|
267
|
+
// (deliberate overrides exist), but it must never be silent.
|
|
268
|
+
if (!projectMissing) {
|
|
269
|
+
warnOnSeatDrift(projectPath, fallbackPath, seats);
|
|
270
|
+
}
|
|
179
271
|
return seats;
|
|
180
272
|
}
|
|
181
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Warn (never block) when a repository-local config disagrees with the
|
|
276
|
+
* machine-wide one.
|
|
277
|
+
*
|
|
278
|
+
* 2026-10-27 incident: the machine-wide config had been updated to replace a
|
|
279
|
+
* flaky seat, but an older copy survived in the repo root. The project file
|
|
280
|
+
* won, the review kept calling the retired seat, and nothing anywhere said so —
|
|
281
|
+
* the only symptom was intermittent HTTP 500s that looked like a gateway
|
|
282
|
+
* problem. Silence is what made it expensive.
|
|
283
|
+
*
|
|
284
|
+
* Deliberate per-repo overrides are legitimate, so this is a WARN on stderr and
|
|
285
|
+
* never changes the exit code. Absence of either file is not drift.
|
|
286
|
+
*
|
|
287
|
+
* @param {string} projectPath repository config path
|
|
288
|
+
* @param {string} fallbackPath machine-wide config path
|
|
289
|
+
* @param {Map<string, string>} projectSeats seats actually in effect
|
|
290
|
+
*/
|
|
291
|
+
function warnOnSeatDrift(projectPath, fallbackPath, projectSeats) {
|
|
292
|
+
let machineRaw;
|
|
293
|
+
try {
|
|
294
|
+
machineRaw = fs.readFileSync(fallbackPath, 'utf8');
|
|
295
|
+
} catch {
|
|
296
|
+
return; // no machine-wide config -> nothing to disagree with
|
|
297
|
+
}
|
|
298
|
+
let machineSeats;
|
|
299
|
+
try {
|
|
300
|
+
machineSeats = resolveBindingSeats(JSON.parse(machineRaw));
|
|
301
|
+
} catch {
|
|
302
|
+
return; // a malformed machine config is reported by its own path when used
|
|
303
|
+
}
|
|
304
|
+
const drift = REQUIRED_ROLES.filter(
|
|
305
|
+
(role) => machineSeats.has(role) && projectSeats.get(role) !== machineSeats.get(role)
|
|
306
|
+
);
|
|
307
|
+
if (drift.length === 0) return;
|
|
308
|
+
const detail = drift
|
|
309
|
+
.map((role) => `${role}: repo=${projectSeats.get(role)} machine=${machineSeats.get(role)}`)
|
|
310
|
+
.join('; ');
|
|
311
|
+
process.stderr.write(
|
|
312
|
+
`⚠️ ${DELPHI_CONFIG_FILE} in this repository overrides the machine-wide seats `
|
|
313
|
+
+ `(${detail}). The repository copy wins. If the machine-wide config was updated `
|
|
314
|
+
+ `to retire a seat, this repo is still calling the old one.\n`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
182
318
|
/**
|
|
183
319
|
* Validate an expert's identity fields: shape, role, approval status, and
|
|
184
320
|
* channel provenance. Split out of `validateExpert`, which exceeded the
|
|
@@ -284,10 +420,24 @@ function validateExpert(expert, index, roles, models, resolvedModels, bindingSea
|
|
|
284
420
|
|
|
285
421
|
function validateEvidence(evidence, expectedCommit, expectedBranch, now, bindingSeats) {
|
|
286
422
|
if (!isPlainObject(evidence)) fail('top level must be a plain object.');
|
|
423
|
+
validateEvidenceIdentity(evidence, expectedCommit, expectedBranch);
|
|
424
|
+
validateEvidenceTimestamps(evidence, now);
|
|
425
|
+
validateConsensusRatio(evidence.consensus_ratio);
|
|
426
|
+
validateExperts(evidence.experts, bindingSeats);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** The document must describe this exact push, and must approve it. */
|
|
430
|
+
function validateEvidenceIdentity(evidence, expectedCommit, expectedBranch) {
|
|
287
431
|
if (evidence.commit !== expectedCommit) fail('commit does not match HEAD.');
|
|
288
432
|
if (evidence.branch !== expectedBranch) fail('branch does not match the current branch.');
|
|
289
433
|
if (evidence.verdict !== 'APPROVED') fail('top-level verdict must be APPROVED.');
|
|
434
|
+
}
|
|
290
435
|
|
|
436
|
+
/**
|
|
437
|
+
* The evidence must be recent and self-consistent: not from the future, not
|
|
438
|
+
* expired, and valid for exactly one hour from its own timestamp.
|
|
439
|
+
*/
|
|
440
|
+
function validateEvidenceTimestamps(evidence, now) {
|
|
291
441
|
const timestamp = parseTimestamp(evidence.timestamp, 'timestamp');
|
|
292
442
|
const expires = parseTimestamp(evidence.expires, 'expires');
|
|
293
443
|
if (timestamp > now) fail('timestamp is in the future.');
|
|
@@ -295,15 +445,22 @@ function validateEvidence(evidence, expectedCommit, expectedBranch, now, binding
|
|
|
295
445
|
if (expires - timestamp !== VALIDITY_MS) {
|
|
296
446
|
fail('expires must be exactly one hour after timestamp.');
|
|
297
447
|
}
|
|
448
|
+
}
|
|
298
449
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|| evidence.consensus_ratio > 1) {
|
|
450
|
+
/** The three experts must have agreed at 90% or better. */
|
|
451
|
+
function validateConsensusRatio(ratio) {
|
|
452
|
+
if (typeof ratio !== 'number' || !Number.isFinite(ratio) || ratio < 0.90 || ratio > 1) {
|
|
303
453
|
fail('consensus_ratio must be a finite number from 0.90 through 1.');
|
|
304
454
|
}
|
|
455
|
+
}
|
|
305
456
|
|
|
306
|
-
|
|
457
|
+
/**
|
|
458
|
+
* Validate each of the three expert records, then confirm every required role
|
|
459
|
+
* appeared. `roles` accumulates across the records, so it is checked once after
|
|
460
|
+
* the loop rather than per expert.
|
|
461
|
+
*/
|
|
462
|
+
function validateExperts(experts, bindingSeats) {
|
|
463
|
+
if (!Array.isArray(experts) || experts.length !== 3) {
|
|
307
464
|
fail('experts must contain exactly three records.');
|
|
308
465
|
}
|
|
309
466
|
const roles = new Set();
|
|
@@ -311,7 +468,7 @@ function validateEvidence(evidence, expectedCommit, expectedBranch, now, binding
|
|
|
311
468
|
// Scoped to this validation run, so one document's models cannot leak into the
|
|
312
469
|
// next (a long-lived process validating several pushes).
|
|
313
470
|
const resolvedModels = new Set();
|
|
314
|
-
|
|
471
|
+
experts.forEach((expert, index) => {
|
|
315
472
|
validateExpert(expert, index, roles, models, resolvedModels, bindingSeats);
|
|
316
473
|
});
|
|
317
474
|
if (roles.size !== REQUIRED_ROLES.length) fail('all required expert roles must be present.');
|