@mycadet/cli 0.13.0-dev.202611140220.fac72d3 → 0.13.0-dev.202611141723.98995ee

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 (92) hide show
  1. package/knip.json +0 -3
  2. package/node_modules/@mycadet/assistant-api/constants/codex-models.ts +22 -0
  3. package/node_modules/@mycadet/assistant-api/index.ts +1 -0
  4. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
  5. package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  6. package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  8. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  9. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
  10. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/index.ts +11 -0
  11. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +7 -6
  12. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/seeds.ts +151 -0
  13. package/node_modules/@mycadet/local-mode/package.json +1 -2
  14. package/node_modules/@mycadet/local-mode/src/__tests__/cloud-backup.test.ts +5 -9
  15. package/node_modules/@mycadet/local-mode/src/__tests__/environment-base-url.test.ts +67 -0
  16. package/node_modules/@mycadet/local-mode/src/__tests__/helpers/lockfile-entry.ts +0 -1
  17. package/node_modules/@mycadet/local-mode/src/__tests__/operations-doctor.test.ts +16 -6
  18. package/node_modules/@mycadet/local-mode/src/__tests__/operations-retire.test.ts +3 -4
  19. package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-retire.test.ts +4 -10
  20. package/node_modules/@mycadet/local-mode/src/cloud-auth.ts +9 -31
  21. package/node_modules/@mycadet/local-mode/src/cloud-registration.ts +7 -18
  22. package/node_modules/@mycadet/local-mode/src/cloud-releases.ts +2 -3
  23. package/node_modules/@mycadet/local-mode/src/config.ts +2 -7
  24. package/node_modules/@mycadet/local-mode/src/daemon-readiness.ts +3 -5
  25. package/node_modules/@mycadet/local-mode/src/index.ts +0 -1
  26. package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -1
  27. package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +4 -22
  28. package/node_modules/@mycadet/local-mode/src/operations/cloud-proxy.ts +3 -3
  29. package/node_modules/@mycadet/local-mode/src/operations/exec.ts +3 -2
  30. package/node_modules/@mycadet/local-mode/src/ports.ts +1 -1
  31. package/node_modules/@mycadet/local-mode/src/remotes/cloud/backup.ts +4 -4
  32. package/node_modules/@mycadet/local-mode/src/remotes/cloud/exec.ts +0 -10
  33. package/node_modules/@mycadet/local-mode/src/remotes/cloud/hatch.ts +5 -8
  34. package/node_modules/@mycadet/local-mode/src/remotes/cloud/migrations.ts +11 -18
  35. package/node_modules/@mycadet/local-mode/src/remotes/cloud/restore.ts +3 -8
  36. package/node_modules/@mycadet/local-mode/src/remotes/cloud/retire.ts +3 -6
  37. package/node_modules/@mycadet/local-mode/src/remotes/cloud/terminal-client.ts +13 -16
  38. package/node_modules/@mycadet/local-mode/src/remotes/cloud/upgrade.ts +11 -17
  39. package/node_modules/@mycadet/local-mode/src/remotes/local/common.ts +20 -41
  40. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  41. package/node_modules/@mycadet/shared/index.ts +11 -0
  42. package/node_modules/@mycadet/shared/package.json +7 -6
  43. package/node_modules/@mycadet/shared/seeds.ts +151 -0
  44. package/package.json +1 -3
  45. package/src/__tests__/cloud-client.test.ts +49 -90
  46. package/src/__tests__/debug.test.ts +7 -1
  47. package/src/__tests__/helpers/lockfile-entry.ts +0 -1
  48. package/src/__tests__/pair.test.ts +11 -12
  49. package/src/__tests__/ps-cloud-status.test.ts +6 -3
  50. package/src/__tests__/servers/bun.test.ts +1 -1
  51. package/src/__tests__/setup.test.ts +16 -10
  52. package/src/commands/debug.ts +3 -3
  53. package/src/commands/login.ts +1 -2
  54. package/src/commands/ps.ts +3 -1
  55. package/src/commands/terminal.ts +2 -5
  56. package/src/lib/__tests__/cloud-client-signed-url.test.ts +24 -19
  57. package/src/lib/assistant-client.ts +2 -2
  58. package/src/lib/assistant-config.ts +1 -17
  59. package/src/lib/cloud-client.ts +11 -16
  60. package/src/lib/cloud-login.ts +7 -9
  61. package/src/lib/live-voice/tunnel.ts +1 -1
  62. package/src/lib/remotes/cloud.ts +3 -3
  63. package/src/lib/servers/common.ts +1 -2
  64. package/src/lib/sync-cloud-assistants.ts +2 -2
  65. package/src/lib/terminal-session.ts +3 -2
  66. package/node_modules/@mycadet/environments/package.json +0 -21
  67. package/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -76
  68. package/node_modules/@mycadet/environments/src/__tests__/install-layout.test.ts +0 -98
  69. package/node_modules/@mycadet/environments/src/__tests__/package-boundary.test.ts +0 -95
  70. package/node_modules/@mycadet/environments/src/__tests__/test-path-guard.test.ts +0 -89
  71. package/node_modules/@mycadet/environments/src/index.ts +0 -21
  72. package/node_modules/@mycadet/environments/src/install-layout.ts +0 -49
  73. package/node_modules/@mycadet/environments/src/seeds.ts +0 -89
  74. package/node_modules/@mycadet/environments/src/shell.test.ts +0 -89
  75. package/node_modules/@mycadet/environments/src/shell.ts +0 -110
  76. package/node_modules/@mycadet/environments/src/test-path-guard.ts +0 -113
  77. package/node_modules/@mycadet/environments/src/types.ts +0 -70
  78. package/node_modules/@mycadet/environments/tsconfig.json +0 -20
  79. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +0 -21
  80. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -76
  81. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/install-layout.test.ts +0 -98
  82. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/package-boundary.test.ts +0 -95
  83. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/test-path-guard.test.ts +0 -89
  84. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/index.ts +0 -21
  85. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/install-layout.ts +0 -49
  86. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/seeds.ts +0 -89
  87. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/shell.test.ts +0 -89
  88. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/shell.ts +0 -110
  89. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/test-path-guard.ts +0 -113
  90. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/types.ts +0 -70
  91. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/tsconfig.json +0 -20
  92. package/src/lib/environments/__tests__/seeds.test.ts +0 -78
