@devries-cameron20 / t3code Mirror · read-only / commits / ac49a626c2
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 09:30 UTC

fix(install): verify archives in homes with backslashes or newlines (#25240)

Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>

maria committed Oct 31, 2026 at 08:45 UTC ac49a626c2cf0f47ac80fa26a32b049fa376d8ec
2 files changed +119 -2
scripts/install.sh
+2 -2
@@ -138,9 +138,9 @@ if [ "${platform}-${arch}" = darwin-x64 ]; then
138 fi
139 command -v tar >/dev/null 2>&1 || fail "tar is required"
140 if command -v sha256sum >/dev/null 2>&1; then
141 - checksum() { sha256sum "$1" | cut -d' ' -f1; }
141 + checksum() { sha256sum < "$1" | cut -d' ' -f1; }
142 elif command -v shasum >/dev/null 2>&1; then
143 - checksum() { shasum -a 256 "$1" | cut -d' ' -f1; }
143 + checksum() { shasum -a 256 < "$1" | cut -d' ' -f1; }
144 else
145 fail "sha256sum or shasum is required"
146 fi
scripts/install.test.ts
+117
@@ -1,6 +1,7 @@
1 // @effect-diagnostics nodeBuiltinImport:off - Drives the real shell installer against a local GitHub fixture.
2 import * as HostProcess from "@t3tools/shared/HostProcess";
3 import * as NodeChildProcess from "node:child_process";
4 +import * as NodeCrypto from "node:crypto";
5 import * as NodeFSP from "node:fs/promises";
6 import * as NodeHttp from "node:http";
7 import * as NodeOS from "node:os";
@@ -78,3 +79,119 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer chan
79 }
80 });
81 });
82 +
83 +describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer checksum", () => {
84 + it.each(
85 + ["home\\data", "home\ndata"].flatMap((homeName) =>
86 + [true, false].map((validChecksum) => ({ homeName, validChecksum })),
87 + ),
88 + )(
89 + "verifies home $homeName with valid checksum $validChecksum",
90 + async ({ homeName, validChecksum }) => {
91 + const availableTools = ["sha256sum", "shasum"].filter(
92 + (tool) =>
93 + NodeChildProcess.spawnSync("sh", ["-c", 'command -v "$1"', "sh", tool]).status === 0,
94 + );
95 + expect(availableTools.length).toBeGreaterThan(0);
96 + for (const checksumTool of availableTools) {
97 + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-checksum-"));
98 + const home = NodePath.join(root, homeName);
99 + const version = "1.2.3";
100 + const stem = `t3-${version}-linux-${HostProcess.Architecture.defaultValue()}`;
101 + const archiveName = `${stem}.tar.gz`;
102 + const server = NodeHttp.createServer();
103 + try {
104 + const tools = NodePath.join(root, "tools");
105 + await NodeFSP.mkdir(tools);
106 + for (const command of [
107 + "sh",
108 + "uname",
109 + "tar",
110 + "gzip",
111 + "cut",
112 + "curl",
113 + "grep",
114 + "mkdir",
115 + "mktemp",
116 + "rm",
117 + "mv",
118 + "ln",
119 + checksumTool,
120 + ]) {
121 + const executable = NodeChildProcess.execFileSync(
122 + "sh",
123 + ["-c", 'command -v "$1"', "sh", command],
124 + { encoding: "utf8" },
125 + ).trim();
126 + await NodeFSP.symlink(executable, NodePath.join(tools, command));
127 + }
128 + await NodeFSP.mkdir(NodePath.join(root, stem));
129 + await NodeFSP.writeFile(
130 + NodePath.join(root, stem, "t3"),
131 + "#!/bin/sh\necho 't3 v1.2.3'\n",
132 + { mode: 0o755 },
133 + );
134 + const archivePath = NodePath.join(root, archiveName);
135 + NodeChildProcess.execFileSync("tar", ["-czf", archivePath, "-C", root, stem]);
136 + const archive = await NodeFSP.readFile(archivePath);
137 + const digest = NodeCrypto.createHash("sha256").update(archive).digest("hex");
138 + server.on("request", (request, response) => {
139 + response.end(
140 + request.url?.endsWith("/SHA256SUMS")
141 + ? `${validChecksum ? digest : "0".repeat(64)} ${archiveName}\n`
142 + : archive,
143 + );
144 + });
145 + await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
146 + const address = server.address();
147 + if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
148 + const { code, output } = await new Promise<{ code: number | null; output: string }>(
149 + (resolve, reject) => {
150 + const child = NodeChildProcess.spawn(
151 + "sh",
152 + [NodePath.resolve(import.meta.dirname, "install.sh")],
153 + {
154 + env: {
155 + ...process.env,
156 + PATH: tools,
157 + T3CODE_VERSION: version,
158 + T3CODE_HOME: home,
159 + T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin"),
160 + T3CODE_RELEASE_BASE_URL: `http://127.0.0.1:${address.port}`,
161 + },
162 + stdio: ["ignore", "pipe", "pipe"],
163 + },
164 + );
165 + let output = "";
166 + child.stdout.on("data", (chunk: Buffer) => (output += chunk.toString()));
167 + child.stderr.on("data", (chunk: Buffer) => (output += chunk.toString()));
168 + child.on("error", reject);
169 + child.on("close", (code) => resolve({ code, output }));
170 + },
171 + );
172 + const versions = NodePath.join(home, "runtime/versions");
173 + if (validChecksum) {
174 + expect(code, `${checksumTool}: ${output}`).toBe(0);
175 + expect(
176 + await NodeFSP.readFile(NodePath.join(versions, version, ".install-complete"), "utf8"),
177 + ).toBe("1.2.3\n");
178 + expect(
179 + NodeChildProcess.execFileSync(NodePath.join(root, "bin/t3"), ["--version"], {
180 + encoding: "utf8",
181 + }).trim(),
182 + ).toBe("t3 v1.2.3");
183 + } else {
184 + expect(code).not.toBe(0);
185 + expect(output).toContain("checksum mismatch");
186 + expect(output).not.toContain("Installed T3 Code");
187 + expect(await NodeFSP.readdir(versions)).toEqual([]);
188 + }
189 + } finally {
190 + server.closeAllConnections();
191 + await new Promise<void>((resolve) => server.close(() => resolve()));
192 + await NodeFSP.rm(root, { recursive: true, force: true });
193 + }
194 + }
195 + },
196 + );
197 +});