@exagone313/dsh-podman 1.0.3 → 1.1.0

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 (140) hide show
  1. package/README.md +1 -0
  2. package/README.zh.md +1 -0
  3. package/dist/approval-reasons.d.ts +12 -0
  4. package/dist/approval-reasons.js +15 -0
  5. package/dist/approval.js +21 -0
  6. package/dist/card-route.js +83 -1
  7. package/dist/client/ContainerCard.js +14 -2
  8. package/dist/client/card-protocol.d.ts +16 -1
  9. package/dist/client/container-card-controller.d.ts +8 -2
  10. package/dist/client/container-card-controller.js +21 -0
  11. package/dist/client/container-card-ports.d.ts +13 -0
  12. package/dist/client/container-card-ports.js +74 -0
  13. package/dist/client/container-card-row.d.ts +3 -0
  14. package/dist/client/container-card-row.js +12 -2
  15. package/dist/client/container-card-workspace.d.ts +3 -0
  16. package/dist/client/container-card-workspace.js +2 -2
  17. package/dist/client/index.js +653 -386
  18. package/dist/client/locales.d.ts +1 -1
  19. package/dist/client/locales.js +30 -0
  20. package/dist/client/tool-presentations.d.ts +167 -0
  21. package/dist/client/tool-presentations.js +167 -0
  22. package/dist/client/tool-views.d.ts +1 -2
  23. package/dist/client/tool-views.js +54 -190
  24. package/dist/generated/version.d.ts +2 -2
  25. package/dist/generated/version.js +2 -2
  26. package/dist/grpc/proto/dshctl/v1/control.proto +47 -1
  27. package/dist/grpc/proto/dshgateway/v1/gateway.proto +89 -0
  28. package/dist/grpc/proto/dshguest/v1/guest.proto +17 -0
  29. package/dist/index.d.ts +3 -2
  30. package/dist/index.js +3 -2
  31. package/dist/public.d.ts +1 -0
  32. package/dist/public.js +14 -0
  33. package/dist/publish-port.d.ts +6 -0
  34. package/dist/publish-port.js +37 -0
  35. package/dist/tool-defs.js +15 -1
  36. package/dist/tool-handlers.js +31 -1
  37. package/dist/tool-params.d.ts +48 -0
  38. package/dist/tool-params.js +42 -0
  39. package/docs/architecture.md +44 -7
  40. package/docs/architecture.zh.md +38 -6
  41. package/docs/configuration.md +25 -0
  42. package/docs/configuration.zh.md +23 -0
  43. package/docs/development.md +17 -6
  44. package/docs/development.zh.md +16 -6
  45. package/docs/install-dsh-and-dsh-podman.md +10 -4
  46. package/docs/install-dsh-and-dsh-podman.zh.md +9 -3
  47. package/docs/uninstall.md +4 -3
  48. package/docs/uninstall.zh.md +3 -2
  49. package/docs/update.md +23 -6
  50. package/docs/update.zh.md +23 -6
  51. package/docs/usage.md +48 -13
  52. package/docs/usage.zh.md +31 -2
  53. package/package.json +3 -1
  54. package/quadlet/dsh-podman-gateway.container +23 -0
  55. package/quadlet/dsh-podman-orchestrator.container +1 -1
  56. package/quadlet/dsh.container +1 -1
  57. package/dist/approval-reasons.test.d.ts +0 -1
  58. package/dist/approval-reasons.test.js +0 -143
  59. package/dist/approval.test.d.ts +0 -1
  60. package/dist/approval.test.js +0 -593
  61. package/dist/card-route.test.d.ts +0 -1
  62. package/dist/card-route.test.js +0 -223
  63. package/dist/card-test-support.d.ts +0 -15
  64. package/dist/card-test-support.js +0 -133
  65. package/dist/container-env.test.d.ts +0 -1
  66. package/dist/container-env.test.js +0 -93
  67. package/dist/containers.test.d.ts +0 -1
  68. package/dist/containers.test.js +0 -621
  69. package/dist/daemons.test.d.ts +0 -1
  70. package/dist/daemons.test.js +0 -167
  71. package/dist/dsh-version.test.d.ts +0 -1
  72. package/dist/dsh-version.test.js +0 -25
  73. package/dist/env-rows.test.d.ts +0 -1
  74. package/dist/env-rows.test.js +0 -43
  75. package/dist/fs-provider.test.d.ts +0 -1
  76. package/dist/fs-provider.test.js +0 -301
  77. package/dist/guest-rpc.test.d.ts +0 -1
  78. package/dist/guest-rpc.test.js +0 -241
  79. package/dist/images.test.d.ts +0 -1
  80. package/dist/images.test.js +0 -86
  81. package/dist/locales.test.d.ts +0 -1
  82. package/dist/locales.test.js +0 -34
  83. package/dist/misc.test.d.ts +0 -1
  84. package/dist/misc.test.js +0 -169
  85. package/dist/mounts.test.d.ts +0 -1
  86. package/dist/mounts.test.js +0 -478
  87. package/dist/naming.test.d.ts +0 -1
  88. package/dist/naming.test.js +0 -28
  89. package/dist/package-deps.test.d.ts +0 -1
  90. package/dist/package-deps.test.js +0 -49
  91. package/dist/paths.test.d.ts +0 -1
  92. package/dist/paths.test.js +0 -76
  93. package/dist/plugin-meta.test.d.ts +0 -1
  94. package/dist/plugin-meta.test.js +0 -29
  95. package/dist/project-path.test.d.ts +0 -1
  96. package/dist/project-path.test.js +0 -66
  97. package/dist/read-only-shell.test.d.ts +0 -1
  98. package/dist/read-only-shell.test.js +0 -182
  99. package/dist/runtime-client.test.d.ts +0 -1
  100. package/dist/runtime-client.test.js +0 -53
  101. package/dist/secrets.test.d.ts +0 -1
  102. package/dist/secrets.test.js +0 -196
  103. package/dist/settings-commands.test.d.ts +0 -1
  104. package/dist/settings-commands.test.js +0 -596
  105. package/dist/settings-create.test.d.ts +0 -1
  106. package/dist/settings-create.test.js +0 -416
  107. package/dist/settings-default-env.test.d.ts +0 -1
  108. package/dist/settings-default-env.test.js +0 -175
  109. package/dist/settings-mounts.test.d.ts +0 -1
  110. package/dist/settings-mounts.test.js +0 -506
  111. package/dist/settings-paths.test.d.ts +0 -1
  112. package/dist/settings-paths.test.js +0 -65
  113. package/dist/settings-schema.test.d.ts +0 -1
  114. package/dist/settings-schema.test.js +0 -35
  115. package/dist/settings-workspaces.test.d.ts +0 -1
  116. package/dist/settings-workspaces.test.js +0 -240
  117. package/dist/spill-store.test.d.ts +0 -1
  118. package/dist/spill-store.test.js +0 -82
  119. package/dist/subprocess.test.d.ts +0 -1
  120. package/dist/subprocess.test.js +0 -344
  121. package/dist/terminal-preference.test.d.ts +0 -1
  122. package/dist/terminal-preference.test.js +0 -62
  123. package/dist/terminal-route.test.d.ts +0 -1
  124. package/dist/terminal-route.test.js +0 -265
  125. package/dist/terminal-tab.test.d.ts +0 -1
  126. package/dist/terminal-tab.test.js +0 -58
  127. package/dist/terminal-targets.test.d.ts +0 -1
  128. package/dist/terminal-targets.test.js +0 -43
  129. package/dist/terminal-titles.test.d.ts +0 -1
  130. package/dist/terminal-titles.test.js +0 -36
  131. package/dist/test-support.d.ts +0 -358
  132. package/dist/test-support.js +0 -499
  133. package/dist/version-compat.test.d.ts +0 -1
  134. package/dist/version-compat.test.js +0 -27
  135. package/dist/views.test.d.ts +0 -1
  136. package/dist/views.test.js +0 -23
  137. package/dist/volumes.test.d.ts +0 -1
  138. package/dist/volumes.test.js +0 -40
  139. package/dist/workspace-binding.test.d.ts +0 -1
  140. package/dist/workspace-binding.test.js +0 -523
