Skip to content

Commit 8de106c

Browse files
committed
test(mcp): derive size counts dynamically in annotations test
Follow-up to CodeRabbit feedback on rohitg00#1098: hardcoding 53 and 8 duplicated contracts owned elsewhere (tool-count-consistency.test.ts owns the 53; ESSENTIAL_TOOLS.size is the source of truth for core). Derive total via getAllTools().length and core via ESSENTIAL_TOOLS.size, keeping the 23/26/4 classification counts and frozen name sets hardcoded since those are the contract this test verifies. Adds a partition sum invariant (23+4+26 === total) that now meaningfully catches a new tool added without classification. Refs rohitg00#1097 Signed-off-by: AJ Alon <alexander.joel.alon@gmail.com>
1 parent 8ebfe49 commit 8de106c

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

test/mcp-tool-annotations.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ vi.mock("../src/config.js", () => ({
2222
import {
2323
getAllTools,
2424
getVisibleTools,
25+
ESSENTIAL_TOOLS,
2526
type McpToolDef,
2627
} from "../src/mcp/tools-registry.js";
2728
import { handleToolsList } from "../src/mcp/standalone.js";
@@ -63,6 +64,8 @@ const DESTRUCTIVE_TOOLS = new Set([
6364
"memory_slot_delete",
6465
]);
6566

67+
const TOTAL = getAllTools().length;
68+
6669
const instantLocalFallbackProbe = vi.fn(async () => ({
6770
ok: false,
6871
status: 0,
@@ -135,15 +138,16 @@ describe("MCP tool risk annotations", () => {
135138
}
136139
});
137140

138-
it("every tool falls into exactly one classification (23 + 4 + 26 = 53)", () => {
141+
it("every tool falls into exactly one classification (23 + 4 + 26 covers total)", () => {
139142
const tools = getAllTools();
140-
expect(tools.length).toBe(53);
143+
expect(tools.length).toBe(TOTAL);
141144
const counts = { "read-only": 0, destructive: 0, "state-changing": 0, invalid: 0 };
142145
for (const t of tools) counts[classification(t) as keyof typeof counts]++;
143146
expect(counts["read-only"]).toBe(23);
144147
expect(counts.destructive).toBe(4);
145148
expect(counts["state-changing"]).toBe(26);
146149
expect(counts.invalid).toBe(0);
150+
expect(counts["read-only"] + counts.destructive + counts["state-changing"]).toBe(TOTAL);
147151
});
148152

149153
it("getVisibleTools preserves annotations in every visibility mode", () => {
@@ -152,8 +156,8 @@ describe("MCP tool risk annotations", () => {
152156
for (const mode of ["all", "core"]) {
153157
process.env["AGENTMEMORY_TOOLS"] = mode;
154158
const visible = getVisibleTools();
155-
if (mode === "all") expect(visible.length).toBe(53);
156-
if (mode === "core") expect(visible.length).toBe(8);
159+
if (mode === "all") expect(visible.length).toBe(TOTAL);
160+
if (mode === "core") expect(visible.length).toBe(ESSENTIAL_TOOLS.size);
157161
for (const tool of visible) {
158162
expect(tool.annotations, `tool ${tool.name} lost annotations in ${mode} mode`).toBeDefined();
159163
}

0 commit comments

Comments
 (0)