Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions npm/packages/kge/bench/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function parseArgs(argv) {
const a = {
suite: 'synthetic', scorer: 'hole', dims: 256, epochs: 50, seed: 42,
limit: undefined, ann: false, adversarial: false, tieCheck: false,
gate: false, reportOnly: false, out: undefined, baselineReceipt: undefined,
gate: false, reportOnly: false, requireEngine: false, out: undefined, baselineReceipt: undefined,
};
for (let i = 0; i < argv.length; i++) {
const t = argv[i];
Expand All @@ -58,11 +58,13 @@ export function parseArgs(argv) {
else if (t === '--adversarial') a.adversarial = true;
else if (t === '--tie-check') a.tieCheck = true;
else if (t === '--gate') a.gate = true;
else if (t === '--require-engine') a.requireEngine = true;
else if (t === '--report-only') a.reportOnly = true;
else if (t === '--out') a.out = next();
else if (t === '--baseline-receipt') a.baselineReceipt = next();
else throw new Error(`unknown flag: ${t}`);
}
if (a.requireEngine && !a.gate) throw new Error('--require-engine requires --gate');
return a;
}

Expand Down Expand Up @@ -247,7 +249,8 @@ export async function main(argv, deps = {}) {
for (const suite of suites) {
const run = await runSuite(suite, args, deps);
if (run.skipped) {
results.push({ suite, skipped: run.skipped });
if (args.requireEngine) anyFail = true;
results.push({ suite, skipped: run.skipped, ...(args.requireEngine ? { required_engine_failed: true } : {}) });
console.log(`\n## ${suite}\nskipped: ${run.skipped}`);
continue;
}
Expand All @@ -265,6 +268,19 @@ export async function main(argv, deps = {}) {
latencyP95: run.predictLatency?.p95, backend: run.binding?.backend, limit: args.limit,
};
gateResult = evaluateGates(gateBag(run, baselineReceipt), ctx, loadGates());
// Opt-in availability gate only: does not authenticate bindings, prove
// successful training, require every quality arm, or establish transfer.
// Use --gate --require-engine in execution validation; --report-only
// still records failures without changing its historical zero exit.
if (args.requireEngine) {
gateResult.rows.unshift({
name: 'required_engine',
status: engineAvailable ? 'PASS' : 'FAIL',
detail: engineAvailable ? 'engine completed evaluation; provenance and training are separate checks' : 'required engine unavailable',
});
gateResult.anyFail ||= !engineAvailable;
gateResult.pass = !gateResult.anyFail;
}
if (gateResult.anyFail) anyFail = true;
}

Expand Down
33 changes: 33 additions & 0 deletions npm/packages/kge/test/bench.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,36 @@ test('check-security fails on a temp file using child_process', () => {
rmSync(root, { recursive: true, force: true });
}
});


test('--require-engine requires explicit --gate', async () => {
await assert.rejects(main(['--require-engine']), /requires --gate/);
});

test('--require-engine fails unavailable engine, preserving report-only compatibility', async () => {
const binding = { Model: class { constructor() { throw new Error('required backend missing'); } }, version: () => '0', backend: 'stub' };
for (const reportOnly of [false, true]) {
const dir = mkdtempSync(join(tmpdir(), 'kge-required-'));
try {
const args = ['--suite', 'synthetic', '--gate', '--require-engine', '--out', join(dir, 'receipt.json')];
if (reportOnly) args.push('--report-only');
const { code, receipt } = await main(args, { binding });
assert.equal(code, reportOnly ? 0 : 1);
assert.equal(receipt.gates.pass, false);
assert.equal(receipt.gates.anyFail, true);
assert.equal(receipt.gates.rows.find(r => r.name === 'required_engine').status, 'FAIL');
} finally { rmSync(dir, { recursive: true, force: true }); }
}
});

test('--require-engine accepts available engine without claiming binding provenance', async () => {
const dir = mkdtempSync(join(tmpdir(), 'kge-required-'));
try {
const { code, receipt } = await main(
['--suite', 'synthetic', '--epochs', '1', '--gate', '--require-engine', '--out', join(dir, 'receipt.json')],
{ binding: FAKE });
assert.equal(code, 0);
assert.equal(receipt.gates.rows.find(r => r.name === 'required_engine').status, 'PASS');
assert.equal(receipt.binding.backend, 'fake');
} finally { rmSync(dir, { recursive: true, force: true }); }
});
Loading