import test from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { buildBossAgentStatus, mergeBossAgentNativePermissionOverrides, renderBossAgentHtml, renderBossAgentHtmlWithQr, } from "../local-agent/boss-agent-status.mjs"; test("boss-agent status exposes unbound QR binding and local permission states", () => { const status = buildBossAgentStatus( { deviceId: "macbook-air", name: "MacBook Air", avatar: "A", account: "", controlPlaneUrl: "https://boss.hyzq.net", pairingCode: "482913", token: "", primaryApiLabel: "DeepSeek V4", backupApiLabel: "未启用", licenseExpiresAt: "2027-05-12T00:00:00.000Z", }, { lastHeartbeatOk: true, lastHeartbeatStatus: 200, lastHeartbeatAt: "2026-05-12T05:00:00.000Z", lastSkills: [ { name: "bb-browser", category: "MacBook Air", path: "/Users/jas/.codex/skills/bb-browser/SKILL.md" }, { name: "skill-installer", category: ".system", path: "/Users/jas/.codex/skills/.system/skill-installer/SKILL.md" }, ], lastSkillSyncOk: true, lastSkillSyncAt: "2026-05-12T05:30:00.000Z", }, { permissions: { accessibility: "granted", screenRecording: "missing", automation: "unknown", }, now: "2026-05-12T06:00:00.000Z", }, ); assert.equal(status.appName, "boss-agent"); assert.equal(status.binding.bound, false); assert.equal(status.binding.qrPayload.includes("pairingCode=482913"), true); assert.equal(status.server.ok, true); assert.equal(status.api.primary, "DeepSeek V4"); assert.equal(status.api.backup, "未启用"); assert.equal(status.license.status, "pending_binding"); assert.equal(status.skills.total, 2); assert.equal(status.skills.syncOk, true); assert.equal(status.permissionReadiness.coreReady, false); assert.equal(status.permissionReadiness.fullControlReady, false); assert.match(status.permissionReadiness.summary, /基础桌面控制/); assert.equal(status.permissionSetup.mode, "minimal_computer_use"); assert.equal(status.permissionSetup.silentUseReady, false); assert.equal(status.permissionSetup.actions.some((action) => action.key === "fullDiskAccess"), true); assert.equal( status.permissionSetup.actions.every((action) => action.settingsUrl.startsWith("x-apple.systempreferences:")), true, ); assert.equal( status.permissionSetup.actions.find((action) => action.key === "localNetwork")?.settingsUrl, "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?privacy-localnetwork", ); assert.equal( status.permissionSetup.actions.find((action) => action.key === "inputMonitoring")?.settingsUrl, "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_ListenEvent", ); assert.equal( status.permissionSetup.actions.find((action) => action.key === "screenRecording")?.settingsUrl, "x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_ScreenCapture", ); assert.deepEqual( status.permissions.items.map((item) => [item.key, item.status]), [ ["accessibility", "granted"], ["screenRecording", "missing"], ], ); assert.deepEqual( status.permissions.extendedItems.slice(0, 1).map((item) => [item.key, item.status]), [ ["automation", "unknown"], ], ); }); test("boss-agent status treats token-backed devices as bound and renders enterprise UI", () => { const status = buildBossAgentStatus( { deviceId: "mac-studio", name: "Mac Studio", avatar: "M", account: "krisolo", controlPlaneUrl: "https://boss.hyzq.net", token: "boss-secret-token", primaryApiLabel: "DeepSeek V4", backupApiLabel: "OpenAI 备用", license: { enterpriseName: "默认公司", status: "valid", expiresAt: "2027-05-12T00:00:00.000Z", }, }, { lastHeartbeatOk: true, lastHeartbeatStatus: 200, lastHeartbeatAt: "2026-05-12T05:00:00.000Z", lastSkills: [ { name: "bb-browser", category: "MacBook Air", path: "/Users/jas/.codex/skills/bb-browser/SKILL.md" }, { name: "skill-installer", category: ".system", path: "/Users/jas/.codex/skills/.system/skill-installer/SKILL.md" }, ], lastSkillSyncOk: true, }, { permissions: { accessibility: "granted", screenRecording: "granted", automation: "granted", fullDiskAccess: "missing", inputMonitoring: "unknown", }, now: "2026-05-12T06:00:00.000Z", }, ); assert.equal(status.binding.bound, true); assert.equal(status.binding.account, "krisolo"); assert.equal(status.license.status, "valid"); assert.equal(status.license.enterpriseName, "默认公司"); const html = renderBossAgentHtml(status); assert.match(html, /boss-agent/); assert.match(html, /企业电脑接入端/); assert.match(html, /本机权限获取/); assert.match(html, /href="\/boss-agent\?tab=permissions">本机权限获取<\/span>/); assert.match(html, /href="\/boss-agent\?tab=skills">Skill<\/span>/); assert.match(html, /class="active" href="\/boss-agent\?tab=overview"/); assert.doesNotMatch(html, /