@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
|
@@ -22,9 +22,13 @@ import { homedir, tmpdir } from "node:os";
|
|
|
22
22
|
import * as osModule from "node:os";
|
|
23
23
|
import { basename, join } from "node:path";
|
|
24
24
|
|
|
25
|
-
import
|
|
25
|
+
import {
|
|
26
|
+
getLocalInstanceDir,
|
|
27
|
+
type LockfileAssistant,
|
|
28
|
+
} from "../lib/assistant-config.js";
|
|
26
29
|
import * as localModule from "../lib/local.js";
|
|
27
30
|
import * as stepRunnerModule from "../lib/step-runner.js";
|
|
31
|
+
import { makeEntry } from "./helpers/lockfile-entry.js";
|
|
28
32
|
|
|
29
33
|
// Captured real exports — afterAll restores these so module mocks don't
|
|
30
34
|
// leak into other test files in the same `bun test` run.
|
|
@@ -73,26 +77,9 @@ const originalXdgData = process.env.XDG_DATA_HOME;
|
|
|
73
77
|
// Directories that getRetiredDir() will use when XDG_DATA_HOME is overridden
|
|
74
78
|
const retiredDir = join(testDir, "cadet", "retired");
|
|
75
79
|
|
|
76
|
-
function makeEntry(assistantId: string, instanceDir: string): AssistantEntry {
|
|
77
|
-
return {
|
|
78
|
-
assistantId,
|
|
79
|
-
runtimeUrl: "http://127.0.0.1:7831",
|
|
80
|
-
cloud: "local",
|
|
81
|
-
guardianBootstrapSecret: "existing-bootstrap",
|
|
82
|
-
resources: {
|
|
83
|
-
instanceDir,
|
|
84
|
-
daemonPort: 7801,
|
|
85
|
-
gatewayPort: 7831,
|
|
86
|
-
qdrantPort: 6334,
|
|
87
|
-
cesPort: 7790,
|
|
88
|
-
signingKey: "ab".repeat(32),
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
80
|
function writeArchiveFixtures(
|
|
94
81
|
name: string,
|
|
95
|
-
entry:
|
|
82
|
+
entry: LockfileAssistant,
|
|
96
83
|
): {
|
|
97
84
|
archivePath: string;
|
|
98
85
|
metadataPath: string;
|
|
@@ -124,7 +111,7 @@ beforeEach(() => {
|
|
|
124
111
|
// Route lockfile and retired archives to the temp directory
|
|
125
112
|
process.env.CADET_LOCKFILE_DIR = testDir;
|
|
126
113
|
process.env.XDG_DATA_HOME = testDir;
|
|
127
|
-
// Write an empty lockfile so
|
|
114
|
+
// Write an empty lockfile so saveLockfileAssistant has a dir to write to
|
|
128
115
|
mkdirSync(testDir, { recursive: true });
|
|
129
116
|
writeFileSync(
|
|
130
117
|
resolveLockfilePaths(process.env)[0]!,
|
|
@@ -192,7 +179,10 @@ describe("restore error cases", () => {
|
|
|
192
179
|
test(`recovery ${failure} leaves destination and registry untouched and permits retry`, async () => {
|
|
193
180
|
const name = `retry-${failure}`;
|
|
194
181
|
const instanceDir = join(testDir, "cadet", "assistants", name);
|
|
195
|
-
const entry = makeEntry(
|
|
182
|
+
const entry = makeEntry({
|
|
183
|
+
assistantId: name,
|
|
184
|
+
resources: { instanceDir },
|
|
185
|
+
});
|
|
196
186
|
delete entry.resources!.signingKey;
|
|
197
187
|
const { archivePath, metadataPath, extractedPath } = writeArchiveFixtures(
|
|
198
188
|
name,
|
|
@@ -233,7 +223,11 @@ describe("restore error cases", () => {
|
|
|
233
223
|
|
|
234
224
|
test("recovers an archived legacy identity from staging", async () => {
|
|
235
225
|
const name = "legacy-staged";
|
|
236
|
-
const entry = makeEntry(
|
|
226
|
+
const entry = makeEntry({
|
|
227
|
+
guardianBootstrapSecret: "existing-bootstrap",
|
|
228
|
+
assistantId: name,
|
|
229
|
+
resources: { instanceDir: join(testDir, "cadet", "assistants", name) },
|
|
230
|
+
});
|
|
237
231
|
delete entry.resources!.signingKey;
|
|
238
232
|
const { extractedPath } = writeArchiveFixtures(name, entry);
|
|
239
233
|
const dir = join(extractedPath, "workspace", "deprecated");
|
|
@@ -249,12 +243,18 @@ describe("restore error cases", () => {
|
|
|
249
243
|
expect.objectContaining({ signingKey: "cd".repeat(32) }),
|
|
250
244
|
{ signingKey: "cd".repeat(32), bootstrapSecret: "existing-bootstrap" },
|
|
251
245
|
);
|
|
252
|
-
rmSync(entry.resources
|
|
246
|
+
rmSync(getLocalInstanceDir(entry.resources), {
|
|
247
|
+
recursive: true,
|
|
248
|
+
force: true,
|
|
249
|
+
});
|
|
253
250
|
});
|
|
254
251
|
|
|
255
252
|
test("missing identity preserves the archive and starts no processes", async () => {
|
|
256
253
|
const name = "missing-key";
|
|
257
|
-
const entry = makeEntry(
|
|
254
|
+
const entry = makeEntry({
|
|
255
|
+
assistantId: name,
|
|
256
|
+
resources: { instanceDir: join(testDir, "cadet", "assistants", name) },
|
|
257
|
+
});
|
|
258
258
|
delete entry.resources!.signingKey;
|
|
259
259
|
const { archivePath, metadataPath } = writeArchiveFixtures(name, entry);
|
|
260
260
|
process.argv = ["bun", "cadet", "restore", name];
|
|
@@ -283,7 +283,7 @@ describe("restore error cases", () => {
|
|
|
283
283
|
const name = "no-resources";
|
|
284
284
|
mkdirSync(retiredDir, { recursive: true });
|
|
285
285
|
writeFileSync(join(retiredDir, `${name}.tar.gz`), "");
|
|
286
|
-
const entry: Partial<
|
|
286
|
+
const entry: Partial<LockfileAssistant> = {
|
|
287
287
|
assistantId: name,
|
|
288
288
|
runtimeUrl: "http://127.0.0.1:7831",
|
|
289
289
|
cloud: "local",
|
|
@@ -300,7 +300,7 @@ describe("restore error cases", () => {
|
|
|
300
300
|
test("exits 1 when target .cadet/ already exists", async () => {
|
|
301
301
|
const name = "already-exists";
|
|
302
302
|
const instanceDir = join(testDir, name);
|
|
303
|
-
const entry = makeEntry(name, instanceDir);
|
|
303
|
+
const entry = makeEntry({ assistantId: name, resources: { instanceDir } });
|
|
304
304
|
writeArchiveFixtures(name, entry);
|
|
305
305
|
// Pre-create the collision path that recover checks
|
|
306
306
|
mkdirSync(join(instanceDir, ".cadet"), { recursive: true });
|
|
@@ -314,7 +314,11 @@ describe("archive-recovery extraction path — named instance (instanceDir !== h
|
|
|
314
314
|
test("extracts to retiredDir and renames staging dir to instanceDir directly", async () => {
|
|
315
315
|
const name = "named-instance";
|
|
316
316
|
const instanceDir = join(testDir, "custom-location", name);
|
|
317
|
-
const entry = makeEntry(
|
|
317
|
+
const entry = makeEntry({
|
|
318
|
+
assistantId: name,
|
|
319
|
+
guardianBootstrapSecret: "existing-bootstrap",
|
|
320
|
+
resources: { instanceDir },
|
|
321
|
+
});
|
|
318
322
|
const { archivePath, extractedPath } = writeArchiveFixtures(name, entry);
|
|
319
323
|
|
|
320
324
|
// Named instance: targetDir is instanceDir itself (not instanceDir/.cadet)
|
|
@@ -353,7 +357,7 @@ describe("archive-recovery extraction path — named instance (instanceDir !== h
|
|
|
353
357
|
const name = "deep-nested-instance";
|
|
354
358
|
// Use a path whose parent directory does not yet exist
|
|
355
359
|
const instanceDir = join(testDir, "new-parent", "deeper", name);
|
|
356
|
-
const entry = makeEntry(name, instanceDir);
|
|
360
|
+
const entry = makeEntry({ assistantId: name, resources: { instanceDir } });
|
|
357
361
|
const { archivePath, extractedPath } = writeArchiveFixtures(name, entry);
|
|
358
362
|
|
|
359
363
|
process.argv = ["bun", "cadet", "restore", name];
|
|
@@ -14,10 +14,11 @@ import { join } from "node:path";
|
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
16
|
getDaemonPidPath,
|
|
17
|
-
type
|
|
17
|
+
type LockfileAssistant,
|
|
18
18
|
} from "../lib/assistant-config.js";
|
|
19
19
|
import { getLockfilePath } from "../lib/environments/paths.js";
|
|
20
20
|
import { getCurrentEnvironment } from "../lib/environments/resolve.js";
|
|
21
|
+
import { makeEntry } from "./helpers/lockfile-entry.js";
|
|
21
22
|
|
|
22
23
|
const testDir = mkdtempSync(join(tmpdir(), "retire-local-test-"));
|
|
23
24
|
const originalLockfileDir = process.env.CADET_LOCKFILE_DIR;
|
|
@@ -77,22 +78,7 @@ import { getRetireArchiveCommand, retireLocal } from "../lib/retire-local.js";
|
|
|
77
78
|
|
|
78
79
|
const instanceDir = join(testDir, "test-instance");
|
|
79
80
|
|
|
80
|
-
function
|
|
81
|
-
return {
|
|
82
|
-
assistantId,
|
|
83
|
-
runtimeUrl: "http://127.0.0.1:7801",
|
|
84
|
-
cloud: "local",
|
|
85
|
-
resources: {
|
|
86
|
-
instanceDir,
|
|
87
|
-
daemonPort: 7801,
|
|
88
|
-
gatewayPort: 7831,
|
|
89
|
-
qdrantPort: 6334,
|
|
90
|
-
cesPort: 7790,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function writeLockfile(entries: AssistantEntry[]): void {
|
|
81
|
+
function writeLockfile(entries: LockfileAssistant[]): void {
|
|
96
82
|
writeFileSync(
|
|
97
83
|
getLockfilePath(getCurrentEnvironment()),
|
|
98
84
|
JSON.stringify({ assistants: entries }, null, 2) + "\n",
|
|
@@ -115,7 +101,7 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
115
101
|
rmSync(instanceDir, { recursive: true, force: true });
|
|
116
102
|
rmSync(join(testDir, "retired"), { recursive: true, force: true });
|
|
117
103
|
mkdirSync(instanceDir, { recursive: true });
|
|
118
|
-
writeLockfile([makeEntry("test-assistant")]);
|
|
104
|
+
writeLockfile([makeEntry({ assistantId: "test-assistant" })]);
|
|
119
105
|
|
|
120
106
|
// Suppress console output from the lifecycle reporter.
|
|
121
107
|
spyOn(console, "log").mockImplementation(() => {});
|
|
@@ -132,7 +118,10 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
132
118
|
});
|
|
133
119
|
|
|
134
120
|
test("stops the CES sibling alongside daemon and gateway", async () => {
|
|
135
|
-
const entry = makeEntry(
|
|
121
|
+
const entry = makeEntry({
|
|
122
|
+
assistantId: "test-assistant",
|
|
123
|
+
resources: { instanceDir },
|
|
124
|
+
});
|
|
136
125
|
await retireLocal("test-assistant", entry, {
|
|
137
126
|
progress: () => {},
|
|
138
127
|
log: () => {},
|
|
@@ -165,7 +154,7 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
165
154
|
// default in stopProcess would SIGKILL it first, stranding those workers as
|
|
166
155
|
// orphans that outlive the runtime that spawned them.
|
|
167
156
|
test("gives the daemon its full stop budget, not the default grace", async () => {
|
|
168
|
-
const entry = makeEntry("test-assistant");
|
|
157
|
+
const entry = makeEntry({ assistantId: "test-assistant" });
|
|
169
158
|
await retireLocal("test-assistant", entry, {
|
|
170
159
|
progress: () => {},
|
|
171
160
|
log: () => {},
|
|
@@ -193,7 +182,10 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
193
182
|
},
|
|
194
183
|
);
|
|
195
184
|
|
|
196
|
-
const entry = makeEntry(
|
|
185
|
+
const entry = makeEntry({
|
|
186
|
+
assistantId: "test-assistant",
|
|
187
|
+
resources: { instanceDir },
|
|
188
|
+
});
|
|
197
189
|
await retireLocal("test-assistant", entry, {
|
|
198
190
|
progress: () => {},
|
|
199
191
|
log: () => {},
|
|
@@ -212,7 +204,7 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
212
204
|
|
|
213
205
|
test("protects other assistants during orphan cleanup", async () => {
|
|
214
206
|
const otherInstanceDir = join(testDir, "other-instance");
|
|
215
|
-
const otherEntry = makeEntry("other-assistant");
|
|
207
|
+
const otherEntry = makeEntry({ assistantId: "other-assistant" });
|
|
216
208
|
otherEntry.resources!.instanceDir = otherInstanceDir;
|
|
217
209
|
const otherPid = "4242";
|
|
218
210
|
const otherPidFile = getDaemonPidPath(otherEntry.resources);
|
|
@@ -220,18 +212,22 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
220
212
|
recursive: true,
|
|
221
213
|
});
|
|
222
214
|
writeFileSync(otherPidFile, otherPid);
|
|
223
|
-
writeLockfile([makeEntry("test-assistant"), otherEntry]);
|
|
215
|
+
writeLockfile([makeEntry({ assistantId: "test-assistant" }), otherEntry]);
|
|
224
216
|
stopProcessByPidFileMock.mockImplementation(
|
|
225
217
|
async (_pidFile: string, label: string): Promise<boolean> =>
|
|
226
218
|
label !== "daemon",
|
|
227
219
|
);
|
|
228
220
|
|
|
229
|
-
await retireLocal(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
221
|
+
await retireLocal(
|
|
222
|
+
"test-assistant",
|
|
223
|
+
makeEntry({ assistantId: "test-assistant" }),
|
|
224
|
+
{
|
|
225
|
+
progress: () => {},
|
|
226
|
+
log: () => {},
|
|
227
|
+
warn: () => {},
|
|
228
|
+
error: () => {},
|
|
229
|
+
},
|
|
230
|
+
);
|
|
235
231
|
|
|
236
232
|
expect(stopOrphanedDaemonProcessesMock).toHaveBeenCalledTimes(1);
|
|
237
233
|
const excludedPids = stopOrphanedDaemonProcessesMock.mock.calls[0]?.[0];
|
|
@@ -18,11 +18,12 @@ import {
|
|
|
18
18
|
import { tmpdir } from "node:os";
|
|
19
19
|
import { join } from "node:path";
|
|
20
20
|
|
|
21
|
-
import type {
|
|
21
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
22
22
|
import { loadAllAssistants } from "../lib/assistant-config.js";
|
|
23
23
|
import * as loopbackFetchModule from "../lib/loopback-fetch.js";
|
|
24
24
|
import * as cloudClientModule from "../lib/cloud-client.js";
|
|
25
25
|
import * as retireLocalModule from "../lib/retire-local.js";
|
|
26
|
+
import { makeEntry } from "./helpers/lockfile-entry.js";
|
|
26
27
|
|
|
27
28
|
const testDir = mkdtempSync(join(tmpdir(), "cli-retire-test-"));
|
|
28
29
|
const originalArgv = [...process.argv];
|
|
@@ -89,26 +90,7 @@ let consoleLogSpy: ReturnType<typeof spyOn>;
|
|
|
89
90
|
let consoleErrorSpy: ReturnType<typeof spyOn>;
|
|
90
91
|
let consoleWarnSpy: ReturnType<typeof spyOn>;
|
|
91
92
|
|
|
92
|
-
function
|
|
93
|
-
assistantId: string,
|
|
94
|
-
extra: Partial<AssistantEntry> = {},
|
|
95
|
-
): AssistantEntry {
|
|
96
|
-
return {
|
|
97
|
-
assistantId,
|
|
98
|
-
runtimeUrl: `http://127.0.0.1:${7800 + assistantId.length}`,
|
|
99
|
-
cloud: "local",
|
|
100
|
-
resources: {
|
|
101
|
-
instanceDir: join(testDir, assistantId),
|
|
102
|
-
daemonPort: 7801,
|
|
103
|
-
gatewayPort: 7831,
|
|
104
|
-
qdrantPort: 6334,
|
|
105
|
-
cesPort: 7790,
|
|
106
|
-
},
|
|
107
|
-
...extra,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function writeLockfile(entries: AssistantEntry[]): void {
|
|
93
|
+
function writeLockfile(entries: LockfileAssistant[]): void {
|
|
112
94
|
mkdirSync(testDir, { recursive: true });
|
|
113
95
|
writeFileSync(
|
|
114
96
|
join(testDir, "lockfile.json"),
|
|
@@ -240,7 +222,10 @@ describe("cadet retire", () => {
|
|
|
240
222
|
});
|
|
241
223
|
|
|
242
224
|
test("--yes retires by unquoted display name and removes by assistant ID", async () => {
|
|
243
|
-
const entry = makeEntry(
|
|
225
|
+
const entry = makeEntry({
|
|
226
|
+
assistantId: "assistant-1",
|
|
227
|
+
name: "Example Assistant",
|
|
228
|
+
});
|
|
244
229
|
writeLockfile([entry]);
|
|
245
230
|
process.argv = ["bun", "cadet", "retire", "Example", "Assistant", "--yes"];
|
|
246
231
|
|
|
@@ -255,7 +240,8 @@ describe("cadet retire", () => {
|
|
|
255
240
|
});
|
|
256
241
|
|
|
257
242
|
test("local retire unregisters the cloud record straight from the lockfile entry", async () => {
|
|
258
|
-
const entry = makeEntry(
|
|
243
|
+
const entry = makeEntry({
|
|
244
|
+
assistantId: "assistant-1",
|
|
259
245
|
name: "Example Assistant",
|
|
260
246
|
cloudAssistantId: "cloud-asst-1",
|
|
261
247
|
cloudOrganizationId: "org-123",
|
|
@@ -286,7 +272,8 @@ describe("cadet retire", () => {
|
|
|
286
272
|
});
|
|
287
273
|
|
|
288
274
|
test("local retire resolves the organization via the cloud when the entry omits it", async () => {
|
|
289
|
-
const entry = makeEntry(
|
|
275
|
+
const entry = makeEntry({
|
|
276
|
+
assistantId: "assistant-1",
|
|
290
277
|
name: "Example Assistant",
|
|
291
278
|
cloudAssistantId: "cloud-asst-1",
|
|
292
279
|
});
|
|
@@ -317,7 +304,10 @@ describe("cadet retire", () => {
|
|
|
317
304
|
});
|
|
318
305
|
|
|
319
306
|
test("local retire skips the cloud unregister when no assistant id is bound", async () => {
|
|
320
|
-
const entry = makeEntry(
|
|
307
|
+
const entry = makeEntry({
|
|
308
|
+
assistantId: "assistant-1",
|
|
309
|
+
name: "Example Assistant",
|
|
310
|
+
});
|
|
321
311
|
writeLockfile([entry]);
|
|
322
312
|
readCloudTokenMock.mockReturnValue("session-token");
|
|
323
313
|
getCloudUrlMock.mockReturnValue("https://platform.example.test");
|
|
@@ -331,7 +321,8 @@ describe("cadet retire", () => {
|
|
|
331
321
|
});
|
|
332
322
|
|
|
333
323
|
test("local retire uses injected platform token from the app host", async () => {
|
|
334
|
-
const entry = makeEntry(
|
|
324
|
+
const entry = makeEntry({
|
|
325
|
+
assistantId: "assistant-1",
|
|
335
326
|
name: "Example Assistant",
|
|
336
327
|
cloudAssistantId: "cloud-asst-1",
|
|
337
328
|
cloudOrganizationId: "org-123",
|
|
@@ -359,7 +350,8 @@ describe("cadet retire", () => {
|
|
|
359
350
|
});
|
|
360
351
|
|
|
361
352
|
test("local retire continues when the cloud unregister fails", async () => {
|
|
362
|
-
const entry = makeEntry(
|
|
353
|
+
const entry = makeEntry({
|
|
354
|
+
assistantId: "assistant-1",
|
|
363
355
|
name: "Example Assistant",
|
|
364
356
|
cloudAssistantId: "cloud-asst-1",
|
|
365
357
|
cloudOrganizationId: "org-123",
|
|
@@ -382,7 +374,10 @@ describe("cadet retire", () => {
|
|
|
382
374
|
});
|
|
383
375
|
|
|
384
376
|
test("non-interactive retire without --yes fails before deleting", async () => {
|
|
385
|
-
const entry = makeEntry(
|
|
377
|
+
const entry = makeEntry({
|
|
378
|
+
assistantId: "assistant-1",
|
|
379
|
+
name: "Example Assistant",
|
|
380
|
+
});
|
|
386
381
|
writeLockfile([entry]);
|
|
387
382
|
const before = readLockfile();
|
|
388
383
|
process.argv = ["bun", "cadet", "retire", "Example", "Assistant"];
|
|
@@ -397,7 +392,10 @@ describe("cadet retire", () => {
|
|
|
397
392
|
});
|
|
398
393
|
|
|
399
394
|
test("interactive cancel leaves the assistant untouched", async () => {
|
|
400
|
-
const entry = makeEntry(
|
|
395
|
+
const entry = makeEntry({
|
|
396
|
+
assistantId: "assistant-1",
|
|
397
|
+
name: "Example Assistant",
|
|
398
|
+
});
|
|
401
399
|
writeLockfile([entry]);
|
|
402
400
|
const before = readLockfile();
|
|
403
401
|
setInteractiveTerminal();
|
|
@@ -417,7 +415,10 @@ describe("cadet retire", () => {
|
|
|
417
415
|
});
|
|
418
416
|
|
|
419
417
|
test("interactive confirmation retires the assistant", async () => {
|
|
420
|
-
const entry = makeEntry(
|
|
418
|
+
const entry = makeEntry({
|
|
419
|
+
assistantId: "assistant-1",
|
|
420
|
+
name: "Example Assistant",
|
|
421
|
+
});
|
|
421
422
|
writeLockfile([entry]);
|
|
422
423
|
setInteractiveTerminal();
|
|
423
424
|
process.argv = ["bun", "cadet", "retire", "Example", "Assistant"];
|
|
@@ -434,8 +435,8 @@ describe("cadet retire", () => {
|
|
|
434
435
|
|
|
435
436
|
test("ambiguous display names fail before deleting", async () => {
|
|
436
437
|
writeLockfile([
|
|
437
|
-
makeEntry("assistant-1",
|
|
438
|
-
makeEntry("assistant-2",
|
|
438
|
+
makeEntry({ assistantId: "assistant-1", name: "Example Assistant" }),
|
|
439
|
+
makeEntry({ assistantId: "assistant-2", name: "Example Assistant" }),
|
|
439
440
|
]);
|
|
440
441
|
const before = readLockfile();
|
|
441
442
|
process.argv = ["bun", "cadet", "retire", "Example", "Assistant", "--yes"];
|
|
@@ -25,10 +25,10 @@ import {
|
|
|
25
25
|
sleepContainers,
|
|
26
26
|
startContainers,
|
|
27
27
|
} from "../lib/docker.js";
|
|
28
|
-
import type {
|
|
28
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
29
29
|
import { mockCommands } from "./commands-mock.js";
|
|
30
30
|
|
|
31
|
-
const entry:
|
|
31
|
+
const entry: LockfileAssistant = {
|
|
32
32
|
assistantId: "docker-backup",
|
|
33
33
|
cloud: "docker",
|
|
34
34
|
runtimeUrl: "http://127.0.0.1:1",
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { tmpdir } from "node:os";
|
|
16
16
|
import { join } from "node:path";
|
|
17
17
|
import * as tar from "tar";
|
|
18
|
-
import type {
|
|
18
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
19
19
|
import {
|
|
20
20
|
createRootBackup,
|
|
21
21
|
initializeRootArchive,
|
|
@@ -63,7 +63,7 @@ async function fixture() {
|
|
|
63
63
|
);
|
|
64
64
|
await writeFile(join(root, "ces-data", "grants.json"), "CES policies");
|
|
65
65
|
await symlink("notes.md", join(root, "workspace", "notes-link"));
|
|
66
|
-
const entry:
|
|
66
|
+
const entry: LockfileAssistant = {
|
|
67
67
|
assistantId: "test",
|
|
68
68
|
cloud: "local",
|
|
69
69
|
runtimeUrl: "http://127.0.0.1:7831",
|
|
@@ -72,7 +72,6 @@ async function fixture() {
|
|
|
72
72
|
daemonPort: 7821,
|
|
73
73
|
gatewayPort: 7831,
|
|
74
74
|
cesPort: 7790,
|
|
75
|
-
qdrantPort: 6334,
|
|
76
75
|
signingKey: "07".repeat(32),
|
|
77
76
|
},
|
|
78
77
|
};
|
|
@@ -81,7 +81,7 @@ afterAll(async () => {
|
|
|
81
81
|
|
|
82
82
|
for (const topology of ["local", "docker"] as const) {
|
|
83
83
|
test(`${topology} restore uses root storage without runtime authentication`, async () => {
|
|
84
|
-
const entry: config.
|
|
84
|
+
const entry: config.LockfileAssistant = {
|
|
85
85
|
assistantId: "test",
|
|
86
86
|
cloud: topology,
|
|
87
87
|
runtimeUrl: "http://127.0.0.1:1",
|
|
@@ -97,7 +97,7 @@ for (const topology of ["local", "docker"] as const) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
test("cloud restore uploads tar and calls the cloud API using the assistant's cloud session", async () => {
|
|
100
|
-
const entry: config.
|
|
100
|
+
const entry: config.LockfileAssistant = {
|
|
101
101
|
assistantId: "cloud-test",
|
|
102
102
|
cloud: "cloud",
|
|
103
103
|
runtimeUrl: "https://cloud.mycadet.ai",
|
|
@@ -11,7 +11,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { join } from "node:path";
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
15
15
|
import {
|
|
16
16
|
saveGuardianToken,
|
|
17
17
|
type GuardianTokenData,
|
|
@@ -58,7 +58,7 @@ function guardianTokenFixture(
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function writeLockfile(entry:
|
|
61
|
+
function writeLockfile(entry: LockfileAssistant): void {
|
|
62
62
|
const lockfileDir = process.env.CADET_LOCKFILE_DIR!;
|
|
63
63
|
mkdirSync(lockfileDir, { recursive: true });
|
|
64
64
|
writeFileSync(
|
|
@@ -191,7 +191,6 @@ describe("setup command", () => {
|
|
|
191
191
|
instanceDir: testDir,
|
|
192
192
|
gatewayPort: 3000,
|
|
193
193
|
daemonPort: 8501,
|
|
194
|
-
qdrantPort: 9001,
|
|
195
194
|
cesPort: 9002,
|
|
196
195
|
},
|
|
197
196
|
});
|
|
@@ -226,7 +225,6 @@ describe("setup command", () => {
|
|
|
226
225
|
instanceDir: testDir,
|
|
227
226
|
gatewayPort: 3000,
|
|
228
227
|
daemonPort: 8501,
|
|
229
|
-
qdrantPort: 9001,
|
|
230
228
|
cesPort: 9002,
|
|
231
229
|
},
|
|
232
230
|
});
|
|
@@ -254,7 +252,6 @@ describe("setup command", () => {
|
|
|
254
252
|
instanceDir: testDir,
|
|
255
253
|
gatewayPort: 3000,
|
|
256
254
|
daemonPort: 8501,
|
|
257
|
-
qdrantPort: 9001,
|
|
258
255
|
cesPort: 9002,
|
|
259
256
|
},
|
|
260
257
|
});
|
|
@@ -14,7 +14,7 @@ import { dirname, join } from "node:path";
|
|
|
14
14
|
import {
|
|
15
15
|
getLockfileData,
|
|
16
16
|
resolveExistingLocalSigningKey,
|
|
17
|
-
|
|
17
|
+
upsertLockfileAssistant,
|
|
18
18
|
} from "@mycadet/local-mode";
|
|
19
19
|
|
|
20
20
|
// wake, upgrade and recover resolve the existing signing identity through
|
|
@@ -119,97 +119,6 @@ describe("local signing identity continuity", () => {
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
describe("renderer saves preserve host identity", () => {
|
|
123
|
-
const lockfilePath = () => join(instanceDir, "lockfile.json");
|
|
124
|
-
function writeOnDisk(value: unknown): void {
|
|
125
|
-
writeFileSync(lockfilePath(), JSON.stringify(value, null, 2));
|
|
126
|
-
}
|
|
127
|
-
function readOnDisk(): Record<string, unknown> {
|
|
128
|
-
return JSON.parse(readFileSync(lockfilePath(), "utf-8")) as Record<
|
|
129
|
-
string,
|
|
130
|
-
unknown
|
|
131
|
-
>;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
test("a renderer read/select/save preserves host resources and credentials", () => {
|
|
135
|
-
const entry = {
|
|
136
|
-
assistantId: "local-1",
|
|
137
|
-
cloud: "local",
|
|
138
|
-
name: "Example Assistant",
|
|
139
|
-
runtimeUrl: "http://127.0.0.1:7830",
|
|
140
|
-
guardianBootstrapSecret: "bootstrap-secret",
|
|
141
|
-
resources: {
|
|
142
|
-
instanceDir: "/example/instance",
|
|
143
|
-
gatewayPort: 7830,
|
|
144
|
-
daemonPort: 7831,
|
|
145
|
-
signingKey: key,
|
|
146
|
-
cesPort: 7832,
|
|
147
|
-
futureHostField: "keep",
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
writeOnDisk({ assistants: [entry], activeAssistant: null });
|
|
151
|
-
const read = getLockfileData([lockfilePath()]);
|
|
152
|
-
expect(read.ok).toBe(true);
|
|
153
|
-
if (!read.ok) {
|
|
154
|
-
throw new Error("fixture read failed");
|
|
155
|
-
}
|
|
156
|
-
const view = read.data.assistants[0]!;
|
|
157
|
-
expect(view.resources).not.toHaveProperty("signingKey");
|
|
158
|
-
const result = upsertRendererLockfileAssistant(
|
|
159
|
-
[lockfilePath()],
|
|
160
|
-
{ ...view },
|
|
161
|
-
"local-1",
|
|
162
|
-
);
|
|
163
|
-
expect(result.ok).toBe(true);
|
|
164
|
-
expect(readOnDisk()).toEqual({
|
|
165
|
-
assistants: [entry],
|
|
166
|
-
activeAssistant: "local-1",
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test("stale or forged renderer resources cannot replace host state", () => {
|
|
171
|
-
const entry = {
|
|
172
|
-
assistantId: "local-1",
|
|
173
|
-
cloud: "local",
|
|
174
|
-
guardianBootstrapSecret: "keep",
|
|
175
|
-
resources: {
|
|
176
|
-
instanceDir: "/example/current",
|
|
177
|
-
signingKey: key,
|
|
178
|
-
gatewayPort: 7830,
|
|
179
|
-
daemonPort: 7831,
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
writeOnDisk({ assistants: [entry], activeAssistant: null });
|
|
183
|
-
const result = upsertRendererLockfileAssistant(
|
|
184
|
-
[lockfilePath()],
|
|
185
|
-
{
|
|
186
|
-
assistantId: "local-1",
|
|
187
|
-
name: "Updated",
|
|
188
|
-
guardianBootstrapSecret: "replace",
|
|
189
|
-
resources: {
|
|
190
|
-
instanceDir: "/example/stale",
|
|
191
|
-
signingKey: other,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
undefined,
|
|
195
|
-
);
|
|
196
|
-
expect(result.ok).toBe(true);
|
|
197
|
-
expect(readOnDisk().assistants).toEqual([{ ...entry, name: "Updated" }]);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
test("a renderer save refuses an unreadable registry without replacing it", () => {
|
|
201
|
-
writeFileSync(lockfilePath(), "{ invalid");
|
|
202
|
-
expect(
|
|
203
|
-
upsertRendererLockfileAssistant(
|
|
204
|
-
[lockfilePath()],
|
|
205
|
-
{ assistantId: "local-1" },
|
|
206
|
-
"local-1",
|
|
207
|
-
),
|
|
208
|
-
).toMatchObject({ ok: false, status: 409 });
|
|
209
|
-
expect(readFileSync(lockfilePath(), "utf-8")).toBe("{ invalid");
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
122
|
describe("across desktop saves and wake cycles", () => {
|
|
214
123
|
test("read/select/save and repeated key loads preserve a retained credential", () => {
|
|
215
124
|
const registry = join(instanceDir, "registry.json");
|
|
@@ -240,7 +149,7 @@ describe("local signing identity continuity", () => {
|
|
|
240
149
|
throw new Error("fixture read failed");
|
|
241
150
|
}
|
|
242
151
|
expect(
|
|
243
|
-
|
|
152
|
+
upsertLockfileAssistant(
|
|
244
153
|
[registry],
|
|
245
154
|
{ ...view.data.assistants[0]! },
|
|
246
155
|
"example",
|
|
@@ -87,9 +87,9 @@ afterAll(() => {
|
|
|
87
87
|
|
|
88
88
|
import { sleep } from "../commands/sleep.js";
|
|
89
89
|
import {
|
|
90
|
+
DEFAULT_CES_PORT,
|
|
90
91
|
DEFAULT_DAEMON_PORT,
|
|
91
92
|
DEFAULT_GATEWAY_PORT,
|
|
92
|
-
DEFAULT_QDRANT_PORT,
|
|
93
93
|
} from "../lib/constants.js";
|
|
94
94
|
import { makeGuardianTokenData } from "./helpers/guardian-token.js";
|
|
95
95
|
|
|
@@ -109,7 +109,7 @@ function writeLockfile(extraEntryFields: Record<string, unknown> = {}): void {
|
|
|
109
109
|
instanceDir: testDir,
|
|
110
110
|
daemonPort: DEFAULT_DAEMON_PORT,
|
|
111
111
|
gatewayPort: DEFAULT_GATEWAY_PORT,
|
|
112
|
-
|
|
112
|
+
cesPort: DEFAULT_CES_PORT,
|
|
113
113
|
},
|
|
114
114
|
...extraEntryFields,
|
|
115
115
|
},
|
|
@@ -219,7 +219,14 @@ describe("sleep command", () => {
|
|
|
219
219
|
test("default sleep passes the non-escalating service stopper", async () => {
|
|
220
220
|
process.argv = ["bun", "cadet", "sleep", "sleep-test"];
|
|
221
221
|
await sleep();
|
|
222
|
-
expect(stopProcessByPidFileMock).toHaveBeenNthCalledWith(
|
|
222
|
+
expect(stopProcessByPidFileMock).toHaveBeenNthCalledWith(
|
|
223
|
+
1,
|
|
224
|
+
join(assistantRootDir, "workspace", "cadet.pid"),
|
|
225
|
+
"assistant",
|
|
226
|
+
undefined,
|
|
227
|
+
45_000,
|
|
228
|
+
realProcess.stopProcessGracefully,
|
|
229
|
+
);
|
|
223
230
|
});
|
|
224
231
|
|
|
225
232
|
test("force stops the assistant even when an active call lease exists", async () => {
|
|
@@ -272,7 +279,7 @@ describe("sleep command", () => {
|
|
|
272
279
|
instanceDir: testDir,
|
|
273
280
|
daemonPort: 8501,
|
|
274
281
|
gatewayPort: 9999,
|
|
275
|
-
|
|
282
|
+
cesPort: DEFAULT_CES_PORT,
|
|
276
283
|
},
|
|
277
284
|
});
|
|
278
285
|
isProcessAliveMock.mockReturnValue({ alive: true, pid: 4321 });
|
|
@@ -402,7 +409,7 @@ describe("sleep command", () => {
|
|
|
402
409
|
instanceDir: join(testDir, "instance-1"),
|
|
403
410
|
daemonPort: DEFAULT_DAEMON_PORT,
|
|
404
411
|
gatewayPort: DEFAULT_GATEWAY_PORT,
|
|
405
|
-
|
|
412
|
+
cesPort: DEFAULT_CES_PORT,
|
|
406
413
|
},
|
|
407
414
|
},
|
|
408
415
|
{
|
|
@@ -413,7 +420,7 @@ describe("sleep command", () => {
|
|
|
413
420
|
instanceDir: join(testDir, "instance-2"),
|
|
414
421
|
daemonPort: DEFAULT_DAEMON_PORT,
|
|
415
422
|
gatewayPort: DEFAULT_GATEWAY_PORT,
|
|
416
|
-
|
|
423
|
+
cesPort: DEFAULT_CES_PORT,
|
|
417
424
|
},
|
|
418
425
|
},
|
|
419
426
|
],
|