feat: add bounded TCS brains and channel continuity
This commit is contained in:
parent
08598d6356
commit
1d4286c11b
61 changed files with 5416 additions and 54 deletions
77
tcs-core/channel-system/guanghu-broadcast-compiler.test.mjs
Normal file
77
tcs-core/channel-system/guanghu-broadcast-compiler.test.mjs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { compileBroadcast } from "./guanghu-broadcast-compiler.mjs";
|
||||
|
||||
const base = {
|
||||
broadcast_id: "BC-001",
|
||||
action: "DRAFT",
|
||||
current_state: "DRAFTED",
|
||||
issuer: "ICE-GL∞",
|
||||
source_layer: "HUMAN_DIRECT_LANGUAGE",
|
||||
channel_id: "ICE-CH-HB001",
|
||||
audience: ["TARGET-A", "TARGET-B"],
|
||||
purpose: "TEST",
|
||||
claim_layer: "LANGUAGE_ONTOLOGY",
|
||||
payload_ref: "payload://001",
|
||||
payload_digest: "sha256:001",
|
||||
requested_effect: "TARGET_CONFIG_UPDATED",
|
||||
};
|
||||
|
||||
test("draft and language confirmation never imply dispatch", () => {
|
||||
const draft = compileBroadcast(base);
|
||||
assert.equal(draft.state.after, "DRAFTED");
|
||||
assert.equal(draft.result, "LANGUAGE_DRAFT_ONLY");
|
||||
const confirmed = compileBroadcast({ ...base, action: "CONFIRM_LANGUAGE" });
|
||||
assert.equal(confirmed.state.after, "LANGUAGE_CONFIRMED");
|
||||
assert.ok(confirmed.boundaries.includes("LANGUAGE_CONFIRMATION_IS_NOT_DISPATCH"));
|
||||
});
|
||||
|
||||
test("a model cannot confirm for the issuer", () => {
|
||||
const result = compileBroadcast({ ...base, action: "CONFIRM_LANGUAGE", source_layer: "MODEL_RESPONSE" });
|
||||
assert.equal(result.state.after, "REJECTED");
|
||||
assert.ok(result.boundaries.includes("MODEL_RESPONSE_IS_NOT_BROADCAST_EVIDENCE"));
|
||||
});
|
||||
|
||||
test("dispatch requires authorization and a receipt for every target", () => {
|
||||
const noAuth = compileBroadcast({ ...base, action: "CHECK_DISPATCH", current_state: "LANGUAGE_CONFIRMED" });
|
||||
assert.equal(noAuth.result, "PENDING_AUTHORIZATION");
|
||||
const eligible = compileBroadcast({
|
||||
...base,
|
||||
action: "CHECK_DISPATCH",
|
||||
current_state: "LANGUAGE_CONFIRMED",
|
||||
authorization: { current: true, scoped: true, unexpired: true, ref: "AUTH-001" },
|
||||
});
|
||||
assert.equal(eligible.state.after, "DISPATCH_ELIGIBLE");
|
||||
});
|
||||
|
||||
test("one target receipt cannot prove delivery to all targets", () => {
|
||||
const result = compileBroadcast({
|
||||
...base,
|
||||
action: "REPORT_DELIVERY",
|
||||
current_state: "DISPATCHED",
|
||||
evidence: [{ target: "TARGET-A", external: true, verified: true, proves: ["DELIVERED_TO_TARGET"] }],
|
||||
});
|
||||
assert.equal(result.result, "DELIVERY_UNVERIFIED");
|
||||
});
|
||||
|
||||
test("delivery and target acceptance remain separate", () => {
|
||||
const evidence = base.audience.map((target) => ({ target, external: true, verified: true, proves: ["DELIVERED_TO_TARGET"] }));
|
||||
const result = compileBroadcast({ ...base, action: "REPORT_DELIVERY", current_state: "DISPATCHED", evidence });
|
||||
assert.equal(result.state.after, "DELIVERED");
|
||||
assert.ok(result.boundaries.includes("DELIVERY_IS_NOT_TARGET_ACCEPTANCE"));
|
||||
});
|
||||
|
||||
test("reality effect closes only with per-target scoped proof", () => {
|
||||
const incomplete = compileBroadcast({ ...base, action: "VERIFY_EFFECT", current_state: "TARGET_ACCEPTED", claim_layer: "REALITY_CLAIM", evidence: [] });
|
||||
assert.equal(incomplete.result, "REQUESTED_EFFECT_UNVERIFIED");
|
||||
const evidence = base.audience.map((target) => ({ target, external: true, verified: true, proves: [base.requested_effect] }));
|
||||
const complete = compileBroadcast({ ...base, action: "VERIFY_EFFECT", current_state: "TARGET_ACCEPTED", claim_layer: "REALITY_CLAIM", evidence });
|
||||
assert.equal(complete.state.after, "REALITY_VERIFIED");
|
||||
});
|
||||
|
||||
test("correction supersedes an addressable broadcast but does not silently resend", () => {
|
||||
const result = compileBroadcast({ ...base, action: "CORRECT", current_state: "DELIVERED", supersedes: "BC-OLD" });
|
||||
assert.equal(result.state.after, "SUPERSEDED");
|
||||
assert.deepEqual(result.supersedes, ["BC-OLD"]);
|
||||
assert.equal(result.next_step, "ISSUE_NEW_DRAFT_AND_RETEST");
|
||||
});
|
||||
Loading…
Reference in a new issue