@exagone313/dsh-podman 1.0.2 → 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 (91) hide show
  1. package/dist/generated/version.d.ts +2 -2
  2. package/dist/generated/version.js +2 -2
  3. package/docs/architecture.md +13 -4
  4. package/docs/architecture.zh.md +7 -2
  5. package/docs/development.md +8 -4
  6. package/docs/development.zh.md +7 -4
  7. package/package.json +3 -1
  8. package/dist/approval-reasons.test.d.ts +0 -1
  9. package/dist/approval-reasons.test.js +0 -143
  10. package/dist/approval.test.d.ts +0 -1
  11. package/dist/approval.test.js +0 -593
  12. package/dist/card-route.test.d.ts +0 -1
  13. package/dist/card-route.test.js +0 -223
  14. package/dist/card-test-support.d.ts +0 -15
  15. package/dist/card-test-support.js +0 -133
  16. package/dist/container-env.test.d.ts +0 -1
  17. package/dist/container-env.test.js +0 -93
  18. package/dist/containers.test.d.ts +0 -1
  19. package/dist/containers.test.js +0 -621
  20. package/dist/daemons.test.d.ts +0 -1
  21. package/dist/daemons.test.js +0 -167
  22. package/dist/dsh-version.test.d.ts +0 -1
  23. package/dist/dsh-version.test.js +0 -25
  24. package/dist/env-rows.test.d.ts +0 -1
  25. package/dist/env-rows.test.js +0 -43
  26. package/dist/fs-provider.test.d.ts +0 -1
  27. package/dist/fs-provider.test.js +0 -301
  28. package/dist/guest-rpc.test.d.ts +0 -1
  29. package/dist/guest-rpc.test.js +0 -241
  30. package/dist/images.test.d.ts +0 -1
  31. package/dist/images.test.js +0 -86
  32. package/dist/locales.test.d.ts +0 -1
  33. package/dist/locales.test.js +0 -34
  34. package/dist/misc.test.d.ts +0 -1
  35. package/dist/misc.test.js +0 -169
  36. package/dist/mounts.test.d.ts +0 -1
  37. package/dist/mounts.test.js +0 -478
  38. package/dist/naming.test.d.ts +0 -1
  39. package/dist/naming.test.js +0 -28
  40. package/dist/package-deps.test.d.ts +0 -1
  41. package/dist/package-deps.test.js +0 -49
  42. package/dist/paths.test.d.ts +0 -1
  43. package/dist/paths.test.js +0 -76
  44. package/dist/plugin-meta.test.d.ts +0 -1
  45. package/dist/plugin-meta.test.js +0 -29
  46. package/dist/project-path.test.d.ts +0 -1
  47. package/dist/project-path.test.js +0 -66
  48. package/dist/read-only-shell.test.d.ts +0 -1
  49. package/dist/read-only-shell.test.js +0 -182
  50. package/dist/runtime-client.test.d.ts +0 -1
  51. package/dist/runtime-client.test.js +0 -53
  52. package/dist/secrets.test.d.ts +0 -1
  53. package/dist/secrets.test.js +0 -196
  54. package/dist/settings-commands.test.d.ts +0 -1
  55. package/dist/settings-commands.test.js +0 -596
  56. package/dist/settings-create.test.d.ts +0 -1
  57. package/dist/settings-create.test.js +0 -416
  58. package/dist/settings-default-env.test.d.ts +0 -1
  59. package/dist/settings-default-env.test.js +0 -175
  60. package/dist/settings-mounts.test.d.ts +0 -1
  61. package/dist/settings-mounts.test.js +0 -506
  62. package/dist/settings-paths.test.d.ts +0 -1
  63. package/dist/settings-paths.test.js +0 -65
  64. package/dist/settings-schema.test.d.ts +0 -1
  65. package/dist/settings-schema.test.js +0 -35
  66. package/dist/settings-workspaces.test.d.ts +0 -1
  67. package/dist/settings-workspaces.test.js +0 -240
  68. package/dist/spill-store.test.d.ts +0 -1
  69. package/dist/spill-store.test.js +0 -82
  70. package/dist/subprocess.test.d.ts +0 -1
  71. package/dist/subprocess.test.js +0 -344
  72. package/dist/terminal-preference.test.d.ts +0 -1
  73. package/dist/terminal-preference.test.js +0 -62
  74. package/dist/terminal-route.test.d.ts +0 -1
  75. package/dist/terminal-route.test.js +0 -265
  76. package/dist/terminal-tab.test.d.ts +0 -1
  77. package/dist/terminal-tab.test.js +0 -58
  78. package/dist/terminal-targets.test.d.ts +0 -1
  79. package/dist/terminal-targets.test.js +0 -43
  80. package/dist/terminal-titles.test.d.ts +0 -1
  81. package/dist/terminal-titles.test.js +0 -36
  82. package/dist/test-support.d.ts +0 -358
  83. package/dist/test-support.js +0 -499
  84. package/dist/version-compat.test.d.ts +0 -1
  85. package/dist/version-compat.test.js +0 -27
  86. package/dist/views.test.d.ts +0 -1
  87. package/dist/views.test.js +0 -23
  88. package/dist/volumes.test.d.ts +0 -1
  89. package/dist/volumes.test.js +0 -40
  90. package/dist/workspace-binding.test.d.ts +0 -1
  91. package/dist/workspace-binding.test.js +0 -523
