Files
ECC/tests/skills/mcp-dependency-review.test.js
T

105 lines
4.7 KiB
JavaScript

'use strict';
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..', '..');
const canonicalPath = path.join(repoRoot, 'skills', 'mcp-dependency-review', 'SKILL.md');
const codexPath = path.join(repoRoot, '.agents', 'skills', 'mcp-dependency-review', 'SKILL.md');
const cursorPath = path.join(repoRoot, '.cursor', 'skills', 'mcp-dependency-review', 'SKILL.md');
let passed = 0;
let failed = 0;
function test(name, fn) {
try {
fn();
console.log(` ✓ ${name}`);
passed += 1;
} catch (error) {
console.log(` ✗ ${name}`);
console.log(` Error: ${error.message}`);
failed += 1;
}
}
function body(markdown) {
return markdown.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, '').trim();
}
const canonical = fs.readFileSync(canonicalPath, 'utf8');
const codex = fs.readFileSync(codexPath, 'utf8');
const cursor = fs.readFileSync(cursorPath, 'utf8');
console.log('\n=== MCP dependency review skill tests ===\n');
test('has a focused activation surface for MCP config review', () => {
const frontmatter = canonical.match(/^---\n([\s\S]*?)\n---/);
assert.ok(frontmatter, 'SKILL.md frontmatter is missing');
assert.match(frontmatter[1], /name:\s*mcp-dependency-review/);
assert.match(frontmatter[1], /description:.*statically review MCP configuration/i);
assert.match(canonical, /## When to Activate/);
assert.match(canonical, /\.mcp\.json/);
});
test('keeps a zero-execution and bounded-scope security boundary', () => {
assert.match(canonical, /Do not execute discovered MCP server commands/i);
assert.match(canonical, /Do not inspect home-directory or machine-wide MCP configuration unless the user explicitly requests/i);
assert.match(canonical, /do not:\s*[\s\S]*run a `command` or `args` value/i);
assert.match(canonical, /never execute the discovered command/i);
assert.match(canonical, /No MCP servers were executed during this review/i);
});
test('classifies mutable selectors without treating them as compromise evidence', () => {
assert.match(canonical, /`package@1\.2\.3`\s*\| SAFE/);
assert.match(canonical, /`package`\s*\| HIGH/);
assert.match(canonical, /`package@latest`\s*\| HIGH/);
assert.match(canonical, /`package@\^1\.2\.0`\s*\| MEDIUM/);
assert.match(canonical, /local path \/ script \/ unknown binary\s*\| REVIEW/);
assert.match(canonical, /not breach claims/i);
assert.match(canonical, /describe dependency mutability alone as proof of a vulnerability, compromise, or malicious package/i);
});
test('covers Docker and Python selectors without silently skipping ambiguous invocations', () => {
const rows = canonical.split('\n').filter(line => line.startsWith('| '));
const cases = [
['Docker image pinned by', 'SAFE'],
['Docker image with a tag or no tag and no digest', 'HIGH'],
['Python exact version', 'SAFE'],
['Python package without a version', 'HIGH'],
['Python version range or wildcard', 'MEDIUM'],
['Python editable / direct URL / VCS reference', 'REVIEW'],
];
for (const [selector, result] of cases) {
assert.ok(rows.some(row => row.includes(selector) && row.includes(`| ${result} |`)),
`${selector} must have an explicit ${result} classification`);
}
assert.match(canonical, /`docker run`.*`docker container run`/);
assert.match(canonical, /image separately from Docker options and the in-container command/i);
assert.match(canonical, /`uvx --from example-tool==1\.2\.3 example-command`/);
assert.match(canonical, /`pipx run --spec example-tool==1\.2\.3 example-command`/);
assert.match(canonical, /`--from=SPEC`.*`--spec=SPEC`/);
assert.match(canonical, /unsupported or ambiguous.*REVIEW.*never omit/i);
assert.match(canonical, /package integrity, provenance, or full transitive dependency reproducibility/i);
});
test('does not recommend substituting an arbitrary current latest version', () => {
assert.match(canonical, /Do \*\*not\*\* invent a pin by substituting today's latest registry version/i);
assert.match(canonical, /pin a version the team has reviewed/i);
assert.match(canonical, /registry-history lookup is a separate network operation/i);
});
test('keeps the external reference optional rather than making it a dependency', () => {
assert.match(canonical, /external project is optional/i);
assert.match(canonical, /does not require it to perform the static review/i);
});
test('keeps the same review workflow across ECC, Codex, and Cursor surfaces', () => {
assert.strictEqual(body(codex), body(canonical));
assert.strictEqual(body(cursor), body(canonical));
assert.match(codex, /license:\s*MIT/);
assert.match(cursor, /origin:\s*ECC/);
});
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);