34 lines
2.2 KiB
JavaScript
34 lines
2.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import test from "node:test";
|
|
import { startBridgeDaemon } from "../src/bridge/daemon.js";
|
|
import { createNoctaliaStateRelay } from "../src/client/noctalia-relay.js";
|
|
|
|
test("starts a bridge daemon around the local bridge service", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "pi-status-bridge-daemon-"));
|
|
const home = join(root, "home");
|
|
await mkdir(home);
|
|
const daemon = await startBridgeDaemon({ homeWorktree: home, runtimeDir: join(root, "runtime"), sessionRoot: join(root, "sessions"), startAdapter: () => ({ send: async () => ({ type: "response", success: true }), respondToExtension: () => {}, stop: async () => {} }) });
|
|
try { assert.match(daemon.socketPath, /bridge\.sock$/); assert.equal(daemon.listAgents()[0].worktreePath, home); }
|
|
finally { await daemon.close(); }
|
|
});
|
|
|
|
test("relays aggregate workspace summary as compact Noctalia state", async () => {
|
|
const updates = [];
|
|
const relay = createNoctaliaStateRelay({
|
|
client: { request: async (operation) => { assert.equal(operation, "get_workspace_summary"); return { openCount: 3, workingCount: 1, attentionCount: 2, recoveringCount: 0, errorCount: 1 }; } },
|
|
onState: (state) => updates.push(state), pollMs: 250,
|
|
});
|
|
await relay.start(); relay.stop();
|
|
assert.deepEqual(updates, [{ state: "error", projectLabel: "3 sessions", attentionCount: 2, detail: "3 open · 1 working · 2 attention · 0 recovering · 1 errors", openCount: 3, workingCount: 1, recoveringCount: 0, errorCount: 1 }]);
|
|
});
|
|
|
|
test("retains agent-scoped relay behavior only when explicitly requested", async () => {
|
|
let listener; const updates = [];
|
|
const relay = createNoctaliaStateRelay({ client: { request: async () => ({ data: { isStreaming: false } }), subscribe: async (_agentId, _cursor, callback) => { listener = callback; return () => {}; } }, agent: { id: "agent-1", worktreePath: "/worktrees/feature" }, onState: (state) => updates.push(state) });
|
|
await relay.start(); listener({ type: "agent_state", data: { state: "streaming" } });
|
|
assert.equal(updates.at(-1).state, "streaming"); assert.equal(updates.at(-1).projectLabel, "feature");
|
|
});
|