-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell.test.ts
More file actions
56 lines (47 loc) · 1.79 KB
/
Copy pathshell.test.ts
File metadata and controls
56 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as fs from 'node:fs/promises';
import * as os from 'node:os';
import * as path from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { ShellValidationError } from '../common/errors.js';
import { ShellUtils } from './shell.js';
describe('ShellUtils.validateShell', () => {
it('passes on a clean shell', async () => {
await expect(ShellUtils.validateShell()).resolves.toBeUndefined();
});
describe('dirty output', () => {
let originalShell: string | undefined;
let tmpScript: string;
beforeEach(async () => {
originalShell = process.env.SHELL;
// Write a wrapper script that prints unexpected output before delegating
const realShell = originalShell ?? '/bin/sh';
tmpScript = path.join(os.tmpdir(), `codify-test-shell-${Date.now()}.sh`);
await fs.writeFile(
tmpScript,
`#!/bin/sh\necho "unexpected banner output"\nexec ${realShell} "$@"\n`,
{ mode: 0o755 },
);
process.env.SHELL = tmpScript;
});
afterEach(async () => {
process.env.SHELL = originalShell;
await fs.unlink(tmpScript).catch(() => {});
});
it('throws ShellValidationError with timedOut=false when shell emits unexpected output', async () => {
await expect(ShellUtils.validateShell()).rejects.toMatchObject({
name: 'ShellValidationError',
timedOut: false,
});
});
it('includes the unexpected output in the error', async () => {
try {
await ShellUtils.validateShell();
expect.fail('should have thrown');
} catch (err) {
expect(err).toBeInstanceOf(ShellValidationError);
const shellErr = err as ShellValidationError;
expect(shellErr.capturedOutput).toContain('unexpected banner output');
}
});
});
});