@@ -9,6 +9,90 @@ import * as NodePath from "node:path"; |
9 | 9 | import { describe, expect, it } from "vite-plus/test"; |
10 | 10 |
|
11 | 11 | describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer terminal", () => { |
| 12 | + it.each([ |
| 13 | + { channel: "stable", matchPage: 1, endPage: 1 }, |
| 14 | + { channel: "stable", matchPage: 2, endPage: 2 }, |
| 15 | + { channel: "nightly", matchPage: 2, endPage: 2 }, |
| 16 | + { channel: "preview", matchPage: 2, endPage: 2 }, |
| 17 | + { channel: "stable", matchPage: 0, endPage: 2 }, |
| 18 | + { channel: "stable", matchPage: 0, endPage: 10 }, |
| 19 | + ])( |
| 20 | + "resolves $channel releases (match page: $matchPage, last page: $endPage)", |
| 21 | + async ({ channel, matchPage, endPage }) => { |
| 22 | + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-index-")); |
| 23 | + const version = `1.2.3${channel === "stable" ? "" : `-${channel}.20261020.1`}`; |
| 24 | + const target = NodePath.join(root, "home/runtime/versions", version); |
| 25 | + const pages: number[] = []; |
| 26 | + const server = NodeHttp.createServer((request, response) => { |
| 27 | + const url = new URL(request.url ?? "/", "http://localhost"); |
| 28 | + const page = Number(url.searchParams.get("page") ?? "1"); |
| 29 | + pages.push(page); |
| 30 | + const releases = |
| 31 | + page === matchPage |
| 32 | + ? [{ tag_name: `v${version}` }] |
| 33 | + : page === endPage && endPage < 10 |
| 34 | + ? [] |
| 35 | + : Array.from({ length: 100 }, (_, index) => ({ |
| 36 | + tag_name: `v1.2.4-${channel === "nightly" ? "preview" : "nightly"}.20261020.${100 - index}`, |
| 37 | + })); |
| 38 | + response.setHeader("Content-Type", "application/json"); |
| 39 | + response.end(JSON.stringify(releases, null, 2)); |
| 40 | + }); |
| 41 | + try { |
| 42 | + // An existing completed install isolates release resolution from archive downloads. |
| 43 | + await NodeFSP.mkdir(target, { recursive: true }); |
| 44 | + await NodeFSP.writeFile(NodePath.join(target, ".install-complete"), `${version}\n`); |
| 45 | + await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve)); |
| 46 | + const address = server.address(); |
| 47 | + if (!address || typeof address === "string") throw new Error("Expected a TCP listener"); |
| 48 | + const source = await NodeFSP.readFile( |
| 49 | + NodePath.resolve(import.meta.dirname, "install.sh"), |
| 50 | + "utf8", |
| 51 | + ); |
| 52 | + const installer = NodePath.join(root, "install.sh"); |
| 53 | + // Redirect only the API host; keep the installer's real channel lookup intact. |
| 54 | + await NodeFSP.writeFile( |
| 55 | + installer, |
| 56 | + source.replace("https://api.github.com", `http://127.0.0.1:${address.port}`), |
| 57 | + ); |
| 58 | + const { code, output } = await new Promise<{ code: number | null; output: string }>( |
| 59 | + (resolve, reject) => { |
| 60 | + const child = NodeChildProcess.spawn("sh", [installer], { |
| 61 | + env: { |
| 62 | + ...process.env, |
| 63 | + T3CODE_VERSION: "", |
| 64 | + T3CODE_CHANNEL: channel, |
| 65 | + T3CODE_HOME: NodePath.join(root, "home"), |
| 66 | + T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin"), |
| 67 | + }, |
| 68 | + stdio: ["ignore", "pipe", "pipe"], |
| 69 | + }); |
| 70 | + let output = ""; |
| 71 | + child.stdout.on("data", (chunk: Buffer) => (output += chunk.toString())); |
| 72 | + child.stderr.on("data", (chunk: Buffer) => (output += chunk.toString())); |
| 73 | + child.on("error", reject); |
| 74 | + child.on("close", (code) => resolve({ code, output })); |
| 75 | + }, |
| 76 | + ); |
| 77 | + expect(pages).toEqual(Array.from({ length: endPage }, (_, index) => index + 1)); |
| 78 | + if (matchPage) { |
| 79 | + expect(code, output).toBe(0); |
| 80 | + expect(output).toContain(`Installed T3 Code ${version}`); |
| 81 | + expect(await NodeFSP.readlink(NodePath.join(root, "bin/t3"))).toBe( |
| 82 | + NodePath.join(target, "t3"), |
| 83 | + ); |
| 84 | + } else { |
| 85 | + expect(code).not.toBe(0); |
| 86 | + expect(output).toContain(`could not find a ${channel} release; set T3CODE_VERSION`); |
| 87 | + } |
| 88 | + } finally { |
| 89 | + server.closeAllConnections(); |
| 90 | + await new Promise<void>((resolve) => server.close(() => resolve())); |
| 91 | + await NodeFSP.rm(root, { recursive: true, force: true }); |
| 92 | + } |
| 93 | + }, |
| 94 | + ); |
| 95 | + |
12 | 96 | it.each([false, true])( |
13 | 97 | "preserves download and install behavior (HTTP failure: %s)", |
14 | 98 | async (fail) => { |
|