mail-address-semantics/impl/js/test/statute-aware.test.mjs
tegwick a841ceec73 MAS-WP-0009 T01: independent JS implementation (impl/js), differential test, SCP-9
impl/js (Node, zero deps, written from the specs): parser, v0.2
statute-aware rules, signing, outside master. Passes addresses.json,
statute-aware.json and auth.json unchanged; its master passes the 11
slave-setup mode flows against the Python email side (ExternalMaster).
Differential testing vs mas_core found two unstated stand-in rules, now
SCP-9 in the v0.2 draft with fixtures si-011..013, dt-109; ABNF comments
no longer say v0.1. Runner: external masters, step errors fail the flow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 5787@bnt-lap001
Assistant-Session: 5db26b82-138b-40cc-9856-4d5eb0f752fd
2026-10-19 13:22:22 +02:00

30 lines
1.3 KiB
JavaScript

// mas-v0.2-spec/conformance/statute-aware.json, consumed unchanged (CONFORMANCE.md section 5).
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { Statute, interpret, equivalent, forDestination, CannotExpress } from "../src/statute.mjs";
const BUNDLE = new URL("../../../mas-v0.2-spec/", import.meta.url);
const fx = JSON.parse(readFileSync(new URL("conformance/statute-aware.json", BUNDLE)));
const statutes = Object.fromEntries(Object.entries(fx.statutes).map(([k, d]) => [k, new Statute(d)]));
for (const c of fx.interpretation) {
test(`${c.id} interpret ${c.local_part}`, () => {
const r = interpret(c.local_part, statutes[c.statute]);
assert.deepEqual([r.canonical, r.stand_ins], [c.canonical, c.stand_ins]);
});
}
for (const c of fx.equivalence) {
test(`${c.id} ${c.a} ~ ${c.b}`, () => {
assert.equal(equivalent(c.a, c.b, statutes[c.statute]), c.equivalent);
});
}
for (const c of fx.destination) {
test(`${c.id} ${c.local_part} for [${c.needs}]`, () => {
const run = () => forDestination(c.local_part, statutes[c.statute], c.needs, { allowLossy: c.allow_lossy ?? false });
if (c.expect === null) assert.throws(run, CannotExpress, c.reason);
else assert.equal(run(), c.expect);
});
}