update-cmd.test.js
1 'use strict' 2 /* eslint-disable @typescript-eslint/no-require-imports */ 3 4 const test = require('node:test') 5 const assert = require('node:assert/strict') 6 7 const { runRegistrySelfUpdate } = require('./update-cmd.js') 8 9 test('runRegistrySelfUpdate executes the manager-specific global update command', () => { 10 const messages = [] 11 const captured = [] 12 13 const exitCode = runRegistrySelfUpdate( 14 'pnpm', 15 (command, args, options) => { 16 captured.push({ command, args, options }) 17 }, 18 { 19 log: (message) => messages.push(`log:${message}`), 20 logError: (message) => messages.push(`err:${message}`), 21 }, 22 ) 23 24 assert.equal(exitCode, 0) 25 assert.deepEqual(captured, [ 26 { 27 command: 'pnpm', 28 args: ['add', '-g', '@swarmclawai/swarmclaw@latest'], 29 options: { 30 cwd: process.cwd(), 31 stdio: 'inherit', 32 timeout: 120_000, 33 }, 34 }, 35 ]) 36 assert.match(messages.join('\n'), /updating the global @swarmclawai\/swarmclaw install via pnpm/i) 37 assert.match(messages.join('\n'), /global update complete via pnpm/i) 38 }) 39 40 test('runRegistrySelfUpdate reports a manual retry command when the registry update fails', () => { 41 const messages = [] 42 43 const exitCode = runRegistrySelfUpdate( 44 'bun', 45 () => { 46 throw new Error('spawn bun ENOENT') 47 }, 48 { 49 log: (message) => messages.push(`log:${message}`), 50 logError: (message) => messages.push(`err:${message}`), 51 }, 52 ) 53 54 assert.equal(exitCode, 1) 55 assert.match(messages.join('\n'), /registry update failed: spawn bun ENOENT/i) 56 assert.match(messages.join('\n'), /retry manually with: bun add -g @swarmclawai\/swarmclaw@latest/i) 57 })