@mycadet/cli 0.13.0-dev.202610231952.fa65022 → 0.13.0-dev.202610241003.f9cbe80
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/local-mode/src/__tests__/status.test.ts +0 -4
- package/node_modules/@mycadet/local-mode/src/index.ts +6 -2
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -3
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +0 -2
- package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +0 -31
- package/node_modules/@mycadet/local-mode/src/lockfile.ts +28 -48
- package/package.json +1 -1
- package/src/__tests__/app-command.test.ts +2 -2
- package/src/__tests__/assistant-client-cloud-auth.test.ts +2 -2
- package/src/__tests__/assistant-client-refresh.test.ts +2 -2
- package/src/__tests__/assistant-config.test.ts +28 -27
- package/src/__tests__/backup-ops.test.ts +4 -3
- package/src/__tests__/backup.test.ts +2 -2
- package/src/__tests__/client-tui-refresh.test.ts +3 -3
- package/src/__tests__/connect-import.test.ts +4 -52
- package/src/__tests__/debug.test.ts +1 -1
- package/src/__tests__/devices.test.ts +5 -6
- package/src/__tests__/gateway-token.test.ts +3 -3
- package/src/__tests__/helpers/lockfile-entry.ts +37 -0
- package/src/__tests__/host-teleport-docker.test.ts +2 -2
- package/src/__tests__/host-teleport.test.ts +15 -15
- package/src/__tests__/local-runtime-version.test.ts +4 -2
- package/src/__tests__/multi-local.test.ts +14 -25
- package/src/__tests__/nginx-ingress.test.ts +73 -5
- package/src/__tests__/orphan-detection.test.ts +13 -12
- package/src/__tests__/ps-cloud-status.test.ts +9 -9
- package/src/__tests__/restore.test.ts +32 -28
- package/src/__tests__/retire-local.test.ts +25 -29
- package/src/__tests__/retire.test.ts +33 -32
- package/src/__tests__/root-backup-docker.test.ts +2 -2
- package/src/__tests__/root-backup.test.ts +2 -3
- package/src/__tests__/root-restore-command.test.ts +2 -2
- package/src/__tests__/setup.test.ts +2 -5
- package/src/__tests__/signing-key-continuity.test.ts +2 -93
- package/src/__tests__/sleep.test.ts +13 -6
- package/src/__tests__/teleport-backup.test.ts +8 -2
- package/src/__tests__/teleport.test.ts +1 -1
- package/src/__tests__/tui-midsession-refresh.test.ts +4 -23
- package/src/__tests__/tunnel-stop.test.ts +2 -3
- package/src/__tests__/tunnel.test.ts +27 -16
- package/src/__tests__/uninstall.test.ts +31 -28
- package/src/__tests__/upgrade-local.test.ts +29 -15
- package/src/__tests__/upgrade-root-recovery.test.ts +2 -2
- package/src/__tests__/use.test.ts +16 -24
- package/src/__tests__/wake-error.test.ts +0 -1
- package/src/__tests__/wake.test.ts +22 -24
- package/src/commands/client.ts +5 -5
- package/src/commands/completions.test.ts +2 -2
- package/src/commands/debug.ts +13 -5
- package/src/commands/devices.ts +5 -5
- package/src/commands/gateway/token.ts +4 -4
- package/src/commands/hatch.ts +2 -2
- package/src/commands/login.ts +2 -2
- package/src/commands/logs.ts +4 -4
- package/src/commands/pair.ts +5 -5
- package/src/commands/ps.ts +23 -17
- package/src/commands/restore.ts +32 -20
- package/src/commands/retire.ts +6 -6
- package/src/commands/sleep.ts +117 -96
- package/src/commands/uninstall.ts +6 -4
- package/src/commands/upgrade.ts +200 -140
- package/src/commands/wake.ts +93 -93
- package/src/lib/__tests__/local-gateway-cli.test.ts +3 -3
- package/src/lib/__tests__/runtime-url.test.ts +1 -15
- package/src/lib/assistant-client.ts +5 -2
- package/src/lib/assistant-config.ts +43 -81
- package/src/lib/cloud-login.ts +12 -6
- package/src/lib/constants.ts +0 -1
- package/src/lib/docker.ts +11 -11
- package/src/lib/exec-apple-container.ts +2 -2
- package/src/lib/hatch-local.ts +12 -6
- package/src/lib/health-check.ts +123 -109
- package/src/lib/host-teleport.ts +31 -23
- package/src/lib/ingress-config.ts +2 -2
- package/src/lib/live-voice/connection.ts +2 -2
- package/src/lib/local.ts +76 -48
- package/src/lib/nginx-ingress.ts +41 -10
- package/src/lib/orphan-detection.ts +4 -3
- package/src/lib/retire-apple-container.ts +2 -2
- package/src/lib/retire-local.ts +11 -5
- package/src/lib/root-backup.ts +35 -21
- package/src/lib/runtime-url.ts +4 -4
- package/src/lib/ssh-apple-container.ts +2 -2
- package/src/lib/sync-cloud-assistants.ts +5 -5
- package/src/lib/teleport-backup.ts +15 -13
- package/src/lib/tunnel.ts +6 -6
- package/src/lib/upgrade-lifecycle.ts +36 -30
|
@@ -26,7 +26,7 @@ import { join } from "node:path";
|
|
|
26
26
|
|
|
27
27
|
import { gatewayToken } from "../commands/gateway/token.js";
|
|
28
28
|
import {
|
|
29
|
-
|
|
29
|
+
saveLockfileAssistant,
|
|
30
30
|
setActiveAssistant,
|
|
31
31
|
} from "../lib/assistant-config.js";
|
|
32
32
|
import {
|
|
@@ -45,7 +45,7 @@ const REAL_FETCH = globalThis.fetch;
|
|
|
45
45
|
let tempHome: string;
|
|
46
46
|
|
|
47
47
|
function seedLocalEntry(overrides: Record<string, unknown> = {}): void {
|
|
48
|
-
|
|
48
|
+
saveLockfileAssistant({
|
|
49
49
|
assistantId: "px",
|
|
50
50
|
name: "Prime Quail",
|
|
51
51
|
runtimeUrl: "http://127.0.0.1:7830",
|
|
@@ -176,7 +176,7 @@ describe("gateway token command", () => {
|
|
|
176
176
|
|
|
177
177
|
test("get without a name targets the active assistant", async () => {
|
|
178
178
|
seedLocalEntry();
|
|
179
|
-
|
|
179
|
+
saveLockfileAssistant({
|
|
180
180
|
assistantId: "py",
|
|
181
181
|
name: "Other Box",
|
|
182
182
|
runtimeUrl: "http://127.0.0.1:7831",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LockfileAssistantSchema,
|
|
3
|
+
type LocalAssistantResources,
|
|
4
|
+
} from "@mycadet/local-mode/contract";
|
|
5
|
+
|
|
6
|
+
import type { LockfileAssistant } from "../../lib/assistant-config.js";
|
|
7
|
+
|
|
8
|
+
type EntryOverrides = Partial<Omit<LockfileAssistant, "resources">> & {
|
|
9
|
+
resources?: Partial<LocalAssistantResources>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const BASE_RESOURCES = {
|
|
13
|
+
instanceDir: "/tmp/cadet-test-instance",
|
|
14
|
+
daemonPort: 7801,
|
|
15
|
+
gatewayPort: 7831,
|
|
16
|
+
cesPort: 7790,
|
|
17
|
+
signingKey: "ab".repeat(32),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The canonical lockfile-entry fixture — one `makeEntry` for every suite.
|
|
22
|
+
* Parses through `LockfileAssistantSchema` so the shape is always the
|
|
23
|
+
* contract's. A `resources` override MERGES onto the base ports instead of
|
|
24
|
+
* replacing them: a partial override that dropped `instanceDir` once broke
|
|
25
|
+
* a drain test.
|
|
26
|
+
*/
|
|
27
|
+
export function makeEntry(overrides: EntryOverrides = {}): LockfileAssistant {
|
|
28
|
+
const { resources, ...rest } = overrides;
|
|
29
|
+
return LockfileAssistantSchema.parse({
|
|
30
|
+
assistantId: "assistant-1",
|
|
31
|
+
cloud: "local",
|
|
32
|
+
runtimeUrl: "http://127.0.0.1:7831",
|
|
33
|
+
guardianBootstrapSecret: "test-bootstrap-secret",
|
|
34
|
+
...rest,
|
|
35
|
+
resources: { ...BASE_RESOURCES, ...resources },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
import { dockerResourceNames } from "../lib/docker.js";
|
|
13
13
|
import { DOCKER_STATEFUL_SET_SPEC } from "../lib/statefulset.js";
|
|
14
14
|
import { packRoot, STATE_ROOTS } from "../lib/root-backup.js";
|
|
15
|
-
import type {
|
|
15
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
16
16
|
import { mockCommands } from "./commands-mock.js";
|
|
17
17
|
|
|
18
|
-
const entry:
|
|
18
|
+
const entry: LockfileAssistant = {
|
|
19
19
|
assistantId: "destination",
|
|
20
20
|
cloud: "docker",
|
|
21
21
|
runtimeUrl: "http://localhost:7830",
|
|
@@ -4,8 +4,9 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import {
|
|
6
6
|
findAssistantByName,
|
|
7
|
-
|
|
8
|
-
type
|
|
7
|
+
getLocalInstanceDir,
|
|
8
|
+
type LockfileAssistant,
|
|
9
|
+
saveLockfileAssistant,
|
|
9
10
|
} from "../lib/assistant-config.js";
|
|
10
11
|
import {
|
|
11
12
|
teleportHostInstallation,
|
|
@@ -20,8 +21,8 @@ import {
|
|
|
20
21
|
} from "../lib/root-backup.js";
|
|
21
22
|
|
|
22
23
|
let directory: string,
|
|
23
|
-
source:
|
|
24
|
-
target:
|
|
24
|
+
source: LockfileAssistant,
|
|
25
|
+
target: LockfileAssistant,
|
|
25
26
|
ops: HostTeleportOps;
|
|
26
27
|
let order: string[],
|
|
27
28
|
running: Map<string, boolean>,
|
|
@@ -32,7 +33,7 @@ async function instance(
|
|
|
32
33
|
name: string,
|
|
33
34
|
cloud: "local" | "docker",
|
|
34
35
|
byte: number,
|
|
35
|
-
): Promise<
|
|
36
|
+
): Promise<LockfileAssistant> {
|
|
36
37
|
const root = join(directory, name);
|
|
37
38
|
for (const state of STATE_ROOTS) {
|
|
38
39
|
await mkdir(join(root, state), { recursive: true });
|
|
@@ -61,7 +62,6 @@ async function instance(
|
|
|
61
62
|
daemonPort: 1,
|
|
62
63
|
gatewayPort: 2,
|
|
63
64
|
cesPort: 3,
|
|
64
|
-
qdrantPort: 4,
|
|
65
65
|
signingKey: byte.toString(16).padStart(2, "0").repeat(32),
|
|
66
66
|
},
|
|
67
67
|
};
|
|
@@ -74,8 +74,8 @@ beforeEach(async () => {
|
|
|
74
74
|
process.env.CADET_LOCKFILE_DIR = join(directory, "registry");
|
|
75
75
|
source = await instance("source", "docker", 7);
|
|
76
76
|
target = await instance("target", "local", 3);
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
saveLockfileAssistant(source);
|
|
78
|
+
saveLockfileAssistant(target);
|
|
79
79
|
order = [];
|
|
80
80
|
running = new Map([
|
|
81
81
|
["source", true],
|
|
@@ -115,7 +115,7 @@ beforeEach(async () => {
|
|
|
115
115
|
storage,
|
|
116
116
|
sleep: () => ops.sleep(entry),
|
|
117
117
|
wake: () => storage.resume(),
|
|
118
|
-
save:
|
|
118
|
+
save: saveLockfileAssistant,
|
|
119
119
|
});
|
|
120
120
|
order.push(`backup:${entry.assistantId}`);
|
|
121
121
|
return file;
|
|
@@ -132,7 +132,7 @@ beforeEach(async () => {
|
|
|
132
132
|
storage,
|
|
133
133
|
sleep: () => ops.sleep(entry),
|
|
134
134
|
wake: () => storage.resume(),
|
|
135
|
-
save:
|
|
135
|
+
save: saveLockfileAssistant,
|
|
136
136
|
},
|
|
137
137
|
);
|
|
138
138
|
await storage.resume();
|
|
@@ -163,19 +163,19 @@ test("moves all four roots and encrypted key pairs using the exact stopped-sourc
|
|
|
163
163
|
for (const state of STATE_ROOTS) {
|
|
164
164
|
expect(
|
|
165
165
|
await readFile(
|
|
166
|
-
join(target.resources
|
|
166
|
+
join(getLocalInstanceDir(target.resources), state, "state"),
|
|
167
167
|
"utf8",
|
|
168
168
|
),
|
|
169
169
|
).toBe(`source:${state}`);
|
|
170
170
|
}
|
|
171
171
|
expect(
|
|
172
172
|
await readFile(
|
|
173
|
-
join(target.resources
|
|
173
|
+
join(getLocalInstanceDir(target.resources), "ces-security", "keys.enc"),
|
|
174
174
|
),
|
|
175
175
|
).toEqual(Buffer.from([7, 0, 255]));
|
|
176
176
|
expect(
|
|
177
177
|
await readFile(
|
|
178
|
-
join(target.resources
|
|
178
|
+
join(getLocalInstanceDir(target.resources), "ces-security", "store.key"),
|
|
179
179
|
),
|
|
180
180
|
).toEqual(Buffer.alloc(32, 8));
|
|
181
181
|
expect(findAssistantByName("target")!.resources!.signingKey).toBe(
|
|
@@ -387,7 +387,7 @@ test("holds source and target operation locks through import and releases them a
|
|
|
387
387
|
storage,
|
|
388
388
|
sleep: () => ops.sleep(entry),
|
|
389
389
|
wake: () => storage.resume(),
|
|
390
|
-
save:
|
|
390
|
+
save: saveLockfileAssistant,
|
|
391
391
|
}),
|
|
392
392
|
).rejects.toThrow("Another backup/restore owns");
|
|
393
393
|
}
|
|
@@ -400,6 +400,6 @@ test("holds source and target operation locks through import and releases them a
|
|
|
400
400
|
storage,
|
|
401
401
|
sleep: () => ops.sleep(source),
|
|
402
402
|
wake: () => storage.resume(),
|
|
403
|
-
save:
|
|
403
|
+
save: saveLockfileAssistant,
|
|
404
404
|
});
|
|
405
405
|
});
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test";
|
|
|
2
2
|
|
|
3
3
|
import { isValidReleaseVersion } from "@mycadet/local-mode";
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { LocalAssistantResources } from "@mycadet/local-mode/contract";
|
|
6
6
|
import { ensureLocalRuntime } from "../lib/local.js";
|
|
7
7
|
|
|
8
8
|
// Only `instanceDir` is read, and only after the validation guard passes —
|
|
@@ -10,7 +10,9 @@ import { ensureLocalRuntime } from "../lib/local.js";
|
|
|
10
10
|
// sufficient for the rejection cases.
|
|
11
11
|
const resources = {
|
|
12
12
|
instanceDir: "/tmp/cadet-nonexistent-instance",
|
|
13
|
-
|
|
13
|
+
daemonPort: 0,
|
|
14
|
+
gatewayPort: 0,
|
|
15
|
+
} satisfies LocalAssistantResources;
|
|
14
16
|
|
|
15
17
|
const VALID_VERSIONS = ["latest", "v1.2.3", "1.2.3", "0.6.0-staging.5"];
|
|
16
18
|
const MALICIOUS_VERSIONS = [
|
|
@@ -26,15 +26,11 @@ import {
|
|
|
26
26
|
resolveTargetAssistant,
|
|
27
27
|
setActiveAssistant,
|
|
28
28
|
getActiveAssistant,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type
|
|
29
|
+
removeLockfileAssistant,
|
|
30
|
+
saveLockfileAssistant,
|
|
31
|
+
type LockfileAssistant,
|
|
32
32
|
} from "../lib/assistant-config.js";
|
|
33
|
-
import {
|
|
34
|
-
DEFAULT_DAEMON_PORT,
|
|
35
|
-
DEFAULT_GATEWAY_PORT,
|
|
36
|
-
DEFAULT_QDRANT_PORT,
|
|
37
|
-
} from "../lib/constants.js";
|
|
33
|
+
import { DEFAULT_DAEMON_PORT, DEFAULT_GATEWAY_PORT } from "../lib/constants.js";
|
|
38
34
|
import { mockOsHomedir } from "./helpers/os-mock.js";
|
|
39
35
|
|
|
40
36
|
afterAll(() => {
|
|
@@ -43,10 +39,7 @@ afterAll(() => {
|
|
|
43
39
|
});
|
|
44
40
|
|
|
45
41
|
function writeLockfile(data: unknown): void {
|
|
46
|
-
writeFileSync(
|
|
47
|
-
join(testDir, "lockfile.json"),
|
|
48
|
-
JSON.stringify(data, null, 2),
|
|
49
|
-
);
|
|
42
|
+
writeFileSync(join(testDir, "lockfile.json"), JSON.stringify(data, null, 2));
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
function readLockfileRaw(): Record<string, unknown> {
|
|
@@ -58,11 +51,11 @@ function readLockfileRaw(): Record<string, unknown> {
|
|
|
58
51
|
const makeEntry = (
|
|
59
52
|
id: string,
|
|
60
53
|
remote: Remote = "local",
|
|
61
|
-
extra?: Partial<
|
|
62
|
-
):
|
|
54
|
+
extra?: Partial<LockfileAssistant>,
|
|
55
|
+
): LockfileAssistant => ({
|
|
63
56
|
assistantId: id,
|
|
64
57
|
runtimeUrl: `http://localhost:${DEFAULT_DAEMON_PORT}`,
|
|
65
|
-
// The
|
|
58
|
+
// The LockfileAssistant field is `cloud` — the rename happens only here,
|
|
66
59
|
// where the type forces it.
|
|
67
60
|
cloud: remote,
|
|
68
61
|
...extra,
|
|
@@ -108,7 +101,6 @@ describe("multi-local", () => {
|
|
|
108
101
|
// AND it gets the default ports since no other instances exist
|
|
109
102
|
expect(res.daemonPort).toBe(DEFAULT_DAEMON_PORT);
|
|
110
103
|
expect(res.gatewayPort).toBe(DEFAULT_GATEWAY_PORT);
|
|
111
|
-
expect(res.qdrantPort).toBe(DEFAULT_QDRANT_PORT);
|
|
112
104
|
} finally {
|
|
113
105
|
if (prevXdg !== undefined) {
|
|
114
106
|
process.env.XDG_DATA_HOME = prevXdg;
|
|
@@ -162,7 +154,6 @@ describe("multi-local", () => {
|
|
|
162
154
|
const res = await allocateLocalResources("dev-a");
|
|
163
155
|
expect(res.daemonPort).toBe(18000);
|
|
164
156
|
expect(res.gatewayPort).toBe(18100);
|
|
165
|
-
expect(res.qdrantPort).toBe(18200);
|
|
166
157
|
expect(res.cesPort).toBe(18300);
|
|
167
158
|
} finally {
|
|
168
159
|
if (prevEnv !== undefined) {
|
|
@@ -181,13 +172,12 @@ describe("multi-local", () => {
|
|
|
181
172
|
|
|
182
173
|
test("second instance gets distinct ports and dir when first instance is saved", async () => {
|
|
183
174
|
// GIVEN a first local assistant already exists in the lockfile
|
|
184
|
-
|
|
175
|
+
saveLockfileAssistant(makeEntry("instance-a"));
|
|
185
176
|
|
|
186
177
|
// AND the default ports are occupied
|
|
187
178
|
const occupiedPorts = new Set([
|
|
188
179
|
DEFAULT_DAEMON_PORT,
|
|
189
180
|
DEFAULT_GATEWAY_PORT,
|
|
190
|
-
DEFAULT_QDRANT_PORT,
|
|
191
181
|
]);
|
|
192
182
|
probePortMock.mockImplementation((port: number) =>
|
|
193
183
|
Promise.resolve(occupiedPorts.has(port)),
|
|
@@ -199,7 +189,6 @@ describe("multi-local", () => {
|
|
|
199
189
|
// THEN the second instance gets non-default ports
|
|
200
190
|
expect(occupiedPorts.has(b.daemonPort)).toBe(false);
|
|
201
191
|
expect(occupiedPorts.has(b.gatewayPort)).toBe(false);
|
|
202
|
-
expect(occupiedPorts.has(b.qdrantPort)).toBe(false);
|
|
203
192
|
|
|
204
193
|
// AND it gets its own dedicated instance directory
|
|
205
194
|
expect(b.instanceDir).toContain("instance-b");
|
|
@@ -207,7 +196,7 @@ describe("multi-local", () => {
|
|
|
207
196
|
|
|
208
197
|
test("skips ports that probePort reports as in-use", async () => {
|
|
209
198
|
// GIVEN a first local assistant already exists in the lockfile
|
|
210
|
-
|
|
199
|
+
saveLockfileAssistant(makeEntry("existing"));
|
|
211
200
|
|
|
212
201
|
// AND the default daemon ports are occupied
|
|
213
202
|
const portsInUse = new Set([
|
|
@@ -302,13 +291,13 @@ describe("multi-local", () => {
|
|
|
302
291
|
});
|
|
303
292
|
});
|
|
304
293
|
|
|
305
|
-
describe("
|
|
294
|
+
describe("removeLockfileAssistant() reassigns activeAssistant on removal", () => {
|
|
306
295
|
test("set active to foo, remove foo, verify active is reassigned to bar", () => {
|
|
307
296
|
writeLockfile({
|
|
308
297
|
assistants: [makeEntry("foo"), makeEntry("bar")],
|
|
309
298
|
activeAssistant: "foo",
|
|
310
299
|
});
|
|
311
|
-
|
|
300
|
+
removeLockfileAssistant("foo");
|
|
312
301
|
expect(getActiveAssistant()).toBe("bar");
|
|
313
302
|
});
|
|
314
303
|
|
|
@@ -317,7 +306,7 @@ describe("multi-local", () => {
|
|
|
317
306
|
assistants: [makeEntry("foo"), makeEntry("bar")],
|
|
318
307
|
activeAssistant: "foo",
|
|
319
308
|
});
|
|
320
|
-
|
|
309
|
+
removeLockfileAssistant("bar");
|
|
321
310
|
expect(getActiveAssistant()).toBe("foo");
|
|
322
311
|
});
|
|
323
312
|
});
|
|
@@ -343,7 +332,7 @@ describe("multi-local", () => {
|
|
|
343
332
|
});
|
|
344
333
|
writeLockfile({ assistants: [remoteEntry] });
|
|
345
334
|
// Save and reload to verify resources are not injected
|
|
346
|
-
|
|
335
|
+
saveLockfileAssistant(remoteEntry);
|
|
347
336
|
const result = resolveTargetAssistant("cloud-box");
|
|
348
337
|
expect(result.resources).toBeUndefined();
|
|
349
338
|
});
|
|
@@ -27,7 +27,7 @@ import { z } from "zod";
|
|
|
27
27
|
|
|
28
28
|
import * as httpClient from "../lib/http-client.js";
|
|
29
29
|
import * as versionModule from "@mycadet/shared/version";
|
|
30
|
-
import type {
|
|
30
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
31
31
|
|
|
32
32
|
const realChildProcess = { ...childProcess };
|
|
33
33
|
const realFs = { ...fsModule };
|
|
@@ -458,6 +458,74 @@ describe("buildIngressNginxConfig", () => {
|
|
|
458
458
|
expect(conf).toContain("proxy_buffering off;");
|
|
459
459
|
expect(conf).toContain("proxy_read_timeout 1h;");
|
|
460
460
|
});
|
|
461
|
+
|
|
462
|
+
test("the app-mode edge forwards every unversioned path to the gateway", () => {
|
|
463
|
+
// No route enumeration lives at the edge: the forward matches any path
|
|
464
|
+
// the edge does not serve itself, and the gateway's router resolves the
|
|
465
|
+
// optional /v1 prefix (P7).
|
|
466
|
+
const rootLocation = remoteConf
|
|
467
|
+
.split("location ~ ^/(?!")[1]
|
|
468
|
+
?.split(" }")[0];
|
|
469
|
+
expect(rootLocation).toBeDefined();
|
|
470
|
+
expect(rootLocation).toContain("proxy_pass http://127.0.0.1:7830;");
|
|
471
|
+
expect(rootLocation).not.toContain("rewrite");
|
|
472
|
+
// The lookahead spares only the edge's own surface — the shell's routes
|
|
473
|
+
// and the root files it ships.
|
|
474
|
+
for (const owned of [
|
|
475
|
+
"account(?:/|$)",
|
|
476
|
+
"logout(?:/|$)",
|
|
477
|
+
"index\\.html$",
|
|
478
|
+
"favicon\\.svg$",
|
|
479
|
+
"cadet-logo-white\\.svg$",
|
|
480
|
+
"cadet-scene-cut\\.mp4$",
|
|
481
|
+
]) {
|
|
482
|
+
expect(rootLocation).toContain(owned);
|
|
483
|
+
}
|
|
484
|
+
// Never gateway API vocabulary: a new gateway route needs no edge edit.
|
|
485
|
+
for (const segment of [
|
|
486
|
+
"admin",
|
|
487
|
+
"assistants",
|
|
488
|
+
"channels",
|
|
489
|
+
"contacts",
|
|
490
|
+
"oauth",
|
|
491
|
+
"integrations",
|
|
492
|
+
]) {
|
|
493
|
+
expect(rootLocation).not.toContain(segment);
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test("the iframe twin forwards the /web namespace's remainder to the /v1 route", () => {
|
|
498
|
+
expect(remoteConf).toContain(
|
|
499
|
+
"location ~ ^/web/(?!assistant(?:/|$)|v1(?:/|$))",
|
|
500
|
+
);
|
|
501
|
+
expect(remoteConf).toContain("rewrite ^/web/(.*)$ /v1/$1 break;");
|
|
502
|
+
// Ordered ahead of the root catch-all so /web paths reach the twin
|
|
503
|
+
// instead of forwarding verbatim with their iframe prefix.
|
|
504
|
+
expect(remoteConf.indexOf("location ~ ^/web/(?!")).toBeLessThan(
|
|
505
|
+
remoteConf.indexOf("location ~ ^/(?!"),
|
|
506
|
+
);
|
|
507
|
+
expect(remoteConf).not.toContain("location ^~ /web/ {");
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
test("web mode keeps its surface versioned (the gateway handles both spellings)", () => {
|
|
511
|
+
expect(conf).not.toContain("location ~ ^/(?:");
|
|
512
|
+
expect(conf).not.toContain("location ~ ^/web/");
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test("the sensitive routes are blocked in both spellings at both prefixes", () => {
|
|
516
|
+
for (const location of [
|
|
517
|
+
"location = /pair ",
|
|
518
|
+
"location = /pair/ ",
|
|
519
|
+
"location = /devices ",
|
|
520
|
+
"location = /v1/pair ",
|
|
521
|
+
"location = /web/pair ",
|
|
522
|
+
"location = /web/v1/pair ",
|
|
523
|
+
]) {
|
|
524
|
+
expect(remoteConf).toContain(`${location}{ return 404; }`);
|
|
525
|
+
}
|
|
526
|
+
// Web mode's denylist also gains the unversioned twins.
|
|
527
|
+
expect(conf).toContain("location = /pair { return 404; }");
|
|
528
|
+
});
|
|
461
529
|
});
|
|
462
530
|
|
|
463
531
|
describe("buildRemoteWebIndexHtml", () => {
|
|
@@ -2039,7 +2107,7 @@ describe("stopContainerAppServer", () => {
|
|
|
2039
2107
|
});
|
|
2040
2108
|
|
|
2041
2109
|
/** A container entry whose gateway port is only recoverable from its URLs. */
|
|
2042
|
-
function containerEntry(port: number):
|
|
2110
|
+
function containerEntry(port: number): LockfileAssistant {
|
|
2043
2111
|
return {
|
|
2044
2112
|
assistantId: "docker-1",
|
|
2045
2113
|
runtimeUrl: `http://localhost:${port}`,
|
|
@@ -2310,9 +2378,9 @@ describe("the app shell edge", () => {
|
|
|
2310
2378
|
// Prefixed API paths the web UI builds from its serving prefix.
|
|
2311
2379
|
expect(conf).toContain("location ^~ /web/v1/ {");
|
|
2312
2380
|
expect(conf).toContain("proxy_pass http://127.0.0.1:7830/v1/;");
|
|
2313
|
-
// Nothing else under /web
|
|
2314
|
-
//
|
|
2315
|
-
expect(conf).toContain("location
|
|
2381
|
+
// Nothing else under /web is served by the edge: the twin forwards the
|
|
2382
|
+
// namespace's remainder to the gateway, which 404s unknown paths.
|
|
2383
|
+
expect(conf).toContain("location ~ ^/web/(?!assistant(?:/|$)|v1(?:/|$)) {");
|
|
2316
2384
|
});
|
|
2317
2385
|
|
|
2318
2386
|
test("blocks the sensitive gateway routes under both prefixes", () => {
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "../lib/orphan-detection.js";
|
|
17
17
|
import {
|
|
18
18
|
loadAllAssistantsAcrossEnvs,
|
|
19
|
-
type
|
|
19
|
+
type LockfileAssistant,
|
|
20
20
|
} from "../lib/assistant-config.js";
|
|
21
21
|
|
|
22
22
|
afterAll(() => {
|
|
@@ -33,7 +33,7 @@ function makeLocalEntry(
|
|
|
33
33
|
qdrant?: string;
|
|
34
34
|
embed?: string;
|
|
35
35
|
} = {},
|
|
36
|
-
):
|
|
36
|
+
): LockfileAssistant {
|
|
37
37
|
mkdirSync(join(instanceDir, "workspace", "data", "qdrant"), {
|
|
38
38
|
recursive: true,
|
|
39
39
|
});
|
|
@@ -50,7 +50,10 @@ function makeLocalEntry(
|
|
|
50
50
|
);
|
|
51
51
|
}
|
|
52
52
|
if (pids.embed !== undefined) {
|
|
53
|
-
writeFileSync(
|
|
53
|
+
writeFileSync(
|
|
54
|
+
join(instanceDir, "workspace", "embed-worker.pid"),
|
|
55
|
+
pids.embed,
|
|
56
|
+
);
|
|
54
57
|
}
|
|
55
58
|
return {
|
|
56
59
|
assistantId: id,
|
|
@@ -60,7 +63,6 @@ function makeLocalEntry(
|
|
|
60
63
|
instanceDir,
|
|
61
64
|
daemonPort: 7821,
|
|
62
65
|
gatewayPort: 7830,
|
|
63
|
-
qdrantPort: 6333,
|
|
64
66
|
cesPort: 8090,
|
|
65
67
|
},
|
|
66
68
|
};
|
|
@@ -93,7 +95,7 @@ describe("getKnownPidsFromAssistants", () => {
|
|
|
93
95
|
});
|
|
94
96
|
|
|
95
97
|
test("includes docker watcherPid when present", () => {
|
|
96
|
-
const entry:
|
|
98
|
+
const entry: LockfileAssistant = {
|
|
97
99
|
assistantId: "docker-1",
|
|
98
100
|
runtimeUrl: "http://localhost:18100",
|
|
99
101
|
cloud: "docker",
|
|
@@ -104,7 +106,7 @@ describe("getKnownPidsFromAssistants", () => {
|
|
|
104
106
|
});
|
|
105
107
|
|
|
106
108
|
test("ignores non-local entries without watcherPid", () => {
|
|
107
|
-
const entry:
|
|
109
|
+
const entry: LockfileAssistant = {
|
|
108
110
|
assistantId: "managed-1",
|
|
109
111
|
runtimeUrl: "https://cloud.mycadet.ai/foo",
|
|
110
112
|
cloud: "cloud",
|
|
@@ -114,7 +116,7 @@ describe("getKnownPidsFromAssistants", () => {
|
|
|
114
116
|
});
|
|
115
117
|
|
|
116
118
|
test("local entry without resources contributes no PIDs", () => {
|
|
117
|
-
const entry:
|
|
119
|
+
const entry: LockfileAssistant = {
|
|
118
120
|
assistantId: "legacy",
|
|
119
121
|
runtimeUrl: "http://localhost:7821",
|
|
120
122
|
cloud: "local",
|
|
@@ -198,14 +200,14 @@ describe("loadAllAssistantsAcrossEnvs", () => {
|
|
|
198
200
|
expect(all).toEqual([]);
|
|
199
201
|
});
|
|
200
202
|
|
|
201
|
-
test("
|
|
203
|
+
test("keeps schema-valid entries; the schema drops id-less rows", () => {
|
|
202
204
|
const envDir = mkdtempSync(join(testDir, "partial-"));
|
|
203
205
|
writeFileSync(
|
|
204
206
|
join(envDir, "lockfile.json"),
|
|
205
207
|
JSON.stringify({
|
|
206
208
|
assistants: [
|
|
207
|
-
{ assistantId: "no-url" }, //
|
|
208
|
-
{ runtimeUrl: "http://x" }, // missing assistantId
|
|
209
|
+
{ assistantId: "no-url" }, // valid: runtimeUrl is optional now
|
|
210
|
+
{ runtimeUrl: "http://x" }, // missing assistantId: dropped
|
|
209
211
|
{
|
|
210
212
|
assistantId: "good",
|
|
211
213
|
runtimeUrl: "http://localhost:7821",
|
|
@@ -215,7 +217,7 @@ describe("loadAllAssistantsAcrossEnvs", () => {
|
|
|
215
217
|
}),
|
|
216
218
|
);
|
|
217
219
|
const all = loadAllAssistantsAcrossEnvs([makeEnv("partial", envDir)]);
|
|
218
|
-
expect(all.map((e) => e.assistantId)).toEqual(["good"]);
|
|
220
|
+
expect(all.map((e) => e.assistantId)).toEqual(["no-url", "good"]);
|
|
219
221
|
});
|
|
220
222
|
|
|
221
223
|
test("end-to-end: dev env's daemon is not flagged as orphan from local env", () => {
|
|
@@ -242,7 +244,6 @@ describe("loadAllAssistantsAcrossEnvs", () => {
|
|
|
242
244
|
instanceDir,
|
|
243
245
|
daemonPort: 18000,
|
|
244
246
|
gatewayPort: 18100,
|
|
245
|
-
qdrantPort: 18200,
|
|
246
247
|
cesPort: 18300,
|
|
247
248
|
},
|
|
248
249
|
},
|
|
@@ -68,9 +68,9 @@ const fetchCloudAssistantsMock = spyOn(
|
|
|
68
68
|
cloudClient,
|
|
69
69
|
"fetchCloudAssistants",
|
|
70
70
|
).mockResolvedValue([]);
|
|
71
|
-
const
|
|
71
|
+
const checkCloudHealthMock = spyOn(
|
|
72
72
|
healthCheck,
|
|
73
|
-
"
|
|
73
|
+
"checkCloudHealth",
|
|
74
74
|
).mockResolvedValue({ status: "healthy", detail: null });
|
|
75
75
|
|
|
76
76
|
// ---------------------------------------------------------------------------
|
|
@@ -118,8 +118,8 @@ afterEach(() => {
|
|
|
118
118
|
});
|
|
119
119
|
fetchCloudAssistantsMock.mockReset();
|
|
120
120
|
fetchCloudAssistantsMock.mockResolvedValue([]);
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
checkCloudHealthMock.mockReset();
|
|
122
|
+
checkCloudHealthMock.mockResolvedValue({ status: "healthy", detail: null });
|
|
123
123
|
readRootProcessesMock.mockReturnValue({});
|
|
124
124
|
});
|
|
125
125
|
|
|
@@ -131,7 +131,7 @@ afterAll(() => {
|
|
|
131
131
|
readCloudTokenMock.mockRestore();
|
|
132
132
|
fetchCurrentUserMock.mockRestore();
|
|
133
133
|
fetchCloudAssistantsMock.mockRestore();
|
|
134
|
-
|
|
134
|
+
checkCloudHealthMock.mockRestore();
|
|
135
135
|
rmSync(testDir, { recursive: true, force: true });
|
|
136
136
|
});
|
|
137
137
|
|
|
@@ -238,7 +238,7 @@ describe("cadet ps — platform status line", () => {
|
|
|
238
238
|
},
|
|
239
239
|
]);
|
|
240
240
|
getActiveAssistantMock.mockReturnValue(null);
|
|
241
|
-
|
|
241
|
+
checkCloudHealthMock.mockImplementation(async () => ({
|
|
242
242
|
status: "healthy",
|
|
243
243
|
detail: null,
|
|
244
244
|
}));
|
|
@@ -311,8 +311,8 @@ describe("cadet ps — platform status line", () => {
|
|
|
311
311
|
},
|
|
312
312
|
]);
|
|
313
313
|
getActiveAssistantMock.mockReturnValue("assistant-123");
|
|
314
|
-
|
|
315
|
-
status:
|
|
314
|
+
checkCloudHealthMock.mockImplementation(async (entry) => ({
|
|
315
|
+
status: entry.assistantId === "assistant-123" ? "healthy" : "sleeping",
|
|
316
316
|
detail: null,
|
|
317
317
|
}));
|
|
318
318
|
|
|
@@ -388,7 +388,7 @@ describe("cadet ps <built-in process name> details", () => {
|
|
|
388
388
|
cloud: "cloud",
|
|
389
389
|
},
|
|
390
390
|
]);
|
|
391
|
-
|
|
391
|
+
checkCloudHealthMock.mockImplementation(async () => ({
|
|
392
392
|
status: "healthy",
|
|
393
393
|
detail: null,
|
|
394
394
|
}));
|