-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobs.test.ts
More file actions
67 lines (66 loc) · 2.16 KB
/
Copy pathjobs.test.ts
File metadata and controls
67 lines (66 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { test, expect } from "bun:test";
import { CLI } from "./cli.ts";
import { configure } from "./config.ts";
import { job } from "./jobs.ts";
function fixture() {
let destroyed = 0;
const cli = new CLI();
cli.create = async () => "job-box";
cli.ready = async () => {};
cli.script = async () => ({ code: 0, stdout: "", stderr: "", truncated: false });
cli.push = async () => {};
cli.execute = async () => ({
code: 0,
stdout: "done",
stderr: "",
truncated: false,
processId: "process",
});
cli.destroy = async () => {
destroyed++;
};
return { cli, destroyed: () => destroyed };
}
test("successful one-shot job releases its sandbox", async () => {
const fixture_ = fixture();
const result = await job(fixture_.cli, configure({}, {}), "/project", {
code: "print(1)",
lang: "py",
});
expect(result.kept).toBe(false);
expect(fixture_.destroyed()).toBe(1);
});
test("artifact retrieval failure retains output and reports sandbox ID", async () => {
const fixture_ = fixture();
fixture_.cli.script = async (_, command) => {
if (command.includes("test -f")) throw new Error("artifact missing");
return { code: 0, stdout: "", stderr: "", truncated: false };
};
await expect(
job(fixture_.cli, configure({}, {}), "/project", {
code: "print(1)",
lang: "py",
out: "output.txt",
}),
).rejects.toThrow("job-box retained");
expect(fixture_.destroyed()).toBe(0);
});
test("uncertain managed execution is retained for inspection", async () => {
const fixture_ = fixture();
fixture_.cli.execute = async () => {
throw new Error("connection lost");
};
await expect(
job(fixture_.cli, configure({}, {}), "/project", { code: "print(1)", lang: "py" }),
).rejects.toThrow("retained for recovery");
expect(fixture_.destroyed()).toBe(0);
});
test("cleanup failure is visible rather than reporting a destroyed sandbox", async () => {
const fixture_ = fixture();
fixture_.cli.destroy = async () => {
throw new Error("unreachable");
};
await expect(
job(fixture_.cli, configure({}, {}), "/project", { code: "print(1)", lang: "py" }),
).rejects.toThrow("job-box is still allocated");
});