@mycadet/cli 0.12.9 → 0.12.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.12.9",
3
+ "version": "0.12.10",
4
4
  "description": "CLI tools for mycadet",
5
5
  "type": "module",
6
6
  "exports": {
@@ -20,11 +20,11 @@
20
20
  "scripts": {
21
21
  "format": "prettier --write .",
22
22
  "format:check": "prettier --check .",
23
- "lint": "eslint --max-warnings 322",
23
+ "lint": "eslint --max-warnings 323",
24
24
  "lint:unused": "knip --include files,dependencies,unlisted",
25
25
  "compile:check": "bun build --compile src/index.ts --outfile /dev/null",
26
26
  "test": "bun run scripts/run-tests.ts",
27
- "typecheck": "bunx tsc --noEmit"
27
+ "typecheck": "bunx tsgo --noEmit"
28
28
  },
29
29
  "author": "Cadet AI",
30
30
  "license": "MIT",
@@ -57,6 +57,7 @@
57
57
  "@types/bun": "1.3.11",
58
58
  "@types/qrcode-terminal": "0.12.2",
59
59
  "@types/react": "19.2.14",
60
+ "@typescript/native-preview": "7.0.0-dev.20260624.1",
60
61
  "eslint": "10.1.0",
61
62
  "knip": "5.88.1",
62
63
  "prettier": "3.8.1",
@@ -13,7 +13,6 @@ import { buildWebInterfaceConfig } from "../commands/client.js";
13
13
  const BASE = {
14
14
  webUrl: "https://app.example.com",
15
15
  cloudUrl: "https://platform.example.com",
16
- disableCloud: true,
17
16
  };
18
17
 
19
18
  describe("cadet client web __config", () => {
@@ -160,7 +160,6 @@ describe("buildIngressNginxConfig", () => {
160
160
  config: {
161
161
  remote: "docker",
162
162
  apiBaseUrl: "/v1",
163
- cloudDisabled: true,
164
163
  },
165
164
  },
166
165
  });
@@ -330,7 +329,7 @@ describe("buildIngressNginxConfig", () => {
330
329
  expect(remoteConf).toContain("default_type application/json;");
331
330
  expect(remoteConf).toContain('add_header Cache-Control "no-store";');
332
331
  expect(remoteConf).toContain(
333
- 'return 200 "{\\"remote\\":\\"docker\\",\\"apiBaseUrl\\":\\"/v1\\",\\"cloudDisabled\\":true,\\"disableCloud\\":true}";',
332
+ 'return 200 "{\\"remote\\":\\"docker\\",\\"apiBaseUrl\\":\\"/v1\\"}";',
334
333
  );
335
334
  expect(remoteConf).not.toContain("assistantId");
336
335
  });
@@ -347,7 +346,7 @@ describe("buildIngressNginxConfig", () => {
347
346
  },
348
347
  });
349
348
  expect(named).toContain(
350
- 'return 200 "{\\"remote\\":\\"custom\\",\\"apiBaseUrl\\":\\"/v1\\",\\"cloudDisabled\\":true,\\"disableCloud\\":true,\\"assistantName\\":\\"Homelab\\",\\"assistantId\\":\\"assistant-1\\",\\"hubUrl\\":\\"https://mycadet.ai/assistant\\"}";',
349
+ 'return 200 "{\\"remote\\":\\"custom\\",\\"apiBaseUrl\\":\\"/v1\\",\\"assistantName\\":\\"Homelab\\",\\"assistantId\\":\\"assistant-1\\",\\"hubUrl\\":\\"https://mycadet.ai/assistant\\"}";',
351
350
  );
352
351
  });
353
352
 
