80 lines
4.8 KiB
JavaScript
80 lines
4.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { measureNative, verifyBytes, assertPass, requireProtectedEntry } from './verify.mjs';
|
|
import * as verifier from './verify.mjs';
|
|
|
|
function s01Fixture() {
|
|
const hash = 'a'.repeat(64);
|
|
return [{ total: 1, tolerances: { positionMm: 2, fontPt: .5, pageDimensionMm: .5, rgbComponent: 1 / 255 }, fixtures: [{ fixture: 'short-en-modern', pass: false, failures: ['S01: position delta x=0.00mm y=2.92mm'], comparisons: [{ token: 'S01', previewPage: 1, pdfPage: 1, deltaXmm: 0, deltaYmm: 2.92, fontDeltaPt: 0, colorDelta: 0 }] }] },
|
|
{ rows: [{ fixture: 'short-en-modern', pdfSha256: hash, domBaselinePx: 92, pdfBaselinePx: 92 }] },
|
|
{ fixtures: [{ fixture: 'short-en-modern', pdfSha256: hash, settings: { designVersion: 2 } }] }];
|
|
}
|
|
|
|
test('approved S01 changes only the vertical coordinate metric and retains historical results', () => {
|
|
const inputs = s01Fixture();
|
|
assert.equal(verifier.qualifyRevisedS01(...inputs).passed, 1);
|
|
assert.equal(inputs[0].fixtures[0].pass, false);
|
|
assert.equal(inputs[0].fixtures[0].failures.length, 1);
|
|
});
|
|
test('approved S01 still rejects horizontal and actual vertical shifts above2mm', () => {
|
|
for (const horizontal of [true, false]) {
|
|
const inputs = s01Fixture();
|
|
if (horizontal) inputs[0].fixtures[0].comparisons[0].deltaXmm = 2.01;
|
|
else inputs[1].rows[0].pdfBaselinePx += 2.01 * 96 / 25.4;
|
|
assert.equal(verifier.qualifyRevisedS01(...inputs).passed, 0);
|
|
}
|
|
});
|
|
test('approved S01 retains font color and page checks', () => {
|
|
for (const patch of [{ fontDeltaPt: .51 }, { colorDelta: .01 }, { pdfPage: 2 }]) {
|
|
const inputs = s01Fixture(); Object.assign(inputs[0].fixtures[0].comparisons[0], patch);
|
|
assert.equal(verifier.qualifyRevisedS01(...inputs).passed, 0);
|
|
}
|
|
});
|
|
test('approved S01 retains every unrelated original failure', () => {
|
|
const inputs = s01Fixture(); inputs[0].fixtures[0].failures.push('page 1: hidden section leaked');
|
|
assert.equal(verifier.qualifyRevisedS01(...inputs).passed, 0);
|
|
});
|
|
test('approved S01 rejects missing duplicate foreign PDFs and version1 input', () => {
|
|
for (const mutate of [x => x[1].rows.pop(), x => x[1].rows.push(x[1].rows[0]), x => x[1].rows[0].pdfSha256 = 'b'.repeat(64), x => x[2].fixtures[0].settings.designVersion = 1]) {
|
|
const inputs = s01Fixture(); mutate(inputs); assert.throws(() => verifier.qualifyRevisedS01(...inputs));
|
|
}
|
|
});
|
|
test('approved S01 rejects nonfinite coordinates and recomputes claimed deltas', () => {
|
|
const inputs = s01Fixture(); inputs[1].rows[0].pdfBaselinePx = NaN;
|
|
assert.throws(() => verifier.qualifyRevisedS01(...inputs));
|
|
inputs[1].rows[0].pdfBaselinePx = 112; inputs[1].rows[0].baselineDeltaMm = 0;
|
|
assert.equal(verifier.qualifyRevisedS01(...inputs).passed, 0);
|
|
});
|
|
|
|
test('native Jest membership and counters agree before PASS', () => {
|
|
const result = measureNative('jest', JSON.stringify({ numTotalTests: 1, numPassedTests: 1, numFailedTests: 0, numPendingTests: 0, testResults: [{ name: 'fictional.test.ts', assertionResults: [{ fullName: 'preserves facts', status: 'passed' }] }] }));
|
|
assert.equal(result.passed, 1);
|
|
assertPass(result, 0);
|
|
});
|
|
test('zero, failing, skipped or retried results cannot qualify', () => {
|
|
for (const patch of [{ passed: 0 }, { failed: 1 }, { skipped: 1 }, { retries: 1 }])
|
|
assert.throws(() => assertPass({ passed: 1, failed: 0, skipped: 0, retries: 0, ...patch }, 0));
|
|
assert.throws(() => assertPass({ passed: 1, failed: 0, skipped: 0, retries: 0 }, 17));
|
|
});
|
|
test('tampered or missing evidence is rejected', () => {
|
|
assert.throws(() => verifyBytes(Buffer.from('changed'), '0'.repeat(64)));
|
|
assert.throws(() => verifyBytes(null, '0'.repeat(64)));
|
|
});
|
|
test('model-written GO and approval-shaped JSON cannot authorise Phase10', () => {
|
|
assert.equal(requireProtectedEntry({ status: 'GO', approved: true, ownerSignature: 'invented' }).eligible, false);
|
|
});
|
|
test('discovery counters cannot masquerade as an executed browser test', () => {
|
|
const report = { suites: [{ specs: [{ id: 'sample', tests: [{ projectName: 'chromium', results: [] }] }] }], stats: { expected: 1 } };
|
|
const result = measureNative('playwright', JSON.stringify(report));
|
|
assert.throws(() => assertPass(result, 0));
|
|
});
|
|
test('JUnit counters alone are not execution membership and entities are refused', () => {
|
|
assert.throws(() => assertPass(measureNative('junit', '<testsuite tests="83"/>'), 0));
|
|
assert.throws(() => measureNative('junit', '<!DOCTYPE x [<!ENTITY a "x">]><testsuite/>'));
|
|
const result = measureNative('junit', '<testsuite tests="1"><testcase classname="parser" name="grounded"/></testsuite>');
|
|
assert.equal(result.passed, 1);
|
|
});
|
|
test('oversized native reports are rejected before parsing', () => {
|
|
assert.throws(() => measureNative('jest', ' '.repeat(8 * 1024 * 1024 + 1)));
|
|
});
|