From 0c28013167986d6e411ad73258bed41c0993ba3f Mon Sep 17 00:00:00 2001 From: cafitac Date: Wed, 29 Apr 2026 18:24:52 +0900 Subject: [PATCH] fix: delegate wrapper subcommand help to core cli --- lib/wrapper.cjs | 7 ++++++- test/npm-wrapper.test.cjs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/wrapper.cjs b/lib/wrapper.cjs index 4bd1e7d..4aa7113 100644 --- a/lib/wrapper.cjs +++ b/lib/wrapper.cjs @@ -85,9 +85,13 @@ Environment overrides: - AI_CRAWLER_UVX_PYTHON Override uvx Python version (default: 3.11)`); } +function shouldPrintWrapperHelp(args) { + return args.length === 0 || (args.length === 1 && (args[0] === '--help' || args[0] === '-h' || args[0] === 'help')); +} + function runCli(argv, options = {}) { const args = Array.isArray(argv) ? argv : []; - if (args.includes('--help') || args.includes('-h') || args[0] === 'help') { + if (shouldPrintWrapperHelp(args)) { printHelp(options.packageRoot || packageRootFromModuleDir()); return 0; } @@ -133,4 +137,5 @@ module.exports = { publishedPythonSpec, readPackageMetadata, runCli, + shouldPrintWrapperHelp, }; diff --git a/test/npm-wrapper.test.cjs b/test/npm-wrapper.test.cjs index 209ac43..1a92d83 100644 --- a/test/npm-wrapper.test.cjs +++ b/test/npm-wrapper.test.cjs @@ -89,6 +89,40 @@ test('readPackageMetadata loads wrapper metadata gitHead when present', () => { assert.deepEqual(metadata, {version: '0.1.1', gitHead: 'abc123'}); }); +test('runCli prints wrapper help for top-level --help without spawning the core CLI', () => { + const calls = []; + const exitCode = wrapper.runCli(['--help'], { + packageRoot: '/repo/ai-crawler', + spawnSync: (...args) => { + calls.push(args); + return {status: 0}; + }, + }); + + assert.equal(exitCode, 0); + assert.deepEqual(calls, []); +}); + +test('runCli delegates subcommand --help to the core CLI', () => { + const calls = []; + const exitCode = wrapper.runCli(['mcp-config', '--help'], { + packageRoot: '/repo/ai-crawler', + localCoreAvailable: true, + spawnSync: (executable, args) => { + calls.push({executable, args}); + return {status: 0}; + }, + }); + + assert.equal(exitCode, 0); + assert.deepEqual(calls, [ + { + executable: 'uv', + args: ['run', '--project', '/repo/ai-crawler', 'ai-crawler', 'mcp-config', '--help'], + }, + ]); +}); + test('packageRootFromModuleDir resolves package root from lib directory', () => { const packageRoot = wrapper.packageRootFromModuleDir(path.join('/repo/ai-crawler', 'lib')); assert.equal(packageRoot, '/repo/ai-crawler');