Skip to content

Commit ace295b

Browse files
committed
fix(dashboard): statusSignalHasCommErrorKey sibling companion lands on the live-status mirror
The harness contract gained statusSignalHasCommErrorKey (REQ-B version-skew observability) with its dashboard sibling explicitly left to the dashboard owner. Add the byte-identity-safe companion to live-status.ts — placed OUTSIDE the commErrorFromStatusSignal region pinned by commError-contract-drift.test.ts (only the decode function source is mirrored; proven by the drift suite staying green) — so dashboard consumers can distinguish a present-but-undecodable overlay from a genuinely absent one. Unit-pinned: unknown future kind, well-formed, absent, and array-expando wire shapes.
1 parent 7ef9623 commit ace295b

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

showcase/shell-dashboard/src/lib/live-status.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { describe, it, expect, vi, afterEach } from "vitest";
22
import {
33
CATALOG_TO_D5_KEY,
4+
FLEET_COMM_ERROR_SIGNAL_KEY,
45
STARTER_COLUMNS,
56
STARTER_LEVELS,
67
STATUS_LIST_FIELDS,
78
buildStarterBadge,
9+
commErrorFromStatusSignal,
810
keyFor,
911
mergeRowsToMap,
1012
resolveCell,
1113
resolveD5Row,
1214
resolveD6Row,
1315
resolveStarterRow,
1416
starterIsSupported,
17+
statusSignalHasCommErrorKey,
1518
upsertByKey,
1619
} from "./live-status";
1720
import type { LiveStatusMap, StatusRow, StarterLevel } from "./live-status";
@@ -53,6 +56,45 @@ function mapOf(rows: StatusRow[]): LiveStatusMap {
5356
return m;
5457
}
5558

59+
describe("statusSignalHasCommErrorKey (sibling of the harness contract companion)", () => {
60+
it("distinguishes 'key present but undecodable' from 'genuinely absent' without changing the decode contract", () => {
61+
// Key present, kind unknown to this reader (the version-skew case): the
62+
// decode fail-safes to undefined but the companion still sees the key.
63+
const unknownKind = {
64+
[FLEET_COMM_ERROR_SIGNAL_KEY]: {
65+
kind: "some-future-kind",
66+
message: "x",
67+
observedAt: FRESH_OBSERVED_AT,
68+
},
69+
};
70+
expect(commErrorFromStatusSignal(unknownKind)).toBeUndefined();
71+
expect(statusSignalHasCommErrorKey(unknownKind)).toBe(true);
72+
73+
// Key present and well-formed: both sides agree.
74+
const wellFormed = {
75+
[FLEET_COMM_ERROR_SIGNAL_KEY]: {
76+
kind: "worker-unreachable",
77+
message: "connect ECONNREFUSED",
78+
observedAt: FRESH_OBSERVED_AT,
79+
},
80+
};
81+
expect(commErrorFromStatusSignal(wellFormed)).toBeDefined();
82+
expect(statusSignalHasCommErrorKey(wellFormed)).toBe(true);
83+
84+
// Genuinely absent / never a valid wire shape (mirrors the decoder's
85+
// null / non-object / array guards — including the key as an array
86+
// expando property).
87+
expect(statusSignalHasCommErrorKey({ failedCount: 0 })).toBe(false);
88+
expect(statusSignalHasCommErrorKey(null)).toBe(false);
89+
expect(statusSignalHasCommErrorKey("nope")).toBe(false);
90+
expect(
91+
statusSignalHasCommErrorKey(
92+
Object.assign([], { [FLEET_COMM_ERROR_SIGNAL_KEY]: {} }),
93+
),
94+
).toBe(false);
95+
});
96+
});
97+
5698
describe("keyFor", () => {
5799
it("integration-level dimensions have no feature segment", () => {
58100
expect(keyFor("health", "agno")).toBe("health:agno");

showcase/shell-dashboard/src/lib/live-status.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ export function commErrorFromStatusSignal(
204204
return out;
205205
}
206206

207+
/**
208+
* Companion to `commErrorFromStatusSignal`: does the signal blob CARRY the
209+
* well-known comm-error key at all, regardless of whether the embedded value
210+
* decodes? Lets consumers distinguish "key present but undecodable" (a REQ-B
211+
* overlay written by a NEWER producer — e.g. a new `PoolCommErrorKind` rolled
212+
* out write-side first — that this reader silently drops; count/log it) from
213+
* "genuinely absent" (nothing to report) without changing the decode's return
214+
* contract. Mirrors the decoder's wire-shape guards: a null / non-object /
215+
* array blob is never a valid signal, so the key cannot be "present" on one.
216+
* Sibling of the harness contract's `statusSignalHasCommErrorKey`
217+
* (`showcase/harness/src/fleet/contracts.ts`) — both live OUTSIDE the
218+
* byte-identity region pinned by `commError-contract-drift.test.ts` (only the
219+
* `commErrorFromStatusSignal` function source is mirrored). Pure;
220+
* unit-tested.
221+
*/
222+
export function statusSignalHasCommErrorKey(signal: unknown): boolean {
223+
if (signal === null || typeof signal !== "object" || Array.isArray(signal)) {
224+
return false;
225+
}
226+
return FLEET_COMM_ERROR_SIGNAL_KEY in signal;
227+
}
228+
207229
export interface StatusRow {
208230
id: string;
209231
key: string;

0 commit comments

Comments
 (0)