178 lines
6.2 KiB
TypeScript
178 lines
6.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" }],
|
|
accountSummary: { signedIn: true, authMode: "chatgpt", planType: "pro", requiresOpenaiAuth: true },
|
|
rateLimitSummary: { bucketCount: 2, maxUsedPercent: 42, reached: false },
|
|
appConfigSummary: { appCount: 2, enabledAppCount: 1 },
|
|
configRequirements: { managed: true, requirementCount: 2, warningCount: 1 },
|
|
externalAgentMigration: { itemCount: 3, homeItemCount: 1, projectItemCount: 2 },
|
|
skillExtraRootsSummary: {
|
|
configured: true,
|
|
status: "applied",
|
|
rootCount: 2,
|
|
rootLabels: ["boss-shared-skills", "team-skills"],
|
|
},
|
|
threadSummary: {
|
|
threadCount: 3,
|
|
loadedThreadCount: 2,
|
|
activeThreadCount: 1,
|
|
latestUpdatedAt: "2026-06-03T08:20:00.000Z",
|
|
visibleThreads: [{ id: "thr-active", name: "Boss App Server rollout", loaded: true }],
|
|
},
|
|
threadTurnSummary: {
|
|
threadCount: 2,
|
|
totalTurnCount: 3,
|
|
runningTurnCount: 1,
|
|
latestUpdatedAt: "2026-06-03T08:21:00.000Z",
|
|
threads: [{ threadId: "thr-active", turnCount: 2, runningTurnCount: 1 }],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
}),
|
|
);
|
|
|
|
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,
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.accountSummary as
|
|
| { authMode?: string; planType?: string }
|
|
| undefined
|
|
)?.authMode,
|
|
"chatgpt",
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.externalAgentMigration as
|
|
| { itemCount?: number }
|
|
| undefined
|
|
)?.itemCount,
|
|
3,
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.skillExtraRootsSummary as
|
|
| { rootCount?: number; rootLabels?: string[] }
|
|
| undefined
|
|
)?.rootCount,
|
|
2,
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.skillExtraRootsSummary as
|
|
| { rootLabels?: string[] }
|
|
| undefined
|
|
)?.rootLabels?.[0],
|
|
"boss-shared-skills",
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.threadSummary as
|
|
| { threadCount?: number; visibleThreads?: Array<{ id?: string }> }
|
|
| undefined
|
|
)?.threadCount,
|
|
3,
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.threadSummary as
|
|
| { visibleThreads?: Array<{ id?: string }> }
|
|
| undefined
|
|
)?.visibleThreads?.[0]?.id,
|
|
"thr-active",
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.threadTurnSummary as
|
|
| { totalTurnCount?: number; threads?: Array<{ threadId?: string }> }
|
|
| undefined
|
|
)?.totalTurnCount,
|
|
3,
|
|
);
|
|
assert.equal(
|
|
(
|
|
updatedDevice?.capabilities?.codexAppServer.metadata?.threadTurnSummary as
|
|
| { threads?: Array<{ threadId?: string }> }
|
|
| undefined
|
|
)?.threads?.[0]?.threadId,
|
|
"thr-active",
|
|
);
|
|
});
|