@mycadet/cli 0.13.0-dev.202610280329.ad222b0 → 0.13.0-dev.202610290143.526d7ca

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 (31) 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/lockfile-contract.ts +0 -14
  11. package/node_modules/@mycadet/local-mode/src/lockfile.ts +9 -8
  12. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  13. package/node_modules/@mycadet/shared/package.json +1 -1
  14. package/package.json +1 -1
  15. package/src/__tests__/app-command.test.ts +0 -21
  16. package/src/__tests__/app-tunnel-status.test.ts +1 -0
  17. package/src/__tests__/nginx-ingress.test.ts +36 -14
  18. package/src/__tests__/tailscale.test.ts +28 -133
  19. package/src/__tests__/tunnel-stop.test.ts +12 -18
  20. package/src/__tests__/tunnel.test.ts +116 -293
  21. package/src/__tests__/upgrade-local.test.ts +3 -1
  22. package/src/__tests__/wake.test.ts +17 -30
  23. package/src/commands/tunnel.ts +13 -52
  24. package/src/lib/ingress-config.ts +3 -85
  25. package/src/lib/nginx-ingress.ts +7 -14
  26. package/src/lib/tunnel.ts +29 -132
  27. package/src/lib/tunnels/cloudflare.ts +5 -26
  28. package/src/lib/tunnels/ngrok.ts +17 -64
  29. package/src/lib/tunnels/process-lifecycle.ts +0 -2
  30. package/src/lib/tunnels/tailscale.ts +13 -114
  31. package/src/__tests__/ingress-config.test.ts +0 -184
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,7 +22,6 @@
22
22
  * on disk; see `lockfile.ts`); the validated value carries only the modeled
23
23
  * shape.
24
24
  */
25
- import { isLoopbackPublicUrl } from "@mycadet/service-contracts/remote-web-pairing";
26
25
  import { TUNNEL_PROVIDERS } from "@mycadet/service-contracts/ingress";
27
26
  import { SEEDS } from "@mycadet/environments";
28
27
  import { z } from "zod";
@@ -203,19 +202,6 @@ export function getGatewayUrl(entry: LockfileAssistant): string {
203
202
  return `http://127.0.0.1:${port ?? GATEWAY_PORT}`;
204
203
  }
205
204
 
206
- /**
207
- * Whether the entry's gateway lives on another machine: a custom remote.
208
- * Its recorded host and port are inherently off-machine — a loopback
209
- * topology's gateway is always on this machine.
210
- */
211
- export function isRemoteGatewayEntry(entry: LockfileAssistant): boolean {
212
- if (entry.cloud !== "custom") {
213
- return false;
214
- }
215
- const gatewayUrl = getGatewayUrl(entry);
216
- return isUsableRuntimeUrl(gatewayUrl) && !isLoopbackPublicUrl(gatewayUrl);
217
- }
218
-
219
205
  /**
220
206
  * Per-instance resources for a local assistant: the renderer-facing ports,
221
207
  * the instance directory, the local runtime install metadata, and the
@@ -152,8 +152,7 @@ export function stampLockfileAssistantOnboardedIfPresent(
152
152
  return patchLockfileAssistantIfPresent(
153
153
  assistantId,
154
154
  { onboardedAt },
155
- (entry) =>
156
- typeof entry.onboardedAt === "string" && entry.onboardedAt !== "",
155
+ (entry) => typeof entry.onboardedAt === "string" && entry.onboardedAt !== "",
157
156
  );
158
157
  }
159
158
 
@@ -164,8 +163,8 @@ export function stampLockfileAssistantOnboardedIfPresent(
164
163
  */
