The best way to control Claude Code, Codex and more from any computer or phone

main
ts 127 lines 5.29 KB
Raw
1 import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { assert, describe, it } from "@effect/vitest";
3 import * as HostProcess from "@t3tools/shared/HostProcess";
4 import * as Effect from "effect/Effect";
5 import * as FileSystem from "effect/FileSystem";
6 import * as Path from "effect/Path";
7 import * as Stream from "effect/Stream";
8 import { ChildProcess, ChildProcessSpawner } from "effect/process";
9
10 const run = Effect.fn("test.aur.run")(function* (
11 command: string,
12 args: ReadonlyArray<string>,
13 cwd: string,
14 env: Record<string, string | undefined>,
15 ) {
16 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
17 const child = yield* spawner.spawn(
18 ChildProcess.make(command, args, { cwd, env, extendEnv: false }),
19 );
20 const collect = <E>(stream: Stream.Stream<Uint8Array, E>) =>
21 stream.pipe(
22 Stream.decodeText(),
23 Stream.runFold(
24 () => "",
25 (left, right) => left + right,
26 ),
27 );
28 const [stdout, stderr, code] = yield* Effect.all(
29 [collect(child.stdout), collect(child.stderr), child.exitCode],
30 { concurrency: "unbounded" },
31 );
32 return { stdout, stderr, code };
33 }, Effect.scoped);
34
35 describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("AUR release", () => {
36 it.live.each([
37 { nightly: false, naming: "versioned", failure: undefined },
38 { nightly: true, naming: "versioned", failure: undefined },
39 { nightly: false, naming: "versionless", failure: undefined },
40 { nightly: true, naming: "versionless", failure: undefined },
41 { nightly: false, naming: "versioned", failure: "missing" },
42 { nightly: false, naming: "versioned", failure: "digest" },
43 { nightly: false, naming: "versioned", failure: "version" },
44 ])("updates architecture-specific sources: %j", ({ nightly, naming, failure }) =>
45 Effect.gen(function* () {
46 const fs = yield* FileSystem.FileSystem;
47 const path = yield* Path.Path;
48 const inherited = yield* HostProcess.Environment;
49 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-aur-release-" });
50 const aur = path.join(root, "packaging/aur");
51 yield* fs.copy(path.join(import.meta.dirname, "../packaging/aur"), aur);
52 const tools = path.join(root, "tools");
53 yield* fs.makeDirectory(tools);
54 for (const [name, source] of Object.entries({
55 gh: '#!/bin/bash\nif [[ "$*" == *releases/tags/* ]]; then cat "$AUR_FIXTURE_RELEASE"; else echo "fixture license"; fi\n',
56 id: "#!/bin/sh\necho 1000\n",
57 namcap: "#!/bin/sh\nexit 0\n",
58 makepkg: '#!/bin/sh\nif [ "$1" = --packagelist ]; then echo fixture.pkg.tar.zst; fi\n',
59 })) {
60 const file = path.join(tools, name);
61 yield* fs.writeFileString(file, source);
62 yield* fs.chmod(file, 0o755);
63 }
64 const version = nightly ? "1.2.4-nightly.20261104.1" : "1.2.3";
65 const pkgname = nightly ? "t3code-nightly-bin" : "t3code-bin";
66 const prefix =
67 naming === "versioned" ? `T3-Code-${version}` : nightly ? "T3-Code-Nightly" : "T3-Code";
68 const assets = [
69 { name: `${prefix}-x86_64.AppImage`, digest: `sha256:${"a".repeat(64)}` },
70 ...(failure === "missing"
71 ? []
72 : [
73 {
74 name:
75 failure === "version"
76 ? "T3-Code-1.2.2-arm64.AppImage"
77 : `${prefix}-arm64.AppImage`,
78 digest: failure === "digest" ? "invalid" : `sha256:${"b".repeat(64)}`,
79 },
80 ]),
81 ];
82 const fixture = path.join(root, "release.json");
83 yield* fs.writeFileString(fixture, JSON.stringify({ assets }));
84 const packageDir = path.join(aur, pkgname);
85 const recipe = path.join(packageDir, "PKGBUILD");
86 const before = yield* fs.readFileString(recipe);
87 const env = {
88 PATH: `${tools}:${inherited.PATH}`,
89 RELEASE_TAG: `v${version}`,
90 AUR_FIXTURE_RELEASE: fixture,
91 AUR_SSH_PRIVATE_KEY: "",
92 };
93 const result = yield* run("bash", [path.join(aur, "scripts/release.sh")], root, env);
94 if (failure) {
95 assert.notEqual(Number(result.code), 0, result.stdout + result.stderr);
96 assert.equal(yield* fs.readFileString(recipe), before);
97 return;
98 }
99 assert.equal(Number(result.code), 0, result.stdout + result.stderr);
100 for (const [arch, upstreamArch, checksum] of [
101 ["x86_64", "x86_64", "a"],
102 ["aarch64", "arm64", "b"],
103 ] as const) {
104 const selected = yield* run(
105 "bash",
106 [
107 "-c",
108 `source PKGBUILD
109 declare -n sources="source_$CARCH" sums="sha256sums_$CARCH"
110 printf '%s\\n' "$pkgver" "\${arch[*]}" "\${sources[@]}" "\${sums[@]}" "$_appimage"`,
111 ],
112 packageDir,
113 { ...env, CARCH: arch },
114 );
115 assert.equal(Number(selected.code), 0, selected.stderr);
116 const localName = `T3-Code-${version}-${upstreamArch}.AppImage`;
117 assert.deepEqual(selected.stdout.trim().split("\n"), [
118 version.replace("-nightly.", "_nightly."),
119 "x86_64 aarch64",
120 `${localName}::https://github.com/pingdotgg/t3code/releases/download/v${version}/${prefix}-${upstreamArch}.AppImage`,
121 checksum.repeat(64),
122 localName,
123 ]);
124 }
125 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
126 );
127 });