char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somcut a bunch of code volumecb11725

main
1.8 KiB43 linesraw
1import { assertEquals, assertMatch } from "@std/assert";
2import { join } from "@std/path";
3import { denoExecutable } from "./deno.ts";
4import { tempDir } from "@berry/util";
5
6Deno.test({
7  name: "subprocesses use the installed Deno before and after an atomic update",
8  ignore: Deno.build.os !== "linux",
9  async fn() {
10    await using directoryDir = await tempDir({ prefix: "berry-deno-test-" });
11    const directory = directoryDir.path;
12    const executable = join(directory, "deno");
13    const replacement = join(directory, "replacement");
14    await Deno.copyFile(denoExecutable(), executable);
15    await Deno.chmod(executable, 0o755);
16    await Deno.writeTextFile(replacement, "#!/bin/sh\nprintf 'updated deno\\n'\n");
17    await Deno.chmod(replacement, 0o755);
18
19    const { success, stdout, stderr } = await new Deno.Command(executable, {
20      args: [
21        "eval",
22        `import { denoExecutable } from ${
23          JSON.stringify(new URL("./deno.ts", import.meta.url).href)
24        };
25          const before = await new Deno.Command(denoExecutable(), { args: ["--version"] }).output();
26          await Deno.rename(${JSON.stringify(replacement)}, ${JSON.stringify(executable)});
27          const after = await new Deno.Command(denoExecutable(), { args: ["--version"] }).output();
28          console.log(JSON.stringify({
29            before: new TextDecoder().decode(before.stdout),
30            after: new TextDecoder().decode(after.stdout),
31            success: before.success && after.success,
32          }));`,
33      ],
34      stdout: "piped",
35      stderr: "piped",
36    }).output();
37    assertEquals(success, true, new TextDecoder().decode(stderr));
38    const result = JSON.parse(new TextDecoder().decode(stdout));
39    assertEquals(result.success, true);
40    assertMatch(result.before, /^deno /);
41    assertEquals(result.after, "updated deno\n");
42  },
43});