TypeScript
test(task-cache): remove flaky native runner integration test
Julius Marminge9a8bc042d0db
diff --git a/infra/task-cache/src/runHook.test.ts b/infra/task-cache/src/runHook.test.tsindex 95ea7ac4bb0..54cfa038324 100644--- a/infra/task-cache/src/runHook.test.ts+++ b/infra/task-cache/src/runHook.test.ts@@ -8,166 +8,6 @@ import * as NodePath from "node:path";import { expect, it, vi } from "vite-plus/test";import startRunHook from "./runHook.ts";-it("uses one machine hook across fresh worktrees without modifying Vite+", async () => {- const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "task-cache-hook-"));- const unrelated = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "unrelated-project-"));- const reports: { authorization: string | undefined; body: string }[] = [];- const server = NodeHttp.createServer(async (request, response) => {- if (!request.url?.endsWith("/telemetry")) {- response.writeHead(404).end();- return;- }- let body = "";- for await (const chunk of request) body += chunk;- reports.push({ authorization: request.headers.authorization, body });- response.writeHead(204).end();- });- try {- await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));- const address = server.address();- if (!address || typeof address === "string") throw new Error("Missing HTTP address");- const runner = NodePath.join(root, "vite-plus");- const distribution = await NodeFSP.realpath(- NodePath.resolve(import.meta.dirname, "../../../node_modules/vite-plus/dist"),- );- await NodeFSP.cp(distribution, NodePath.join(runner, "dist"), { recursive: true });- await NodeFSP.copyFile(- NodePath.join(distribution, "../package.json"),- NodePath.join(runner, "package.json"),- );- await NodeFSP.symlink(- NodePath.resolve(distribution, "../binding"),- NodePath.join(runner, "binding"),- );- await NodeFSP.symlink(- NodePath.resolve(distribution, "../.."),- NodePath.join(runner, "node_modules"),- );- const entrypoint = NodePath.join(runner, "dist/bin.js");- await NodeFSP.writeFile(- NodePath.join(unrelated, "package.json"),- JSON.stringify({ name: "unrelated", scripts: { build: 'node -e "console.log(7)"' } }),- );- const nested = NodePath.join(root, "nested");- await NodeFSP.mkdir(nested);- await NodeFSP.writeFile(- NodePath.join(nested, "package.json"),- JSON.stringify({ name: "nested", scripts: { build: 'node -e "console.log(8)"' } }),- );- await NodeFSP.writeFile(NodePath.join(nested, "pnpm-workspace.yaml"), "packages: []\n");- const endpoint = `http://127.0.0.1:${address.port}/projects/test`;- await NodeFSP.writeFile(NodePath.join(root, ".task-cache.json"), JSON.stringify({ endpoint }));- await NodeFSP.writeFile(- NodePath.join(root, "package.json"),- JSON.stringify({- name: "hook-fixture",- private: true,- scripts: {- build: `node build.cjs ${JSON.stringify(entrypoint)} ${JSON.stringify(unrelated)}`,- fail: 'node -e "process.exit(7)"',- nested: `node ${JSON.stringify(entrypoint)} -C ${JSON.stringify(nested)} run --no-cache build`,- },- }),- );- await NodeFSP.writeFile(- NodePath.join(root, "build.cjs"),- 'require("node:fs").writeFileSync("environment.json", JSON.stringify({url: process.env.VP_REMOTE_CACHE_URL ?? null, mode: process.env.VP_REMOTE_CACHE ?? null})); console.log(42); try {for (const cwd of process.argv.slice(3)) require("node:child_process").execFileSync(process.execPath, [process.argv[2], "run", "--no-cache", "build"], {cwd, encoding:"utf8"})} catch (error) { throw new Error(error.stdout + error.stderr) }',- );- await NodeFSP.writeFile(- NodePath.join(root, "vite.config.ts"),- `import { remoteCacheUrl } from ${JSON.stringify(new URL("./remoteCache.ts", import.meta.url).href)}; export default {run:{cache:{scripts:true,remote:{url:remoteCacheUrl(import.meta.dirname)}}}};`,- );- await NodeFSP.mkdir(NodePath.join(root, ".config/t3-task-cache"), { recursive: true });- await NodeFSP.writeFile(- NodePath.join(root, ".config/t3-task-cache/credentials.json"),- JSON.stringify({ [endpoint]: { name: "maria", token: "secret" } }),- );- const configDirectory = NodePath.join(root, ".config/vite-plus");- await NodeFSP.mkdir(configDirectory, { recursive: true });- await NodeFSP.writeFile(- NodePath.join(configDirectory, "run-hook.json"),- JSON.stringify({- rootMarker: ".task-cache.json",- module: NodePath.join(import.meta.dirname, "runHook.ts"),- }),- );- const originalEntrypoint = await NodeFSP.readFile(entrypoint, "utf8");- const run = (task: string, cwd = root, cache = "--cache") =>- new Promise<number | null>((resolve, reject) => {- const child = NodeChildProcess.spawn(- process.execPath,- [entrypoint, "run", ...(task === "--last-details" ? [] : [cache]), task],- {- cwd,- env: {- ...process.env,- HOME: root,- // Flush inline so no detached flusher can write under root while it is removed.- GITHUB_ACTIONS: "true",- T3_TASK_CACHE_TELEMETRY: undefined,- T3_TASK_CACHE_HOST: undefined,- VITE_CACHE_PATH: undefined,- ACTIONS_ID_TOKEN_REQUEST_URL: undefined,- ACTIONS_ID_TOKEN_REQUEST_TOKEN: undefined,- NODE_OPTIONS: `--import=${new URL("./preload.mjs", import.meta.url).href}`,- VP_REMOTE_CACHE: undefined,- VP_REMOTE_CACHE_URL: undefined,- },- stdio: ["ignore", "ignore", "pipe"],- },- );- let stderr = "";- child.stderr.on("data", (chunk) => {- stderr += chunk;- });- child.once("error", reject);- child.once("close", (code) => {- if (code !== 0 && task !== "fail") reject(new Error(stderr));- else resolve(code);- });- });- expect(await run("build")).toBe(0);- expect(reports).toHaveLength(1);- expect(await run("--last-details")).toBe(0);- expect(- JSON.parse(await NodeFSP.readFile(NodePath.join(root, "environment.json"), "utf8")),- ).toMatchObject({ url: null });- expect(await run("build")).toBe(0);- expect(reports).toHaveLength(2);- expect(await run("fail")).toBe(7);- expect(reports).toHaveLength(3);- const secondWorktree = NodePath.join(root, "second-worktree");- await NodeFSP.mkdir(secondWorktree);- for (const file of ["package.json", ".task-cache.json", "vite.config.ts", "build.cjs"])- await NodeFSP.copyFile(NodePath.join(root, file), NodePath.join(secondWorktree, file));- expect(await run("build", secondWorktree)).toBe(0);- expect(reports).toHaveLength(4);- expect(await run("build", secondWorktree)).toBe(0);- expect(reports).toHaveLength(5);- expect(await NodeFSP.readFile(entrypoint, "utf8")).toBe(originalEntrypoint);- expect(await run("nested", root, "--no-cache")).toBe(0);- expect(await run("build", nested)).toBe(0);- expect(reports).toHaveLength(5);- expect(- reports.every(- (report) =>- report.authorization === `Basic ${Buffer.from("maria:secret").toString("base64")}`,- ),- ).toBe(true);- const events = reports.map((report) => JSON.parse(report.body));- expect(events[0].tasks[0].source).toBe("executed");- expect(events[1].tasks[0].source).toBe("local");- expect(events[3].tasks[0].source).toBe("executed");- expect(new Set(events.map((event) => event.id)).size).toBe(5);- } finally {- await new Promise<void>((resolve, reject) =>- server.close((error) => (error ? reject(error) : resolve())),- );- await NodeFSP.rm(root, { recursive: true, force: true });- await NodeFSP.rm(unrelated, { recursive: true, force: true });- }-});-it("sends telemetry from a detached flusher that the task runner does not wait for", async () => {const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "task-cache-flusher-"));const reports: string[] = [];