@mycadet/cli 0.13.0-dev.202610311714.d661ca6 → 0.13.0-dev.202610312329.a740c1c

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.
Files changed (105) hide show
  1. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
  2. package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  3. package/node_modules/@mycadet/environments/package.json +1 -1
  4. package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  5. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  6. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +1 -1
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
  8. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
  9. package/node_modules/@mycadet/local-mode/package.json +1 -1
  10. package/node_modules/@mycadet/local-mode/src/__tests__/gateway-proxy.test.ts +240 -145
  11. package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token-refresh.test.ts +6 -6
  12. package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token.test.ts +22 -106
  13. package/node_modules/@mycadet/local-mode/src/__tests__/hatch.test.ts +22 -8
  14. package/node_modules/@mycadet/local-mode/src/__tests__/retire.test.ts +13 -5
  15. package/node_modules/@mycadet/local-mode/src/__tests__/upgrade.test.ts +12 -6
  16. package/node_modules/@mycadet/local-mode/src/__tests__/wake.test.ts +19 -7
  17. package/node_modules/@mycadet/local-mode/src/cli-invocation.ts +85 -0
  18. package/node_modules/@mycadet/local-mode/src/devices.test.ts +44 -16
  19. package/node_modules/@mycadet/local-mode/src/devices.ts +3 -6
  20. package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +99 -13
  21. package/node_modules/@mycadet/local-mode/src/guardian-token.ts +15 -85
  22. package/node_modules/@mycadet/local-mode/src/hatch.ts +2 -3
  23. package/node_modules/@mycadet/local-mode/src/index.ts +8 -12
  24. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +0 -8
  25. package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +1 -515
  26. package/node_modules/@mycadet/local-mode/src/lockfile.ts +8 -169
  27. package/node_modules/@mycadet/local-mode/src/retire.ts +2 -3
  28. package/node_modules/@mycadet/local-mode/src/sleep.ts +3 -6
  29. package/node_modules/@mycadet/local-mode/src/upgrade.ts +3 -2
  30. package/node_modules/@mycadet/local-mode/src/wake.ts +2 -3
  31. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  32. package/node_modules/@mycadet/shared/package.json +1 -1
  33. package/package.json +2 -8
  34. package/src/__tests__/backup-ops.test.ts +7 -11
  35. package/src/__tests__/backup.test.ts +3 -2
  36. package/src/__tests__/cloud-releases.test.ts +1 -1
  37. package/src/__tests__/debug.test.ts +2 -1
  38. package/src/__tests__/host-teleport-docker.test.ts +2 -34
  39. package/src/__tests__/host-teleport.test.ts +37 -67
  40. package/src/__tests__/local-runtime-version.test.ts +3 -14
  41. package/src/__tests__/nginx.test.ts +1 -1
  42. package/src/__tests__/ngrok-spawn.test.ts +1 -1
  43. package/src/__tests__/restore.test.ts +1 -1
  44. package/src/__tests__/retire-local.test.ts +2 -39
  45. package/src/__tests__/root-backup-docker.test.ts +9 -16
  46. package/src/__tests__/root-backup.test.ts +126 -134
  47. package/src/__tests__/root-restore-command.test.ts +3 -2
  48. package/src/__tests__/runtime-url.test.ts +4 -4
  49. package/src/__tests__/setup.test.ts +13 -8
  50. package/src/__tests__/statefulset.test.ts +0 -1
  51. package/src/__tests__/teleport-backup.test.ts +1 -1
  52. package/src/__tests__/teleport.test.ts +2 -1
  53. package/src/__tests__/tunnel.test.ts +45 -103
  54. package/src/__tests__/uninstall.test.ts +1 -1
  55. package/src/__tests__/upgrade-local.test.ts +5 -7
  56. package/src/__tests__/upgrade-root-recovery.test.ts +9 -12
  57. package/src/__tests__/wake.test.ts +38 -56
  58. package/src/commands/client.ts +1 -1
  59. package/src/commands/debug.ts +1 -1
  60. package/src/commands/devices.ts +2 -2
  61. package/src/commands/exec.ts +2 -2
  62. package/src/commands/gateway/token.ts +2 -4
  63. package/src/commands/hatch.ts +1 -1
  64. package/src/commands/login.ts +1 -1
  65. package/src/commands/logs.ts +2 -2
  66. package/src/commands/pair.ts +33 -95
  67. package/src/commands/ps.ts +3 -3
  68. package/src/commands/restore.ts +3 -7
  69. package/src/commands/retire.ts +5 -5
  70. package/src/commands/setup.ts +8 -13
  71. package/src/commands/sleep.ts +4 -18
  72. package/src/commands/terminal.ts +1 -1
  73. package/src/commands/tunnel.ts +1 -8
  74. package/src/commands/uninstall.ts +12 -36
  75. package/src/commands/upgrade.ts +12 -26
  76. package/src/commands/wake.ts +2 -2
  77. package/src/components/DefaultMainScreen.tsx +31 -18
  78. package/src/lib/__tests__/docker.test.ts +4 -6
  79. package/src/lib/assistant-config.ts +6 -65
  80. package/src/lib/backup-ops.ts +0 -2
  81. package/src/lib/cloud-login.ts +17 -13
  82. package/src/lib/cloud-releases.ts +2 -2
  83. package/src/lib/guardian-token.ts +6 -32
  84. package/src/lib/health-check.ts +1 -1
  85. package/src/lib/host-teleport.ts +8 -62
  86. package/src/lib/ingress-config.ts +1 -1
  87. package/src/lib/live-voice/connection.ts +1 -1
  88. package/src/lib/port-heal.ts +1 -1
  89. package/src/lib/remotes/apple-container.ts +35 -3
  90. package/src/lib/remotes/cloud.ts +36 -0
  91. package/src/lib/remotes/docker.ts +2044 -19
  92. package/src/lib/remotes/local.ts +61 -76
  93. package/src/lib/retire-local.ts +6 -62
  94. package/src/lib/root-backup.ts +27 -33
  95. package/src/lib/runtime-url.ts +1 -1
  96. package/src/lib/servers/nginx.ts +1 -1
  97. package/src/lib/statefulset.ts +1 -9
  98. package/src/lib/teleport-backup.ts +1 -1
  99. package/src/lib/terminal-session.ts +64 -22
  100. package/src/lib/tunnel.ts +43 -106
  101. package/src/lib/tunnels/cloudflare.ts +0 -2
  102. package/src/lib/tunnels/ngrok.ts +3 -9
  103. package/src/lib/tunnels/tailscale.ts +0 -2
  104. package/src/lib/upgrade-lifecycle.ts +12 -35
  105. package/src/lib/docker.ts +0 -2041
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/environments",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/environments",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/shared",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "exports": {
6
6
  ".": "./github-repository.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/local-mode",
