@exagone313/dsh-podman 1.0.3 → 1.0.4

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 (89) hide show
  1. package/dist/generated/version.d.ts +2 -2
  2. package/dist/generated/version.js +2 -2
  3. package/docs/development.md +8 -4
  4. package/docs/development.zh.md +7 -4
  5. package/package.json +3 -1
  6. package/dist/approval-reasons.test.d.ts +0 -1
  7. package/dist/approval-reasons.test.js +0 -143
  8. package/dist/approval.test.d.ts +0 -1
  9. package/dist/approval.test.js +0 -593
  10. package/dist/card-route.test.d.ts +0 -1
  11. package/dist/card-route.test.js +0 -223
  12. package/dist/card-test-support.d.ts +0 -15
  13. package/dist/card-test-support.js +0 -133
  14. package/dist/container-env.test.d.ts +0 -1
  15. package/dist/container-env.test.js +0 -93
  16. package/dist/containers.test.d.ts +0 -1
  17. package/dist/containers.test.js +0 -621
  18. package/dist/daemons.test.d.ts +0 -1
  19. package/dist/daemons.test.js +0 -167
  20. package/dist/dsh-version.test.d.ts +0 -1
  21. package/dist/dsh-version.test.js +0 -25
  22. package/dist/env-rows.test.d.ts +0 -1
  23. package/dist/env-rows.test.js +0 -43
  24. package/dist/fs-provider.test.d.ts +0 -1
  25. package/dist/fs-provider.test.js +0 -301
  26. package/dist/guest-rpc.test.d.ts +0 -1
  27. package/dist/guest-rpc.test.js +0 -241
  28. package/dist/images.test.d.ts +0 -1
  29. package/dist/images.test.js +0 -86
  30. package/dist/locales.test.d.ts +0 -1
  31. package/dist/locales.test.js +0 -34
  32. package/dist/misc.test.d.ts +0 -1
  33. package/dist/misc.test.js +0 -169
  34. package/dist/mounts.test.d.ts +0 -1
  35. package/dist/mounts.test.js +0 -478
  36. package/dist/naming.test.d.ts +0 -1
  37. package/dist/naming.test.js +0 -28
  38. package/dist/package-deps.test.d.ts +0 -1
  39. package/dist/package-deps.test.js +0 -49
  40. package/dist/paths.test.d.ts +0 -1
  41. package/dist/paths.test.js +0 -76
  42. package/dist/plugin-meta.test.d.ts +0 -1
  43. package/dist/plugin-meta.test.js +0 -29
  44. package/dist/project-path.test.d.ts +0 -1
  45. package/dist/project-path.test.js +0 -66
  46. package/dist/read-only-shell.test.d.ts +0 -1
  47. package/dist/read-only-shell.test.js +0 -182
  48. package/dist/runtime-client.test.d.ts +0 -1
  49. package/dist/runtime-client.test.js +0 -53
  50. package/dist/secrets.test.d.ts +0 -1
  51. package/dist/secrets.test.js +0 -196
  52. package/dist/settings-commands.test.d.ts +0 -1
  53. package/dist/settings-commands.test.js +0 -596
  54. package/dist/settings-create.test.d.ts +0 -1
  55. package/dist/settings-create.test.js +0 -416
  56. package/dist/settings-default-env.test.d.ts +0 -1
  57. package/dist/settings-default-env.test.js +0 -175
  58. package/dist/settings-mounts.test.d.ts +0 -1
  59. package/dist/settings-mounts.test.js +0 -506
  60. package/dist/settings-paths.test.d.ts +0 -1
  61. package/dist/settings-paths.test.js +0 -65
  62. package/dist/settings-schema.test.d.ts +0 -1
  63. package/dist/settings-schema.test.js +0 -35
  64. package/dist/settings-workspaces.test.d.ts +0 -1
  65. package/dist/settings-workspaces.test.js +0 -240
  66. package/dist/spill-store.test.d.ts +0 -1
  67. package/dist/spill-store.test.js +0 -82
  68. package/dist/subprocess.test.d.ts +0 -1
  69. package/dist/subprocess.test.js +0 -344
  70. package/dist/terminal-preference.test.d.ts +0 -1
  71. package/dist/terminal-preference.test.js +0 -62
  72. package/dist/terminal-route.test.d.ts +0 -1
  73. package/dist/terminal-route.test.js +0 -265
  74. package/dist/terminal-tab.test.d.ts +0 -1
  75. package/dist/terminal-tab.test.js +0 -58
  76. package/dist/terminal-targets.test.d.ts +0 -1
  77. package/dist/terminal-targets.test.js +0 -43
  78. package/dist/terminal-titles.test.d.ts +0 -1
  79. package/dist/terminal-titles.test.js +0 -36
  80. package/dist/test-support.d.ts +0 -358
  81. package/dist/test-support.js +0 -499
  82. package/dist/version-compat.test.d.ts +0 -1
  83. package/dist/version-compat.test.js +0 -27
  84. package/dist/views.test.d.ts +0 -1
  85. package/dist/views.test.js +0 -23
  86. package/dist/volumes.test.d.ts +0 -1
  87. package/dist/volumes.test.js +0 -40
  88. package/dist/workspace-binding.test.d.ts +0 -1
  89. package/dist/workspace-binding.test.js +0 -523
