mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-23 16:41:22 +08:00
fix: add plugin cache health check (#2249)
* fix: add plugin cache health check * fix: harden plugin cache diagnostics * fix: reject escaping plugin cache refs * test: remove unused plugin cache fixture
This commit is contained in:
@@ -11,9 +11,12 @@ const TOML = require('@iarna/toml');
|
||||
|
||||
const repoRoot = path.join(__dirname, '..', '..');
|
||||
const installScript = path.join(repoRoot, 'scripts', 'codex', 'install-global-git-hooks.sh');
|
||||
const pluginCacheCheckScript = path.join(repoRoot, 'scripts', 'codex', 'check-plugin-cache.js');
|
||||
const mergeCodexConfigScript = path.join(repoRoot, 'scripts', 'codex', 'merge-codex-config.js');
|
||||
const mergeMcpConfigScript = path.join(repoRoot, 'scripts', 'codex', 'merge-mcp-config.js');
|
||||
const syncScript = path.join(repoRoot, 'scripts', 'sync-ecc-to-codex.sh');
|
||||
const packageJson = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
|
||||
const packageVersion = packageJson.version;
|
||||
const deterministicPackageEnv = {
|
||||
CLAUDE_PACKAGE_MANAGER: 'npm',
|
||||
CLAUDE_CODE_PACKAGE_MANAGER: 'npm',
|
||||
@@ -82,9 +85,177 @@ function makeHermeticCodexEnv(homeDir, codexDir, extraEnv = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function writeJson(filePath, value) {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
|
||||
}
|
||||
|
||||
function seedPluginCache(codexDir, manifest, files = []) {
|
||||
const cacheDir = path.join(codexDir, 'plugins', 'cache', 'ecc', 'ecc', packageVersion);
|
||||
writeJson(path.join(cacheDir, '.codex-plugin', 'plugin.json'), manifest);
|
||||
fs.writeFileSync(path.join(cacheDir, 'README.md'), '# cached plugin\n');
|
||||
for (const [relativePath, content] of files) {
|
||||
const target = path.join(cacheDir, relativePath);
|
||||
fs.mkdirSync(path.dirname(target), { recursive: true });
|
||||
fs.writeFileSync(target, content);
|
||||
}
|
||||
return cacheDir;
|
||||
}
|
||||
|
||||
const cacheManifestWithLocalRefs = {
|
||||
name: 'ecc',
|
||||
version: packageVersion,
|
||||
skills: './skills/',
|
||||
mcpServers: './.mcp.json',
|
||||
interface: {
|
||||
composerIcon: './assets/ecc-icon.svg',
|
||||
logo: './assets/hero.png',
|
||||
},
|
||||
};
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
if (
|
||||
test('check-plugin-cache fails when the installed cache is missing manifest-referenced files', () => {
|
||||
const homeDir = createTempDir('codex-plugin-cache-home-');
|
||||
const codexDir = path.join(homeDir, '.codex');
|
||||
|
||||
try {
|
||||
seedPluginCache(codexDir, cacheManifestWithLocalRefs);
|
||||
const result = runNode(pluginCacheCheckScript, [], makeHermeticCodexEnv(homeDir, codexDir));
|
||||
|
||||
assert.strictEqual(result.status, 1, `${result.stdout}\n${result.stderr}`);
|
||||
assert.match(result.stdout, /Plugin cache:/);
|
||||
assert.match(result.stdout, /\[FAIL\] skills missing/);
|
||||
assert.match(result.stdout, /\[FAIL\] mcpServers missing/);
|
||||
assert.match(result.stdout, /codex plugin list only confirms marketplace registration/);
|
||||
assert.match(result.stdout, /sync-ecc-to-codex\.sh/);
|
||||
} finally {
|
||||
cleanup(homeDir);
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('check-plugin-cache rejects manifest references that escape the cache boundary', () => {
|
||||
const homeDir = createTempDir('codex-plugin-cache-manifest-traversal-home-');
|
||||
const codexDir = path.join(homeDir, '.codex');
|
||||
|
||||
try {
|
||||
seedPluginCache(codexDir, {
|
||||
name: 'ecc',
|
||||
version: packageVersion,
|
||||
skills: '../../../../../etc/passwd',
|
||||
mcpServers: '../../.mcp.json',
|
||||
});
|
||||
const result = runNode(pluginCacheCheckScript, [], makeHermeticCodexEnv(homeDir, codexDir));
|
||||
|
||||
assert.strictEqual(result.status, 1, `${result.stdout}\n${result.stderr}`);
|
||||
assert.match(result.stdout, /\[FAIL\] skills escapes cache boundary/);
|
||||
assert.match(result.stdout, /\[FAIL\] mcpServers escapes cache boundary/);
|
||||
assert.doesNotMatch(result.stdout, /etc\/passwd/);
|
||||
} finally {
|
||||
cleanup(homeDir);
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('check-plugin-cache passes when cached manifest references resolve inside the cache', () => {
|
||||
const homeDir = createTempDir('codex-plugin-cache-ok-home-');
|
||||
const codexDir = path.join(homeDir, '.codex');
|
||||
|
||||
try {
|
||||
const cacheDir = seedPluginCache(codexDir, cacheManifestWithLocalRefs, [
|
||||
['.mcp.json', '{"mcpServers":{}}\n'],
|
||||
['assets/ecc-icon.svg', '<svg />\n'],
|
||||
['assets/hero.png', 'png\n'],
|
||||
]);
|
||||
fs.mkdirSync(path.join(cacheDir, 'skills'), { recursive: true });
|
||||
|
||||
const result = runNode(pluginCacheCheckScript, [], makeHermeticCodexEnv(homeDir, codexDir));
|
||||
|
||||
assert.strictEqual(result.status, 0, `${result.stdout}\n${result.stderr}`);
|
||||
assert.match(result.stdout, /\[OK\] skills/);
|
||||
assert.match(result.stdout, /\[OK\] mcpServers/);
|
||||
assert.match(result.stdout, /All cached manifest references resolve/);
|
||||
} finally {
|
||||
cleanup(homeDir);
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('check-plugin-cache reports a missing installed cache clearly', () => {
|
||||
const homeDir = createTempDir('codex-plugin-cache-missing-home-');
|
||||
const codexDir = path.join(homeDir, '.codex');
|
||||
|
||||
try {
|
||||
const result = runNode(pluginCacheCheckScript, [], makeHermeticCodexEnv(homeDir, codexDir));
|
||||
|
||||
assert.strictEqual(result.status, 1, `${result.stdout}\n${result.stderr}`);
|
||||
assert.match(result.stdout, /Cached plugin manifest missing/);
|
||||
assert.match(result.stdout, /codex plugin marketplace add affaan-m\/ECC/);
|
||||
} finally {
|
||||
cleanup(homeDir);
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('check-plugin-cache rejects traversal in cache path segments', () => {
|
||||
const homeDir = createTempDir('codex-plugin-cache-traversal-home-');
|
||||
const codexDir = path.join(homeDir, '.codex');
|
||||
|
||||
try {
|
||||
const result = runNode(
|
||||
pluginCacheCheckScript,
|
||||
['--marketplace', '../outside'],
|
||||
makeHermeticCodexEnv(homeDir, codexDir)
|
||||
);
|
||||
|
||||
assert.strictEqual(result.status, 1, `${result.stdout}\n${result.stderr}`);
|
||||
assert.match(result.stderr, /Invalid --marketplace/);
|
||||
} finally {
|
||||
cleanup(homeDir);
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
if (
|
||||
test('check-plugin-cache names custom missing cache entries in diagnostics', () => {
|
||||
const homeDir = createTempDir('codex-plugin-cache-custom-home-');
|
||||
const codexDir = path.join(homeDir, '.codex');
|
||||
|
||||
try {
|
||||
const result = runNode(
|
||||
pluginCacheCheckScript,
|
||||
['--marketplace', 'custom-market', '--plugin', 'custom-plugin', '--version', '1.2.3'],
|
||||
makeHermeticCodexEnv(homeDir, codexDir)
|
||||
);
|
||||
|
||||
assert.strictEqual(result.status, 1, `${result.stdout}\n${result.stderr}`);
|
||||
assert.match(result.stdout, /No installed cache entries found for custom-market\/custom-plugin/);
|
||||
assert.match(result.stdout, /Install the requested plugin into the Codex plugin cache/);
|
||||
} finally {
|
||||
cleanup(homeDir);
|
||||
}
|
||||
})
|
||||
)
|
||||
passed++;
|
||||
else failed++;
|
||||
|
||||
// Windows NTFS does not allow double-quote characters in file paths,
|
||||
// so the quoted-path shell-injection test is only meaningful on Unix.
|
||||
if (os.platform() === 'win32') {
|
||||
|
||||
@@ -69,6 +69,7 @@ function buildExpectedPublishPaths(repoRoot) {
|
||||
"scripts/session-inspect.js",
|
||||
"scripts/uninstall.js",
|
||||
"scripts/gemini-adapt-agents.js",
|
||||
"scripts/codex/check-plugin-cache.js",
|
||||
"scripts/codex/merge-codex-config.js",
|
||||
"scripts/codex/merge-mcp-config.js",
|
||||
".codex-plugin",
|
||||
@@ -141,6 +142,7 @@ function main() {
|
||||
"scripts/release-video-suite.js",
|
||||
"scripts/work-items.js",
|
||||
"scripts/platform-audit.js",
|
||||
"scripts/codex/check-plugin-cache.js",
|
||||
".gemini/GEMINI.md",
|
||||
".qwen/QWEN.md",
|
||||
".claude-plugin/plugin.json",
|
||||
|
||||
Reference in New Issue
Block a user