fix: keep validator providers off root declarations (#2425)

Co-authored-by: Sehlani042 <257166922+Sehlani042@users.noreply.github.com>
This commit is contained in:
Sehlani042 2026-07-07 02:34:24 +08:00 • committed by GitHub
commit e8de519d31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ const requireDist = createRequire(join(pkgDir, 'package.json'));
const NODE_ONLY = /\b(child_process|cross-spawn|node:stream|node:child_process)\b/;
// Anchored at start-of-line so JSDoc-example `from 'ajv'` strings in vendored chunks don't match.
const VALIDATOR_BACKEND_IMPORT = /^import[^\n]*?from\s+["'](?:ajv|ajv-formats|@cfworker\/json-schema)["']/m;
const ROOT_VALIDATOR_EXPORTS = ['AjvJsonSchemaValidator', 'CfWorkerJsonSchemaValidator', 'CfWorkerSchemaDraft'];
function chunkImportsOf(entryPath: string): string[] {
const visited = new Set<string>();
@ -29,6 +30,12 @@ function chunkImportsOf(entryPath: string): string[] {
return [...visited];
}
function rootExportBlockOf(content: string): string {
const blocks = content.match(/(?:^|\n)export \{[\s\S]*?\};/g);
expect(blocks).toBeTruthy();
return blocks!.at(-1)!;
}
describe('@modelcontextprotocol/server root entry is browser-safe', () => {
beforeAll(() => {
if (!existsSync(join(distDir, 'index.mjs')) || !existsSync(join(distDir, 'stdio.mjs'))) {
@ -81,4 +88,13 @@ describe('@modelcontextprotocol/server root entry is browser-safe', () => {
expect(new AjvJsonSchemaValidator(ajv)).toBeInstanceOf(AjvJsonSchemaValidator);
});
test('root declarations do not advertise validator provider classes', () => {
for (const declaration of ['index.d.mts', 'index.d.cts']) {
const rootExportBlock = rootExportBlockOf(readFileSync(join(distDir, declaration), 'utf8'));
for (const symbol of ROOT_VALIDATOR_EXPORTS) {
expect(rootExportBlock).not.toMatch(new RegExp(`\\b(?:type\\s+)?${symbol}\\b`));
}
}
});
});