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
6 changes: 4 additions & 2 deletions lib/wrapper.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,10 @@ function printDoctor(report, jsonMode = false) {
}
}

function runWrapperUpdate(stdio = 'inherit', runner = spawnSync) {
const result = runner('npm', ['install', '-g', '@cafitac/agent-learner@latest'], {
function runWrapperUpdate(stdio = 'inherit', runner = spawnSync, nodeExecutable = process.execPath) {
const siblingNpm = path.join(path.dirname(nodeExecutable), process.platform === 'win32' ? 'npm.cmd' : 'npm');
const tool = fs.existsSync(siblingNpm) ? siblingNpm : 'npm';
const result = runner(tool, ['install', '-g', '@cafitac/agent-learner@latest'], {
stdio,
encoding: 'utf-8'
});
Expand Down
17 changes: 14 additions & 3 deletions test/wrapper.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,23 @@ test('printHelp advertises bootstrap as the install path', () => {
assert.doesNotMatch(output, /install-claude/);
});

test('runWrapperUpdate shells out to npm global install', () => {
test('runWrapperUpdate prefers the npm next to the active node executable', () => {
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-learner-wrapper-update-'));
const binDir = path.join(tempRoot, 'bin');
fs.mkdirSync(binDir, { recursive: true });
const nodeExecutable = path.join(binDir, process.platform === 'win32' ? 'node.exe' : 'node');
const npmExecutable = path.join(binDir, process.platform === 'win32' ? 'npm.cmd' : 'npm');
fs.writeFileSync(nodeExecutable, '');
fs.writeFileSync(npmExecutable, '');

const calls = [];
const fakeRunner = (tool, args) => {
calls.push({ tool, args });
return { status: 0, stdout: '', stderr: '' };
};
assert.equal(runWrapperUpdate('pipe', fakeRunner), 0);
assert.deepEqual(calls[0], { tool: 'npm', args: ['install', '-g', '@cafitac/agent-learner@latest'] });
assert.equal(runWrapperUpdate('pipe', fakeRunner, nodeExecutable), 0);
assert.deepEqual(calls[0], {
tool: npmExecutable,
args: ['install', '-g', '@cafitac/agent-learner@latest']
});
});
Loading