@@ -1,523 +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 grpc from "@grpc/grpc-js";
7
- import loader from "@grpc/proto-loader";
8
- import { fileURLToPath } from "node:url";
9
- import { dirname, resolve } from "node:path";
10
- import { tmpdir } from "node:os";
11
- import { existsSync, mkdirSync, rmSync } from "node:fs";
12
- import { controlClient, guestClient } from "./grpc/runtime-client.js";
13
- import { containerNotFound, metadata, normalizeToolError, WorkspaceResolver, workspaceSlug, } from "./workspace-binding.js";
14
- import { VERSION } from "./generated/version.js";
15
- const SLUG = "2c573001-4171-4900-904b-12a5cc02737a";
16
- const SLUG_SUB = "3d684112-5282-4a11-a15c-23b6dd13848b";
17
- test("normalizeToolError strips the prefix only for a gRPC status", () => {
18
- const statusError = Object.assign(new Error("5 NOT_FOUND: missing"), {
19
- code: 5,
20
- });
21
- const normalized = normalizeToolError(statusError);
22
- assert.equal(normalized.message, "missing");
23
- assert.equal(normalized.code, "NOT_FOUND");
24
- // A plain message that merely looks like a status keeps its text.
25
- const plain = normalizeToolError(new Error("5 NOT_FOUND: missing"));
26
- assert.equal(plain.message, "5 NOT_FOUND: missing");
27
- assert.equal(plain.code, undefined);
28
- });
29
- test("workspaceSlug accepts a UUID workspace id", () => {
30
- assert.equal(workspaceSlug(SLUG), SLUG);
31
- assert.equal(workspaceSlug(SLUG.toUpperCase()), SLUG);
32
- });
33
- test("workspaceSlug rejects anything that is not a UUID", () => {
34
- const invalid = [
35
- undefined,
36
- null,
37
- "",
38
- "proj",
39
- "team-app",
40
- "a/b",
41
- "..",
42
- "a b",
43
- `${SLUG}-x`,
44
- SLUG.slice(0, -1),
45
- ];
46
- for (const value of invalid) {
47
- assert.throws(() => workspaceSlug(value), /expected a UUID/, `expected ${JSON.stringify(value)} to be rejected`);
48
- }
49
- });
50
- test("metadata carries the bearer token", () => {
51
- const result = metadata("token-1");
52
- assert.ok(result instanceof grpc.Metadata);
53
- assert.equal(result.get("authorization")[0], "bearer token-1");
54
- });
55
- test("metadata omits the header when the token is empty", () => {
56
- const result = metadata("");
57
- assert.ok(result instanceof grpc.Metadata);
58
- assert.equal(result.get("authorization").length, 0);
59
- });
60
- test("metadata carries the plugin version only when one is given", () => {
61
- const withVersion = metadata("token-1", "1.2.3");
62
- assert.equal(withVersion.get("x-dsh-podman-plugin-version")[0], "1.2.3");
63
- // Guest calls pass no version, and the guest agent does not check it.
64
- assert.equal(metadata("token-1").get("x-dsh-podman-plugin-version").length, 0);
65
- });
66
- test("normalizeToolError strips the grpc prefix and names the code", () => {
67
- const prefixed = Object.assign(new Error("5 NOT_FOUND: container not found"), { code: 5 });
68
- const normalized = normalizeToolError(prefixed);
69
- assert.equal(normalized.message, "container not found");
70
- assert.equal(normalized.code, "NOT_FOUND");
71
- const plain = normalizeToolError(new Error("boom"));
72
- assert.equal(plain.message, "boom");
73
- assert.equal(plain.code, undefined);
74
- const named = Object.assign(new Error("bad input"), {
75
- code: "INVALID_ARGUMENT",
76
- });
77
- assert.equal(normalizeToolError(named).code, "INVALID_ARGUMENT");
78
- });
79
- test("containerNotFound reports one stable shape", () => {
80
- assert.equal(containerNotFound("db", "w1").message, 'container "db" not found in workspace "w1"');
81
- assert.equal(containerNotFound("db").code, "NOT_FOUND");
82
- assert.equal(containerNotFound("db").message, 'container "db" not found');
83
- });
84
- test("control and guest proto files resolve next to the runtime", () => {
85
- const control = controlClient("/tmp/dsh-proto-control.sock");
86
- const guest = guestClient("/tmp/dsh-proto-guest.sock");
87
- control.close();
88
- guest.close();
89
- });
90
- async function startControlServer(containers = [], options = {}) {
91
- const protoPath = resolve(dirname(fileURLToPath(import.meta.url)), "grpc/proto/dshctl/v1/control.proto");
92
- const definition = loader.loadSync(protoPath, {
93
- longs: String,
94
- enums: String,
95
- defaults: true,
96
- });
97
- const loaded = grpc.loadPackageDefinition(definition);
98
- const guestDefinition = loader.loadSync(resolve(dirname(fileURLToPath(import.meta.url)), "grpc/proto/dshguest/v1/guest.proto"), { longs: String, enums: String, defaults: true });
99
- const guestLoaded = grpc.loadPackageDefinition(guestDefinition);
100
- const server = new grpc.Server();
101
- // With staleToken, the first container row carries a credential the agent
102
- // rejects, so the caller must refresh before it can proceed.
103
- let ensureCalls = 0;
104
- server.addService(guestLoaded.dshguest.v1.WorkspaceGuestAgent.service, {
105
- ping: (call, callback) => {
106
- const bearer = String(call.metadata.get("authorization")[0] ?? "");
107
- if (bearer === "bearer stale") {
108
- callback({
109
- code: grpc.status.UNAUTHENTICATED,
110
- details: "invalid agent token",
111
- });
112
- return;
113
- }
114
- callback(null, { version: "test", commit: "test" });
115
- },
116
- });
117
- const received = [];
118
- const versions = [];
119
- const createRequests = [];
120
- const recreateRequests = [];
121
- server.addService(loaded.dshctl.v1.OrchestratorControl.service, {
122
- listWorkspaces: (call, callback) => {
123
- received.push(call.metadata.get("authorization")[0]);
124
- versions.push(call.metadata.get("x-dsh-podman-plugin-version")[0]);
125
- callback(null, { workspaces: [] });
126
- },
127
- describeWorkspace: (_call, callback) => {
128
- callback({ code: grpc.status.NOT_FOUND, details: "workspace not found" });
129
- },
130
- ensureContainer: (call, callback) => {
131
- const agentToken = options.staleToken === true && ensureCalls++ === 0
132
- ? "stale"
133
- : "tok";
134
- const row = containers.find((candidate) => candidate.workspaceSlug === call.request.workspaceSlug &&
135
- candidate.containerName === call.request.container);
136
- if (row !== undefined) {
137
- callback(null, { ...row, agentToken });
138
- return;
139
- }
140
- if (call.request.container === "default") {
141
- // The default container createWorkspace just made.
142
- callback(null, {
143
- workspaceSlug: call.request.workspaceSlug,
144
- containerName: "default",
145
- agentSocketPath: resolve(socketsRoot, "guest.sock"),
146
- agentToken,
147
- mounts: [],
148
- });
149
- return;
150
- }
151
- callback({ code: grpc.status.NOT_FOUND, details: "container not found" });
152
- },
153
- createWorkspace: (call, callback) => {
154
- createRequests.push(call.request);
155
- callback(null, {
156
- workspaceSlug: call.request.workspaceSlug,
157
- agentSocketPath: resolve(socketsRoot, "guest.sock"),
158
- agentToken: "tok",
159
- });
160
- },
161
- recreateContainer: (call, callback) => {
162
- recreateRequests.push(call.request);
163
- callback(null, { workspaceSlug: call.request.workspaceSlug });
164
- },
165
- addContainerMount: (_call, callback) => {
166
- callback(null, {});
167
- },
168
- removeWorkspace: (_call, callback) => {
169
- callback(null, {});
170
- },
171
- });
172
- const socketsRoot = resolve(tmpdir(), `dsh-control-test-${process.pid}-${Date.now()}-${Math.random()}`);
173
- mkdirSync(socketsRoot, { recursive: true });
174
- const socket = resolve(socketsRoot, "orchestrator.sock");
175
- await new Promise((ok, fail) => server.bindAsync(`unix:${socket}`, grpc.ServerCredentials.createInsecure(), (error) => (error ? fail(error) : ok())));
176
- // Also answer on the guest socket the fake createWorkspace hands back, so a
177
- // resolved binding becomes ready immediately instead of waiting out the
178
- // readiness deadline.
179
- await new Promise((ok, fail) => server.bindAsync(`unix:${resolve(socketsRoot, "guest.sock")}`, grpc.ServerCredentials.createInsecure(), (error) => (error ? fail(error) : ok())));
180
- // Point the fake container rows at the same guest socket, so a named
181
- // container binding becomes ready immediately too.
182
- if (options.rewriteContainerSocket !== false) {
183
- for (const row of containers) {
184
- row.agentSocketPath = resolve(socketsRoot, "guest.sock");
185
- }
186
- }
187
- return {
188
- socketsRoot,
189
- received,
190
- versions,
191
- createRequests,
192
- recreateRequests,
193
- stop: () => {
194
- server.forceShutdown();
195
- // gRPC unlinks its sockets on shutdown; drop the root too so repeated
196
- // runs do not accumulate directories under the system temp dir.
197
- rmSync(socketsRoot, { recursive: true, force: true });
198
- },
199
- };
200
- }
201
- test("the control server cleanup removes its temp root", async () => {
202
- const control = await startControlServer();
203
- assert.ok(existsSync(control.socketsRoot));
204
- control.stop();
205
- assert.equal(existsSync(control.socketsRoot), false);
206
- });
207
- test("control calls carry the bearer token", async () => {
208
- const { socketsRoot, received, versions, stop } = await startControlServer();
209
- try {
210
- const resolver = new WorkspaceResolver({
211
- socketsRoot,
212
- defaultImage: "arch",
213
- projectsRoot: "/projects",
214
- controlToken: "tok-1",
215
- }, undefined);
216
- await resolver.control("listWorkspaces", {});
217
- assert.equal(received[0], "bearer tok-1");
218
- assert.equal(versions[0], VERSION, "control calls report the plugin version");
219
- }
220
- finally {
221
- stop();
222
- }
223
- });
224
- test("control calls omit the token when unset", async () => {
225
- const { socketsRoot, received, versions, stop } = await startControlServer();
226
- try {
227
- const resolver = new WorkspaceResolver({
228
- socketsRoot,
229
- defaultImage: "arch",
230
- projectsRoot: "/projects",
231
- controlToken: "",
232
- }, undefined);
233
- await resolver.control("listWorkspaces", {});
234
- assert.equal(received[0], undefined);
235
- }
236
- finally {
237
- stop();
238
- }
239
- });
240
- test("the auto-created workspace mount stays read-write", async () => {
241
- // Additional mounts default to read-only, but the workspace's own project
242
- // directory must stay writable or the agent cannot edit the project.
243
- const { socketsRoot, createRequests, stop } = await startControlServer();
244
- try {
245
- const resolver = new WorkspaceResolver({
246
- socketsRoot,
247
- defaultImage: "arch",
248
- projectsRoot: "/projects",
249
- controlToken: "",
250
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
251
- await resolver.resolve("/projects/team");
252
- assert.equal(createRequests.length, 1);
253
- assert.equal(createRequests[0].projectName, "team");
254
- const mounts = createRequests[0].mounts;
255
- assert.equal(mounts.length, 1);
256
- assert.equal(mounts[0].projectName, "team");
257
- assert.equal(mounts[0].mode, "MOUNT_MODE_READ_WRITE");
258
- }
259
- finally {
260
- stop();
261
- }
262
- });
263
- test("resolve exposes the session directory as the default cwd", async () => {
264
- const { socketsRoot, stop } = await startControlServer();
265
- try {
266
- const resolver = new WorkspaceResolver({
267
- socketsRoot,
268
- defaultImage: "arch",
269
- projectsRoot: "/projects",
270
- controlToken: "",
271
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
272
- const binding = await resolver.resolve("/projects/team");
273
- assert.equal(binding.defaultCwd, "/projects/team");
274
- }
275
- finally {
276
- stop();
277
- }
278
- });
279
- test("resolve refreshes a binding whose token the agent rejects", async () => {
280
- // The first row carries a credential the guest agent rejects; resolving must
281
- // re-run the orchestrator's ensure and end with the usable token.
282
- const { socketsRoot, stop } = await startControlServer([], {
283
- staleToken: true,
284
- });
285
- try {
286
- const resolver = new WorkspaceResolver({
287
- socketsRoot,
288
- defaultImage: "arch",
289
- projectsRoot: "/projects",
290
- controlToken: "",
291
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
292
- const binding = await resolver.resolve("/projects/team");
293
- assert.equal(binding.token, "tok");
294
- }
295
- finally {
296
- stop();
297
- }
298
- });
299
- test("the auto-created workspace seeds the default environment", async () => {
300
- const { socketsRoot, createRequests, stop } = await startControlServer();
301
- try {
302
- const resolver = new WorkspaceResolver({
303
- socketsRoot,
304
- defaultImage: "arch",
305
- projectsRoot: "/projects",
306
- controlToken: "",
307
- containerEnv: { GIT_AUTHOR_NAME: "John Doe" },
308
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
309
- await resolver.resolve("/projects/team");
310
- assert.equal(createRequests.length, 1);
311
- assert.deepEqual(createRequests[0].env, { GIT_AUTHOR_NAME: "John Doe" });
312
- }
313
- finally {
314
- stop();
315
- }
316
- });
317
- test("the auto-created workspace omits env without defaults", async () => {
318
- const { socketsRoot, createRequests, stop } = await startControlServer();
319
- try {
320
- const resolver = new WorkspaceResolver({
321
- socketsRoot,
322
- defaultImage: "arch",
323
- projectsRoot: "/projects",
324
- controlToken: "",
325
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
326
- await resolver.resolve("/projects/team");
327
- assert.deepEqual(createRequests[0].env, {});
328
- }
329
- finally {
330
- stop();
331
- }
332
- });
333
- test("containerBinding exposes the session directory only when a project mount covers it", async () => {
334
- const mounted = await startControlServer([{
335
- workspaceSlug: SLUG,
336
- containerName: "db",
337
- agentSocketPath: "/run/x.sock",
338
- agentToken: "tok",
339
- mounts: [{ kind: "MOUNT_KIND_PROJECT", projectName: "team" }],
340
- }]);
341
- try {
342
- const resolver = new WorkspaceResolver({
343
- socketsRoot: mounted.socketsRoot,
344
- defaultImage: "arch",
345
- projectsRoot: "/projects",
346
- controlToken: "",
347
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
348
- const binding = await resolver.containerBinding("/projects/team", "db");
349
- assert.equal(binding.defaultCwd, "/projects/team");
350
- }
351
- finally {
352
- mounted.stop();
353
- }
354
- const unmounted = await startControlServer([{
355
- workspaceSlug: SLUG,
356
- containerName: "db",
357
- agentSocketPath: "/run/x.sock",
358
- agentToken: "tok",
359
- mounts: [{
360
- kind: "MOUNT_KIND_VOLUME",
361
- volume: "data",
362
- destination: "/data",
363
- }],
364
- }]);
365
- try {
366
- const resolver = new WorkspaceResolver({
367
- socketsRoot: unmounted.socketsRoot,
368
- defaultImage: "arch",
369
- projectsRoot: "/projects",
370
- controlToken: "",
371
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
372
- const binding = await resolver.containerBinding("/projects/team", "db");
373
- assert.equal(binding.defaultCwd, undefined);
374
- }
375
- finally {
376
- unmounted.stop();
377
- }
378
- });
379
- test("containerBinding re-resolves the mount set after a container mutation", async () => {
380
- const rows = [
381
- {
382
- workspaceSlug: SLUG,
383
- containerName: "db",
384
- agentSocketPath: "/run/x.sock",
385
- agentToken: "tok",
386
- mounts: [{ kind: "MOUNT_KIND_PROJECT", projectName: "team" }],
387
- },
388
- ];
389
- const control = await startControlServer(rows);
390
- try {
391
- const resolver = new WorkspaceResolver({
392
- socketsRoot: control.socketsRoot,
393
- defaultImage: "arch",
394
- projectsRoot: "/projects",
395
- controlToken: "",
396
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
397
- const first = await resolver.containerBinding("/projects/team", "db");
398
- assert.equal(first.defaultCwd, "/projects/team");
399
- // The container no longer mounts the session directory, but the cached
400
- // entry still describes the row it was built from.
401
- rows[0].mounts = [
402
- { kind: "MOUNT_KIND_VOLUME", volume: "data", destination: "/data" },
403
- ];
404
- const stale = await resolver.containerBinding("/projects/team", "db");
405
- assert.equal(stale.defaultCwd, "/projects/team", "the cache is served until it is invalidated");
406
- await resolver.control("addContainerMount", {
407
- workspaceSlug: SLUG,
408
- container: "db",
409
- });
410
- const fresh = await resolver.containerBinding("/projects/team", "db");
411
- assert.equal(fresh.defaultCwd, undefined, "a mutation re-resolves the mount set");
412
- }
413
- finally {
414
- control.stop();
415
- }
416
- });
417
- test("removing a workspace drops every cached container binding", async () => {
418
- const rows = [
419
- {
420
- workspaceSlug: SLUG,
421
- containerName: "db",
422
- agentSocketPath: "/run/x.sock",
423
- agentToken: "tok",
424
- mounts: [{ kind: "MOUNT_KIND_PROJECT", projectName: "team" }],
425
- },
426
- ];
427
- const control = await startControlServer(rows);
428
- try {
429
- const resolver = new WorkspaceResolver({
430
- socketsRoot: control.socketsRoot,
431
- defaultImage: "arch",
432
- projectsRoot: "/projects",
433
- controlToken: "",
434
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
435
- await resolver.containerBinding("/projects/team", "db");
436
- rows[0].mounts = [];
437
- await resolver.control("removeWorkspace", { workspaceSlug: SLUG });
438
- const fresh = await resolver.containerBinding("/projects/team", "db");
439
- assert.equal(fresh.defaultCwd, undefined);
440
- }
441
- finally {
442
- control.stop();
443
- }
444
- });
445
- test("containerBinding recreates a container whose agent never answers", async () => {
446
- const control = await startControlServer([{
447
- workspaceSlug: SLUG,
448
- containerName: "db",
449
- agentSocketPath: "/nonexistent/guest.sock",
450
- agentToken: "tok",
451
- mounts: [],
452
- }], { rewriteContainerSocket: false });
453
- try {
454
- const resolver = new WorkspaceResolver({
455
- socketsRoot: control.socketsRoot,
456
- defaultImage: "arch",
457
- projectsRoot: "/projects",
458
- controlToken: "",
459
- readyTimeoutMs: 50,
460
- }, { resolveByPath: () => ({ id: SLUG, path: "/projects/team" }) });
461
- await assert.rejects(() => resolver.containerBinding("/projects/team", "db"));
462
- assert.equal(control.recreateRequests.length, 1);
463
- assert.equal(control.recreateRequests[0].container, "db");
464
- }
465
- finally {
466
- control.stop();
467
- }
468
- });
469
- test("resolveForPath derives the workspace from an absolute path without a cwd", async () => {
470
- const { socketsRoot, createRequests, stop } = await startControlServer();
471
- try {
472
- const resolver = new WorkspaceResolver({
473
- socketsRoot,
474
- defaultImage: "arch",
475
- projectsRoot: "/projects",
476
- controlToken: "",
477
- }, {
478
- list: () => [
479
- { id: SLUG, path: "/projects/team" },
480
- { id: SLUG_SUB, path: "/projects/team/sub" },
481
- ],
482
- resolveByPath: (path) => path === "/projects/team/sub"
483
- ? { id: SLUG_SUB, path: "/projects/team/sub" }
484
- : { id: SLUG, path: "/projects/team" },
485
- });
486
- const binding = await resolver.resolveForPath("/projects/team/sub/AGENTS.md", undefined);
487
- assert.equal(binding.defaultCwd, "/projects/team/sub");
488
- assert.equal(createRequests[0].projectName, "team/sub");
489
- }
490
- finally {
491
- stop();
492
- }
493
- });
494
- test("resolveForPath rejects paths it cannot map to a workspace", async () => {
495
- const resolver = new WorkspaceResolver({
496
- socketsRoot: "/run/dsh",
497
- defaultImage: "arch",
498
- projectsRoot: "/projects",
499
- controlToken: "",
500
- }, {
501
- list: () => [{ id: SLUG, path: "/projects/team" }],
502
- resolveByPath: () => undefined,
503
- });
504
- await assert.rejects(() => resolver.resolveForPath("README.md", undefined), /session working directory/);
505
- // A path outside every workspace is not in any container's filesystem: it is
506
- // reported with the harness's missing-path code so callers treat it as absent
507
- // (agent-instructions walks ancestors above the workspace this way).
508
- await assert.rejects(() => resolver.resolveForPath("/elsewhere/file", undefined), (error) => error instanceof Error &&
509
- error.code === "FS_NOT_FOUND");
510
- });
511
- test("resolve rejects a missing cwd without stringifying it", async () => {
512
- const resolver = new WorkspaceResolver({
513
- socketsRoot: "/run/dsh",
514
- defaultImage: "arch",
515
- projectsRoot: "/projects",
516
- controlToken: "",
517
- }, {
518
- resolveByPath: () => {
519
- throw new Error("resolveByPath must not be called with a missing cwd");
520
- },
521
- });
522
- await assert.rejects(() => resolver.resolve(undefined), /session working directory/);
523
- });