89 lines
3.2 KiB
TypeScript
89 lines
3.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { NextRequest } from "next/server";
|
|
|
|
let runtimeRoot = "";
|
|
let readState: (typeof import("../src/lib/boss-data"))["readState"];
|
|
let deviceHeartbeatRoute: (typeof import("../src/app/api/device-heartbeat/route"))["POST"];
|
|
|
|
async function setup() {
|
|
if (runtimeRoot) return;
|
|
runtimeRoot = await mkdtemp(path.join(os.tmpdir(), "boss-device-capability-metadata-"));
|
|
process.env.BOSS_RUNTIME_ROOT = runtimeRoot;
|
|
process.env.BOSS_STATE_FILE = path.join(runtimeRoot, "boss-state.json");
|
|
|
|
const [data, heartbeatModule] = await Promise.all([
|
|
import("../src/lib/boss-data.ts"),
|
|
import("../src/app/api/device-heartbeat/route.ts"),
|
|
]);
|
|
readState = data.readState;
|
|
deviceHeartbeatRoute = heartbeatModule.POST;
|
|
}
|
|
|
|
test.after(async () => {
|
|
if (runtimeRoot) {
|
|
await rm(runtimeRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("device heartbeat preserves Codex App Server capability metadata", async () => {
|
|
await setup();
|
|
const state = await readState();
|
|
const device = state.devices.find((item) => item.id === "mac-studio");
|
|
assert.ok(device, "expected seeded mac-studio device");
|
|
|
|
const response = await deviceHeartbeatRoute(
|
|
new NextRequest("http://127.0.0.1:3000/api/device-heartbeat", {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({
|
|
deviceId: device!.id,
|
|
token: device!.token,
|
|
name: device!.name,
|
|
avatar: device!.avatar,
|
|
account: device!.account,
|
|
status: "online",
|
|
quota5h: device!.quota5h,
|
|
quota7d: device!.quota7d,
|
|
projects: device!.projects,
|
|
endpoint: device!.endpoint,
|
|
capabilities: {
|
|
codexAppServer: {
|
|
connected: true,
|
|
lastSeenAt: "2026-05-31T10:00:00.000Z",
|
|
metadata: {
|
|
models: [{ id: "gpt-5.4", displayName: "GPT-5.4" }],
|
|
defaultModelId: "gpt-5.4",
|
|
fastModelId: "gpt-5.4-mini",
|
|
providerCapabilities: { webSearch: true },
|
|
experimentalFeatures: [{ name: "multi_agent", stage: "stable", enabled: true }],
|
|
collaborationModes: [{ id: "plan" }],
|
|
permissionProfiles: [{ id: ":workspace" }],
|
|
mcpServers: [{ name: "github", toolCount: 2, authStatus: "oAuth" }],
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
}),
|
|
);
|
|
|
|
assert.equal(response.status, 200);
|
|
const nextState = await readState();
|
|
const updatedDevice = nextState.devices.find((item) => item.id === device!.id);
|
|
assert.equal(updatedDevice?.capabilities?.codexAppServer.metadata?.models?.[0]?.id, "gpt-5.4");
|
|
assert.equal(updatedDevice?.capabilities?.codexAppServer.metadata?.providerCapabilities?.webSearch, true);
|
|
assert.equal(
|
|
(updatedDevice?.capabilities?.codexAppServer.metadata?.experimentalFeatures as Array<{ name: string }> | undefined)?.[0]
|
|
?.name,
|
|
"multi_agent",
|
|
);
|
|
assert.equal(
|
|
(updatedDevice?.capabilities?.codexAppServer.metadata?.mcpServers as Array<{ toolCount: number }> | undefined)?.[0]
|
|
?.toolCount,
|
|
2,
|
|
);
|
|
});
|