Files
Netcatty/scripts/generate-capability-tools.test.cjs
T
陈大猫 e2b3004d4b perf(memory): Phase 3 deep business-code memory optimization (main, renderer & active terminals) (#4488)
Includes all Phase 3 rounds (1-5), Node unit test mock compatibility fixes,
and Codex review fixes (pinyin readiness subscribers & KnownHostsManager
mount retention).
2026-11-27 23:24:40 +08:00

82 lines
2.6 KiB
JavaScript

"use strict";
const test = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const { AGENT_KINDS, listAgentToolSpecs, listCattyToolSpecs } = require("../electron/capabilities/codegen/toolSurfaces.cjs");
const GENERATED_DIR = path.join(
__dirname,
"..",
"infrastructure",
"ai",
"harness",
"generated",
);
test("committed cattyToolSpecs.json matches listCattyToolSpecs()", () => {
const committed = JSON.parse(
fs.readFileSync(path.join(GENERATED_DIR, "cattyToolSpecs.json"), "utf8"),
);
const fresh = listCattyToolSpecs();
assert.deepEqual(committed, fresh);
});
test("committed globalAgentToolSpecs.json matches listAgentToolSpecs(global)", () => {
const committed = JSON.parse(
fs.readFileSync(path.join(GENERATED_DIR, "globalAgentToolSpecs.json"), "utf8"),
);
const fresh = listAgentToolSpecs(AGENT_KINDS.GLOBAL);
assert.deepEqual(committed, fresh);
});
test("committed toolNameIndex.json matches sidebar and global capability tool specs", () => {
const committed = JSON.parse(
fs.readFileSync(path.join(GENERATED_DIR, "toolNameIndex.json"), "utf8"),
);
const globalByCapabilityId = {};
for (const spec of listAgentToolSpecs(AGENT_KINDS.GLOBAL)) {
if (spec.capabilityId && spec.toolName && !globalByCapabilityId[spec.capabilityId]) {
globalByCapabilityId[spec.capabilityId] = spec.toolName;
}
}
const sidebarByRpcMethod = {};
const sidebarToolNameToCapability = {};
const sidebarRpcMethodToCapability = {};
const freshApprovalSet = new Set();
const grantableSet = new Set();
for (const spec of listCattyToolSpecs()) {
if (spec.rpcMethod && spec.toolName && !sidebarByRpcMethod[spec.rpcMethod]) {
sidebarByRpcMethod[spec.rpcMethod] = spec.toolName;
}
if (spec.toolName && spec.capabilityId) {
sidebarToolNameToCapability[spec.toolName] = spec.capabilityId;
}
if (spec.rpcMethod && spec.capabilityId) {
sidebarRpcMethodToCapability[spec.rpcMethod] = spec.capabilityId;
}
if (spec.policy?.requiresFreshApproval && spec.capabilityId) {
freshApprovalSet.add(spec.capabilityId);
}
if (
spec.policy?.write
&& !spec.policy?.bypassesApproval
&& !spec.policy?.requiresFreshApproval
&& spec.capabilityId
) {
grantableSet.add(spec.capabilityId);
}
}
assert.deepEqual(committed, {
globalByCapabilityId,
sidebarByRpcMethod,
sidebarToolNameToCapability,
sidebarRpcMethodToCapability,
freshApprovalOnlyCapabilities: [...freshApprovalSet].sort(),
grantableCapabilityIds: [...grantableSet].sort(),
});
});