merge: t2db.40 sources and signing into pg/foundation

Resolves against t2db.36: captures carry both event_type and unsigned (proto field 10), the State Store serves sources and event types from the Postgres EDA store, the capture row shows event type and signature together, and the staterpc sentinels map both ways from one table.
This commit is contained in:
sam committed 2026-09-24 14:38:40 +10:00
commit 8a2b5b95f9
63 files changed
+3839 -1753

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
import assert from "node:assert/strict";
import test from "node:test";
import { bindingPayload, emptyDraft } from "../src/bindings/binding-draft.ts";
import { captureSignature } from "../src/captures/capture-signature.ts";
import { signingKind, signingLabel, sourceURL } from "../src/sources/source-signing.ts";
import { describeTimelineEvent } from "../src/tasks/timeline-event.ts";
test("a capture shows how it may dispatch", () => {
const cases: Array<[{ authenticated?: boolean; unsigned?: boolean }, string, string]> = [
[{ authenticated: true }, "Signed", "ok"],
[{ unsigned: true }, "Unsigned", "warn"],
[{}, "Unverified", "idle"],
[{ authenticated: false, unsigned: false }, "Unverified", "idle"],
];
for (const [capture, label, kind] of cases) {
assert.deepEqual(captureSignature(capture), { label, kind }, JSON.stringify(capture));
}
});
test("a source's signing state names itself and its tone", () => {
const cases: Array<[string | undefined, string, string]> = [
["signed", "signed", "ok"],
["unsigned_pending_approval", "unsigned pending approval", "info"],
["unsigned", "unsigned", "warn"],
["something_new", "something_new", "idle"],
[undefined, "unknown", "idle"],
];
for (const [signing, label, kind] of cases) {
assert.equal(signingLabel(signing), label, String(signing));
assert.equal(signingKind(signing), kind, String(signing));
}
});
test("a source's URL escapes nothing a valid path can hold", () => {
assert.equal(
sourceURL("https://archie.example", "0199a0b2-0000-7000-8000-000000000000"),
"https://archie.example/webhooks/capture/0199a0b2-0000-7000-8000-000000000000",
);
assert.equal(sourceURL("http://h", "a b"), "http://h/webhooks/capture/a%20b");
});
test("a task started by an unsigned event says so on its timeline", () => {
const line = describeTimelineEvent({ kind: "unsigned_event", data: { source: "firewall" } });
assert.deepEqual(line, { title: "Started by an unsigned event", detail: "source firewall", tone: "warn" });
assert.equal(describeTimelineEvent({ kind: "stage_start", stage: "plan" }).tone, undefined);
});
test("a binding no longer carries a signing secret", () => {
const payload = bindingPayload(emptyDraft());
assert.equal("secret" in payload, false);
});