165
164
  function patchLockfileAssistantIfPresent(
166
165
  assistantId: string,
167
- patch: Record<string, unknown>,
168
- skip?: (entry: Record<string, unknown>) => boolean,
166
+ patch: LockfileAssistantPatch,
167
+ skip?: (entry: LockfileAssistant) => boolean,
169
168
  ): WriteResult {
170
169
  if (typeof assistantId !== "string" || assistantId === "") {
171
170
  return { ok: false, status: 400, error: "Missing assistantId" };
@@ -182,16 +181,18 @@ function patchLockfileAssistantIfPresent(
182
181
  error: "No lockfile entry for this assistant",
183
182
  };
184
183
  }
185
- const entry = assistants[idx] as unknown as Record<string, unknown>;
184
+ const entry = assistants[idx]!;
186
185
  const converged =
187
186
  skip?.(entry) ??
188
- Object.entries(patch).every(([key, value]) => entry[key] === value);
187
+ (Object.entries(patch) as Array<[keyof LockfileAssistant, unknown]>).every(
188
+ ([key, value]) => entry[key] === value,
189
+ );
189
190
  if (converged) {
190
191
  return { ok: true, lockfile };
191
192
  }
192
- assistants[idx] = { ...entry, ...patch } as LockfileAssistant;
193
+ assistants[idx] = { ...entry, ...patch };
193
194
  lockfile.assistants = assistants;
194
- return writeRawLockfile(lockfile as unknown as Record<string, unknown>);
195
+ return writeRawLockfile(lockfile);
195
196
  });
196
197
  return locked.ok ? locked.value : lockFailure(locked.error);
197
198
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
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.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
4
4
  "private": true,
