-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpreflight.test.js
More file actions
107 lines (100 loc) · 3.75 KB
/
Copy pathpreflight.test.js
File metadata and controls
107 lines (100 loc) · 3.75 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { checkEngines, installPlan } from '../src/steps/preflight.js';
// The engines probe is informational by contract: with NOTHING on PATH it must
// still resolve (no prompt, no process.exit) and record the status in ctx.
// A reintroduced gate would hang or kill this run — that's the guard.
test('checkEngines: never blocks — resolves and records status even with no engine on PATH', async () => {
const originalPath = process.env.PATH;
process.env.PATH = '';
const ctx = {};
try {
await checkEngines(ctx);
} finally {
process.env.PATH = originalPath;
}
assert.equal(ctx.engines.claude, false);
assert.equal(typeof ctx.engines.codex, 'boolean');
});
// `installPlan` depends on the OS via osKind() (reads process.platform), so we
// pin the platform in each case.
function onPlatform(value, fn) {
const original = Object.getOwnPropertyDescriptor(process, 'platform');
Object.defineProperty(process, 'platform', { value, configurable: true });
try {
return fn();
} finally {
Object.defineProperty(process, 'platform', original);
}
}
test('installPlan: gh on apt uses the official repository, not `apt-get install gh`', () => {
const plan = onPlatform('linux', () => installPlan('gh', { 'apt-get': true }));
assert.equal(plan.bin, 'bash');
const script = plan.args[1];
// The bug was exactly this command — `gh` doesn't exist in the Debian repos.
assert.ok(!/apt-get install -y gh\s*$/m.test(script) || /cli\.github\.com/.test(script));
assert.match(script, /cli\.github\.com\/packages/, 'must register the GitHub CLI source');
assert.match(script, /githubcli-archive-keyring\.gpg/, 'must register the signed key');
assert.match(script, /apt-get update/, 'update before install');
assert.match(script, /apt-get install -y gh/);
});
test('installPlan: git on apt runs update before install', () => {
const plan = onPlatform('linux', () => installPlan('git', { 'apt-get': true }));
assert.equal(plan.bin, 'bash');
assert.match(plan.args[1], /apt-get update;\s*sudo apt-get install -y git/);
});
test('installPlan: git on windows uses winget (Git.Git) or choco as fallback', () => {
assert.deepEqual(
onPlatform('win32', () => installPlan('git', { winget: true })),
{
bin: 'winget',
args: ['install', '--id', 'Git.Git', '-e', '--source', 'winget'],
},
);
assert.deepEqual(
onPlatform('win32', () => installPlan('git', { choco: true })),
{
bin: 'choco',
args: ['install', 'git', '-y'],
},
);
// gh on winget has its own id.
assert.equal(onPlatform('win32', () => installPlan('gh', { winget: true })).args[2], 'GitHub.cli');
});
test('installPlan: git on mac without brew → null (manual path suggests xcode-select)', () => {
// The step then instructs `xcode-select --install` via manualHint — a Mac
// without Homebrew still has the native CLT route for git.
assert.equal(
onPlatform('darwin', () => installPlan('git', {})),
null,
);
});
test('installPlan: non-apt paths stay unchanged', () => {
assert.deepEqual(
onPlatform('darwin', () => installPlan('gh', { brew: true })),
{
bin: 'brew',
args: ['install', 'gh'],
},
);
assert.deepEqual(
onPlatform('linux', () => installPlan('gh', { dnf: true })),
{
bin: 'sudo',
args: ['dnf', 'install', '-y', 'gh'],
},
);
// vercel has no formula: npm global on every OS.
assert.deepEqual(
onPlatform('linux', () => installPlan('vercel', { 'apt-get': true })),
{
bin: 'npm',
args: ['install', '-g', 'vercel'],
},
);
// No known package manager → null (the step instructs manually).
assert.equal(
onPlatform('linux', () => installPlan('gh', {})),
null,
);
});