Skip to content

Commit f377004

Browse files
ochafikchenxi-null
authored andcommitted
widen type extraction regex, introduce + test MISSING_SDK_TYPES, check LoggingLevel
1 parent 33f1501 commit f377004

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

src/spec.types.test.ts

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -658,51 +658,55 @@ function checkServerNotification(
658658
sdk = spec;
659659
spec = sdk;
660660
}
661+
function checkLoggingLevel(
662+
sdk: SDKTypes.LoggingLevel,
663+
spec: SpecTypes.LoggingLevel
664+
) {
665+
sdk = spec;
666+
spec = sdk;
667+
}
661668

662-
// TODO(bug): missing type in SDK. This dead code is checked by the test suite below.
663-
// function checkModelHint(
664-
// RemovePassthrough< sdk: SDKTypes.ModelHint>,
665-
// spec: SpecTypes.ModelHint
666-
// ) {
667-
// sdk = spec;
668-
// spec = sdk;
669-
// }
669+
// This file is .gitignore'd, and fetched by `npm run fetch:spec-types` (called by `npm run test`)
670+
const SPEC_TYPES_FILE = 'src/spec.types.ts';
671+
const SDK_TYPES_FILE = 'src/types.ts';
670672

671-
// TODO(bug): missing type in SDK. This dead code is checked by the test suite below.
672-
// function checkModelPreferences(
673-
// RemovePassthrough< sdk: SDKTypes.ModelPreferences>,
674-
// spec: SpecTypes.ModelPreferences
675-
// ) {
676-
// sdk = spec;
677-
// spec = sdk;
678-
// }
673+
const MISSING_SDK_TYPES = [
674+
// These are inlined in the SDK:
675+
'Role',
679676

680-
// TODO(bug): missing type in SDK. This dead code is checked by the test suite below.
681-
// function checkAnnotations(
682-
// RemovePassthrough< sdk: SDKTypes.Annotations>,
683-
// spec: SpecTypes.Annotations
684-
// ) {
685-
// sdk = spec;
686-
// spec = sdk;
687-
// }
677+
// These aren't supported by the SDK yet:
678+
// TODO: Add definitions to the SDK
679+
'ModelHint',
680+
'ModelPreferences',
681+
'Annotations',
682+
]
688683

689-
// This file is .gitignore'd, and fetched by `npm run fetch:spec-types` (called by `npm run test`)
690-
const SPEC_TYPES_FILE = 'src/spec.types.ts';
691-
const THIS_SOURCE_FILE = 'src/spec.types.test.ts';
684+
function extractExportedTypes(source: string): string[] {
685+
return [...source.matchAll(/export\s+(?:interface|class|type)\s+(\w+)\b/g)].map(m => m[1]);
686+
}
692687

693688
describe('Spec Types', () => {
694-
const specTypesContent = fs.readFileSync(SPEC_TYPES_FILE, 'utf-8');
695-
const typeNames = [...specTypesContent.matchAll(/export\s+interface\s+(\w+)\b/g)].map(m => m[1]);
696-
const testContent = fs.readFileSync(THIS_SOURCE_FILE, 'utf-8');
689+
const specTypes = extractExportedTypes(fs.readFileSync(SPEC_TYPES_FILE, 'utf-8'));
690+
const sdkTypes = extractExportedTypes(fs.readFileSync(SDK_TYPES_FILE, 'utf-8'));
691+
const testSource = fs.readFileSync(__filename, 'utf-8');
697692

698693
it('should define some expected types', () => {
699-
expect(typeNames).toContain('JSONRPCNotification');
700-
expect(typeNames).toContain('ElicitResult');
694+
expect(specTypes).toContain('JSONRPCNotification');
695+
expect(specTypes).toContain('ElicitResult');
696+
});
697+
698+
it('should have up to date list of missing sdk types', () => {
699+
for (const typeName of MISSING_SDK_TYPES) {
700+
expect(sdkTypes).not.toContain(typeName);
701+
}
701702
});
702703

703-
for (const typeName of typeNames) {
704-
it(`${typeName} should have a compatibility test`, () => {
705-
expect(testContent).toContain(`function check${typeName}(`);
704+
for (const type of specTypes) {
705+
if (MISSING_SDK_TYPES.includes(type)) {
706+
continue; // Skip missing SDK types
707+
}
708+
it(`${type} should have a compatibility test`, () => {
709+
expect(testSource).toContain(`function check${type}(`);
706710
});
707711
}
708712
});

0 commit comments

Comments
 (0)