package/knip.json CHANGED
@@ -2,8 +2,6 @@
2
2
  "entry": [
3
3
  "src/**/*.test.ts",
4
4
  "src/**/__tests__/**/*.ts",
5
- "src/lib/version-compat.ts",
6
- "src/lib/cloud-releases.ts",
7
5
  "src/lib/cli-error.ts",
8
6
  "scripts/**/*.ts"
9
7
  ],
@@ -11,7 +9,6 @@
11
9
  "ignoreDependencies": [
12
10
  "@mycadet/assistant-api",
13
11
  "@mycadet/avatar-manifest",
14
- "@mycadet/environments",
15
12
  "@mycadet/ipc-server-utils",
16
13
  "@mycadet/local-mode",
17
14
  "@mycadet/service-contracts",
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Model IDs Cadet allows through the ChatGPT Codex subscription endpoint
3
+ * (`https://chatgpt.com/backend-api/codex`).
4
+ *
5
+ * `oauth_subscription` OpenAI connections hard-route every request to that
6
+ * endpoint. Because unsupported model IDs return HTTP 400, this manually
7
+ * maintained compatibility allowlist gates whether such a connection may
8
+ * serve a given model during auto-resolution of an "Any active OpenAI
9
+ * connection" profile.
10
+ *
11
+ * Lives in the @mycadet/assistant-api package so the web client imports
12
+ * the same set the daemon enforces — one source, no drift.
13
+ */
14
+ export const CODEX_SUBSCRIPTION_MODEL_IDS: ReadonlySet<string> = new Set([
15
+ "gpt-6-astra",
16
+ "gpt-6-sol",
17
+ "gpt-6-luna",
18
+ "gpt-5.6-sol",
19
+ "gpt-5.6-terra",
20
+ "gpt-5.6-luna",
21
+ "gpt-5.5",
22
+ ]);
@@ -154,6 +154,7 @@ export {
154
154
  CALL_SITE_COMPACTION_AGENT,
155
155
  CALL_SITE_SYNTHETIC_AGENT_ERROR_MESSAGE,
156
156
  } from "./constants/call-sites.js";
157
+ export { CODEX_SUBSCRIPTION_MODEL_IDS } from "./constants/codex-models.js";
157
158
  export {
158
159
  DOCUMENT_EDIT_TOOL_NAMES,
159
160
  DOCUMENT_MUTATION_TOOL_NAMES,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
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.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
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.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
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.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
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.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
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.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,11 @@
1
+ export {
2
+ CADET_GITHUB_REPOSITORY,
3
+ CADET_GITHUB_REPOSITORY_URL,
4
+ } from "./github-repository.js";
5
+ export {
6
+ DEFAULT_APP_SERVER_PORT,
7
+ getCloudBaseUrl,
8
+ SEEDS,
9
+ type EnvironmentDefinition,
10
+ type PortMap,
11
+ } from "./seeds.js";
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@mycadet/shared",
3
- "version": "0.13.0-dev.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
4
4
  "private": true,
5
5
  "exports": {
6
- ".": "./github-repository.ts",
6
+ ".": "./index.ts",
7
+ "./eslint/imports-first": "./eslint/imports-first.mjs",
8
+ "./eslint/no-empty-imports": "./eslint/no-empty-imports.mjs",
9
+ "./eslint/no-re-exports": "./eslint/no-re-exports.mjs",
7
10
  "./fetch": "./fetch.ts",
8
11
  "./github-repository": "./github-repository.ts",
9
12
  "./providers/baseten": "./providers/baseten.ts",
10
13
  "./scripts/run-isolated-tests": "./scripts/run-isolated-tests.ts",
11
- "./version": "./version.ts",
12
- "./eslint/no-re-exports": "./eslint/no-re-exports.mjs",
13
- "./eslint/imports-first": "./eslint/imports-first.mjs",
14
- "./eslint/no-empty-imports": "./eslint/no-empty-imports.mjs"
14
+ "./seeds": "./seeds.ts",
15
+ "./version": "./version.ts"
15
16
  },
16
17
  "devDependencies": {
17
18
  "eslint": "10.1.0",
@@ -0,0 +1,151 @@
1
+ // Loaded standalone by Capacitor's single-file TS config loader (via the
2
+ // `./seeds` subpath) — keep imports type-only (this file has none) and keep
3
+ // this file free of the import-meta meta-property: the loader transpiles this
4
+ // file to CJS, where that syntax is illegal and makes Node misroute the
5
+ // result as ESM. Browser bundles (chrome extension, web renderer) import it
6
+ // for the same reason.
7
+
8
+ /**
9
+ * Per-service default port set. Phase 5 (per-environment port offsets) is
10
+ * deferred from MVP, so today every environment uses the same port set. The
11
+ * shape exists so the rest of the stack can call `getDefaultPorts(env)` and
12
+ * gain per-env offsets later without changing any call sites.
13
+ */
14
+ export interface PortMap {
15
+ daemon: number;
16
+ gateway: number;
17
+ qdrant: number;
18
+ ces: number;
19
+ outboundProxy: number;
20
+ tcp: number;
21
+ }
22
+
23
+ /**
24
+ * The port the local app server binds by default — the single origin every
25
+ * local surface (webview, assistant daemon, CLI) dials. The local seed's
26
+ * base URL reuses it so no surface carries its own port constant.
27
+ */
28
+ export const DEFAULT_APP_SERVER_PORT = 7840;
29
+
30
+ /**
31
+ * A resolved environment definition. Required fields are `name` and
32
+ * `baseUrl`. All other fields are optional and declared upfront — new
33
+ * fields are additive, never breaking. `name` is intentionally typed as
34
+ * `string` (not `keyof SEEDS`) so custom environments can be represented by
35
+ * future layers (user config file, ad-hoc env vars, etc.).
36
+ */
37
+ export interface EnvironmentDefinition {
38
+ name: string;
39
+
40
+ /**
41
+ * The single origin for API, auth, web, and the assistant mount — one
42
+ * deployment serves all of it, so one URL describes it. The local seed
43
+ * points at the app server's default port; the cloud seeds point at the
44
+ * environment's host.
45
+ */
46
+ baseUrl: string;
47
+
48
+ /** Human-readable label for UI surfaces. */
49
+ displayName?: string;
50
+
51
+ /** Hint for UI surfaces that want to tint or badge their display. */
52
+ tintColor?: string;
53
+
54
+ /** Per-service port overrides merged on top of defaults. */
55
+ portsOverride?: Partial<PortMap>;
56
+
57
+ /** Override for the XDG config directory. */
58
+ configDirOverride?: string;
59
+
60
+ /**
61
+ * Override for the directory containing the lockfile. In-memory only —
62
+ * tests inject curated env lists with it; path helpers never read env
63
+ * vars to populate it.
64
+ */
65
+ lockfileDirOverride?: string;
66
+ }
67
+
68
+ /**
69
+ * Non-prod port blocks. Each environment gets a 1000-port window in the
70
+ * 17000–21000 band. Within a block, services are spaced 100 apart so up to
71
+ * 100 assistants can coexist without the scan (`findAvailablePort`) running
72
+ * one service's range into the next. Band chosen to sit below Linux's
73
+ * default ephemeral start (32768) and macOS's (49152), and away from the
74
+ * 3000/5000/8000/9000 dev-tool swamp. Production keeps its legacy,
75
+ * non-contiguous port set (7821/7830/6333/8090/8080/8765): cross-env
76
+ * collision is the only problem this change targets, prod is unaffected
77
+ * because only one env's assistants compete on a given machine, and
78
+ * churning it would leave existing hatches on 7821 while new ones
79
+ * allocated elsewhere.
80
+ */
81
+ function portBlock(base: number): PortMap {
82
+ return {
83
+ daemon: base,
84
+ gateway: base + 100,
85
+ qdrant: base + 200,
86
+ ces: base + 300,
87
+ outboundProxy: base + 400,
88
+ tcp: base + 500,
89
+ };
90
+ }
91
+
92
+ /**
93
+ * The base URL of Cadet Cloud — the hosted deployment the local surfaces
94
+ * pair with (API, auth, web, and the assistant mount all live on it). The
95
+ * explicit `CADET_CLOUD_URL` override wins, else the environment's seed —
96
+ * `CADET_ENVIRONMENT` or `VITE_ENVIRONMENT` picks it; unknown falls back
97
+ * to dev. This says "cloud" because the URL always points at a Cadet Cloud
98
+ * deployment, never at something that represents this surface itself.
99
+ */
100
+ export function getCloudBaseUrl(): string {
101
+ // globalThis.process reads the same env under bun/node while staying
102
+ // crash-free in browser bundles (no bare `process` reference) — and free
103
+ // of import-meta syntax, which the Capacitor config loader can't transpile.
104
+ const env = (
105
+ globalThis as unknown as {
106
+ process?: { env?: Record<string, string | undefined> };
107
+ }
108
+ ).process?.env;
109
+ const explicit = env?.CADET_CLOUD_URL?.trim();
110
+ if (explicit) return explicit;
111
+ const envName = env?.CADET_ENVIRONMENT ?? env?.VITE_ENVIRONMENT;
112
+ return ((envName && SEEDS[envName]) || SEEDS.dev).baseUrl;
113
+ }
114
+
115
+ /**
116
+ * Built-in environment definitions and the source of truth for the
117
+ * set of known environment names.
118
+ *
119
+ * Custom environments via a user config file are a future phase — see the
120
+ * "Coexisting environments" design doc. Until then, a call site that needs a
121
+ * new environment must add it here and rebuild.
122
+ */
123
+ export const SEEDS: Record<string, EnvironmentDefinition> = {
124
+ production: {
125
+ name: "production",
126
+ baseUrl: "https://mycadet.ai",
127
+ },
128
+ staging: {
129
+ name: "staging",
130
+ baseUrl: "https://staging.mycadet.ai",
131
+ portsOverride: portBlock(17000),
132
+ },
133
+ test: {
134
+ name: "test",
135
+ baseUrl: "https://test.mycadet.ai",
136
+ portsOverride: portBlock(19000),
137
+ },
138
+ dev: {
139
+ name: "dev",
140
+ baseUrl: "https://dev.mycadet.ai",
141
+ portsOverride: portBlock(18000),
142
+ },
143
+ local: {
144
+ name: "local",
145
+ baseUrl: `http://localhost:${DEFAULT_APP_SERVER_PORT}`,
146
+ // assistantBaseUrl: "http://host.docker.internal:7840",
147
+ // ^ uncomment once dockerized hatch path is live — the assistant runs
148
+ // in a different network namespace than the host.
149
+ portsOverride: portBlock(20000),
150
+ },
151
+ };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/local-mode",
3
- "version": "0.13.0-dev.202611140220.fac72d3",
3
+ "version": "0.13.0-dev.202611141723.98995ee",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@mycadet/avatar-manifest": "workspace:*",
18
- "@mycadet/environments": "workspace:*",
19
18
  "@mycadet/ipc-server-utils": "workspace:*",
20
19
  "@mycadet/service-contracts": "workspace:*",
21
20
  "@mycadet/shared": "workspace:*",
@@ -9,6 +9,8 @@ import {
9
9
  test,
10
10
  } from "bun:test";
11
11
 
12
+ import * as shared from "@mycadet/shared";
13
+
12
14
  import type { LockfileAssistant } from "../lockfile-contract";
13
15
  import * as cloudAuth from "../cloud-auth";
14
16
  import { createCloudBackup, listCloudBackups } from "../remotes/cloud/backup";
@@ -22,7 +24,7 @@ const invalidateOrgIdCacheSpy = spyOn(
22
24
  cloudAuth,
23
25
  "invalidateOrgIdCache",
24
26
  ).mockImplementation(() => {});
25
- const getCloudUrlSpy = spyOn(cloudAuth, "resolveCloudUrl").mockReturnValue(
27
+ const getCloudUrlSpy = spyOn(shared, "getCloudBaseUrl").mockReturnValue(
26
28
  "https://cloud.mycadet.ai",
27
29
  );
28
30
 
@@ -89,10 +91,7 @@ describe("listCloudBackups", () => {
89
91
 
90
92
  expect(result).toEqual(["2026-09-15T11:00:00Z", "2026-09-15T10:00:00Z"]);
91
93
  expect(fetchCalls[0]).toEqual({ url: BACKUPS_URL, method: "GET" });
92
- expect(authHeadersSpy).toHaveBeenCalledWith(
93
- "test-cloud-token",
94
- "https://cloud.mycadet.ai",
95
- );
94
+ expect(authHeadersSpy).toHaveBeenCalledWith("test-cloud-token");
96
95
  });
97
96
 
98
97
  test("refreshes the org id cache and retries once on 401", async () => {
@@ -103,10 +102,7 @@ describe("listCloudBackups", () => {
103
102
 
104
103
  expect(result).toEqual([]);
105
104
  expect(fetchCalls).toHaveLength(2);
106
- expect(invalidateOrgIdCacheSpy).toHaveBeenCalledWith(
107
- "test-cloud-token",
108
- "https://cloud.mycadet.ai",
109
- );
105
+ expect(invalidateOrgIdCacheSpy).toHaveBeenCalledWith("test-cloud-token");
110
106
  });
111
107
 
112
108
  test("throws on a persistent error", async () => {
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Pins the environment-to-origin mapping and the `CADET_CLOUD_URL`
3
+ * override in one place. The helper reads `VITE_ENVIRONMENT` and
4
+ * `CADET_ENVIRONMENT` itself — these cases drive both by setting and
5
+ * restoring them.
6
+ */
7
+
8
+ import { afterEach, describe, expect, test } from "bun:test";
9
+
10
+ import { getCloudBaseUrl, SEEDS } from "@mycadet/shared";
11
+
12
+ describe("getCloudBaseUrl", () => {
13
+ const original = {
14
+ vite: process.env.VITE_ENVIRONMENT,
15
+ env: process.env.CADET_ENVIRONMENT,
16
+ cloud: process.env.CADET_CLOUD_URL,
17
+ };
18
+
19
+ const restoreEnv = (name: string, value: string | undefined) => {
20
+ if (value === undefined) delete process.env[name];
21
+ else process.env[name] = value;
22
+ };
23
+
24
+ afterEach(() => {
25
+ restoreEnv("VITE_ENVIRONMENT", original.vite);
26
+ restoreEnv("CADET_ENVIRONMENT", original.env);
27
+ restoreEnv("CADET_CLOUD_URL", original.cloud);
28
+ });
29
+
30
+ test("VITE_ENVIRONMENT picks its own origin (the build-time inlined var)", () => {
31
+ for (const name of ["production", "staging", "dev", "test", "local"]) {
32
+ process.env.VITE_ENVIRONMENT = name;
33
+ delete process.env.CADET_ENVIRONMENT;
34
+ expect(getCloudBaseUrl()).toBe(SEEDS[name].baseUrl);
35
+ }
36
+ });
37
+
38
+ test("CADET_ENVIRONMENT picks its own origin (the runtime var)", () => {
39
+ for (const name of ["production", "staging", "dev", "test", "local"]) {
40
+ process.env.CADET_ENVIRONMENT = name;
41
+ delete process.env.VITE_ENVIRONMENT;
42
+ expect(getCloudBaseUrl()).toBe(SEEDS[name].baseUrl);
43
+ }
44
+ });
45
+
46
+ test("an unknown environment falls back to dev", () => {
47
+ process.env.CADET_ENVIRONMENT = "not-a-seed";
48
+ expect(getCloudBaseUrl()).toBe(SEEDS.dev.baseUrl);
49
+ });
50
+
51
+ test("the explicit CADET_CLOUD_URL override wins", () => {
52
+ process.env.CADET_CLOUD_URL = "https://override.example";
53
+ process.env.CADET_ENVIRONMENT = "dev";
54
+ expect(getCloudBaseUrl()).toBe("https://override.example");
55
+ });
56
+
57
+ test("trims whitespace from CADET_CLOUD_URL", () => {
58
+ process.env.CADET_CLOUD_URL = " https://trimmed.example ";
59
+ expect(getCloudBaseUrl()).toBe("https://trimmed.example");
60
+ });
61
+
62
+ test("an unset environment falls back to dev", () => {
63
+ delete process.env.CADET_ENVIRONMENT;
64
+ delete process.env.VITE_ENVIRONMENT;
65
+ expect(getCloudBaseUrl()).toBe(SEEDS.dev.baseUrl);
66
+ });
67
+ });
@@ -26,7 +26,6 @@ export type EntryOverrides = {
26
26
  containerInfo?: Record<string, unknown>;
27
27
  mgmtSocket?: string;
28
28
  cloudAssistantId?: string;
29
- cloudBaseUrl?: string;
30
29
  cloudOrganizationId?: string;
31
30
  ipAddress?: string;
32
31
  port?: number;
@@ -14,6 +14,7 @@ import {
14
14
  const realCloudAuth = { ...(await import("../cloud-auth")) };
15
15
  const realLoopbackFetch = { ...(await import("../loopback-fetch")) };
16
16
  const realLookup = { ...(await import("../operations/lookup")) };
17
+ const realShared = { ...(await import("@mycadet/shared")) };
17
18
 
18
19
  const fetchMock = mock<
19
20
  (url: string | URL | Request, init?: RequestInit) => Promise<Response>
@@ -30,10 +31,13 @@ let credentialState: {
30
31
  organizationId?: string;
31
32
  } = { token: null, cloudUrl: "https://test-cloud.mycadet.ai" };
32
33
 
34
+ mock.module("@mycadet/shared", () => ({
35
+ ...realShared,
36
+ getCloudBaseUrl: () => credentialState.cloudUrl,
37
+ }));
33
38
  mock.module("../cloud-auth", () => ({
34
39
  ...realCloudAuth,
35
40
  readCloudToken: () => credentialState.token,
36
- resolveCloudUrl: () => credentialState.cloudUrl,
37
41
  authHeadersForKnownOrganization: (token: string, organizationId: string) => ({
38
42
  "X-Session-Token": token,
39
43
  "Cadet-Organization-Id": organizationId,
@@ -141,9 +145,13 @@ describe("the doctor operator rows", () => {
141
145
  async () => new Response("event: status\ndata: {}\n\n"),
142
146
  );
143
147
 
144
- const res = await dial("GET", `/v1/assistants/${ENTRY.assistantId}/doctor/sessions/${SESSION_ID}/events/`, {
145
- headers: { "Last-Event-ID": "evt-9" },
146
- });
148
+ const res = await dial(
149
+ "GET",
150
+ `/v1/assistants/${ENTRY.assistantId}/doctor/sessions/${SESSION_ID}/events/`,
151
+ {
152
+ headers: { "Last-Event-ID": "evt-9" },
153
+ },
154
+ );
147
155
  expect(res?.status).toBe(200);
148
156
 
149
157
  const [url, init] = fetchMock.mock.calls[0] as unknown as [
@@ -169,8 +177,10 @@ describe("the doctor operator rows", () => {
169
177
  `/v1/assistants/${ENTRY.assistantId}/doctor/sessions/${SESSION_ID}/messages/`,
170
178
  { body: JSON.stringify({ content: "hi" }) },
171
179
  );
172
- const [messagesUrl, messagesInit] = fetchMock.mock
173
- .calls[0] as unknown as [string, RequestInit];
180
+ const [messagesUrl, messagesInit] = fetchMock.mock.calls[0] as unknown as [
181
+ string,
182
+ RequestInit,
183
+ ];
174
184
  expect(messagesUrl).toBe(
175
185
  `https://test-cloud.mycadet.ai/v1/assistants/${CLOUD_ASSISTANT_ID}/doctor/sessions/${SESSION_ID}/messages/`,
176
186
  );
@@ -41,7 +41,6 @@ const cloudAuthHeadersMock = mock(async () => ({
41
41
  "Content-Type": "application/json",
42
42
  "X-Session-Token": "session-token",
43
43
  }));
44
- const resolveCloudUrlMock = mock(() => "https://platform.example.test");
45
44
  const retireLocalMock = mock(
46
45
  async (
47
46
  assistantId: string,
@@ -65,7 +64,6 @@ mock.module("../cloud-auth", () => ({
65
64
  readCloudToken: readCloudTokenMock,
66
65
  authHeadersForKnownOrganization: authHeadersForKnownOrganizationMock,
67
66
  cloudAuthHeaders: cloudAuthHeadersMock,
68
- resolveCloudUrl: resolveCloudUrlMock,
69
67
  }));
70
68
  mock.module("../exec", () => ({
71
69
  ...realExec,
@@ -114,12 +112,13 @@ beforeEach(() => {
114
112
  lockfilePath = path.join(tmpDir, "cadet", "lockfile.json");
115
113
  process.env.XDG_CONFIG_HOME = tmpDir;
116
114
  delete process.env.CADET_CLOUD_TOKEN;
115
+ // The cloud URL rides the shared seeds' CADET_CLOUD_URL override.
116
+ process.env.CADET_CLOUD_URL = "https://platform.example.test";
117
117
  for (const m of [
118
118
  loopbackSafeFetchMock,
119
119
  readCloudTokenMock,
120
120
  authHeadersForKnownOrganizationMock,
121
121
  cloudAuthHeadersMock,
122
- resolveCloudUrlMock,
123
122
  retireLocalMock,
124
123
  retireDockerMock,
125
124
  retireAppleContainerMock,
@@ -130,7 +129,6 @@ beforeEach(() => {
130
129
  loopbackSafeFetchMock.mockResolvedValue(new Response(null, { status: 204 }));
131
130
  execMock.mockResolvedValue("");
132
131
  readCloudTokenMock.mockReturnValue(null);
133
- resolveCloudUrlMock.mockReturnValue("https://platform.example.test");
134
132
  authHeadersForKnownOrganizationMock.mockImplementation(
135
133
  (token: string, organizationId: string) => ({
136
134
  "Content-Type": "application/json",
@@ -145,6 +143,7 @@ beforeEach(() => {
145
143
  });
146
144
 
147
145
  afterEach(() => {
146
+ delete process.env.CADET_CLOUD_URL;
148
147
  delete process.env.XDG_CONFIG_HOME;
149
148
  delete process.env.CADET_CLOUD_TOKEN;
150
149
  fs.rmSync(tmpDir, { recursive: true, force: true });
@@ -69,7 +69,6 @@ const cloudAuthHeadersMock = mock(async () => ({
69
69
  "Content-Type": "application/json",
70
70
  "X-Session-Token": "session-token",
71
71
  }));
72
- const resolveCloudUrlMock = mock(() => "https://platform.example.test");
73
72
 
74
73
  mock.module("../loopback-fetch", () => ({
75
74
  ...realLoopbackFetch,
@@ -80,7 +79,6 @@ mock.module("../cloud-auth", () => ({
80
79
  readCloudToken: readCloudTokenMock,
81
80
  authHeadersForKnownOrganization: authHeadersForKnownOrganizationMock,
82
81
  cloudAuthHeaders: cloudAuthHeadersMock,
83
- resolveCloudUrl: resolveCloudUrlMock,
84
82
  }));
85
83
 
86
84
  // Restore the real modules once this file finishes so the mocks above do not
@@ -267,17 +265,16 @@ describe("retireLocal — the self-hosted platform unregister", () => {
267
265
  "Cadet-Organization-Id": organizationId,
268
266
  }),
269
267
  );
270
- resolveCloudUrlMock.mockReset();
271
- resolveCloudUrlMock.mockReturnValue("https://platform.example.test");
272
- delete process.env.CADET_CLOUD_TOKEN;
273
268
  delete process.env.CADET_CLOUD_TOKEN;
269
+ // The cloud URL rides the shared seeds' CADET_CLOUD_URL override.
270
+ process.env.CADET_CLOUD_URL = "https://platform.example.test";
274
271
 
275
272
  rmSync(join(unregisterDir, "retired"), { recursive: true, force: true });
276
273
  });
277
274
 
278
275
  afterAll(() => {
279
276
  delete process.env.CADET_CLOUD_TOKEN;
280
- delete process.env.CADET_CLOUD_TOKEN;
277
+ delete process.env.CADET_CLOUD_URL;
281
278
  if (originalConfigHome === undefined) {
282
279
  delete process.env.XDG_CONFIG_HOME;
283
280
  } else {
@@ -324,10 +321,7 @@ describe("retireLocal — the self-hosted platform unregister", () => {
324
321
 
325
322
  await retireLocal("test-assistant", entry, silentReporter);
326
323
 
327
- expect(cloudAuthHeadersMock).toHaveBeenCalledWith(
328
- "session-token",
329
- "https://platform.example.test",
330
- );
324
+ expect(cloudAuthHeadersMock).toHaveBeenCalledWith("session-token");
331
325
  expect(authHeadersForKnownOrganizationMock).not.toHaveBeenCalled();
332
326
  expect(loopbackSafeFetchMock).toHaveBeenCalledWith(
333
327
  "https://platform.example.test/v1/assistants/cloud-asst-1/retire/",