Files
pikasTech-HWLAB/web/hwlab-cloud-web/wiring-status.test.mjs
T
2026-05-23 10:38:50 +00:00

82 lines
3.1 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import {
trustedM3StatusEvidenceFrom,
wiringPresentationFromSummary
} from "./wiring-status.mjs";
const trustedGreenStatus = Object.freeze({
contractVersion: "m3-status-v1",
status: "live",
sourceKind: "DEV-LIVE",
patchPanel: {
serviceId: "hwlab-patch-panel",
connectionActive: true
},
trust: {
durableStatus: "green",
blocker: null,
operationId: "op_m3_di_read_75fc664f-e94f-41e8-816e-aff9fdb3666f",
traceId: "trc_hotfix_307_verify_1779527747043_read_false",
auditId: "aud_m3_di_read_d5afd84b-3a9d-475f-894f-dff8ea5f49ff_succeeded",
evidenceId: "evd_m3_di_read_75fc664f-e94f-41e8-816e-aff9fdb3666f_succeeded"
}
});
test("m3-status-v1 trusted green renders verified wiring and preserves operation trace audit evidence IDs", () => {
const presentation = wiringPresentationFromSummary(trustedGreenStatus);
assert.equal(presentation.m3Live, true);
assert.equal(presentation.stateLabel, "实况已验证");
assert.equal(presentation.sourceLabel, "/v1/m3/status 聚合 / 实况可信记录");
assert.equal(presentation.rowSourceKind, "DEV-LIVE");
assert.equal(presentation.badgeTone, "dev-live");
assert.doesNotMatch(presentation.stateLabel, /持久化受阻/u);
assert.match(presentation.traceEvidence, /op_m3_di_read_75fc664f-e94f-41e8-816e-aff9fdb3666f/u);
assert.match(presentation.traceEvidence, /trc_hotfix_307_verify_1779527747043_read_false/u);
assert.match(presentation.traceEvidence, /aud_m3_di_read_d5afd84b-3a9d-475f-894f-dff8ea5f49ff_succeeded/u);
assert.match(presentation.traceEvidence, /evd_m3_di_read_75fc664f-e94f-41e8-816e-aff9fdb3666f_succeeded/u);
});
test("m3-status-v1 only reports persistence blocked when durable is not green or blocker exists", () => {
for (const trustPatch of [
{ durableStatus: "blocked", blocker: "runtime_durable_not_green" },
{ durableStatus: "green", blocker: "runtime_durable_not_green" }
]) {
const presentation = wiringPresentationFromSummary({
...trustedGreenStatus,
trust: {
...trustedGreenStatus.trust,
...trustPatch
}
});
assert.equal(presentation.m3Live, false);
assert.equal(presentation.stateLabel, "接线实况 / 持久化受阻");
assert.equal(presentation.sourceLabel, "/v1/m3/status 聚合");
assert.equal(presentation.rowSourceKind, "SOURCE");
assert.equal(presentation.badgeTone, "blocked");
assert.match(presentation.traceEvidence, /op_m3_di_read_75fc664f-e94f-41e8-816e-aff9fdb3666f/u);
}
});
test("SOURCE and DRY-RUN status inputs cannot be promoted to DEV-LIVE wiring", () => {
for (const sourceKind of ["SOURCE", "DRY-RUN"]) {
const evidence = trustedM3StatusEvidenceFrom({
...trustedGreenStatus,
sourceKind
});
const presentation = wiringPresentationFromSummary({
...trustedGreenStatus,
sourceKind
});
assert.equal(evidence, null);
assert.equal(presentation.m3Live, false);
assert.equal(presentation.rowSourceKind, "SOURCE");
assert.equal(presentation.badgeTone, "blocked");
assert.equal(presentation.stateLabel, "待可信记录");
}
});