test: make suites robust in restricted environments

This commit is contained in:
William Valentin
2026-02-15 18:39:39 -08:00
parent 342f22db14
commit ef48a86f80
2 changed files with 108 additions and 4 deletions
+22 -4
View File
@@ -1033,8 +1033,18 @@ describe('skills CLI helpers', () => {
expect(runner.run).toHaveBeenCalledWith(['brew install jq']);
});
it('shell command runner reports succeeded command status', () => {
const runner = createShellSkillInstallerCommandRunner();
it('shell command runner reports succeeded command status', async () => {
// This test must not rely on actually spawning a shell (some sandboxed
// environments disallow spawnSync(/bin/sh) with EPERM).
vi.resetModules();
const mockSpawnSync = vi.fn(() => ({ status: 0, signal: null, error: undefined }));
vi.doMock('child_process', async () => {
const actual = await vi.importActual<typeof import('child_process')>('child_process');
return { ...actual, spawnSync: mockSpawnSync };
});
const mod = await import('./skills.js');
const runner = mod.createShellSkillInstallerCommandRunner();
const results = runner.run(['node -e "process.exit(0)"']);
@@ -1046,8 +1056,16 @@ describe('skills CLI helpers', () => {
]);
});
it('shell command runner reports failed command with exit code reason', () => {
const runner = createShellSkillInstallerCommandRunner();
it('shell command runner reports failed command with exit code reason', async () => {
vi.resetModules();
const mockSpawnSync = vi.fn(() => ({ status: 7, signal: null, error: undefined }));
vi.doMock('child_process', async () => {
const actual = await vi.importActual<typeof import('child_process')>('child_process');
return { ...actual, spawnSync: mockSpawnSync };
});
const mod = await import('./skills.js');
const runner = mod.createShellSkillInstallerCommandRunner();
const results = runner.run(['node -e "process.exit(7)"']);