Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions src/filesystem/__tests__/dependencies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { builtinModules } from 'module';

/**
* Guards against phantom dependencies: modules that are imported by the shipped
* source but not declared in package.json. Such imports resolve by accident
* under npm's hoisted node_modules layout, then fail at startup for anyone
* using a strict layout (pnpm, yarn PnP) with ERR_MODULE_NOT_FOUND.
*/
describe('declared dependencies', () => {
const packageDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');

const packageJson = JSON.parse(
readFileSync(path.join(packageDir, 'package.json'), 'utf-8')
) as { dependencies?: Record<string, string> };

// Source files that get compiled into dist/, i.e. everything except tests and configs.
const sourceFiles = readdirSync(packageDir)
.filter((file) => file.endsWith('.ts'))
.filter((file) => !file.endsWith('.test.ts') && file !== 'vitest.config.ts');

const IMPORT_PATTERN = /(?:import|export)[\s\S]*?from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;

/** Reduces a specifier like `zod/v4` or `@scope/pkg/sub` to its package name. */
const toPackageName = (specifier: string): string => {
const segments = specifier.split('/');
return specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
};

const isBareSpecifier = (specifier: string): boolean =>
!specifier.startsWith('.') &&
!specifier.startsWith('node:') &&
!builtinModules.includes(toPackageName(specifier));

it('finds source files to check', () => {
expect(sourceFiles.length).toBeGreaterThan(0);
});

it.each(sourceFiles)('%s imports only declared packages', (file) => {
const contents = readFileSync(path.join(packageDir, file), 'utf-8');
const declared = Object.keys(packageJson.dependencies ?? {});

const imported = new Set<string>();
for (const match of contents.matchAll(IMPORT_PATTERN)) {
const specifier = match[1] ?? match[2];
if (specifier && isBareSpecifier(specifier)) {
imported.add(toPackageName(specifier));
}
}

expect(declared).toEqual(expect.arrayContaining([...imported]));
});
});
3 changes: 2 additions & 1 deletion src/filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"@modelcontextprotocol/sdk": "^1.29.0",
"diff": "^8.0.3",
"glob": "^10.5.0",
"minimatch": "^10.0.1"
"minimatch": "^10.0.1",
"zod": "^4.0.0"
},
"devDependencies": {
"@types/diff": "^5.0.9",
Expand Down
56 changes: 56 additions & 0 deletions src/memory/__tests__/dependencies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { builtinModules } from 'module';

/**
* Guards against phantom dependencies: modules that are imported by the shipped
* source but not declared in package.json. Such imports resolve by accident
* under npm's hoisted node_modules layout, then fail at startup for anyone
* using a strict layout (pnpm, yarn PnP) with ERR_MODULE_NOT_FOUND.
*/
describe('declared dependencies', () => {
const packageDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');

const packageJson = JSON.parse(
readFileSync(path.join(packageDir, 'package.json'), 'utf-8')
) as { dependencies?: Record<string, string> };

// Source files that get compiled into dist/, i.e. everything except tests and configs.
const sourceFiles = readdirSync(packageDir)
.filter((file) => file.endsWith('.ts'))
.filter((file) => !file.endsWith('.test.ts') && file !== 'vitest.config.ts');

const IMPORT_PATTERN = /(?:import|export)[\s\S]*?from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;

/** Reduces a specifier like `zod/v4` or `@scope/pkg/sub` to its package name. */
const toPackageName = (specifier: string): string => {
const segments = specifier.split('/');
return specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
};

const isBareSpecifier = (specifier: string): boolean =>
!specifier.startsWith('.') &&
!specifier.startsWith('node:') &&
!builtinModules.includes(toPackageName(specifier));

it('finds source files to check', () => {
expect(sourceFiles.length).toBeGreaterThan(0);
});

it.each(sourceFiles)('%s imports only declared packages', (file) => {
const contents = readFileSync(path.join(packageDir, file), 'utf-8');
const declared = Object.keys(packageJson.dependencies ?? {});

const imported = new Set<string>();
for (const match of contents.matchAll(IMPORT_PATTERN)) {
const specifier = match[1] ?? match[2];
if (specifier && isBareSpecifier(specifier)) {
imported.add(toPackageName(specifier));
}
}

expect(declared).toEqual(expect.arrayContaining([...imported]));
});
});
3 changes: 2 additions & 1 deletion src/memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"test": "vitest run --coverage"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0"
"@modelcontextprotocol/sdk": "^1.29.0",
"zod": "^4.0.0"
},
"devDependencies": {
"@types/node": "^22",
Expand Down
56 changes: 56 additions & 0 deletions src/sequentialthinking/__tests__/dependencies.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { builtinModules } from 'module';

/**
* Guards against phantom dependencies: modules that are imported by the shipped
* source but not declared in package.json. Such imports resolve by accident
* under npm's hoisted node_modules layout, then fail at startup for anyone
* using a strict layout (pnpm, yarn PnP) with ERR_MODULE_NOT_FOUND.
*/
describe('declared dependencies', () => {
const packageDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');

const packageJson = JSON.parse(
readFileSync(path.join(packageDir, 'package.json'), 'utf-8')
) as { dependencies?: Record<string, string> };

// Source files that get compiled into dist/, i.e. everything except tests and configs.
const sourceFiles = readdirSync(packageDir)
.filter((file) => file.endsWith('.ts'))
.filter((file) => !file.endsWith('.test.ts') && file !== 'vitest.config.ts');

const IMPORT_PATTERN = /(?:import|export)[\s\S]*?from\s*['"]([^'"]+)['"]|import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;

/** Reduces a specifier like `zod/v4` or `@scope/pkg/sub` to its package name. */
const toPackageName = (specifier: string): string => {
const segments = specifier.split('/');
return specifier.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
};

const isBareSpecifier = (specifier: string): boolean =>
!specifier.startsWith('.') &&
!specifier.startsWith('node:') &&
!builtinModules.includes(toPackageName(specifier));

it('finds source files to check', () => {
expect(sourceFiles.length).toBeGreaterThan(0);
});

it.each(sourceFiles)('%s imports only declared packages', (file) => {
const contents = readFileSync(path.join(packageDir, file), 'utf-8');
const declared = Object.keys(packageJson.dependencies ?? {});

const imported = new Set<string>();
for (const match of contents.matchAll(IMPORT_PATTERN)) {
const specifier = match[1] ?? match[2];
if (specifier && isBareSpecifier(specifier)) {
imported.add(toPackageName(specifier));
}
}

expect(declared).toEqual(expect.arrayContaining([...imported]));
});
});
3 changes: 2 additions & 1 deletion src/sequentialthinking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0",
"chalk": "^5.3.0",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"zod": "^4.0.0"
},
"devDependencies": {
"@types/node": "^22",
Expand Down
Loading