@mycadet/cli 0.13.0-dev.202611141723.98995ee → 0.13.0-dev.202611141959.760a53b
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/assistant-api/node_modules/@mycadet/service-contracts/src/rpc.ts +33 -3
- 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/service-contracts/src/rpc.ts +33 -3
- 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__/remotes-local-pair.test.ts +3 -1
- 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/pair.ts +8 -1
- 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 +17 -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/service-contracts/src/rpc.ts +33 -3
- 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
package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/src/rpc.ts
CHANGED
|
@@ -55,6 +55,8 @@ export const CesRpcMethod = {
|
|
|
55
55
|
ListCredentialRecords: "list_credential_records",
|
|
56
56
|
/** Bulk-import credential records. */
|
|
57
57
|
BulkSetCredentialRecords: "bulk_set_credential_records",
|
|
58
|
+
/** Collect CES's own log files for a diagnostic export (tar.gz, base64). */
|
|
59
|
+
ExportLogs: "export_logs",
|
|
58
60
|
} as const;
|
|
59
61
|
|
|
60
62
|
export type CesRpcMethod = (typeof CesRpcMethod)[keyof typeof CesRpcMethod];
|
|
@@ -72,9 +74,7 @@ export const UpdateCloudCredentialSchema = z.object({
|
|
|
72
74
|
*/
|
|
73
75
|
assistantId: z.string().optional(),
|
|
74
76
|
});
|
|
75
|
-
export type UpdateCloudCredential = z.infer<
|
|
76
|
-
typeof UpdateCloudCredentialSchema
|
|
77
|
-
>;
|
|
77
|
+
export type UpdateCloudCredential = z.infer<typeof UpdateCloudCredentialSchema>;
|
|
78
78
|
|
|
79
79
|
export const UpdateCloudCredentialResponseSchema = z.object({
|
|
80
80
|
/** Whether the cloud credential was successfully updated. */
|
|
@@ -302,6 +302,28 @@ export type BulkSetCredentialRecordsResponse = z.infer<
|
|
|
302
302
|
typeof BulkSetCredentialRecordsResponseSchema
|
|
303
303
|
>;
|
|
304
304
|
|
|
305
|
+
// ---------------------------------------------------------------------------
|
|
306
|
+
// export_logs
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
|
|
309
|
+
export const ExportLogsSchema = z.object({
|
|
310
|
+
/** Inclusive range start (epoch ms); log files entirely before it are skipped. */
|
|
311
|
+
startTime: z.number().optional(),
|
|
312
|
+
/** Inclusive range end (epoch ms); log files entirely after it are skipped. */
|
|
313
|
+
endTime: z.number().optional(),
|
|
314
|
+
});
|
|
315
|
+
export type ExportLogs = z.infer<typeof ExportLogsSchema>;
|
|
316
|
+
|
|
317
|
+
export const ExportLogsResponseSchema = z.object({
|
|
318
|
+
/** tar.gz of the collected log files plus a manifest, base64-encoded. */
|
|
319
|
+
archiveBase64: z.string(),
|
|
320
|
+
/** Number of log files included in the archive. */
|
|
321
|
+
filesCollected: z.number(),
|
|
322
|
+
/** Cumulative size of the collected log files, before archiving. */
|
|
323
|
+
totalBytes: z.number(),
|
|
324
|
+
});
|
|
325
|
+
export type ExportLogsResponse = z.infer<typeof ExportLogsResponseSchema>;
|
|
326
|
+
|
|
305
327
|
// ---------------------------------------------------------------------------
|
|
306
328
|
// Full RPC contract type map
|
|
307
329
|
// ---------------------------------------------------------------------------
|
|
@@ -355,6 +377,10 @@ export interface CesRpcContract {
|
|
|
355
377
|
request: BulkSetCredentialRecords;
|
|
356
378
|
response: BulkSetCredentialRecordsResponse;
|
|
357
379
|
};
|
|
380
|
+
[CesRpcMethod.ExportLogs]: {
|
|
381
|
+
request: ExportLogs;
|
|
382
|
+
response: ExportLogsResponse;
|
|
383
|
+
};
|
|
358
384
|
}
|
|
359
385
|
|
|
360
386
|
/**
|
|
@@ -405,4 +431,8 @@ export const CesRpcSchemas = {
|
|
|
405
431
|
request: BulkSetCredentialRecordsSchema,
|
|
406
432
|
response: BulkSetCredentialRecordsResponseSchema,
|
|
407
433
|
},
|
|
434
|
+
[CesRpcMethod.ExportLogs]: {
|
|
435
|
+
request: ExportLogsSchema,
|
|
436
|
+
response: ExportLogsResponseSchema,
|
|
437
|
+
},
|
|
408
438
|
} as const;
|
|
@@ -55,6 +55,8 @@ export const CesRpcMethod = {
|
|
|
55
55
|
ListCredentialRecords: "list_credential_records",
|
|
56
56
|
/** Bulk-import credential records. */
|
|
57
57
|
BulkSetCredentialRecords: "bulk_set_credential_records",
|
|
58
|
+
/** Collect CES's own log files for a diagnostic export (tar.gz, base64). */
|
|
59
|
+
ExportLogs: "export_logs",
|
|
58
60
|
} as const;
|
|
59
61
|
|
|
60
62
|
export type CesRpcMethod = (typeof CesRpcMethod)[keyof typeof CesRpcMethod];
|
|
@@ -72,9 +74,7 @@ export const UpdateCloudCredentialSchema = z.object({
|
|
|
72
74
|
*/
|
|
73
75
|
assistantId: z.string().optional(),
|
|
74
76
|
});
|
|
75
|
-
export type UpdateCloudCredential = z.infer<
|
|
76
|
-
typeof UpdateCloudCredentialSchema
|
|
77
|
-
>;
|
|
77
|
+
export type UpdateCloudCredential = z.infer<typeof UpdateCloudCredentialSchema>;
|
|
78
78
|
|
|
79
79
|
export const UpdateCloudCredentialResponseSchema = z.object({
|
|
80
80
|
/** Whether the cloud credential was successfully updated. */
|
|
@@ -302,6 +302,28 @@ export type BulkSetCredentialRecordsResponse = z.infer<
|
|
|
302
302
|
typeof BulkSetCredentialRecordsResponseSchema
|
|
303
303
|
>;
|
|
304
304
|
|
|
305
|
+
// ---------------------------------------------------------------------------
|
|
306
|
+
// export_logs
|
|
307
|
+
// ---------------------------------------------------------------------------
|
|
308
|
+
|
|
309
|
+
export const ExportLogsSchema = z.object({
|
|
310
|
+
/** Inclusive range start (epoch ms); log files entirely before it are skipped. */
|
|
311
|
+
startTime: z.number().optional(),
|
|
312
|
+
/** Inclusive range end (epoch ms); log files entirely after it are skipped. */
|
|
313
|
+
endTime: z.number().optional(),
|
|
314
|
+
});
|
|
315
|
+
export type ExportLogs = z.infer<typeof ExportLogsSchema>;
|
|
316
|
+
|
|
317
|
+
export const ExportLogsResponseSchema = z.object({
|
|
318
|
+
/** tar.gz of the collected log files plus a manifest, base64-encoded. */
|
|
319
|
+
archiveBase64: z.string(),
|
|
320
|
+
/** Number of log files included in the archive. */
|
|
321
|
+
filesCollected: z.number(),
|
|
322
|
+
/** Cumulative size of the collected log files, before archiving. */
|
|
323
|
+
totalBytes: z.number(),
|
|
324
|
+
});
|
|
325
|
+
export type ExportLogsResponse = z.infer<typeof ExportLogsResponseSchema>;
|
|
326
|
+
|
|
305
327
|
// ---------------------------------------------------------------------------
|
|
306
328
|
// Full RPC contract type map
|
|
307
329
|
// ---------------------------------------------------------------------------
|
|
@@ -355,6 +377,10 @@ export interface CesRpcContract {
|
|
|
355
377
|
request: BulkSetCredentialRecords;
|
|
356
378
|
response: BulkSetCredentialRecordsResponse;
|
|
357
379
|
};
|
|
380
|
+
[CesRpcMethod.ExportLogs]: {
|
|
381
|
+
request: ExportLogs;
|
|
382
|
+
response: ExportLogsResponse;
|
|
383
|
+
};
|
|
358
384
|
}
|
|
359
385
|
|
|
360
386
|
/**
|
|
@@ -405,4 +431,8 @@ export const CesRpcSchemas = {
|
|
|
405
431
|
request: BulkSetCredentialRecordsSchema,
|
|
406
432
|
response: BulkSetCredentialRecordsResponseSchema,
|
|
407
433
|
},
|
|
434
|
+
[CesRpcMethod.ExportLogs]: {
|
|
435
|
+
request: ExportLogsSchema,
|
|
436
|
+
response: ExportLogsResponseSchema,
|
|
437
|
+
},
|
|
408
438
|
} as const;
|
|
@@ -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
|
});
|