5
5
  "exports": {
6
6
  ".": "./github-repository.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/cli",
3
- "version": "0.13.0-dev.202610280329.ad222b0",
3
+ "version": "0.13.0-dev.202610290143.526d7ca",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -18,12 +18,9 @@ import { join } from "node:path";
18
18
  // ---------------------------------------------------------------------------
19
19
 
20
20
  import * as tunnelLib from "../lib/tunnel.js";
21
- import type { LockfileAssistant } from "../lib/assistant-config.js";
22
21
  import * as nginxIngress from "../lib/nginx-ingress.js";
23
22
 
24
23
  const ensureNginxForEdgeMock = mock(tunnelLib.ensureNginxForEdge);
25
- const resolveLocalTunnelTargetMock = mock(tunnelLib.resolveLocalTunnelTarget);
26
-
27
24
  const ensureAppServerMock = mock(nginxIngress.ensureAppServer);
28
25
  const isIngressRunningMock = mock(nginxIngress.isIngressRunning);
29
26
  const readIngressStateMock = mock(nginxIngress.readIngressState);
@@ -32,7 +29,6 @@ const stopIngressNginxMock = mock(nginxIngress.stopIngressNginx);
32
29
  mock.module("../lib/tunnel.js", () => ({
33
30
  ...tunnelLib,
34
31
  ensureNginxForEdge: ensureNginxForEdgeMock,
35
- resolveLocalTunnelTarget: resolveLocalTunnelTargetMock,
36
32
  }));
37
33
  mock.module("../lib/nginx-ingress.js", () => ({
38
34
  ...nginxIngress,
@@ -67,7 +63,6 @@ beforeEach(() => {
67
63
  };
68
64
  ensureNginxForEdgeMock.mockReset();
69
65
  ensureNginxForEdgeMock.mockResolvedValue("nginx/1.26.3");
70
- resolveLocalTunnelTargetMock.mockReset();
71
66
  ensureAppServerMock.mockReset();
72
67
  isIngressRunningMock.mockReset();
73
68
  isIngressRunningMock.mockReturnValue(false);
@@ -90,19 +85,8 @@ afterAll(() => {
90
85
  rmSync(testDir, { recursive: true, force: true });
91
86
  });
92
87
 
93
- const LOCAL_ENTRY: LockfileAssistant = {
94
- assistantId: "assistant-1",
95
- cloud: "local",
96
- };
97
-
98
88
  describe("cadet app", () => {
99
89
  test("start brings the edge up for the resolved local assistant", async () => {
100
- const workspaceDir = join(testDir, "workspace");
101
- resolveLocalTunnelTargetMock.mockReturnValue({
102
- entry: LOCAL_ENTRY,
103
- gatewayPort: 7830,
104
- workspaceDir,
105
- });
106
90
  ensureAppServerMock.mockResolvedValue({ port: 7841, started: true });
107
91
  process.argv = ["bun", "cadet", "app", "start"];
108
92
 
@@ -116,11 +100,6 @@ describe("cadet app", () => {
116
100
  });
117
101
 
118
102
  test("start reports a reused edge and the stop command", async () => {
119
- resolveLocalTunnelTargetMock.mockReturnValue({
120
- entry: LOCAL_ENTRY,
121
- gatewayUrl: "http://127.0.0.1:7830",
122
- workspaceDir: join(testDir, "workspace"),
123
- } as never);
124
103
  ensureAppServerMock.mockResolvedValue({ port: 7841, started: false });
125
104
  process.argv = ["bun", "cadet", "app", "start"];
126
105
 
@@ -35,6 +35,7 @@ beforeEach(() => {
35
35
  });
36
36
 
37
37
  afterAll(() => {
38
+ readRootProcessesMock.mockRestore();
38
39
  logMock.mockRestore();
39
40
  errorMock.mockRestore();
40
41
  rmSync(testDir, { recursive: true, force: true });
@@ -23,6 +23,7 @@ import {
23
23
  test,
24
24
  } from "bun:test";
25
25
 
26
+ import { resolveLockfilePath } from "@mycadet/local-mode";
26
27
  import * as httpClient from "../lib/http-client.js";
27
28
  import * as versionModule from "@mycadet/shared/version";
28
29
  import * as assistantConfigModule from "../lib/assistant-config.js";
@@ -156,6 +157,11 @@ function installKillMock(): void {
156
157
  }
157
158
 
158
159
  afterEach(() => {
160
+ if (originalConfigHome === undefined) {
161
+ delete process.env.XDG_CONFIG_HOME;
162
+ } else {
163
+ process.env.XDG_CONFIG_HOME = originalConfigHome;
164
+ }
159
165
  process.kill = originalKill;
160
166
  fakePids.clear();
161
167
  execFileSyncMock.mockReset();
@@ -186,23 +192,41 @@ afterEach(() => {
186
192
  }
187
193
  });
188
194
 
195
+ const originalConfigHome = process.env.XDG_CONFIG_HOME;
196
+
189
197
  function makeWorkspace(): string {
190
198
  const dir = mkdtempSync(join(tmpdir(), "cadet-ingress-test-"));
191
199
  workspaces.push(dir);
192
- // The edge reads the tunnel contract (publicBaseUrl) from the default
193
- // workspace and keeps its own state under the XDG data dir — pin both so
194
- // every test is hermetic.
200
+ // The edge reads the lockfile's tunnel record and keeps its own state
201
+ // under the XDG data dir — pin both config and data homes so every test
202
+ // is hermetic.
195
203
  process.env.CADET_WORKSPACE_DIR = dir;
204
+ process.env.XDG_CONFIG_HOME = dir;
196
205
  process.env.XDG_DATA_HOME = dir;
197
206
  return dir;
198
207
  }
199
208
 
200
- /** Seed the workspace's saved tunnel URL (ingress.publicBaseUrl). */
201
- function writeWorkspaceIngressUrl(workspaceDir: string, url: string): void {
202
- realFs.writeFileSync(
203
- join(workspaceDir, "config.json"),
204
- JSON.stringify({ ingress: { publicBaseUrl: url } }),
205
- );
209
+ /** Stamp the lockfile's tunnel record with a published URL. */
210
+ function stampTunnelRecord(url: string): void {
211
+ // Resolve exactly as the edge's own read will.
212
+ const path = resolveLockfilePath();
213
+ let lockfile: Record<string, unknown> = {};
214
+ try {
215
+ lockfile = JSON.parse(realFs.readFileSync(path, "utf-8")) as Record<
216
+ string,
217
+ unknown
218
+ >;
219
+ } catch {
220
+ // No lockfile yet: the stamp creates it.
221
+ }
222
+ lockfile.tunnel = {
223
+ pid: 4242,
224
+ provider: "ngrok",
225
+ startedAt: new Date().toISOString(),
226
+ publicUrl: url,
227
+ };
228
+ realFs.mkdirSync(join(path, ".."), { recursive: true });
229
+ realFs.writeFileSync(path, JSON.stringify(lockfile));
206
230
  }
207
231
 
208
232
  describe("buildIngressNginxConfig", () => {
@@ -1712,7 +1736,6 @@ describe("ensureAppServer", () => {
1712
1736
  });
1713
1737
 
1714
1738
  test("threads the lockfile display name and assistant id into the served SPA config", async () => {
1715
- makeWorkspace();
1716
1739
  mockNginxInstalled();
1717
1740
  mockNginxSpawn();
1718
1741
  mockWebDistPresent();
@@ -1744,7 +1767,6 @@ describe("ensureAppServer", () => {
1744
1767
  });
1745
1768
 
1746
1769
  test("omits the assistant label when the lockfile has no matching entry", async () => {
1747
- makeWorkspace();
1748
1770
  mockNginxInstalled();
1749
1771
  mockNginxSpawn();
1750
1772
  mockWebDistPresent();
@@ -1783,7 +1805,6 @@ describe("ensureAppServer", () => {
1783
1805
  });
1784
1806
 
1785
1807
  test("restarts the edge when the lockfile display name changes", async () => {
1786
- makeWorkspace();
1787
1808
  mockNginxInstalled();
1788
1809
  mockNginxSpawn();
1789
1810
  mockWebDistPresent();
@@ -2353,11 +2374,12 @@ describe("the app shell edge", () => {
2353
2374
  });
2354
2375
 
2355
2376
  test("stamps the saved tunnel URL as the served config's cloudUrl", async () => {
2356
- const ws = makeWorkspace();
2377
+ makeWorkspace();
2357
2378
  mockNginxInstalled();
2358
2379
  mockNginxSpawn();
2359
2380
  mockWebDistPresent();
2360
- writeWorkspaceIngressUrl(ws, "https://camping.ngrok-free.dev");
2381
+ // The record is the save: the edge reads its cloudUrl from there.
2382
+ stampTunnelRecord("https://camping.ngrok-free.dev");
2361
2383
 
2362
2384
  const result = await startRemoteWebIngress({
2363
2385
  gatewayUrl: "http://127.0.0.1:7830",
@@ -1,11 +1,5 @@
1
1
  import { afterEach, describe, expect, test } from "bun:test";
2
- import {
3
- existsSync,
4
- mkdtempSync,
5
- readFileSync,
6
- rmSync,
7
- writeFileSync,
8
- } from "node:fs";
2
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
9
3
  import { tmpdir } from "node:os";
10
4
  import { join } from "node:path";
11
5
 
@@ -14,13 +8,12 @@ import {
14
8
  getTailscaleInstallMessage,
15
9
  normalizeDnsName,
16
10
  resolveServeHostname,
17
- retractServeUrl,
18
- shouldClearIngressUrl,
19
11
  startTailscaleServe,
20
12
  stopTailscaleServe,
21
13
  type TailscaleCommandResult,
22
14
  type TailscaleDeps,
23
15
  } from "../lib/tunnels/tailscale.js";
16
+ import { resolveLockfilePath } from "@mycadet/local-mode";
24
17
  import { snapshotEnv } from "./helpers/env.js";
25
18
 
26
19
  describe("Tailscale discovery", () => {
@@ -51,10 +44,14 @@ const tempDirs: string[] = [];
51
44
  function makeWorkspace(): string {
52
45
  const dir = mkdtempSync(join(tmpdir(), "cadet-tailscale-test-"));
53
46
  tempDirs.push(dir);
47
+ // The providers resolve the machine-level workspace themselves, and the
48
+ // run's lockfile stamp lands in the sandboxed xdg root beside it.
49
+ process.env.CADET_WORKSPACE_DIR = dir;
50
+ process.env.XDG_CONFIG_HOME = dir;
54
51
  return dir;
55
52
  }
56
53
 
57
- const TAILNET_URL = "https://my-host.tail-scale.ts.net";
54
+ const restoreEnv = snapshotEnv(["XDG_CONFIG_HOME", "CADET_WORKSPACE_DIR"]);
58
55
 
59
56
  const RUNNING_STATUS = JSON.stringify({
60
57
  BackendState: "Running",
@@ -88,37 +85,7 @@ function makeDeps(opts: {
88
85
  return { deps, calls };
89
86
  }
90
87
 
91
- interface WorkspaceIngressConfig {
92
- ingress: {
93
- enabled?: boolean;
94
- publicBaseUrl?: string;
95
- assistantId?: string;
96
- lastTunnel?: { provider: string; publicBaseUrl: string };
97
- pairingTunnel?: { provider: string; publicBaseUrl: string };
98
- };
99
- }
100
-
101
- function readConfig(workspaceDir: string): WorkspaceIngressConfig {
102
- return JSON.parse(
103
- readFileSync(join(workspaceDir, "config.json"), "utf-8"),
104
- ) as WorkspaceIngressConfig;
105
- }
106
-
107
- /** A workspace whose ingress base URL is a live webhook callback base. */
108
- function writePreservedConfig(workspaceDir: string, webhookBase: string): void {
109
- writeFileSync(
110
- join(workspaceDir, "config.json"),
111
- JSON.stringify({
112
- ingress: {
113
- enabled: true,
114
- publicBaseUrl: webhookBase,
115
- lastTunnel: { provider: "ngrok", publicBaseUrl: webhookBase },
116
- },
117
- }),
118
- );
119
- }
120
88
 
121
- const restoreEnv = snapshotEnv(["XDG_CONFIG_HOME"]);
122
89
 
123
90
  afterEach(() => {
124
91
  restoreEnv();
@@ -179,7 +146,7 @@ describe("startTailscaleServe", () => {
179
146
  test("throws install guidance when the binary is missing", async () => {
180
147
  const { deps, calls } = makeDeps({ binary: null });
181
148
  await expect(
182
- startTailscaleServe({ port: 7840, workspaceDir: makeWorkspace() }, deps),
149
+ (makeWorkspace(), startTailscaleServe({ port: 7840 }, deps)),
183
150
  ).rejects.toThrow("Tailscale is not installed");
184
151
  expect(calls).toHaveLength(0);
185
152
  });
@@ -193,7 +160,7 @@ describe("startTailscaleServe", () => {
193
160
  },
194
161
  });
195
162
  await expect(
196
- startTailscaleServe({ port: 7840, workspaceDir: makeWorkspace() }, deps),
163
+ (makeWorkspace(), startTailscaleServe({ port: 7840 }, deps)),
197
164
  ).rejects.toThrow("not logged in");
198
165
  expect(calls).not.toContainEqual(["serve", "--bg", "7840"]);
199
166
  });
@@ -209,7 +176,7 @@ describe("startTailscaleServe", () => {
209
176
  },
210
177
  });
211
178
  await expect(
212
- startTailscaleServe({ port: 7840, workspaceDir: makeWorkspace() }, deps),
179
+ (makeWorkspace(), startTailscaleServe({ port: 7840 }, deps)),
213
180
  ).rejects.toThrow("Could not query Tailscale");
214
181
  });
215
182
 
@@ -222,53 +189,21 @@ describe("startTailscaleServe", () => {
222
189
  },
223
190
  });
224
191
 
225
- const info = await startTailscaleServe({ port: 7840, workspaceDir }, deps);
192
+ const info = await startTailscaleServe({ port: 7840 }, deps);
226
193
 
227
194
  expect(info.publicUrl).toBe("https://my-host.tail-scale.ts.net");
228
195
  expect(info.port).toBe(7840);
229
196
  expect(calls).toContainEqual(["serve", "--bg", "7840"]);
230
197
 
231
- const config = JSON.parse(
232
- readFileSync(join(workspaceDir, "config.json"), "utf-8"),
233
- );
234
- expect(config.ingress.publicBaseUrl).toBe(
198
+ // The lockfile record is the save: the tailnet URL is the tunnel's
199
+ // published base, and the wake restore reads it from there.
200
+ const lockfile = JSON.parse(
201
+ readFileSync(resolveLockfilePath(), "utf-8"),
202
+ ) as { tunnel?: { publicUrl?: string } };
203
+ expect(lockfile.tunnel?.publicUrl).toBe(
235
204
  "https://my-host.tail-scale.ts.net",
236
205
  );
237
- expect(config.ingress.enabled).toBe(true);
238
- });
239
-
240
- test("preserveIngressUrl records a pairing tunnel and leaves the ingress record", async () => {
241
- const workspaceDir = makeWorkspace();
242
- const webhookBase = "https://existing.ngrok.app";
243
- writePreservedConfig(workspaceDir, webhookBase);
244
- const { deps } = makeDeps({
245
- responses: {
246
- "status --json": ok(RUNNING_STATUS),
247
- "serve --bg 7840": ok(),
248
- },
249
- });
250
-
251
- await startTailscaleServe(
252
- {
253
- port: 7840,
254
- workspaceDir,
255
- assistantId: "ts-1",
256
- preserveIngressUrl: true,
257
- },
258
- deps,
259
- );
260
-
261
- // The webhook callback base and the tunnel it names survive untouched...
262
- const config = readConfig(workspaceDir);
263
- expect(config.ingress.publicBaseUrl).toBe(webhookBase);
264
- expect(config.ingress.lastTunnel?.provider).toBe("ngrok");
265
- // ...while the tailnet URL is recorded as the address to pair against, in
266
- // the workspace config the daemon's status route reads...
267
- expect(config.ingress.pairingTunnel).toEqual({
268
- provider: "tailscale",
269
- publicBaseUrl: TAILNET_URL,
270
- });
271
- expect(config.ingress.assistantId).toBe("ts-1");
206
+ expect(existsSync(join(workspaceDir, "config.json"))).toBe(false);
272
207
  });
273
208
 
274
209
  test("surfaces tailscale's enable-URL guidance when serve is not enabled", async () => {
@@ -286,7 +221,7 @@ describe("startTailscaleServe", () => {
286
221
  });
287
222
 
288
223
  await expect(
289
- startTailscaleServe({ port: 7840, workspaceDir }, deps),
224
+ startTailscaleServe({ port: 7840 }, deps),
290
225
  ).rejects.toThrow(enableUrl);
291
226
 
292
227
  // A failed serve must not persist an ingress URL.
@@ -307,55 +242,15 @@ describe("stopTailscaleServe", () => {
307
242
  });
308
243
  });
309
244
 
310
- // ── retractServeUrl ───────────────────────────────────────────────────────────
311
-
312
- describe("retractServeUrl", () => {
313
- const PRESERVE_OPTS = { assistantId: "ts-1", preserveIngressUrl: true };
314
-
315
- test("drops the pairing record and leaves the webhook callback base", () => {
316
- const workspaceDir = makeWorkspace();
317
- writePreservedConfig(workspaceDir, "https://existing.ngrok.app");
318
-
319
- retractServeUrl(PRESERVE_OPTS, workspaceDir);
320
-
321
- // The pairing record goes, the webhook callback base stays.
322
- const config = readConfig(workspaceDir);
323
- expect(config.ingress.pairingTunnel).toBeUndefined();
324
- expect(config.ingress.publicBaseUrl).toBe("https://existing.ngrok.app");
325
- expect(config.ingress.lastTunnel?.provider).toBe("ngrok");
326
- });
327
-
328
- test("clears the ingress URL outright when it owns it", () => {
329
- const workspaceDir = makeWorkspace();
330
- writeFileSync(
331
- join(workspaceDir, "config.json"),
332
- JSON.stringify({
333
- ingress: { enabled: true, publicBaseUrl: TAILNET_URL },
334
- }),
335
- );
336
-
337
- retractServeUrl({ assistantId: "ts-1" }, workspaceDir);
338
-
339
- expect(readConfig(workspaceDir).ingress.publicBaseUrl).toBeUndefined();
340
- });
341
- });
342
-
343
- // ── shouldClearIngressUrl ─────────────────────────────────────────────────────
344
-
345
- describe("shouldClearIngressUrl", () => {
346
- test("clears only after a confirmed successful stop", () => {
347
- expect(shouldClearIngressUrl({ status: 0, stdout: "", stderr: "" })).toBe(
348
- true,
349
- );
350
- });
351
-
352
- test("keeps the URL when the stop command fails", () => {
353
- expect(
354
- shouldClearIngressUrl({ status: 1, stdout: "", stderr: "boom" }),
355
- ).toBe(false);
356
- });
245
+ // ── stopTailscaleServe ────────────────────────────────────────────────────────
357
246
 
358
- test("keeps the URL when the stop command threw before running", () => {
359
- expect(shouldClearIngressUrl(null)).toBe(false);
247
+ describe("stopTailscaleServe", () => {
248
+ test("turns off the HTTPS:443 serve (narrow off form)", () => {
249
+ const { deps, calls } = makeDeps({
250
+ responses: { "serve --https=443 off": ok() },
251
+ });
252
+ const result = stopTailscaleServe("tailscale", deps);
253
+ expect(result.status).toBe(0);
254
+ expect(calls).toContainEqual(["serve", "--https=443", "off"]);
360
255
  });
361
256
  });