@mycadet/cli 0.13.0-dev.202611131045.a556a8a → 0.13.0-dev.202611140319.cca5491
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/knip.json +0 -3
- 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 +11 -0
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +7 -6
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/seeds.ts +151 -0
- package/node_modules/@mycadet/local-mode/package.json +1 -2
- package/node_modules/@mycadet/local-mode/src/__tests__/cloud-backup.test.ts +5 -9
- package/node_modules/@mycadet/local-mode/src/__tests__/environment-base-url.test.ts +67 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/hatch-config.test.ts +110 -99
- package/node_modules/@mycadet/local-mode/src/__tests__/{hatch-local-overlay.test.ts → hatch-local-config-api.test.ts} +60 -50
- package/node_modules/@mycadet/local-mode/src/__tests__/helpers/lockfile-entry.ts +0 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/local-exec-invocation.test.ts +15 -5
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-doctor.test.ts +16 -6
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-retire.test.ts +3 -4
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-retire.test.ts +4 -10
- package/node_modules/@mycadet/local-mode/src/__tests__/teleport-init.test.ts +1 -8
- package/node_modules/@mycadet/local-mode/src/cloud-auth.ts +9 -31
- package/node_modules/@mycadet/local-mode/src/cloud-registration.ts +6 -17
- package/node_modules/@mycadet/local-mode/src/cloud-releases.ts +2 -3
- package/node_modules/@mycadet/local-mode/src/config.ts +2 -7
- package/node_modules/@mycadet/local-mode/src/daemon-readiness.ts +3 -5
- package/node_modules/@mycadet/local-mode/src/index.ts +3 -10
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +4 -22
- package/node_modules/@mycadet/local-mode/src/operations/cloud-proxy.ts +3 -3
- package/node_modules/@mycadet/local-mode/src/operations/exec.ts +3 -2
- package/node_modules/@mycadet/local-mode/src/ports.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/backup.ts +4 -4
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/exec.ts +0 -10
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/hatch.ts +4 -7
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/migrations.ts +11 -18
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/restore.ts +3 -8
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/retire.ts +3 -6
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/terminal-client.ts +13 -16
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/upgrade.ts +11 -17
- package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +15 -48
- package/node_modules/@mycadet/local-mode/src/remotes/local/common.ts +82 -40
- package/node_modules/@mycadet/local-mode/src/remotes/local/exec.ts +8 -61
- package/node_modules/@mycadet/local-mode/src/remotes/local/hatch-config.ts +71 -44
- package/node_modules/@mycadet/local-mode/src/remotes/local/hatch.ts +15 -8
- package/node_modules/@mycadet/local-mode/src/remotes/local/teleport.ts +5 -13
- package/node_modules/@mycadet/local-mode/src/remotes/local/wake.ts +10 -38
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/index.ts +11 -0
- package/node_modules/@mycadet/shared/package.json +7 -6
- package/node_modules/@mycadet/shared/seeds.ts +151 -0
- package/package.json +1 -3
- package/src/__tests__/cloud-client.test.ts +49 -90
- package/src/__tests__/debug.test.ts +7 -1
- package/src/__tests__/helpers/lockfile-entry.ts +0 -1
- package/src/__tests__/pair.test.ts +11 -12
- package/src/__tests__/ps-cloud-status.test.ts +6 -3
- package/src/__tests__/servers/bun.test.ts +1 -1
- package/src/__tests__/setup.test.ts +16 -10
- package/src/commands/debug.ts +3 -3
- package/src/commands/login.ts +1 -2
- package/src/commands/ps.ts +3 -1
- package/src/commands/terminal.ts +2 -5
- package/src/lib/__tests__/cloud-client-signed-url.test.ts +24 -19
- package/src/lib/assistant-client.ts +2 -2
- package/src/lib/assistant-config.ts +1 -17
- package/src/lib/cloud-client.ts +11 -16
- package/src/lib/cloud-login.ts +7 -9
- package/src/lib/live-voice/tunnel.ts +1 -1
- package/src/lib/remotes/cloud.ts +3 -3
- package/src/lib/servers/common.ts +1 -2
- package/src/lib/sync-cloud-assistants.ts +2 -2
- package/src/lib/terminal-session.ts +3 -2
- package/node_modules/@mycadet/environments/package.json +0 -21
- package/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -76
- package/node_modules/@mycadet/environments/src/__tests__/install-layout.test.ts +0 -98
- package/node_modules/@mycadet/environments/src/__tests__/package-boundary.test.ts +0 -95
- package/node_modules/@mycadet/environments/src/__tests__/test-path-guard.test.ts +0 -89
- package/node_modules/@mycadet/environments/src/index.ts +0 -21
- package/node_modules/@mycadet/environments/src/install-layout.ts +0 -49
- package/node_modules/@mycadet/environments/src/seeds.ts +0 -89
- package/node_modules/@mycadet/environments/src/shell.test.ts +0 -89
- package/node_modules/@mycadet/environments/src/shell.ts +0 -110
- package/node_modules/@mycadet/environments/src/test-path-guard.ts +0 -113
- package/node_modules/@mycadet/environments/src/types.ts +0 -70
- package/node_modules/@mycadet/environments/tsconfig.json +0 -20
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +0 -21
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -76
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/install-layout.test.ts +0 -98
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/package-boundary.test.ts +0 -95
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/test-path-guard.test.ts +0 -89
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/index.ts +0 -21
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/install-layout.ts +0 -49
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/seeds.ts +0 -89
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/shell.test.ts +0 -89
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/shell.ts +0 -110
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/test-path-guard.ts +0 -113
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/types.ts +0 -70
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/tsconfig.json +0 -20
- 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",
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mycadet/shared",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.202611140319.cca5491",
|
|
4
4
|
"private": true,
|
|
5
5
|
"exports": {
|
|
6
|
-
".": "./
|
|
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
|
-
"./
|
|
12
|
-
"./
|
|
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.
|
|
3
|
+
"version": "0.13.0-dev.202611140319.cca5491",
|
|
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(
|
|
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
|
+
});
|
|
@@ -1,25 +1,12 @@
|
|
|
1
|
-
import { readFileSync, rmSync } from "fs";
|
|
2
1
|
import { describe, expect, test } from "bun:test";
|
|
3
2
|
|
|
4
3
|
import {
|
|
4
|
+
applyHatchConfig,
|
|
5
5
|
buildHatchConfigValues,
|
|
6
6
|
buildNestedConfig,
|
|
7
|
-
writeInitialConfig,
|
|
8
7
|
} from "../remotes/local/hatch-config";
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
configValues: Record<string, string>,
|
|
12
|
-
): Record<string, unknown> {
|
|
13
|
-
const path = writeInitialConfig(configValues);
|
|
14
|
-
expect(path).toBeDefined();
|
|
15
|
-
try {
|
|
16
|
-
return JSON.parse(readFileSync(path!, "utf-8")) as Record<string, unknown>;
|
|
17
|
-
} finally {
|
|
18
|
-
if (path !== undefined) rmSync(path, { force: true });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe("config-utils", () => {
|
|
9
|
+
describe("hatch-config", () => {
|
|
23
10
|
test("buildNestedConfig only converts dot-notation values", () => {
|
|
24
11
|
expect(
|
|
25
12
|
buildNestedConfig({
|
|
@@ -36,51 +23,9 @@ describe("config-utils", () => {
|
|
|
36
23
|
});
|
|
37
24
|
});
|
|
38
25
|
|
|
39
|
-
test("
|
|
40
|
-
expect(buildHatchConfigValues({}, "anthropic")).toEqual({
|
|
41
|
-
"llm.default.provider": "anthropic",
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("buildHatchConfigValues preserves explicit provider config", () => {
|
|
46
|
-
expect(
|
|
47
|
-
buildHatchConfigValues(
|
|
48
|
-
{
|
|
49
|
-
"llm.default.provider": "openai",
|
|
50
|
-
"llm.default.model": "gpt-5.4",
|
|
51
|
-
},
|
|
52
|
-
"anthropic",
|
|
53
|
-
),
|
|
54
|
-
).toEqual({
|
|
55
|
-
"llm.default.provider": "openai",
|
|
56
|
-
"llm.default.model": "gpt-5.4",
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("buildHatchConfigValues skips internal hatches without provider setup", () => {
|
|
61
|
-
expect(buildHatchConfigValues({}, undefined)).toEqual({});
|
|
62
|
-
expect(buildHatchConfigValues({}, null)).toEqual({});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("writeInitialConfig does not add a mainAgent callSite for Anthropic defaults", () => {
|
|
66
|
-
expect(
|
|
67
|
-
readInitialConfig({
|
|
68
|
-
"llm.default.provider": "anthropic",
|
|
69
|
-
"llm.default.model": "claude-opus-4-7",
|
|
70
|
-
}),
|
|
71
|
-
).toEqual({
|
|
72
|
-
llm: {
|
|
73
|
-
default: {
|
|
74
|
-
provider: "anthropic",
|
|
75
|
-
model: "claude-opus-4-7",
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("writeInitialConfig preserves profile-based Anthropic model selection", () => {
|
|
26
|
+
test("buildNestedConfig preserves nested fragments like profile overrides", () => {
|
|
82
27
|
expect(
|
|
83
|
-
|
|
28
|
+
buildNestedConfig({
|
|
84
29
|
"llm.activeProfile": "quality-optimized",
|
|
85
30
|
"llm.profiles.quality-optimized.provider": "anthropic",
|
|
86
31
|
"llm.profiles.quality-optimized.model": "claude-opus-4-7",
|
|
@@ -100,9 +45,9 @@ describe("config-utils", () => {
|
|
|
100
45
|
});
|
|
101
46
|
});
|
|
102
47
|
|
|
103
|
-
test("
|
|
48
|
+
test("buildNestedConfig does not invent a mainAgent callSite for Anthropic defaults", () => {
|
|
104
49
|
expect(
|
|
105
|
-
|
|
50
|
+
buildNestedConfig({
|
|
106
51
|
"llm.default.provider": "anthropic",
|
|
107
52
|
"llm.default.model": "claude-opus-4-7",
|
|
108
53
|
"llm.callSites.mainAgent.model": "claude-haiku-4-5-20251001",
|
|
@@ -122,55 +67,121 @@ describe("config-utils", () => {
|
|
|
122
67
|
});
|
|
123
68
|
});
|
|
124
69
|
|
|
125
|
-
test("
|
|
126
|
-
expect(
|
|
127
|
-
|
|
128
|
-
"llm.default.provider": "anthropic",
|
|
129
|
-
"llm.default.model": "claude-haiku-4-5-20251001",
|
|
130
|
-
}),
|
|
131
|
-
).toEqual({
|
|
132
|
-
llm: {
|
|
133
|
-
default: {
|
|
134
|
-
provider: "anthropic",
|
|
135
|
-
model: "claude-haiku-4-5-20251001",
|
|
136
|
-
},
|
|
137
|
-
},
|
|
70
|
+
test("buildHatchConfigValues adds the default hatch provider when no config exists", () => {
|
|
71
|
+
expect(buildHatchConfigValues({}, "anthropic")).toEqual({
|
|
72
|
+
"llm.default.provider": "anthropic",
|
|
138
73
|
});
|
|
139
74
|
});
|
|
140
75
|
|
|
141
|
-
test("
|
|
76
|
+
test("buildHatchConfigValues preserves explicit provider config", () => {
|
|
142
77
|
expect(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}),
|
|
148
|
-
).toEqual({
|
|
149
|
-
llm: {
|
|
150
|
-
activeProfile: "fast",
|
|
151
|
-
profiles: {
|
|
152
|
-
fast: {
|
|
153
|
-
provider: "openai",
|
|
154
|
-
model: "gpt-5.5",
|
|
155
|
-
},
|
|
78
|
+
buildHatchConfigValues(
|
|
79
|
+
{
|
|
80
|
+
"llm.default.provider": "openai",
|
|
81
|
+
"llm.default.model": "gpt-5.4",
|
|
156
82
|
},
|
|
83
|
+
"anthropic",
|
|
84
|
+
),
|
|
85
|
+
).toEqual({
|
|
86
|
+
"llm.default.provider": "openai",
|
|
87
|
+
"llm.default.model": "gpt-5.4",
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("buildHatchConfigValues skips internal hatches without provider setup", () => {
|
|
92
|
+
expect(buildHatchConfigValues({}, undefined)).toEqual({});
|
|
93
|
+
expect(buildHatchConfigValues({}, null)).toEqual({});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("applyHatchConfig sets each dotted path through the config API", async () => {
|
|
97
|
+
const calls: { url: string; body: unknown; auth?: string }[] = [];
|
|
98
|
+
const response = new Response(JSON.stringify({ ok: true }), {
|
|
99
|
+
status: 200,
|
|
100
|
+
});
|
|
101
|
+
await applyHatchConfig({
|
|
102
|
+
gatewayUrl: "http://localhost:4444/",
|
|
103
|
+
bearerToken: "test-token",
|
|
104
|
+
configValues: {
|
|
105
|
+
"llm.default.model": "claude-opus-4-7",
|
|
106
|
+
"llm.default.provider": "anthropic",
|
|
157
107
|
},
|
|
108
|
+
fetchImpl: (async (url, init) => {
|
|
109
|
+
calls.push({
|
|
110
|
+
url: String(url),
|
|
111
|
+
body: JSON.parse(String(init?.body)),
|
|
112
|
+
auth: new Headers(init?.headers).get("Authorization") ?? undefined,
|
|
113
|
+
});
|
|
114
|
+
return response;
|
|
115
|
+
}) as typeof fetch,
|
|
158
116
|
});
|
|
117
|
+
|
|
118
|
+
expect(calls.map((c) => c.url)).toEqual([
|
|
119
|
+
"http://localhost:4444/v1/config/set",
|
|
120
|
+
"http://localhost:4444/v1/config/set",
|
|
121
|
+
]);
|
|
122
|
+
expect(calls.map((c) => c.body)).toEqual([
|
|
123
|
+
{ path: "llm.default.model", value: "claude-opus-4-7" },
|
|
124
|
+
{ path: "llm.default.provider", value: "anthropic" },
|
|
125
|
+
]);
|
|
126
|
+
for (const call of calls) {
|
|
127
|
+
expect(call.auth).toBe("Bearer test-token");
|
|
128
|
+
}
|
|
159
129
|
});
|
|
160
130
|
|
|
161
|
-
test("
|
|
162
|
-
|
|
163
|
-
|
|
131
|
+
test("applyHatchConfig is a no-op without values", async () => {
|
|
132
|
+
let fetched = false;
|
|
133
|
+
await applyHatchConfig({
|
|
134
|
+
gatewayUrl: "http://localhost:4444",
|
|
135
|
+
bearerToken: "test-token",
|
|
136
|
+
configValues: {},
|
|
137
|
+
fetchImpl: (async (..._args: unknown[]) => {
|
|
138
|
+
fetched = true;
|
|
139
|
+
return new Response("{}", { status: 200 });
|
|
140
|
+
}) as typeof fetch,
|
|
141
|
+
});
|
|
142
|
+
expect(fetched).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("applyHatchConfig skips with a warning when no token was leased", async () => {
|
|
146
|
+
const warnings: string[] = [];
|
|
147
|
+
let fetched = false;
|
|
148
|
+
await applyHatchConfig({
|
|
149
|
+
gatewayUrl: "http://localhost:4444",
|
|
150
|
+
configValues: { "llm.default.provider": "anthropic" },
|
|
151
|
+
fetchImpl: (async (..._args: unknown[]) => {
|
|
152
|
+
fetched = true;
|
|
153
|
+
return new Response("{}", { status: 200 });
|
|
154
|
+
}) as typeof fetch,
|
|
155
|
+
log: (m) => warnings.push(m),
|
|
156
|
+
});
|
|
157
|
+
expect(fetched).toBe(false);
|
|
158
|
+
expect(warnings.join("\n")).toContain("assistant config set");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("applyHatchConfig keeps applying the remaining keys when one fails", async () => {
|
|
162
|
+
const paths: string[] = [];
|
|
163
|
+
const warnings: string[] = [];
|
|
164
|
+
await applyHatchConfig({
|
|
165
|
+
gatewayUrl: "http://localhost:4444",
|
|
166
|
+
bearerToken: "test-token",
|
|
167
|
+
configValues: {
|
|
168
|
+
"llm.default.model": "gpt-5.4",
|
|
164
169
|
"llm.default.provider": "openai",
|
|
165
|
-
"llm.default.model": "gpt-5.5",
|
|
166
|
-
}),
|
|
167
|
-
).toEqual({
|
|
168
|
-
llm: {
|
|
169
|
-
default: {
|
|
170
|
-
provider: "openai",
|
|
171
|
-
model: "gpt-5.5",
|
|
172
|
-
},
|
|
173
170
|
},
|
|
171
|
+
fetchImpl: (async (...args: Parameters<typeof fetch>) => {
|
|
172
|
+
const body = JSON.parse(String(args[1]?.body)) as { path: string };
|
|
173
|
+
paths.push(body.path);
|
|
174
|
+
if (body.path === "llm.default.model") {
|
|
175
|
+
return new Response("boom", { status: 500 });
|
|
176
|
+
}
|
|
177
|
+
return new Response("{}", { status: 200 });
|
|
178
|
+
}) as typeof fetch,
|
|
179
|
+
log: (m) => warnings.push(m),
|
|
174
180
|
});
|
|
181
|
+
|
|
182
|
+
// Both keys attempted; the failure warns and names a re-apply path.
|
|
183
|
+
expect(paths).toEqual(["llm.default.model", "llm.default.provider"]);
|
|
184
|
+
expect(warnings.join("\n")).toContain("llm.default.model");
|
|
185
|
+
expect(warnings.join("\n")).toContain("assistant config set");
|
|
175
186
|
});
|
|
176
187
|
});
|