Skip to content
Merged
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
7 changes: 6 additions & 1 deletion lib/wrapper.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -133,4 +137,5 @@ module.exports = {
publishedPythonSpec,
readPackageMetadata,
runCli,
shouldPrintWrapperHelp,
};
34 changes: 34 additions & 0 deletions test/npm-wrapper.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Loading