nftables: test that a start waits for the watch's expiry; refuse a stale node-engine package

Review round 2 (1): the start's wait for the expiries the watch handed over
had no test that failed without it; the start test gains a store whose
deletes wait, and without the wait the key is said expired twice. The note:
a node-engine package naming no verb converged refuses the start loudly
instead of asking seat:node-engine.undefined.

Builds: design 33 control-verbs §10, §11, §14; design 47 H H-A-312
This commit is contained in:
2026-11-21 22:05:47 +01:00
parent f589b5af5c
commit 31abcad907
2 changed files with 27 additions and 3 deletions
+22 -3
View File
@@ -15,7 +15,8 @@ const TABLE = 'table inet mesh {\n\tchain input {\n\t\ttype filter hook input pr
'\t\tip saddr { 10.77.0.1, 10.77.0.2 } tcp dport 5432 accept\n\t\tip6 saddr { fd77::1 } tcp dport 5432 accept\n' +
'\t\ttcp dport 80 accept\n\t\tip saddr { 10.77.0.1 } tcp dport { 8443, 9500-9600 } accept\n\t\ttcp dport 8443 accept\n\t}\n}\n';
function fake(at = "2026-11-21T20:00:00Z", node = "shanks", kept = new Map<string, Value>()) {
// gate, when given, holds every delete until it opens, and every get waits a turn of the event loop: a slow store.
function fake(at = "2026-11-21T20:00:00Z", node = "shanks", kept = new Map<string, Value>(), gate?: Promise<void>) {
const said: Changed[] = [];
const journal: string[] = [];
const timers: Timer[] = [];
@@ -26,9 +27,12 @@ function fake(at = "2026-11-21T20:00:00Z", node = "shanks", kept = new Map<strin
return () => { t.cancelled = true; };
};
const store: Store = {
get: async (k) => (kept.has(k) ? { value: kept.get(k)! } : null),
get: async (k) => {
if (gate) await new Promise((r) => setImmediate(r));
return kept.has(k) ? { value: kept.get(k)! } : null;
},
put: async (k, v) => { kept.set(k, v); return kept.size; },
delete: async (k) => { kept.delete(k); },
delete: async (k) => { await gate; kept.delete(k); },
keys: async () => [...kept.keys()],
};
const acts: HandAct[] = [];
@@ -278,6 +282,21 @@ test("at a start every expired allowance is removed before started is said (H-A-
assert.deepEqual([...kept.keys()], [k("allow.tcp.9000")]);
assert.deepEqual(said.slice(-2).map((b) => [b.change, b.allowances.map((x) => x.key)]),
[["expired", ["allow.tcp.8000"]], ["started", ["allow.tcp.9000"]]]);
// §11, §14: a key past its until that the watch hands over while the start runs, through a store whose get and delete
// wait: the start waits for that expiry, so it is removed and said once, and started after it.
let open!: () => void;
const waits = new Promise<void>((r) => { open = r; });
const slow = fake("2026-11-21T22:00:00Z", "shanks", new Map(), waits);
const past: Value = { port: 7000, protocol: "tcp", why: "w", by: "x", at: "2026-11-21T20:00:00Z", until: "2026-11-21T21:00:00Z" };
slow.kept.set(k("allow.tcp.7000"), past);
await slow.a.watched({ key: k("allow.tcp.7000"), op: "put", value: past });
const start = slow.a.started();
for (let i = 0; i < 10; i++) await settle(); // the start runs as far as it goes while the expiry's delete waits
open();
await start;
assert.deepEqual(slow.said.map((b) => [b.change, b.allowances.map((x) => x.key)]),
[["expired", ["allow.tcp.7000"]], ["started", []]]);
});
test("started is said before the first allowed: the verbs are held until the start ends, a failed start refuses them", async () => {
+5
View File
@@ -146,6 +146,11 @@ const allowances = new Allowances(store, node, (body) => seatPublish(allowancesC
meshTable: () => firewall.ruleset(),
});
const start = (async () => {
// A node-engine package older than the verb converged names none: refused here, loudly, never asked as
// seat:node-engine.undefined (H-A-312).
if (!nodeEngineVerbs.converged) {
throw new Error("the node-engine seat's package names no verb converged (a package older than design 33 control-verbs §10)");
}
await keeps([{ name: STATE }]);
await kept.watch(async (change) => {
if (change.op === "put") own.add(change.key);