b7fea83ed6
Deliver the initial local bridge, Noctalia v4/v5 adapters, desktop client, service unit, tests, and implementation documentation for persistent Pi status and control.
60 lines
1.7 KiB
JavaScript
60 lines
1.7 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 { connectLocalClient } from "../src/client/local-client.js";
|
|
import { startBridgeService } from "../src/bridge/service.js";
|
|
|
|
test("uses only the approved local protocol for requests and live event subscriptions", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "pi-status-bridge-client-"));
|
|
const home = join(root, "home");
|
|
await mkdir(home);
|
|
const starts = [];
|
|
const service = await startBridgeService({
|
|
homeWorktree: home,
|
|
runtimeDir: join(root, "runtime"),
|
|
sessionRoot: join(root, "sessions"),
|
|
startAdapter: (options) => {
|
|
const adapter = {
|
|
send: async () => ({ type: "response", success: true }),
|
|
respondToExtension: () => {},
|
|
stop: async () => {},
|
|
};
|
|
starts.push({ options, adapter });
|
|
return adapter;
|
|
},
|
|
});
|
|
const client = await connectLocalClient({ socketPath: service.socketPath });
|
|
|
|
try {
|
|
const agents = await client.request("list_agents");
|
|
assert.equal(agents.agents.length, 1);
|
|
const events = [];
|
|
const unsubscribe = await client.subscribe(
|
|
agents.agents[0].id,
|
|
0,
|
|
(event) => events.push(event),
|
|
);
|
|
starts[0].options.onEvent({
|
|
type: "queue",
|
|
data: { event: { type: "queue_update" } },
|
|
});
|
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
|
|
assert.deepEqual(events, [
|
|
{
|
|
version: "v1",
|
|
seq: 1,
|
|
type: "queue",
|
|
agentId: agents.agents[0].id,
|
|
data: { event: { type: "queue_update" } },
|
|
},
|
|
]);
|
|
unsubscribe();
|
|
} finally {
|
|
await client.close();
|
|
await service.close();
|
|
}
|
|
});
|