@mycadet/cli 0.13.0-dev.202611022129.ce2988d → 0.13.0-dev.202611031057.420f196

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.
Files changed (56) hide show
  1. package/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
  2. package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  3. package/node_modules/@mycadet/environments/package.json +1 -1
  4. package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  5. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
  6. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +1 -1
  7. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
  8. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
  9. package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
  10. package/node_modules/@mycadet/local-mode/package.json +1 -1
  11. package/{src → node_modules/@mycadet/local-mode/src}/__tests__/device-id.test.ts +3 -6
  12. package/node_modules/@mycadet/local-mode/src/__tests__/helpers/env.ts +19 -0
  13. package/node_modules/@mycadet/local-mode/src/__tests__/helpers/os-mock.ts +27 -0
  14. package/node_modules/@mycadet/local-mode/src/__tests__/operations-wake.test.ts +32 -19
  15. package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-recreate.test.ts +72 -0
  16. package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-statefulset.test.ts +307 -0
  17. package/node_modules/@mycadet/local-mode/src/__tests__/remotes-docker-wake.test.ts +176 -0
  18. package/{src/lib → node_modules/@mycadet/local-mode/src}/device-id.ts +4 -4
  19. package/node_modules/@mycadet/local-mode/src/index.ts +20 -2
  20. package/node_modules/@mycadet/local-mode/src/operations/wake.ts +9 -2
  21. package/node_modules/@mycadet/local-mode/src/provider-env-vars.ts +24 -0
  22. package/node_modules/@mycadet/local-mode/src/remotes/docker/recreate.ts +193 -0
  23. package/{src/lib → node_modules/@mycadet/local-mode/src/remotes/docker}/statefulset.ts +22 -7
  24. package/node_modules/@mycadet/local-mode/src/remotes/docker/wake.ts +35 -22
  25. package/node_modules/@mycadet/local-mode/src/remotes/local/common.ts +26 -49
  26. package/node_modules/@mycadet/local-mode/src/remotes/local/wake.ts +3 -13
  27. package/node_modules/@mycadet/service-contracts/package.json +1 -1
  28. package/node_modules/@mycadet/shared/package.json +1 -1
  29. package/package.json +1 -1
  30. package/src/__tests__/app-command.test.ts +3 -3
  31. package/src/__tests__/host-teleport-docker.test.ts +115 -42
  32. package/src/__tests__/root-backup-docker.test.ts +1 -1
  33. package/src/__tests__/root-backup.test.ts +6 -3
  34. package/src/__tests__/search-provider-env-var-parity.test.ts +2 -2
  35. package/src/__tests__/{app-server-state.test.ts → servers/app-server-state.test.ts} +1 -1
  36. package/src/__tests__/{bun.test.ts → servers/bun.test.ts} +12 -14
  37. package/src/__tests__/tunnel.test.ts +5 -5
  38. package/src/__tests__/upgrade-replay-env.test.ts +4 -2
  39. package/src/__tests__/upgrade-root-recovery.test.ts +2 -2
  40. package/src/__tests__/wake.test.ts +41 -116
  41. package/src/commands/app.ts +3 -2
  42. package/src/commands/exec.ts +1 -1
  43. package/src/commands/ps.ts +4 -1
  44. package/src/commands/tunnel.ts +1 -1
  45. package/src/commands/wake.ts +8 -103
  46. package/src/lib/__tests__/docker.test.ts +0 -228
  47. package/src/lib/cloud-releases.ts +1 -1
  48. package/src/lib/host-teleport.ts +11 -186
  49. package/src/lib/remotes/baseten/index.ts +2 -4
  50. package/src/lib/remotes/docker.ts +124 -205
  51. package/src/lib/root-backup.ts +87 -9
  52. package/src/lib/servers/bun.ts +18 -941
  53. package/src/lib/servers/common.ts +946 -0
  54. package/src/lib/upgrade-lifecycle.ts +6 -4
  55. package/src/__tests__/statefulset.test.ts +0 -152
  56. package/src/shared/provider-env-vars.ts +0 -46
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/environments",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/avatar-manifest",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/environments",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/ipc-server-utils",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/service-contracts",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/shared",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "exports": {
6
6
  ".": "./github-repository.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/local-mode",
3
- "version": "0.13.0-dev.202611022129.ce2988d",
3
+ "version": "0.13.0-dev.202611031057.420f196",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,12 +16,9 @@ import { join } from "path";
16
16
  let fakeHome: string | undefined;
17
17
  await mockOsHomedir((realHomedir) => () => fakeHome ?? realHomedir());
18
18
 
19
- import {
20
- getOrCreateHostDeviceId,
21
- resetHostDeviceIdCache,
22
- } from "../lib/device-id.js";
23
- import { snapshotEnv } from "./helpers/env.js";
24
- import { mockOsHomedir } from "./helpers/os-mock.js";
19
+ import { getOrCreateHostDeviceId, resetHostDeviceIdCache } from "../device-id";
20
+ import { snapshotEnv } from "./helpers/env";
21
+ import { mockOsHomedir } from "./helpers/os-mock";
25
22
 
26
23
  const UUID_RE =
27
24
  /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Snapshot the given env vars now; returns a restore function suitable for
3
+ * `afterEach` that resets each var to its captured value (or deletes it).
4
+ */
5
+ export function snapshotEnv(keys: readonly string[]): () => void {
6
+ const saved: Record<string, string | undefined> = {};
7
+ for (const key of keys) {
8
+ saved[key] = process.env[key];
9
+ }
10
+ return () => {
11
+ for (const key of keys) {
12
+ if (saved[key] === undefined) {
13
+ delete process.env[key];
14
+ } else {
15
+ process.env[key] = saved[key];
16
+ }
17
+ }
18
+ };
19
+ }
@@ -0,0 +1,27 @@
1
+ import { mock } from "bun:test";
2
+
3
+ /**
4
+ * Mock `os.homedir()` (both the `"os"` and `"node:os"` specifiers) while
5
+ * keeping every other os export intact.
6
+ *
7
+ * The factory passed to `mock.module()` must only close over plain snapshots
8
+ * captured before the mock is installed. When another test file has already
9
+ * loaded "os", `mock.module()` patches the live namespace in place — a
10
+ * factory that spreads or calls back through that namespace resolves to the
11
+ * mock itself and recurses forever, a synchronous spin that froze the whole
12
+ * suite (and CI) at whichever file loaded next. This helper owns that
13
+ * invariant so test files don't have to.
14
+ *
15
+ * @param makeHomedir Receives the real (pre-mock) `homedir` and returns the
16
+ * replacement implementation.
17
+ */
18
+ export async function mockOsHomedir(
19
+ makeHomedir: (realHomedir: () => string) => () => string,
20
+ ): Promise<void> {
21
+ const realOs = await import("node:os");
22
+ const realOsSnapshot = { ...realOs };
23
+ const homedir = makeHomedir(realOs.homedir);
24
+ const factory = () => ({ ...realOsSnapshot, homedir });
25
+ mock.module("node:os", factory);
26
+ mock.module("os", factory);
27
+ }
@@ -150,6 +150,38 @@ describe("the wake operation — a remote -> method router", () => {
150
150
  expect(result).toEqual({ ok: true });
151
151
  expect(wakeLocalMock).toHaveBeenCalledWith(
152
152
  expect.objectContaining({ assistantId: "asst-local" }),
153
+ {},
154
+ );
155
+ });
156
+
157
+ test("the local leg receives the caller's launch opts", async () => {
158
+ await wakeAssistant(
159
+ {
160
+ assistantId: "asst-local",
161
+ cloud: "local",
162
+ port: 7830,
163
+ } as LockfileAssistant,
164
+ { watch: true },
165
+ );
166
+
167
+ expect(wakeLocalMock).toHaveBeenCalledWith(
168
+ expect.objectContaining({ assistantId: "asst-local" }),
169
+ { watch: true },
170
+ );
171
+ });
172
+
173
+ test("the docker leg never sees the launch opts — its containers run detached", async () => {
174
+ await wakeAssistant(
175
+ {
176
+ assistantId: "asst-docker",
177
+ cloud: "docker",
178
+ port: 7831,
179
+ } as LockfileAssistant,
180
+ { watch: true },
181
+ );
182
+
183
+ expect(wakeDockerMock).toHaveBeenCalledWith(
184
+ expect.objectContaining({ assistantId: "asst-docker" }),
153
185
  );
154
186
  });
155
187
 
@@ -184,25 +216,6 @@ describe("the wake operation — a remote -> method router", () => {
184
216
  );
185
217
  });
