Skip to content

Commit 85a7ee0

Browse files
t3dotggclaude
andcommitted
test(install): keep one installer pagination case
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5496120 commit 85a7ee0

1 file changed

Lines changed: 58 additions & 81 deletions

File tree

‎scripts/install.test.ts‎

Lines changed: 58 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -8,85 +8,62 @@ import * as NodePath from "node:path";
88
import { describe, expect, it } from "vite-plus/test";
99

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

0 commit comments

Comments
 (0)