@@ -1,621 +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 { fakeToolContext, guestExecRecorder, guestFileRecorder, secretBearingResolver, WORKSPACE_ID, } from "./test-support.js";
7
- import { podmanRuntimeSection, resolveGuestCwd, resolveGuestPath, toolHandlers, TOOLS, } from "./index.js";
8
- test("container start/recreate/bash accept an env map schema", () => {
9
- for (const name of ["container_start", "container_recreate", "container_bash"]) {
10
- const tool = TOOLS.find((entry) => entry.name === name);
11
- assert.ok(tool, `${name} registered`);
12
- const env = tool.parameters.properties.env;
13
- assert.equal(env.type, "object", `${name}.env type`);
14
- assert.equal(env.additionalProperties.type, "string", `${name}.env values type`);
15
- assert.ok(!Array.isArray(tool.parameters.required.includes("env")), `${name}.env must stay optional`);
16
- }
17
- });
18
- test("container_list returns sanitized container objects with env values", async () => {
19
- const resolver = {
20
- registry: {
21
- resolveByPath: async () => ({ id: WORKSPACE_ID }),
22
- },
23
- control: async (method) => {
24
- if (method === "listContainers") {
25
- return {
26
- containers: [
27
- {
28
- workspaceSlug: WORKSPACE_ID,
29
- containerName: "default",
30
- status: "running",
31
- imageId: "img-1",
32
- env: { PATH: "/bin", HOME: "/root" },
33
- },
34
- {
35
- workspaceSlug: WORKSPACE_ID,
36
- containerName: "db",
37
- status: "running",
38
- env: { PORT: "5432", DB: "main", X: "1", Y: "2" },
39
- },
40
- {
41
- workspaceSlug: WORKSPACE_ID,
42
- containerName: "worker",
43
- status: "stopped",
44
- },
45
- ],
46
- };
47
- }
48
- return {};
49
- },
50
- };
51
- const exec = { agent: { session: { header: { cwd: "/proj" } } } };
52
- const out = (await toolHandlers.container_list(resolver, {}, exec));
53
- assert.deepEqual(out, [
54
- {
55
- containerName: "default",
56
- status: "running",
57
- imageId: "img-1",
58
- mounts: [],
59
- paths: [],
60
- env: { PATH: "/bin", HOME: "/root" },
61
- secretEnv: {},
62
- },
63
- {
64
- containerName: "db",
65
- status: "running",
66
- mounts: [],
67
- paths: [],
68
- env: { PORT: "5432", DB: "main", X: "1", Y: "2" },
69
- secretEnv: {},
70
- },
71
- {
72
- containerName: "worker",
73
- status: "stopped",
74
- mounts: [],
75
- paths: [],
76
- env: {},
77
- secretEnv: {},
78
- },
79
- ]);
80
- });
81
- test("container_list reports an uncreated default container as not started", async () => {
82
- const resolver = {
83
- registry: {
84
- resolveByPath: async () => ({ id: WORKSPACE_ID }),
85
- },
86
- control: async () => ({ containers: [] }),
87
- };
88
- const exec = { agent: { session: { header: { cwd: "/proj" } } } };
89
- const out = (await toolHandlers.container_list(resolver, {}, exec));
90
- assert.deepEqual(out, [
91
- { containerName: "default", status: "not started" },
92
- ]);
93
- });
94
- test("container tools never expose internal fields in their results", async () => {
95
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
96
- const cases = [
97
- [toolHandlers.container_start, { container: "default", image: "img-1" }],
98
- [toolHandlers.container_recreate, { container: "default" }],
99
- [toolHandlers.container_mount_add, {
100
- container: "default",
101
- kind: "volume",
102
- volume: "v",
103
- destination: "/data",
104
- }],
105
- [toolHandlers.container_mount_remove, {
106
- container: "default",
107
- kind: "volume",
108
- volume: "v",
109
- destination: "/data",
110
- }],
111
- [toolHandlers.container_mount_update, {
112
- container: "default",
113
- kind: "volume",
114
- volume: "v",
115
- destination: "/data",
116
- mode: "read_only",
117
- }],
118
- [toolHandlers.container_secret_add, {
119
- container: "default",
120
- env: "DB_PASS",
121
- secret: "db-pass",
122
- }],
123
- [toolHandlers.container_secret_remove, {
124
- container: "default",
125
- env: "DB_PASS",
126
- }],
127
- ];
128
- for (const [handler, input] of cases) {
129
- const out = await handler(secretBearingResolver(), input, exec);
130
- const json = JSON.stringify(out);
131
- assert.ok(!json.includes("agentSocketPath"), "must not expose agentSocketPath");
132
- assert.ok(!json.includes("agentToken"), "must not expose agentToken");
133
- assert.ok(!json.includes("podmanName"), "must not expose podmanName");
134
- assert.ok(!json.includes("workspaceSlug"), "must not expose workspaceSlug");
135
- assert.ok(!json.includes("createdAt"), "must not expose createdAt");
136
- assert.ok(json.includes("hunter2"), "env values are returned to the model");
137
- assert.equal(out.containerName, "default");
138
- assert.equal(out.status, "running");
139
- assert.equal(out.imageId, "img-1");
140
- assert.equal(out.secretEnv.DB_PASS, "db-pass");
141
- }
142
- });
143
- test("container_recreate reports the recreated container", async () => {
144
- const resolver = {
145
- registry: {
146
- resolveByPath: async () => ({ id: WORKSPACE_ID }),
147
- },
148
- getConfig: () => ({ projectsRoot: "/projects" }),
149
- // The control plane answers with the container it recreated: its logical
150
- // name, and its own mounts and env rather than the default container's.
151
- control: async () => ({
152
- workspaceSlug: WORKSPACE_ID,
153
- containerName: "db",
154
- imageId: "img-1",
155
- status: "running",
156
- mounts: [],
157
- env: { APP_ENV: "probe" },
158
- }),
159
- };
160
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
161
- const named = (await toolHandlers.container_recreate(resolver, { container: "db", image: "img-1" }, exec));
162
- assert.equal(named.containerName, "db");
163
- assert.deepEqual(named.env, { APP_ENV: "probe" });
164
- });
165
- test("container start and recreate forward PATH additions", async () => {
166
- const calls = [];
167
- const resolver = {
168
- registry: {
169
- resolveByPath: async () => ({ id: WORKSPACE_ID }),
170
- },
171
- getConfig: () => ({ projectsRoot: "/projects" }),
172
- control: async (method, request) => {
173
- calls.push([method, request]);
174
- return {
175
- containerName: "default",
176
- status: "running",
177
- paths: ["/opt/bin"],
178
- };
179
- },
180
- };
181
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
182
- const started = (await toolHandlers.container_start(resolver, { container: "default", paths: ["/opt/bin"] }, exec));
183
- assert.deepEqual(calls[0][1].paths, ["/opt/bin"]);
184
- assert.deepEqual(started.paths, ["/opt/bin"]);
185
- const recreated = (await toolHandlers.container_recreate(resolver, { container: "default", paths: ["/usr/local/bin"] }, exec));
186
- assert.deepEqual(calls[1][1].paths, ["/usr/local/bin"]);
187
- assert.deepEqual(recreated.paths, ["/opt/bin"]);
188
- });
189
- test("container_start seeds the default environment into a new container", async () => {
190
- const calls = [];
191
- const resolver = {
192
- registry: { resolveByPath: async () => ({ id: WORKSPACE_ID }) },
193
- getConfig: () => ({
194
- projectsRoot: "/projects",
195
- containerEnv: { GIT_AUTHOR_NAME: "John Doe" },
196
- }),
197
- control: async (method, request) => {
198
- calls.push([method, request]);
199
- if (method === "listContainers")
200
- return { containers: [] };
201
- return { containerName: "web", status: "running" };
202
- },
203
- };
204
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
205
- await toolHandlers.container_start(resolver, { container: "web", image: "img-1" }, exec);
206
- assert.deepEqual(calls.map(([method]) => method), ["listContainers", "startContainer"]);
207
- const start = calls.find(([method]) => method === "startContainer");
208
- assert.deepEqual(start[1].env, { GIT_AUTHOR_NAME: "John Doe" });
209
- });
210
- test("container_start keeps an existing container's environment", async () => {
211
- const calls = [];
212
- const resolver = {
213
- registry: { resolveByPath: async () => ({ id: WORKSPACE_ID }) },
214
- getConfig: () => ({
215
- projectsRoot: "/projects",
216
- containerEnv: { GIT_AUTHOR_NAME: "John Doe" },
217
- }),
218
- control: async (method, request) => {
219
- calls.push([method, request]);
220
- if (method === "listContainers") {
221
- return {
222
- containers: [
223
- {
224
- workspaceSlug: WORKSPACE_ID,
225
- containerName: "web",
226
- env: { KEEP: "1" },
227
- },
228
- ],
229
- };
230
- }
231
- return { containerName: "web", status: "running" };
232
- },
233
- };
234
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
235
- await toolHandlers.container_start(resolver, { container: "web", image: "img-1" }, exec);
236
- const start = calls.find(([method]) => method === "startContainer");
237
- assert.equal("env" in start[1], false, "a stored environment must survive a start");
238
- });
239
- test("container_start lets the caller's environment win over the defaults", async () => {
240
- const calls = [];
241
- const resolver = {
242
- registry: { resolveByPath: async () => ({ id: WORKSPACE_ID }) },
243
- getConfig: () => ({
244
- projectsRoot: "/projects",
245
- containerEnv: {
246
- GIT_AUTHOR_NAME: "John Doe",
247
- GIT_AUTHOR_EMAIL: "john.doe@git.example",
248
- },
249
- }),
250
- control: async (method, request) => {
251
- calls.push([method, request]);
252
- return { containerName: "web", status: "running" };
253
- },
254
- };
255
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
256
- await toolHandlers.container_start(resolver, { container: "web", image: "img-1", env: { GIT_AUTHOR_NAME: "Other" } }, exec);
257
- assert.deepEqual(calls.map(([method]) => method), ["startContainer"]);
258
- assert.deepEqual(calls[0][1].env, {
259
- GIT_AUTHOR_NAME: "Other",
260
- GIT_AUTHOR_EMAIL: "john.doe@git.example",
261
- });
262
- });
263
- test("container_recreate never injects the default environment", async () => {
264
- const calls = [];
265
- const resolver = {
266
- registry: { resolveByPath: async () => ({ id: WORKSPACE_ID }) },
267
- getConfig: () => ({
268
- projectsRoot: "/projects",
269
- containerEnv: { GIT_AUTHOR_NAME: "John Doe" },
270
- }),
271
- control: async (method, request) => {
272
- calls.push([method, request]);
273
- return { containerName: "default", status: "running" };
274
- },
275
- };
276
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
277
- await toolHandlers.container_recreate(resolver, { container: "default" }, exec);
278
- assert.equal("env" in calls[0][1], false, "a recreate stores what it is given");
279
- });
280
- test("resolveGuestPath resolves relative paths and refuses traversal", () => {
281
- assert.equal(resolveGuestPath("/abs/file", "/projects/team"), "/abs/file");
282
- assert.equal(resolveGuestPath("README.md", "/projects/team"), "/projects/team/README.md");
283
- assert.equal(resolveGuestPath("src/main.go", "/projects/team"), "/projects/team/src/main.go");
284
- assert.equal(resolveGuestPath("./a", "/projects/team"), "/projects/team/a");
285
- // ".." is refused before resolution, where it would be normalised away.
286
- assert.throws(() => resolveGuestPath("../escape", "/projects/team"), /must not escape/);
287
- assert.throws(() => resolveGuestPath("a/../b", "/projects/team"), /must not escape/);
288
- assert.throws(() => resolveGuestPath("/a/../b", "/projects/team"), /must not escape/);
289
- // A relative path is meaningless without a session working directory.
290
- assert.throws(() => resolveGuestPath("rel", undefined), /session working directory/);
291
- assert.throws(() => resolveGuestPath("rel", ""), /session working directory/);
292
- assert.equal(resolveGuestPath("/abs", undefined), "/abs");
293
- });
294
- test("resolveGuestCwd resolves working directories but keeps traversal", () => {
295
- assert.equal(resolveGuestCwd(undefined, "/projects/team"), undefined);
296
- assert.equal(resolveGuestCwd("", "/projects/team"), undefined);
297
- assert.equal(resolveGuestCwd("/abs", "/projects/team"), "/abs");
298
- assert.equal(resolveGuestCwd("sub", "/projects/team"), "/projects/team/sub");
299
- // Commands are not confined to the projects root, so ".." is allowed here.
300
- assert.equal(resolveGuestCwd("../sibling", "/projects/team"), "/projects/sibling");
301
- });
302
- test("container_read applies offset and limit like the built-in read tool", async () => {
303
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
304
- const { resolver } = guestFileRecorder("l1\nl2\nl3\nl4\n");
305
- assert.equal(await toolHandlers.container_read(resolver, { container: "default", file_path: "f" }, exec, fakeToolContext(resolver)), "l1\nl2\nl3\nl4\n", "no offset/limit returns the whole content");
306
- assert.equal(await toolHandlers.container_read(resolver, { container: "default", file_path: "f", offset: 2, limit: 2 }, exec, fakeToolContext(resolver)), "l2\nl3");
307
- });
308
- test("container_read records the read so a later write needs no re-read", async () => {
309
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
310
- const { resolver } = guestFileRecorder("hello\n");
311
- const ctx = fakeToolContext(resolver);
312
- assert.equal(await toolHandlers.container_read(resolver, { container: "default", file_path: "f" }, exec, ctx), "hello\n");
313
- assert.equal(ctx.observed.length, 1, "a successful read reports one observation");
314
- assert.equal(ctx.observed[0].target.displayPath, "/projects/team/f");
315
- assert.equal(ctx.observed[0].observation.kind, "present");
316
- assert.match(ctx.observed[0].observation.version, /^agent:/);
317
- });
318
- test("container_read reports a missing file and records it as absent", async () => {
319
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
320
- const { resolver } = guestFileRecorder("", false);
321
- const ctx = fakeToolContext(resolver);
322
- await assert.rejects(() => toolHandlers.container_read(resolver, { container: "default", file_path: "gone" }, exec, ctx), (error) => error.code === "FS_NOT_FOUND" && /not found/.test(error.message));
323
- assert.deepEqual(ctx.observed[0].observation, { kind: "absent" });
324
- });
325
- test("container_edit requires a unique match unless replace_all is set", async () => {
326
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
327
- const duplicate = guestFileRecorder("a a a");
328
- await assert.rejects(() => toolHandlers.container_edit(duplicate.resolver, {
329
- container: "default",
330
- file_path: "f",
331
- old_string: "a",
332
- new_string: "b",
333
- }, exec, fakeToolContext(duplicate.resolver)), /matched 3 times/);
334
- assert.deepEqual(duplicate.writes, [], "a non-unique match must not be written");
335
- const all = guestFileRecorder("a a a");
336
- await toolHandlers.container_edit(all.resolver, {
337
- container: "default",
338
- file_path: "f",
339
- old_string: "a",
340
- new_string: "b",
341
- replace_all: true,
342
- }, exec, fakeToolContext(all.resolver));
343
- assert.equal(all.writes[0].content, "b b b");
344
- });
345
- test("container command and file tools mirror the built-in arguments", () => {
346
- const parameters = (name) => TOOLS.find((entry) => entry.name === name).parameters;
347
- const bash = parameters("container_bash");
348
- assert.ok(bash.required.includes("command"));
349
- assert.ok(bash.required.includes("description"));
350
- assert.equal(bash.properties.timeoutMs.type, "number");
351
- const exec = parameters("container_exec");
352
- assert.ok(exec.required.includes("description"));
353
- assert.equal(exec.properties.workdir.type, "string");
354
- assert.equal(exec.properties.cwd, undefined);
355
- const read = parameters("container_read");
356
- assert.equal(read.properties.file_path.type, "string");
357
- assert.equal(read.properties.offset.type, "integer");
358
- assert.equal(read.properties.limit.type, "integer");
359
- const write = parameters("container_write");
360
- assert.equal(write.properties.file_path.type, "string");
361
- const edit = parameters("container_edit");
362
- assert.equal(edit.properties.old_string.type, "string");
363
- assert.equal(edit.properties.new_string.type, "string");
364
- assert.equal(edit.properties.replace_all.type, "boolean");
365
- const glob = parameters("container_glob");
366
- assert.equal(glob.properties.path.type, "string");
367
- assert.equal(glob.properties.cwd, undefined);
368
- const grep = parameters("container_grep");
369
- assert.equal(grep.properties.include.type, "string");
370
- assert.equal(grep.properties.cwd, undefined);
371
- });
372
- test("container_bash enforces timeoutMs", async () => {
373
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
374
- let signaled;
375
- const guest = {
376
- exec: () => {
377
- const handlers = {};
378
- return {
379
- on(event, handler) {
380
- (handlers[event] ??= []).push(handler);
381
- if (event === "data") {
382
- queueMicrotask(() => handler({ processId: "42" }));
383
- }
384
- },
385
- write() { },
386
- end() { },
387
- };
388
- },
389
- signal: (request, _metadata, callback) => {
390
- signaled = request;
391
- callback(null, {});
392
- },
393
- };
394
- const resolver = {
395
- resolve: async () => ({
396
- guest,
397
- token: "t",
398
- socket: "/run/x.sock",
399
- defaultCwd: "/projects/team",
400
- }),
401
- };
402
- await assert.rejects(() => toolHandlers.container_bash(resolver, {
403
- container: "default",
404
- command: "sleep",
405
- description: "x",
406
- timeoutMs: 10,
407
- }, exec), /timed out/);
408
- assert.equal(signaled.processId, "42");
409
- assert.equal(signaled.signal, "SIGTERM");
410
- });
411
- test("container commands inherit the managed shell environment", async () => {
412
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
413
- const ctx = {
414
- get: (name) => name === "shellEnv"
415
- ? {
416
- collect: () => ({
417
- DSH_HOME: "/dsh",
418
- DSH_SHELL: "1",
419
- DSH_SESSION_ID: "s1",
420
- }),
421
- }
422
- : undefined,
423
- };
424
- const bash = guestExecRecorder();
425
- await toolHandlers.container_bash(bash.resolver, {
426
- container: "default",
427
- command: "env",
428
- description: "x",
429
- env: { TERM: "xterm", DSH_SESSION_ID: "spoofed" },
430
- }, exec, ctx);
431
- assert.deepEqual(bash.starts[0].env, {
432
- // The terminal overrides come first, the caller's entry beats them, and
433
- // the managed DSH_* snapshot displaces the caller's spoofed session id.
434
- NO_COLOR: "1",
435
- TERM: "xterm",
436
- PAGER: "cat",
437
- GIT_PAGER: "cat",
438
- DSH_HOME: "/dsh",
439
- DSH_SHELL: "1",
440
- DSH_SESSION_ID: "s1",
441
- });
442
- const run = guestExecRecorder();
443
- await toolHandlers.container_exec(run.resolver, { container: "default", argv: ["env"], description: "x" }, exec, ctx);
444
- assert.equal(run.starts[0].env?.DSH_SESSION_ID, "s1");
445
- assert.equal(run.starts[0].env?.TERM, "dumb");
446
- });
447
- test("container_grep resolves its search path like a shell would", async () => {
448
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
449
- // With a search path, it is relative to the session directory.
450
- const plain = guestExecRecorder("/projects/team");
451
- await toolHandlers.container_grep(plain.resolver, { container: "default", pattern: "TODO", path: "src" }, exec);
452
- assert.deepEqual(plain.starts[0].argv, [
453
- "/usr/bin/rg",
454
- "-n",
455
- "TODO",
456
- "/projects/team/src",
457
- ]);
458
- // An include filter maps to ripgrep's --glob.
459
- const filtered = guestExecRecorder("/projects/team");
460
- await toolHandlers.container_grep(filtered.resolver, { container: "default", pattern: "TODO", path: "src", include: "*.ts" }, exec);
461
- assert.deepEqual(filtered.starts[0].argv, [
462
- "/usr/bin/rg",
463
- "-n",
464
- "--glob",
465
- "*.ts",
466
- "TODO",
467
- "/projects/team/src",
468
- ]);
469
- assert.equal(filtered.starts[0].cwd, "/projects/team");
470
- const none = guestExecRecorder("/projects/team");
471
- await toolHandlers.container_grep(none.resolver, { container: "default", pattern: "TODO" }, exec);
472
- // No path searches the session workspace explicitly: ripgrep would otherwise
473
- // read its (non-TTY) stdin instead of the working directory.
474
- assert.deepEqual(none.starts[0].argv, [
475
- "/usr/bin/rg",
476
- "-n",
477
- "TODO",
478
- "/projects/team",
479
- ]);
480
- assert.equal(none.starts[0].cwd, "/projects/team");
481
- });
482
- test("container_glob passes the pattern as a glob and scopes the search", async () => {
483
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
484
- const plain = guestExecRecorder("/projects/team");
485
- await toolHandlers.container_glob(plain.resolver, { container: "default", pattern: "*.ts" }, exec);
486
- assert.deepEqual(plain.starts[0].argv, [
487
- "/usr/bin/rg",
488
- "--files",
489
- "--glob=*.ts",
490
- "--sort=modified",
491
- "--no-ignore",
492
- "--hidden",
493
- "--glob=!**/.git",
494
- "--glob=!**/.git/**",
495
- "--glob=!**/.svn",
496
- "--glob=!**/.svn/**",
497
- "--glob=!**/.hg",
498
- "--glob=!**/.hg/**",
499
- "--glob=!**/.bzr",
500
- "--glob=!**/.bzr/**",
501
- "--glob=!**/.jj",
502
- "--glob=!**/.jj/**",
503
- "--glob=!**/.sl",
504
- "--glob=!**/.sl/**",
505
- ]);
506
- assert.equal(plain.starts[0].cwd, "/projects/team");
507
- // An explicit search path becomes the working directory.
508
- const scoped = guestExecRecorder("/projects/team");
509
- await toolHandlers.container_glob(scoped.resolver, { container: "default", pattern: "*", path: "/volumes/data" }, exec);
510
- assert.equal(scoped.starts[0].cwd, "/volumes/data");
511
- assert.ok(scoped.starts[0].argv.includes("--glob=*"));
512
- });
513
- test("container_glob caps its result at 100 files", async () => {
514
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
515
- const lines = (count) => Array.from({ length: count }, (_, index) => `file-${index}.ts`).join("\n") +
516
- "\n";
517
- const small = guestExecRecorder("/projects/team", lines(3));
518
- const few = (await toolHandlers.container_glob(small.resolver, { container: "default", pattern: "*" }, exec));
519
- assert.equal(few.files.length, 3);
520
- assert.equal(few.note, undefined);
521
- const big = guestExecRecorder("/projects/team", lines(101));
522
- const many = (await toolHandlers.container_glob(big.resolver, { container: "default", pattern: "*" }, exec));
523
- assert.equal(many.files.length, 100);
524
- assert.match(many.note ?? "", /showing 100 of 101 files/);
525
- });
526
- test("podmanRuntimeSection names only the tools the agent has", () => {
527
- // The harness's shell/filesystem tools are mounted for this agent.
528
- const withBuiltins = podmanRuntimeSection({ tools: { get: () => ({}) } });
529
- assert.equal(withBuiltins.name, "podman:runtime");
530
- assert.equal(withBuiltins.order, 950);
531
- const full = withBuiltins.text({ scope: "agent" });
532
- for (const tool of ["bash", "read", "write", "edit", "glob", "grep"]) {
533
- assert.match(full, new RegExp("`" + tool + "`"));
534
- }
535
- assert.match(full, /container-backed/);
536
- assert.match(full, /run in a Podman container/);
537
- assert.match(full, /There is no host shell/);
538
- // The facts that pre-empt the "bash runs on the host" hallucination: the
539
- // built-in shell and container_bash run in one container, and identical uname
540
- // output is the shared kernel, not a host shell.
541
- assert.match(full, /container: "default"/);
542
- assert.match(full, /sees the same environment and filesystem/);
543
- assert.match(full, /share the host kernel/);
544
- assert.match(full, /hostname/);
545
- assert.match(full, /\/etc\/os-release/);
546
- // Containers belong to a dsh workspace, and the daemon tools are
547
- // container-scoped too (they do not start with `container_`).
548
- assert.match(full, /scoped to a dsh workspace/);
549
- assert.match(full, /container_\*/);
550
- assert.match(full, /daemon_\*/);
551
- // Neither the old vocabulary nor plugin lore belongs in the section.
552
- assert.doesNotMatch(full, /Podman workspace/);
553
- assert.doesNotMatch(full, /those same operations/);
554
- assert.doesNotMatch(full, /plugin/i);
555
- // The Podman operator preset mounts none of them, so the wording must not
556
- // name a tool the agent cannot call.
557
- const containerOnly = podmanRuntimeSection({
558
- tools: { get: () => undefined },
559
- });
560
- const short = containerOnly.text({ scope: "agent" });
561
- for (const tool of ["bash", "read", "write", "edit", "glob", "grep"]) {
562
- assert.doesNotMatch(short, new RegExp("`" + tool + "`"));
563
- }
564
- assert.doesNotMatch(short, /container-backed/);
565
- assert.doesNotMatch(short, /sees the same/);
566
- assert.match(short, /run in a Podman container/);
567
- assert.match(short, /There is no host shell/);
568
- assert.match(short, /container: "default"/);
569
- assert.match(short, /scoped to a dsh workspace/);
570
- assert.match(short, /container_\*/);
571
- assert.match(short, /daemon_\*/);
572
- assert.match(short, /share the host kernel/);
573
- });
574
- test("podmanRuntimeSection guides the model to custom images and named volumes", () => {
575
- const variants = [
576
- podmanRuntimeSection({ tools: { get: () => ({}) } }),
577
- podmanRuntimeSection({ tools: { get: () => undefined } }),
578
- ];
579
- for (const section of variants) {
580
- const text = section.text({ scope: "agent" });
581
- // Software installs belong in an image, not a running container.
582
- assert.match(text, /custom image/);
583
- assert.match(text, /`image_build`/);
584
- assert.match(text, /`container_start`/);
585
- assert.match(text, /`container_recreate`/);
586
- // Persistence belongs in a named volume, not a tmpfs.
587
- assert.match(text, /named `volume`/);
588
- assert.match(text, /`tmpfs`/);
589
- assert.match(text, /\/tmp/);
590
- assert.match(text, /clears tmpfs contents/);
591
- // The guidance stays free of plugin lore: the section reads as facts.
592
- assert.doesNotMatch(text, /plugin/i);
593
- }
594
- });
595
- test("container_grep fails loudly when ripgrep reports an error", async () => {
596
- const guest = {
597
- exec: () => {
598
- const handlers = {};
599
- return {
600
- on(event, handler) {
601
- (handlers[event] ??= []).push(handler);
602
- },
603
- write() { },
604
- end() {
605
- for (const handler of handlers.data ?? []) {
606
- handler({
607
- stderrChunk: Buffer.from("rg: error parsing glob '[bad'\n"),
608
- });
609
- handler({ exit: { exitCode: 2, signaled: false } });
610
- }
611
- },
612
- };
613
- },
614
- };
615
- const resolver = {
616
- resolve: async () => ({ guest, token: "t" }),
617
- containerBinding: async () => ({ guest, token: "t" }),
618
- };
619
- const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
620
- await assert.rejects(toolHandlers.container_grep(resolver, { container: "default", pattern: "TODO", include: "[bad" }, exec), /error parsing glob/);
621
- });
@@ -1 +0,0 @@
1
- export {};