Skip to content

Commit b4150c0

Browse files
alexneymanclaude
andcommitted
test(policy): assert the rendered MCP tools, not just the exposed names
The exposed-name list proves the commands are registered, not that a usable tool reaches a model. The assertion now reads the rendered tool: it takes a goal, its description names the variable to set, and no input in its schema can ever carry the credential's value. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 6862da6 commit b4150c0

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

‎src/commands/interaction/policy-commands.test.ts‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import {
88
} from './index.ts';
99
import { createPolicyProvider } from '../policy/policy-provider.ts';
1010
import { listCliCommandNames } from '@agent-device/command-registry/catalog';
11-
import {
12-
commandDescriptors,
13-
listMcpExposedCommandNames,
14-
} from '@agent-device/command-registry/registry';
11+
import { commandDescriptors } from '@agent-device/command-registry/registry';
12+
import { listMcpCommandMetadata } from '../command-metadata.ts';
1513
import { POLICY_API_KEY_ENV } from '@agent-device/command-registry/flag-definitions-workflow';
1614

1715
describe('policy command interface', () => {
@@ -103,10 +101,28 @@ describe('the command surface does not depend on the key', () => {
103101
});
104102

105103
test('both commands are offered over MCP whether or not the key is set', () => {
106-
const withoutKey = withKey(undefined, listMcpExposedCommandNames);
107-
const withKeySet = withKey('a-key', listMcpExposedCommandNames);
108-
expect(withoutKey).toEqual(withKeySet);
109-
for (const command of POLICY_COMMANDS) expect(withoutKey).toContain(command);
104+
const toolNames = () => listMcpCommandMetadata().map((tool) => tool.name);
105+
expect(withKey(undefined, toolNames)).toEqual(withKey('a-key', toolNames));
106+
for (const command of POLICY_COMMANDS) {
107+
expect(withKey(undefined, toolNames)).toContain(command);
108+
}
109+
});
110+
111+
test('each MCP tool takes a goal and never takes the credential', () => {
112+
for (const command of POLICY_COMMANDS) {
113+
const tool = withKey(undefined, () =>
114+
listMcpCommandMetadata().find((entry) => entry.name === command),
115+
);
116+
const schema = tool?.inputSchema;
117+
expect(Object.keys(schema?.properties ?? {}), `${command} must accept a goal`).toContain(
118+
'goal',
119+
);
120+
// The credential is environment-only: the description may name the variable so a model
121+
// knows what to set, but no input may ever carry its value.
122+
expect(JSON.stringify(schema)).not.toContain(POLICY_API_KEY_ENV);
123+
expect(JSON.stringify(schema).toLowerCase()).not.toContain('apikey');
124+
expect(tool?.description).toContain(POLICY_API_KEY_ENV);
125+
}
110126
});
111127

112128
test('neither command owns a daemon route', () => {

0 commit comments

Comments
 (0)