Skip to content

Commit d8c7405

Browse files
committed
test(mcp): guard projected schema families against silent shadowing in the composed map
1 parent 666a960 commit d8c7405

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎src/mcp/__tests__/command-tools-replay-schemas.test.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ test('the projected family map declares exactly the commands its module owns', (
5959
}
6060
});
6161

62+
/**
63+
* A projected family is spread into the base map, so two families naming one command would resolve
64+
* last-wins with nothing to complain about: the composed map still satisfies
65+
* `Record<keyof CommandResultMap, JsonSchema>` and publishes whichever schema spread last. Totality
66+
* stays the compiler's; this owns the shadowing half. Every family the seam spreads is listed here,
67+
* so registering a new family is the migration step.
68+
*/
69+
const PROJECTED_FAMILIES = [{ name: 'replay', schemas: REPLAY_COMMAND_OUTPUT_SCHEMAS }] as const;
70+
71+
test('projected output-schema families claim disjoint commands and survive the composition intact', () => {
72+
const claimedBy = new Map<string, string>();
73+
for (const family of PROJECTED_FAMILIES) {
74+
for (const command of Object.keys(family.schemas)) {
75+
const previous = claimedBy.get(command);
76+
assert.equal(
77+
previous,
78+
undefined,
79+
`${command} is claimed by both ${previous} and ${family.name}; the later spread would win silently`,
80+
);
81+
claimedBy.set(command, family.name);
82+
}
83+
}
84+
for (const family of PROJECTED_FAMILIES) {
85+
for (const [command, schema] of Object.entries(family.schemas)) {
86+
assert.equal(
87+
COMMAND_OUTPUT_SCHEMAS[command as keyof typeof COMMAND_OUTPUT_SCHEMAS],
88+
schema,
89+
`${family.name}.${command} is not the schema the map publishes`,
90+
);
91+
}
92+
}
93+
});
94+
6295
test('MCP replay outputSchema validates a full result and refuses a dropped required count', () => {
6396
assert.deepEqual(validateAgainstSchema(REPLAY_RESULT, COMMAND_OUTPUT_SCHEMAS.replay), []);
6497

0 commit comments

Comments
 (0)