unbound-cli 1.26.2 → 1.27.1
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 +4 -4
- package/package.json +1 -1
- package/src/api.js +11 -1
- package/src/commands/delivery.js +17 -9
- package/src/commands/onboard.js +3 -1
- package/src/commands/setup.js +111 -16
- package/src/index.js +1 -1
- package/src/setup-report.js +54 -0
- package/src/toolHealth.js +23 -7
- package/test/delivery.test.js +5 -2
- package/test/onboard-scope.test.js +22 -3
- package/test/setup-args.test.js +15 -1
- package/test/setup-removal-context.test.js +428 -0
- package/test/tool-health.test.js +161 -0
package/test/tool-health.test.js
CHANGED
|
@@ -143,6 +143,167 @@ test('detectTools: both claude-code modes present at once → one line, flagged
|
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
145
|
|
|
146
|
+
// --- a healthy mode beside a config-only leftover of the other mode ---
|
|
147
|
+
const MODE_ENVS = ['UNBOUND_API_KEY', 'ANTHROPIC_BASE_URL', 'OPENAI_API_KEY', 'UNBOUND_DEVICE_TOKEN', 'UNBOUND_CLAUDE_API_KEY', 'UNBOUND_CODEX_API_KEY', 'CLAUDE_CONFIG_DIR'];
|
|
148
|
+
function withEnv(vars, fn) {
|
|
149
|
+
const saved = Object.fromEntries(MODE_ENVS.map((n) => [n, process.env[n]]));
|
|
150
|
+
for (const n of MODE_ENVS) delete process.env[n];
|
|
151
|
+
Object.assign(process.env, vars);
|
|
152
|
+
try { return fn(); } finally {
|
|
153
|
+
for (const n of MODE_ENVS) { if (saved[n] === undefined) delete process.env[n]; else process.env[n] = saved[n]; }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const loggedIn = (tmp) => writeFile(path.join(tmp, '.unbound', 'config.json'), JSON.stringify({ api_key: 'k' }));
|
|
157
|
+
const claudeOf = (th) => th.detectTools().find((t) => t.family === 'claude-code');
|
|
158
|
+
|
|
159
|
+
test('detectTools: healthy claude subscription + dangling gateway key helper → reports subscription so --fix keeps that mode', () => {
|
|
160
|
+
withHome((tmp, th) => withEnv({}, () => {
|
|
161
|
+
loggedIn(tmp);
|
|
162
|
+
const hook = path.join(tmp, '.claude', 'hooks', 'unbound.py');
|
|
163
|
+
writeFile(path.join(tmp, '.claude', 'settings.json'), JSON.stringify({
|
|
164
|
+
hooks: { PreToolUse: [{ command: hook }] },
|
|
165
|
+
apiKeyHelper: path.join(tmp, '.claude', 'anthropic_key.sh'), // script is gone
|
|
166
|
+
}));
|
|
167
|
+
writeFile(hook, '#');
|
|
168
|
+
const claude = claudeOf(th);
|
|
169
|
+
assert.equal(claude.key, 'claude-code-subscription');
|
|
170
|
+
assert.equal(claude.mode, 'subscription');
|
|
171
|
+
assert.equal(claude.conflict, true);
|
|
172
|
+
assert.equal(claude.status, 'tampered', 'still flagged so --fix clears the leftover');
|
|
173
|
+
}));
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('detectTools: healthy claude gateway + stale subscription hooks → reports gateway', () => {
|
|
177
|
+
withHome((tmp, th) => withEnv({ UNBOUND_API_KEY: 'k', ANTHROPIC_BASE_URL: 'https://api.getunbound.ai' }, () => {
|
|
178
|
+
loggedIn(tmp);
|
|
179
|
+
const helper = path.join(tmp, '.claude', 'anthropic_key.sh');
|
|
180
|
+
writeFile(path.join(tmp, '.claude', 'settings.json'), JSON.stringify({
|
|
181
|
+
hooks: { PreToolUse: [{ command: path.join(tmp, '.claude', 'hooks', 'unbound.py') }] }, // script is gone
|
|
182
|
+
apiKeyHelper: helper,
|
|
183
|
+
}));
|
|
184
|
+
writeFile(helper, 'echo $UNBOUND_API_KEY');
|
|
185
|
+
const claude = claudeOf(th);
|
|
186
|
+
assert.equal(claude.key, 'claude-code-gateway');
|
|
187
|
+
assert.equal(claude.conflict, true);
|
|
188
|
+
assert.equal(claude.status, 'tampered');
|
|
189
|
+
}));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('detectTools: gateway with real env exports beside intact hooks → still reports the tampered gateway', () => {
|
|
193
|
+
withHome((tmp, th) => withEnv({ UNBOUND_API_KEY: 'k', ANTHROPIC_BASE_URL: 'https://api.getunbound.ai' }, () => {
|
|
194
|
+
loggedIn(tmp);
|
|
195
|
+
const hook = path.join(tmp, '.claude', 'hooks', 'unbound.py');
|
|
196
|
+
writeFile(path.join(tmp, '.claude', 'settings.json'), JSON.stringify({
|
|
197
|
+
hooks: { PreToolUse: [{ command: hook }] },
|
|
198
|
+
apiKeyHelper: path.join(tmp, '.claude', 'anthropic_key.sh'), // script is gone
|
|
199
|
+
}));
|
|
200
|
+
writeFile(hook, '#');
|
|
201
|
+
const claude = claudeOf(th);
|
|
202
|
+
assert.equal(claude.key, 'claude-code-gateway', 'real gateway wiring is not overridden');
|
|
203
|
+
assert.equal(claude.conflict, true);
|
|
204
|
+
assert.equal(claude.status, 'tampered');
|
|
205
|
+
}));
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test('detectTools: healthy claude subscription + the user\'s own key helper script → reports subscription', () => {
|
|
209
|
+
withHome((tmp, th) => withEnv({}, () => {
|
|
210
|
+
loggedIn(tmp);
|
|
211
|
+
const hook = path.join(tmp, '.claude', 'hooks', 'unbound.py');
|
|
212
|
+
const helper = path.join(tmp, '.claude', 'anthropic_key.sh');
|
|
213
|
+
writeFile(path.join(tmp, '.claude', 'settings.json'), JSON.stringify({
|
|
214
|
+
hooks: { PreToolUse: [{ command: hook }] },
|
|
215
|
+
apiKeyHelper: helper,
|
|
216
|
+
}));
|
|
217
|
+
writeFile(hook, '#');
|
|
218
|
+
writeFile(helper, '#!/bin/sh\nsecurity find-generic-password -s my-llm -w\n');
|
|
219
|
+
const claude = claudeOf(th);
|
|
220
|
+
assert.equal(claude.key, 'claude-code-subscription', 'hooks setup keeps a helper it did not write');
|
|
221
|
+
assert.equal(claude.conflict, true);
|
|
222
|
+
assert.equal(claude.status, 'healthy', '--fix cannot remove a helper setup keeps, so doctor must not stay red');
|
|
223
|
+
}));
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('detectTools: healthy claude subscription + gateway config + customer ANTHROPIC_BASE_URL → still reports gateway', () => {
|
|
227
|
+
withHome((tmp, th) => withEnv({ ANTHROPIC_BASE_URL: 'https://llm.example.invalid' }, () => {
|
|
228
|
+
loggedIn(tmp);
|
|
229
|
+
const hook = path.join(tmp, '.claude', 'hooks', 'unbound.py');
|
|
230
|
+
writeFile(path.join(tmp, '.claude', 'settings.json'), JSON.stringify({
|
|
231
|
+
hooks: { PreToolUse: [{ command: hook }] },
|
|
232
|
+
apiKeyHelper: path.join(tmp, '.claude', 'anthropic_key.sh'),
|
|
233
|
+
}));
|
|
234
|
+
writeFile(hook, '#');
|
|
235
|
+
const claude = claudeOf(th);
|
|
236
|
+
assert.equal(claude.key, 'claude-code-gateway', 'an endpoint that differs from setup is wiring, not a leftover');
|
|
237
|
+
assert.equal(claude.status, 'tampered');
|
|
238
|
+
}));
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('detectTools: healthy codex subscription + leftover openai_base_url line → reports subscription', () => {
|
|
242
|
+
withHome((tmp, th) => withEnv({}, () => {
|
|
243
|
+
loggedIn(tmp);
|
|
244
|
+
const hook = path.join(tmp, '.codex', 'hooks', 'unbound.py');
|
|
245
|
+
writeFile(path.join(tmp, '.codex', 'hooks.json'), JSON.stringify({ hooks: { PreToolUse: [{ command: hook }] } }));
|
|
246
|
+
writeFile(hook, '#');
|
|
247
|
+
writeFile(path.join(tmp, '.codex', 'config.toml'), 'openai_base_url = "https://api.getunbound.ai/v1"\n\n[features]\nhooks = true\n');
|
|
248
|
+
const codex = th.detectTools({ _codexManagedOnly: null }).find((t) => t.family === 'codex');
|
|
249
|
+
assert.equal(codex.key, 'codex-subscription');
|
|
250
|
+
assert.equal(codex.conflict, true);
|
|
251
|
+
assert.equal(codex.status, 'tampered');
|
|
252
|
+
}));
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('detectTools: healthy codex gateway + stale hooks entry and hooks flag (script gone) → reports gateway', () => {
|
|
256
|
+
withHome((tmp, th) => withEnv({ OPENAI_API_KEY: 'k' }, () => {
|
|
257
|
+
loggedIn(tmp);
|
|
258
|
+
const hook = path.join(tmp, '.codex', 'hooks', 'unbound.py'); // script is gone
|
|
259
|
+
writeFile(path.join(tmp, '.codex', 'hooks.json'), JSON.stringify({ hooks: { PreToolUse: [{ command: hook }] } }));
|
|
260
|
+
writeFile(path.join(tmp, '.codex', 'config.toml'), 'openai_base_url = "https://api.getunbound.ai/v1"\n\n[features]\nhooks = true\n');
|
|
261
|
+
const codex = th.detectTools({ _codexManagedOnly: null }).find((t) => t.family === 'codex');
|
|
262
|
+
assert.equal(codex.key, 'codex-gateway', 'the hooks flag is a config line, not proof the hooks are installed');
|
|
263
|
+
assert.equal(codex.conflict, true);
|
|
264
|
+
assert.equal(codex.status, 'tampered');
|
|
265
|
+
}));
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
const codexSub = (tmp, { script = true } = {}) => {
|
|
269
|
+
const hook = path.join(tmp, '.codex', 'hooks', 'unbound.py');
|
|
270
|
+
writeFile(path.join(tmp, '.codex', 'hooks.json'), JSON.stringify({ hooks: { PreToolUse: [{ command: hook }] } }));
|
|
271
|
+
if (script) writeFile(hook, '#');
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
test('detectTools: healthy codex subscription + the user\'s own openai_base_url → healthy, nothing for --fix to strip', () => {
|
|
275
|
+
withHome((tmp, th) => withEnv({}, () => {
|
|
276
|
+
loggedIn(tmp);
|
|
277
|
+
codexSub(tmp);
|
|
278
|
+
writeFile(path.join(tmp, '.codex', 'config.toml'), 'openai_base_url = "https://openrouter.ai/api/v1"\n\n[features]\nhooks = true\n');
|
|
279
|
+
const codex = th.detectTools({ _codexManagedOnly: null }).find((t) => t.family === 'codex');
|
|
280
|
+
assert.equal(codex.key, 'codex-subscription');
|
|
281
|
+
assert.equal(codex.status, 'healthy');
|
|
282
|
+
}));
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test('detectTools: healthy codex subscription + a commented-out openai_base_url → healthy', () => {
|
|
286
|
+
withHome((tmp, th) => withEnv({}, () => {
|
|
287
|
+
loggedIn(tmp);
|
|
288
|
+
codexSub(tmp);
|
|
289
|
+
writeFile(path.join(tmp, '.codex', 'config.toml'), '# openai_base_url = "https://api.getunbound.ai/v1"\n\n[features]\nhooks = true\n');
|
|
290
|
+
const codex = th.detectTools({ _codexManagedOnly: null }).find((t) => t.family === 'codex');
|
|
291
|
+
assert.equal(codex.key, 'codex-subscription');
|
|
292
|
+
assert.equal(codex.status, 'healthy');
|
|
293
|
+
}));
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('detectTools: codex subscription with its script deleted + the user\'s own endpoint and key → still reports subscription', () => {
|
|
297
|
+
withHome((tmp, th) => withEnv({ OPENAI_API_KEY: 'sk-own' }, () => {
|
|
298
|
+
loggedIn(tmp);
|
|
299
|
+
codexSub(tmp, { script: false });
|
|
300
|
+
writeFile(path.join(tmp, '.codex', 'config.toml'), 'openai_base_url = "https://my-azure.example/openai/v1"\n\n[features]\nhooks = true\n');
|
|
301
|
+
const codex = th.detectTools({ _codexManagedOnly: null }).find((t) => t.family === 'codex');
|
|
302
|
+
assert.equal(codex.key, 'codex-subscription', '--fix must reinstall the hooks, not switch to gateway over the user\'s endpoint');
|
|
303
|
+
assert.equal(codex.status, 'tampered');
|
|
304
|
+
}));
|
|
305
|
+
});
|
|
306
|
+
|
|
146
307
|
// --- MDM (org-managed) scenarios, exercised via the _mdmDirs test override ---
|
|
147
308
|
test('MDM: managed config references unbound + hook present → managed by MDM', () => {
|
|
148
309
|
withHome((tmp, th) => {
|