Publish bounded live swarm operator state
This commit is contained in:
parent
3d86b93fd3
commit
6357cfcded
3 changed files with 346 additions and 0 deletions
72
scripts/voidbot-swarm-operator-view.test.cjs
Normal file
72
scripts/voidbot-swarm-operator-view.test.cjs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
const test = require("node:test");
|
||||
const { operatorViewPublication, projectSwarmOperatorView, readSwarmOperatorInputs } = require("./voidbot-swarm-operator-view.cjs");
|
||||
|
||||
test("projects bounded operator state and lets control own heat", () => {
|
||||
const view = projectSwarmOperatorView({
|
||||
heartbeat: {
|
||||
globalHeat: 0.5,
|
||||
initiativeClock: 12,
|
||||
lastTickAt: "2026-07-15T10:00:00.000Z",
|
||||
pendingMentions: [{ identityId: "eve" }],
|
||||
participants: [
|
||||
{ identityId: "eve", displayName: "Eve", status: "active", nextTurnInMinutes: 3 },
|
||||
{ identityId: "odin", displayName: "Odin", status: "active", activeJobId: "job-1", nextTurnInMinutes: 8 },
|
||||
],
|
||||
},
|
||||
orchestrator: { organs: { heartbeat: { label: "Heartbeat", lastStatus: "ok", lastDurationSeconds: 2 } } },
|
||||
pause: { paused: false },
|
||||
control: { globalHeat: 0.85 },
|
||||
observedAt: "2026-07-15T10:01:00.000Z",
|
||||
sources: { heartbeat: { readable: true }, orchestrator: { readable: true } },
|
||||
});
|
||||
|
||||
assert.equal(view.version, "voidbot.swarm_operator_view.v1");
|
||||
assert.equal(view.summary.activeTurnCount, 1);
|
||||
assert.equal(view.summary.pendingMentionCount, 1);
|
||||
assert.equal(view.summary.nextIdentityId, "eve");
|
||||
assert.equal(view.queue[0].heat, 0.85);
|
||||
assert.equal(view.selectedFace.identityId, "eve");
|
||||
assert.equal(view.recentEvents, undefined);
|
||||
});
|
||||
|
||||
test("publication exposes the typed record without dashboard-shaped authority", () => {
|
||||
const value = projectSwarmOperatorView({
|
||||
heartbeat: null,
|
||||
orchestrator: null,
|
||||
pause: { paused: true, reason: "maintenance" },
|
||||
control: null,
|
||||
sources: { heartbeat: { readable: false }, orchestrator: { readable: false } },
|
||||
});
|
||||
const publication = operatorViewPublication(value);
|
||||
assert.equal(publication.publicationId, "voidbot.swarm.operator-view");
|
||||
assert.equal(publication.documentType, "voidbot.swarm_operator_view");
|
||||
assert.equal(publication.schemaId, "voidbot.swarm_operator_view.v1");
|
||||
assert.equal(publication.recordKey, "voidbot-swarm");
|
||||
assert.equal(value.summary.state, "missing");
|
||||
assert.equal(value.selectedFace, null);
|
||||
});
|
||||
|
||||
test("reads source files independently and reports a missing owner", async () => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "voidbot-operator-view-"));
|
||||
try {
|
||||
const heartbeat = path.join(root, "heartbeat.json");
|
||||
await fs.writeFile(heartbeat, JSON.stringify({ participants: [] }));
|
||||
const inputs = await readSwarmOperatorInputs({
|
||||
heartbeat,
|
||||
orchestrator: path.join(root, "missing.json"),
|
||||
pause: path.join(root, "pause.json"),
|
||||
});
|
||||
assert.deepEqual(inputs.heartbeat, { participants: [] });
|
||||
assert.equal(inputs.sources.heartbeat.readable, true);
|
||||
assert.equal(inputs.sources.orchestrator.readable, false);
|
||||
assert.equal(inputs.control, null);
|
||||
} finally {
|
||||
await fs.rm(root, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Loading…
Reference in a new issue