feat(bridge): establish local pi status bridge
Deliver the initial local bridge, Noctalia v4/v5 adapters, desktop client, service unit, tests, and implementation documentation for persistent Pi status and control.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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 { createAgentRegistry } from "../src/bridge/agent-registry.js";
|
||||
|
||||
test("recovers an exited agent with its last Pi session reference", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "pi-status-bridge-recovery-"));
|
||||
const home = join(root, "home");
|
||||
const sessionRoot = join(root, "sessions");
|
||||
await mkdir(home);
|
||||
const sessionFile = join(sessionRoot, "pi-session.jsonl");
|
||||
const calls = [];
|
||||
const registry = createAgentRegistry({
|
||||
homeWorktree: home,
|
||||
sessionRoot,
|
||||
recoveryDelayForAttempt: () => 0,
|
||||
sleep: async () => {},
|
||||
startAdapter: (options) => {
|
||||
const adapter = {
|
||||
send: async () => ({
|
||||
type: "response",
|
||||
success: true,
|
||||
data: { sessionFile },
|
||||
}),
|
||||
respondToExtension: () => {},
|
||||
stop: async () => {},
|
||||
};
|
||||
calls.push({ options, adapter });
|
||||
return adapter;
|
||||
},
|
||||
});
|
||||
|
||||
const agent = await registry.start();
|
||||
calls[0].options.onError({ code: "child_exited", message: "crashed" });
|
||||
await registry.waitForRecovery(agent.id);
|
||||
|
||||
assert.equal(calls.length, 2);
|
||||
assert.equal(calls[1].options.sessionPath, sessionFile);
|
||||
assert.deepEqual(
|
||||
registry.eventsAfter(agent.id, 0).map((event) => event.type),
|
||||
["agent_state", "recovery", "recovery", "agent_state"],
|
||||
);
|
||||
await registry.stop();
|
||||
});
|
||||
Reference in New Issue
Block a user