fix(conformance): validate paired fixture count expectations (#14125)

* fix(conformance): refuse a fixture that declares half of a count pair

A counted expectation is a pair: the prefix selects the records and the count is
what the verifier binds to the source. Admission accepted either half, and
verifyCount returned silently when one was missing, so a fixture could declare
the invariant and never have it checked while verify:fixtures still reported
the fixture as verified.

Require both members in parseConformanceFixtureManifest and treat a half pair
at verification time as a producer defect instead of skipping the count.

* fix(fixtures): validate counted expectation types

---------

Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
Dery Ferdika
2026-11-30 18:01:46 +08:00
committed by GitHub
co-authored by Vincent Koc
parent c73940aa72
commit 81384ecfdc
3 changed files with 132 additions and 5 deletions
+23
View File
@@ -31,6 +31,29 @@ export const parseConformanceFixtureManifest = (manifest) => {
)
)
throw new Error("Invalid conformance fixture string expectations");
// A counted expectation is a pair: the prefix selects the records and the
// count is what the verifier binds to the source. Admitting one without the
// other would let a fixture declare the invariant and never check it.
for (const [prefix, count] of [
["symbolPrefix", "symbolCount"],
["stringPrefix", "stringCount"],
]) {
const prefixValue = expectations[prefix];
const countValue = expectations[count];
if (prefixValue === undefined && countValue === undefined) continue;
if ((prefixValue === undefined) !== (countValue === undefined))
throw new Error(
`Conformance fixture declarations must carry ${prefix} and ${count} together`,
);
if (
typeof prefixValue !== "string" ||
!Number.isSafeInteger(countValue) ||
countValue < 0
)
throw new Error(
`Invalid conformance fixture ${prefix}/${count} expectation: prefix must be a string and count must be a nonnegative safe integer`,
);
}
}
return manifest;
};
+7 -1
View File
@@ -128,7 +128,13 @@ async function verifyFixture(fixture) {
}
function verifyCount(output, prefix, expected, fixture) {
if (prefix === undefined || expected === undefined) return;
// A fixture that declares neither member has no count to check; admission
// rejects a fixture that declares only one of the pair.
if (prefix === undefined && expected === undefined) return;
if (prefix === undefined || expected === undefined)
throw new Error(
`${fixture}: counted expectation requires a prefix and a count`,
);
const count = output.filter((record) => record.startsWith(prefix)).length;
if (count !== expected)
throw new Error(
@@ -5,7 +5,10 @@ import { fileURLToPath } from "node:url";
import { expect, it, onTestFinished } from "vitest";
import { splitNmSymbolRecords } from "../../../scripts/lib/conformance-fixtures.mjs";
import {
parseConformanceFixtureManifest,
splitNmSymbolRecords,
} from "../../../scripts/lib/conformance-fixtures.mjs";
import { createVerifierCommands } from "../../../scripts/lib/verify-commands.mjs";
import { awaitAcknowledgement } from "../../fixtures/lifecycleAcknowledgement.js";
import { runningTestDeadline } from "../../support/runningTestDeadline.js";
@@ -27,12 +30,99 @@ const ownedFixture = async (prefix: string) => {
return { commands, root };
};
for (const [prefix, count] of [
["symbolPrefix", "symbolCount"],
["stringPrefix", "stringCount"],
] as const) {
it.each([
{ name: "omitted", expectation: {}, valid: true },
{
name: "zero",
expectation: { [prefix]: "fixture_", [count]: 0 },
valid: true,
},
{
name: "positive",
expectation: { [prefix]: "fixture_", [count]: 3 },
valid: true,
},
{
name: "empty prefix",
expectation: { [prefix]: "", [count]: 0 },
valid: true,
},
{
name: "prefix only",
expectation: { [prefix]: "fixture_" },
valid: false,
},
{ name: "count only", expectation: { [count]: 0 }, valid: false },
{
name: "null prefix",
expectation: { [prefix]: null, [count]: 0 },
valid: false,
},
{
name: "numeric prefix",
expectation: { [prefix]: 1, [count]: 0 },
valid: false,
},
{
name: "array prefix",
expectation: { [prefix]: [], [count]: 0 },
valid: false,
},
{
name: "null count",
expectation: { [prefix]: "fixture_", [count]: null },
valid: false,
},
{
name: "negative count",
expectation: { [prefix]: "fixture_", [count]: -1 },
valid: false,
},
{
name: "fractional count",
expectation: { [prefix]: "fixture_", [count]: 0.5 },
valid: false,
},
{
name: "string count",
expectation: { [prefix]: "fixture_", [count]: "0" },
valid: false,
},
{
name: "nonfinite count",
expectation: { [prefix]: "fixture_", [count]: Infinity },
valid: false,
},
{
name: "unsafe count",
expectation: {
[prefix]: "fixture_",
[count]: Number.MAX_SAFE_INTEGER + 1,
},
valid: false,
},
])(`validates ${prefix}/${count}: $name`, ({ expectation, valid }) => {
const manifest = {
schemaVersion: 2,
platform: "linux",
fixtures: [{ expectations: expectation }],
};
if (valid) expect(parseConformanceFixtureManifest(manifest)).toBe(manifest);
else expect(() => parseConformanceFixtureManifest(manifest)).toThrow();
});
}
it.skipIf(process.platform !== "darwin" && process.platform !== "linux").each([
{ mode: "complete", marker: "REA_C_ENTRY" },
{ mode: "cancelled", marker: "REA_C_ENTRY" },
{ mode: "renamed", marker: "REA_C_ENTRY" },
{ mode: "wrong-prefix", marker: "REA_C_ENTRY" },
{ mode: "prefix-complete", marker: "REA_C_ENTRY" },
{ mode: "half-count", marker: "REA_C_ENTRY" },
{ mode: "marker", marker: "REA_C_ENTRY" },
{ mode: "fragment", marker: "performAction:error:" },
])(
@@ -77,8 +167,14 @@ it.skipIf(process.platform !== "darwin" && process.platform !== "linux").each([
...(mode === "fragment"
? { stringFragments: [marker] }
: { stringMarkers: [marker] }),
...(mode === "wrong-prefix" || mode === "prefix-complete"
? { symbolPrefix: `${prefix}rea_inventory_`, symbolCount: 1 }
...(mode === "wrong-prefix" ||
mode === "prefix-complete" ||
mode === "half-count"
? {
symbolPrefix: `${prefix}rea_inventory_`,
// A half-declared pair must be refused before verification.
...(mode === "half-count" ? {} : { symbolCount: 1 }),
}
: {}),
},
});
@@ -149,7 +245,9 @@ setTimeout(() => {}, 15_000);
? `missing symbol ${prefix}rea_version_entry`
: mode === "wrong-prefix"
? `expected 1 ${prefix}rea_inventory_ records, received 0`
: `missing string marker ${marker}`,
: mode === "half-count"
? "must carry symbolPrefix and symbolCount together"
: `missing string marker ${marker}`,
),
},
},