@mycadet/cli 0.13.0-dev.202610200020.9f20440 → 0.13.0-dev.202610201855.522ff0d

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 (80) hide show
  1. package/node_modules/@mycadet/assistant-api/constants/personality-sliders.test.ts +0 -8
  2. package/node_modules/@mycadet/assistant-api/constants/personality-sliders.ts +5 -41
  3. package/node_modules/@mycadet/assistant-api/events/message-complete.ts +0 -5
  4. package/node_modules/@mycadet/assistant-api/index.ts +0 -2
  5. package/node_modules/@mycadet/assistant-api/responses/conversation-message.ts +0 -10
  6. package/node_modules/@mycadet/environments/src/seeds.ts +6 -2
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/seeds.ts +6 -2
  8. package/node_modules/@mycadet/local-mode/src/config.ts +0 -2
  9. package/node_modules/@mycadet/local-mode/src/index.ts +1 -1
  10. package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +1 -22
  11. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +26 -7
  12. package/node_modules/@mycadet/local-mode/src/util.ts +1 -20
  13. package/node_modules/@mycadet/shared/github-repository.ts +5 -0
  14. package/node_modules/@mycadet/shared/package.json +10 -0
  15. package/node_modules/@mycadet/shared/scripts/run-isolated-tests.ts +700 -0
  16. package/package.json +3 -2
  17. package/src/__tests__/app-command.test.ts +164 -0
  18. package/src/__tests__/client-web-config.test.ts +0 -1
  19. package/src/__tests__/cloud-releases.test.ts +1 -1
  20. package/src/__tests__/local-version.test.ts +16 -0
  21. package/src/__tests__/nginx-ingress.test.ts +248 -630
  22. package/src/__tests__/ps-cloud-status.test.ts +85 -11
  23. package/src/__tests__/root-process-lockfile.test.ts +29 -2
  24. package/src/__tests__/tunnel-holder-heal.test.ts +119 -0
  25. package/src/__tests__/tunnel-stop.test.ts +6 -13
  26. package/src/__tests__/tunnel.test.ts +50 -193
  27. package/src/__tests__/wake.test.ts +6 -38
  28. package/src/__tests__/web-dist.test.ts +267 -89
  29. package/src/commands/app.ts +113 -0
  30. package/src/commands/backup.ts +5 -4
  31. package/src/commands/clean.ts +2 -1
  32. package/src/commands/client.ts +5 -68
  33. package/src/commands/completions.ts +12 -1
  34. package/src/commands/connect.ts +2 -1
  35. package/src/commands/debug.ts +2 -1
  36. package/src/commands/exec.ts +7 -6
  37. package/src/commands/gateway/token.ts +2 -1
  38. package/src/commands/gateway.ts +2 -1
  39. package/src/commands/hatch.ts +74 -80
  40. package/src/commands/login.ts +7 -6
  41. package/src/commands/logs.ts +2 -1
  42. package/src/commands/ps.ts +136 -6
  43. package/src/commands/restart.ts +2 -1
  44. package/src/commands/restore.ts +10 -9
  45. package/src/commands/retire.ts +4 -3
  46. package/src/commands/setup.ts +5 -4
  47. package/src/commands/sleep.ts +3 -2
  48. package/src/commands/teleport.ts +2 -1
  49. package/src/commands/terminal.ts +7 -6
  50. package/src/commands/tunnel.ts +196 -242
  51. package/src/commands/uninstall.ts +2 -1
  52. package/src/commands/upgrade.ts +2 -1
  53. package/src/commands/use.ts +2 -1
  54. package/src/commands/wake.ts +3 -2
  55. package/src/index.ts +5 -4
  56. package/src/lib/__tests__/web-dist.test.ts +1 -27
  57. package/src/lib/assistant-config.ts +101 -37
  58. package/src/lib/cli-name.ts +14 -0
  59. package/src/lib/cloud-client.ts +2 -1
  60. package/src/lib/cloud-login-poll.ts +2 -1
  61. package/src/lib/cloud-releases.ts +1 -1
  62. package/src/lib/docker.ts +32 -21
  63. package/src/lib/hatch-local.ts +1 -3
  64. package/src/lib/hatch-next-steps.ts +1 -9
  65. package/src/lib/ingress-config.ts +0 -31
  66. package/src/lib/local-version.ts +25 -4
  67. package/src/lib/local.ts +34 -9
  68. package/src/lib/nginx-ingress.ts +143 -244
  69. package/src/lib/provider-secrets.ts +0 -5
  70. package/src/lib/statefulset.ts +0 -1
  71. package/src/lib/tunnel.ts +244 -43
  72. package/src/lib/tunnels/ngrok.ts +57 -9
  73. package/src/lib/tunnels/tailscale.ts +2 -1
  74. package/src/lib/web-dist.ts +134 -56
  75. package/src/__tests__/flags.test.ts +0 -318
  76. package/src/__tests__/shell-mode.test.ts +0 -83
  77. package/src/commands/flags.ts +0 -255
  78. package/src/lib/flag-args.test.ts +0 -84
  79. package/src/lib/flag-args.ts +0 -74
  80. package/src/lib/github-repository.ts +0 -2
