Skip to content

Commit 25268f7

Browse files
test(specTypeSchema): assert isSpecType narrows to input type for schemas with defaults
The previous 'narrows the value type' test asserted against SpecTypes['Implementation'] (the output type), which only passed because Implementation has no defaults. Clarified that case and added a CallToolResult case that proves the documented input-type narrowing: content is optional in the narrowed type, and the narrowed type is not CallToolResult.
1 parent 94684b6 commit 25268f7

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

packages/core/test/types/specTypeSchema.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,22 @@ describe('isSpecType', () => {
6767
expect(isSpecType['NotificationsParams']).toBeUndefined();
6868
});
6969

70-
it('narrows the value type', () => {
70+
it('narrows the value type to the schema input type', () => {
7171
const v: unknown = { name: 'x', version: '1.0.0' };
7272
if (isSpecType.Implementation(v)) {
73-
expectTypeOf(v).toEqualTypeOf<SpecTypes['Implementation']>();
73+
// ImplementationSchema has no defaults/transforms, so its input type equals Implementation.
74+
expectTypeOf(v).toEqualTypeOf<Implementation>();
75+
}
76+
});
77+
78+
it('narrows to the input type, not the output type, for schemas with defaults', () => {
79+
const v: unknown = {};
80+
expect(isSpecType.CallToolResult(v)).toBe(true);
81+
if (isSpecType.CallToolResult(v)) {
82+
// CallToolResultSchema has `content: z.array(...).default([])`, so the input type
83+
// permits `content` to be absent. The guard narrows to that input shape.
84+
expectTypeOf(v.content).toEqualTypeOf<ContentBlock[] | undefined>();
85+
expectTypeOf(v).not.toEqualTypeOf<CallToolResult>();
7486
}
7587
});
7688

0 commit comments

Comments
 (0)