@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.
- package/dist/generated/version.d.ts +2 -2
- package/dist/generated/version.js +2 -2
- package/docs/development.md +8 -4
- package/docs/development.zh.md +7 -4
- package/package.json +3 -1
- package/dist/approval-reasons.test.d.ts +0 -1
- package/dist/approval-reasons.test.js +0 -143
- package/dist/approval.test.d.ts +0 -1
- package/dist/approval.test.js +0 -593
- package/dist/card-route.test.d.ts +0 -1
- package/dist/card-route.test.js +0 -223
- package/dist/card-test-support.d.ts +0 -15
- package/dist/card-test-support.js +0 -133
- package/dist/container-env.test.d.ts +0 -1
- package/dist/container-env.test.js +0 -93
- package/dist/containers.test.d.ts +0 -1
- package/dist/containers.test.js +0 -621
- package/dist/daemons.test.d.ts +0 -1
- package/dist/daemons.test.js +0 -167
- package/dist/dsh-version.test.d.ts +0 -1
- package/dist/dsh-version.test.js +0 -25
- package/dist/env-rows.test.d.ts +0 -1
- package/dist/env-rows.test.js +0 -43
- package/dist/fs-provider.test.d.ts +0 -1
- package/dist/fs-provider.test.js +0 -301
- package/dist/guest-rpc.test.d.ts +0 -1
- package/dist/guest-rpc.test.js +0 -241
- package/dist/images.test.d.ts +0 -1
- package/dist/images.test.js +0 -86
- package/dist/locales.test.d.ts +0 -1
- package/dist/locales.test.js +0 -34
- package/dist/misc.test.d.ts +0 -1
- package/dist/misc.test.js +0 -169
- package/dist/mounts.test.d.ts +0 -1
- package/dist/mounts.test.js +0 -478
- package/dist/naming.test.d.ts +0 -1
- package/dist/naming.test.js +0 -28
- package/dist/package-deps.test.d.ts +0 -1
- package/dist/package-deps.test.js +0 -49
- package/dist/paths.test.d.ts +0 -1
- package/dist/paths.test.js +0 -76
- package/dist/plugin-meta.test.d.ts +0 -1
- package/dist/plugin-meta.test.js +0 -29
- package/dist/project-path.test.d.ts +0 -1
- package/dist/project-path.test.js +0 -66
- package/dist/read-only-shell.test.d.ts +0 -1
- package/dist/read-only-shell.test.js +0 -182
- package/dist/runtime-client.test.d.ts +0 -1
- package/dist/runtime-client.test.js +0 -53
- package/dist/secrets.test.d.ts +0 -1
- package/dist/secrets.test.js +0 -196
- package/dist/settings-commands.test.d.ts +0 -1
- package/dist/settings-commands.test.js +0 -596
- package/dist/settings-create.test.d.ts +0 -1
- package/dist/settings-create.test.js +0 -416
- package/dist/settings-default-env.test.d.ts +0 -1
- package/dist/settings-default-env.test.js +0 -175
- package/dist/settings-mounts.test.d.ts +0 -1
- package/dist/settings-mounts.test.js +0 -506
- package/dist/settings-paths.test.d.ts +0 -1
- package/dist/settings-paths.test.js +0 -65
- package/dist/settings-schema.test.d.ts +0 -1
- package/dist/settings-schema.test.js +0 -35
- package/dist/settings-workspaces.test.d.ts +0 -1
- package/dist/settings-workspaces.test.js +0 -240
- package/dist/spill-store.test.d.ts +0 -1
- package/dist/spill-store.test.js +0 -82
- package/dist/subprocess.test.d.ts +0 -1
- package/dist/subprocess.test.js +0 -344
- package/dist/terminal-preference.test.d.ts +0 -1
- package/dist/terminal-preference.test.js +0 -62
- package/dist/terminal-route.test.d.ts +0 -1
- package/dist/terminal-route.test.js +0 -265
- package/dist/terminal-tab.test.d.ts +0 -1
- package/dist/terminal-tab.test.js +0 -58
- package/dist/terminal-targets.test.d.ts +0 -1
- package/dist/terminal-targets.test.js +0 -43
- package/dist/terminal-titles.test.d.ts +0 -1
- package/dist/terminal-titles.test.js +0 -36
- package/dist/test-support.d.ts +0 -358
- package/dist/test-support.js +0 -499
- package/dist/version-compat.test.d.ts +0 -1
- package/dist/version-compat.test.js +0 -27
- package/dist/views.test.d.ts +0 -1
- package/dist/views.test.js +0 -23
- package/dist/volumes.test.d.ts +0 -1
- package/dist/volumes.test.js +0 -40
- package/dist/workspace-binding.test.d.ts +0 -1
- package/dist/workspace-binding.test.js +0 -523
package/dist/guest-rpc.test.js
DELETED
|
@@ -1,241 +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 { EventEmitter } from "node:events";
|
|
7
|
-
import { runExec, sessionWorkspaceSlug, sliceLines, streamLines, withGuestAuth, } from "./guest-rpc.js";
|
|
8
|
-
import { grpc } from "./grpc/runtime-client.js";
|
|
9
|
-
// pingOnce is a stand-in for a real guest call: it invokes the guest client and
|
|
10
|
-
// settles from its callback.
|
|
11
|
-
function pingOnce(guest, _token) {
|
|
12
|
-
return new Promise((resolve, reject) => {
|
|
13
|
-
guest.ping({}, undefined, (error, value) => error ? reject(error) : resolve(value));
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
function rejectingGuest() {
|
|
17
|
-
return {
|
|
18
|
-
guest: {
|
|
19
|
-
ping: (_request, _metadata, callback) => callback(Object.assign(new Error("invalid agent token"), {
|
|
20
|
-
code: grpc.status.UNAUTHENTICATED,
|
|
21
|
-
})),
|
|
22
|
-
},
|
|
23
|
-
token: "old",
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
test("withGuestAuth retries once with a refreshed binding", async () => {
|
|
27
|
-
const seen = [];
|
|
28
|
-
const fresh = {
|
|
29
|
-
guest: {
|
|
30
|
-
ping: (_request, _metadata, callback) => callback(null, { version: "v" }),
|
|
31
|
-
},
|
|
32
|
-
token: "new",
|
|
33
|
-
};
|
|
34
|
-
const binding = { ...rejectingGuest(), refresh: async () => fresh };
|
|
35
|
-
const result = await withGuestAuth(binding, (guest, token) => {
|
|
36
|
-
seen.push(token);
|
|
37
|
-
return pingOnce(guest, token);
|
|
38
|
-
});
|
|
39
|
-
assert.deepEqual(seen, ["old", "new"]);
|
|
40
|
-
assert.deepEqual(result, { version: "v" });
|
|
41
|
-
});
|
|
42
|
-
test("withGuestAuth surfaces a second rejection", async () => {
|
|
43
|
-
const rejecting = rejectingGuest();
|
|
44
|
-
const binding = { ...rejecting, refresh: async () => rejecting };
|
|
45
|
-
await assert.rejects(() => withGuestAuth(binding, pingOnce), /invalid agent token/);
|
|
46
|
-
});
|
|
47
|
-
test("withGuestAuth does not refresh on a non-auth error", async () => {
|
|
48
|
-
let refreshed = false;
|
|
49
|
-
const binding = {
|
|
50
|
-
guest: {
|
|
51
|
-
ping: (_request, _metadata, callback) => callback(Object.assign(new Error("boom"), { code: grpc.status.INTERNAL })),
|
|
52
|
-
},
|
|
53
|
-
token: "t",
|
|
54
|
-
refresh: async () => {
|
|
55
|
-
refreshed = true;
|
|
56
|
-
return binding;
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
await assert.rejects(() => withGuestAuth(binding, pingOnce), /boom/);
|
|
60
|
-
assert.equal(refreshed, false);
|
|
61
|
-
});
|
|
62
|
-
test("withGuestAuth surfaces the error when the binding cannot refresh", async () => {
|
|
63
|
-
const binding = rejectingGuest();
|
|
64
|
-
await assert.rejects(() => withGuestAuth(binding, pingOnce), /invalid agent token/);
|
|
65
|
-
});
|
|
66
|
-
// FakeExecStream is the guest Exec bidi stream a real channel would give us.
|
|
67
|
-
class FakeExecStream extends EventEmitter {
|
|
68
|
-
written = [];
|
|
69
|
-
ended = false;
|
|
70
|
-
cancelled = false;
|
|
71
|
-
write(message) {
|
|
72
|
-
this.written.push(message);
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
end() {
|
|
76
|
-
this.ended = true;
|
|
77
|
-
}
|
|
78
|
-
cancel() {
|
|
79
|
-
this.cancelled = true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// execGuest returns a guest double driving one FakeExecStream. `signal` and
|
|
83
|
-
// `delete` are the calls runExec makes for cancellation and spill cleanup.
|
|
84
|
-
function execGuest(stream) {
|
|
85
|
-
const signals = [];
|
|
86
|
-
return {
|
|
87
|
-
stream,
|
|
88
|
-
signals,
|
|
89
|
-
guest: {
|
|
90
|
-
exec: () => stream,
|
|
91
|
-
signal: (request, _metadata, callback) => {
|
|
92
|
-
signals.push(request.signal);
|
|
93
|
-
callback(null, {});
|
|
94
|
-
},
|
|
95
|
-
delete: (_request, _metadata, callback) => callback(null, {}),
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
const EXIT_OK = {
|
|
100
|
-
exitCode: 0,
|
|
101
|
-
signaled: false,
|
|
102
|
-
stdoutSpillValid: true,
|
|
103
|
-
stderrSpillValid: true,
|
|
104
|
-
};
|
|
105
|
-
test("runExec resolves on exit and asks the guest for a spill copy", async () => {
|
|
106
|
-
const harness = execGuest(new FakeExecStream());
|
|
107
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
108
|
-
const promise = runExec(binding, ["echo", "hi"]);
|
|
109
|
-
harness.stream.emit("data", { processId: "1" });
|
|
110
|
-
harness.stream.emit("data", { stdoutChunk: Buffer.from("hi\n") });
|
|
111
|
-
harness.stream.emit("data", { exit: EXIT_OK });
|
|
112
|
-
const result = await promise;
|
|
113
|
-
assert.equal(result.exitCode, 0);
|
|
114
|
-
assert.equal(result.stdout, "hi\n");
|
|
115
|
-
const start = harness.stream.written[0].start;
|
|
116
|
-
assert.match(start.spillStdout.path, /^\/tmp\/dsh-podman\/[0-9a-f-]+\.stdout$/);
|
|
117
|
-
assert.equal(start.spillStderr.path.endsWith(".stderr"), true);
|
|
118
|
-
// The output fit in memory, so the spill file is deleted again.
|
|
119
|
-
assert.equal(result.stdoutSpillPath, undefined);
|
|
120
|
-
});
|
|
121
|
-
test("runExec rejects when the stream ends without an exit message", async () => {
|
|
122
|
-
const harness = execGuest(new FakeExecStream());
|
|
123
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
124
|
-
const promise = runExec(binding, ["hang"]);
|
|
125
|
-
harness.stream.emit("end");
|
|
126
|
-
await assert.rejects(promise, /ended before the process exited/);
|
|
127
|
-
});
|
|
128
|
-
test("runExec aborts with the turn signal, then escalates to SIGKILL", async () => {
|
|
129
|
-
const harness = execGuest(new FakeExecStream());
|
|
130
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
131
|
-
const controller = new AbortController();
|
|
132
|
-
const promise = runExec(binding, ["sleep", "99"], undefined, undefined, undefined, undefined, {
|
|
133
|
-
signal: controller.signal,
|
|
134
|
-
killGraceMs: 60,
|
|
135
|
-
});
|
|
136
|
-
harness.stream.emit("data", { processId: "7" });
|
|
137
|
-
controller.abort();
|
|
138
|
-
await assert.rejects(promise, /aborted/);
|
|
139
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
140
|
-
assert.deepEqual(harness.signals, ["SIGTERM"]);
|
|
141
|
-
// The stream stays open for the grace period, so a command that ignores
|
|
142
|
-
// SIGTERM can still be killed by its process group.
|
|
143
|
-
assert.equal(harness.stream.cancelled, false);
|
|
144
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
145
|
-
assert.deepEqual(harness.signals, ["SIGTERM", "SIGKILL"]);
|
|
146
|
-
assert.equal(harness.stream.cancelled, true);
|
|
147
|
-
});
|
|
148
|
-
test("runExec leaves a command that exits within the grace period alone", async () => {
|
|
149
|
-
const harness = execGuest(new FakeExecStream());
|
|
150
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
151
|
-
const controller = new AbortController();
|
|
152
|
-
const promise = runExec(binding, ["sleep", "99"], undefined, undefined, undefined, undefined, {
|
|
153
|
-
signal: controller.signal,
|
|
154
|
-
killGraceMs: 30,
|
|
155
|
-
});
|
|
156
|
-
harness.stream.emit("data", { processId: "7" });
|
|
157
|
-
controller.abort();
|
|
158
|
-
await assert.rejects(promise, /aborted/);
|
|
159
|
-
harness.stream.emit("data", { exit: EXIT_OK });
|
|
160
|
-
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
161
|
-
assert.deepEqual(harness.signals, ["SIGTERM"]);
|
|
162
|
-
assert.equal(harness.stream.cancelled, false);
|
|
163
|
-
});
|
|
164
|
-
test("runExec cancels an abort that arrives before the process id", async () => {
|
|
165
|
-
const harness = execGuest(new FakeExecStream());
|
|
166
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
167
|
-
const controller = new AbortController();
|
|
168
|
-
const promise = runExec(binding, ["sleep", "99"], undefined, undefined, undefined, undefined, {
|
|
169
|
-
signal: controller.signal,
|
|
170
|
-
});
|
|
171
|
-
controller.abort();
|
|
172
|
-
await assert.rejects(promise, /aborted/);
|
|
173
|
-
assert.equal(harness.stream.cancelled, true);
|
|
174
|
-
assert.deepEqual(harness.signals, []);
|
|
175
|
-
});
|
|
176
|
-
test("runExec rejects a pre-aborted call without starting it", async () => {
|
|
177
|
-
const harness = execGuest(new FakeExecStream());
|
|
178
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
179
|
-
const controller = new AbortController();
|
|
180
|
-
controller.abort();
|
|
181
|
-
await assert.rejects(() => runExec(binding, ["x"], undefined, undefined, undefined, undefined, {
|
|
182
|
-
signal: controller.signal,
|
|
183
|
-
}), /aborted/);
|
|
184
|
-
assert.equal(harness.stream.written.length, 0);
|
|
185
|
-
});
|
|
186
|
-
test("runExec keeps a bounded tail and points at the spill on truncation", async () => {
|
|
187
|
-
const harness = execGuest(new FakeExecStream());
|
|
188
|
-
const binding = { guest: harness.guest, token: "t" };
|
|
189
|
-
const promise = runExec(binding, ["big"], undefined, undefined, undefined, undefined, {
|
|
190
|
-
maxBytes: 4,
|
|
191
|
-
spillBytes: 1024,
|
|
192
|
-
});
|
|
193
|
-
harness.stream.emit("data", { stdoutChunk: Buffer.from("0123456789") });
|
|
194
|
-
harness.stream.emit("data", { exit: EXIT_OK });
|
|
195
|
-
const result = await promise;
|
|
196
|
-
assert.equal(result.stdout, "6789", "only the bounded tail is retained");
|
|
197
|
-
assert.match(result.stdoutSpillPath ?? "", /^\/tmp\/dsh-podman\/[0-9a-f-]+\.stdout$/);
|
|
198
|
-
});
|
|
199
|
-
test("sessionWorkspaceSlug fails instead of fabricating a default workspace", async () => {
|
|
200
|
-
const resolver = { registry: { resolveByPath: async () => undefined } };
|
|
201
|
-
await assert.rejects(() => sessionWorkspaceSlug(resolver, "/projects/gone"), /cannot resolve a DH workspace/);
|
|
202
|
-
});
|
|
203
|
-
// chunks yields one character at a time, the worst case for a streaming line
|
|
204
|
-
// reader because every boundary can fall inside a line.
|
|
205
|
-
async function* characters(content) {
|
|
206
|
-
for (const character of content)
|
|
207
|
-
yield character;
|
|
208
|
-
}
|
|
209
|
-
test("streamLines matches sliceLines for every window shape", async () => {
|
|
210
|
-
const cases = [
|
|
211
|
-
["", 1, 5],
|
|
212
|
-
["a", 1, 5],
|
|
213
|
-
["a\n", 1, 5],
|
|
214
|
-
["a\nb\nc", 1, 2],
|
|
215
|
-
["a\nb\nc\n", 1, 2],
|
|
216
|
-
["a\nb\nc\n", 2, 2],
|
|
217
|
-
["a\nb\nc\n", 2, 10],
|
|
218
|
-
["a\nb", 2, 2],
|
|
219
|
-
["a\nb", 5, 2],
|
|
220
|
-
["x\ny\nz\n", 3, 10],
|
|
221
|
-
["1\n2\n3\n4\n5", 2, 3],
|
|
222
|
-
["\n\n\n", 2, 2],
|
|
223
|
-
];
|
|
224
|
-
for (const [content, offset, limit] of cases) {
|
|
225
|
-
const expected = sliceLines(content, offset, limit);
|
|
226
|
-
const streamed = await streamLines(characters(content), offset, limit);
|
|
227
|
-
assert.equal(streamed, expected, `content=${JSON.stringify(content)} offset=${offset} limit=${limit}`);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
test("streamLines stops consuming once the window is filled", async () => {
|
|
231
|
-
let consumed = 0;
|
|
232
|
-
async function* source() {
|
|
233
|
-
for (let index = 1; index <= 100; index++) {
|
|
234
|
-
consumed++;
|
|
235
|
-
yield `${index}\n`;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
const out = await streamLines(source(), 1, 2);
|
|
239
|
-
assert.equal(out, "1\n2");
|
|
240
|
-
assert.equal(consumed, 2);
|
|
241
|
-
});
|
package/dist/images.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/images.test.js
DELETED
|
@@ -1,86 +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 { EXPECTED_TOOLS } from "./test-support.js";
|
|
7
|
-
import { imageRemoveParameters, toolHandlers, TOOLS } from "./index.js";
|
|
8
|
-
test("tool set covers the image and container surface", () => {
|
|
9
|
-
assert.deepEqual(TOOLS.map((tool) => tool.name).sort(), [...EXPECTED_TOOLS].sort());
|
|
10
|
-
});
|
|
11
|
-
test("image_build requires imageId, parent and packages", () => {
|
|
12
|
-
const tool = TOOLS.find((entry) => entry.name === "image_build");
|
|
13
|
-
assert.ok(tool, "image_build registered");
|
|
14
|
-
assert.equal(tool.approval, true, "image_build must require approval");
|
|
15
|
-
assert.deepEqual(tool.parameters.required, [
|
|
16
|
-
"imageId",
|
|
17
|
-
"parent",
|
|
18
|
-
"packages",
|
|
19
|
-
]);
|
|
20
|
-
assert.equal(tool.parameters.properties.imageId.description, "Image short name.");
|
|
21
|
-
assert.ok(tool.parameters.properties.parent.description.includes("Short name of the parent image"), "parent must be documented as a short name");
|
|
22
|
-
});
|
|
23
|
-
test("image_remove is registered, requires approval and requires imageId", () => {
|
|
24
|
-
const tool = TOOLS.find((entry) => entry.name === "image_remove");
|
|
25
|
-
assert.ok(tool, "image_remove registered");
|
|
26
|
-
assert.equal(tool.approval, true, "image_remove must require approval");
|
|
27
|
-
assert.equal(tool.parameters.type, "object", "image_remove type");
|
|
28
|
-
assert.equal(typeof tool.parameters.properties, "object");
|
|
29
|
-
assert.deepEqual(tool.parameters.required, ["imageId"]);
|
|
30
|
-
assert.equal(tool.parameters.properties.imageId.type, "string");
|
|
31
|
-
assert.deepEqual(imageRemoveParameters, tool.parameters);
|
|
32
|
-
});
|
|
33
|
-
test("image_list returns image objects", async () => {
|
|
34
|
-
const resolver = {
|
|
35
|
-
control: async () => ({
|
|
36
|
-
images: [
|
|
37
|
-
{
|
|
38
|
-
imageId: "archlinux",
|
|
39
|
-
isBase: true,
|
|
40
|
-
status: "built",
|
|
41
|
-
primitive: "docker.io/library/archlinux:latest",
|
|
42
|
-
packageManager: "pacman",
|
|
43
|
-
basePublic: false,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
imageId: "dev",
|
|
47
|
-
parent: "ubuntu",
|
|
48
|
-
status: "built",
|
|
49
|
-
packages: ["git"],
|
|
50
|
-
packageManager: "apt",
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
const out = await toolHandlers.image_list(resolver, {}, {});
|
|
56
|
-
assert.deepEqual(out, [
|
|
57
|
-
{
|
|
58
|
-
imageId: "archlinux",
|
|
59
|
-
isBase: true,
|
|
60
|
-
status: "built",
|
|
61
|
-
primitive: "docker.io/library/archlinux:latest",
|
|
62
|
-
packageManager: "pacman",
|
|
63
|
-
basePublic: false,
|
|
64
|
-
packages: [],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
imageId: "dev",
|
|
68
|
-
parent: "ubuntu",
|
|
69
|
-
isBase: false,
|
|
70
|
-
status: "built",
|
|
71
|
-
packageManager: "apt",
|
|
72
|
-
basePublic: false,
|
|
73
|
-
packages: ["git"],
|
|
74
|
-
},
|
|
75
|
-
]);
|
|
76
|
-
});
|
|
77
|
-
test("image_rebuild_all returns rebuilt and skipped arrays", async () => {
|
|
78
|
-
const resolver = {
|
|
79
|
-
control: async () => ({
|
|
80
|
-
rebuilt: ["archlinux", "dev"],
|
|
81
|
-
skipped: ["broken"],
|
|
82
|
-
}),
|
|
83
|
-
};
|
|
84
|
-
const out = await toolHandlers.image_rebuild_all(resolver, {}, {});
|
|
85
|
-
assert.deepEqual(out, { rebuilt: ["archlinux", "dev"], skipped: ["broken"] });
|
|
86
|
-
});
|
package/dist/locales.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/locales.test.js
DELETED
|
@@ -1,34 +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
|
-
// Importing the client dictionary here also typechecks it under the host
|
|
7
|
-
// program, which has no DOM lib: it must stay environment-free data.
|
|
8
|
-
import { en, zh } from "./client/locales.js";
|
|
9
|
-
// A confirmation that acts on one object must name it. Each call site passes the
|
|
10
|
-
// placeholder listed here, so dropping a subject from either language fails.
|
|
11
|
-
const SUBJECTS = [
|
|
12
|
-
["confirmRemovePod", "workspace"],
|
|
13
|
-
["confirmRemoveContainer", "workspace"],
|
|
14
|
-
["confirmRemoveContainer", "container"],
|
|
15
|
-
["confirmRecreate", "workspace"],
|
|
16
|
-
["confirmRecreate", "container"],
|
|
17
|
-
["confirmDetachSecret", "env"],
|
|
18
|
-
["confirmDetachSecret", "secret"],
|
|
19
|
-
["confirmRebuildImage", "image"],
|
|
20
|
-
["confirmRemoveImage", "image"],
|
|
21
|
-
["confirmRemoveVolume", "volume"],
|
|
22
|
-
["confirmSetSecret", "secret"],
|
|
23
|
-
["confirmRemoveSecret", "secret"],
|
|
24
|
-
["confirmRemountReadOnly", "mount"],
|
|
25
|
-
["confirmRemountReadWrite", "mount"],
|
|
26
|
-
["confirmRemoveMount", "mount"],
|
|
27
|
-
];
|
|
28
|
-
test("every object-naming confirmation interpolates its subject", () => {
|
|
29
|
-
for (const [key, placeholder] of SUBJECTS) {
|
|
30
|
-
for (const [language, dictionary] of [["en", en], ["zh", zh]]) {
|
|
31
|
-
assert.ok(dictionary[key].includes(`{${placeholder}}`), `${language} ${key} must name {${placeholder}}`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
});
|
package/dist/misc.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/misc.test.js
DELETED
|
@@ -1,169 +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, } from "./test-support.js";
|
|
7
|
-
import { HARNESS_SOURCE_SECTION, toolCallView, toolHandlers, toolResultView, TOOLS, withoutHarnessSourceSection, } from "./index.js";
|
|
8
|
-
test("every tool parameters is a valid JSON-Schema object", () => {
|
|
9
|
-
for (const tool of TOOLS) {
|
|
10
|
-
assert.equal(tool.parameters.type, "object", `${tool.name} type`);
|
|
11
|
-
assert.equal(typeof tool.parameters.properties, "object");
|
|
12
|
-
assert.ok(Array.isArray(tool.parameters.required));
|
|
13
|
-
for (const key of Object.keys(tool.parameters.properties)) {
|
|
14
|
-
const property = tool.parameters.properties[key];
|
|
15
|
-
assert.ok(!Object.prototype.hasOwnProperty.call(property, "required"), `${tool.name}.${key} must not carry per-property required`);
|
|
16
|
-
assert.ok(!Array.isArray(property.required), `${tool.name}.${key} must not carry a required array`);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
test("file tools resolve relative paths against the session cwd", async () => {
|
|
21
|
-
const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
|
|
22
|
-
const read = guestFileRecorder();
|
|
23
|
-
await toolHandlers.container_read(read.resolver, { container: "default", file_path: "README.md" }, exec, fakeToolContext(read.resolver));
|
|
24
|
-
assert.deepEqual(read.reads, ["/projects/team/README.md"]);
|
|
25
|
-
const absolute = guestFileRecorder();
|
|
26
|
-
await toolHandlers.container_read(absolute.resolver, { container: "default", file_path: "/etc/hosts" }, exec, fakeToolContext(absolute.resolver));
|
|
27
|
-
assert.deepEqual(absolute.reads, ["/etc/hosts"], "absolute paths pass through");
|
|
28
|
-
const write = guestFileRecorder();
|
|
29
|
-
await toolHandlers.container_write(write.resolver, { container: "default", file_path: "out.txt", content: "x" }, exec, fakeToolContext(write.resolver));
|
|
30
|
-
assert.deepEqual(write.writes.map((entry) => entry.path), [
|
|
31
|
-
"/projects/team/out.txt",
|
|
32
|
-
]);
|
|
33
|
-
const edit = guestFileRecorder("hello");
|
|
34
|
-
await toolHandlers.container_edit(edit.resolver, {
|
|
35
|
-
container: "default",
|
|
36
|
-
file_path: "a.txt",
|
|
37
|
-
old_string: "hello",
|
|
38
|
-
new_string: "bye",
|
|
39
|
-
}, exec, fakeToolContext(edit.resolver));
|
|
40
|
-
assert.deepEqual(edit.reads, ["/projects/team/a.txt"]);
|
|
41
|
-
assert.deepEqual(edit.writes.map((entry) => entry.path), [
|
|
42
|
-
"/projects/team/a.txt",
|
|
43
|
-
]);
|
|
44
|
-
});
|
|
45
|
-
test("file tools refuse traversal before reaching the guest", async () => {
|
|
46
|
-
const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
|
|
47
|
-
const { reads, writes, resolver } = guestFileRecorder();
|
|
48
|
-
for (const path of ["../escape", "a/../../b"]) {
|
|
49
|
-
await assert.rejects(() => toolHandlers.container_read(resolver, { container: "default", file_path: path }, exec, fakeToolContext(resolver)), /must not escape/);
|
|
50
|
-
}
|
|
51
|
-
await assert.rejects(() => toolHandlers.container_write(resolver, { container: "default", file_path: "../escape", content: "x" }, exec, fakeToolContext(resolver)), /must not escape/);
|
|
52
|
-
assert.deepEqual(reads, [], "a refused path must not reach the guest");
|
|
53
|
-
assert.deepEqual(writes, []);
|
|
54
|
-
});
|
|
55
|
-
test("tool presenters label every tool and render terminal commands", () => {
|
|
56
|
-
for (const tool of TOOLS) {
|
|
57
|
-
assert.notEqual(toolCallView(tool.name, {}), undefined, `${tool.name} has a call view`);
|
|
58
|
-
}
|
|
59
|
-
assert.deepEqual(toolCallView("container_bash", {
|
|
60
|
-
command: "ls",
|
|
61
|
-
description: "List files",
|
|
62
|
-
}), { card: "terminal", title: "ls", description: "List files" });
|
|
63
|
-
assert.deepEqual(toolCallView("container_exec", {
|
|
64
|
-
argv: ["ls", "-la"],
|
|
65
|
-
description: "List all",
|
|
66
|
-
}), { card: "terminal", title: "ls -la", description: "List all" });
|
|
67
|
-
assert.deepEqual(toolCallView("image_list", {}), { card: "generic", title: "List images", kind: "search" });
|
|
68
|
-
assert.deepEqual(toolCallView("container_read", {}), { card: "generic", title: "Container read", kind: "read" });
|
|
69
|
-
assert.deepEqual(toolCallView("container_write", {}), { card: "generic", title: "Container write", kind: "edit" });
|
|
70
|
-
assert.deepEqual(toolCallView("container_edit", {}), { card: "generic", title: "Container edit", kind: "edit" });
|
|
71
|
-
assert.deepEqual(toolCallView("container_glob", {}), { card: "generic", title: "Container glob", kind: "search" });
|
|
72
|
-
assert.deepEqual(toolCallView("container_grep", {}), { card: "generic", title: "Container grep", kind: "search" });
|
|
73
|
-
});
|
|
74
|
-
test("tool presenters render command results as terminal output", () => {
|
|
75
|
-
const result = (value) => ({
|
|
76
|
-
content: [{ type: "text", text: JSON.stringify(value) }],
|
|
77
|
-
isError: false,
|
|
78
|
-
});
|
|
79
|
-
assert.deepEqual(toolResultView("container_bash", {}, result({ exitCode: 0, signal: null, stdout: "hi\n", stderr: "" })), { card: "terminal", output: "hi\n", exitCode: 0 });
|
|
80
|
-
assert.deepEqual(toolResultView("container_bash", {}, result({ exitCode: 0, signal: "SIGTERM", stdout: "", stderr: "" })), { card: "terminal", output: "", signal: "SIGTERM" });
|
|
81
|
-
assert.equal(toolResultView("container_bash", {}, {
|
|
82
|
-
content: [{ type: "text", text: "boom" }],
|
|
83
|
-
isError: true,
|
|
84
|
-
}), undefined);
|
|
85
|
-
assert.equal(toolResultView("image_list", {}, result({})), undefined);
|
|
86
|
-
});
|
|
87
|
-
test("command tools resolve a relative working directory", async () => {
|
|
88
|
-
const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
|
|
89
|
-
const bash = guestExecRecorder("/projects/team");
|
|
90
|
-
await toolHandlers.container_bash(bash.resolver, { container: "default", command: "ls", workdir: "sub" }, exec);
|
|
91
|
-
assert.equal(bash.starts[0].cwd, "/projects/team/sub");
|
|
92
|
-
const run = guestExecRecorder("/projects/team");
|
|
93
|
-
await toolHandlers.container_exec(run.resolver, { container: "default", argv: ["ls"], workdir: "/abs" }, exec);
|
|
94
|
-
assert.equal(run.starts[0].cwd, "/abs", "absolute working directories pass through");
|
|
95
|
-
// An unset working directory defaults to the session's (when mounted).
|
|
96
|
-
const bare = guestExecRecorder("/projects/team");
|
|
97
|
-
await toolHandlers.container_exec(bare.resolver, { container: "default", argv: ["ls"] }, exec);
|
|
98
|
-
assert.equal(bare.starts[0].cwd, "/projects/team");
|
|
99
|
-
// Commands are not confined to the projects root, so ".." is allowed.
|
|
100
|
-
const up = guestExecRecorder("/projects/team");
|
|
101
|
-
await toolHandlers.container_bash(up.resolver, { container: "default", command: "ls", workdir: "../sibling" }, exec);
|
|
102
|
-
assert.equal(up.starts[0].cwd, "/projects/sibling");
|
|
103
|
-
});
|
|
104
|
-
test("command tools pass an optional uid, gid, and groups", async () => {
|
|
105
|
-
const exec = { agent: { session: { header: { cwd: "/projects/team" } } } };
|
|
106
|
-
const bash = guestExecRecorder("/projects/team");
|
|
107
|
-
await toolHandlers.container_bash(bash.resolver, { container: "default", command: "id", uid: 1000 }, exec);
|
|
108
|
-
// The managed environment is asserted separately; this pins the identity.
|
|
109
|
-
const { env: _bashEnv, ...bashStart } = bash.starts[0];
|
|
110
|
-
assert.deepEqual(bashStart, {
|
|
111
|
-
argv: ["bash", "-c", "id"],
|
|
112
|
-
cwd: "/projects/team",
|
|
113
|
-
uid: 1000,
|
|
114
|
-
});
|
|
115
|
-
const run = guestExecRecorder("/projects/team");
|
|
116
|
-
await toolHandlers.container_exec(run.resolver, {
|
|
117
|
-
container: "default",
|
|
118
|
-
argv: ["id"],
|
|
119
|
-
uid: 1000,
|
|
120
|
-
gid: 2000,
|
|
121
|
-
groups: [3000, 4000],
|
|
122
|
-
}, exec);
|
|
123
|
-
const { env: _runEnv, ...runStart } = run.starts[0];
|
|
124
|
-
assert.deepEqual(runStart, {
|
|
125
|
-
argv: ["id"],
|
|
126
|
-
cwd: "/projects/team",
|
|
127
|
-
uid: 1000,
|
|
128
|
-
gid: 2000,
|
|
129
|
-
groups: [3000, 4000],
|
|
130
|
-
});
|
|
131
|
-
// No identity leaves the command as the container's default user.
|
|
132
|
-
const none = guestExecRecorder("/projects/team");
|
|
133
|
-
await toolHandlers.container_exec(none.resolver, { container: "default", argv: ["id"] }, exec);
|
|
134
|
-
assert.equal("uid" in none.starts[0], false);
|
|
135
|
-
assert.equal("groups" in none.starts[0], false);
|
|
136
|
-
for (const bad of [
|
|
137
|
-
{ uid: -1 },
|
|
138
|
-
{ gid: -1 },
|
|
139
|
-
{ groups: [1, -2] },
|
|
140
|
-
{ groups: "1" },
|
|
141
|
-
{ uid: 1.5 },
|
|
142
|
-
]) {
|
|
143
|
-
await assert.rejects(toolHandlers.container_exec(guestExecRecorder("/projects/team").resolver, { container: "default", argv: ["id"], ...bad }, exec));
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
test("withoutHarnessSourceSection drops only the harness checkout section", () => {
|
|
147
|
-
const assembly = {
|
|
148
|
-
sections: [
|
|
149
|
-
{ name: "harness:identity", text: "identity" },
|
|
150
|
-
{ name: HARNESS_SOURCE_SECTION, text: "checkout at /src" },
|
|
151
|
-
{ name: "deployment:persona", text: "persona" },
|
|
152
|
-
],
|
|
153
|
-
contexts: [{ name: "c", text: "t" }],
|
|
154
|
-
tools: [{ name: "t" }],
|
|
155
|
-
variables: { model: "m" },
|
|
156
|
-
};
|
|
157
|
-
const result = withoutHarnessSourceSection(assembly);
|
|
158
|
-
assert.deepEqual(result.sections.map((section) => section.name), ["harness:identity", "deployment:persona"]);
|
|
159
|
-
assert.deepEqual(result.contexts, assembly.contexts);
|
|
160
|
-
assert.deepEqual(result.tools, assembly.tools);
|
|
161
|
-
assert.deepEqual(result.variables, assembly.variables);
|
|
162
|
-
// The input assembly is not mutated.
|
|
163
|
-
assert.equal(assembly.sections.length, 3);
|
|
164
|
-
});
|
|
165
|
-
test("withoutHarnessSourceSection leaves an assembly without the section intact", () => {
|
|
166
|
-
const assembly = { sections: [{ name: "harness:identity", text: "i" }] };
|
|
167
|
-
const result = withoutHarnessSourceSection(assembly);
|
|
168
|
-
assert.deepEqual(result, assembly);
|
|
169
|
-
});
|
package/dist/mounts.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|