3
- "version": "0.13.0-dev.202610311714.d661ca6",
3
+ "version": "0.13.0-dev.202610312329.a740c1c",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -3,12 +3,16 @@ import fs from "node:fs";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
5
 
6
- import { GATEWAY_PORT } from "../lockfile-contract";
6
+ import {
7
+ GATEWAY_PORT,
8
+ LockfileAssistantSchema,
9
+ type LockfileAssistant,
10
+ } from "../lockfile-contract";
7
11
  import {
8
12
  authorizePairedForwardHeaders,
9
- gatewayTargetsFromLockfile,
10
13
  parseAssistantGatewayUrl,
11
14
  readGatewayTargets,
15
+ resolveAssistantRetireProxyDecision,
12
16
  resolveGatewayProxyTarget,
13
17
  sanitizePairedForwardHeaders,
14
18
  } from "../gateway-proxy";
@@ -23,16 +27,12 @@ const loopback = (port: number) => ({ kind: "loopback", port }) as const;
23
27
  const remote = (runtimeUrl: string) =>
24
28
  ({ kind: "remote", runtimeUrl }) as const;
25
29
 
26
- const targets =
27
- (
28
- map: Record<
29
- string,
30
- | { kind: "loopback"; port: number }
31
- | { kind: "remote"; runtimeUrl: string }
32
- >,
33
- ) =>
34
- () =>
35
- new Map(Object.entries(map));
30
+ const entries = (map: Record<string, unknown>) => () =>
31
+ new Map(
32
+ Object.entries(map).map(
33
+ ([id, raw]) => [id, LockfileAssistantSchema.parse(raw)] as const,
34
+ ),
35
+ );
36
36
 
