mirror of
https://github.com/block/buzz.git
synced 2026-11-02 23:41:08 +00:00
Signed-off-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: Matt Toohey <contact@matttoohey.com> Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Signed-off-by: Tyler <109685178+tlongwell-block@users.noreply.github.com> Co-authored-by: npub1jh9wn95s0472h86ahapupaf7m6kx4v9sx2n0atj2hltcfer8k06s5n3pyf <95cae996907d7cab9f5dbf43c0f53edeac6ab0b032a6feae4abfd784e467b3f5@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Tyler Longwell <tlongwell@block.xyz> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1t2tgm7d8f995uqvmnm8h88sg3wnpp9a5xysjf6dg3tjmgt3ltulqdp8ehr <5a968df9a7494b4e019b9ecf739e088ba61097b4312124e9a88ae5b42e3f5f3e@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Dawn <c6237ef84fa537c78dcee78efd2d4e59f728859c7f194da42ac51ededfa0be05@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@sprout-oss.stage.blox.sqprod.co> Co-authored-by: Matt Toohey <contact@matttoohey.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: npub1hwqy0rnujtl25dzmlhn8qwux4kr8sjhas3ugltx9j5dm5dwkp2dsqjhytw <bb80478e7c92feaa345bfde6703b86ad86784afd84788facc5951bba35d60a9b@buzz.block.builderlab.xyz>
114 lines
3.3 KiB
JavaScript
114 lines
3.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
agentCommunityAvailability,
|
|
agentCommunityStatusDetail,
|
|
canonicalRelayUrl,
|
|
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,
|
|
);
|
|
});
|
|
|
|
test("canonicalRelayUrl mirrors the backend pair-key normalization", () => {
|
|
// Loopback folding + default-port and trailing-slash stripping — the
|
|
// standard dev setup that previously broke pair matching.
|
|
assert.equal(canonicalRelayUrl("ws://localhost:3000"), "ws://127.0.0.1:3000");
|
|
assert.equal(
|
|
canonicalRelayUrl("WSS://Relay.Example:443/"),
|
|
"wss://relay.example",
|
|
);
|
|
assert.equal(
|
|
canonicalRelayUrl("ws://relay.example:80/"),
|
|
"ws://relay.example",
|
|
);
|
|
assert.equal(
|
|
canonicalRelayUrl("wss://relay.example/path/"),
|
|
"wss://relay.example/path",
|
|
);
|
|
assert.equal(canonicalRelayUrl("ws://[::1]:3000"), "ws://127.0.0.1:3000");
|
|
assert.equal(canonicalRelayUrl("https://relay.example"), null);
|
|
assert.equal(canonicalRelayUrl("not a url"), null);
|
|
});
|
|
|
|
test("matches a stored community URL against canonical backend rows", () => {
|
|
const runtimes = [
|
|
runtime({ relayUrl: "ws://127.0.0.1:3000", lifecycle: "ready" }),
|
|
];
|
|
assert.equal(
|
|
findManagedAgentRuntime(runtimes, "aa", "ws://localhost:3000")?.lifecycle,
|
|
"ready",
|
|
);
|
|
assert.equal(
|
|
findManagedAgentRuntime(runtimes, "aa", "ws://localhost:3001"),
|
|
undefined,
|
|
);
|
|
});
|