186
218
 
187
- test("a docker entry's structured 404 carries the recreate pointer through", async () => {
188
- wakeDockerMock.mockResolvedValue({
189
- ok: false,
190
- status: 404,
191
- error:
192
- "the containers for 'asst-docker' don't exist yet — run `cadet wake` once to recreate them from the recorded images",
193
- });
194
- const result = await wakeAssistant({
195
- assistantId: "asst-docker",
196
- cloud: "docker",
197
- port: 7831,
198
- } as LockfileAssistant);
199
- expect(result.ok).toBe(false);
200
- expect((result as { status: number }).status).toBe(404);
201
- expect((result as { error: string }).error).toContain(
202
- "run `cadet wake` once to recreate",
203
- );
204
- });
205
-
206
219
  test("a docker wake failure carries the docker error", async () => {
207
220
  wakeDockerMock.mockResolvedValue({
208
221
  ok: false,
@@ -0,0 +1,72 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import { pullImage } from "../remotes/docker/recreate";
4
+
5
+ describe("pullImage", () => {
6
+ function fakePull(
7
+ opts: {
8
+ failFirstPullWith?: string;
9
+ failAllPullsWith?: string;
10
+ } = {},
11
+ ) {
12
+ const calls: Array<{ cmd: string; args: string[] }> = [];
13
+ let pulls = 0;
14
+ const exec = async (cmd: string, args: string[] = []): Promise<void> => {
15
+ calls.push({ cmd, args });
16
+ if (cmd === "docker" && args[0] === "pull") {
17
+ pulls++;
18
+ if (opts.failAllPullsWith) throw new Error(opts.failAllPullsWith);
19
+ if (opts.failFirstPullWith && pulls === 1) {
20
+ throw new Error(opts.failFirstPullWith);
21
+ }
22
+ }
23
+ // `docker logout` (and anything else) succeeds silently.
24
+ };
25
+ const ran = (sub: string): boolean =>
26
+ calls.some((c) => c.cmd === "docker" && c.args[0] === sub);
27
+ return { exec, ran };
28
+ }
29
+
30
+ test("pulls without touching stored credentials on success", async () => {
31
+ const { exec, ran } = fakePull();
32
+
33
+ await pullImage("mycadet/mycadet-assistant:v1", () => {}, exec);
34
+
35
+ expect(ran("pull")).toBe(true);
36
+ expect(ran("logout")).toBe(false);
37
+ });
38
+
39
+ test("clears stale Docker Hub credentials and retries once on an expired-token error", async () => {
40
+ const { exec, ran } = fakePull({
41
+ failFirstPullWith:
42
+ "Error response from daemon: authentication required - personal access token is expired",
43
+ });
44
+
45
+ await pullImage("mycadet/mycadet-assistant:v1", () => {}, exec);
46
+
47
+ expect(ran("logout")).toBe(true);
48
+ });
49
+
50
+ test("wraps the failure with actionable copy when the auth retry also fails", () => {
51
+ const { exec } = fakePull({
52
+ failAllPullsWith:
53
+ "Error response from daemon: authentication required - personal access token is expired",
54
+ });
55
+
56
+ expect(
57
+ pullImage("mycadet/mycadet-assistant:v1", () => {}, exec),
58
+ ).rejects.toThrow("Failed to pull mycadet/mycadet-assistant:v1");
59
+ });
60
+
61
+ test("rethrows non-auth pull errors raw and never logs out", () => {
62
+ const { exec, ran } = fakePull({
63
+ failAllPullsWith:
64
+ "Cannot connect to the Docker daemon at unix:///var/run/docker.sock",
65
+ });
66
+
67
+ expect(
68
+ pullImage("mycadet/mycadet-assistant:v1", () => {}, exec),
69
+ ).rejects.toThrow("Cannot connect to the Docker daemon");
70
+ expect(ran("logout")).toBe(false);
71
+ });
72
+ });
@@ -0,0 +1,307 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
+ import {
3
+ AVATAR_DEVICE_ENV_VAR,
4
+ buildServiceRunArgs,
5
+ getBuilderManagedEnvKeys,
6
+ resolveAvatarDevicePath,
7
+ type BuildServiceRunArgsOpts,
8
+ type DockerStatefulSetSpec,
9
+ type ServiceName,
10
+ } from "../remotes/docker/statefulset";
11
+ import { dockerResourceNames } from "../remotes/docker/retire";
12
+ import { ASSISTANT_INTERNAL_PORT } from "../ports";
13
+ import { PROVIDER_ENV_VAR_NAMES } from "../provider-env-vars";
14
+
15
+ const instanceName = "test-instance";
16
+ const imageTags: Record<ServiceName, string> = {
17
+ assistant: "mycadet/mycadet:test",
18
+ "credential-executor": "mycadet/cadet-credential-executor:test",
19
+ gateway: "mycadet/cadet-gateway:test",
20
+ };
21
+
22
+ function buildAssistantArgs(
23
+ overrides: Partial<Parameters<typeof buildServiceRunArgs>[0]> = {},
24
+ ): string[] {
25
+ const res = dockerResourceNames(instanceName);
26
+ const builders = buildServiceRunArgs({
27
+ gatewayPort: 7830,
28
+ imageTags,
29
+ instanceName,
30
+ res,
31
+ ...overrides,
32
+ });
33
+ return builders.assistant();
34
+ }
35
+
36
+ function buildGatewayArgs(
37
+ overrides: Partial<Parameters<typeof buildServiceRunArgs>[0]> = {},
38
+ ): string[] {
39
+ const res = dockerResourceNames(instanceName);
40
+ const builders = buildServiceRunArgs({
41
+ gatewayPort: 7830,
42
+ imageTags,
43
+ instanceName,
44
+ res,
45
+ ...overrides,
46
+ });
47
+ return builders.gateway();
48
+ }
49
+
50
+ const SECRET_KEYS = ["CES_SERVICE_TOKEN"];
51
+
52
+ describe("getBuilderManagedEnvKeys", () => {
53
+ test("gateway always-set keys cover spec static + secret entries and PATH", () => {
54
+ const { always } = getBuilderManagedEnvKeys("gateway");
55
+
56
+ const expected = [
57
+ "CADET_WORKSPACE_DIR",
58
+ "GATEWAY_SECURITY_DIR",
59
+ "ASSISTANT_HOST",
60
+ "CES_CREDENTIAL_URL",
61
+ "GATEWAY_IPC_SOCKET_DIR",
62
+ "ASSISTANT_IPC_SOCKET_DIR",
63
+ "GATEWAY_PORT",
64
+ "RUNTIME_HTTP_PORT",
65
+ ...SECRET_KEYS,
66
+ "PATH",
67
+ ];
68
+ for (const key of expected) {
69
+ expect(always.has(key)).toBe(true);
70
+ }
71
+
72
+ expect(always.has("CADET_DEVICE_ID")).toBe(false);
73
+ });
74
+
75
+ test("assistant always-set keys include secrets and builder-computed extras", () => {
76
+ const { always } = getBuilderManagedEnvKeys("assistant");
77
+
78
+ const expected = [
79
+ ...SECRET_KEYS,
80
+ "CADET_ASSISTANT_NAME",
81
+ "GATEWAY_INTERNAL_URL",
82
+ "RUNTIME_HTTP_HOST",
83
+ "PATH",
84
+ ];
85
+ for (const key of expected) {
86
+ expect(always.has(key)).toBe(true);
87
+ }
88
+ });
89
+
90
+ test("gateway hostForwarded equals the three spec host entries", () => {
91
+ const { hostForwarded } = getBuilderManagedEnvKeys("gateway");
92
+ const sorted = [...hostForwarded].sort((a, b) =>
93
+ a.name.localeCompare(b.name),
94
+ );
95
+ expect(sorted).toEqual([
96
+ { name: "CADET_CLOUD_URL", hostVar: "CADET_CLOUD_URL" },
97
+ { name: "CADET_ENVIRONMENT", hostVar: "CADET_ENVIRONMENT" },
98
+ { name: "TUNNEL_BASE_URL", hostVar: "TUNNEL_BASE_URL" },
99
+ ]);
100
+ });
101
+
102
+ test("assistant hostForwarded includes provider keys and platform URL", () => {
103
+ const { hostForwarded } = getBuilderManagedEnvKeys("assistant");
104
+ expect(hostForwarded).toContainEqual({
105
+ name: "ANTHROPIC_API_KEY",
106
+ hostVar: "ANTHROPIC_API_KEY",
107
+ });
108
+ for (const envVar of Object.values(PROVIDER_ENV_VAR_NAMES)) {
109
+ expect(hostForwarded).toContainEqual({ name: envVar, hostVar: envVar });
110
+ }
111
+ expect(hostForwarded).toContainEqual({
112
+ name: "CADET_CLOUD_URL",
113
+ hostVar: "CADET_CLOUD_URL",
114
+ });
115
+ });
116
+
117
+ test("hostForwarded keeps container name when hostVar differs", () => {
118
+ const spec: DockerStatefulSetSpec = {
119
+ startOrder: ["gateway"],
120
+ readiness: { endpoint: "/readyz", timeoutMs: 1, intervalMs: 1 },
121
+ volumeClaimTemplates: [],
122
+ containers: [
123
+ {
124
+ name: "gateway-sidecar",
125
+ internalName: "gateway",
126
+ network: "container",
127
+ env: [{ kind: "host", name: "CONTAINER_NAME", hostVar: "HOST_NAME" }],
128
+ volumeMounts: [],
129
+ },
130
+ ],
131
+ };
132
+
133
+ const { hostForwarded } = getBuilderManagedEnvKeys("gateway", spec);
134
+ expect(hostForwarded).toEqual([
135
+ { name: "CONTAINER_NAME", hostVar: "HOST_NAME" },
136
+ ]);
137
+ });
138
+
139
+ test("throws on unknown service name", () => {
140
+ expect(() => getBuilderManagedEnvKeys("bogus" as ServiceName)).toThrow(
141
+ 'docker-statefulset: unknown service "bogus"',
142
+ );
143
+ });
144
+ });
145
+
146
+ describe("buildServiceRunArgs extra env routing", () => {
147
+ const opts: BuildServiceRunArgsOpts = {
148
+ gatewayPort: 18080,
149
+ imageTags: {
150
+ assistant: "assistant:test",
151
+ gateway: "gateway:test",
152
+ "credential-executor": "ces:test",
153
+ },
154
+ instanceName: "test-instance",
155
+ res: {
156
+ assistantContainer: "test-assistant",
157
+ cesContainer: "test-ces",
158
+ gatewayContainer: "test-gateway",
159
+ network: "test-net",
160
+ },
161
+ extraGatewayEnv: { BAR: "1" },
162
+ extraAssistantEnv: { FOO: "bar" },
163
+ };
164
+
165
+ const runArgs = buildServiceRunArgs(opts);
166
+
167
+ test("extraGatewayEnv lands only in gateway args", () => {
168
+ const gatewayArgs = runArgs.gateway();
169
+ expect(gatewayArgs).toContain("BAR=1");
170
+ expect(gatewayArgs).not.toContain("FOO=bar");
171
+ });
172
+
173
+ test("extraAssistantEnv lands only in assistant args", () => {
174
+ const assistantArgs = runArgs.assistant();
175
+ expect(assistantArgs).toContain("FOO=bar");
176
+ expect(assistantArgs).not.toContain("BAR=1");
177
+ });
178
+
179
+ test("credential-executor args get neither extra env map", () => {
180
+ const cesArgs = runArgs["credential-executor"]();
181
+ expect(cesArgs).not.toContain("BAR=1");
182
+ expect(cesArgs).not.toContain("FOO=bar");
183
+ });
184
+
185
+ test("credential-executor args carry the /ces-security and /ces-data wiring", () => {
186
+ const cesArgs = runArgs["credential-executor"]();
187
+ expect(cesArgs).toContain("CREDENTIAL_SECURITY_DIR=/ces-security");
188
+ expect(cesArgs).toContain("CES_DATA_DIR=/ces-data");
189
+ });
190
+ });
191
+
192
+ describe("buildServiceRunArgs — assistant", () => {
193
+ test("does not grant elevated capabilities or disable security profiles", () => {
194
+ const args = buildAssistantArgs();
195
+ expect(args).not.toContain("--privileged");
196
+ expect(args).not.toContain("--cap-add");
197
+ expect(args).not.toContain("SYS_ADMIN");
198
+ expect(args).not.toContain("NET_ADMIN");
199
+ expect(args).not.toContain("seccomp=unconfined");
200
+ expect(args).not.toContain("apparmor=unconfined");
201
+ });
202
+
203
+ test("does not mount a dockerd data volume", () => {
204
+ const args = buildAssistantArgs();
205
+ expect(args.some((a) => a.includes("/var/lib/docker"))).toBe(false);
206
+ });
207
+
208
+ test("does NOT bind-mount the host Docker socket", () => {
209
+ const args = buildAssistantArgs();
210
+ expect(args).not.toContain("/var/run/docker.sock:/var/run/docker.sock");
211
+ });
212
+
213
+ test("keeps existing workspace and socket volume mounts intact", () => {
214
+ const args = buildAssistantArgs();
215
+ expect(args).toContain(`${instanceName}-workspace:/workspace`);
216
+ expect(args).toContain(`${instanceName}-socket:/run/ces-bootstrap`);
217
+ });
218
+
219
+ test("preserves existing required env vars", () => {
220
+ const args = buildAssistantArgs();
221
+ expect(args).toContain("IS_CONTAINERIZED=true");
222
+ expect(args).toContain("CADET_WORKSPACE_DIR=/workspace");
223
+ expect(args).toContain("CES_BOOTSTRAP_SOCKET_DIR=/run/ces-bootstrap");
224
+ expect(args).toContain(`CADET_ASSISTANT_NAME=${instanceName}`);
225
+ });
226
+
227
+ test("publishes the assistant HTTP port loopback-only — the same-pod gateway and host-local tooling are the only callers", () => {
228
+ const args = buildAssistantArgs();
229
+ // The port mapping is expressed as two adjacent args: "-p" then the spec.
230
+ // Bound to `127.0.0.1:` — the assistant HTTP API serves the gateway (same
231
+ // pod) and host-local tooling; the gateway's edge is the only ingress, so
232
+ // the API never faces the LAN.
233
+ const portSpec = `127.0.0.1:${ASSISTANT_INTERNAL_PORT}:${ASSISTANT_INTERNAL_PORT}`;
234
+ const portIndex = args.indexOf(portSpec);
235
+ expect(portIndex).toBeGreaterThan(0);
236
+ expect(args[portIndex - 1]).toBe("-p");
237
+ });
238
+ });
239
+
240
+ describe("buildServiceRunArgs — gateway", () => {
241
+ const savedTunnelBaseUrl = process.env.TUNNEL_BASE_URL;
242
+
243
+ beforeEach(() => {
244
+ delete process.env.TUNNEL_BASE_URL;
245
+ });
246
+
247
+ afterEach(() => {
248
+ if (savedTunnelBaseUrl === undefined) delete process.env.TUNNEL_BASE_URL;
249
+ else process.env.TUNNEL_BASE_URL = savedTunnelBaseUrl;
250
+ });
251
+
252
+ test("passes TUNNEL_BASE_URL into the gateway container when set", () => {
253
+ process.env.TUNNEL_BASE_URL = "http://host.docker.internal:8501";
254
+
255
+ expect(buildGatewayArgs()).toContain(
256
+ "TUNNEL_BASE_URL=http://host.docker.internal:8501",
257
+ );
258
+ });
259
+
260
+ test("omits TUNNEL_BASE_URL from gateway args when unset", () => {
261
+ expect(
262
+ buildGatewayArgs().some((arg) => arg.startsWith("TUNNEL_BASE_URL=")),
263
+ ).toBe(false);
264
+ });
265
+
266
+ test("forces gateway to run as uid 0 so it can connect to the assistant's root-owned IPC socket (mirrors K8s securityContext.runAsUser=0)", () => {
267
+ const args = buildGatewayArgs();
268
+ const userIdx = args.indexOf("--user");
269
+ expect(userIdx).toBeGreaterThan(-1);
270
+ expect(args[userIdx + 1]).toBe("0");
271
+ });
272
+
273
+ test("assistant container does NOT get a --user override (image USER root wins)", () => {
274
+ expect(buildAssistantArgs().includes("--user")).toBe(false);
275
+ });
276
+ });
277
+
278
+ describe("CADET_AVATAR_DEVICE passthrough", () => {
279
+ const savedValue = process.env[AVATAR_DEVICE_ENV_VAR];
280
+
281
+ beforeEach(() => {
282
+ delete process.env[AVATAR_DEVICE_ENV_VAR];
283
+ });
284
+
285
+ afterEach(() => {
286
+ if (savedValue === undefined) delete process.env[AVATAR_DEVICE_ENV_VAR];
287
+ else process.env[AVATAR_DEVICE_ENV_VAR] = savedValue;
288
+ });
289
+
290
+ test("resolveAvatarDevicePath returns default when env var is unset", () => {
291
+ expect(resolveAvatarDevicePath({})).toBe("/dev/video10");
292
+ });
293
+
294
+ test("resolveAvatarDevicePath honors override", () => {
295
+ expect(
296
+ resolveAvatarDevicePath({ [AVATAR_DEVICE_ENV_VAR]: "/dev/video11" }),
297
+ ).toBe("/dev/video11");
298
+ });
299
+
300
+ test("assistant args omit --device and env var when device node is absent", () => {
301
+ const args = buildAssistantArgs();
302
+ expect(args).not.toContain("--device");
303
+ expect(args.some((a) => a.startsWith(`${AVATAR_DEVICE_ENV_VAR}=`))).toBe(
304
+ false,
305
+ );
306
+ });
307
+ });