37
37
  describe("parseAssistantGatewayUrl", () => {
38
38
  test("parses the scoped SDK surface and forwards the full path", () => {
@@ -131,9 +131,19 @@ describe("parseAssistantGatewayUrl", () => {
131
131
  });
132
132
 
133
133
  describe("resolveGatewayProxyTarget", () => {
134
- const entry = targets({
135
- "abc-123": loopback(8080),
136
- "def-456": remote("https://gw.example.com"),
134
+ const entry = entries({
135
+ "abc-123": {
136
+ assistantId: "abc-123",
137
+ cloud: "local",
138
+ port: 8080,
139
+ daemonPort: 8501,
140
+ },
141
+ "def-456": {
142
+ assistantId: "def-456",
143
+ cloud: "custom",
144
+ ipAddress: "gw.example.com",
145
+ port: 443,
146
+ },
137
147
  });
138
148
 
139
149
  test("passes non-gateway paths through untouched", () => {
@@ -141,7 +151,7 @@ describe("resolveGatewayProxyTarget", () => {
141
151
  kind: "pass",
142
152
  });
143
153
  expect(
144
- resolveGatewayProxyTarget("/assistant/assets/app.js", targets({})),
154
+ resolveGatewayProxyTarget("/assistant/assets/app.js", entries({})),
145
155
  ).toEqual({ kind: "pass" });
146
156
  });
147
157
 
@@ -156,7 +166,6 @@ describe("resolveGatewayProxyTarget", () => {
156
166
  target: loopback(8080),
157
167
  });
158
168
  });
159
-
160
169
  test("forwards a scoped path for an imported pairing to its runtimeUrl", () => {
161
170
  expect(
162
171
  resolveGatewayProxyTarget("/v1/assistants/def-456/messages?x=1", entry),
@@ -187,159 +196,106 @@ describe("resolveGatewayProxyTarget", () => {
187
196
  resolveGatewayProxyTarget("/v1/assistants/zzz-999/messages", entry),
188
197
  ).toEqual({ kind: "pass" });
189
198
  expect(
190
- resolveGatewayProxyTarget("/v1/assistants/zzz-999/x", targets({})),
199
+ resolveGatewayProxyTarget("/v1/assistants/zzz-999/x", entries({})),
191
200
  ).toEqual({ kind: "pass" });
192
201
  });
193
202
  });
194
203
 
195
- describe("gatewayTargetsFromLockfile", () => {
204
+ describe("gateway target derivation", () => {
205
+ const forwardTarget = (id: string, raw: unknown) =>
206
+ resolveGatewayProxyTarget(`/v1/assistants/${id}/x`, entries({ [id]: raw }))
207
+ .kind === "forward"
208
+ ? (
209
+ resolveGatewayProxyTarget(
210
+ `/v1/assistants/${id}/x`,
211
+ entries({ [id]: raw }),
212
+ ) as { target: unknown }
213
+ ).target
214
+ : undefined;
215
+
196
216
  test("resolves a paired entry's custom addressing to a remote target", () => {
197
217
  expect(
198
- gatewayTargetsFromLockfile({
199
- assistants: [
200
- {
201
- assistantId: "abc-123",
202
- cloud: "custom",
203
- ipAddress: "gw.example.com",
204
- port: 443,
205
- },
206
- ],
218
+ forwardTarget("abc-123", {
219
+ assistantId: "abc-123",
220
+ cloud: "custom",
221
+ ipAddress: "gw.example.com",
222
+ port: 443,
207
223
  }),
208
- ).toEqual(targets({ "abc-123": remote("https://gw.example.com") })());
224
+ ).toEqual(remote("https://gw.example.com"));
209
225
  });
210
226
 
211
- test("omits loopback entries with no recorded port beyond the default's loopback form", () => {
227
+ test("a custom entry pointing at loopback is not targetable", () => {
212
228
  expect(
213
- gatewayTargetsFromLockfile({
214
- assistants: [
215
- { assistantId: "abc-123", cloud: "custom" },
216
- { assistantId: "def-456", cloud: "cloud" },
217
- ],
218
- }),
219
- ).toEqual(new Map());
229
+ resolveGatewayProxyTarget(
230
+ "/v1/assistants/abc-123/x",
231
+ entries({
232
+ "abc-123": {
233
+ assistantId: "abc-123",
234
+ cloud: "custom",
235
+ ipAddress: "127.0.0.1",
236
+ port: 443,
237
+ },
238
+ }),
239
+ ),
240
+ ).toEqual({ kind: "pass" });
220
241
  });
221
242
 
222
243
  test("resolves a local entry's recorded gatewayPort to a loopback target", () => {
223
244
  expect(
224
- gatewayTargetsFromLockfile({
225
- assistants: [
226
- {
227
- assistantId: "abc-123",
228
- cloud: "local",
229
- port: 8080,
230
- daemonPort: 8501,
231
- },
232
- ],
245
+ forwardTarget("abc-123", {
246
+ assistantId: "abc-123",
247
+ cloud: "local",
248
+ port: 8080,
249
+ daemonPort: 8501,
233
250
  }),
234
- ).toEqual(targets({ "abc-123": loopback(8080) })());
251
+ ).toEqual(loopback(8080));
235
252
  });
236
253
 
237
254
  test("a docker entry without a recorded port derives the default gateway port", () => {
238
255
  expect(
239
- gatewayTargetsFromLockfile({
240
- assistants: [{ assistantId: "abc-123", cloud: "docker" }],
256
+ forwardTarget("abc-123", {
257
+ assistantId: "abc-123",
258
+ cloud: "docker",
241
259
  }),
242
- ).toEqual(new Map([["abc-123", loopback(GATEWAY_PORT)]]));
260
+ ).toEqual(loopback(GATEWAY_PORT));
243
261
  });
244
262
 
245
- test("omits ports outside the 1024-65535 proxy range", () => {
246
- expect(
247
- gatewayTargetsFromLockfile({
248
- assistants: [
249
- {
250
- assistantId: "abc-123",
251
- cloud: "local",
252
- port: 80,
253
- daemonPort: 8501,
254
- },
255
- {
256
- assistantId: "def-456",
257
- cloud: "docker",
258
- port: 70000,
259
- },
260
- ],
261
- }),
262
- ).toEqual(new Map());
263
+ test("ports outside the 1024-65535 proxy range are not targetable", () => {
264
+ for (const port of [80, 70000]) {
265
+ expect(
266
+ resolveGatewayProxyTarget(
267
+ "/v1/assistants/abc-123/x",
268
+ entries({
269
+ "abc-123": {
270
+ assistantId: "abc-123",
271
+ cloud: "local",
272
+ port,
273
+ daemonPort: 8501,
274
+ },
275
+ }),
276
+ ),
277
+ ).toEqual({ kind: "pass" });
278
+ }
263
279
  });
264
280
 
265
281
  test("omits clouds the SPA does not drive over this proxy", () => {
266
282
  expect(
267
- gatewayTargetsFromLockfile({
268
- assistants: [
269
- { assistantId: "a", cloud: "cloud" },
270
- // A retired spelling parses as "local": loopback-gated, so it
271
- // derives the default loopback port rather than being omitted.
272
- { assistantId: "b", cloud: "gcp" },
273
- ],
274
- }),
275
- ).toEqual(new Map([["b", { kind: "loopback", port: GATEWAY_PORT }]]));
276
- });
277
-
278
- test("a custom entry's recorded addressing is targetable", () => {
279
- expect(
280
- gatewayTargetsFromLockfile({
281
- assistants: [
282
- {
283
- assistantId: "c",
284
- cloud: "custom",
285
- ipAddress: "gw.example.com",
286
- port: 7831,
287
- },
288
- ],
289
- }),
290
- ).toEqual(
291
- new Map([
292
- ["c", { kind: "remote", runtimeUrl: "https://gw.example.com:7831" }],
293
- ]),
294
- );
283
+ resolveGatewayProxyTarget(
284
+ "/v1/assistants/a/x",
285
+ entries({ a: { assistantId: "a", cloud: "cloud" } }),
286
+ ),
287
+ ).toEqual({ kind: "pass" });
295
288
  });
296
289
 
297
290
  test("a baseten entry resolves to a remote target on the sandbox /port/ route", () => {
298
291
  expect(
299
- gatewayTargetsFromLockfile({
300
- assistants: [
301
- {
302
- assistantId: "sbx-1",
303
- cloud: "baseten",
304
- sandboxUrl: "https://sbx-name-abc123.us-pdx-1.b10.co",
305
- port: 7830,
306
- },
307
- ],
308
- }),
309
- ).toEqual(
310
- targets({
311
- "sbx-1": remote("https://sbx-name-abc123.us-pdx-1.b10.co/port/7830"),
312
- })(),
313
- );
314
- });
315
-
316
- test("a baseten entry without a recorded URL is not targetable", () => {
317
- // The hatch records the entry only once describe returns a URL; a
318
- // URL-less record must not forward anywhere.
319
- expect(
320
- gatewayTargetsFromLockfile({
321
- assistants: [{ assistantId: "sbx-1", cloud: "baseten", port: 7830 }],
322
- }),
323
- ).toEqual(new Map());
324
- });
325
-
326
- test("tolerates malformed entries", () => {
327
- expect(
328
- gatewayTargetsFromLockfile({
329
- assistants: [
330
- null,
331
- 42,
332
- { noId: true },
333
- { assistantId: "", paired: true },
334
- {
335
- assistantId: "abc-123",
336
- cloud: "local",
337
- port: 8080,
338
- daemonPort: 8501,
339
- },
340
- ],
292
+ forwardTarget("sbx-1", {
293
+ assistantId: "sbx-1",
294
+ cloud: "baseten",
295
+ sandboxUrl: "https://sbx-name-abc123.us-pdx-1.b10.co",
296
+ port: 7830,
341
297
  }),
342
- ).toEqual(targets({ "abc-123": loopback(8080) })());
298
+ ).toEqual(remote("https://sbx-name-abc123.us-pdx-1.b10.co/port/7830"));
343
299
  });
344
300
  });
345
301
 
@@ -380,9 +336,19 @@ describe("readGatewayTargets", () => {
380
336
  ),
381
337
  );
382
338
  expect(readGatewayTargets()).toEqual(
383
- targets({
384
- "abc-123": loopback(8080),
385
- "def-456": remote("https://gw.example.com"),
339
+ entries({
340
+ "abc-123": {
341
+ assistantId: "abc-123",
342
+ cloud: "local",
343
+ port: 8080,
344
+ daemonPort: 8501,
345
+ },
346
+ "def-456": {
347
+ assistantId: "def-456",
348
+ cloud: "custom",
349
+ ipAddress: "gw.example.com",
350
+ port: 443,
351
+ },
386
352
  })(),
387
353
  );
388
354
  fs.rmSync(dir, { recursive: true, force: true });
@@ -396,6 +362,30 @@ describe("readGatewayTargets", () => {
396
362
  fs.rmSync(dir, { recursive: true, force: true });
397
363
  });
398
364
 
365
+ test("malformed entries are skipped, not fatal", () => {
366
+ const dir = withAmbientLockfile((lockfilePath) =>
367
+ fs.writeFileSync(
368
+ lockfilePath,
369
+ JSON.stringify({
370
+ assistants: [
371
+ null,
372
+ 42,
373
+ { noId: true },
374
+ { assistantId: "", cloud: "local", port: 8080, daemonPort: 8501 },
375
+ {
376
+ assistantId: "abc-123",
377
+ cloud: "local",
378
+ port: 8080,
379
+ daemonPort: 8501,
380
+ },
381
+ ],
382
+ }),
383
+ ),
384
+ );
385
+ expect(readGatewayTargets().size).toBe(1);
386
+ fs.rmSync(dir, { recursive: true, force: true });
387
+ });
388
+
399
389
  test("an unreadable or absent lockfile yields an empty map", () => {
400
390
  const dir = withAmbientLockfile((lockfilePath) =>
401
391
  fs.writeFileSync(lockfilePath, "{ not json"),
@@ -429,11 +419,9 @@ describe("remote-forward header handling", () => {
429
419
  const headers = new Headers({ authorization: "Bearer renderer" });
430
420
  const result = await authorizePairedForwardHeaders(
431
421
  "abc-123",
432
- "https://gw.example.com",
433
422
  headers,
434
- async (assistantId, runtimeUrl) => {
423
+ async (assistantId) => {
435
424
  expect(assistantId).toBe("abc-123");
436
- expect(runtimeUrl).toBe("https://gw.example.com");
437
425
  return { ok: true, accessToken: "host-token" };
438
426
  },
439
427
  );
@@ -441,3 +429,110 @@ describe("remote-forward header handling", () => {
441
429
  expect(headers.get("authorization")).toBe("Bearer host-token");
442
430
  });
443
431
  });
432
+
433
+ describe("resolveAssistantRetireProxyDecision", () => {
434
+ const noLockfile = () => null as never;
435
+ const withEntries =
436
+ (...entries: unknown[]) =>
437
+ () => ({ assistants: entries });
438
+
439
+ const localEntry = { assistantId: "asst-local", cloud: "local", port: 7830 };
440
+ const dockerEntry = {
441
+ assistantId: "asst-docker",
442
+ cloud: "docker",
443
+ port: 7831,
444
+ };
445
+ const appleEntry = {
446
+ assistantId: "asst-apple",
447
+ cloud: "apple-container",
448
+ mgmtSocket: "/tmp/mgmt.sock",
449
+ };
450
+ const cloudEntry = {
451
+ assistantId: "asst-cloud",
452
+ cloud: "cloud",
453
+ };
454
+ const pairedEntry = {
455
+ assistantId: "asst-paired",
456
+ cloud: "custom",
457
+ runtimeUrl: "https://gw.example.com",
458
+ };
459
+
460
+ test("non-DELETE methods pass without consulting the lockfile", () => {
461
+ expect(
462
+ resolveAssistantRetireProxyDecision(
463
+ "/v1/assistants/asst-local/retire/",
464
+ "POST",
465
+ withEntries(localEntry),
466
+ ),
467
+ ).toEqual({ kind: "pass" });
468
+ // The thunk is never called for a bail, so null proves the point.
469
+ expect(
470
+ resolveAssistantRetireProxyDecision(
471
+ "/v1/assistants/asst-local/retire/",
472
+ "GET",
473
+ noLockfile,
474
+ ),
475
+ ).toEqual({ kind: "pass" });
476
+ });
477
+
478
+ test("non-retire paths pass without consulting the lockfile", () => {
479
+ expect(
480
+ resolveAssistantRetireProxyDecision(
481
+ "/v1/assistants/asst-local/conversations",
482
+ "DELETE",
483
+ noLockfile,
484
+ ),
485
+ ).toEqual({ kind: "pass" });
486
+ });
487
+
488
+ test("a host-retirable entry resolves to retireLocal", () => {
489
+ expect(
490
+ resolveAssistantRetireProxyDecision(
491
+ "/v1/assistants/asst-local/retire/",
492
+ "DELETE",
493
+ withEntries(localEntry),
494
+ ),
495
+ ).toEqual({ kind: "retireLocal", assistantId: "asst-local" });
496
+ expect(
497
+ resolveAssistantRetireProxyDecision(
498
+ "/v1/assistants/asst-docker/retire/",
499
+ "DELETE",
500
+ withEntries(dockerEntry),
501
+ ),
502
+ ).toEqual({ kind: "retireLocal", assistantId: "asst-docker" });
503
+ expect(
504
+ resolveAssistantRetireProxyDecision(
505
+ "/v1/assistants/asst-apple/retire/",
506
+ "DELETE",
507
+ withEntries(appleEntry),
508
+ ),
509
+ ).toEqual({ kind: "retireLocal", assistantId: "asst-apple" });
510
+ });
511
+
512
+ test("cloud and paired entries pass through to the endpoint's forward", () => {
513
+ expect(
514
+ resolveAssistantRetireProxyDecision(
515
+ "/v1/assistants/asst-cloud/retire/",
516
+ "DELETE",
517
+ withEntries(cloudEntry),
518
+ ),
519
+ ).toEqual({ kind: "pass" });
520
+ expect(
521
+ resolveAssistantRetireProxyDecision(
522
+ "/v1/assistants/asst-paired/retire/",
523
+ "DELETE",
524
+ withEntries(pairedEntry),
525
+ ),
526
+ ).toEqual({ kind: "pass" });
527
+ });
528
+
529
+ test("an id the lockfile does not know passes", () => {
530
+ expect(
531
+ resolveAssistantRetireProxyDecision(
532
+ "/v1/assistants/ghost/retire/",
533
+ "DELETE",
534
+ withEntries(localEntry),
535
+ ),
536
+ ).toEqual({ kind: "pass" });
537
+ });
538
+ });
@@ -11,7 +11,7 @@ import fs from "node:fs";
11
11
  import os from "node:os";
12
12
  import path from "node:path";
13
13
 
14
- import type { CliInvocation } from "../util";
14
+ import { configureCliPaths } from "../cli-invocation";
15
15
  import type { GuardianTokenData } from "../guardian-token";
16
16
  import { FakeChild, mockChildProcessSpawn } from "./helpers/child-process-mock";
17
17
 
@@ -39,7 +39,7 @@ afterEach(() => {
39
39
  spawnMock.mockClear();
40
40
  });
41
41
 
42
- const invocation: CliInvocation = { command: "bun", baseArgs: ["run", "cli"] };
42
+ configureCliPaths({ devEntry: () => "cli" });
43
43
  const FUTURE = new Date(Date.now() + 60 * 60 * 1000).toISOString();
44
44
  const PAST = new Date(Date.now() - 60_000).toISOString();
45
45
  const tick = () => new Promise<void>((resolve) => setTimeout(resolve, 0));
@@ -72,7 +72,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
72
72
  });
73
73
 
74
74
  test("a labeled CLI 503 is an unreachable gateway, not a spent token", async () => {
75
- const pending = getGuardianAccessToken("asst-1", invocation, true);
75
+ const pending = getGuardianAccessToken("asst-1");
76
76
  await tick();
77
77
  lastChild.stderr.emit(
78
78
  "data",
@@ -90,7 +90,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
90
90
  });
91
91
 
92
92
  test("a labeled CLI 401 is a spent credential", async () => {
93
- const pending = getGuardianAccessToken("asst-1", invocation, true);
93
+ const pending = getGuardianAccessToken("asst-1");
94
94
  await tick();
95
95
  lastChild.stderr.emit(
96
96
  "data",
@@ -108,7 +108,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
108
108
  });
109
109
 
110
110
  test("a labeled CLI 403 is a local confidentiality refusal, not a spent credential", async () => {
111
- const pending = getGuardianAccessToken("asst-1", invocation, true);
111
+ const pending = getGuardianAccessToken("asst-1");
112
112
  await tick();
113
113
  lastChild.stderr.emit(
114
114
  "data",
@@ -126,7 +126,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
126
126
  });
127
127
 
128
128
  test("an unlabeled non-zero CLI exit is a 503, not a 401", async () => {
129
- const pending = getGuardianAccessToken("asst-1", invocation, true);
129
+ const pending = getGuardianAccessToken("asst-1");
130
130
  await tick();
131
131
  lastChild.stderr.emit(
132
132
  "data",