@@ -1,478 +0,0 @@
1
- // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
- //
3
- // SPDX-License-Identifier: MIT
4
- import test from "node:test";
5
- import assert from "node:assert/strict";
6
- import { guestExecRecorder, MOUNT_EXEC, MOUNT_TOOLS, mountRequestRecorder, testReadSession, WORKSPACE_ID, } from "./test-support.js";
7
- import { approvalDecision, preExecutePolicy, summarizeArgs, toolHandlers, TOOLS, } from "./index.js";
8
- import { forcedMountMode } from "./mount-enums.js";
9
- import { mountInputToProto, mountsFromInput, validateMountInput, } from "./mount-input.js";
10
- test("mount validation is shared between the tools and the card", () => {
11
- // A secret mount is read-only on every entry point.
12
- assert.throws(() => validateMountInput({ kind: "secret", secret: "s", mode: "read_write" }, "/projects"), /read-only/);
13
- assert.throws(() => mountInputToProto({ kind: "secret", secret: "s", mode: "read_write" }, "/projects"), /read-only/);
14
- // A project mount never takes a destination.
15
- assert.throws(() => mountInputToProto({ kind: "project", project: "p", destination: "/x" }, "/projects"), /destination/);
16
- assert.deepEqual(mountInputToProto({ kind: "project", project: "team" }, "/projects"), {
17
- projectName: "team",
18
- kind: "MOUNT_KIND_PROJECT",
19
- mode: "MOUNT_MODE_READ_ONLY",
20
- });
21
- assert.deepEqual(mountInputToProto({ kind: "secret", secret: "s", destination: "/run/s" }, "/projects"), {
22
- projectName: "",
23
- kind: "MOUNT_KIND_SECRET",
24
- mode: "MOUNT_MODE_READ_ONLY",
25
- destination: "/run/s",
26
- secret: "s",
27
- });
28
- assert.deepEqual(mountsFromInput([{ kind: "tmpfs", destination: "/data" }], "/projects"), [
29
- {
30
- projectName: "",
31
- kind: "MOUNT_KIND_TMPFS",
32
- mode: "MOUNT_MODE_READ_WRITE",
33
- destination: "/data",
34
- },
35
- ]);
36
- });
37
- test("container_start approval depends on mounts being passed", () => {
38
- const tool = TOOLS.find((entry) => entry.name === "container_start");
39
- assert.ok(tool, "container_start registered");
40
- assert.notEqual(tool.approval, true, "container_start must not always ask");
41
- assert.ok(typeof tool.approvalWhen === "function", "container_start approvalWhen");
42
- assert.equal(approvalDecision("container_start", { container: "web" }), undefined, "no mounts: must not ask");
43
- assert.equal(approvalDecision("container_start", { container: "web", mounts: [] }), undefined, "empty mounts: must not ask");
44
- const decision = approvalDecision("container_start", {
45
- container: "web",
46
- image: "localhost/dsh-podman/nginx:latest",
47
- mounts: [
48
- { project: "team/src", mode: "read_only" },
49
- { project: "team", destination: "/workspace/team", mode: "read_write" },
50
- ],
51
- });
52
- assert.ok(decision, "mounts passed: must ask");
53
- assert.equal(decision.kind, "ask");
54
- assert.equal(decision.reason, 'Start container "web" from image "localhost/dsh-podman/nginx:latest" with mounts: project "team/src" (read-only), project "team" at "/workspace/team" (read-write).');
55
- });
56
- test("summarizeArgs infers the mount target when kind is omitted", () => {
57
- assert.equal(summarizeArgs("container_mount_remove", {
58
- container: "valkey-ctr",
59
- secret: "valkey-tls",
60
- }), 'Remove mount from container "valkey-ctr": secret "valkey-tls".');
61
- assert.equal(summarizeArgs("container_mount_add", {
62
- container: "valkey-ctr",
63
- volume: "valkey-data",
64
- }), 'Add mount to container "valkey-ctr": volume "valkey-data" (read-only).');
65
- });
66
- test("preExecutePolicy denies project mounts that carry a destination", async () => {
67
- const deny = (await preExecutePolicy({
68
- name: "container_mount_add",
69
- arguments: {
70
- kind: "project",
71
- project: "team/src",
72
- destination: "/custom",
73
- },
74
- }, () => Promise.resolve({ kind: "allow" }), () => "/projects"));
75
- assert.equal(deny.kind, "deny", "must deny instead of asking");
76
- assert.equal(deny.reason, 'Project mounts cannot set a destination; "team/src" always mounts at "/projects/team/src".');
77
- const startDeny = (await preExecutePolicy({
78
- name: "container_start",
79
- arguments: {
80
- container: "web",
81
- mounts: [
82
- { project: "team", mode: "read_only" },
83
- { kind: "project", project: "team", destination: "/x" },
84
- ],
85
- },
86
- }, () => Promise.resolve({ kind: "allow" }), () => "/projects"));
87
- assert.equal(startDeny.kind, "deny", "a mounts array with a project destination must deny");
88
- const volumeAllowed = (await preExecutePolicy({
89
- name: "container_mount_add",
90
- arguments: { kind: "volume", volume: "data", destination: "/data" },
91
- }, () => Promise.resolve({ kind: "ask", reason: "x" })));
92
- assert.equal(volumeAllowed.kind, "ask", "non-project mounts with a destination must still ask");
93
- const underNever = (await preExecutePolicy({
94
- name: "container_mount_add",
95
- arguments: { kind: "project", project: "team", destination: "/x" },
96
- agent: { session: { facts: { policy: "never" } } },
97
- }, () => Promise.resolve({ kind: "allow" }), () => "/projects", undefined, testReadSession));
98
- assert.equal(underNever.kind, "deny", "full access must not accept an invalid project mount");
99
- });
100
- test("mount tools are registered with the expected schemas", () => {
101
- const listTool = TOOLS.find((entry) => entry.name === "container_mount_list");
102
- assert.ok(listTool, "container_mount_list registered");
103
- assert.notEqual(listTool.approval, true, "container_mount_list must not require approval");
104
- assert.deepEqual(listTool.parameters.required, ["container"]);
105
- const addTool = TOOLS.find((entry) => entry.name === "container_mount_add");
106
- assert.ok(addTool, "container_mount_add registered");
107
- assert.equal(addTool.approval, true, "container_mount_add must require approval");
108
- assert.deepEqual(addTool.parameters.required, ["container"]);
109
- assert.deepEqual(addTool.parameters.properties.mode.enum, [
110
- "read_only",
111
- "read_write",
112
- ]);
113
- assert.deepEqual(addTool.parameters.properties.kind.enum, [
114
- "project",
115
- "tmpfs",
116
- "volume",
117
- "secret",
118
- ]);
119
- assert.equal(typeof addTool.parameters.properties.volume, "object", "container_mount_add accepts a volume");
120
- assert.equal(typeof addTool.parameters.properties.secret, "object", "container_mount_add accepts a secret");
121
- const removeTool = TOOLS.find((entry) => entry.name === "container_mount_remove");
122
- assert.ok(removeTool, "container_mount_remove registered");
123
- assert.equal(removeTool.approval, true, "container_mount_remove must require approval");
124
- assert.deepEqual(removeTool.parameters.required, ["container"]);
125
- assert.deepEqual(removeTool.parameters.properties.kind.enum, [
126
- "project",
127
- "tmpfs",
128
- "volume",
129
- "secret",
130
- ]);
131
- assert.equal(typeof removeTool.parameters.properties.volume, "object", "container_mount_remove accepts a volume");
132
- assert.equal(typeof removeTool.parameters.properties.secret, "object", "container_mount_remove accepts a secret");
133
- assert.equal(typeof removeTool.parameters.properties.destination, "object", "container_mount_remove accepts a destination");
134
- const updateTool = TOOLS.find((entry) => entry.name === "container_mount_update");
135
- assert.ok(updateTool, "container_mount_update registered");
136
- assert.equal(updateTool.approval, true, "container_mount_update must require approval");
137
- assert.deepEqual(updateTool.parameters.required, ["container", "mode"]);
138
- assert.deepEqual(updateTool.parameters.properties.kind.enum, [
139
- "project",
140
- "volume",
141
- ]);
142
- assert.deepEqual(updateTool.parameters.properties.mode.enum, [
143
- "read_only",
144
- "read_write",
145
- ]);
146
- assert.equal(typeof updateTool.parameters.properties.destination, "object", "container_mount_update accepts a destination");
147
- });
148
- test("an omitted mount kind is inferred from the source field", async () => {
149
- const { requests, resolver } = mountRequestRecorder();
150
- await toolHandlers.container_mount_remove(resolver, { container: "valkey-ctr", secret: "valkey-tls" }, MOUNT_EXEC);
151
- await toolHandlers.container_mount_add(resolver, { container: "valkey-ctr", volume: "valkey-data", destination: "/data" }, MOUNT_EXEC);
152
- assert.deepEqual(requests[0], [
153
- "removeContainerMount",
154
- {
155
- workspaceSlug: WORKSPACE_ID,
156
- container: "valkey-ctr",
157
- kind: "MOUNT_KIND_SECRET",
158
- secret: "valkey-tls",
159
- },
160
- ]);
161
- assert.deepEqual(requests[1], [
162
- "addContainerMount",
163
- {
164
- workspaceSlug: WORKSPACE_ID,
165
- container: "valkey-ctr",
166
- kind: "MOUNT_KIND_VOLUME",
167
- volume: "valkey-data",
168
- destination: "/data",
169
- mode: "MOUNT_MODE_READ_ONLY",
170
- },
171
- ]);
172
- });
173
- test("container_mount_update maps the selector and mode", async () => {
174
- const { requests, resolver } = mountRequestRecorder();
175
- await toolHandlers.container_mount_update(resolver, {
176
- container: "valkey-ctr",
177
- kind: "project",
178
- project: "team/src",
179
- mode: "read_only",
180
- }, MOUNT_EXEC);
181
- await toolHandlers.container_mount_update(resolver, {
182
- container: "valkey-ctr",
183
- volume: "valkey-data",
184
- destination: "/data",
185
- mode: "read_write",
186
- }, MOUNT_EXEC);
187
- assert.deepEqual(requests[0], [
188
- "updateContainerMount",
189
- {
190
- workspaceSlug: WORKSPACE_ID,
191
- container: "valkey-ctr",
192
- kind: "MOUNT_KIND_PROJECT",
193
- project: "team/src",
194
- mode: "MOUNT_MODE_READ_ONLY",
195
- },
196
- ]);
197
- assert.deepEqual(requests[1], [
198
- "updateContainerMount",
199
- {
200
- workspaceSlug: WORKSPACE_ID,
201
- container: "valkey-ctr",
202
- kind: "MOUNT_KIND_VOLUME",
203
- volume: "valkey-data",
204
- destination: "/data",
205
- mode: "MOUNT_MODE_READ_WRITE",
206
- },
207
- ]);
208
- });
209
- test("container_mount_update rejects kinds without a mode", async () => {
210
- const { requests, resolver } = mountRequestRecorder();
211
- await assert.rejects(() => toolHandlers.container_mount_update(resolver, {
212
- container: "web",
213
- kind: "tmpfs",
214
- destination: "/mnt",
215
- mode: "read_only",
216
- }, MOUNT_EXEC), /only project and volume mounts carry a mode; tmpfs mounts cannot be remounted/);
217
- await assert.rejects(() => toolHandlers.container_mount_update(resolver, { container: "web", project: "team", mode: "rw" }, MOUNT_EXEC), /unknown mount mode: rw/);
218
- assert.deepEqual(requests, [], "a rejected update must not reach the orchestrator");
219
- });
220
- test("summarizeArgs renders the remount reason", () => {
221
- assert.equal(summarizeArgs("container_mount_update", {
222
- container: "valkey-ctr",
223
- kind: "project",
224
- project: "team",
225
- mode: "read_only",
226
- }), 'Update mount in container "valkey-ctr": remount project "team" to read-only.');
227
- assert.equal(summarizeArgs("container_mount_update", {
228
- container: "valkey-ctr",
229
- volume: "data",
230
- destination: "/data",
231
- mode: "read_write",
232
- }), 'Update mount in container "valkey-ctr": remount volume "data" at "/data" to read-write.');
233
- });
234
- test("container_mount_add rejects unknown mount kinds and modes", async () => {
235
- const { requests, resolver } = mountRequestRecorder();
236
- await assert.rejects(() => toolHandlers.container_mount_add(resolver, { container: "web", kind: "bind", project: "team" }, MOUNT_EXEC), /unknown mount kind: bind/);
237
- await assert.rejects(() => toolHandlers.container_mount_add(resolver, { container: "web", project: "team", mode: "rw" }, MOUNT_EXEC), /unknown mount mode: rw/);
238
- assert.deepEqual(requests, [], "a rejected mount must not reach the orchestrator");
239
- });
240
- test("container_mount_add rejects a destination on a project mount", async () => {
241
- const { requests, resolver } = mountRequestRecorder();
242
- await assert.rejects(() => toolHandlers.container_mount_add(resolver, {
243
- container: "web",
244
- kind: "project",
245
- project: "team/src",
246
- destination: "/custom",
247
- }, MOUNT_EXEC), /Project mounts cannot set a destination; "team\/src" always mounts at "\/projects\/team\/src"/);
248
- await assert.rejects(() => toolHandlers.container_mount_add(resolver, { container: "web", project: "team", destination: "/custom" }, MOUNT_EXEC), /Project mounts cannot set a destination/);
249
- assert.deepEqual(requests, [], "a rejected mount must not reach the orchestrator");
250
- await toolHandlers.container_mount_add(resolver, { container: "web", kind: "volume", volume: "data", destination: "/data" }, MOUNT_EXEC);
251
- assert.equal(requests.length, 1, "a volume mount with a destination is still accepted");
252
- });
253
- test("container_start rejects a destination on a project mount", async () => {
254
- const { requests, resolver } = mountRequestRecorder();
255
- await assert.rejects(() => toolHandlers.container_start(resolver, {
256
- container: "web",
257
- image: "img1",
258
- mounts: [{ project: "team", destination: "/custom" }],
259
- }, MOUNT_EXEC), /Project mounts cannot set a destination/);
260
- assert.deepEqual(requests, [], "a rejected mount must not reach the orchestrator");
261
- });
262
- test("container_mount_remove rejects unknown mount kinds", async () => {
263
- const { requests, resolver } = mountRequestRecorder();
264
- await assert.rejects(() => toolHandlers.container_mount_remove(resolver, { container: "web", kind: "bind", project: "team" }, MOUNT_EXEC), /unknown mount kind: bind/);
265
- assert.deepEqual(requests, [], "a rejected mount must not reach the orchestrator");
266
- });
267
- test("adding a tmpfs mount without a mode stays read_write", async () => {
268
- // The orchestrator rejects a read-only tmpfs, so the read-only default must
269
- // not apply to it.
270
- const { requests, resolver } = mountRequestRecorder();
271
- await toolHandlers.container_mount_add(resolver, { container: "web", kind: "tmpfs", destination: "/scratch" }, MOUNT_EXEC);
272
- assert.deepEqual(requests, [
273
- ["addContainerMount", {
274
- workspaceSlug: WORKSPACE_ID,
275
- container: "web",
276
- kind: "MOUNT_KIND_TMPFS",
277
- destination: "/scratch",
278
- mode: "MOUNT_MODE_READ_WRITE",
279
- }],
280
- ]);
281
- });
282
- test("mount tools default a missing kind to project and a missing mode to read_only", async () => {
283
- const { requests, resolver } = mountRequestRecorder();
284
- await toolHandlers.container_mount_add(resolver, { container: "web", project: "team" }, MOUNT_EXEC);
285
- await toolHandlers.container_mount_add(resolver, {
286
- container: "web",
287
- kind: "volume",
288
- volume: "valkey-data",
289
- destination: "/data",
290
- mode: "read_only",
291
- }, MOUNT_EXEC);
292
- await toolHandlers.container_mount_remove(resolver, { container: "web", project: "team" }, MOUNT_EXEC);
293
- assert.deepEqual(requests, [
294
- ["addContainerMount", {
295
- workspaceSlug: WORKSPACE_ID,
296
- container: "web",
297
- kind: "MOUNT_KIND_PROJECT",
298
- project: "team",
299
- mode: "MOUNT_MODE_READ_ONLY",
300
- }],
301
- ["addContainerMount", {
302
- workspaceSlug: WORKSPACE_ID,
303
- container: "web",
304
- kind: "MOUNT_KIND_VOLUME",
305
- volume: "valkey-data",
306
- destination: "/data",
307
- mode: "MOUNT_MODE_READ_ONLY",
308
- }],
309
- ["removeContainerMount", {
310
- workspaceSlug: WORKSPACE_ID,
311
- container: "web",
312
- kind: "MOUNT_KIND_PROJECT",
313
- project: "team",
314
- }],
315
- ]);
316
- });
317
- test("container start and recreate reject unknown mount kinds and modes", async () => {
318
- const { requests, resolver } = mountRequestRecorder();
319
- await assert.rejects(() => toolHandlers.container_start(resolver, { container: "web", mounts: [{ project: "team", kind: "bind" }] }, MOUNT_EXEC), /unknown mount kind: bind/);
320
- await assert.rejects(() => toolHandlers.container_recreate(resolver, { container: "web", mounts: [{ project: "team", mode: "rw" }] }, MOUNT_EXEC), /unknown mount mode: rw/);
321
- assert.deepEqual(requests, [], "a rejected mount must not reach the orchestrator");
322
- });
323
- test("container start maps valid mounts and defaults the mode to read_only", async () => {
324
- const { requests, resolver } = mountRequestRecorder();
325
- await toolHandlers.container_start(resolver, {
326
- container: "web",
327
- image: "img1",
328
- mounts: [
329
- { project: "team/src", mode: "read_only" },
330
- { project: "team", mode: "read_write" },
331
- { kind: "volume", volume: "valkey-data", destination: "/data" },
332
- {
333
- kind: "secret",
334
- secret: "valkey-tls",
335
- destination: "/run/secrets/tls",
336
- },
337
- { kind: "tmpfs", destination: "/scratch" },
338
- ],
339
- }, MOUNT_EXEC);
340
- assert.deepEqual(requests, [
341
- ["startContainer", {
342
- workspaceSlug: WORKSPACE_ID,
343
- container: "web",
344
- imageId: "img1",
345
- mounts: [
346
- {
347
- projectName: "team/src",
348
- kind: "MOUNT_KIND_PROJECT",
349
- mode: "MOUNT_MODE_READ_ONLY",
350
- },
351
- {
352
- projectName: "team",
353
- kind: "MOUNT_KIND_PROJECT",
354
- mode: "MOUNT_MODE_READ_WRITE",
355
- },
356
- {
357
- projectName: "",
358
- kind: "MOUNT_KIND_VOLUME",
359
- mode: "MOUNT_MODE_READ_ONLY",
360
- destination: "/data",
361
- volume: "valkey-data",
362
- },
363
- {
364
- projectName: "",
365
- kind: "MOUNT_KIND_SECRET",
366
- mode: "MOUNT_MODE_READ_ONLY",
367
- destination: "/run/secrets/tls",
368
- secret: "valkey-tls",
369
- },
370
- {
371
- projectName: "",
372
- kind: "MOUNT_KIND_TMPFS",
373
- mode: "MOUNT_MODE_READ_WRITE",
374
- destination: "/scratch",
375
- },
376
- ],
377
- }],
378
- ]);
379
- });
380
- test("mount schemas are object-rooted without per-property required", () => {
381
- for (const name of MOUNT_TOOLS) {
382
- const tool = TOOLS.find((entry) => entry.name === name);
383
- assert.ok(tool, `${name} registered`);
384
- assert.equal(tool.parameters.type, "object", `${name} type`);
385
- assert.equal(typeof tool.parameters.properties, "object");
386
- assert.ok(Array.isArray(tool.parameters.required));
387
- for (const key of Object.keys(tool.parameters.properties)) {
388
- const property = tool.parameters.properties[key];
389
- assert.ok(!Object.prototype.hasOwnProperty.call(property, "required"), `${name}.${key} must not carry per-property required`);
390
- }
391
- }
392
- for (const name of ["container_start", "container_recreate"]) {
393
- const tool = TOOLS.find((entry) => entry.name === name);
394
- assert.ok(tool, `${name} registered`);
395
- const mounts = tool.parameters.properties.mounts;
396
- assert.equal(mounts.type, "array", `${name}.mounts type`);
397
- assert.equal(mounts.items.type, "object", `${name}.mounts items type`);
398
- assert.equal(mounts.items.additionalProperties, false);
399
- assert.deepEqual(mounts.items.required, []);
400
- for (const key of Object.keys(mounts.items.properties)) {
401
- const property = mounts.items.properties[key];
402
- assert.ok(!Object.prototype.hasOwnProperty.call(property, "required"), `${name}.mounts.items.${key} must not carry per-property required`);
403
- }
404
- }
405
- });
406
- test("container_mount_list returns mount objects", async () => {
407
- const resolver = {
408
- registry: {
409
- resolveByPath: async () => ({ id: WORKSPACE_ID }),
410
- },
411
- control: async () => ({
412
- containers: [
413
- {
414
- workspaceSlug: WORKSPACE_ID,
415
- containerName: "default",
416
- mounts: [
417
- {
418
- projectName: "team",
419
- mode: "MOUNT_MODE_READ_WRITE",
420
- kind: "MOUNT_KIND_PROJECT",
421
- },
422
- {
423
- volume: "myvol",
424
- destination: "/data",
425
- mode: "MOUNT_MODE_READ_ONLY",
426
- kind: "MOUNT_KIND_VOLUME",
427
- },
428
- ],
429
- },
430
- ],
431
- }),
432
- };
433
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
434
- const out = await toolHandlers.container_mount_list(resolver, { container: "default" }, exec);
435
- assert.deepEqual(out, [
436
- { projectName: "team", mode: "read_write", kind: "project" },
437
- {
438
- volume: "myvol",
439
- destination: "/data",
440
- mode: "read_only",
441
- kind: "volume",
442
- },
443
- ]);
444
- });
445
- test("command tools default to the session directory when mounted", async () => {
446
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
447
- const bash = guestExecRecorder("/projects/team");
448
- await toolHandlers.container_bash(bash.resolver, { container: "default", command: "ls" }, exec);
449
- assert.equal(bash.starts[0].cwd, "/projects/team");
450
- const run = guestExecRecorder("/projects/team");
451
- await toolHandlers.container_exec(run.resolver, { container: "default", argv: ["ls"] }, exec);
452
- assert.equal(run.starts[0].cwd, "/projects/team");
453
- const glob = guestExecRecorder("/projects/team");
454
- await toolHandlers.container_glob(glob.resolver, { container: "default", pattern: "*.ts" }, exec);
455
- assert.equal(glob.starts[0].cwd, "/projects/team");
456
- const grep = guestExecRecorder("/projects/team");
457
- await toolHandlers.container_grep(grep.resolver, { container: "default", pattern: "TODO" }, exec);
458
- assert.equal(grep.starts[0].cwd, "/projects/team");
459
- });
460
- test("command tools fall back to the guest cwd when the session directory is not mounted", async () => {
461
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
462
- const bare = guestExecRecorder();
463
- await toolHandlers.container_exec(bare.resolver, { container: "db", argv: ["ls"] }, exec);
464
- assert.equal(bare.starts[0].cwd, undefined);
465
- // An explicit working directory still resolves without a mounted default.
466
- const explicit = guestExecRecorder();
467
- await toolHandlers.container_exec(explicit.resolver, { container: "db", argv: ["ls"], workdir: "/data" }, exec);
468
- assert.equal(explicit.starts[0].cwd, "/data");
469
- });
470
- test("forcedMountMode fixes tmpfs and secret and leaves project and volume editable", () => {
471
- // The orchestrator rejects a read-only tmpfs and exposes secrets read-only,
472
- // so the card shows those two as a fixed mode.
473
- assert.equal(forcedMountMode("tmpfs"), "read_write");
474
- assert.equal(forcedMountMode("secret"), "read_only");
475
- assert.equal(forcedMountMode("project"), undefined);
476
- assert.equal(forcedMountMode("volume"), undefined);
477
- assert.equal(forcedMountMode(undefined), undefined);
478
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
- //
3
- // SPDX-License-Identifier: MIT
4
- import test from "node:test";
5
- import assert from "node:assert/strict";
6
- import { TOOLS } from "./index.js";
7
- // Tool parameters are camelCase. The only snake_case names allowed are the ones
8
- // that intentionally mirror the harness's built-in read/write/edit tools. Proto
9
- // field names are lower_snake_case and never reach a tool schema: proto-loader
10
- // projects them to camelCase (`secret_env` -> `secretEnv`, `image_id` ->
11
- // `imageId`), so an exposed snake_case proto name is a bug.
12
- const BUILTIN_MIRRORED = new Set([
13
- "file_path",
14
- "old_string",
15
- "new_string",
16
- "replace_all",
17
- ]);
18
- test("tool parameters never expose a proto-style snake_case name", () => {
19
- for (const tool of TOOLS) {
20
- for (const name of Object.keys(tool.parameters.properties)) {
21
- if (name.includes("_")) {
22
- assert.ok(BUILTIN_MIRRORED.has(name), `${tool.name}.${name} is snake_case but does not mirror a built-in tool`);
23
- }
24
- assert.notEqual(name, "secret_env", `${tool.name} must expose secretEnv, not secret_env`);
25
- assert.notEqual(name, "image_id", `${tool.name} must expose imageId, not image_id`);
26
- }
27
- }
28
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,49 +0,0 @@
1
- // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
- //
3
- // SPDX-License-Identifier: MIT
4
- import test from "node:test";
5
- import assert from "node:assert/strict";
6
- import { existsSync, readFileSync } from "node:fs";
7
- // Every harness dependency must be an exact version: the set moves together
8
- // with the supported dsh release, and a caret quietly allowed the manifest to
9
- // drift a release behind the image.
10
- const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
11
- const SECTIONS = ["devDependencies", "peerDependencies"];
12
- function manifest() {
13
- return JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
14
- }
15
- test("every @deepseek-ai specifier is an exact version", () => {
16
- const pkg = manifest();
17
- for (const section of SECTIONS) {
18
- for (const [name, specifier] of Object.entries(pkg[section] ?? {})) {
19
- if (!name.startsWith("@deepseek-ai/"))
20
- continue;
21
- assert.match(String(specifier), EXACT_VERSION, `${section}: "${name}": "${specifier}" must be an exact version`);
22
- }
23
- }
24
- });
25
- test("every peer dependency is declared optional", () => {
26
- const pkg = manifest();
27
- for (const name of Object.keys(pkg.peerDependencies ?? {})) {
28
- assert.equal(pkg.peerDependenciesMeta?.[name]?.optional, true, `peerDependenciesMeta["${name}"].optional must be true`);
29
- }
30
- });
31
- test("every @deepseek-ai/dsh-* specifier matches ARG DSH_VERSION", (context) => {
32
- const containerfile = new URL("../Containerfile.dsh", import.meta.url);
33
- if (!existsSync(containerfile)) {
34
- context.skip("not a source checkout");
35
- return;
36
- }
37
- const match = /^ARG\s+DSH_VERSION=(\S+)/m.exec(readFileSync(containerfile, "utf8"));
38
- assert.ok(match, "Containerfile.dsh must declare ARG DSH_VERSION");
39
- const dshVersion = match[1];
40
- assert.match(dshVersion, EXACT_VERSION, "ARG DSH_VERSION must be exact");
41
- const pkg = manifest();
42
- for (const section of SECTIONS) {
43
- for (const [name, specifier] of Object.entries(pkg[section] ?? {})) {
44
- if (!name.startsWith("@deepseek-ai/dsh-"))
45
- continue;
46
- assert.equal(specifier, dshVersion, `${section}: "${name}": "${specifier}" must match ARG DSH_VERSION (${dshVersion})`);
47
- }
48
- }
49
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,76 +0,0 @@
1
- // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
- //
3
- // SPDX-License-Identifier: MIT
4
- import test from "node:test";
5
- import assert from "node:assert/strict";
6
- import { pathRequestRecorder, WORKSPACE_ID } from "./test-support.js";
7
- import { summarizeArgs, toolHandlers, TOOLS } from "./index.js";
8
- const EXEC = { agent: { session: { header: { cwd: "/proj" } } } };
9
- test("the path tools are registered and approval-gated", () => {
10
- for (const name of [
11
- "container_path_set",
12
- "container_path_add",
13
- "container_path_remove",
14
- ]) {
15
- const tool = TOOLS.find((entry) => entry.name === name);
16
- assert.ok(tool, `${name} registered`);
17
- assert.equal(tool.approval, true, `${name} must require approval`);
18
- assert.ok(tool.parameters.required.includes("container"), `${name} requires container`);
19
- }
20
- assert.deepEqual(TOOLS.find((entry) => entry.name === "container_path_set").parameters
21
- .required, ["container", "paths"]);
22
- assert.deepEqual(TOOLS.find((entry) => entry.name === "container_path_add").parameters
23
- .required, ["container", "path"]);
24
- });
25
- test("container_path_set persists and applies the whole list", async () => {
26
- const { controlCalls, setCalls, resolver } = pathRequestRecorder();
27
- const out = await toolHandlers.container_path_set(resolver, { container: "default", paths: ["/opt/bin", "/usr/local/bin"] }, EXEC);
28
- assert.deepEqual(controlCalls, [
29
- [
30
- "setContainerPaths",
31
- {
32
- workspaceSlug: WORKSPACE_ID,
33
- container: "default",
34
- paths: ["/opt/bin", "/usr/local/bin"],
35
- },
36
- ],
37
- ]);
38
- assert.deepEqual(setCalls, [["/opt/bin", "/usr/local/bin"]]);
39
- assert.deepEqual(out, { paths: ["/opt/bin", "/usr/local/bin"] });
40
- });
41
- test("container_path_add prepends and moves an existing entry to the front", async () => {
42
- const { controlCalls, resolver } = pathRequestRecorder({
43
- paths: ["/a", "/b"],
44
- });
45
- const added = await toolHandlers.container_path_add(resolver, { container: "default", path: "/c" }, EXEC);
46
- assert.deepEqual(added, { paths: ["/c", "/a", "/b"] });
47
- const moved = await toolHandlers.container_path_add(resolver, { container: "default", path: "/b" }, EXEC);
48
- assert.deepEqual(moved, { paths: ["/b", "/c", "/a"] });
49
- assert.equal(controlCalls.length, 2);
50
- });
51
- test("container_path_remove removes an added path", async () => {
52
- const { resolver } = pathRequestRecorder({ paths: ["/a", "/b"] });
53
- const out = await toolHandlers.container_path_remove(resolver, { container: "default", path: "/a" }, EXEC);
54
- assert.deepEqual(out, { paths: ["/b"] });
55
- });
56
- test("container_path_remove distinguishes a default path from an unknown one", async () => {
57
- const { controlCalls, resolver } = pathRequestRecorder({
58
- paths: ["/a"],
59
- defaultPath: "/usr/bin:/bin",
60
- });
61
- await assert.rejects(() => toolHandlers.container_path_remove(resolver, { container: "default", path: "/usr/bin" }, EXEC), /is part of the container's default PATH and cannot be removed/);
62
- await assert.rejects(() => toolHandlers.container_path_remove(resolver, { container: "default", path: "/nope" }, EXEC), /is not an added path/);
63
- assert.deepEqual(controlCalls, [], "a rejected removal must not reach the orchestrator");
64
- });
65
- test("summarizeArgs renders the PATH reasons", () => {
66
- assert.equal(summarizeArgs("container_path_set", {
67
- container: "web",
68
- paths: ["/opt/bin", "/usr/local/bin"],
69
- }), 'Set the PATH additions of container "web": "/opt/bin", "/usr/local/bin".');
70
- assert.equal(summarizeArgs("container_path_set", { container: "web", paths: [] }), 'Set the PATH additions of container "web": (none).');
71
- assert.equal(summarizeArgs("container_path_add", { container: "web", path: "/opt/bin" }), 'Add "/opt/bin" to the PATH of container "web".');
72
- assert.equal(summarizeArgs("container_path_remove", {
73
- container: "web",
74
- path: "/opt/bin",
75
- }), 'Remove "/opt/bin" from the PATH of container "web".');
76
- });
@@ -1 +0,0 @@
1
- export {};