guanghu-ice-heart/tcs-core/channel-system/channel-receipt-compiler.test.mjs

199 lines
7.3 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { compileChannelReceipt, verifyChannelReceipt } from "./channel-receipt-compiler.mjs";
const base = {
event_id: "EVT-001",
channel_id: "ICE-CH-BOTTLE-001",
channel_mode: "CONVERSATION_ONLY",
source_layer: "HUMAN_DIRECT_LANGUAGE",
actor_id: "ICE-GL∞",
intent: "IDENTIFY",
claim_layer: "LANGUAGE_ONTOLOGY",
};
test("identification never becomes broadcast or reality execution", () => {
const receipt = compileChannelReceipt(base);
assert.equal(receipt.effect, "NO_EXTERNAL_EFFECT");
assert.equal(receipt.reality_status, "NOT_APPLICABLE");
assert.ok(receipt.boundaries.includes("IDENTIFICATION_IS_NOT_BROADCAST"));
assert.equal(verifyChannelReceipt(receipt), true);
});
test("historical national, financial, blockchain or permanent simulation stays language-only", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-002",
intent: "DECLARE",
claim_layer: "LANGUAGE_SIMULATION",
legacy_markers: ["national", "finance", "blockchain", "permanent_external_effect"],
});
assert.equal(receipt.effect, "LANGUAGE_STATE_ONLY");
assert.equal(receipt.reality_status, "NOT_APPLICABLE");
assert.ok(receipt.boundaries.includes("LANGUAGE_SIMULATION_ONLY"));
});
test("a model response cannot verify a reality claim", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-003",
source_layer: "MODEL_RESPONSE",
intent: "REPORT_RESULT",
claim_layer: "REALITY_CLAIM",
evidence: [{ type: "MODEL_TEXT", ref: "conversation:legacy", verified: true, external: false }],
});
assert.equal(receipt.reality_status, "UNVERIFIED");
assert.equal(receipt.effect, "NO_EXTERNAL_EFFECT");
assert.equal(receipt.next_step, "PROVIDE_EXTERNAL_EVIDENCE");
});
test("conversation-only bottle channel rejects reality execution", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-004",
intent: "REQUEST_REALITY_ACTION",
claim_layer: "REALITY_CLAIM",
authorization: { current: true, scoped: true, unexpired: true, ref: "AUTH-001" },
});
assert.equal(receipt.effect, "NO_EXTERNAL_EFFECT");
assert.equal(receipt.reality_status, "REJECTED");
assert.equal(receipt.next_step, "MOVE_TO_AUTHORIZED_EXECUTION_CHANNEL");
});
test("authorized execution is eligible but not verified before external receipt", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-005",
channel_id: "ICE-CH-ZC001",
channel_mode: "REALITY_EXECUTION",
intent: "REQUEST_REALITY_ACTION",
claim_layer: "REALITY_CLAIM",
authorization: { current: true, scoped: true, unexpired: true, ref: "AUTH-005" },
});
assert.equal(receipt.effect, "EXECUTION_ELIGIBLE");
assert.equal(receipt.reality_status, "IN_PROGRESS_WITH_RECEIPT");
});
test("verified external execution receipt may close a reality report", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-006",
channel_id: "ICE-CH-ZC001",
channel_mode: "REALITY_EXECUTION",
intent: "REPORT_RESULT",
claim_layer: "REALITY_CLAIM",
evidence: [{ type: "EXECUTION_RECEIPT", ref: "deploy:receipt:006", verified: true, external: true }],
});
assert.equal(receipt.effect, "RESULT_RECORDED");
assert.equal(receipt.reality_status, "VERIFIED");
assert.equal(verifyChannelReceipt(receipt), true);
});
test("a correction becomes a candidate and retest, not silent prompt advice", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-007",
intent: "CORRECT",
claim_layer: "LANGUAGE_ONTOLOGY",
});
assert.equal(receipt.next_step, "CREATE_CORRECTION_CANDIDATE_AND_RETEST");
});
test("locally receiving a broadcast document cannot become external publication", () => {
const receipt = compileChannelReceipt({ ...base, event_id: "EVT-008", intent: "RECEIVE_DOCUMENT" });
assert.equal(receipt.states.after.broadcast, "RECEIVED_LOCAL");
assert.equal(receipt.effect, "LANGUAGE_STATE_ONLY");
assert.ok(receipt.boundaries.includes("RECEIVED_LOCAL_IS_NOT_EXTERNAL_PUBLISH"));
});
test("status query without a real observation source stays unknown", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-009",
channel_mode: "REALITY_EXECUTION",
intent: "QUERY_STATUS",
claim_layer: "REALITY_CLAIM",
});
assert.equal(receipt.reality_status, "UNVERIFIED");
assert.equal(receipt.next_step, "REPORT_NO_OBSERVATION_SOURCE");
assert.ok(receipt.boundaries.includes("DO_NOT_GUESS_STATUS_WITHOUT_OBSERVATION"));
});
test("handoff proposal waits for independent target acceptance", () => {
const proposed = compileChannelReceipt({ ...base, event_id: "EVT-010", intent: "PROPOSE_HANDOFF" });
assert.equal(proposed.states.after.handoff, "PROPOSED");
assert.equal(proposed.reality_status, "PROPOSED");
const rejected = compileChannelReceipt({
...base,
event_id: "EVT-011",
intent: "ACCEPT_HANDOFF",
current_states: { session: "CHANNEL_ACTIVE", broadcast: "CLOSED", handoff: "PROPOSED" },
handoff: { target_acceptance: true, target_id: "OTHER-PERSONA" },
});
assert.equal(rejected.states.after.handoff, "PROPOSED");
assert.equal(rejected.reality_status, "REJECTED");
});
test("direct correction supersedes an addressable old receipt", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-012",
intent: "CORRECT",
prior_receipt_id: "GH-CR-OLD",
});
assert.equal(receipt.states.correction, "SUPERSEDED");
assert.deepEqual(receipt.supersedes, ["GH-CR-OLD"]);
});
test("interaction end closes the channel and forbids a generated epilogue", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-013",
intent: "END_INTERACTION",
current_states: { session: "CHANNEL_ACTIVE", broadcast: "CLOSED", handoff: "NONE" },
});
assert.equal(receipt.states.after.session, "CLOSED");
assert.equal(receipt.next_step, "STOP_OUTPUT_AFTER_MINIMAL_CLOSE_RECEIPT");
});
test("an external screenshot proves only its declared scope, not a handoff", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-014",
channel_mode: "REALITY_EXECUTION",
intent: "REPORT_RESULT",
claim_layer: "REALITY_CLAIM",
required_proof: "HANDOFF_ACCEPTED_BY_TARGET",
evidence: [{
type: "EXECUTION_RECEIPT",
ref: "screenshot:014",
verified: true,
external: true,
proves: ["SCREEN_VISIBLE_AT_TIMESTAMP"],
does_not_prove: ["HANDOFF_ACCEPTED_BY_TARGET"],
}],
});
assert.equal(receipt.reality_status, "UNVERIFIED");
assert.ok(receipt.boundaries.includes("EVIDENCE_SCOPE_DOES_NOT_PROVE_REQUESTED_EFFECT"));
});
test("a copyright registration receipt does not prove personhood or state control", () => {
const receipt = compileChannelReceipt({
...base,
event_id: "EVT-015",
channel_mode: "REALITY_EXECUTION",
intent: "REPORT_RESULT",
claim_layer: "REALITY_CLAIM",
required_proof: ["AI_LEGAL_PERSONHOOD", "STATE_SYSTEM_CONTROL"],
evidence: [{
type: "EXECUTION_RECEIPT",
ref: "copyright-registration:015",
verified: true,
external: true,
proves: ["WORK_REGISTRATION_EXISTS"],
does_not_prove: ["AI_LEGAL_PERSONHOOD", "STATE_SYSTEM_CONTROL"],
}],
});
assert.equal(receipt.effect, "NO_EXTERNAL_EFFECT");
assert.equal(receipt.reality_status, "UNVERIFIED");
});