|
1 | 1 | import { describe, expect, expectTypeOf, it } from 'vitest'; |
2 | 2 |
|
3 | 3 | import type { OAuthMetadata, OAuthTokens } from '../../src/shared/auth.js'; |
| 4 | +import * as schemas from '../../src/types/schemas.js'; |
4 | 5 | import type { SpecTypeName, SpecTypes } from '../../src/types/specTypeSchema.js'; |
5 | 6 | import { isSpecType, specTypeSchemas } from '../../src/types/specTypeSchema.js'; |
6 | 7 | import type { |
@@ -146,3 +147,30 @@ describe('SpecTypeName / SpecTypes (type-level)', () => { |
146 | 147 | expectTypeOf<SpecTypes['ResourceTemplate']>().toEqualTypeOf<ResourceTemplateType>(); |
147 | 148 | }); |
148 | 149 | }); |
| 150 | + |
| 151 | +describe('SPEC_SCHEMA_KEYS allowlist', () => { |
| 152 | + // Mirrors the exclusion comment in specTypeSchema.ts. If this list grows, confirm the new |
| 153 | + // entry has no public type in types.ts before adding it here; otherwise add it to the allowlist. |
| 154 | + const INTERNAL_HELPER_SCHEMAS: readonly string[] = [ |
| 155 | + 'ListChangedOptionsBaseSchema', |
| 156 | + 'BaseRequestParamsSchema', |
| 157 | + 'NotificationsParamsSchema', |
| 158 | + 'ClientTasksCapabilitySchema', |
| 159 | + 'ServerTasksCapabilitySchema' |
| 160 | + ]; |
| 161 | + |
| 162 | + it('covers every public protocol schema in schemas.ts (drift guard)', () => { |
| 163 | + // PascalCase filters out helper functions like getRequestSchema/getResultSchema. |
| 164 | + const allProtocolSchemas = Object.keys(schemas).filter(k => k.endsWith('Schema') && /^[A-Z]/.test(k)); |
| 165 | + const expected = allProtocolSchemas |
| 166 | + .filter(k => !INTERNAL_HELPER_SCHEMAS.includes(k)) |
| 167 | + .map(k => k.slice(0, -'Schema'.length)) |
| 168 | + .sort(); |
| 169 | + // Auth schemas are sourced from shared/auth.ts, not schemas.ts, so filter them out of the |
| 170 | + // observed side before comparing. |
| 171 | + const actual = Object.keys(isSpecType) |
| 172 | + .filter(k => !k.startsWith('OAuth') && !k.startsWith('OpenId')) |
| 173 | + .sort(); |
| 174 | + expect(actual).toEqual(expected); |
| 175 | + }); |
| 176 | +}); |
0 commit comments