Files
rea/tests/evaluation/packetWorkflowSemantics.test.ts
T
ca7450beff test(perf): evaluate larger and non-HTTP packet workflows (#3232)
Add reproducible larger/non-HTTP packet cost measurements, an independent header oracle, exact page validation and separate factual/plan grading. Document caller-selected controls and retain negative/mixed model results. Production defaults and APIs remain unchanged.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
2026-10-14 16:18:22 +08:00

33 lines
1.7 KiB
TypeScript

import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { test } from "vitest";
test("packet page verification rejects skipped matches with unchanged counts and monotone frames", () => {
const moduleUrl = new URL(
"../../experiments/analysis-efficiency/packet-entry.mjs",
import.meta.url,
).href;
const source = `
import assert from 'node:assert/strict';
import {verifyPacketPage} from ${JSON.stringify(moduleUrl)};
const rows = Array.from({length:36}, (_,i)=>({frame:i+1, source_port:1000,destination_port:5432,flags:16}));
const sha256 = 'a'.repeat(64);
const report = (selected)=>({artifact:{sha256},output_window:{matching_packets:36},packets:selected.map(row=>({
'frame.number':[String(row.frame)],'tcp.srcport':['1000'],'tcp.dstport':['5432'],'tcp.flags':['0x0010']
}))});
const oracle={sha256,matching_packets:36,rows:rows.slice(0,24)};
const first=report(rows.slice(0,12));
verifyPacketPage(first,report(rows.slice(12,24)),oracle);
assert.throws(()=>verifyPacketPage(first,report(rows.slice(24,36)),oracle),/independently parsed/);
assert.throws(()=>verifyPacketPage(first,report(rows.slice(12,24).reverse()),oracle),/independently parsed/);
assert.throws(()=>verifyPacketPage(first,{...report(rows.slice(12,24)),artifact:{sha256:'b'.repeat(64)}},oracle),/independently parsed/);
`;
// Semantic checker only; synthetic rows do not establish provider behavior.
const result = spawnSync(process.execPath, ["--input-type=module", "-"], {
input: source,
encoding: "utf8",
});
assert.ifError(result.error);
assert.equal(result.status, 0, result.stderr);
});