@@ -26,22 +26,38 @@ import {
26
26
  import { z } from "zod";
27
27
 
28
28
  import * as httpClient from "../lib/http-client.js";
29
+ import * as localVersionModule from "../lib/local-version.js";
29
30
  import type { AssistantEntry } from "../lib/assistant-config.js";
30
- import { saveShellMode } from "../lib/ingress-config.js";
31
31
 
32
32
  const realChildProcess = { ...childProcess };
33
33
  const realFs = { ...fsModule };
34
34
  const realHttpClient = { ...httpClient };
35
+ const realLocalVersion = { ...localVersionModule };
35
36
 
36
37
  const execFileSyncMock = mock(childProcess.execFileSync);
37
38
  const spawnSyncMock = mock(childProcess.spawnSync);
38
39
  const spawnMock = mock(childProcess.spawn);
39
40
 
41
+ /**
42
+ * A git rev-parse that fails like a git-less tree: the built-sha stamp's
43
+ * staleness probe stays inert and the per-test nginx fakes never see a git
44
+ * spawn.
45
+ */
46
+ function gitStubSpawn(): childProcess.ChildProcess {
47
+ const child = new childProcess.ChildProcess();
48
+ Object.defineProperty(child, "stdout", { value: null });
49
+ setTimeout(() => child.emit("exit", 1), 0);
50
+ return child;
51
+ }
52
+
40
53
  mock.module("node:child_process", () => ({
41
54
  ...childProcess,
42
55
  execFileSync: execFileSyncMock,
43
56
  spawnSync: spawnSyncMock,
44
- spawn: spawnMock,
57
+ spawn: ((command: string, args: readonly string[], options?: SpawnOptions) =>
58
+ command === "git"
59
+ ? gitStubSpawn()
60
+ : spawnMock(command, args, options ?? {})) as typeof childProcess.spawn,
45
61
  }));
46
62
 
47
63
  const existsSyncMock = mock(fsModule.existsSync);
@@ -53,10 +69,6 @@ mock.module("node:fs", () => ({
53
69
  readFileSync: readFileSyncMock,
54
70
  }));
55
71
 
56
- const fetchCurrentVersionMock = mock<typeof httpClient.fetchCurrentVersion>(
57
- async () => "1.2.3",
58
- );
59
-
60
72
  const waitForDaemonReadyMock = mock<typeof httpClient.waitForDaemonReady>(
61
73
  async () => true,
62
74
  );
@@ -64,7 +76,14 @@ const waitForDaemonReadyMock = mock<typeof httpClient.waitForDaemonReady>(
64
76
  mock.module("../lib/http-client.js", () => ({
65
77
  ...httpClient,
66
78
  waitForDaemonReady: waitForDaemonReadyMock,
67
- fetchCurrentVersion: fetchCurrentVersionMock,
79
+ }));
80
+
81
+ // The edge stamps the CLI's own displayVersion as the served version — a
82
+ // fixed value here keeps the fingerprint replicas below exact.
83
+ const displayVersionMock = mock(() => "1.2.3");
84
+
85
+ mock.module("../lib/local-version.js", () => ({
86
+ displayVersion: displayVersionMock,
68
87
  }));
69
88
 
70
89
  // Restore the real modules once this file finishes so the mocks do not leak
@@ -73,6 +92,7 @@ afterAll(() => {
73
92
  mock.module("node:child_process", () => realChildProcess);
74
93
  mock.module("node:fs", () => realFs);
75
94
  mock.module("../lib/http-client.js", () => realHttpClient);
95
+ mock.module("../lib/local-version.js", () => realLocalVersion);
76
96
  });
77
97
 
78
98
  import {
@@ -131,8 +151,8 @@ afterEach(() => {
131
151
  existsSyncMock.mockImplementation(realFs.existsSync);
132
152
  readFileSyncMock.mockReset();
133
153
  readFileSyncMock.mockImplementation(realFs.readFileSync);
134
- fetchCurrentVersionMock.mockReset();
135
- fetchCurrentVersionMock.mockImplementation(async () => "1.2.3");
154
+ displayVersionMock.mockReset();
155
+ displayVersionMock.mockImplementation(() => "1.2.3");
136
156
  waitForDaemonReadyMock.mockReset();
137
157
  waitForDaemonReadyMock.mockImplementation(async () => true);
138
158
  for (const dir of workspaces.splice(0)) {
@@ -160,6 +180,14 @@ function readConfig(workspaceDir: string) {
160
180
  );
161
181
  }
162
182
 
183
+ /** Seed the workspace's saved tunnel URL (ingress.publicBaseUrl). */
184
+ function writeWorkspaceIngressUrl(workspaceDir: string, url: string): void {
185
+ realFs.writeFileSync(
186
+ join(workspaceDir, "config.json"),
187
+ JSON.stringify({ ingress: { publicBaseUrl: url } }),
188
+ );
189
+ }
190
+
163
191
  describe("buildIngressNginxConfig", () => {
164
192
  const conf = buildIngressNginxConfig({ gatewayPort: 7830, listenPort: 7840 });
165
193
  const remoteConf = buildIngressNginxConfig({
@@ -167,6 +195,7 @@ describe("buildIngressNginxConfig", () => {
167
195
  listenPort: 7840,
168
196
  remoteWebIngress: {
169
197
  webDistDir: "/tmp/cadet web/dist",
198
+ appDistDir: "/tmp/cadet app/dist/standalone",
170
199
  config: {
171
200
  remote: "docker",
172
201
  apiBaseUrl: "/v1",
@@ -257,33 +286,6 @@ describe("buildIngressNginxConfig", () => {
257
286
  expect(remoteConf).toContain("image/svg+xml svg svgz;");
258
287
  });
259
288
 
260
- test("serves the remote web SPA from /assistant when configured", () => {
261
- expect(remoteConf).toContain("location = / {");
262
- expect(remoteConf).toContain("return 302 /assistant/;");
263
- expect(remoteConf.indexOf("location = / {")).toBeLessThan(
264
- remoteConf.indexOf("location / {"),
265
- );
266
- expect(remoteConf).toContain("location = /assistant {");
267
- expect(remoteConf).toContain("return 302 /assistant/;");
268
- expect(remoteConf).toContain("location ^~ /assistant/assets/ {");
269
- expect(remoteConf).toContain('alias "/tmp/cadet web/dist/assets/";');
270
- expect(remoteConf).toContain("try_files $uri =404;");
271
- expect(remoteConf).toContain("location = /assistant/ {");
272
- expect(remoteConf).toContain(
273
- "rewrite ^ /assistant/__remote-index.html last;",
274
- );
275
- expect(remoteConf).toContain("location = /assistant/index.html {");
276
- expect(remoteConf).toContain("location = /assistant/__remote-index.html {");
277
- expect(remoteConf).toContain("internal;");
278
- expect(remoteConf).toContain('alias "/tmp/cadet web/dist/index.html";');
279
- expect(remoteConf).toContain("location ^~ /assistant/ {");
280
- expect(remoteConf).toContain('alias "/tmp/cadet web/dist/";');
281
- expect(remoteConf).toContain(
282
- "try_files $uri $uri/ /assistant/__remote-index.html;",
283
- );
284
- expect(remoteConf).toContain("location / {\n return 404;\n }");
285
- });
286
-
287
289
  test("compresses text asset types", () => {
288
290
  expect(remoteConf).toContain(
289
291
  "gzip_types application/javascript application/json application/wasm image/svg+xml text/css text/plain;",
@@ -303,9 +305,13 @@ describe("buildIngressNginxConfig", () => {
303
305
  .map((b) => b.matcher)
304
306
  .sort(),
305
307
  ).toEqual([
306
- "= /assistant/__remote-index.html",
308
+ "/",
309
+ "= /__cadet-app-index.html",
310
+ "= /web/assistant/__remote-index.html",
311
+ "^~ /assets/",
307
312
  "^~ /assistant/",
308
313
  "^~ /assistant/assets/",
314
+ "^~ /web/assistant/",
309
315
  ]);
310
316
  expect(
311
317
  blocks
@@ -322,17 +328,24 @@ describe("buildIngressNginxConfig", () => {
322
328
  blocks
323
329
  .find((b) => b.matcher === matcher)
324
330
  ?.body.match(/add_header Cache-Control "([^"]+)"/)?.[1];
325
- expect(cacheControlOf("= /assistant/__remote-index.html")).toBe("no-cache");
326
- expect(cacheControlOf("^~ /assistant/")).toBe("no-cache");
331
+ expect(cacheControlOf("= /web/assistant/__remote-index.html")).toBe(
332
+ "no-cache",
333
+ );
334
+ expect(cacheControlOf("^~ /web/assistant/")).toBe("no-cache");
327
335
  expect(cacheControlOf("^~ /assistant/assets/")).toBe(
328
336
  "public, max-age=31536000, immutable",
329
337
  );
338
+ // The app shell's own document revalidates too; its hashed assets don't.
339
+ expect(cacheControlOf("= /__cadet-app-index.html")).toBe("no-cache");
340
+ expect(cacheControlOf("^~ /assets/")).toBe(
341
+ "public, max-age=31536000, immutable",
342
+ );
330
343
  // Inline config has no validator and must not be stored.
331
- expect(cacheControlOf("= /assistant/__config")).toBe("no-store");
344
+ expect(cacheControlOf("= /web/assistant/__config")).toBe("no-store");
332
345
  });
333
346
 
334
347
  test("serves remote web config for the SPA", () => {
335
- expect(remoteConf).toContain("location = /assistant/__config {");
348
+ expect(remoteConf).toContain("location = /web/assistant/__config {");
336
349
  expect(remoteConf).toContain("default_type application/json;");
337
350
  expect(remoteConf).toContain('add_header Cache-Control "no-store";');
338
351
  expect(remoteConf).toContain(
@@ -347,6 +360,7 @@ describe("buildIngressNginxConfig", () => {
347
360
  listenPort: 7840,
348
361
  remoteWebIngress: {
349
362
  webDistDir: "/tmp/cadet web/dist",
363
+ appDistDir: "/tmp/cadet app/dist/standalone",
350
364
  assistantName: "Homelab",
351
365
  assistantId: "assistant-1",
352
366
  hubUrl: "https://mycadet.ai/assistant",
@@ -354,7 +368,7 @@ describe("buildIngressNginxConfig", () => {
354
368
  },
355
369
  });
356
370
  expect(named).toContain(
357
- 'return 200 "{\\"remote\\":\\"custom\\",\\"apiBaseUrl\\":\\"/v1\\",\\"assistantName\\":\\"Homelab\\",\\"assistantId\\":\\"assistant-1\\",\\"hubUrl\\":\\"https://mycadet.ai/assistant\\",\\"version\\":\\"1.2.3\\"}";',
371
+ 'return 200 "{\\"remote\\":\\"custom\\",\\"assistantName\\":\\"Homelab\\",\\"assistantId\\":\\"assistant-1\\",\\"hubUrl\\":\\"https://mycadet.ai/assistant\\",\\"version\\":\\"1.2.3\\"}";',
358
372
  );
359
373
  });
360
374
 
@@ -654,6 +668,18 @@ describe("nginx ingress process state", () => {
654
668
  const NGINX_VERSION = "nginx version: nginx/1.29.0";
655
669
  const FAKE_INDEX_HTML = "<html><head></head><body></body></html>";
656
670
  const WEB_INDEX_SUFFIX = join("dist", "index.html");
671
+ const APP_INDEX_SUFFIX = join("standalone", "index.html");
672
+ const FAKE_APP_INDEX_HTML =
673
+ "<!doctype html><html><head><title>app</title></head><body>app-shell</body></html>";
674
+
675
+ /** The app dist the mocked fs presents (npm-arm resolution, like web's). */
676
+ function fakeAppDistDir(): string {
677
+ const dist = findAppDistDir();
678
+ if (dist === null) {
679
+ throw new Error("expected a mocked app dist dir");
680
+ }
681
+ return dist;
682
+ }
657
683
 
658
684
  function ingressConfPath(workspaceDir: string): string {
659
685
  return join(workspaceDir, "data", "ingress", "nginx.conf");
@@ -751,19 +777,21 @@ function mockWebDistMissing(): void {
751
777
  }
752
778
 
753
779
  /** Force findWebDistDir() to resolve a dist dir, regardless of checkout state. */
754
- function mockWebDistPresent(version: string | null = "1.2.3"): void {
755
- existsSyncMock.mockImplementation((path) =>
756
- String(path).endsWith(WEB_INDEX_SUFFIX) ? true : realFs.existsSync(path),
757
- );
758
- readFileSyncMock.mockImplementation(((path, options) =>
759
- String(path).endsWith(WEB_INDEX_SUFFIX)
760
- ? FAKE_INDEX_HTML
761
- : String(path).endsWith("release.json")
762
- ? JSON.stringify(version === null ? {} : { version })
763
- : realFs.readFileSync(
764
- path as never,
765
- options as never,
766
- )) as typeof readFileSync);
780
+ function mockWebDistPresent(): void {
781
+ // The edge always serves both bundles (the app shell plus the iframed web
782
+ // SPA), so one mock presents both dists.
783
+ existsSyncMock.mockImplementation((path) => {
784
+ const p = String(path);
785
+ if (p.endsWith(WEB_INDEX_SUFFIX)) return true;
786
+ if (p.endsWith(APP_INDEX_SUFFIX)) return true;
787
+ return realFs.existsSync(path);
788
+ });
789
+ readFileSyncMock.mockImplementation(((path, options) => {
790
+ const p = String(path);
791
+ if (p.endsWith(WEB_INDEX_SUFFIX)) return FAKE_INDEX_HTML;
792
+ if (p.endsWith(APP_INDEX_SUFFIX)) return FAKE_APP_INDEX_HTML;
793
+ return realFs.readFileSync(path as never, options as never);
794
+ }) as typeof readFileSync);
767
795
  }
768
796
 
769
797
  /** Record a running edge: ingress state, live pidfile, matching ps output. */
@@ -771,7 +799,6 @@ function mockRunningEdge(
771
799
  ws: string,
772
800
  opts: {
773
801
  listenPort: number;
774
- includeWebApp?: boolean;
775
802
  gatewayPort?: number;
776
803
  remoteWebConfigHash?: string;
777
804
  },
@@ -783,9 +810,6 @@ function mockRunningEdge(
783
810
  ingress: {
784
811
  nginx: {
785
812
  listenPort: opts.listenPort,
786
- ...(opts.includeWebApp === undefined
787
- ? {}
788
- : { includeWebApp: opts.includeWebApp }),
789
813
  ...(opts.gatewayPort === undefined
790
814
  ? {}
791
815
  : { gatewayPort: opts.gatewayPort }),
@@ -842,45 +866,6 @@ function locationBlocks(
842
866
 
843
867
  const PRODUCTION_HUB_URL = "https://mycadet.ai/assistant";
844
868
 
845
- /**
846
- * Mirror of the SPA config fingerprint the edge records in its ingress state
847
- * (sha256 over the template, injected config, bundle directory and index). Pins
848
- * both the injected config shape and the hash format; assumes the
849
- * production-pinned environment. The version itself is imported rather than
850
- * mirrored: bumping it is the correct response to any template edit, so a
851
- * copy here would fail every such edit without naming a defect.
852
- */
853
- function spaConfigHash(
854
- opts: {
855
- assistantName?: string;
856
- assistantId?: string;
857
- indexHtml?: string;
858
- webDistDir?: string;
859
- } = {},
860
- ): string {
861
- return createHash("sha256")
862
- .update(
863
- JSON.stringify({
864
- template: EDGE_TEMPLATE_VERSION,
865
- config: {
866
- remote: "custom",
867
- apiBaseUrl: "/v1",
868
- ...(opts.assistantName ? { assistantName: opts.assistantName } : {}),
869
- ...(opts.assistantId ? { assistantId: opts.assistantId } : {}),
870
- hubUrl: PRODUCTION_HUB_URL,
871
- version: "1.2.3",
872
- },
873
- webDistDir: opts.webDistDir ?? findWebDistDir(),
874
- version: "1.2.3",
875
- // Web mode is the default shell; the fingerprint covers the mode so
876
- // an edge built for the other shell is never mistaken for this one.
877
- shellMode: "web",
878
- indexHtml: opts.indexHtml ?? FAKE_INDEX_HTML,
879
- }),
880
- )
881
- .digest("hex");
882
- }
883
-
884
869
  const originalEnvironment = process.env.CADET_ENVIRONMENT;
885
870
 
886
871
  /** Pin the build environment so the stamped hubUrl is deterministic. */
@@ -900,55 +885,11 @@ function pinProductionEnvironment(): void {
900
885
  describe("startRemoteWebIngress", () => {
901
886
  pinProductionEnvironment();
902
887
 
903
- for (const [webVersion, runtimeVersion, ready] of [
904
- ["1.2.3", "1.2.3", true],
905
- ["1.2.3", "v1.2.3", true],
906
- ["1.2.2", "1.2.3", false],
907
- ["1.2.3", undefined, false],
908
- [null, "1.2.3", false],
909
- ] as const) {
910
- test(`release resolution: UI ${webVersion}, assistant ${runtimeVersion}`, async () => {
911
- const ws = makeWorkspace();
912
- mockNginxInstalled();
913
- mockNginxSpawn();
914
- mockWebDistPresent(webVersion);
915
- fetchCurrentVersionMock.mockResolvedValue(runtimeVersion);
916
- const result = await startRemoteWebIngress({
917
- workspaceDir: ws,
918
- gatewayPort: 7830,
919
- listenPort: 7845,
920
- assistantId: "assistant-1",
921
- });
922
- expect(result.status).toBe("started");
923
- expect(fetchCurrentVersionMock).toHaveBeenCalledWith(
924
- "http://127.0.0.1:7830",
925
- );
926
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf8");
927
- const detail = conf
928
- .split('location = "/v1/assistants/assistant-1/" {')[1]
929
- ?.split("\n }")[0];
930
- expect(detail).toContain(`return ${ready ? 200 : 409} `);
931
- if (ready) {
932
- expect(detail).toContain('\\"version\\":\\"1.2.3\\"');
933
- } else {
934
- expect(detail).not.toContain('\\"url\\"');
935
- }
936
- });
937
- }
938
-
939
- test("restarts an edge when its verified assistant/UI release changes", async () => {
888
+ test("the metadata route serves the CLI's own version stamp, always ready", async () => {
940
889
  const ws = makeWorkspace();
941
890
  mockNginxInstalled();
942
891
  mockNginxSpawn();
943
- mockWebDistPresent("1.2.3");
944
- fetchCurrentVersionMock.mockResolvedValue("1.2.4");
945
- const pid = mockRunningEdge(ws, {
946
- listenPort: 7845,
947
- includeWebApp: true,
948
- gatewayPort: 7830,
949
- remoteWebConfigHash: spaConfigHash({ assistantId: "assistant-1" }),
950
- });
951
- const edge = mockKillableNginx(pid);
892
+ mockWebDistPresent();
952
893
  const result = await startRemoteWebIngress({
953
894
  workspaceDir: ws,
954
895
  gatewayPort: 7830,
@@ -956,69 +897,18 @@ describe("startRemoteWebIngress", () => {
956
897
  assistantId: "assistant-1",
957
898
  });
958
899
  expect(result.status).toBe("started");
959
- expect(edge.killed()).toBe(true);
960
900
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf8");
961
901
  const detail = conf
962
902
  .split('location = "/v1/assistants/assistant-1/" {')[1]
963
903
  ?.split("\n }")[0];
964
- expect(detail).toContain("return 409 ");
904
+ // The version is the CLI's own stamp (mocked to "1.2.3" here), so the
905
+ // detail route is always a 200 — the served page's "which one is
906
+ // running" answer follows the CLI, not the runtime's /healthz.
907
+ expect(detail).toContain("return 200 ");
908
+ expect(detail).toContain('\\"version\\":\\"1.2.3\\"');
965
909
  });
966
910
 
967
- test("webhooks-only mode starts the denylist+proxy edge without a web dist", async () => {
968
- const ws = makeWorkspace();
969
- mockNginxInstalled();
970
- mockNginxSpawn();
971
- mockWebDistMissing();
972
-
973
- const onStarting = mock(
974
- (_info: {
975
- version: string;
976
- webDistDir: string | null;
977
- listenPort: number;
978
- }) => {},
979
- );
980
- const result = await startRemoteWebIngress({
981
- workspaceDir: ws,
982
- gatewayPort: 7830,
983
- listenPort: 7845,
984
- includeWebApp: false,
985
- onStarting,
986
- });
987
-
988
- expect(result).toEqual({
989
- status: "started",
990
- listenPort: 7845,
991
- webDistDir: null,
992
- version: NGINX_VERSION,
993
- });
994
- expect(onStarting).toHaveBeenCalledWith({
995
- version: NGINX_VERSION,
996
- webDistDir: null,
997
- listenPort: 7845,
998
- });
999
-
1000
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
1001
- expect(conf).toBe(
1002
- buildIngressNginxConfig({
1003
- gatewayPort: 7830,
1004
- listenPort: 7845,
1005
- ipv6Loopback: hasIpv6Loopback(),
1006
- }),
1007
- );
1008
- expect(conf).toContain("location = /auth/token { return 404; }");
1009
- expect(conf).toContain("location = /v1/pair { return 404; }");
1010
- expect(conf).toContain("proxy_pass http://127.0.0.1:7830;");
1011
- expect(conf).not.toContain("__remote-index.html");
1012
- expect(conf).not.toContain("location ^~ /assistant/assets/");
1013
- expect(conf).not.toContain("alias ");
1014
- expect(readConfig(ws).ingress?.nginx).toEqual({
1015
- listenPort: 7845,
1016
- includeWebApp: false,
1017
- gatewayPort: 7830,
1018
- });
1019
- });
1020
-
1021
- test("default mode serves the SPA config unchanged", async () => {
911
+ test("serves the SPA config unchanged", async () => {
1022
912
  const ws = makeWorkspace();
1023
913
  mockNginxInstalled();
1024
914
  mockNginxSpawn();
@@ -1046,7 +936,9 @@ describe("startRemoteWebIngress", () => {
1046
936
  ipv6Loopback: hasIpv6Loopback(),
1047
937
  remoteWebIngress: {
1048
938
  webDistDir,
939
+ appDistDir: fakeAppDistDir(),
1049
940
  indexHtmlPath: join(ws, "data", "ingress", "assistant-index.html"),
941
+ appIndexHtmlPath: join(ws, "data", "ingress", "app-index.html"),
1050
942
  hubUrl: PRODUCTION_HUB_URL,
1051
943
  version: "1.2.3",
1052
944
  },
@@ -1065,9 +957,8 @@ describe("startRemoteWebIngress", () => {
1065
957
  expect(indexHtml).not.toContain("assistantName");
1066
958
  expect(readConfig(ws).ingress?.nginx).toEqual({
1067
959
  listenPort: 7845,
1068
- includeWebApp: true,
1069
960
  gatewayPort: 7830,
1070
- remoteWebConfigHash: spaConfigHash(),
961
+ remoteWebConfigHash: appConfigHash(),
1071
962
  });
1072
963
  });
1073
964
 
@@ -1134,7 +1025,7 @@ describe("startRemoteWebIngress", () => {
1134
1025
  expect(conf).toContain('\\"assistantName\\":\\"My Homelab\\"');
1135
1026
  });
1136
1027
 
1137
- test("default mode still requires the web dist", async () => {
1028
+ test("requires the web dist", async () => {
1138
1029
  const ws = makeWorkspace();
1139
1030
  mockNginxInstalled();
1140
1031
  mockNginxSpawn();
@@ -1162,6 +1053,7 @@ describe("startRemoteWebIngress", () => {
1162
1053
  existsSyncMock.mockImplementation((path) => {
1163
1054
  const p = String(path);
1164
1055
  if (p.endsWith(WEB_INDEX_SUFFIX)) return false;
1056
+ if (p.endsWith(APP_INDEX_SUFFIX)) return true;
1165
1057
  if (p.includes("clients/web/package.json")) return true;
1166
1058
  return realFs.existsSync(path);
1167
1059
  });
@@ -1200,7 +1092,6 @@ describe("startRemoteWebIngress", () => {
1200
1092
  expect(buildCalls).toHaveLength(1);
1201
1093
  const [, buildArgs, buildOptions] = buildCalls[0] ?? [];
1202
1094
  expect(buildArgs).toEqual(["run", "build"]);
1203
- expect(buildOptions?.env?.VITE_CLOUD_MODE).toBe("false");
1204
1095
  expect(String(buildOptions?.cwd).endsWith(join("clients", "web"))).toBe(
1205
1096
  true,
1206
1097
  );
@@ -1214,6 +1105,7 @@ describe("startRemoteWebIngress", () => {
1214
1105
  existsSyncMock.mockImplementation((path) => {
1215
1106
  const p = String(path);
1216
1107
  if (p.endsWith(WEB_INDEX_SUFFIX)) return false;
1108
+ if (p.endsWith(APP_INDEX_SUFFIX)) return true;
1217
1109
  if (p.includes("clients/web/package.json")) return true;
1218
1110
  return realFs.existsSync(path);
1219
1111
  });
@@ -1229,45 +1121,18 @@ describe("startRemoteWebIngress", () => {
1229
1121
  gatewayPort: 7830,
1230
1122
  listenPort: 7845,
1231
1123
  }),
1232
- ).rejects.toThrow("cd clients/web && VITE_CLOUD_MODE=false bun run build");
1233
- });
1234
-
1235
- test("short-circuits when the running edge already serves the requested mode", async () => {
1236
- const ws = makeWorkspace();
1237
- mockNginxInstalled();
1238
- mockNginxSpawn();
1239
- const pid = mockRunningEdge(ws, {
1240
- listenPort: 7845,
1241
- includeWebApp: false,
1242
- gatewayPort: 7830,
1243
- });
1244
- const edge = mockKillableNginx(pid);
1245
-
1246
- const result = await startRemoteWebIngress({
1247
- workspaceDir: ws,
1248
- gatewayPort: 7830,
1249
- listenPort: 7845,
1250
- includeWebApp: false,
1251
- });
1252
-
1253
- expect(result).toEqual({
1254
- status: "already-running",
1255
- listenPort: 7845,
1256
- includeWebApp: false,
1257
- gatewayPort: 7830,
1258
- });
1259
- expect(edge.killed()).toBe(false);
1260
- expect(spawnMock).not.toHaveBeenCalled();
1124
+ ).rejects.toThrow("cd clients/web && bun run build");
1261
1125
  });
1262
1126
 
1263
1127
  test("already-running carries the recorded listen port over the requested one", async () => {
1264
1128
  const ws = makeWorkspace();
1265
1129
  mockNginxInstalled();
1266
1130
  mockNginxSpawn();
1131
+ mockWebDistPresent();
1267
1132
  const pid = mockRunningEdge(ws, {
1268
1133
  listenPort: 7845,
1269
- includeWebApp: false,
1270
1134
  gatewayPort: 7830,
1135
+ remoteWebConfigHash: appConfigHash(),
1271
1136
  });
1272
1137
  const edge = mockKillableNginx(pid);
1273
1138
 
@@ -1275,27 +1140,24 @@ describe("startRemoteWebIngress", () => {
1275
1140
  workspaceDir: ws,
1276
1141
  gatewayPort: 7830,
1277
1142
  listenPort: 7999,
1278
- includeWebApp: false,
1279
1143
  });
1280
1144
 
1281
1145
  expect(result).toEqual({
1282
1146
  status: "already-running",
1283
1147
  listenPort: 7845,
1284
- includeWebApp: false,
1285
1148
  gatewayPort: 7830,
1286
1149
  });
1287
1150
  expect(edge.killed()).toBe(false);
1288
1151
  expect(spawnMock).not.toHaveBeenCalled();
1289
1152
  });
1290
1153
 
1291
- test("a failed restart reports the recorded mode and gateway port", async () => {
1154
+ test("a failed restart reports the recorded gateway port", async () => {
1292
1155
  const ws = makeWorkspace();
1293
1156
  mockNginxInstalled();
1294
1157
  mockNginxSpawn();
1295
- mockWebDistMissing();
1158
+ mockWebDistPresent();
1296
1159
  const pid = mockRunningEdge(ws, {
1297
1160
  listenPort: 7845,
1298
- includeWebApp: true,
1299
1161
  gatewayPort: 7900,
1300
1162
  });
1301
1163
  mockUnkillableNginx(pid);
@@ -1304,13 +1166,11 @@ describe("startRemoteWebIngress", () => {
1304
1166
  workspaceDir: ws,
1305
1167
  gatewayPort: 7830,
1306
1168
  listenPort: 7845,
1307
- includeWebApp: false,
1308
1169
  });
1309
1170
 
1310
1171
  expect(result).toEqual({
1311
1172
  status: "already-running",
1312
1173
  listenPort: 7845,
1313
- includeWebApp: true,
1314
1174
  gatewayPort: 7900,
1315
1175
  });
1316
1176
  expect(spawnMock).not.toHaveBeenCalled();
@@ -1320,10 +1180,9 @@ describe("startRemoteWebIngress", () => {
1320
1180
  const ws = makeWorkspace();
1321
1181
  mockNginxInstalled();
1322
1182
  mockNginxSpawn();
1323
- mockWebDistMissing();
1183
+ mockWebDistPresent();
1324
1184
  const pid = mockRunningEdge(ws, {
1325
1185
  listenPort: 7845,
1326
- includeWebApp: false,
1327
1186
  gatewayPort: 7900,
1328
1187
  });
1329
1188
  const edge = mockKillableNginx(pid);
@@ -1332,15 +1191,12 @@ describe("startRemoteWebIngress", () => {
1332
1191
  workspaceDir: ws,
1333
1192
  gatewayPort: 7830,
1334
1193
  listenPort: 7845,
1335
- includeWebApp: false,
1336
1194
  });
1337
1195
 
1338
- expect(result).toEqual({
1339
- status: "started",
1340
- listenPort: 7845,
1341
- webDistDir: null,
1342
- version: NGINX_VERSION,
1343
- });
1196
+ if (result.status !== "started") {
1197
+ throw new Error(`expected started, got ${result.status}`);
1198
+ }
1199
+ const { webDistDir } = result;
1344
1200
  expect(edge.killed()).toBe(true);
1345
1201
  expect(spawnMock).toHaveBeenCalledTimes(1);
1346
1202
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
@@ -1349,13 +1205,21 @@ describe("startRemoteWebIngress", () => {
1349
1205
  gatewayPort: 7830,
1350
1206
  listenPort: 7845,
1351
1207
  ipv6Loopback: hasIpv6Loopback(),
1208
+ remoteWebIngress: {
1209
+ webDistDir,
1210
+ appDistDir: fakeAppDistDir(),
1211
+ indexHtmlPath: join(ws, "data", "ingress", "assistant-index.html"),
1212
+ appIndexHtmlPath: join(ws, "data", "ingress", "app-index.html"),
1213
+ hubUrl: PRODUCTION_HUB_URL,
1214
+ version: "1.2.3",
1215
+ },
1352
1216
  }),
1353
1217
  );
1354
1218
  expect(conf).toContain("proxy_pass http://127.0.0.1:7830;");
1355
1219
  expect(readConfig(ws).ingress?.nginx).toEqual({
1356
1220
  listenPort: 7845,
1357
- includeWebApp: false,
1358
1221
  gatewayPort: 7830,
1222
+ remoteWebConfigHash: appConfigHash(),
1359
1223
  });
1360
1224
  });
1361
1225
 
@@ -1363,23 +1227,20 @@ describe("startRemoteWebIngress", () => {
1363
1227
  const ws = makeWorkspace();
1364
1228
  mockNginxInstalled();
1365
1229
  mockNginxSpawn();
1366
- mockWebDistMissing();
1367
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: false });
1230
+ mockWebDistPresent();
1231
+ const pid = mockRunningEdge(ws, { listenPort: 7845 });
1368
1232
  const edge = mockKillableNginx(pid);
1369
1233
 
1370
1234
  const result = await startRemoteWebIngress({
1371
1235
  workspaceDir: ws,
1372
1236
  gatewayPort: 7900,
1373
1237
  listenPort: 7845,
1374
- includeWebApp: false,
1375
1238
  });
1376
1239
 
1377
- expect(result).toEqual({
1378
- status: "started",
1379
- listenPort: 7845,
1380
- webDistDir: null,
1381
- version: NGINX_VERSION,
1382
- });
1240
+ if (result.status !== "started") {
1241
+ throw new Error(`expected started, got ${result.status}`);
1242
+ }
1243
+ const { webDistDir } = result;
1383
1244
  expect(edge.killed()).toBe(true);
1384
1245
  expect(spawnMock).toHaveBeenCalledTimes(1);
1385
1246
  expect(realFs.readFileSync(ingressConfPath(ws), "utf-8")).toBe(
@@ -1387,43 +1248,23 @@ describe("startRemoteWebIngress", () => {
1387
1248
  gatewayPort: 7900,
1388
1249
  listenPort: 7845,
1389
1250
  ipv6Loopback: hasIpv6Loopback(),
1251
+ remoteWebIngress: {
1252
+ webDistDir,
1253
+ appDistDir: fakeAppDistDir(),
1254
+ indexHtmlPath: join(ws, "data", "ingress", "assistant-index.html"),
1255
+ appIndexHtmlPath: join(ws, "data", "ingress", "app-index.html"),
1256
+ hubUrl: PRODUCTION_HUB_URL,
1257
+ version: "1.2.3",
1258
+ },
1390
1259
  }),
1391
1260
  );
1392
1261
  expect(readConfig(ws).ingress?.nginx).toEqual({
1393
1262
  listenPort: 7845,
1394
- includeWebApp: false,
1395
1263
  gatewayPort: 7900,
1264
+ remoteWebConfigHash: appConfigHash(),
1396
1265
  });
1397
1266
  });
1398
1267
 
1399
- test("treats recorded state without a mode as an SPA edge", async () => {
1400
- const ws = makeWorkspace();
1401
- mockNginxInstalled();
1402
- mockNginxSpawn();
1403
- mockWebDistPresent();
1404
- const pid = mockRunningEdge(ws, {
1405
- listenPort: 7845,
1406
- gatewayPort: 7830,
1407
- remoteWebConfigHash: spaConfigHash(),
1408
- });
1409
- const edge = mockKillableNginx(pid);
1410
-
1411
- const result = await startRemoteWebIngress({
1412
- workspaceDir: ws,
1413
- gatewayPort: 7830,
1414
- listenPort: 7845,
1415
- });
1416
-
1417
- expect(result).toEqual({
1418
- status: "already-running",
1419
- listenPort: 7845,
1420
- includeWebApp: true,
1421
- gatewayPort: 7830,
1422
- });
1423
- expect(edge.killed()).toBe(false);
1424
- expect(spawnMock).not.toHaveBeenCalled();
1425
- });
1426
-
1427
1268
  test("short-circuits when the running SPA edge already serves the requested config", async () => {
1428
1269
  const ws = makeWorkspace();
1429
1270
  mockNginxInstalled();
@@ -1431,9 +1272,8 @@ describe("startRemoteWebIngress", () => {
1431
1272
  mockWebDistPresent();
1432
1273
  const pid = mockRunningEdge(ws, {
1433
1274
  listenPort: 7845,
1434
- includeWebApp: true,
1435
1275
  gatewayPort: 7830,
1436
- remoteWebConfigHash: spaConfigHash({ assistantName: "My Homelab" }),
1276
+ remoteWebConfigHash: appConfigHash({ assistantName: "My Homelab" }),
1437
1277
  });
1438
1278
  const edge = mockKillableNginx(pid);
1439
1279
 
@@ -1447,7 +1287,6 @@ describe("startRemoteWebIngress", () => {
1447
1287
  expect(result).toEqual({
1448
1288
  status: "already-running",
1449
1289
  listenPort: 7845,
1450
- includeWebApp: true,
1451
1290
  gatewayPort: 7830,
1452
1291
  });
1453
1292
  expect(edge.killed()).toBe(false);
@@ -1462,9 +1301,8 @@ describe("startRemoteWebIngress", () => {
1462
1301
  mockWebDistPresent();
1463
1302
  const pid = mockRunningEdge(ws, {
1464
1303
  listenPort: 7845,
1465
- includeWebApp: true,
1466
1304
  gatewayPort: 7830,
1467
- remoteWebConfigHash: spaConfigHash({
1305
+ remoteWebConfigHash: appConfigHash({
1468
1306
  ...(drift === "indexHtml"
1469
1307
  ? {
1470
1308
  indexHtml:
@@ -1481,7 +1319,7 @@ describe("startRemoteWebIngress", () => {
1481
1319
  expect(result).toMatchObject({ status: "started", listenPort: 7845 });
1482
1320
  expect(edge.killed()).toBe(true);
1483
1321
  expect(readConfig(ws).ingress?.nginx?.remoteWebConfigHash).toBe(
1484
- spaConfigHash(),
1322
+ appConfigHash(),
1485
1323
  );
1486
1324
  expect(
1487
1325
  realFs.readFileSync(
@@ -1499,9 +1337,8 @@ describe("startRemoteWebIngress", () => {
1499
1337
  mockWebDistPresent();
1500
1338
  const pid = mockRunningEdge(ws, {
1501
1339
  listenPort: 7845,
1502
- includeWebApp: true,
1503
1340
  gatewayPort: 7830,
1504
- remoteWebConfigHash: spaConfigHash({ assistantName: "Old Name" }),
1341
+ remoteWebConfigHash: appConfigHash({ assistantName: "Old Name" }),
1505
1342
  });
1506
1343
  const edge = mockKillableNginx(pid);
1507
1344
 
@@ -1522,9 +1359,8 @@ describe("startRemoteWebIngress", () => {
1522
1359
  expect(indexHtml).toContain('"assistantName":"New Name"');
1523
1360
  expect(readConfig(ws).ingress?.nginx).toEqual({
1524
1361
  listenPort: 7845,
1525
- includeWebApp: true,
1526
1362
  gatewayPort: 7830,
1527
- remoteWebConfigHash: spaConfigHash({ assistantName: "New Name" }),
1363
+ remoteWebConfigHash: appConfigHash({ assistantName: "New Name" }),
1528
1364
  });
1529
1365
  });
1530
1366
 
@@ -1549,7 +1385,6 @@ describe("startRemoteWebIngress", () => {
1549
1385
  .digest("hex");
1550
1386
  const pid = mockRunningEdge(ws, {
1551
1387
  listenPort: 7845,
1552
- includeWebApp: true,
1553
1388
  gatewayPort: 7830,
1554
1389
  remoteWebConfigHash: priorTemplateHash,
1555
1390
  });
@@ -1567,9 +1402,8 @@ describe("startRemoteWebIngress", () => {
1567
1402
  expect(conf).toContain("location = /readyz {");
1568
1403
  expect(readConfig(ws).ingress?.nginx).toEqual({
1569
1404
  listenPort: 7845,
1570
- includeWebApp: true,
1571
1405
  gatewayPort: 7830,
1572
- remoteWebConfigHash: spaConfigHash(),
1406
+ remoteWebConfigHash: appConfigHash(),
1573
1407
  });
1574
1408
  });
1575
1409
 
@@ -1580,7 +1414,6 @@ describe("startRemoteWebIngress", () => {
1580
1414
  mockWebDistPresent();
1581
1415
  const pid = mockRunningEdge(ws, {
1582
1416
  listenPort: 7845,
1583
- includeWebApp: true,
1584
1417
  gatewayPort: 7830,
1585
1418
  });
1586
1419
  const edge = mockKillableNginx(pid);
@@ -1595,9 +1428,8 @@ describe("startRemoteWebIngress", () => {
1595
1428
  expect(edge.killed()).toBe(true);
1596
1429
  expect(readConfig(ws).ingress?.nginx).toEqual({
1597
1430
  listenPort: 7845,
1598
- includeWebApp: true,
1599
1431
  gatewayPort: 7830,
1600
- remoteWebConfigHash: spaConfigHash(),
1432
+ remoteWebConfigHash: appConfigHash(),
1601
1433
  });
1602
1434
  });
1603
1435
 
@@ -1608,9 +1440,8 @@ describe("startRemoteWebIngress", () => {
1608
1440
  mockWebDistPresent();
1609
1441
  const pid = mockRunningEdge(ws, {
1610
1442
  listenPort: 7845,
1611
- includeWebApp: true,
1612
1443
  gatewayPort: 7830,
1613
- remoteWebConfigHash: spaConfigHash({ assistantName: "Old Name" }),
1444
+ remoteWebConfigHash: appConfigHash({ assistantName: "Old Name" }),
1614
1445
  });
1615
1446
  mockUnkillableNginx(pid);
1616
1447
 
@@ -1624,57 +1455,22 @@ describe("startRemoteWebIngress", () => {
1624
1455
  expect(result).toEqual({
1625
1456
  status: "already-running",
1626
1457
  listenPort: 7845,
1627
- includeWebApp: true,
1628
1458
  gatewayPort: 7830,
1629
1459
  staleRemoteWebConfig: true,
1630
1460
  });
1631
1461
  expect(spawnMock).not.toHaveBeenCalled();
1632
1462
  });
1633
1463
 
1634
- test("restarts an SPA edge when webhooks-only mode is requested", async () => {
1464
+ test("starts a fresh edge when the old one exits during the stop", async () => {
1635
1465
  const ws = makeWorkspace();
1636
1466
  mockNginxInstalled();
1637
1467
  mockNginxSpawn();
1638
- mockWebDistMissing();
1639
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: true });
1640
- const edge = mockKillableNginx(pid);
1641
-
1642
- const result = await startRemoteWebIngress({
1643
- workspaceDir: ws,
1644
- gatewayPort: 7830,
1645
- listenPort: 7845,
1646
- includeWebApp: false,
1647
- });
1648
-
1649
- expect(result).toEqual({
1650
- status: "started",
1651
- listenPort: 7845,
1652
- webDistDir: null,
1653
- version: NGINX_VERSION,
1654
- });
1655
- expect(edge.killed()).toBe(true);
1656
- expect(spawnMock).toHaveBeenCalledTimes(1);
1657
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
1658
- expect(conf).toBe(
1659
- buildIngressNginxConfig({
1660
- gatewayPort: 7830,
1661
- listenPort: 7845,
1662
- ipv6Loopback: hasIpv6Loopback(),
1663
- }),
1664
- );
1665
- expect(readConfig(ws).ingress?.nginx).toEqual({
1468
+ mockWebDistPresent();
1469
+ const pid = mockRunningEdge(ws, {
1666
1470
  listenPort: 7845,
1667
- includeWebApp: false,
1668
1471
  gatewayPort: 7830,
1472
+ remoteWebConfigHash: "outdated-hash",
1669
1473
  });
1670
- });
1671
-
1672
- test("starts the requested mode when the old edge exits during the stop", async () => {
1673
- const ws = makeWorkspace();
1674
- mockNginxInstalled();
1675
- mockNginxSpawn();
1676
- mockWebDistMissing();
1677
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: true });
1678
1474
  // Alive for the initial running check, dead by the time the stop helper
1679
1475
  // probes it: the race where the old edge exits on its own mid-switch.
1680
1476
  let liveChecks = 0;
@@ -1688,15 +1484,12 @@ describe("startRemoteWebIngress", () => {
1688
1484
  workspaceDir: ws,
1689
1485
  gatewayPort: 7830,
1690
1486
  listenPort: 7845,
1691
- includeWebApp: false,
1692
1487
  });
1693
1488
 
1694
- expect(result).toEqual({
1695
- status: "started",
1696
- listenPort: 7845,
1697
- webDistDir: null,
1698
- version: NGINX_VERSION,
1699
- });
1489
+ if (result.status !== "started") {
1490
+ throw new Error(`expected started, got ${result.status}`);
1491
+ }
1492
+ const { webDistDir } = result;
1700
1493
  expect(spawnMock).toHaveBeenCalledTimes(1);
1701
1494
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
1702
1495
  expect(conf).toBe(
@@ -1704,65 +1497,20 @@ describe("startRemoteWebIngress", () => {
1704
1497
  gatewayPort: 7830,
1705
1498
  listenPort: 7845,
1706
1499
  ipv6Loopback: hasIpv6Loopback(),
1500
+ remoteWebIngress: {
1501
+ webDistDir,
1502
+ appDistDir: fakeAppDistDir(),
1503
+ indexHtmlPath: join(ws, "data", "ingress", "assistant-index.html"),
1504
+ appIndexHtmlPath: join(ws, "data", "ingress", "app-index.html"),
1505
+ hubUrl: PRODUCTION_HUB_URL,
1506
+ version: "1.2.3",
1507
+ },
1707
1508
  }),
1708
1509
  );
1709
1510
  expect(readConfig(ws).ingress?.nginx).toEqual({
1710
1511
  listenPort: 7845,
1711
- includeWebApp: false,
1712
1512
  gatewayPort: 7830,
1713
- });
1714
- });
1715
-
1716
- test("restarts a webhooks-only edge when SPA mode is requested", async () => {
1717
- const ws = makeWorkspace();
1718
- mockNginxInstalled();
1719
- mockNginxSpawn();
1720
- mockWebDistPresent();
1721
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: false });
1722
- const edge = mockKillableNginx(pid);
1723
-
1724
- const result = await startRemoteWebIngress({
1725
- workspaceDir: ws,
1726
- gatewayPort: 7830,
1727
- listenPort: 7845,
1728
- });
1729
-
1730
- if (result.status !== "started") {
1731
- throw new Error(`expected started, got ${result.status}`);
1732
- }
1733
- expect(result.webDistDir).not.toBeNull();
1734
- expect(edge.killed()).toBe(true);
1735
- expect(spawnMock).toHaveBeenCalledTimes(1);
1736
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
1737
- expect(conf).toContain("location ^~ /assistant/ {");
1738
- expect(readConfig(ws).ingress?.nginx).toEqual({
1739
- listenPort: 7845,
1740
- includeWebApp: true,
1741
- gatewayPort: 7830,
1742
- remoteWebConfigHash: spaConfigHash(),
1743
- });
1744
- });
1745
-
1746
- test("keeps a webhooks-only edge running when SPA mode is requested without a web dist", async () => {
1747
- const ws = makeWorkspace();
1748
- mockNginxInstalled();
1749
- mockNginxSpawn();
1750
- mockWebDistMissing();
1751
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: false });
1752
- const edge = mockKillableNginx(pid);
1753
-
1754
- const result = await startRemoteWebIngress({
1755
- workspaceDir: ws,
1756
- gatewayPort: 7830,
1757
- listenPort: 7845,
1758
- });
1759
-
1760
- expect(result).toEqual({ status: "web-dist-missing" });
1761
- expect(edge.killed()).toBe(false);
1762
- expect(spawnMock).not.toHaveBeenCalled();
1763
- expect(readConfig(ws).ingress?.nginx).toEqual({
1764
- listenPort: 7845,
1765
- includeWebApp: false,
1513
+ remoteWebConfigHash: appConfigHash(),
1766
1514
  });
1767
1515
  });
1768
1516
 
@@ -1773,14 +1521,13 @@ describe("startRemoteWebIngress", () => {
1773
1521
  const ws = makeWorkspace();
1774
1522
  mockNginxInstalled();
1775
1523
  mockNginxSpawnExitsOnStartup();
1776
- mockWebDistMissing();
1524
+ mockWebDistPresent();
1777
1525
  waitForDaemonReadyMock.mockImplementation(async () => true);
1778
1526
 
1779
1527
  const result = await startRemoteWebIngress({
1780
1528
  workspaceDir: ws,
1781
1529
  gatewayPort: 7830,
1782
1530
  listenPort: 7845,
1783
- includeWebApp: false,
1784
1531
  });
1785
1532
 
1786
1533
  expect(result).toEqual({
@@ -1800,14 +1547,13 @@ describe("startRemoteWebIngress", () => {
1800
1547
  const ws = makeWorkspace();
1801
1548
  mockNginxInstalled();
1802
1549
  mockNginxSpawnExitsAfterProbe();
1803
- mockWebDistMissing();
1550
+ mockWebDistPresent();
1804
1551
  waitForDaemonReadyMock.mockImplementation(async () => true);
1805
1552
 
1806
1553
  const result = await startRemoteWebIngress({
1807
1554
  workspaceDir: ws,
1808
1555
  gatewayPort: 7830,
1809
1556
  listenPort: 7845,
1810
- includeWebApp: false,
1811
1557
  });
1812
1558
 
1813
1559
  expect(result).toEqual({
@@ -1824,19 +1570,18 @@ describe("startRemoteWebIngress", () => {
1824
1570
  const ws = makeWorkspace();
1825
1571
  mockNginxInstalled();
1826
1572
  mockNginxSpawn();
1827
- mockWebDistMissing();
1573
+ mockWebDistPresent();
1828
1574
 
1829
1575
  const result = await startRemoteWebIngress({
1830
1576
  workspaceDir: ws,
1831
1577
  gatewayPort: 7830,
1832
1578
  listenPort: 7845,
1833
- includeWebApp: false,
1834
1579
  });
1835
1580
 
1836
1581
  expect(result).toEqual({
1837
1582
  status: "started",
1838
1583
  listenPort: 7845,
1839
- webDistDir: null,
1584
+ webDistDir: expect.any(String),
1840
1585
  version: NGINX_VERSION,
1841
1586
  });
1842
1587
  expect(
@@ -1856,14 +1601,13 @@ describe("startRemoteWebIngress", () => {
1856
1601
  const ws = makeWorkspace();
1857
1602
  mockNginxInstalled();
1858
1603
  mockNginxSpawnExitsOnStartup();
1859
- mockWebDistMissing();
1604
+ mockWebDistPresent();
1860
1605
  waitForDaemonReadyMock.mockImplementation(async () => false);
1861
1606
 
1862
1607
  const result = await startRemoteWebIngress({
1863
1608
  workspaceDir: ws,
1864
1609
  gatewayPort: 7830,
1865
1610
  listenPort: 7845,
1866
- includeWebApp: false,
1867
1611
  });
1868
1612
 
1869
1613
  expect(result.status).toBe("port-conflict");
@@ -1872,7 +1616,7 @@ describe("startRemoteWebIngress", () => {
1872
1616
  test("a child still retrying its bind at the settle deadline is killed before rollback", async () => {
1873
1617
  const ws = makeWorkspace();
1874
1618
  mockNginxInstalled();
1875
- mockWebDistMissing();
1619
+ mockWebDistPresent();
1876
1620
  const kills: string[] = [];
1877
1621
  // Alive for the whole settle window (nginx retrying its bind), never
1878
1622
  // writes a pid file; an orphan left running could win the bind later.
@@ -1892,7 +1636,6 @@ describe("startRemoteWebIngress", () => {
1892
1636
  workspaceDir: ws,
1893
1637
  gatewayPort: 7830,
1894
1638
  listenPort: 7845,
1895
- includeWebApp: false,
1896
1639
  });
1897
1640
 
1898
1641
  expect(result.status).toBe("port-conflict");
@@ -1951,13 +1694,12 @@ describe("ensureTunnelEdge", () => {
1951
1694
  }),
1952
1695
  );
1953
1696
 
1954
- const result = await ensureTunnelEdge({
1697
+ await ensureTunnelEdge({
1955
1698
  assistantId: ASSISTANT_ID,
1956
1699
  workspaceDir: ws,
1957
1700
  gatewayPort: 7830,
1958
1701
  });
1959
1702
 
1960
- expect(result.includesWebApp).toBe(true);
1961
1703
  const indexHtml = realFs.readFileSync(
1962
1704
  join(ws, "data", "ingress", "assistant-index.html"),
1963
1705
  "utf-8",
@@ -1973,13 +1715,12 @@ describe("ensureTunnelEdge", () => {
1973
1715
  mockNginxSpawn();
1974
1716
  mockWebDistPresent();
1975
1717
 
1976
- const result = await ensureTunnelEdge({
1718
+ await ensureTunnelEdge({
1977
1719
  assistantId: ASSISTANT_ID,
1978
1720
  workspaceDir: ws,
1979
1721
  gatewayPort: 7830,
1980
1722
  });
1981
1723
 
1982
- expect(result.includesWebApp).toBe(true);
1983
1724
  const indexHtml = realFs.readFileSync(
1984
1725
  join(ws, "data", "ingress", "assistant-index.html"),
1985
1726
  "utf-8",
@@ -1989,16 +1730,15 @@ describe("ensureTunnelEdge", () => {
1989
1730
  expect(indexHtml).toContain(`"hubUrl":"${PRODUCTION_HUB_URL}"`);
1990
1731
  });
1991
1732
 
1992
- test("reuses a running edge that already serves the SPA mode", async () => {
1733
+ test("reuses a running edge that already serves the requested config", async () => {
1993
1734
  const ws = makeWorkspace();
1994
1735
  mockNginxInstalled();
1995
1736
  mockNginxSpawn();
1996
1737
  mockWebDistPresent();
1997
1738
  const pid = mockRunningEdge(ws, {
1998
1739
  listenPort: 7845,
1999
- includeWebApp: true,
2000
1740
  gatewayPort: 7830,
2001
- remoteWebConfigHash: spaConfigHash({ assistantId: ASSISTANT_ID }),
1741
+ remoteWebConfigHash: appConfigHash({ assistantId: ASSISTANT_ID }),
2002
1742
  });
2003
1743
  const edge = mockKillableNginx(pid);
2004
1744
 
@@ -2011,8 +1751,6 @@ describe("ensureTunnelEdge", () => {
2011
1751
  expect(result).toEqual({
2012
1752
  port: 7845,
2013
1753
  started: false,
2014
- includesWebApp: true,
2015
- shellMode: "web",
2016
1754
  });
2017
1755
  expect(edge.killed()).toBe(false);
2018
1756
  expect(spawnMock).not.toHaveBeenCalled();
@@ -2074,9 +1812,8 @@ describe("ensureTunnelEdge", () => {
2074
1812
  mockWebDistPresent();
2075
1813
  const pid = mockRunningEdge(ws, {
2076
1814
  listenPort: REQUESTED_PORT,
2077
- includeWebApp: true,
2078
1815
  gatewayPort: 7830,
2079
- remoteWebConfigHash: spaConfigHash({
1816
+ remoteWebConfigHash: appConfigHash({
2080
1817
  assistantName: "Stale Name",
2081
1818
  assistantId: ASSISTANT_ID,
2082
1819
  }),
@@ -2096,27 +1833,6 @@ describe("ensureTunnelEdge", () => {
2096
1833
  expect(spawnMock).not.toHaveBeenCalled();
2097
1834
  });
2098
1835
 
2099
- test("a mode-drifted edge that survives the restart attempt throws", async () => {
2100
- const ws = makeWorkspace();
2101
- mockNginxInstalled();
2102
- mockNginxSpawn();
2103
- mockWebDistPresent();
2104
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: false });
2105
- mockUnkillableNginx(pid);
2106
-
2107
- const promise = ensureTunnelEdge({
2108
- assistantId: ASSISTANT_ID,
2109
- workspaceDir: ws,
2110
- gatewayPort: 7830,
2111
- });
2112
-
2113
- await expect(promise).rejects.toThrow(
2114
- "still running in webhooks-only mode and could not be restarted in web app mode",
2115
- );
2116
- await expect(promise).rejects.toThrow("even with SIGKILL");
2117
- expect(spawnMock).not.toHaveBeenCalled();
2118
- });
2119
-
2120
1836
  test("a port-drifted edge that survives the restart attempt throws", async () => {
2121
1837
  const ws = makeWorkspace();
2122
1838
  mockNginxInstalled();
@@ -2124,9 +1840,8 @@ describe("ensureTunnelEdge", () => {
2124
1840
  mockWebDistPresent();
2125
1841
  const pid = mockRunningEdge(ws, {
2126
1842
  listenPort: 7845,
2127
- includeWebApp: true,
2128
1843
  gatewayPort: 7900,
2129
- remoteWebConfigHash: spaConfigHash({ assistantId: ASSISTANT_ID }),
1844
+ remoteWebConfigHash: appConfigHash({ assistantId: ASSISTANT_ID }),
2130
1845
  });
2131
1846
  mockUnkillableNginx(pid);
2132
1847
 
@@ -2150,9 +1865,8 @@ describe("ensureTunnelEdge", () => {
2150
1865
  mockWebDistPresent();
2151
1866
  const pid = mockRunningEdge(ws, {
2152
1867
  listenPort: 7845,
2153
- includeWebApp: true,
2154
1868
  gatewayPort: 7900,
2155
- remoteWebConfigHash: spaConfigHash({ assistantId: ASSISTANT_ID }),
1869
+ remoteWebConfigHash: appConfigHash({ assistantId: ASSISTANT_ID }),
2156
1870
  });
2157
1871
  const edge = mockKillableNginx(pid);
2158
1872
 
@@ -2165,33 +1879,6 @@ describe("ensureTunnelEdge", () => {
2165
1879
  expect(result).toEqual({
2166
1880
  port: REQUESTED_PORT,
2167
1881
  started: true,
2168
- includesWebApp: true,
2169
- shellMode: "web",
2170
- });
2171
- expect(edge.killed()).toBe(true);
2172
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
2173
- expect(conf).toContain("location ^~ /assistant/ {");
2174
- });
2175
-
2176
- test("restarts a webhooks-only edge into the SPA mode", async () => {
2177
- const ws = makeWorkspace();
2178
- mockNginxInstalled();
2179
- mockNginxSpawn();
2180
- mockWebDistPresent();
2181
- const pid = mockRunningEdge(ws, { listenPort: 7845, includeWebApp: false });
2182
- const edge = mockKillableNginx(pid);
2183
-
2184
- const result = await ensureTunnelEdge({
2185
- assistantId: ASSISTANT_ID,
2186
- workspaceDir: ws,
2187
- gatewayPort: 7830,
2188
- });
2189
-
2190
- expect(result).toEqual({
2191
- port: REQUESTED_PORT,
2192
- started: true,
2193
- includesWebApp: true,
2194
- shellMode: "web",
2195
1882
  });
2196
1883
  expect(edge.killed()).toBe(true);
2197
1884
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
@@ -2213,17 +1900,14 @@ describe("ensureTunnelEdge", () => {
2213
1900
  expect(result).toEqual({
2214
1901
  port: REQUESTED_PORT,
2215
1902
  started: true,
2216
- includesWebApp: true,
2217
- shellMode: "web",
2218
1903
  });
2219
1904
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
2220
1905
  expect(conf).toContain("location ^~ /assistant/ {");
2221
1906
  expect(conf).toContain("location ^~ /webhooks/ {");
2222
1907
  expect(readConfig(ws).ingress?.nginx).toEqual({
2223
1908
  listenPort: REQUESTED_PORT,
2224
- includeWebApp: true,
2225
1909
  gatewayPort: 7830,
2226
- remoteWebConfigHash: spaConfigHash({ assistantId: ASSISTANT_ID }),
1910
+ remoteWebConfigHash: appConfigHash({ assistantId: ASSISTANT_ID }),
2227
1911
  });
2228
1912
  });
2229
1913
 
@@ -2269,8 +1953,6 @@ describe("ensureTunnelEdge", () => {
2269
1953
  expect(result).toEqual({
2270
1954
  port: REQUESTED_PORT,
2271
1955
  started: true,
2272
- includesWebApp: true,
2273
- shellMode: "web",
2274
1956
  });
2275
1957
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
2276
1958
  expect(conf).toContain("location ^~ /assistant/ {");
@@ -2429,6 +2111,7 @@ describe("assistant metadata API", () => {
2429
2111
  listenPort: 7840,
2430
2112
  remoteWebIngress: {
2431
2113
  webDistDir: "/tmp/web",
2114
+ appDistDir: "/tmp/app-dist",
2432
2115
  version: "1.2.3",
2433
2116
  assistantId: id,
2434
2117
  assistantName: "My assistant",
@@ -2458,7 +2141,7 @@ describe("assistant metadata API", () => {
2458
2141
  name: "My assistant",
2459
2142
  status: "active",
2460
2143
  version: "1.2.3",
2461
- url: "assistant/",
2144
+ url: "web/assistant/",
2462
2145
  });
2463
2146
  expect(conf).not.toContain('location = "/v1/assistants/other/"');
2464
2147
  });
@@ -2486,7 +2169,7 @@ describe("assistant metadata API", () => {
2486
2169
  const conf = buildIngressNginxConfig({
2487
2170
  gatewayPort: 7830,
2488
2171
  listenPort: 7840,
2489
- remoteWebIngress: { webDistDir: "/tmp/web" },
2172
+ remoteWebIngress: { webDistDir: "/tmp/web", appDistDir: "/tmp/app-dist" },
2490
2173
  });
2491
2174
  expect(body(conf, "/v1/assistants/")).toEqual({ results: [], next: null });
2492
2175
  });
@@ -2494,7 +2177,11 @@ describe("assistant metadata API", () => {
2494
2177
  const conf = buildIngressNginxConfig({
2495
2178
  gatewayPort: 7830,
2496
2179
  listenPort: 7840,
2497
- remoteWebIngress: { webDistDir: "/tmp/web", assistantId: "assistant-1" },
2180
+ remoteWebIngress: {
2181
+ webDistDir: "/tmp/web",
2182
+ appDistDir: "/tmp/app-dist",
2183
+ assistantId: "assistant-1",
2184
+ },
2498
2185
  });
2499
2186
  expect(body(conf, "/v1/assistants/")).toEqual({
2500
2187
  results: [{ id: "assistant-1" }],
@@ -2516,6 +2203,7 @@ describe("assistant metadata API", () => {
2516
2203
  listenPort: 7840,
2517
2204
  remoteWebIngress: {
2518
2205
  webDistDir: "/tmp/web",
2206
+ appDistDir: "/tmp/app-dist",
2519
2207
  config: { appAllowedOrigins: ["https://parent.example/path"] },
2520
2208
  },
2521
2209
  }),
@@ -2523,40 +2211,14 @@ describe("assistant metadata API", () => {
2523
2211
  });
2524
2212
  });
2525
2213
 
2526
- const APP_INDEX_SUFFIX = join("standalone", "index.html");
2527
- const FAKE_APP_INDEX_HTML =
2528
- "<!doctype html><html><head><title>app</title></head><body>app-shell</body></html>";
2529
-
2530
- /**
2531
- * Force findAppDistDir() to resolve a standalone bundle. The web-dist mock
2532
- * below always pairs with it: app mode serves both bundles.
2533
- */
2534
- function mockAppDistPresent(): void {
2535
- const previousExists = existsSyncMock.getMockImplementation();
2536
- existsSyncMock.mockImplementation((path) =>
2537
- String(path).endsWith(APP_INDEX_SUFFIX)
2538
- ? true
2539
- : previousExists
2540
- ? previousExists(path)
2541
- : realFs.existsSync(path),
2542
- );
2543
- const previousRead = readFileSyncMock.getMockImplementation();
2544
- readFileSyncMock.mockImplementation(((path, options) =>
2545
- String(path).endsWith(APP_INDEX_SUFFIX)
2546
- ? FAKE_APP_INDEX_HTML
2547
- : previousRead
2548
- ? previousRead(path as never, options as never)
2549
- : realFs.readFileSync(
2550
- path as never,
2551
- options as never,
2552
- )) as typeof readFileSync);
2553
- }
2554
-
2555
- /** The fingerprint the edge must record for an app-mode SPA config. */
2214
+ /** The fingerprint the edge must record for its served SPA config. */
2556
2215
  function appConfigHash(
2557
2216
  opts: {
2558
2217
  assistantName?: string;
2559
2218
  assistantId?: string;
2219
+ cloudUrl?: string;
2220
+ indexHtml?: string;
2221
+ webDistDir?: string;
2560
2222
  } = {},
2561
2223
  ): string {
2562
2224
  return createHash("sha256")
@@ -2565,24 +2227,23 @@ function appConfigHash(
2565
2227
  template: EDGE_TEMPLATE_VERSION,
2566
2228
  config: {
2567
2229
  remote: "custom",
2568
- apiBaseUrl: "/v1",
2569
- ...(opts.assistantName ? { assistantName: opts.assistantName } : {}),
2570
- ...(opts.assistantId ? { assistantId: opts.assistantId } : {}),
2230
+ assistantName: opts.assistantName,
2231
+ assistantId: opts.assistantId,
2571
2232
  hubUrl: PRODUCTION_HUB_URL,
2233
+ cloudUrl: opts.cloudUrl,
2572
2234
  version: "1.2.3",
2573
2235
  },
2574
- webDistDir: findWebDistDir(),
2236
+ webDistDir: opts.webDistDir ?? findWebDistDir(),
2575
2237
  version: "1.2.3",
2576
- shellMode: "app",
2577
2238
  appDistDir: findAppDistDir(),
2578
2239
  appIndexHtml: FAKE_APP_INDEX_HTML,
2579
- indexHtml: FAKE_INDEX_HTML,
2240
+ indexHtml: opts.indexHtml ?? FAKE_INDEX_HTML,
2580
2241
  }),
2581
2242
  )
2582
2243
  .digest("hex");
2583
2244
  }
2584
2245
 
2585
- describe("app shell mode", () => {
2246
+ describe("the app shell edge", () => {
2586
2247
  pinProductionEnvironment();
2587
2248
 
2588
2249
  function appConf() {
@@ -2681,19 +2342,16 @@ describe("app shell mode", () => {
2681
2342
  );
2682
2343
  });
2683
2344
 
2684
- test("app mode starts, injects both documents, and records the app fingerprint", async () => {
2345
+ test("starts, injects both documents, and records the edge fingerprint", async () => {
2685
2346
  const ws = makeWorkspace();
2686
2347
  mockNginxInstalled();
2687
2348
  mockNginxSpawn();
2688
2349
  mockWebDistPresent();
2689
- mockAppDistPresent();
2690
- fetchCurrentVersionMock.mockResolvedValue("1.2.3");
2691
2350
 
2692
2351
  const result = await startRemoteWebIngress({
2693
2352
  workspaceDir: ws,
2694
2353
  gatewayPort: 7830,
2695
2354
  listenPort: 7845,
2696
- shellMode: "app",
2697
2355
  assistantId: "assistant-1",
2698
2356
  });
2699
2357
 
@@ -2705,85 +2363,109 @@ describe("app shell mode", () => {
2705
2363
  );
2706
2364
  expect(appIndex).toContain("__CADET_CONFIG__");
2707
2365
  expect(appIndex).toContain(`"assistantId":"assistant-1"`);
2708
- expect(appIndex).toContain(`"version":"1.2.3"`);
2709
2366
  const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
2710
2367
  expect(conf).toContain("location = /__cadet-app-index.html {");
2711
2368
  expect(conf).toContain('\\"url\\":\\"web/assistant/\\"');
2369
+ // The served shell document must be the edge's INJECTED copy (which
2370
+ // carries the served config), never the raw dist index — that one only
2371
+ // carries the build-time vite stamp.
2372
+ expect(conf).toContain(`alias "${join(ingressDir, "app-index.html")}"`);
2712
2373
  expect(readConfig(ws).ingress?.nginx).toMatchObject({
2713
2374
  listenPort: 7845,
2714
- includeWebApp: true,
2715
2375
  gatewayPort: 7830,
2716
2376
  remoteWebConfigHash: appConfigHash({ assistantId: "assistant-1" }),
2717
2377
  });
2718
2378
  });
2719
2379
 
2720
- test("fails fast when the app bundle is not built", async () => {
2380
+ test("stamps the saved tunnel URL as the served config's cloudUrl", async () => {
2721
2381
  const ws = makeWorkspace();
2722
2382
  mockNginxInstalled();
2723
2383
  mockNginxSpawn();
2724
2384
  mockWebDistPresent();
2725
- // A real build in the checkout would satisfy the lookup; the failure
2726
- // path needs the lookup to resolve nothing, regardless of checkout state.
2727
- // Web dist stays present so the app-dist check is the one that fires.
2728
- const previousExists = existsSyncMock.getMockImplementation();
2729
- existsSyncMock.mockImplementation((path) => {
2730
- const p = String(path);
2731
- if (p.endsWith(APP_INDEX_SUFFIX)) return false;
2732
- // The app auto-build must not run from the real checkout either.
2733
- if (p.includes("clients/app/package.json")) return false;
2734
- return previousExists ? previousExists(path) : realFs.existsSync(path);
2735
- });
2385
+ writeWorkspaceIngressUrl(ws, "https://camping.ngrok-free.dev");
2736
2386
 
2737
2387
  const result = await startRemoteWebIngress({
2738
2388
  workspaceDir: ws,
2739
2389
  gatewayPort: 7830,
2740
2390
  listenPort: 7845,
2741
- shellMode: "app",
2391
+ assistantId: "assistant-1",
2742
2392
  });
2743
2393
 
2744
- expect(result).toEqual({ status: "app-dist-missing" });
2745
- expect(realFs.existsSync(ingressConfPath(ws))).toBe(false);
2394
+ expect(result.status).toBe("started");
2395
+ const appIndex = realFs.readFileSync(
2396
+ join(ws, "data", "ingress", "app-index.html"),
2397
+ "utf-8",
2398
+ );
2399
+ // Tunnel clients can only reach the origin they came in on, so the
2400
+ // account/auth surfaces' backend base is the tunnel URL, not the
2401
+ // loopback gateway seed.
2402
+ expect(appIndex).toContain(`"cloudUrl":"https://camping.ngrok-free.dev"`);
2403
+ // The URL rides the fingerprint: a changed tunnel URL rotates the edge.
2404
+ expect(readConfig(ws).ingress?.nginx).toMatchObject({
2405
+ remoteWebConfigHash: appConfigHash({
2406
+ assistantId: "assistant-1",
2407
+ cloudUrl: "https://camping.ngrok-free.dev",
2408
+ }),
2409
+ });
2746
2410
  });
2747
2411
 
2748
- test("restarting an edge between shell modes rotates onto the requested mode", async () => {
2412
+ test("omits cloudUrl when no tunnel URL is on record", async () => {
2749
2413
  const ws = makeWorkspace();
2750
2414
  mockNginxInstalled();
2751
2415
  mockNginxSpawn();
2752
2416
  mockWebDistPresent();
2753
- mockAppDistPresent();
2754
- // A running web-mode edge whose fingerprint predates app mode.
2755
- mockRunningEdge(ws, {
2756
- listenPort: 7845,
2757
- includeWebApp: true,
2758
- gatewayPort: 7830,
2759
- remoteWebConfigHash: spaConfigHash({ assistantId: "assistant-1" }),
2760
- });
2761
- const edge = mockKillableNginx(123_460);
2762
2417
 
2763
2418
  const result = await startRemoteWebIngress({
2764
2419
  workspaceDir: ws,
2765
2420
  gatewayPort: 7830,
2766
2421
  listenPort: 7845,
2767
- shellMode: "app",
2768
2422
  assistantId: "assistant-1",
2769
2423
  });
2770
2424
 
2771
2425
  expect(result.status).toBe("started");
2772
- expect(edge.killed()).toBe(true);
2773
- expect(readConfig(ws).ingress?.nginx).toMatchObject({
2774
- remoteWebConfigHash: appConfigHash({ assistantId: "assistant-1" }),
2426
+ const appIndex = realFs.readFileSync(
2427
+ join(ws, "data", "ingress", "app-index.html"),
2428
+ "utf-8",
2429
+ );
2430
+ // Omitted — the shell's same-origin fallbacks own it until a tunnel
2431
+ // saves a URL.
2432
+ expect(appIndex).not.toContain("cloudUrl");
2433
+ });
2434
+
2435
+ test("fails fast when the app bundle is not built", async () => {
2436
+ const ws = makeWorkspace();
2437
+ mockNginxInstalled();
2438
+ mockNginxSpawn();
2439
+ mockWebDistPresent();
2440
+ // A real build in the checkout would satisfy the lookup; the failure
2441
+ // path needs the lookup to resolve nothing, regardless of checkout state.
2442
+ // Web dist stays present so the app-dist check is the one that fires.
2443
+ const previousExists = existsSyncMock.getMockImplementation();
2444
+ existsSyncMock.mockImplementation((path) => {
2445
+ const p = String(path);
2446
+ if (p.endsWith(APP_INDEX_SUFFIX)) return false;
2447
+ // The app auto-build must not run from the real checkout either.
2448
+ if (p.includes("clients/app/package.json")) return false;
2449
+ return previousExists ? previousExists(path) : realFs.existsSync(path);
2450
+ });
2451
+
2452
+ const result = await startRemoteWebIngress({
2453
+ workspaceDir: ws,
2454
+ gatewayPort: 7830,
2455
+ listenPort: 7845,
2775
2456
  });
2457
+
2458
+ expect(result).toEqual({ status: "app-dist-missing" });
2459
+ expect(realFs.existsSync(ingressConfPath(ws))).toBe(false);
2776
2460
  });
2777
2461
 
2778
- test("reuses an already-running app-mode edge", async () => {
2462
+ test("reuses an already-running edge", async () => {
2779
2463
  const ws = makeWorkspace();
2780
2464
  mockNginxInstalled();
2781
2465
  mockNginxSpawn();
2782
2466
  mockWebDistPresent();
2783
- mockAppDistPresent();
2784
2467
  mockRunningEdge(ws, {
2785
2468
  listenPort: 7845,
2786
- includeWebApp: true,
2787
2469
  gatewayPort: 7830,
2788
2470
  remoteWebConfigHash: appConfigHash({ assistantId: "assistant-1" }),
2789
2471
  });
@@ -2793,7 +2475,6 @@ describe("app shell mode", () => {
2793
2475
  workspaceDir: ws,
2794
2476
  gatewayPort: 7830,
2795
2477
  listenPort: 7845,
2796
- shellMode: "app",
2797
2478
  assistantId: "assistant-1",
2798
2479
  });
2799
2480
 
@@ -2804,67 +2485,4 @@ describe("app shell mode", () => {
2804
2485
  expect(edge.killed()).toBe(false);
2805
2486
  expect(spawnMock).not.toHaveBeenCalled();
2806
2487
  });
2807
-
2808
- test("ensureTunnelEdge reads the persisted shell mode from the lockfile", async () => {
2809
- const ws = makeWorkspace();
2810
- mockNginxInstalled();
2811
- mockNginxSpawn();
2812
- mockWebDistPresent();
2813
- mockAppDistPresent();
2814
- const originalLockfileDir = process.env.CADET_LOCKFILE_DIR;
2815
- const lockfileDir = join(ws, "lockfile");
2816
- mkdirSync(lockfileDir, { recursive: true });
2817
- process.env.CADET_LOCKFILE_DIR = lockfileDir;
2818
- try {
2819
- saveShellMode("app");
2820
-
2821
- const result = await ensureTunnelEdge({
2822
- assistantId: "assistant-1",
2823
- workspaceDir: ws,
2824
- gatewayPort: 7830,
2825
- });
2826
-
2827
- expect(result.shellMode).toBe("app");
2828
- } finally {
2829
- if (originalLockfileDir === undefined) {
2830
- delete process.env.CADET_LOCKFILE_DIR;
2831
- } else {
2832
- process.env.CADET_LOCKFILE_DIR = originalLockfileDir;
2833
- }
2834
- }
2835
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
2836
- expect(conf).toContain("location = /__cadet-app-index.html {");
2837
- expect(conf).toContain('\\"url\\":\\"web/assistant/\\"');
2838
- });
2839
-
2840
- test("ensureTunnelEdge defaults to the web shell", async () => {
2841
- const ws = makeWorkspace();
2842
- mockNginxInstalled();
2843
- mockNginxSpawn();
2844
- mockWebDistPresent();
2845
- // Hermetic lockfile dir: no edgeShell key means the web default, even if
2846
- // the machine running the tests has its own shell selection persisted.
2847
- const originalLockfileDir = process.env.CADET_LOCKFILE_DIR;
2848
- const lockfileDir = join(ws, "lockfile");
2849
- mkdirSync(lockfileDir, { recursive: true });
2850
- process.env.CADET_LOCKFILE_DIR = lockfileDir;
2851
- try {
2852
- const result = await ensureTunnelEdge({
2853
- assistantId: "assistant-1",
2854
- workspaceDir: ws,
2855
- gatewayPort: 7830,
2856
- });
2857
-
2858
- expect(result.shellMode).toBe("web");
2859
- } finally {
2860
- if (originalLockfileDir === undefined) {
2861
- delete process.env.CADET_LOCKFILE_DIR;
2862
- } else {
2863
- process.env.CADET_LOCKFILE_DIR = originalLockfileDir;
2864
- }
2865
- }
2866
- const conf = realFs.readFileSync(ingressConfPath(ws), "utf-8");
2867
- expect(conf).not.toContain("__cadet-app-index");
2868
- expect(conf).toContain('\\"url\\":\\"assistant/\\"');
2869
- });
2870
2488
  });