-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathskill-surface-guard.test.ts
More file actions
88 lines (81 loc) · 2.98 KB
/
Copy pathskill-surface-guard.test.ts
File metadata and controls
88 lines (81 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect } from 'vitest';
import { MCPServerRuntime } from './mcp-server-runtime.js';
import type { McpDataBridge, McpActionBridge } from './mcp-http-tools.js';
import { renderSkillMarkdown } from './skill.js';
/**
* Drift guard: the generated SKILL.md must document every native tool the
* HTTP MCP surface actually registers.
*
* The gap this guards against is real: the action tools (#2307) shipped with
* doc updates, but `skill.ts` was written later against the CRUD set only and
* silently documented 7 of 9 tools (fixed in #2715). The skill is the single
* source every distribution shell copies (ADR-0036 Amendment C), so an
* undocumented tool here means every agent installing the skill never learns
* the tool exists.
*
* The registered surface is obtained by driving the REAL registration path —
* a `tools/list` round-trip against `MCPServerRuntime` with a full
* data+action bridge — not from a hand-maintained name list, so adding a new
* tool to `mcp-http-tools.ts` without teaching the skill turns this red.
*/
/** Minimal full-surface bridge: object + action methods present, all stubbed. */
function makeFullBridge(): McpDataBridge & McpActionBridge {
return {
async listObjects() {
return [];
},
async describeObject() {
return null;
},
async query() {
return { records: [] };
},
async get() {
return null;
},
async create() {
return {};
},
async update() {
return {};
},
async remove() {
return {};
},
async listActions() {
return [];
},
async runAction() {
return {};
},
};
}
async function listRegisteredToolNames(): Promise<string[]> {
const runtime = new MCPServerRuntime({ name: 'skill-guard', version: '0.0.0' });
const body = { jsonrpc: '2.0', id: 1, method: 'tools/list' };
const res = await runtime.handleHttpRequest(
new Request('http://localhost/api/v1/mcp', {
method: 'POST',
headers: {
'content-type': 'application/json',
accept: 'application/json, text/event-stream',
},
body: JSON.stringify(body),
}),
{ bridge: makeFullBridge(), parsedBody: body },
);
const json: any = await res.json();
const tools: Array<{ name: string }> = json?.result?.tools ?? [];
return tools.map((t) => t.name);
}
describe('SKILL.md ↔ native tool surface drift guard', () => {
it('documents every tool the HTTP MCP surface registers', async () => {
const registered = await listRegisteredToolNames();
// Sanity: the harness must see the full surface, or the guard guards nothing.
expect(registered.length).toBeGreaterThanOrEqual(9);
const md = renderSkillMarkdown();
const undocumented = registered.filter((name) => !md.includes(name));
expect(undocumented, `tools registered but missing from SKILL.md — update packages/mcp/src/skill.ts: ${undocumented.join(', ')}`).toEqual([]);
});
});