@mycadet/cli 0.13.0-dev.202611141723.98995ee → 0.13.0-dev.202611141833.f5bfff5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/index.ts +7 -0
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/seeds.ts +167 -19
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/version.ts +4 -25
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/cloud-releases.test.ts +2 -3
- package/node_modules/@mycadet/local-mode/src/__tests__/environment-base-url.test.ts +42 -7
- package/node_modules/@mycadet/local-mode/src/__tests__/environment.test.ts +34 -40
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-resolution.test.ts +25 -2
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-hatch.test.ts +2 -2
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-statefulset.test.ts +8 -6
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-common-ces.test.ts +2 -2
- package/node_modules/@mycadet/local-mode/src/__tests__/upgrade-replay-env.test.ts +6 -42
- package/node_modules/@mycadet/local-mode/src/config.ts +1 -2
- package/node_modules/@mycadet/local-mode/src/environment.ts +7 -91
- package/node_modules/@mycadet/local-mode/src/exec.ts +6 -0
- package/node_modules/@mycadet/local-mode/src/guardian-token.ts +19 -81
- package/node_modules/@mycadet/local-mode/src/index.ts +3 -2
- package/node_modules/@mycadet/local-mode/src/operations/routes.ts +46 -33
- package/node_modules/@mycadet/local-mode/src/ports.ts +1 -2
- package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +2 -6
- package/node_modules/@mycadet/local-mode/src/remotes/docker/statefulset.ts +8 -31
- package/node_modules/@mycadet/local-mode/src/remotes/docker/upgrade.ts +2 -9
- package/node_modules/@mycadet/local-mode/src/remotes/docker/wake.ts +0 -3
- package/node_modules/@mycadet/local-mode/src/remotes/docker/watch.ts +0 -2
- package/node_modules/@mycadet/local-mode/src/remotes/local/common.ts +21 -68
- package/node_modules/@mycadet/local-mode/src/remotes/local/upgrade.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/upgrade-lifecycle.ts +5 -14
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/index.ts +7 -0
- package/node_modules/@mycadet/shared/package.json +1 -1
- package/node_modules/@mycadet/shared/seeds.ts +167 -19
- package/node_modules/@mycadet/shared/version.ts +4 -25
- package/package.json +1 -1
- package/src/commands/ps.ts +63 -26
- package/src/index.ts +9 -1
- package/src/lib/guardian-token.ts +21 -10
- package/src/lib/servers/bun.ts +15 -15
|
@@ -4,8 +4,15 @@ export {
|
|
|
4
4
|
} from "./github-repository.js";
|
|
5
5
|
export {
|
|
6
6
|
DEFAULT_APP_SERVER_PORT,
|
|
7
|
+
environmentFromVersion,
|
|
7
8
|
getCloudBaseUrl,
|
|
9
|
+
isDevVersion,
|
|
10
|
+
isLocalVersion,
|
|
11
|
+
isStagingVersion,
|
|
12
|
+
resolveEnvironmentName,
|
|
8
13
|
SEEDS,
|
|
14
|
+
CADET_ENVIRONMENT_NAMES,
|
|
15
|
+
type CadetEnvironment,
|
|
9
16
|
type EnvironmentDefinition,
|
|
10
17
|
type PortMap,
|
|
11
18
|
} from "./seeds.js";
|
|
@@ -30,12 +30,11 @@ export const DEFAULT_APP_SERVER_PORT = 7840;
|
|
|
30
30
|
/**
|
|
31
31
|
* A resolved environment definition. Required fields are `name` and
|
|
32
32
|
* `baseUrl`. All other fields are optional and declared upfront — new
|
|
33
|
-
* fields are additive, never breaking. `name` is
|
|
34
|
-
*
|
|
35
|
-
* future layers (user config file, ad-hoc env vars, etc.).
|
|
33
|
+
* fields are additive, never breaking. `name` is a `CadetEnvironment`: a
|
|
34
|
+
* definition outside the known names has nowhere to key into.
|
|
36
35
|
*/
|
|
37
36
|
export interface EnvironmentDefinition {
|
|
38
|
-
name:
|
|
37
|
+
name: CadetEnvironment;
|
|
39
38
|
|
|
40
39
|
/**
|
|
41
40
|
* The single origin for API, auth, web, and the assistant mount — one
|
|
@@ -90,26 +89,175 @@ function portBlock(base: number): PortMap {
|
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
/**
|
|
93
|
-
* The
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
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.
|
|
92
|
+
* The set of environment names every surface shares — the seeds below are
|
|
93
|
+
* exactly these five. Lockfiles, config directories, release channels, and
|
|
94
|
+
* the mobile shells' scheme keys all key off this union, so a name outside
|
|
95
|
+
* it is a bug the compiler can catch.
|
|
99
96
|
*/
|
|
100
|
-
export
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
export const CADET_ENVIRONMENT_NAMES = [
|
|
98
|
+
"local",
|
|
99
|
+
"dev",
|
|
100
|
+
"staging",
|
|
101
|
+
"production",
|
|
102
|
+
"test",
|
|
103
|
+
] as const;
|
|
104
|
+
|
|
105
|
+
export type CadetEnvironment = (typeof CADET_ENVIRONMENT_NAMES)[number];
|
|
106
|
+
|
|
107
|
+
function isCadetEnvironment(
|
|
108
|
+
name: string | undefined,
|
|
109
|
+
): name is CadetEnvironment {
|
|
110
|
+
return (
|
|
111
|
+
typeof name === "string" &&
|
|
112
|
+
(CADET_ENVIRONMENT_NAMES as readonly string[]).includes(name)
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* globalThis.process reads the same env under bun/node while staying
|
|
118
|
+
* crash-free in browser bundles (no bare `process` reference) — and free
|
|
119
|
+
* of import-meta syntax, which the Capacitor config loader can't transpile.
|
|
120
|
+
*/
|
|
121
|
+
function processEnv(): Record<string, string | undefined> | undefined {
|
|
122
|
+
return (
|
|
105
123
|
globalThis as unknown as {
|
|
106
124
|
process?: { env?: Record<string, string | undefined> };
|
|
107
125
|
}
|
|
108
126
|
).process?.env;
|
|
109
|
-
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Whether a version string denotes a dev build from the dev-release
|
|
131
|
+
* pipeline, e.g. `0.12.6-dev.202610081023.3a27b77`.
|
|
132
|
+
*/
|
|
133
|
+
export function isDevVersion(version: string): boolean {
|
|
134
|
+
return /-dev\./i.test(version);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether a version string denotes a staging build, e.g. `0.6.0-staging.3`.
|
|
139
|
+
*/
|
|
140
|
+
export function isStagingVersion(version: string): boolean {
|
|
141
|
+
return /-staging\./i.test(version);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Whether a version string denotes a local build, e.g. `0.12.6-local.42`.
|
|
146
|
+
* Local builds are never published.
|
|
147
|
+
*/
|
|
148
|
+
export function isLocalVersion(version: string): boolean {
|
|
149
|
+
return /-local\./i.test(version);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The environment a released channel version pins, or `undefined` when the
|
|
154
|
+
* version carries no channel suffix. A plain version — a workspace
|
|
155
|
+
* checkout's unstamped package version — reads as "no version signal",
|
|
156
|
+
* leaving the remaining steps to decide. Mirrors the CLI resolver's mapping
|
|
157
|
+
* (local, dev, staging).
|
|
158
|
+
*/
|
|
159
|
+
export function environmentFromVersion(
|
|
160
|
+
version: string | undefined,
|
|
161
|
+
): CadetEnvironment | undefined {
|
|
162
|
+
if (isLocalVersion(version ?? "")) return "local";
|
|
163
|
+
if (isDevVersion(version ?? "")) return "dev";
|
|
164
|
+
if (isStagingVersion(version ?? "")) return "staging";
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Read the persisted default environment — the file pre-version-tied CLIs
|
|
170
|
+
* wrote so their successors honor the machine's chosen default. Node-only
|
|
171
|
+
* and resolved at call time (`process.getBuiltinModule`), so this file
|
|
172
|
+
* keeps zero static node imports: the Capacitor config loader transpiles it
|
|
173
|
+
* standalone and a static node import would die there, while browser
|
|
174
|
+
* bundles (chrome extension, web renderer) never reach the call.
|
|
175
|
+
*/
|
|
176
|
+
function readPersistedDefault(): CadetEnvironment | undefined {
|
|
177
|
+
const node = process as unknown as {
|
|
178
|
+
getBuiltinModule?: (id: string) => unknown;
|
|
179
|
+
platform: string;
|
|
180
|
+
};
|
|
181
|
+
const fs = node.getBuiltinModule?.("node:fs") as
|
|
182
|
+
| typeof import("node:fs")
|
|
183
|
+
| undefined;
|
|
184
|
+
const os = node.getBuiltinModule?.("node:os") as
|
|
185
|
+
| typeof import("node:os")
|
|
186
|
+
| undefined;
|
|
187
|
+
const path = node.getBuiltinModule?.("node:path") as
|
|
188
|
+
| typeof import("node:path")
|
|
189
|
+
| undefined;
|
|
190
|
+
if (!fs || !os || !path) return undefined;
|
|
191
|
+
|
|
192
|
+
// Mirrors local-mode's resolveConfigHome (the same XDG/AppData derivation).
|
|
193
|
+
const isWindows = node.platform === "win32";
|
|
194
|
+
const join = isWindows ? path.win32.join : path.posix.join;
|
|
195
|
+
const configHome = isWindows
|
|
196
|
+
? process.env.APPDATA?.trim() || join(os.homedir(), "AppData", "Roaming")
|
|
197
|
+
: process.env.XDG_CONFIG_HOME?.trim() || join(os.homedir(), ".config");
|
|
198
|
+
const filePath = join(configHome, "cadet", "environment");
|
|
199
|
+
try {
|
|
200
|
+
if (!fs.existsSync(filePath)) return undefined;
|
|
201
|
+
const content = fs.readFileSync(filePath, "utf-8").trim();
|
|
202
|
+
return isCadetEnvironment(content) ? content : undefined;
|
|
203
|
+
} catch {
|
|
204
|
+
// Unreadable file — no default.
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The environment name every surface shares — the single resolution chain
|
|
211
|
+
* local-mode hosts and the mobile config loader both ride:
|
|
212
|
+
*
|
|
213
|
+
* 1. `CADET_ENVIRONMENT` (explicit override, also inherited by the
|
|
214
|
+
* hatch/retire child processes the CLI spawns), then
|
|
215
|
+
* `VITE_ENVIRONMENT` (the build-time inlined var bundled surfaces bake)
|
|
216
|
+
* 2. the release channel the running copy's version carries —
|
|
217
|
+
* `__CADET_OWN_VERSION__`, which the entrypoints that know their
|
|
218
|
+
* package root inject (the CLI's bin computes its git/local stamp,
|
|
219
|
+
* the Electron builds define it at build time). A released `-dev.`
|
|
220
|
+
* install resolves `dev` even on a machine that never wrote a
|
|
221
|
+
* persisted default
|
|
222
|
+
* 3. the persisted default written by pre-version-tied CLIs (old files
|
|
223
|
+
* are still honored)
|
|
224
|
+
* 4. `production`
|
|
225
|
+
*
|
|
226
|
+
* The version step is what keeps every released install from silently
|
|
227
|
+
* reading production's state: the channel is decided by the release
|
|
228
|
+
* pipeline, not by whatever default an older CLI happened to leave behind.
|
|
229
|
+
* Names outside `CadetEnvironment` are ignored rather than returned: an
|
|
230
|
+
* unrecognized value falls through to the next arm instead of leaking an
|
|
231
|
+
* unkeyable string into `SEEDS` lookups.
|
|
232
|
+
*/
|
|
233
|
+
export function resolveEnvironmentName(): CadetEnvironment {
|
|
234
|
+
const env = processEnv();
|
|
235
|
+
const named = [
|
|
236
|
+
env?.CADET_ENVIRONMENT?.trim(),
|
|
237
|
+
env?.VITE_ENVIRONMENT?.trim(),
|
|
238
|
+
].find(isCadetEnvironment);
|
|
239
|
+
if (named) return named;
|
|
240
|
+
return (
|
|
241
|
+
environmentFromVersion(
|
|
242
|
+
(globalThis as { __CADET_OWN_VERSION__?: string }).__CADET_OWN_VERSION__,
|
|
243
|
+
) ??
|
|
244
|
+
readPersistedDefault() ??
|
|
245
|
+
"production"
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* The base URL of Cadet Cloud — the hosted deployment the local surfaces
|
|
251
|
+
* pair with (API, auth, web, and the assistant mount all live on it). The
|
|
252
|
+
* explicit `CADET_CLOUD_URL` override wins, else the seed of
|
|
253
|
+
* `resolveEnvironmentName`. This says "cloud" because the URL always points
|
|
254
|
+
* at a Cadet Cloud deployment, never at something that represents this
|
|
255
|
+
* surface itself.
|
|
256
|
+
*/
|
|
257
|
+
export function getCloudBaseUrl(): string {
|
|
258
|
+
const explicit = processEnv()?.CADET_CLOUD_URL?.trim();
|
|
110
259
|
if (explicit) return explicit;
|
|
111
|
-
|
|
112
|
-
return ((envName && SEEDS[envName]) || SEEDS.dev).baseUrl;
|
|
260
|
+
return SEEDS[resolveEnvironmentName()].baseUrl;
|
|
113
261
|
}
|
|
114
262
|
|
|
115
263
|
/**
|
|
@@ -120,7 +268,7 @@ export function getCloudBaseUrl(): string {
|
|
|
120
268
|
* "Coexisting environments" design doc. Until then, a call site that needs a
|
|
121
269
|
* new environment must add it here and rebuild.
|
|
122
270
|
*/
|
|
123
|
-
export const SEEDS: Record<
|
|
271
|
+
export const SEEDS: Record<CadetEnvironment, EnvironmentDefinition> = {
|
|
124
272
|
production: {
|
|
125
273
|
name: "production",
|
|
126
274
|
baseUrl: "https://mycadet.ai",
|
|
@@ -7,7 +7,8 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
* The version string a source checkout reports for `--version`.
|
|
8
8
|
*
|
|
9
9
|
* Released CLIs carry their channel in the version itself (`-dev.`,
|
|
10
|
-
* `-staging.`, nothing for production —
|
|
10
|
+
* `-staging.`, nothing for production — the channel mapping lives with the
|
|
11
|
+
* environment resolver (`environmentFromVersion` in shared/seeds). A
|
|
11
12
|
* source checkout reads the static version from package.json, which made
|
|
12
13
|
* `cadet-local --version` indistinguishable from a production install. This
|
|
13
14
|
* stamps a `-local.` postfix using the exact dev-release format
|
|
@@ -50,7 +51,8 @@ function isSourceCheckout(entryPath: string): boolean {
|
|
|
50
51
|
* Bun, Node, and bundled evaluation all resolve it to this file on disk.
|
|
51
52
|
*/
|
|
52
53
|
function moduleEntryPath(): string {
|
|
53
|
-
if (typeof import.meta.url === "string")
|
|
54
|
+
if (typeof import.meta.url === "string")
|
|
55
|
+
return fileURLToPath(import.meta.url);
|
|
54
56
|
return import.meta.path;
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -120,26 +122,3 @@ export function resolveVersion(packageRoot: string = process.cwd()): string {
|
|
|
120
122
|
if ((process.env.CADET_ENVIRONMENT || "local") !== "local") return base;
|
|
121
123
|
return stampedVersion(base, new Date(), moduleEntryPath());
|
|
122
124
|
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Whether a version string denotes a dev build from the dev-release
|
|
126
|
-
* pipeline, e.g. `0.12.6-dev.202610081023.3a27b77`.
|
|
127
|
-
*/
|
|
128
|
-
export function isDevVersion(version: string): boolean {
|
|
129
|
-
return /-dev\./i.test(version);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Whether a version string denotes a staging build, e.g. `0.6.0-staging.3`.
|
|
134
|
-
*/
|
|
135
|
-
export function isStagingVersion(version: string): boolean {
|
|
136
|
-
return /-staging\./i.test(version);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Whether a version string denotes a local build, e.g. `0.12.6-local.42`.
|
|
141
|
-
* Local builds are never published.
|
|
142
|
-
*/
|
|
143
|
-
export function isLocalVersion(version: string): boolean {
|
|
144
|
-
return /-local\./i.test(version);
|
|
145
|
-
}
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
isDevVersion,
|
|
7
7
|
isLocalVersion,
|
|
8
8
|
isStagingVersion,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { CADET_GITHUB_REPOSITORY } from "@mycadet/shared";
|
|
9
|
+
CADET_GITHUB_REPOSITORY,
|
|
10
|
+
} from "@mycadet/shared";
|
|
12
11
|
|
|
13
12
|
const originalFetch = globalThis.fetch;
|
|
14
13
|
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* restoring them.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { afterEach, describe, expect, test } from "bun:test";
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
9
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
+
import os from "node:os";
|
|
11
|
+
import path from "node:path";
|
|
9
12
|
|
|
10
13
|
import { getCloudBaseUrl, SEEDS } from "@mycadet/shared";
|
|
11
14
|
|
|
@@ -14,6 +17,9 @@ describe("getCloudBaseUrl", () => {
|
|
|
14
17
|
vite: process.env.VITE_ENVIRONMENT,
|
|
15
18
|
env: process.env.CADET_ENVIRONMENT,
|
|
16
19
|
cloud: process.env.CADET_CLOUD_URL,
|
|
20
|
+
xdg: process.env.XDG_CONFIG_HOME,
|
|
21
|
+
version: (globalThis as { __CADET_OWN_VERSION__?: string })
|
|
22
|
+
.__CADET_OWN_VERSION__,
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
const restoreEnv = (name: string, value: string | undefined) => {
|
|
@@ -21,14 +27,37 @@ describe("getCloudBaseUrl", () => {
|
|
|
21
27
|
else process.env[name] = value;
|
|
22
28
|
};
|
|
23
29
|
|
|
30
|
+
let configHome: string;
|
|
31
|
+
|
|
32
|
+
// The persisted-default arm reads the config home; pin it to a temp dir so
|
|
33
|
+
// this file never consults the real ~/.config. The version global is
|
|
34
|
+
// pinned to a plain version so the channel arm stays silent and the
|
|
35
|
+
// fallback expectations below are deterministic.
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
configHome = mkdtempSync(path.join(os.tmpdir(), "cadet-cloud-url-"));
|
|
38
|
+
process.env.XDG_CONFIG_HOME = configHome;
|
|
39
|
+
(globalThis as { __CADET_OWN_VERSION__?: string }).__CADET_OWN_VERSION__ =
|
|
40
|
+
"0.0.1";
|
|
41
|
+
});
|
|
42
|
+
|
|
24
43
|
afterEach(() => {
|
|
44
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
25
45
|
restoreEnv("VITE_ENVIRONMENT", original.vite);
|
|
26
46
|
restoreEnv("CADET_ENVIRONMENT", original.env);
|
|
27
47
|
restoreEnv("CADET_CLOUD_URL", original.cloud);
|
|
48
|
+
restoreEnv("XDG_CONFIG_HOME", original.xdg);
|
|
49
|
+
(globalThis as { __CADET_OWN_VERSION__?: string }).__CADET_OWN_VERSION__ =
|
|
50
|
+
original.version;
|
|
28
51
|
});
|
|
29
52
|
|
|
30
53
|
test("VITE_ENVIRONMENT picks its own origin (the build-time inlined var)", () => {
|
|
31
|
-
for (const name of [
|
|
54
|
+
for (const name of [
|
|
55
|
+
"production",
|
|
56
|
+
"staging",
|
|
57
|
+
"dev",
|
|
58
|
+
"test",
|
|
59
|
+
"local",
|
|
60
|
+
] as const) {
|
|
32
61
|
process.env.VITE_ENVIRONMENT = name;
|
|
33
62
|
delete process.env.CADET_ENVIRONMENT;
|
|
34
63
|
expect(getCloudBaseUrl()).toBe(SEEDS[name].baseUrl);
|
|
@@ -36,16 +65,22 @@ describe("getCloudBaseUrl", () => {
|
|
|
36
65
|
});
|
|
37
66
|
|
|
38
67
|
test("CADET_ENVIRONMENT picks its own origin (the runtime var)", () => {
|
|
39
|
-
for (const name of [
|
|
68
|
+
for (const name of [
|
|
69
|
+
"production",
|
|
70
|
+
"staging",
|
|
71
|
+
"dev",
|
|
72
|
+
"test",
|
|
73
|
+
"local",
|
|
74
|
+
] as const) {
|
|
40
75
|
process.env.CADET_ENVIRONMENT = name;
|
|
41
76
|
delete process.env.VITE_ENVIRONMENT;
|
|
42
77
|
expect(getCloudBaseUrl()).toBe(SEEDS[name].baseUrl);
|
|
43
78
|
}
|
|
44
79
|
});
|
|
45
80
|
|
|
46
|
-
test("an unknown environment falls
|
|
81
|
+
test("an unknown environment falls through to production", () => {
|
|
47
82
|
process.env.CADET_ENVIRONMENT = "not-a-seed";
|
|
48
|
-
expect(getCloudBaseUrl()).toBe(SEEDS.
|
|
83
|
+
expect(getCloudBaseUrl()).toBe(SEEDS.production.baseUrl);
|
|
49
84
|
});
|
|
50
85
|
|
|
51
86
|
test("the explicit CADET_CLOUD_URL override wins", () => {
|
|
@@ -59,9 +94,9 @@ describe("getCloudBaseUrl", () => {
|
|
|
59
94
|
expect(getCloudBaseUrl()).toBe("https://trimmed.example");
|
|
60
95
|
});
|
|
61
96
|
|
|
62
|
-
test("an unset environment
|
|
97
|
+
test("an unset environment resolves production", () => {
|
|
63
98
|
delete process.env.CADET_ENVIRONMENT;
|
|
64
99
|
delete process.env.VITE_ENVIRONMENT;
|
|
65
|
-
expect(getCloudBaseUrl()).toBe(SEEDS.
|
|
100
|
+
expect(getCloudBaseUrl()).toBe(SEEDS.production.baseUrl);
|
|
66
101
|
});
|
|
67
102
|
});
|
|
@@ -4,11 +4,9 @@ import os from "node:os";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
defaultEnvironmentFilePath,
|
|
8
7
|
environmentFromVersion,
|
|
9
|
-
readDefaultEnvironment,
|
|
10
8
|
resolveEnvironmentName,
|
|
11
|
-
} from "
|
|
9
|
+
} from "@mycadet/shared/seeds";
|
|
12
10
|
import {
|
|
13
11
|
guardianTokenPath,
|
|
14
12
|
resolveConfigDir,
|
|
@@ -31,6 +29,7 @@ const RESOLUTION_ENV_KEYS = [
|
|
|
31
29
|
"APPDATA",
|
|
32
30
|
"LOCALAPPDATA",
|
|
33
31
|
"CADET_ENVIRONMENT",
|
|
32
|
+
"VITE_ENVIRONMENT",
|
|
34
33
|
] as const;
|
|
35
34
|
|
|
36
35
|
const savedEnv = new Map<string, string | undefined>();
|
|
@@ -69,39 +68,6 @@ afterEach(() => {
|
|
|
69
68
|
savedEnv.clear();
|
|
70
69
|
});
|
|
71
70
|
|
|
72
|
-
describe("defaultEnvironmentFilePath", () => {
|
|
73
|
-
test("honors XDG_CONFIG_HOME", () => {
|
|
74
|
-
expect(defaultEnvironmentFilePath()).toBe(
|
|
75
|
-
path.join(configHome, "cadet", "environment"),
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test("falls back to ~/.config when XDG_CONFIG_HOME is unset", () => {
|
|
80
|
-
Reflect.deleteProperty(process.env, "XDG_CONFIG_HOME");
|
|
81
|
-
expect(defaultEnvironmentFilePath()).toBe(
|
|
82
|
-
path.join(os.homedir(), ".config", "cadet", "environment"),
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe("readDefaultEnvironment", () => {
|
|
88
|
-
test("returns undefined when no file exists", () => {
|
|
89
|
-
expect(readDefaultEnvironment()).toBeUndefined();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("returns the trimmed persisted name", () => {
|
|
93
|
-
persistDefault("dev");
|
|
94
|
-
expect(readDefaultEnvironment()).toBe("dev");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
test("treats an empty file as no default", () => {
|
|
98
|
-
const file = path.join(configHome, "cadet", "environment");
|
|
99
|
-
mkdirSync(path.dirname(file), { recursive: true });
|
|
100
|
-
writeFileSync(file, " \n", "utf-8");
|
|
101
|
-
expect(readDefaultEnvironment()).toBeUndefined();
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
71
|
describe("environmentFromVersion", () => {
|
|
106
72
|
test("maps the release channels like the CLI resolver does", () => {
|
|
107
73
|
expect(environmentFromVersion("0.12.6-local.42")).toBe("local");
|
|
@@ -134,12 +100,44 @@ describe("resolveEnvironmentName", () => {
|
|
|
134
100
|
expect(resolveEnvironmentName()).toBe("dev");
|
|
135
101
|
});
|
|
136
102
|
|
|
103
|
+
test("treats an empty persisted file as no default", () => {
|
|
104
|
+
(globalThis as { __CADET_OWN_VERSION__?: string }).__CADET_OWN_VERSION__ =
|
|
105
|
+
"0.0.1";
|
|
106
|
+
const file = path.join(configHome, "cadet", "environment");
|
|
107
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
108
|
+
writeFileSync(file, " \n", "utf-8");
|
|
109
|
+
expect(resolveEnvironmentName()).toBe("production");
|
|
110
|
+
});
|
|
111
|
+
|
|
137
112
|
test("falls back to production when nothing pins an environment", () => {
|
|
138
113
|
// Stable installed copy: plain version, no persisted default.
|
|
139
114
|
(globalThis as { __CADET_OWN_VERSION__?: string }).__CADET_OWN_VERSION__ =
|
|
140
115
|
"0.0.1";
|
|
141
116
|
expect(resolveEnvironmentName()).toBe("production");
|
|
142
117
|
});
|
|
118
|
+
|
|
119
|
+
test("prefers VITE_ENVIRONMENT when CADET_ENVIRONMENT is unset", () => {
|
|
120
|
+
process.env.VITE_ENVIRONMENT = "staging";
|
|
121
|
+
expect(resolveEnvironmentName()).toBe("staging");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("ignores an unknown CADET_ENVIRONMENT and falls through the chain", () => {
|
|
125
|
+
// The typed contract: a name outside the union is never returned — the
|
|
126
|
+
// remaining arms decide.
|
|
127
|
+
process.env.CADET_ENVIRONMENT = "not-a-seed";
|
|
128
|
+
persistDefault("dev");
|
|
129
|
+
expect(resolveEnvironmentName()).toBe("dev");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the version channel beats the persisted default", () => {
|
|
133
|
+
const globalWithVersion = globalThis as {
|
|
134
|
+
__CADET_OWN_VERSION__?: string;
|
|
135
|
+
};
|
|
136
|
+
globalWithVersion.__CADET_OWN_VERSION__ = "0.12.6-dev.202610081023.3a27b77";
|
|
137
|
+
persistDefault("staging");
|
|
138
|
+
expect(resolveEnvironmentName()).toBe("dev");
|
|
139
|
+
delete globalWithVersion.__CADET_OWN_VERSION__;
|
|
140
|
+
});
|
|
143
141
|
});
|
|
144
142
|
|
|
145
143
|
describe("path resolvers honor the persisted default", () => {
|
|
@@ -185,7 +183,6 @@ describe("Windows path resolution", () => {
|
|
|
185
183
|
|
|
186
184
|
test("uses AppData", () => {
|
|
187
185
|
const paths = [
|
|
188
|
-
[defaultEnvironmentFilePath(), "AppData\\Roaming\\cadet\\environment"],
|
|
189
186
|
[resolveConfigDir(), "AppData\\Roaming\\cadet-dev"],
|
|
190
187
|
[resolveDataDir(), "AppData\\Local\\cadet-dev"],
|
|
191
188
|
[resolveLogDir(), "AppData\\Local\\cadet-dev\\logs"],
|
|
@@ -207,9 +204,6 @@ describe("Windows path resolution", () => {
|
|
|
207
204
|
expect(resolveLockfilePath()).toBe(
|
|
208
205
|
"C:\\Users\\Example\\AppData\\Roaming\\cadet\\lockfile.json",
|
|
209
206
|
);
|
|
210
|
-
expect(defaultEnvironmentFilePath()).toBe(
|
|
211
|
-
"C:\\Users\\Example\\AppData\\Roaming\\cadet\\environment",
|
|
212
|
-
);
|
|
213
207
|
});
|
|
214
208
|
|
|
215
209
|
test("rejects unsafe path segments", () => {
|
|
@@ -125,6 +125,24 @@ describe("matchOperatorRequest — the four prefixes", () => {
|
|
|
125
125
|
}
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
test("every route answers both trailing-slash spellings", () => {
|
|
129
|
+
// Helper 1 owns the trailing slash and makes it optional — the bare
|
|
130
|
+
// spellings match the same rows their slashed forms do. The list row
|
|
131
|
+
// previously REQUIRED the slash, so the bare /v1/assistants fell
|
|
132
|
+
// through to the static surface's 404.
|
|
133
|
+
for (const requestPath of ["/v1/assistants", "/v1/assistants/"]) {
|
|
134
|
+
expect(matchOperatorRequest(requestPath, "GET")).not.toBeNull();
|
|
135
|
+
}
|
|
136
|
+
for (const requestPath of [
|
|
137
|
+
"/v1/devices",
|
|
138
|
+
"/v1/devices/",
|
|
139
|
+
"/v1/remote-web/pairing-start",
|
|
140
|
+
"/v1/remote-web/pairing-start/",
|
|
141
|
+
]) {
|
|
142
|
+
expect(matchOperatorRequest(requestPath, "POST")).not.toBeNull();
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
128
146
|
test("a scoped match carries the decoded id; an unscoped one names the active entry", () => {
|
|
129
147
|
writeLockfile({
|
|
130
148
|
assistants: [
|
|
@@ -160,14 +178,19 @@ describe("matchOperatorRequest — the four prefixes", () => {
|
|
|
160
178
|
const derived = route.pattern.source;
|
|
161
179
|
if (derived.includes("(?<id>")) {
|
|
162
180
|
// An assistant row: helper 2's id capture plus helper 1's required
|
|
163
|
-
// version arm.
|
|
181
|
+
// version arm. Rows declare relative patterns, so the scoping arm
|
|
182
|
+
// carries no leading slash.
|
|
164
183
|
expect(derived).toContain("(?:\\/v1|\\/api)");
|
|
165
|
-
expect(derived).toContain("
|
|
184
|
+
expect(derived).toContain("|assistant");
|
|
166
185
|
} else {
|
|
167
186
|
// An absolute row: helper 1's required version arm, no scoping.
|
|
168
187
|
expect(derived).toContain("(?:\\/v1|\\/api)");
|
|
169
188
|
expect(derived).not.toContain("(?<id>");
|
|
170
189
|
}
|
|
190
|
+
// Helper 1 owns the slashes: every row ends in the optional trailing
|
|
191
|
+
// one, and none spells a slash of its own.
|
|
192
|
+
expect(derived.endsWith("\\/?$")).toBe(true);
|
|
193
|
+
expect(derived).not.toContain("\\/?$\\/");
|
|
171
194
|
}
|
|
172
195
|
});
|
|
173
196
|
});
|
|
@@ -82,14 +82,14 @@ describe("buildServiceRunArgs — assistant", () => {
|
|
|
82
82
|
test("keeps existing workspace and socket volume mounts intact", () => {
|
|
83
83
|
const args = buildAssistantArgs();
|
|
84
84
|
expect(args).toContain(`${instanceName}-workspace:/workspace`);
|
|
85
|
-
expect(args).toContain(`${instanceName}-socket:/run/ces-
|
|
85
|
+
expect(args).toContain(`${instanceName}-socket:/run/ces-ipc`);
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
test("preserves existing required env vars", () => {
|
|
89
89
|
const args = buildAssistantArgs();
|
|
90
90
|
expect(args).toContain("IS_CONTAINERIZED=true");
|
|
91
91
|
expect(args).toContain("CADET_WORKSPACE_DIR=/workspace");
|
|
92
|
-
expect(args).toContain("
|
|
92
|
+
expect(args).toContain("CES_SOCKET_DIR=/run/ces-ipc");
|
|
93
93
|
expect(args).toContain(`CADET_ASSISTANT_NAME=${instanceName}`);
|
|
94
94
|
});
|
|
95
95
|
|