@@ -449,14 +448,13 @@ describe("buildRemoteWebIndexHtml", () => {
449
448
  const result = buildRemoteWebIndexHtml(html, {
450
449
  remote: "docker",
451
450
  apiBaseUrl: "/v1",
452
- disableCloud: true,
453
451
  });
454
452
 
455
453
  expect(result).toContain(
456
454
  'window.__CADET_CONFIG__={"webUrl":"https://mycadet.ai"}',
457
455
  );
458
456
  expect(result).toContain(
459
- 'window.__CADET_CONFIG__={"remote":"docker","apiBaseUrl":"/v1","disableCloud":true}',
457
+ 'window.__CADET_CONFIG__={"remote":"docker","apiBaseUrl":"/v1"}',
460
458
  );
461
459
  expect(result.indexOf('"webUrl"')).toBeLessThan(
462
460
  result.indexOf('"docker"'),
@@ -864,8 +862,6 @@ function spaConfigHash(
864
862
  config: {
865
863
  remote: "custom",
866
864
  apiBaseUrl: "/v1",
867
- cloudDisabled: true,
868
- disableCloud: true,
869
865
  ...(opts.assistantName ? { assistantName: opts.assistantName } : {}),
870
866
  ...(opts.assistantId ? { assistantId: opts.assistantId } : {}),
871
867
  hubUrl: PRODUCTION_HUB_URL,
@@ -1354,8 +1350,6 @@ describe("startRemoteWebIngress", () => {
1354
1350
  config: {
1355
1351
  remote: "custom",
1356
1352
  apiBaseUrl: "/v1",
1357
- cloudDisabled: true,
1358
- disableCloud: true,
1359
1353
  hubUrl: PRODUCTION_HUB_URL,
1360
1354
  },
1361
1355
  }),
@@ -4,6 +4,7 @@ import {
4
4
  beforeEach,
5
5
  describe,
6
6
  expect,
7
+ mock,
7
8
  spyOn,
8
9
  test,
9
10
  } from "bun:test";
@@ -19,9 +20,36 @@ process.env.CADET_LOCKFILE_DIR = testDir;
19
20
  const originalEnvironment = process.env.CADET_ENVIRONMENT;
20
21
  process.env.CADET_ENVIRONMENT = "production";
21
22
 
22
- import { buildAppConnectUrl, pair } from "../commands/pair.js";
23
23
  import { withPreconnect } from "./helpers/http.js";
24
24
 
25
+ // The gateway-CLI mint runs in a SUBPROCESS for local and docker assistants;
26
+ // answer it in-process and record the invocations (the fetch stubs below
27
+ // still serve the loopback HTTP mint the other topologies keep using).
28
+ const mintCalls: Array<{ command: string; args: readonly string[] }> = [];
29
+ const actualStepRunner = await import("../lib/step-runner.js");
30
+ const mockExecOutput = mock(
31
+ (command: string, args: readonly string[]): Promise<string> => {
32
+ mintCalls.push({ command, args });
33
+ const mintedUrl = args[args.length - 1] ?? "";
34
+ return Promise.resolve(
35
+ JSON.stringify({
36
+ deviceCode: "device-code",
37
+ userCode: "ABCD-EFGH",
38
+ verificationUri: `${mintedUrl}/assistant/pair`,
39
+ expiresAt: "2026-06-04T00:10:00.000Z",
40
+ expiresInSeconds: 600,
41
+ intervalSeconds: 5,
42
+ }),
43
+ );
44
+ },
45
+ );
46
+ mock.module("../lib/step-runner.js", () => ({
47
+ ...actualStepRunner,
48
+ execOutput: mockExecOutput,
49
+ }));
50
+
51
+ const { buildAppConnectUrl, pair } = await import("../commands/pair.js");
52
+
25
53
  // Distinct loopback (mint) vs reachable (advertised) URLs to verify the split.
26
54
  const LOCAL_URL = "http://127.0.0.1:7830";
27
55
  const RUNTIME_URL = "http://192.168.1.50:7830";
@@ -93,6 +121,7 @@ const ORIGINAL_ARGV = [...process.argv];
93
121
 
94
122
  describe("pair command", () => {
95
123
  beforeEach(() => {
124
+ mintCalls.length = 0;
96
125
  writeLockfile();
97
126
  });
98
127
 
@@ -130,18 +159,16 @@ describe("pair command", () => {
130
159
  globalThis.fetch = origFetch;
131
160
  }
132
161
 
133
- // Mint over the loopback gateway, then approve: running this command on
134
- // the host IS the approval, so the link alone completes the pairing.
135
- expect(calls.map((c) => c[0])).toEqual([
136
- `${LOCAL_URL}/v1/remote-web/pairing-challenge`,
137
- `${LOCAL_URL}/v1/remote-web/pairing-verification`,
162
+ // Mint through the gateway CLI subprocess: process execution IS the
163
+ // local-presence proof and the approval, so the link alone completes
164
+ // the pairing — no HTTP at all for a local assistant.
165
+ expect(mintCalls).toHaveLength(1);
166
+ expect(mintCalls[0]?.args.slice(-3)).toEqual([
167
+ "pairing",
168
+ "mint",
169
+ PUBLIC_URL,
138
170
  ]);
139
- expect(JSON.parse(String(calls[0][1]?.body))).toEqual({
140
- publicBaseUrl: PUBLIC_URL,
141
- });
142
- expect(JSON.parse(String(calls[1][1]?.body))).toEqual({
143
- userCode: "ABCD-EFGH",
144
- });
171
+ expect(calls).toHaveLength(0);
145
172
 
146
173
  const output = logs.join("\n");
147
174
  // One artifact, two renderings: the link and the same link as a QR.
@@ -391,10 +418,9 @@ describe("pair command", () => {
391
418
  }
392
419
 
393
420
  // Resolution succeeded (no exit), so the challenge was minted.
394
- expect(calls.map((c) => c[0])).toEqual([
395
- `${LOCAL_URL}/v1/remote-web/pairing-challenge`,
396
- `${LOCAL_URL}/v1/remote-web/pairing-verification`,
397
- ]);
421
+ expect(mintCalls).toHaveLength(1);
422
+ expect(mintCalls[0]?.args.at(-1)).toBe(PUBLIC_URL);
423
+ expect(calls).toHaveLength(0);
398
424
  });
399
425
 
400
426
  test("rejects an unknown --flag before any network call", async () => {
@@ -587,11 +613,8 @@ describe("pair command", () => {
587
613
  globalThis.fetch = origFetch;
588
614
  }
589
615
 
590
- // Mint still over loopback; the link advertises the override.
591
- expect(calls[0][0]).toBe(`${LOCAL_URL}/v1/remote-web/pairing-challenge`);
592
- expect(JSON.parse(String(calls[0][1]?.body))).toEqual({
593
- publicBaseUrl: OVERRIDE,
594
- });
616
+ // Mint still through the gateway CLI; the link advertises the override.
617
+ expect(mintCalls[0]?.args.at(-1)).toBe(OVERRIDE);
595
618
  expect(JSON.parse(logs.join("\n")).pairUrl).toBe(
596
619
  `${OVERRIDE}/assistant/pair#device_code=device-code`,
597
620
  );
@@ -1069,35 +1092,8 @@ describe("pair command", () => {
1069
1092
 
1070
1093
  const calls: string[] = [];
1071
1094
  const origFetch = globalThis.fetch;
1072
- globalThis.fetch = withPreconnect(async (input: RequestInfo | URL, init?: RequestInit) => {
1073
- const url = String(input);
1074
- calls.push(url);
1075
- if (url === `${LOCAL_URL}/v1/remote-web/pairing-challenge`) {
1076
- // The minted challenge must advertise the entry's recorded URL.
1077
- expect(JSON.parse(String(init?.body))).toEqual({
1078
- publicBaseUrl: "https://saved.example.ts.net",
1079
- });
1080
- return new Response(
1081
- JSON.stringify({
1082
- deviceCode: "device-code",
1083
- userCode: "ABCD-EFGH",
1084
- verificationUri: "https://saved.example.ts.net/assistant/pair",
1085
- expiresAt: "2026-06-04T00:10:00.000Z",
1086
- expiresInSeconds: 600,
1087
- }),
1088
- { status: 200, headers: { "content-type": "application/json" } },
1089
- );
1090
- }
1091
- if (url === `${LOCAL_URL}/v1/remote-web/pairing-verification`) {
1092
- return new Response(
1093
- JSON.stringify({
1094
- status: "approved",
1095
- verificationUri: "https://saved.example.ts.net/assistant/pair",
1096
- expiresAt: "2026-06-04T00:10:00.000Z",
1097
- }),
1098
- { status: 200, headers: { "content-type": "application/json" } },
1099
- );
1100
- }
1095
+ globalThis.fetch = withPreconnect(async (input: RequestInfo | URL) => {
1096
+ calls.push(String(input));
1101
1097
  return new Response("not found", { status: 404 });
1102
1098
  });
1103
1099
 
@@ -1116,7 +1112,9 @@ describe("pair command", () => {
1116
1112
  globalThis.fetch = origFetch;
1117
1113
  }
1118
1114
 
1119
- expect(calls).toContain(`${LOCAL_URL}/v1/remote-web/pairing-challenge`);
1115
+ // The minted challenge must advertise the entry's recorded URL.
1116
+ expect(mintCalls[0]?.args.at(-1)).toBe("https://saved.example.ts.net");
1117
+ expect(calls).toHaveLength(0);
1120
1118
  const output = logs.join("\n");
1121
1119
  expect(output).toContain(
1122
1120
  "Using saved ingress URL https://saved.example.ts.net",
@@ -1130,33 +1128,7 @@ describe("pair command", () => {
1130
1128
  writeLockfileWithIngress("https://saved.example.ts.net");
1131
1129
 
1132
1130
  const origFetch = globalThis.fetch;
1133
- globalThis.fetch = withPreconnect(async (input: RequestInfo | URL, init?: RequestInit) => {
1134
- const url = String(input);
1135
- if (url === `${LOCAL_URL}/v1/remote-web/pairing-challenge`) {
1136
- expect(JSON.parse(String(init?.body))).toEqual({
1137
- publicBaseUrl: "https://explicit.example.ts.net",
1138
- });
1139
- return new Response(
1140
- JSON.stringify({
1141
- deviceCode: "device-code",
1142
- userCode: "ABCD-EFGH",
1143
- verificationUri: "https://explicit.example.ts.net/assistant/pair",
1144
- expiresAt: "2026-06-04T00:10:00.000Z",
1145
- expiresInSeconds: 600,
1146
- }),
1147
- { status: 200, headers: { "content-type": "application/json" } },
1148
- );
1149
- }
1150
- if (url === `${LOCAL_URL}/v1/remote-web/pairing-verification`) {
1151
- return new Response(
1152
- JSON.stringify({
1153
- status: "approved",
1154
- verificationUri: "https://explicit.example.ts.net/assistant/pair",
1155
- expiresAt: "2026-06-04T00:10:00.000Z",
1156
- }),
1157
- { status: 200, headers: { "content-type": "application/json" } },
1158
- );
1159
- }
1131
+ globalThis.fetch = withPreconnect(async () => {
1160
1132
  return new Response("not found", { status: 404 });
1161
1133
  });
1162
1134
 
@@ -1182,6 +1154,8 @@ describe("pair command", () => {
1182
1154
  }
1183
1155
 
1184
1156
  expect(logs.join("\n")).not.toContain("Using saved ingress URL");
1157
+ // The override reached the mint.
1158
+ expect(mintCalls[0]?.args.at(-1)).toBe("https://explicit.example.ts.net");
1185
1159
  });
1186
1160
 
1187
1161
  test("a non-https recorded ingress URL is ignored", async () => {
@@ -1263,4 +1237,101 @@ describe("pair command", () => {
1263
1237
  expect(errors.join("\n")).toContain(RUNTIME_URL);
1264
1238
  expect(minted).toBe(false);
1265
1239
  });
1240
+
1241
+ test("refuses a paired (connect-import) assistant before minting", async () => {
1242
+ writeFileSync(
1243
+ join(testDir, "lockfile.json"),
1244
+ JSON.stringify({
1245
+ assistants: [
1246
+ {
1247
+ assistantId: "pair-test",
1248
+ runtimeUrl: RUNTIME_URL,
1249
+ cloud: "paired",
1250
+ },
1251
+ ],
1252
+ activeAssistant: "pair-test",
1253
+ }),
1254
+ );
1255
+
1256
+ const errors: string[] = [];
1257
+ const errSpy = spyOn(console, "error").mockImplementation(
1258
+ (...a: unknown[]) => {
1259
+ errors.push(a.join(" "));
1260
+ },
1261
+ );
1262
+ const exitSpy = spyOn(process, "exit").mockImplementation(
1263
+ (code?: number | string | undefined): never => {
1264
+ throw new Error(`exit:${code}`);
1265
+ },
1266
+ );
1267
+
1268
+ process.argv = ["bun", "cadet", "pair", "--url", PUBLIC_URL];
1269
+ let exited = false;
1270
+ try {
1271
+ await pair();
1272
+ } catch (e) {
1273
+ exited = e instanceof Error && e.message === "exit:1";
1274
+ } finally {
1275
+ errSpy.mockRestore();
1276
+ exitSpy.mockRestore();
1277
+ }
1278
+
1279
+ expect(exited).toBe(true);
1280
+ expect(errors.join("\n")).toContain("was paired as a remote");
1281
+ // Keyed on the entry's cloud, not on which fields happen to exist.
1282
+ expect(mintCalls).toHaveLength(0);
1283
+ });
1284
+
1285
+ test("a custom (ssh-managed) assistant keeps the loopback HTTP mint", async () => {
1286
+ writeFileSync(
1287
+ join(testDir, "lockfile.json"),
1288
+ JSON.stringify({
1289
+ assistants: [
1290
+ {
1291
+ assistantId: "pair-test",
1292
+ runtimeUrl: LOCAL_URL,
1293
+ cloud: "custom",
1294
+ },
1295
+ ],
1296
+ activeAssistant: "pair-test",
1297
+ }),
1298
+ );
1299
+
1300
+ const calls: Array<[string, RequestInit | undefined]> = [];
1301
+ const origFetch = globalThis.fetch;
1302
+ globalThis.fetch = withPreconnect(
1303
+ async (input: RequestInfo | URL, init?: RequestInit) => {
1304
+ const url = String(input);
1305
+ calls.push([url, init]);
1306
+ if (url === `${LOCAL_URL}/v1/remote-web/pairing-challenge`) {
1307
+ return challengeResponse(PUBLIC_URL);
1308
+ }
1309
+ if (url === `${LOCAL_URL}/v1/remote-web/pairing-verification`) {
1310
+ return approvalResponse(PUBLIC_URL);
1311
+ }
1312
+ return new Response("not found", { status: 404 });
1313
+ },
1314
+ );
1315
+
1316
+ const logSpy = spyOn(console, "log").mockImplementation(() => {});
1317
+
1318
+ process.argv = ["bun", "cadet", "pair", "--url", PUBLIC_URL];
1319
+ try {
1320
+ await pair();
1321
+ } finally {
1322
+ logSpy.mockRestore();
1323
+ globalThis.fetch = origFetch;
1324
+ }
1325
+
1326
+ // Not local/docker: no CLI execution — the mint rides the loopback HTTP
1327
+ // route, keyed on the entry's cloud, not on containerInfo.
1328
+ expect(mintCalls).toHaveLength(0);
1329
+ expect(calls.map((c) => c[0])).toEqual([
1330
+ `${LOCAL_URL}/v1/remote-web/pairing-challenge`,
1331
+ `${LOCAL_URL}/v1/remote-web/pairing-verification`,
1332
+ ]);
1333
+ expect(JSON.parse(String(calls[0]?.[1]?.body))).toEqual({
1334
+ publicBaseUrl: PUBLIC_URL,
1335
+ });
1336
+ });
1266
1337
  });
@@ -258,9 +258,10 @@ describe("cadet ps — platform status line", () => {
258
258
  await listAllAssistants(false);
259
259
 
260
260
  const output = stdout.join(NL);
261
- // The tunnel nests under Alice — its name is just the provider now…
262
- expect(output).toContain("└ ngrok");
263
- // …the unattributed edge renders machine-level…
261
+ // The tunnel and the edge render machine-level — root resources, never
262
+ // children of an assistant row…
263
+ expect(output).toContain("ngrok");
264
+ expect(output).not.toContain("└ ngrok");
264
265
  expect(output).toContain("nginx edge");
265
266
  // …the type column distinguishes the three process kinds…
266
267
  expect(output).toContain("🧑‍🚀 Assistant");
@@ -2567,7 +2567,6 @@ describe("platform credential injection", () => {
2567
2567
  bearerToken: "local-bearer",
2568
2568
  assistantApiKey: "api-key-123",
2569
2569
  cloudAssistantId: "platform-assistant-1",
2570
- cloudBaseUrl: "https://cloud.mycadet.ai",
2571
2570
  organizationId: "org-1",
2572
2571
  userId: "user-1",
2573
2572
  webhookSecret: "webhook-secret-123",
@@ -3008,17 +3007,3 @@ describe("upload signed-URL records source runtime version (not CLI version)", (
3008
3007
  });
3009
3008
  });
3010
3009
 
3011
- // ---------------------------------------------------------------------------
3012
- // Misc: legacy --to deprecation
3013
- // ---------------------------------------------------------------------------
3014
-
3015
- describe("misc", () => {
3016
- test("legacy --to flag shows deprecation message", async () => {
3017
- setArgv("--from", "source", "--to", "target");
3018
-
3019
- await expect(teleport()).rejects.toThrow("process.exit:1");
3020
- expect(consoleErrorSpy).toHaveBeenCalledWith(
3021
- expect.stringContaining("--to is deprecated"),
3022
- );
3023
- });
3024
- });