unbound-cli 1.22.1 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/package.json +1 -1
- package/src/commands/delivery.js +567 -0
- package/src/commands/setup.js +45 -7
- package/src/index.js +10 -0
- package/test/delivery.test.js +591 -0
- package/test/setup-wsl-task.test.js +123 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const { test } = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const { EventEmitter } = require('events');
|
|
4
|
+
const childProcess = require('child_process');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
|
|
9
|
+
const RAW = 'https://raw.githubusercontent.com/websentry-ai/setup/refs/heads/main';
|
|
10
|
+
|
|
11
|
+
// Stands in for mdm/onboard.py: same names the snippet calls, recording instead of touching Windows.
|
|
12
|
+
const FAKE_ONBOARD = `import json, os
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
_RAW_SETUP = ${JSON.stringify(RAW)}
|
|
15
|
+
def _rec(*a): open(os.environ["REC"], "a").write(json.dumps(a) + "\\n")
|
|
16
|
+
def _wsl_dir(): return Path(os.environ["STAGE"])
|
|
17
|
+
def install_wsl_logon_task(urls): _rec("install", urls); return os.environ.get("FAIL") != "1"
|
|
18
|
+
def remove_wsl_logon_task(): _rec("remove"); return True
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
function runSnippet(mode, urls, { fail = false, staged = [] } = {}) {
|
|
22
|
+
const { WSL_TASK_PY } = require('../src/commands/setup');
|
|
23
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'wsl-task-'));
|
|
24
|
+
const stage = path.join(dir, 'stage');
|
|
25
|
+
fs.mkdirSync(stage);
|
|
26
|
+
for (const name of staged) fs.writeFileSync(path.join(stage, name), '');
|
|
27
|
+
fs.writeFileSync(path.join(dir, 'onboard.py'), FAKE_ONBOARD);
|
|
28
|
+
const rec = path.join(dir, 'rec.jsonl');
|
|
29
|
+
const r = childProcess.spawnSync('python3', ['-I', '-c', WSL_TASK_PY, path.join(dir, 'onboard.py'), mode, ...urls], {
|
|
30
|
+
encoding: 'utf8', env: { ...process.env, REC: rec, STAGE: stage, FAIL: fail ? '1' : '' },
|
|
31
|
+
});
|
|
32
|
+
const calls = fs.existsSync(rec) ? fs.readFileSync(rec, 'utf8').trim().split('\n').map((l) => JSON.parse(l)) : [];
|
|
33
|
+
return { status: r.status, stderr: r.stderr, calls, left: fs.readdirSync(stage).sort() };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test('install hands the MDM script URLs to onboard.py unchanged', () => {
|
|
37
|
+
const urls = [`${RAW}/cursor/mdm/setup.py`, `${RAW}/claude-code/hooks/mdm/setup.py`];
|
|
38
|
+
const r = runSnippet('install', urls);
|
|
39
|
+
assert.equal(r.status, 0, r.stderr);
|
|
40
|
+
assert.deepEqual(r.calls, [['install', urls]]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('install fails when onboard.py could not register the task', () => {
|
|
44
|
+
assert.equal(runSnippet('install', [`${RAW}/cursor/mdm/setup.py`], { fail: true }).status, 1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('clearing one tool drops only its staged installer and keeps the task', () => {
|
|
48
|
+
const r = runSnippet('clear', [`${RAW}/cursor/mdm/setup.py`],
|
|
49
|
+
{ staged: ['cursor-setup.py', 'codex-hooks-setup.py', 'run.py'] });
|
|
50
|
+
assert.equal(r.status, 0, r.stderr);
|
|
51
|
+
assert.deepEqual(r.left, ['codex-hooks-setup.py', 'run.py']);
|
|
52
|
+
assert.deepEqual(r.calls, []);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('clearing the last tool removes the task', () => {
|
|
56
|
+
const r = runSnippet('clear', [`${RAW}/codex/hooks/mdm/setup.py`, `${RAW}/codex/gateway/mdm/setup.py`],
|
|
57
|
+
{ staged: ['codex-hooks-setup.py', 'run.py'] });
|
|
58
|
+
assert.equal(r.status, 0, r.stderr);
|
|
59
|
+
assert.deepEqual(r.calls, [['remove']]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Loads setup.js with the network and every child process faked, on the given platform.
|
|
63
|
+
async function mdmBundle(platform, { exits = [0, 0] } = {}) {
|
|
64
|
+
for (const m of ['../src/commands/setup', '../src/utils', '../src/output']) delete require.cache[require.resolve(m)];
|
|
65
|
+
const utils = require('../src/utils');
|
|
66
|
+
const output = require('../src/output');
|
|
67
|
+
const orig = { spawn: childProcess.spawn, spawnSync: childProcess.spawnSync, dl: utils.downloadToFile,
|
|
68
|
+
spinner: output.spinner, platform: Object.getOwnPropertyDescriptor(process, 'platform') };
|
|
69
|
+
const taskCalls = [];
|
|
70
|
+
childProcess.spawnSync = (cmd, args) => {
|
|
71
|
+
if (args.includes('-c')) taskCalls.push(args.slice(args.indexOf('-c') + 3));
|
|
72
|
+
return { status: 0, stdout: '', stderr: '' };
|
|
73
|
+
};
|
|
74
|
+
childProcess.spawn = () => {
|
|
75
|
+
const child = new EventEmitter();
|
|
76
|
+
child.stdin = { on() {}, end() {} };
|
|
77
|
+
child.stdout = new EventEmitter();
|
|
78
|
+
child.stderr = new EventEmitter();
|
|
79
|
+
const code = exits.shift();
|
|
80
|
+
setImmediate(() => child.emit('close', code));
|
|
81
|
+
return child;
|
|
82
|
+
};
|
|
83
|
+
utils.downloadToFile = async () => {};
|
|
84
|
+
output.spinner = () => ({ succeed() {}, fail() {}, stop() {} });
|
|
85
|
+
Object.defineProperty(process, 'platform', { value: platform, configurable: true });
|
|
86
|
+
const exitCode = process.exitCode;
|
|
87
|
+
try {
|
|
88
|
+
const setup = require('../src/commands/setup');
|
|
89
|
+
const result = await setup.runMdmSetupAllBundle('k', { tools: ['cursor', 'codex-subscription'] });
|
|
90
|
+
return { result, taskCalls };
|
|
91
|
+
} finally {
|
|
92
|
+
Object.assign(childProcess, { spawn: orig.spawn, spawnSync: orig.spawnSync });
|
|
93
|
+
utils.downloadToFile = orig.dl;
|
|
94
|
+
output.spinner = orig.spinner;
|
|
95
|
+
Object.defineProperty(process, 'platform', orig.platform);
|
|
96
|
+
process.exitCode = exitCode;
|
|
97
|
+
for (const m of ['../src/commands/setup', '../src/utils', '../src/output']) delete require.cache[require.resolve(m)];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
test('elevated onboard on Windows registers the WSL task for the tools it set up', async () => {
|
|
102
|
+
const { result, taskCalls } = await mdmBundle('win32');
|
|
103
|
+
assert.equal(result.ok, true);
|
|
104
|
+
assert.deepEqual(taskCalls, [['install', `${RAW}/cursor/mdm/setup.py`, `${RAW}/codex/hooks/mdm/setup.py`]]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('macOS and Linux never touch the WSL task', async () => {
|
|
108
|
+
for (const platform of ['darwin', 'linux']) {
|
|
109
|
+
assert.deepEqual((await mdmBundle(platform)).taskCalls, []);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a failed tool still syncs the tools set up before it', async () => {
|
|
114
|
+
const { result, taskCalls } = await mdmBundle('win32', { exits: [0, 1] });
|
|
115
|
+
assert.equal(result.ok, false);
|
|
116
|
+
assert.deepEqual(taskCalls, [['install', `${RAW}/cursor/mdm/setup.py`]]);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('a batch that set nothing up leaves the WSL task alone', async () => {
|
|
120
|
+
const { result, taskCalls } = await mdmBundle('win32', { exits: [1] });
|
|
121
|
+
assert.equal(result.ok, false);
|
|
122
|
+
assert.deepEqual(taskCalls, []);
|
|
123
|
+
});
|