@mycadet/cli 0.13.0-dev.202611142321.f0c8539 → 0.13.0-dev.202611151727.8310b2c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/local-exec-invocation.test.ts +5 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-retire.test.ts +7 -4
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-hatch.test.ts +6 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-recreate.test.ts +5 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-sleep.test.ts +1 -14
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-statefulset.test.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-common-ces.test.ts +5 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-pair.test.ts +44 -36
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-retire.test.ts +8 -8
- package/node_modules/@mycadet/local-mode/src/__tests__/root-backup-docker.test.ts +10 -16
- package/node_modules/@mycadet/local-mode/src/__tests__/upgrade-root-recovery.test.ts +0 -2
- package/node_modules/@mycadet/local-mode/src/guardian-token.ts +3 -49
- package/node_modules/@mycadet/local-mode/src/index.ts +4 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +3 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +0 -6
- package/node_modules/@mycadet/local-mode/src/operations/retire.ts +2 -2
- package/node_modules/@mycadet/local-mode/src/operations/sleep.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/remotes/docker/common.ts +18 -0
- package/node_modules/@mycadet/local-mode/src/remotes/docker/exec.ts +5 -2
- package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +11 -45
- package/node_modules/@mycadet/local-mode/src/remotes/docker/pair.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/remotes/docker/retire.ts +10 -36
- package/node_modules/@mycadet/local-mode/src/remotes/docker/sleep.ts +19 -55
- package/node_modules/@mycadet/local-mode/src/remotes/docker/statefulset.ts +7 -18
- package/node_modules/@mycadet/local-mode/src/remotes/docker/teleport.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/remotes/docker/upgrade.ts +14 -7
- package/node_modules/@mycadet/local-mode/src/remotes/docker/wake.ts +8 -28
- package/node_modules/@mycadet/local-mode/src/remotes/docker/watch.ts +2 -1
- package/node_modules/@mycadet/local-mode/src/remotes/local/common.ts +52 -87
- package/node_modules/@mycadet/local-mode/src/remotes/local/hatch.ts +10 -5
- package/node_modules/@mycadet/local-mode/src/remotes/local/pair.ts +37 -4
- package/node_modules/@mycadet/local-mode/src/remotes/local/retire.ts +4 -20
- package/node_modules/@mycadet/local-mode/src/remotes/local/wake.ts +0 -15
- package/node_modules/@mycadet/local-mode/src/root-backup.ts +4 -2
- package/node_modules/@mycadet/local-mode/src/source-root.ts +25 -0
- package/node_modules/@mycadet/local-mode/src/upgrade-lifecycle.ts +2 -7
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/package.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/guardian-token.test.ts +54 -19
- package/src/__tests__/root-process-lockfile.test.ts +9 -15
- package/src/__tests__/servers/bun.test.ts +0 -2
- package/src/__tests__/setup.test.ts +6 -4
- package/src/__tests__/uninstall.test.ts +10 -6
- package/src/__tests__/web-dist.test.ts +46 -127
- package/src/commands/uninstall.ts +2 -2
- package/src/index.ts +10 -1
- package/src/lib/assistant-config.ts +0 -27
- package/src/lib/servers/common.ts +2 -26
- package/src/lib/web-dist.ts +110 -43
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-common-gateway-cli.test.ts +0 -52
|
@@ -10,6 +10,7 @@ import { tmpdir } from "node:os";
|
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
12
12
|
import { ensureLocalBinShims } from "../remotes/local/common";
|
|
13
|
+
import { setLocalSourceRoot } from "../source-root";
|
|
13
14
|
|
|
14
15
|
// The bin/ folder is the contract: exec prepends it to the child's PATH, so
|
|
15
16
|
// EVERY invocation shape — argv, compound commands, pipes, shell scripts —
|
|
@@ -20,6 +21,10 @@ import { ensureLocalBinShims } from "../remotes/local/common";
|
|
|
20
21
|
// repo-root source tree — four levels up from this __tests__ dir.
|
|
21
22
|
const repoRoot = join(import.meta.dir, "..", "..", "..", "..");
|
|
22
23
|
|
|
24
|
+
// Shim resolution reads the reported source tree — the same report the
|
|
25
|
+
// CLI's entrypoint makes in production.
|
|
26
|
+
setLocalSourceRoot(repoRoot);
|
|
27
|
+
|
|
23
28
|
describe("ensureLocalBinShims", () => {
|
|
24
29
|
let instanceDir: string;
|
|
25
30
|
|
|
@@ -43,9 +43,9 @@ const cloudAuthHeadersMock = mock(async () => ({
|
|
|
43
43
|
}));
|
|
44
44
|
const retireLocalMock = mock(
|
|
45
45
|
async (
|
|
46
|
-
|
|
46
|
+
entry: LockfileAssistant,
|
|
47
47
|
): Promise<{ assistantId: string; archived: boolean }> => ({
|
|
48
|
-
assistantId,
|
|
48
|
+
assistantId: entry.assistantId,
|
|
49
49
|
archived: false,
|
|
50
50
|
}),
|
|
51
51
|
);
|
|
@@ -170,7 +170,10 @@ describe("retireAssistant — the headless dispatch", () => {
|
|
|
170
170
|
const result = await retireAssistant(entry);
|
|
171
171
|
|
|
172
172
|
expect(result).toEqual({ ok: true });
|
|
173
|
-
|
|
173
|
+
// The dispatch hands the whole lockfile entry to the docker leg.
|
|
174
|
+
expect(retireDockerMock).toHaveBeenCalledWith(
|
|
175
|
+
expect.objectContaining({ assistantId: "asst-docker" }),
|
|
176
|
+
);
|
|
174
177
|
expect(readLockfile().assistants).toEqual([]);
|
|
175
178
|
});
|
|
176
179
|
|
|
@@ -282,8 +285,8 @@ describe("the operator route table — the scoped surface's retire arm", () => {
|
|
|
282
285
|
)!.route.run({ assistantId: "asst-local" });
|
|
283
286
|
|
|
284
287
|
expect(response?.status).toBe(204);
|
|
288
|
+
// The dispatch hands the whole lockfile entry to the local leg.
|
|
285
289
|
expect(retireLocalMock).toHaveBeenCalledWith(
|
|
286
|
-
"asst-local",
|
|
287
290
|
expect.objectContaining({ assistantId: "asst-local" }),
|
|
288
291
|
);
|
|
289
292
|
});
|
|
@@ -19,9 +19,9 @@ import {
|
|
|
19
19
|
resolveDockerHatchMode,
|
|
20
20
|
resolveDockerProviderCredentialSetupAction,
|
|
21
21
|
} from "../remotes/docker/hatch";
|
|
22
|
-
import { dockerResourceNames } from "../remotes/docker/retire";
|
|
23
22
|
import { collectWatchTargets } from "../remotes/docker/watch";
|
|
24
23
|
import { ASSISTANT_INTERNAL_PORT } from "../ports";
|
|
24
|
+
import { dockerResourceNames } from "../remotes/docker/common";
|
|
25
25
|
|
|
26
26
|
const instanceName = "test-instance";
|
|
27
27
|
const imageTags: Record<ServiceName, string> = {
|
|
@@ -322,6 +322,11 @@ describe("pullImage", () => {
|
|
|
322
322
|
let pulls = 0;
|
|
323
323
|
const exec = async (cmd: string, args: string[] = []): Promise<void> => {
|
|
324
324
|
calls.push({ cmd, args });
|
|
325
|
+
if (cmd === "docker" && args[0] === "image" && args[1] === "inspect") {
|
|
326
|
+
// The daemon's inspect rejects a missing image — the pull path's
|
|
327
|
+
// fast-exit must not trigger in these fakes.
|
|
328
|
+
throw new Error(`No such image: ${args[2] ?? ""}`);
|
|
329
|
+
}
|
|
325
330
|
if (cmd === "docker" && args[0] === "pull") {
|
|
326
331
|
pulls++;
|
|
327
332
|
if (opts.failAllPullsWith) throw new Error(opts.failAllPullsWith);
|
|
@@ -13,6 +13,11 @@ describe("pullImage", () => {
|
|
|
13
13
|
let pulls = 0;
|
|
14
14
|
const exec = async (cmd: string, args: string[] = []): Promise<void> => {
|
|
15
15
|
calls.push({ cmd, args });
|
|
16
|
+
if (cmd === "docker" && args[0] === "image" && args[1] === "inspect") {
|
|
17
|
+
// The daemon's inspect rejects a missing image — the pull path's
|
|
18
|
+
// fast-exit must not trigger in this fake.
|
|
19
|
+
throw new Error(`No such image: ${args[2] ?? ""}`);
|
|
20
|
+
}
|
|
16
21
|
if (cmd === "docker" && args[0] === "pull") {
|
|
17
22
|
pulls++;
|
|
18
23
|
if (opts.failAllPullsWith) throw new Error(opts.failAllPullsWith);
|
|
@@ -64,20 +64,7 @@ test("the docker leg narrates the containers-stopped line itself", async () => {
|
|
|
64
64
|
expect(lines).toEqual(["Docker containers stopped."]);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test("the docker leg narrates that --wait is unsupported when asked", async () => {
|
|
68
|
-
const lines: string[] = [];
|
|
69
|
-
await sleepDocker(entry, {
|
|
70
|
-
wait: true,
|
|
71
|
-
log: (line) => lines.push(line),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
expect(lines).toEqual([
|
|
75
|
-
"--wait is not supported for Docker assistants yet — stopping containers now.",
|
|
76
|
-
"Docker containers stopped.",
|
|
77
|
-
]);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
67
|
test("the docker leg stays silent for headless hosts (no log)", async () => {
|
|
81
|
-
await sleepDocker(entry, {
|
|
68
|
+
await sleepDocker(entry, {});
|
|
82
69
|
expect(execMock).toHaveBeenCalled();
|
|
83
70
|
});
|
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
type DockerStatefulSetSpec,
|
|
9
9
|
type ServiceName,
|
|
10
10
|
} from "../remotes/docker/statefulset";
|
|
11
|
-
import { dockerResourceNames } from "../remotes/docker/retire";
|
|
12
11
|
import { ASSISTANT_INTERNAL_PORT } from "../ports";
|
|
13
12
|
import { PROVIDER_ENV_VAR_NAMES } from "../provider-env-vars";
|
|
13
|
+
import { dockerResourceNames } from "../remotes/docker/common";
|
|
14
14
|
|
|
15
15
|
const instanceName = "test-instance";
|
|
16
16
|
const imageTags: Record<ServiceName, string> = {
|
|
@@ -12,6 +12,11 @@ import { afterAll, beforeAll, describe, expect, mock, test } from "bun:test";
|
|
|
12
12
|
import { resolveIpcEndpoint } from "@mycadet/ipc-server-utils";
|
|
13
13
|
|
|
14
14
|
import { resolveCesSocketPath, startCes } from "../remotes/local/common";
|
|
15
|
+
import { setLocalSourceRoot } from "../source-root";
|
|
16
|
+
|
|
17
|
+
// resolveCesDir walks the reported source tree for a credential-executor
|
|
18
|
+
// sibling — the same report the CLI's entrypoint makes in production.
|
|
19
|
+
setLocalSourceRoot(join(import.meta.dir, "..", "..", "..", ".."));
|
|
15
20
|
|
|
16
21
|
// ---------------------------------------------------------------------------
|
|
17
22
|
// Mocks
|
|
@@ -14,58 +14,40 @@ const fakeToken = (token: string): GuardianTokenData => ({
|
|
|
14
14
|
leasedAt: "1970-01-01T00:00:00.000Z",
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
// Snapshot the real
|
|
18
|
-
// below can restore
|
|
17
|
+
// Snapshot the real module before mocking so the module-scoped `afterAll`
|
|
18
|
+
// below can restore it — bun runs every test file in one process with a
|
|
19
19
|
// shared loader, and `mock.restore()` does not undo `mock.module()`.
|
|
20
20
|
const realExec = { ...(await import("../exec")) };
|
|
21
|
-
const realCommon = { ...(await import("../remotes/local/common")) };
|
|
22
21
|
|
|
23
22
|
const execOutputMock = mock<typeof realExec.execOutput>(async () => "");
|
|
24
|
-
const gatewayCliInvocationMock = mock<typeof realCommon.gatewayCliInvocation>(
|
|
25
|
-
() => ({
|
|
26
|
-
command: "/fake/bun",
|
|
27
|
-
args: ["run", "/fake/gateway/src/cli/index.ts"],
|
|
28
|
-
cwd: "/fake/state-root",
|
|
29
|
-
env: {},
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
32
23
|
|
|
33
24
|
mock.module("../exec", () => ({
|
|
34
25
|
...realExec,
|
|
35
26
|
execOutput: execOutputMock,
|
|
36
27
|
}));
|
|
37
|
-
mock.module("../remotes/local/common", () => ({
|
|
38
|
-
...realCommon,
|
|
39
|
-
gatewayCliInvocation: gatewayCliInvocationMock,
|
|
40
|
-
}));
|
|
41
28
|
|
|
42
29
|
const { pairLocal } = await import("../remotes/local/pair");
|
|
43
30
|
|
|
31
|
+
// The invocation context derives from the entry's recorded instanceDir —
|
|
32
|
+
// recorded paths keep the assertions free of XDG resolution.
|
|
44
33
|
const entry: LocalAssistant = {
|
|
45
34
|
assistantId: "asst-local",
|
|
46
35
|
cloud: "local",
|
|
36
|
+
instanceDir: "/data/assistants/asst-local",
|
|
47
37
|
port: 7830,
|
|
48
38
|
};
|
|
49
39
|
|
|
50
40
|
afterAll(() => {
|
|
51
41
|
mock.module("../exec", () => realExec);
|
|
52
|
-
mock.module("../remotes/local/common", () => realCommon);
|
|
53
42
|
});
|
|
54
43
|
|
|
55
44
|
describe("pairLocal — running the gateway's own CLI is the local presence proof", () => {
|
|
56
45
|
beforeEach(() => {
|
|
57
46
|
execOutputMock.mockClear();
|
|
58
47
|
execOutputMock.mockResolvedValue("");
|
|
59
|
-
gatewayCliInvocationMock.mockClear();
|
|
60
|
-
gatewayCliInvocationMock.mockReturnValue({
|
|
61
|
-
command: "/fake/bun",
|
|
62
|
-
args: ["run", "/fake/gateway/src/cli/index.ts"],
|
|
63
|
-
cwd: "/fake/state-root",
|
|
64
|
-
env: {},
|
|
65
|
-
});
|
|
66
48
|
});
|
|
67
49
|
|
|
68
|
-
test("runs `gateway pairing mint` with the device identity as flags", async () => {
|
|
50
|
+
test("runs the instance's `gateway pairing mint` shim with the device identity as flags", async () => {
|
|
69
51
|
execOutputMock.mockResolvedValue(JSON.stringify(fakeToken("t")));
|
|
70
52
|
const result = await pairLocal(entry, {
|
|
71
53
|
platform: "cli",
|
|
@@ -74,10 +56,10 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
|
|
|
74
56
|
});
|
|
75
57
|
expect(execOutputMock).toHaveBeenCalledTimes(1);
|
|
76
58
|
const [command, args, options] = execOutputMock.mock.calls[0]!;
|
|
77
|
-
|
|
59
|
+
// The bare command resolves through the instance's bin/ shim (put
|
|
60
|
+
// first on PATH) — a layer removed from bun.
|
|
61
|
+
expect(command).toBe("gateway");
|
|
78
62
|
expect(args).toEqual([
|
|
79
|
-
"run",
|
|
80
|
-
"/fake/gateway/src/cli/index.ts",
|
|
81
63
|
"pairing",
|
|
82
64
|
"mint",
|
|
83
65
|
"--platform",
|
|
@@ -87,8 +69,20 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
|
|
|
87
69
|
"--client-reported-name",
|
|
88
70
|
"box",
|
|
89
71
|
]);
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
// The same geography `cadet exec --service gateway` uses: cwd is the
|
|
73
|
+
// instance's gateway-security dir, and the workspace/security dirs are
|
|
74
|
+
// pinned to the instance so the pairing store resolves identically to
|
|
75
|
+
// the server's.
|
|
76
|
+
expect(options?.cwd).toBe("/data/assistants/asst-local/gateway-security");
|
|
77
|
+
expect(options?.env?.CADET_WORKSPACE_DIR).toBe(
|
|
78
|
+
"/data/assistants/asst-local/workspace",
|
|
79
|
+
);
|
|
80
|
+
expect(options?.env?.GATEWAY_SECURITY_DIR).toBe(
|
|
81
|
+
"/data/assistants/asst-local/gateway-security",
|
|
82
|
+
);
|
|
83
|
+
expect(
|
|
84
|
+
options?.env?.PATH?.startsWith("/data/assistants/asst-local/bin:"),
|
|
85
|
+
).toBe(true);
|
|
92
86
|
expect(options?.timeoutMs).toBe(30_000);
|
|
93
87
|
expect(result).toEqual({ ok: true, response: fakeToken("t") });
|
|
94
88
|
});
|
|
@@ -97,8 +91,6 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
|
|
|
97
91
|
execOutputMock.mockResolvedValue(JSON.stringify(fakeToken("t")));
|
|
98
92
|
await pairLocal(entry, { platform: "cli", deviceId: "device-2" });
|
|
99
93
|
expect(execOutputMock.mock.calls[0]![1]).toEqual([
|
|
100
|
-
"run",
|
|
101
|
-
"/fake/gateway/src/cli/index.ts",
|
|
102
94
|
"pairing",
|
|
103
95
|
"mint",
|
|
104
96
|
"--platform",
|
|
@@ -119,6 +111,23 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
|
|
|
119
111
|
expect(result).toEqual({ ok: true, response: fakeToken("t") });
|
|
120
112
|
});
|
|
121
113
|
|
|
114
|
+
test("a malformed payload names the shape refusal and is structured", async () => {
|
|
115
|
+
// Valid JSON, wrong shape — the schema arm of the door's parser.
|
|
116
|
+
execOutputMock.mockResolvedValue(
|
|
117
|
+
JSON.stringify({ guardianPrincipalId: "guardian-1", accessToken: 42 }),
|
|
118
|
+
);
|
|
119
|
+
const result = await pairLocal(entry, {
|
|
120
|
+
platform: "cli",
|
|
121
|
+
deviceId: "device-shape",
|
|
122
|
+
});
|
|
123
|
+
expect(result.ok).toBe(false);
|
|
124
|
+
if (result.ok) throw new Error("expected refusal");
|
|
125
|
+
expect(result.status).toBe(0);
|
|
126
|
+
expect(result.error).toBe(
|
|
127
|
+
'the gateway\'s pair output did not match the expected payload shape (stdout tail: {"guardianPrincipalId":"guardian-1","accessToken":42})',
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
|
|
122
131
|
test("an unparseable answer comes back structured", async () => {
|
|
123
132
|
execOutputMock.mockResolvedValue("not json at all");
|
|
124
133
|
const result = await pairLocal(entry, {
|
|
@@ -141,10 +150,9 @@ describe("pairLocal — running the gateway's own CLI is the local presence proo
|
|
|
141
150
|
platform: "cli",
|
|
142
151
|
deviceId: "device-5",
|
|
143
152
|
});
|
|
144
|
-
expect(result).
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
153
|
+
expect(result.ok).toBe(false);
|
|
154
|
+
if (result.ok) throw new Error("expected refusal");
|
|
155
|
+
expect(result.status).toBe(0);
|
|
156
|
+
expect(result.error).toBe("gateway-cli exited with code 1");
|
|
149
157
|
});
|
|
150
158
|
});
|
|
@@ -128,7 +128,7 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
128
128
|
instanceDir,
|
|
129
129
|
});
|
|
130
130
|
const entry = readLocalEntry("test-assistant");
|
|
131
|
-
await retireLocal(
|
|
131
|
+
await retireLocal(entry, {
|
|
132
132
|
progress: () => {},
|
|
133
133
|
log: () => {},
|
|
134
134
|
warn: () => {},
|
|
@@ -162,7 +162,7 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
162
162
|
test("gives the daemon its full stop budget, not the default grace", async () => {
|
|
163
163
|
makeEntry({ assistantId: "test-assistant" });
|
|
164
164
|
const entry = readLocalEntry("test-assistant");
|
|
165
|
-
await retireLocal(
|
|
165
|
+
await retireLocal(entry, {
|
|
166
166
|
progress: () => {},
|
|
167
167
|
log: () => {},
|
|
168
168
|
warn: () => {},
|
|
@@ -194,7 +194,7 @@ describe("retireLocal — CES sibling stop", () => {
|
|
|
194
194
|
instanceDir,
|
|
195
195
|
});
|
|
196
196
|
const entry = readLocalEntry("test-assistant");
|
|
197
|
-
await retireLocal(
|
|
197
|
+
await retireLocal(entry, {
|
|
198
198
|
progress: () => {},
|
|
199
199
|
log: () => {},
|
|
200
200
|
warn: () => {},
|
|
@@ -293,7 +293,7 @@ describe("retireLocal — the self-hosted platform unregister", () => {
|
|
|
293
293
|
readCloudTokenMock.mockReturnValue("session-token");
|
|
294
294
|
const entry = readLocalEntry("test-assistant");
|
|
295
295
|
|
|
296
|
-
await retireLocal(
|
|
296
|
+
await retireLocal(entry, silentReporter);
|
|
297
297
|
|
|
298
298
|
// The cloud record resolves from the entry + env — no gateway credential
|
|
299
299
|
// store is consulted.
|
|
@@ -319,7 +319,7 @@ describe("retireLocal — the self-hosted platform unregister", () => {
|
|
|
319
319
|
readCloudTokenMock.mockReturnValue("session-token");
|
|
320
320
|
const entry = readLocalEntry("test-assistant");
|
|
321
321
|
|
|
322
|
-
await retireLocal(
|
|
322
|
+
await retireLocal(entry, silentReporter);
|
|
323
323
|
|
|
324
324
|
expect(cloudAuthHeadersMock).toHaveBeenCalledWith("session-token");
|
|
325
325
|
expect(authHeadersForKnownOrganizationMock).not.toHaveBeenCalled();
|
|
@@ -343,7 +343,7 @@ describe("retireLocal — the self-hosted platform unregister", () => {
|
|
|
343
343
|
readCloudTokenMock.mockReturnValue("session-token");
|
|
344
344
|
const entry = readLocalEntry("test-assistant");
|
|
345
345
|
|
|
346
|
-
await retireLocal(
|
|
346
|
+
await retireLocal(entry, silentReporter);
|
|
347
347
|
|
|
348
348
|
expect(loopbackSafeFetchMock).not.toHaveBeenCalled();
|
|
349
349
|
});
|
|
@@ -359,7 +359,7 @@ describe("retireLocal — the self-hosted platform unregister", () => {
|
|
|
359
359
|
readCloudTokenMock.mockReturnValue(null);
|
|
360
360
|
const entry = readLocalEntry("test-assistant");
|
|
361
361
|
|
|
362
|
-
await retireLocal(
|
|
362
|
+
await retireLocal(entry, silentReporter);
|
|
363
363
|
|
|
364
364
|
expect(loopbackSafeFetchMock).toHaveBeenCalledWith(
|
|
365
365
|
"https://platform.example.test/v1/assistants/cloud-asst-1/retire/",
|
|
@@ -394,7 +394,7 @@ describe("retireLocal — the self-hosted platform unregister", () => {
|
|
|
394
394
|
);
|
|
395
395
|
|
|
396
396
|
try {
|
|
397
|
-
await retireLocal(
|
|
397
|
+
await retireLocal(entry, silentReporter);
|
|
398
398
|
} finally {
|
|
399
399
|
warnSpy.mockRestore();
|
|
400
400
|
}
|
|
@@ -22,12 +22,12 @@ import {
|
|
|
22
22
|
} from "../root-backup";
|
|
23
23
|
import { createContainers } from "../remotes/docker/wake";
|
|
24
24
|
import { sleepDocker } from "../remotes/docker/sleep";
|
|
25
|
-
import { dockerResourceNames } from "../remotes/docker/retire";
|
|
26
25
|
import type { LockfileAssistant } from "../lockfile-contract";
|
|
27
26
|
// The subprocess-fake harness stays cli-side (its other consumers are the
|
|
28
27
|
// CLI's teleport tests); this docker-flow test is a monorepo-level one and
|
|
29
28
|
// reaches across for it.
|
|
30
29
|
import { mockCommands } from "../../../../cli/src/__tests__/commands-mock.js";
|
|
30
|
+
import { dockerResourceNames } from "../remotes/docker/common";
|
|
31
31
|
|
|
32
32
|
// The sleep operation probes the gateway's health itself now — the flow's
|
|
33
33
|
// restart signal rides the sleep result. A loopback listener stands in for
|
|
@@ -128,10 +128,9 @@ beforeEach(async () => {
|
|
|
128
128
|
);
|
|
129
129
|
commands.on(
|
|
130
130
|
"docker",
|
|
131
|
-
(args) => args[0] === "
|
|
131
|
+
(args) => args[0] === "stop",
|
|
132
132
|
({ args }) => {
|
|
133
|
-
|
|
134
|
-
running.set(args.at(-1)!, false);
|
|
133
|
+
running.set(args[1]!, false);
|
|
135
134
|
return {};
|
|
136
135
|
},
|
|
137
136
|
);
|
|
@@ -205,7 +204,7 @@ test("Docker subprocess round-trip preserves every root, private files and clear
|
|
|
205
204
|
await expect(readFile(join(directory, root, "stale"))).rejects.toThrow();
|
|
206
205
|
}
|
|
207
206
|
expect(writes).toBe(4);
|
|
208
|
-
expect(commands.calls.filter((call) => call.args[0] === "
|
|
207
|
+
expect(commands.calls.filter((call) => call.args[0] === "stop")).toHaveLength(
|
|
209
208
|
3,
|
|
210
209
|
);
|
|
211
210
|
});
|
|
@@ -232,17 +231,12 @@ test("failure during Docker replacement recovers prior roots before restarting",
|
|
|
232
231
|
}
|
|
233
232
|
});
|
|
234
233
|
|
|
235
|
-
test("default Docker sleep
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
()
|
|
240
|
-
);
|
|
241
|
-
await expect(sleepDocker(entry, { timeoutMs: 0 })).rejects.toThrow(
|
|
242
|
-
"did not stop gracefully",
|
|
243
|
-
);
|
|
244
|
-
expect(running.get(names.assistantContainer)).toBe(true);
|
|
245
|
-
expect(commands.calls.some((call) => call.args[0] === "stop")).toBe(false);
|
|
234
|
+
test("default Docker sleep stops containers without forcing them", async () => {
|
|
235
|
+
// No kill handler is registered — a forced kill would fail the fake.
|
|
236
|
+
await sleepDocker(entry);
|
|
237
|
+
for (const container of containers)
|
|
238
|
+
expect(running.get(container)).toBe(false);
|
|
239
|
+
expect(commands.calls.some((call) => call.args[0] === "kill")).toBe(false);
|
|
246
240
|
expect(
|
|
247
241
|
commands.calls
|
|
248
242
|
.filter((call) => call.args[0] === "kill")
|
|
@@ -95,7 +95,6 @@ test("failed-state recovery restores tar roots while stopped before restarting o
|
|
|
95
95
|
entry,
|
|
96
96
|
backupPath: "pre-upgrade.tar.gz",
|
|
97
97
|
backupLabel: "pre-upgrade",
|
|
98
|
-
res,
|
|
99
98
|
containerOptions,
|
|
100
99
|
}),
|
|
101
100
|
).toEqual({ restored: true, ready: true });
|
|
@@ -118,7 +117,6 @@ test("failed root restore does not restart a partial installation", async () =>
|
|
|
118
117
|
entry,
|
|
119
118
|
backupPath: "pre-upgrade.tar.gz",
|
|
120
119
|
backupLabel: "pre-upgrade",
|
|
121
|
-
res,
|
|
122
120
|
containerOptions,
|
|
123
121
|
}),
|
|
124
122
|
).toEqual({ restored: false, ready: false });
|
|
@@ -15,8 +15,7 @@ import {
|
|
|
15
15
|
guardianTokenPath,
|
|
16
16
|
resolveConfigDir,
|
|
17
17
|
} from "./config";
|
|
18
|
-
import {
|
|
19
|
-
import { loopbackSafeFetch } from "./loopback-fetch";
|
|
18
|
+
import type { LockfileAssistant } from "./lockfile-contract";
|
|
20
19
|
import { readLockfile } from "./lockfile";
|
|
21
20
|
import { pairDevice } from "./operations/pair";
|
|
22
21
|
import type { CliInvocation } from "./util";
|
|
@@ -555,36 +554,6 @@ function readClientHostname(): string | undefined {
|
|
|
555
554
|
}
|
|
556
555
|
}
|
|
557
556
|
|
|
558
|
-
const READY_POLL_INTERVAL_MS = 500;
|
|
559
|
-
const READY_POLL_BUDGET_MS = 60_000;
|
|
560
|
-
|
|
561
|
-
/**
|
|
562
|
-
* The gateway 503s every non-probe route ({status: "starting"}) while its
|
|
563
|
-
* post-assistant-ready backfills run — exactly the window that burns the
|
|
564
|
-
* caller's lease-retry budget. Poll /readyz (body-aware: it is the probe
|
|
565
|
-
* the gateway docs point CLI waits at) until the gate opens before the
|
|
566
|
-
* first pair attempt.
|
|
567
|
-
*/
|
|
568
|
-
async function waitForGatewayReady(gatewayUrl: string): Promise<void> {
|
|
569
|
-
const deadline = Date.now() + READY_POLL_BUDGET_MS;
|
|
570
|
-
while (Date.now() < deadline) {
|
|
571
|
-
try {
|
|
572
|
-
const res = await loopbackSafeFetch(`${gatewayUrl}/readyz`, {
|
|
573
|
-
signal: AbortSignal.timeout(3000),
|
|
574
|
-
});
|
|
575
|
-
if (res.ok) return;
|
|
576
|
-
// Only the documented "starting" gate is worth waiting out. Anything
|
|
577
|
-
// else (404, connection refused) means there is no gate here — e.g.
|
|
578
|
-
// test doubles that serve only the leased routes — so proceed and let
|
|
579
|
-
// the caller's own retry budget handle it.
|
|
580
|
-
if (res.status !== 503) return;
|
|
581
|
-
} catch {
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
await new Promise((r) => setTimeout(r, READY_POLL_INTERVAL_MS));
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
|
|
588
557
|
export class GuardianLeasePermanentError extends Error {
|
|
589
558
|
constructor(message: string) {
|
|
590
559
|
super(message);
|
|
@@ -592,32 +561,17 @@ export class GuardianLeasePermanentError extends Error {
|
|
|
592
561
|
}
|
|
593
562
|
}
|
|
594
563
|
|
|
595
|
-
function describeJsonType(value: unknown): string {
|
|
596
|
-
if (value === undefined) return "absent";
|
|
597
|
-
if (value === null) return "null";
|
|
598
|
-
if (Array.isArray(value)) return "array";
|
|
599
|
-
return typeof value;
|
|
600
|
-
}
|
|
601
|
-
|
|
602
564
|
/**
|
|
603
565
|
* Pair with the assistant's gateway and persist the minted credential —
|
|
604
566
|
* the lease every local-topology hatch runs once its gateway is up.
|
|
605
567
|
* The pair operation's transport proves presence; re-pairing IS the repair.
|
|
568
|
+
* Waiting for the gateway's ready gate is the caller's job (the hatch
|
|
569
|
+
* waits on the assistant before leasing) — the lease itself just pairs.
|
|
606
570
|
*/
|
|
607
571
|
export async function leaseGuardianToken(
|
|
608
572
|
entry: LockfileAssistant,
|
|
609
573
|
): Promise<GuardianTokenData> {
|
|
610
|
-
// The gateway address derives from the entry's topology; assistantId and
|
|
611
|
-
// the bootstrap secret ride the entry too. Only the local runtimes lease —
|
|
612
|
-
// they are the topologies a detached hatch records a bootstrap secret for.
|
|
613
|
-
if (entry.cloud !== "local" && entry.cloud !== "docker") {
|
|
614
|
-
throw new Error(
|
|
615
|
-
`Guardian token leasing is not available for '${entry.cloud}' assistants.`,
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
const gatewayUrl = getGatewayUrl(entry);
|
|
619
574
|
const assistantId = entry.assistantId;
|
|
620
|
-
await waitForGatewayReady(gatewayUrl);
|
|
621
575
|
|
|
622
576
|
const deviceId = computeDeviceId();
|
|
623
577
|
const clientReportedName = readClientHostname();
|
|
@@ -176,8 +176,9 @@ export {
|
|
|
176
176
|
getRetiredDir,
|
|
177
177
|
getMetadataPath,
|
|
178
178
|
} from "./remotes/local/archive";
|
|
179
|
-
export {
|
|
179
|
+
export { retireDocker } from "./remotes/docker/retire";
|
|
180
180
|
export { pullImage } from "./remotes/docker/hatch";
|
|
181
|
+
export { dockerResourceNames } from "./remotes/docker/common";
|
|
181
182
|
export { exec, execOutput, execWithStdin, buildExecErrorMessage } from "./exec";
|
|
182
183
|
export {
|
|
183
184
|
isCadetCommandLine,
|
|
@@ -238,3 +239,5 @@ export {
|
|
|
238
239
|
loadGuardianToken,
|
|
239
240
|
} from "./guardian-token";
|
|
240
241
|
export type { TokenResult, GuardianTokenData } from "./guardian-token";
|
|
242
|
+
|
|
243
|
+
export { setLocalSourceRoot } from "./source-root";
|
|
@@ -339,7 +339,9 @@ describe("parseLockfile", () => {
|
|
|
339
339
|
app: { pid: 51, port: 7840, builtSha: "abc1234" },
|
|
340
340
|
};
|
|
341
341
|
expect(parseLockfile(raw).tunnel).toEqual(raw.tunnel);
|
|
342
|
-
|
|
342
|
+
// builtSha is a retired field — pre-rename lockfiles still parse, the
|
|
343
|
+
// stale key just drops (the fingerprint lives in the dist directory now).
|
|
344
|
+
expect(parseLockfile(raw).app).toEqual({ pid: 51, port: 7840 });
|
|
343
345
|
});
|
|
344
346
|
|
|
345
347
|
test("drops a mistyped root process record, never the file", () => {
|
|
@@ -484,12 +484,6 @@ export const AppProcessRecordSchema = z.object({
|
|
|
484
484
|
startedAt: z.string().optional(),
|
|
485
485
|
/** Listening port for the app server. */
|
|
486
486
|
port: z.number(),
|
|
487
|
-
/**
|
|
488
|
-
* The commit the edge's source-built client bundles were last built from
|
|
489
|
-
* — the auto-build staleness stamp. Rides the running edge's record: a
|
|
490
|
-
* build only stamps when an edge record exists to carry it.
|
|
491
|
-
*/
|
|
492
|
-
builtSha: z.string().optional(),
|
|
493
487
|
});
|
|
494
488
|
export type AppProcessRecord = z.infer<typeof AppProcessRecordSchema>;
|
|
495
489
|
|
|
@@ -52,9 +52,9 @@ export async function retireAssistant(
|
|
|
52
52
|
if (cloud === "apple-container") {
|
|
53
53
|
await retireAppleContainer(assistantId, entry);
|
|
54
54
|
} else if (cloud === "docker") {
|
|
55
|
-
await retireDocker(
|
|
55
|
+
await retireDocker(entry);
|
|
56
56
|
} else if (cloud === "local") {
|
|
57
|
-
await retireLocal(
|
|
57
|
+
await retireLocal(entry);
|
|
58
58
|
} else if (cloud === "baseten") {
|
|
59
59
|
await retireBaseten(entry);
|
|
60
60
|
} else if (cloud === "custom") {
|
|
@@ -66,7 +66,7 @@ export async function sleepAssistant(
|
|
|
66
66
|
const wasRunning = await isAssistantHealthy(entry);
|
|
67
67
|
try {
|
|
68
68
|
if (entry.cloud === "docker") {
|
|
69
|
-
await sleepDocker(entry, {
|
|
69
|
+
await sleepDocker(entry, { log: options.log });
|
|
70
70
|
return { ok: true, kind: "containers", wasRunning };
|
|
71
71
|
}
|
|
72
72
|
if (entry.cloud === "local") {
|