Files
buzz/desktop/src/features/agents/managedAgentRuntimeStatus.test.mjs
npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta 8134248e00 fix(desktop): align managed runtime identity contract
Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
Signed-off-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>

Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
2026-07-19 10:53:35 -04:00

78 lines
2.1 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import {
agentCommunityAvailability,
agentCommunityStatusDetail,
findManagedAgentRuntime,
managedAgentRuntimeKey,
} from "./managedAgentRuntimeStatus.ts";
const runtime = (overrides = {}) => ({
pubkey: "aa",
relayUrl: "wss://relay.example",
localSetup: true,
lifecycle: "ready",
pid: 1,
error: null,
logPath: null,
...overrides,
});
test("projects every backend lifecycle to the four product labels", () => {
assert.equal(agentCommunityAvailability(runtime()), "Here");
for (const lifecycle of ["starting", "listening", "waking"]) {
assert.equal(agentCommunityAvailability(runtime({ lifecycle })), "Waking");
}
for (const lifecycle of ["failed", "stopped"]) {
assert.equal(
agentCommunityAvailability(runtime({ lifecycle })),
"Unavailable",
);
}
});
test("backend-authoritative local setup takes precedence", () => {
assert.equal(
agentCommunityAvailability(
runtime({ localSetup: false, lifecycle: "ready" }),
),
"Needs setup on this device",
);
});
test("unavailable detail distinguishes stopped and failed", () => {
assert.equal(
agentCommunityStatusDetail(runtime({ lifecycle: "stopped" })),
"Stopped by you",
);
assert.equal(
agentCommunityStatusDetail(
runtime({ lifecycle: "failed", error: "Relay timed out" }),
),
"Relay timed out",
);
});
test("pair key cannot collide at component boundaries", () => {
assert.notEqual(
managedAgentRuntimeKey(runtime({ pubkey: "ab", relayUrl: "c" })),
managedAgentRuntimeKey(runtime({ pubkey: "a", relayUrl: "bc" })),
);
});
test("selects one relay without collapsing same-pubkey pairs", () => {
const runtimes = [
runtime({ relayUrl: "wss://a.example", lifecycle: "ready" }),
runtime({ relayUrl: "wss://b.example", lifecycle: "failed" }),
];
assert.equal(
findManagedAgentRuntime(runtimes, "AA", "wss://b.example")?.lifecycle,
"failed",
);
assert.equal(
findManagedAgentRuntime(runtimes, "aa", "wss://c.example"),
undefined,
);
});