Skip to content

Write HTML. Render video. Built for agents.

test(studio): the edit accuracy bench starts one server when node is a Volta shim (#5779)

Miguel Ángelc71513997694
diff --git a/packages/studio/tests/e2e/edit-accuracy/case.mjs b/packages/studio/tests/e2e/edit-accuracy/case.mjs
index c92562dba6..9e66cf8edb 100644
--- a/packages/studio/tests/e2e/edit-accuracy/case.mjs
+++ b/packages/studio/tests/e2e/edit-accuracy/case.mjs
@@ -1,5 +1,5 @@
/** Drives one edit accuracy case in the built Studio and measures it. All distances are composition px. */
-import { spawn } from "node:child_process";
+import { execFileSync, spawn } from "node:child_process";
import { classifyTweenPropertyGroup } from "../../../../parsers/src/gsapConstants.ts";
import { parseGsapScript } from "../../../../parsers/src/gsapParser.ts";
import { readFileSync, statSync } from "node:fs";
@@ -62,11 +62,15 @@ export function killServers() {
const announcedPort = (log) => /http:\/\/localhost:(\d+)/.exec(log.join(""))?.[1];
+/** The real node binary: a version manager's shim (Volta) finds node through HOME, which the server's env replaces. */
+const nodeBinary = () =>
+ execFileSync("node", ["-p", "process.execPath"], { encoding: "utf8" }).trim();
+
/** Starts Studio at `port` or, when that is busy, the next free one the CLI binds; returns the port it serves. */
// fallow-ignore-next-line complexity
export async function startServer(cli, dir, port, log, home) {
const child = spawn(
- "node",
+ nodeBinary(),
[cli, "preview", dir, "--port", String(port), "--no-open", "--foreground", "--force-new"],
{
stdio: ["ignore", "pipe", "pipe"],
diff --git a/packages/studio/tests/e2e/edit-accuracy/server.test.mjs b/packages/studio/tests/e2e/edit-accuracy/server.test.mjs
index daa9e7b805..e05554a33c 100644
--- a/packages/studio/tests/e2e/edit-accuracy/server.test.mjs
+++ b/packages/studio/tests/e2e/edit-accuracy/server.test.mjs
@@ -1,6 +1,6 @@
-import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
-import { tmpdir } from "node:os";
-import { join } from "node:path";
+import { chmodSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { homedir, tmpdir } from "node:os";
+import { delimiter, join } from "node:path";
import { describe, expect, it } from "vitest";
import { startServer, stopServer } from "./case.mjs";
@@ -25,4 +25,37 @@ describe("starting the bench's Studio server", () => {
rmSync(root, { recursive: true, force: true });
}
});
+
+ it.skipIf(process.platform === "win32")(
+ "runs one server under the case's HOME when PATH's node is a HOME-keyed shim",
+ async () => {
+ const root = mkdtempSync(join(tmpdir(), "hf-bench-server-"));
+ const shims = join(root, "shims");
+ mkdirSync(shims);
+ const shim = join(shims, "node");
+ writeFileSync(
+ shim,
+ `#!/bin/sh\n[ "$HOME" = "${homedir()}" ] || { echo "shim: no node under HOME=$HOME" >&2; exit 126; }\nexec "${process.execPath}" "$@"\n`,
+ );
+ chmodSync(shim, 0o755);
+ const cli = join(root, "cli.cjs");
+ const starts = join(root, "starts");
+ writeFileSync(
+ cli,
+ `require("node:fs").appendFileSync(${JSON.stringify(starts)}, process.env.HOME + "\\n");\n${FAKE_CLI}`,
+ );
+ const caseHome = join(root, "home");
+ const path = process.env.PATH;
+ process.env.PATH = `${shims}${delimiter}${path}`;
+ let child;
+ try {
+ ({ child } = await startServer(cli, root, 1, [], caseHome));
+ expect(readFileSync(starts, "utf8").trim().split("\n")).toEqual([caseHome]);
+ } finally {
+ process.env.PATH = path;
+ if (child) await stopServer(child);
+ rmSync(root, { recursive: true, force: true });
+ }
+ },
+ );
});