@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
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from "bun:test";
|
|
11
11
|
|
|
12
12
|
import * as cloudClient from "../lib/cloud-client.js";
|
|
13
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
13
14
|
import {
|
|
14
15
|
createPlatformBackup,
|
|
15
16
|
listPlatformBackups,
|
|
@@ -24,10 +25,14 @@ const invalidateOrgIdCacheSpy = spyOn(
|
|
|
24
25
|
cloudClient,
|
|
25
26
|
"invalidateOrgIdCache",
|
|
26
27
|
).mockImplementation(() => {});
|
|
28
|
+
const getCloudUrlSpy = spyOn(cloudClient, "getCloudUrl").mockReturnValue(
|
|
29
|
+
"https://cloud.mycadet.ai",
|
|
30
|
+
);
|
|
27
31
|
|
|
28
32
|
afterAll(() => {
|
|
29
33
|
authHeadersSpy.mockRestore();
|
|
30
34
|
invalidateOrgIdCacheSpy.mockRestore();
|
|
35
|
+
getCloudUrlSpy.mockRestore();
|
|
31
36
|
});
|
|
32
37
|
|
|
33
38
|
let originalFetch: typeof globalThis.fetch;
|
|
@@ -53,14 +58,15 @@ beforeEach(() => {
|
|
|
53
58
|
) as unknown as typeof globalThis.fetch;
|
|
54
59
|
authHeadersSpy.mockClear();
|
|
55
60
|
invalidateOrgIdCacheSpy.mockClear();
|
|
61
|
+
getCloudUrlSpy.mockClear();
|
|
56
62
|
});
|
|
57
63
|
|
|
58
64
|
afterEach(() => {
|
|
59
65
|
globalThis.fetch = originalFetch;
|
|
60
66
|
});
|
|
61
67
|
|
|
62
|
-
const ENTRY = {
|
|
63
|
-
|
|
68
|
+
const ENTRY: LockfileAssistant = {
|
|
69
|
+
cloud: "cloud",
|
|
64
70
|
assistantId: "11111111-2222-3333-4444-555555555555",
|
|
65
71
|
};
|
|
66
72
|
const BACKUPS_URL = `https://cloud.mycadet.ai/v1/assistants/${ENTRY.assistantId}/backups/`;
|
|
@@ -3,7 +3,7 @@ import * as assistants from "../lib/assistant-config.js";
|
|
|
3
3
|
import * as host from "../lib/host-teleport.js";
|
|
4
4
|
import { parseArgs, teleport } from "../commands/teleport.js";
|
|
5
5
|
|
|
6
|
-
const entry: assistants.
|
|
6
|
+
const entry: assistants.LockfileAssistant = {
|
|
7
7
|
assistantId: "source-1",
|
|
8
8
|
name: "source",
|
|
9
9
|
cloud: "local",
|
|
@@ -15,22 +15,21 @@ const ORIGINAL_LOCKFILE_DIR = process.env.CADET_LOCKFILE_DIR;
|
|
|
15
15
|
const ORIGINAL_FETCH = globalThis.fetch;
|
|
16
16
|
|
|
17
17
|
import { maybeRefreshAuthHeaders } from "../components/DefaultMainScreen";
|
|
18
|
-
import {
|
|
18
|
+
import { saveLockfileAssistant } from "../lib/assistant-config";
|
|
19
19
|
import { saveGuardianToken } from "../lib/guardian-token";
|
|
20
20
|
|
|
21
21
|
const RUNTIME = "https://gw.example.com";
|
|
22
22
|
const future = () => new Date(Date.now() + 60 * 60 * 1000).toISOString();
|
|
23
23
|
const past = () => new Date(Date.now() - 60_000).toISOString();
|
|
24
24
|
|
|
25
|
-
function seedEntry(kind: "paired" | "local"
|
|
25
|
+
function seedEntry(kind: "paired" | "local"): void {
|
|
26
26
|
// Paired-ness derives from the addressing (no stored flag): the paired
|
|
27
27
|
// shape is a loopback-cloud entry whose runtimeUrl points off-machine;
|
|
28
28
|
// the plain-local shape uses a loopback runtimeUrl.
|
|
29
|
-
|
|
29
|
+
saveLockfileAssistant({
|
|
30
30
|
assistantId: "px",
|
|
31
31
|
name: kind === "paired" ? "Paired" : "Local",
|
|
32
32
|
runtimeUrl: kind === "paired" ? RUNTIME : "http://127.0.0.1:7830",
|
|
33
|
-
...(localUrl ? { localUrl } : {}),
|
|
34
33
|
cloud: "local",
|
|
35
34
|
});
|
|
36
35
|
}
|
|
@@ -81,7 +80,7 @@ describe("maybeRefreshAuthHeaders", () => {
|
|
|
81
80
|
beforeEach(() => {
|
|
82
81
|
tempHome = mkdtempSync(join(tmpdir(), "tui-midsession-test-"));
|
|
83
82
|
process.env.XDG_CONFIG_HOME = tempHome;
|
|
84
|
-
// Isolate the lockfile too —
|
|
83
|
+
// Isolate the lockfile too — saveLockfileAssistant writes the prod lockfile
|
|
85
84
|
// (~/.cadet.lock.json) unless CADET_LOCKFILE_DIR is set, which would
|
|
86
85
|
// mutate the real user/CI lockfile.
|
|
87
86
|
process.env.CADET_LOCKFILE_DIR = tempHome;
|
|
@@ -130,24 +129,6 @@ describe("maybeRefreshAuthHeaders", () => {
|
|
|
130
129
|
expect(refresh.hit()).toBe(false); // no refresh POST anywhere
|
|
131
130
|
});
|
|
132
131
|
|
|
133
|
-
test("refreshes against the matched persisted URL, keeping the session's interface", async () => {
|
|
134
|
-
// When an entry persists both a loopback localUrl and a different
|
|
135
|
-
// runtimeUrl, a session on the loopback URL must refresh against THAT URL,
|
|
136
|
-
// not the external runtimeUrl (which may be unreachable / public-facing).
|
|
137
|
-
const localUrl = "http://127.0.0.1:7830";
|
|
138
|
-
seedEntry("paired", localUrl); // runtimeUrl = RUNTIME (10.0.0.9), localUrl = loopback
|
|
139
|
-
seedToken("old-acc", "ref");
|
|
140
|
-
const refresh = stubRefresh(true);
|
|
141
|
-
const auth = { Authorization: "Bearer old-acc" };
|
|
142
|
-
|
|
143
|
-
const ok = await maybeRefreshAuthHeaders(localUrl, "px", auth);
|
|
144
|
-
|
|
145
|
-
expect(ok).toBe(true);
|
|
146
|
-
expect(refresh.hit()).toBe(true);
|
|
147
|
-
expect(refresh.url()).toContain("127.0.0.1");
|
|
148
|
-
expect(refresh.url()).not.toContain("10.0.0.9");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
132
|
test("does NOT refresh a local assistant (scoped to paired only)", async () => {
|
|
152
133
|
seedEntry("local");
|
|
153
134
|
seedToken("old-acc", "ref"); // even with a refreshable token
|
|
@@ -18,7 +18,7 @@ import * as ngrok from "../lib/tunnels/ngrok.js";
|
|
|
18
18
|
import { tunnel } from "../commands/tunnel.js";
|
|
19
19
|
import {
|
|
20
20
|
readRootProcesses,
|
|
21
|
-
|
|
21
|
+
saveLockfileAssistant,
|
|
22
22
|
stampRootProcess,
|
|
23
23
|
} from "../lib/assistant-config.js";
|
|
24
24
|
|
|
@@ -39,7 +39,7 @@ beforeEach(() => {
|
|
|
39
39
|
mkdirSync(workspace, { recursive: true });
|
|
40
40
|
process.env.CADET_LOCKFILE_DIR = root;
|
|
41
41
|
process.env.XDG_CONFIG_HOME = root;
|
|
42
|
-
|
|
42
|
+
saveLockfileAssistant({
|
|
43
43
|
assistantId: "fixture",
|
|
44
44
|
name: "fixture",
|
|
45
45
|
cloud: "local",
|
|
@@ -49,7 +49,6 @@ beforeEach(() => {
|
|
|
49
49
|
gatewayPort: 7830,
|
|
50
50
|
daemonPort: 7821,
|
|
51
51
|
cesPort: 8090,
|
|
52
|
-
qdrantPort: 6333,
|
|
53
52
|
},
|
|
54
53
|
});
|
|
55
54
|
writeFileSync(
|
|
@@ -34,7 +34,10 @@ import * as tailscaleTunnel from "../lib/tunnels/tailscale.js";
|
|
|
34
34
|
import { getLogDir } from "../lib/xdg-log.js";
|
|
35
35
|
import { saveIngressUrl } from "../lib/ingress-config.js";
|
|
36
36
|
import { stampRootProcess } from "../lib/assistant-config.js";
|
|
37
|
-
import
|
|
37
|
+
import {
|
|
38
|
+
getLocalInstanceDir,
|
|
39
|
+
type LockfileAssistant,
|
|
40
|
+
} from "../lib/assistant-config.js";
|
|
38
41
|
import { withPreconnect } from "./helpers/http.js";
|
|
39
42
|
|
|
40
43
|
const realCloudflareTunnel = { ...cloudflareTunnel };
|
|
@@ -131,7 +134,7 @@ const originalLockfileDir = process.env.CADET_LOCKFILE_DIR;
|
|
|
131
134
|
const originalWorkspaceDir = process.env.CADET_WORKSPACE_DIR;
|
|
132
135
|
const tempDirs: string[] = [];
|
|
133
136
|
|
|
134
|
-
function makeLocalEntry(assistantId = "assistant-1"):
|
|
137
|
+
function makeLocalEntry(assistantId = "assistant-1"): LockfileAssistant {
|
|
135
138
|
const instanceDir = mkdtempSync(join(tmpdir(), "cadet-tunnel-test-"));
|
|
136
139
|
tempDirs.push(instanceDir);
|
|
137
140
|
return {
|
|
@@ -142,13 +145,12 @@ function makeLocalEntry(assistantId = "assistant-1"): AssistantEntry {
|
|
|
142
145
|
instanceDir,
|
|
143
146
|
daemonPort: 7821,
|
|
144
147
|
gatewayPort: 7830,
|
|
145
|
-
qdrantPort: 6333,
|
|
146
148
|
cesPort: 7822,
|
|
147
149
|
},
|
|
148
150
|
};
|
|
149
151
|
}
|
|
150
152
|
|
|
151
|
-
function makeCloudEntry(assistantId = "cloud-1"):
|
|
153
|
+
function makeCloudEntry(assistantId = "cloud-1"): LockfileAssistant {
|
|
152
154
|
return {
|
|
153
155
|
assistantId,
|
|
154
156
|
runtimeUrl: `https://runtime.example.com/${assistantId}`,
|
|
@@ -157,7 +159,7 @@ function makeCloudEntry(assistantId = "cloud-1"): AssistantEntry {
|
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
/** A `hatch --remote docker` entry: local container gateway, no `resources`. */
|
|
160
|
-
function makeDockerEntry(assistantId = "docker-1"):
|
|
162
|
+
function makeDockerEntry(assistantId = "docker-1"): LockfileAssistant {
|
|
161
163
|
return {
|
|
162
164
|
assistantId,
|
|
163
165
|
runtimeUrl: "http://localhost:7930",
|
|
@@ -166,7 +168,7 @@ function makeDockerEntry(assistantId = "docker-1"): AssistantEntry {
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
/** A macOS-app-managed entry: local container gateway, no `resources`. */
|
|
169
|
-
function makeAppleContainerEntry(assistantId = "apple-1"):
|
|
171
|
+
function makeAppleContainerEntry(assistantId = "apple-1"): LockfileAssistant {
|
|
170
172
|
return {
|
|
171
173
|
assistantId,
|
|
172
174
|
runtimeUrl: "http://localhost:8030",
|
|
@@ -176,10 +178,10 @@ function makeAppleContainerEntry(assistantId = "apple-1"): AssistantEntry {
|
|
|
176
178
|
|
|
177
179
|
/** Seed a local entry's workspace config; returns that workspace dir. */
|
|
178
180
|
function writeEntryWorkspaceConfig(
|
|
179
|
-
entry:
|
|
181
|
+
entry: LockfileAssistant,
|
|
180
182
|
config: Record<string, unknown>,
|
|
181
183
|
): string {
|
|
182
|
-
const workspaceDir = join(entry.resources
|
|
184
|
+
const workspaceDir = join(getLocalInstanceDir(entry.resources), "workspace");
|
|
183
185
|
mkdirSync(workspaceDir, { recursive: true });
|
|
184
186
|
writeFileSync(
|
|
185
187
|
join(workspaceDir, "config.json"),
|
|
@@ -197,7 +199,7 @@ function useTempDefaultWorkspaceDir(): string {
|
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
function writeLockfile(
|
|
200
|
-
entryOrEntries:
|
|
202
|
+
entryOrEntries: LockfileAssistant | LockfileAssistant[],
|
|
201
203
|
activeAssistant?: string,
|
|
202
204
|
): void {
|
|
203
205
|
const entries = Array.isArray(entryOrEntries)
|
|
@@ -359,7 +361,10 @@ describe("app server targeting", () => {
|
|
|
359
361
|
|
|
360
362
|
const logs = await runTunnelCapturingLogs();
|
|
361
363
|
|
|
362
|
-
const workspaceDir = join(
|
|
364
|
+
const workspaceDir = join(
|
|
365
|
+
getLocalInstanceDir(entry.resources),
|
|
366
|
+
"workspace",
|
|
367
|
+
);
|
|
363
368
|
expect(ensureAppServerMock).toHaveBeenCalledWith({
|
|
364
369
|
assistantId: "assistant-1",
|
|
365
370
|
workspaceDir,
|
|
@@ -418,7 +423,10 @@ describe("app server targeting", () => {
|
|
|
418
423
|
|
|
419
424
|
const logs = await runTunnelCapturingLogs();
|
|
420
425
|
|
|
421
|
-
const workspaceDir = join(
|
|
426
|
+
const workspaceDir = join(
|
|
427
|
+
getLocalInstanceDir(local.resources),
|
|
428
|
+
"workspace",
|
|
429
|
+
);
|
|
422
430
|
expect(logs).toContain(
|
|
423
431
|
"Assistant 'cloud-1' runs on Cadet Cloud and needs no tunnel. " +
|
|
424
432
|
"Tunneling the local assistant 'assistant-1' instead.",
|
|
@@ -670,7 +678,7 @@ describe("app server targeting", () => {
|
|
|
670
678
|
expect(runCloudflareTunnelMock).toHaveBeenCalledWith({
|
|
671
679
|
port: EDGE_PORT,
|
|
672
680
|
assistantId: "assistant-1",
|
|
673
|
-
workspaceDir: join(entry.resources
|
|
681
|
+
workspaceDir: join(getLocalInstanceDir(entry.resources), "workspace"),
|
|
674
682
|
});
|
|
675
683
|
expect(runNgrokTunnelMock).not.toHaveBeenCalled();
|
|
676
684
|
});
|
|
@@ -697,7 +705,7 @@ describe("app server targeting", () => {
|
|
|
697
705
|
expect(runTailscaleTunnelMock).toHaveBeenCalledWith({
|
|
698
706
|
port: EDGE_PORT,
|
|
699
707
|
assistantId: "assistant-1",
|
|
700
|
-
workspaceDir: join(entry.resources
|
|
708
|
+
workspaceDir: join(getLocalInstanceDir(entry.resources), "workspace"),
|
|
701
709
|
});
|
|
702
710
|
expect(logs).toContain(`Reusing the nginx edge on 127.0.0.1:${EDGE_PORT}`);
|
|
703
711
|
});
|
|
@@ -713,7 +721,7 @@ describe("app server targeting", () => {
|
|
|
713
721
|
expect(runNgrokTunnelMock).toHaveBeenCalledWith({
|
|
714
722
|
port: EDGE_PORT,
|
|
715
723
|
assistantId: "assistant-1",
|
|
716
|
-
workspaceDir: join(entry.resources
|
|
724
|
+
workspaceDir: join(getLocalInstanceDir(entry.resources), "workspace"),
|
|
717
725
|
});
|
|
718
726
|
expect(ensureAppServerMock).toHaveBeenCalled();
|
|
719
727
|
expect(runTailscaleTunnelMock).not.toHaveBeenCalled();
|
|
@@ -904,7 +912,7 @@ describe("app server targeting", () => {
|
|
|
904
912
|
expect(runNgrokTunnelMock).toHaveBeenCalledWith({
|
|
905
913
|
port: EDGE_PORT,
|
|
906
914
|
assistantId: "assistant-1",
|
|
907
|
-
workspaceDir: join(entry.resources
|
|
915
|
+
workspaceDir: join(getLocalInstanceDir(entry.resources), "workspace"),
|
|
908
916
|
domain: "foo.ngrok.app",
|
|
909
917
|
});
|
|
910
918
|
});
|
|
@@ -935,7 +943,10 @@ describe("app server targeting", () => {
|
|
|
935
943
|
test("--clear-domain drops the saved domain and runs domainless", async () => {
|
|
936
944
|
const entry = makeLocalEntry();
|
|
937
945
|
writeLockfile(entry);
|
|
938
|
-
const workspaceDir = join(
|
|
946
|
+
const workspaceDir = join(
|
|
947
|
+
getLocalInstanceDir(entry.resources),
|
|
948
|
+
"workspace",
|
|
949
|
+
);
|
|
939
950
|
mkdirSync(workspaceDir, { recursive: true });
|
|
940
951
|
realNgrok.saveNgrokDomain("dead.ngrok.app");
|
|
941
952
|
process.argv = [
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
getStateDir,
|
|
21
21
|
} from "../lib/environments/paths.js";
|
|
22
22
|
import { getCurrentEnvironment } from "../lib/environments/resolve.js";
|
|
23
|
-
import
|
|
23
|
+
import { makeEntry } from "./helpers/lockfile-entry.js";
|
|
24
24
|
|
|
25
25
|
// The command reads its argv at call time.
|
|
26
26
|
const ORIGINAL_ARGV = process.argv;
|
|
@@ -73,21 +73,6 @@ function withRestoredEnv(run: () => Promise<void>): Promise<void> {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
function makeEntry(assistantId: string): AssistantEntry {
|
|
77
|
-
return {
|
|
78
|
-
assistantId,
|
|
79
|
-
runtimeUrl: "http://127.0.0.1:7801",
|
|
80
|
-
cloud: "local",
|
|
81
|
-
resources: {
|
|
82
|
-
instanceDir: join(tmpdir(), "cadet-uninstall-instance"),
|
|
83
|
-
daemonPort: 7801,
|
|
84
|
-
gatewayPort: 7831,
|
|
85
|
-
qdrantPort: 6334,
|
|
86
|
-
cesPort: 7790,
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
76
|
describe("cadet uninstall", () => {
|
|
92
77
|
const logSpy = spyOn(console, "log").mockImplementation(() => {});
|
|
93
78
|
const errorSpy = spyOn(console, "error").mockImplementation(() => {});
|
|
@@ -122,13 +107,17 @@ describe("cadet uninstall", () => {
|
|
|
122
107
|
// blocked the uninstall; the fs sweep deletes the archives anyway).
|
|
123
108
|
writeFileSync(
|
|
124
109
|
join(process.env.CADET_LOCKFILE_DIR!, "lockfile.json"),
|
|
125
|
-
JSON.stringify({
|
|
110
|
+
JSON.stringify({
|
|
111
|
+
assistants: [makeEntry({ assistantId: "test-assistant" })],
|
|
112
|
+
}) + "\n",
|
|
126
113
|
);
|
|
127
114
|
|
|
128
115
|
const exitMock = spyOn(process, "exit");
|
|
129
|
-
exitMock.mockImplementation(
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
exitMock.mockImplementation(
|
|
117
|
+
(code?: number | string | undefined): never => {
|
|
118
|
+
throw new Error(`process.exit:${code}`);
|
|
119
|
+
},
|
|
120
|
+
);
|
|
132
121
|
try {
|
|
133
122
|
// Non-interactive without --yes, the CONFIRM gate is what refuses —
|
|
134
123
|
// not an assistant guard.
|
|
@@ -154,9 +143,11 @@ describe("cadet uninstall", () => {
|
|
|
154
143
|
const root = redirectXdg();
|
|
155
144
|
|
|
156
145
|
const exitMock = spyOn(process, "exit");
|
|
157
|
-
exitMock.mockImplementation(
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
exitMock.mockImplementation(
|
|
147
|
+
(code?: number | string | undefined): never => {
|
|
148
|
+
throw new Error(`process.exit:${code}`);
|
|
149
|
+
},
|
|
150
|
+
);
|
|
160
151
|
try {
|
|
161
152
|
process.argv = ["bun", "cadet", "uninstall"];
|
|
162
153
|
await expect(uninstall()).rejects.toThrow("process.exit:1");
|
|
@@ -176,14 +167,21 @@ describe("cadet uninstall", () => {
|
|
|
176
167
|
writeFileSync(
|
|
177
168
|
join(process.env.CADET_LOCKFILE_DIR!, "lockfile.json"),
|
|
178
169
|
JSON.stringify({
|
|
179
|
-
assistants: [
|
|
170
|
+
assistants: [
|
|
171
|
+
{
|
|
172
|
+
...makeEntry({ assistantId: "docker-assistant" }),
|
|
173
|
+
cloud: "docker",
|
|
174
|
+
},
|
|
175
|
+
],
|
|
180
176
|
}) + "\n",
|
|
181
177
|
);
|
|
182
178
|
|
|
183
179
|
const exitMock = spyOn(process, "exit");
|
|
184
|
-
exitMock.mockImplementation(
|
|
185
|
-
|
|
186
|
-
|
|
180
|
+
exitMock.mockImplementation(
|
|
181
|
+
(code?: number | string | undefined): never => {
|
|
182
|
+
throw new Error(`process.exit:${code}`);
|
|
183
|
+
},
|
|
184
|
+
);
|
|
187
185
|
try {
|
|
188
186
|
process.argv = ["bun", "cadet", "uninstall"];
|
|
189
187
|
await expect(uninstall()).rejects.toThrow("process.exit:1");
|
|
@@ -204,7 +202,12 @@ describe("cadet uninstall", () => {
|
|
|
204
202
|
writeFileSync(
|
|
205
203
|
join(process.env.CADET_LOCKFILE_DIR!, "lockfile.json"),
|
|
206
204
|
JSON.stringify({
|
|
207
|
-
assistants: [
|
|
205
|
+
assistants: [
|
|
206
|
+
{
|
|
207
|
+
...makeEntry({ assistantId: "docker-assistant" }),
|
|
208
|
+
cloud: "docker",
|
|
209
|
+
},
|
|
210
|
+
],
|
|
208
211
|
}) + "\n",
|
|
209
212
|
);
|
|
210
213
|
mkdirSync(getConfigDirs(getCurrentEnvironment())[0]!, {
|
|
@@ -13,7 +13,10 @@ import { tmpdir } from "node:os";
|
|
|
13
13
|
import { join } from "node:path";
|
|
14
14
|
|
|
15
15
|
import cliPkg from "../../package.json";
|
|
16
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
getLocalInstanceDir,
|
|
18
|
+
type LockfileAssistant,
|
|
19
|
+
} from "../lib/assistant-config.js";
|
|
17
20
|
import * as assistantConfig from "../lib/assistant-config.js";
|
|
18
21
|
import * as backupOps from "../lib/backup-ops.js";
|
|
19
22
|
import type { GuardianTokenData } from "../lib/guardian-token.js";
|
|
@@ -41,9 +44,9 @@ const getActiveAssistantMock = mock<typeof assistantConfig.getActiveAssistant>(
|
|
|
41
44
|
const loadAllAssistantsMock = mock<typeof assistantConfig.loadAllAssistants>(
|
|
42
45
|
() => [],
|
|
43
46
|
);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
+
const saveLockfileAssistantMock = mock<
|
|
48
|
+
typeof assistantConfig.saveLockfileAssistant
|
|
49
|
+
>(() => {});
|
|
47
50
|
|
|
48
51
|
mock.module("../lib/assistant-config", () => ({
|
|
49
52
|
...realAssistantConfig,
|
|
@@ -51,7 +54,7 @@ mock.module("../lib/assistant-config", () => ({
|
|
|
51
54
|
lookupAssistantByIdentifier: lookupAssistantByIdentifierMock,
|
|
52
55
|
getActiveAssistant: getActiveAssistantMock,
|
|
53
56
|
loadAllAssistants: loadAllAssistantsMock,
|
|
54
|
-
|
|
57
|
+
saveLockfileAssistant: saveLockfileAssistantMock,
|
|
55
58
|
}));
|
|
56
59
|
|
|
57
60
|
const createBackupMock = mock<typeof backupOps.createBackup>(
|
|
@@ -110,7 +113,7 @@ const generateLocalSigningKeyMock = mock<typeof local.generateLocalSigningKey>(
|
|
|
110
113
|
const ensureLocalRuntimeMock = mock<typeof local.ensureLocalRuntime>(
|
|
111
114
|
(resources, version) => ({
|
|
112
115
|
version,
|
|
113
|
-
installDir: join(resources
|
|
116
|
+
installDir: join(getLocalInstanceDir(resources), "runtime", version),
|
|
114
117
|
}),
|
|
115
118
|
);
|
|
116
119
|
const startLocalDaemonMock = mock<typeof local.startLocalDaemon>(
|
|
@@ -189,7 +192,7 @@ let consoleWarnSpy: ReturnType<typeof spyOn>;
|
|
|
189
192
|
let consoleErrorSpy: ReturnType<typeof spyOn>;
|
|
190
193
|
let exitSpy: ReturnType<typeof spyOn>;
|
|
191
194
|
|
|
192
|
-
function makeLocalEntry():
|
|
195
|
+
function makeLocalEntry(): LockfileAssistant {
|
|
193
196
|
tempDir = mkdtempSync(join(tmpdir(), "cadet-upgrade-local-test-"));
|
|
194
197
|
return {
|
|
195
198
|
assistantId: "local-assistant",
|
|
@@ -199,7 +202,6 @@ function makeLocalEntry(): AssistantEntry {
|
|
|
199
202
|
instanceDir: tempDir,
|
|
200
203
|
daemonPort: 7821,
|
|
201
204
|
gatewayPort: 7830,
|
|
202
|
-
qdrantPort: 6333,
|
|
203
205
|
cesPort: 7822,
|
|
204
206
|
signingKey: "ab".repeat(32),
|
|
205
207
|
},
|
|
@@ -210,6 +212,11 @@ function makeLocalEntry(): AssistantEntry {
|
|
|
210
212
|
beforeEach(() => {
|
|
211
213
|
originalArgv = [...process.argv];
|
|
212
214
|
tempDir = "";
|
|
215
|
+
assistantConfig.stampRootProcess("tunnel", {
|
|
216
|
+
pid: 4321,
|
|
217
|
+
provider: "ngrok",
|
|
218
|
+
startedAt: new Date().toISOString(),
|
|
219
|
+
});
|
|
213
220
|
process.argv = [
|
|
214
221
|
"bun",
|
|
215
222
|
"cadet",
|
|
@@ -235,7 +242,7 @@ beforeEach(() => {
|
|
|
235
242
|
getActiveAssistantMock.mockReturnValue("local-assistant");
|
|
236
243
|
loadAllAssistantsMock.mockReset();
|
|
237
244
|
loadAllAssistantsMock.mockReturnValue([entry]);
|
|
238
|
-
|
|
245
|
+
saveLockfileAssistantMock.mockReset();
|
|
239
246
|
createBackupMock.mockReset();
|
|
240
247
|
createBackupMock.mockResolvedValue("/tmp/local-pre-upgrade.tar.gz");
|
|
241
248
|
pruneOldBackupsMock.mockReset();
|
|
@@ -253,7 +260,7 @@ beforeEach(() => {
|
|
|
253
260
|
ensureLocalRuntimeMock.mockReset();
|
|
254
261
|
ensureLocalRuntimeMock.mockImplementation((resources, version) => ({
|
|
255
262
|
version,
|
|
256
|
-
installDir: join(resources
|
|
263
|
+
installDir: join(getLocalInstanceDir(resources), "runtime", version),
|
|
257
264
|
}));
|
|
258
265
|
startLocalDaemonMock.mockReset();
|
|
259
266
|
startLocalDaemonMock.mockResolvedValue(undefined);
|
|
@@ -316,7 +323,7 @@ describe("cadet upgrade local", () => {
|
|
|
316
323
|
expect(startGatewayMock).not.toHaveBeenCalled();
|
|
317
324
|
expect(generateLocalSigningKeyMock).not.toHaveBeenCalled();
|
|
318
325
|
expect(resetGuardianBootstrapMock).not.toHaveBeenCalled();
|
|
319
|
-
expect(
|
|
326
|
+
expect(saveLockfileAssistantMock).not.toHaveBeenCalled();
|
|
320
327
|
});
|
|
321
328
|
|
|
322
329
|
test("uses explicit target versions as-is", async () => {
|
|
@@ -450,9 +457,16 @@ describe("cadet upgrade local", () => {
|
|
|
450
457
|
});
|
|
451
458
|
|
|
452
459
|
test("failed target startup restores prior runtime selection and all roots before restarting", async () => {
|
|
453
|
-
startLocalDaemonMock.mockRejectedValueOnce(
|
|
460
|
+
startLocalDaemonMock.mockRejectedValueOnce(
|
|
461
|
+
new Error("target startup failed"),
|
|
462
|
+
);
|
|
454
463
|
await expect(upgrade()).rejects.toThrow("process.exit(1)");
|
|
455
|
-
expect(restoreBackupMock).toHaveBeenCalledWith(
|
|
464
|
+
expect(restoreBackupMock).toHaveBeenCalledWith(
|
|
465
|
+
"http://127.0.0.1:7830",
|
|
466
|
+
"local-assistant",
|
|
467
|
+
"/tmp/local-pre-upgrade.tar.gz",
|
|
468
|
+
{ resume: false },
|
|
469
|
+
);
|
|
456
470
|
expect(startLocalDaemonMock).toHaveBeenCalledTimes(2);
|
|
457
471
|
expect(startCesMock).toHaveBeenCalledTimes(2);
|
|
458
472
|
expect(stopLocalProcessesMock).toHaveBeenCalledTimes(2);
|
|
@@ -488,8 +502,8 @@ describe("cadet upgrade local", () => {
|
|
|
488
502
|
// lookup rules themselves.
|
|
489
503
|
describe("cadet upgrade assistant targeting", () => {
|
|
490
504
|
function makeQuillEntry(
|
|
491
|
-
overrides: Partial<
|
|
492
|
-
):
|
|
505
|
+
overrides: Partial<LockfileAssistant> = {},
|
|
506
|
+
): LockfileAssistant {
|
|
493
507
|
return {
|
|
494
508
|
...makeLocalEntry(),
|
|
495
509
|
assistantId: "quill-uuid",
|
|
@@ -10,7 +10,7 @@ const capture = spyOn(backups, "createBackup");
|
|
|
10
10
|
const images = spyOn(docker, "captureImageRefs");
|
|
11
11
|
const pull = spyOn(docker, "pullImage");
|
|
12
12
|
const wake = spyOn(docker, "wakeContainers");
|
|
13
|
-
const save = spyOn(config, "
|
|
13
|
+
const save = spyOn(config, "saveLockfileAssistant");
|
|
14
14
|
const restore = spyOn(backups, "restoreBackup");
|
|
15
15
|
const sleep = spyOn(docker, "sleepContainers");
|
|
16
16
|
const stop = spyOn(docker, "stopContainers");
|
|
@@ -128,7 +128,7 @@ test("versioned restore installs roots into stopped target containers before fir
|
|
|
128
128
|
stdout: JSON.stringify(["ACTOR_TOKEN_SIGNING_KEY=" + "01".repeat(32)]),
|
|
129
129
|
}),
|
|
130
130
|
);
|
|
131
|
-
const entry: config.
|
|
131
|
+
const entry: config.LockfileAssistant = {
|
|
132
132
|
assistantId: "recovery",
|
|
133
133
|
cloud: "docker",
|
|
134
134
|
runtimeUrl: "http://127.0.0.1:1",
|
|
@@ -13,9 +13,10 @@ import { join } from "node:path";
|
|
|
13
13
|
|
|
14
14
|
import {
|
|
15
15
|
getActiveAssistant,
|
|
16
|
-
type
|
|
16
|
+
type LockfileAssistant,
|
|
17
17
|
} from "../lib/assistant-config.js";
|
|
18
18
|
import { use } from "../commands/use.js";
|
|
19
|
+
import { makeEntry } from "./helpers/lockfile-entry.js";
|
|
19
20
|
|
|
20
21
|
const testDir = mkdtempSync(join(tmpdir(), "cli-use-test-"));
|
|
21
22
|
const originalArgv = [...process.argv];
|
|
@@ -25,20 +26,8 @@ const originalLockfileDir = process.env.CADET_LOCKFILE_DIR;
|
|
|
25
26
|
let consoleLogSpy: ReturnType<typeof spyOn>;
|
|
26
27
|
let consoleErrorSpy: ReturnType<typeof spyOn>;
|
|
27
28
|
|
|
28
|
-
function makeEntry(
|
|
29
|
-
assistantId: string,
|
|
30
|
-
extra: Partial<AssistantEntry> = {},
|
|
31
|
-
): AssistantEntry {
|
|
32
|
-
return {
|
|
33
|
-
assistantId,
|
|
34
|
-
runtimeUrl: `http://localhost:${7800 + assistantId.length}`,
|
|
35
|
-
cloud: "local",
|
|
36
|
-
...extra,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
29
|
function writeLockfile(
|
|
41
|
-
entries:
|
|
30
|
+
entries: LockfileAssistant[],
|
|
42
31
|
activeAssistant?: string,
|
|
43
32
|
): void {
|
|
44
33
|
mkdirSync(testDir, { recursive: true });
|
|
@@ -85,8 +74,8 @@ describe("cadet use", () => {
|
|
|
85
74
|
|
|
86
75
|
test("sets active assistant by unique display name", async () => {
|
|
87
76
|
writeLockfile([
|
|
88
|
-
makeEntry("assistant-1",
|
|
89
|
-
makeEntry("assistant-2",
|
|
77
|
+
makeEntry({ assistantId: "assistant-1", name: "Alice" }),
|
|
78
|
+
makeEntry({ assistantId: "assistant-2", name: "Bob" }),
|
|
90
79
|
]);
|
|
91
80
|
process.argv = ["bun", "cadet", "use", "Alice"];
|
|
92
81
|
|
|
@@ -94,14 +83,14 @@ describe("cadet use", () => {
|
|
|
94
83
|
|
|
95
84
|
expect(getActiveAssistant()).toBe("assistant-1");
|
|
96
85
|
expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
|
|
97
|
-
"Active assistant set to Alice
|
|
86
|
+
"Active assistant set to Alice.",
|
|
98
87
|
);
|
|
99
88
|
});
|
|
100
89
|
|
|
101
90
|
test("sets active assistant by unquoted multi-word display name", async () => {
|
|
102
91
|
writeLockfile([
|
|
103
|
-
makeEntry("assistant-1",
|
|
104
|
-
makeEntry("assistant-2",
|
|
92
|
+
makeEntry({ assistantId: "assistant-1", name: "Example Assistant" }),
|
|
93
|
+
makeEntry({ assistantId: "assistant-2", name: "Bob" }),
|
|
105
94
|
]);
|
|
106
95
|
process.argv = ["bun", "cadet", "use", "Example", "Assistant"];
|
|
107
96
|
|
|
@@ -109,25 +98,28 @@ describe("cadet use", () => {
|
|
|
109
98
|
|
|
110
99
|
expect(getActiveAssistant()).toBe("assistant-1");
|
|
111
100
|
expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
|
|
112
|
-
"Active assistant set to Example Assistant
|
|
101
|
+
"Active assistant set to Example Assistant.",
|
|
113
102
|
);
|
|
114
103
|
});
|
|
115
104
|
|
|
116
105
|
test("prints active assistant with display name and id", async () => {
|
|
117
|
-
writeLockfile(
|
|
106
|
+
writeLockfile(
|
|
107
|
+
[makeEntry({ assistantId: "assistant-1", name: "Alice" })],
|
|
108
|
+
"assistant-1",
|
|
109
|
+
);
|
|
118
110
|
|
|
119
111
|
await use();
|
|
120
112
|
|
|
121
113
|
expect(consoleLogSpy.mock.calls.flat().join("\n")).toContain(
|
|
122
|
-
"Active assistant: Alice
|
|
114
|
+
"Active assistant: Alice",
|
|
123
115
|
);
|
|
124
116
|
});
|
|
125
117
|
|
|
126
118
|
test("rejects ambiguous display names without changing active assistant", async () => {
|
|
127
119
|
writeLockfile(
|
|
128
120
|
[
|
|
129
|
-
makeEntry("assistant-1",
|
|
130
|
-
makeEntry("assistant-2",
|
|
121
|
+
makeEntry({ assistantId: "assistant-1", name: "Alice" }),
|
|
122
|
+
makeEntry({ assistantId: "assistant-2", name: "Alice" }),
|
|
131
123
|
],
|
|
132
124
|
"assistant-2",
|
|
133
125
|
);
|