import { ok } from "node:assert/strict"; import { execFileSync } from "node:child_process"; import fs from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { expect, it } from "@jest/globals"; import { getArch } from "../../src/utils/platforms"; const bundle = fileURLToPath( new URL("../../dist/setup/index.cjs", import.meta.url), ); it.each([ { fromConfig: true, version: "0.13.4", warns: true }, { fromConfig: false, version: "0.13.5-rc.1", warns: true }, { fromConfig: false, version: "0.13.5", warns: false }, { fromConfig: false, version: "0.13.10", warns: false }, ])( "sets up uv $version with eMudhra warning: $warns", ({ version, fromConfig, warns }) => { const arch = getArch(); ok(arch); const dir = fs.mkdtempSync(path.join(tmpdir(), "setup-uv-emudhra-")); try { const toolCache = path.join(dir, "cache"); const cachedUv = path.join(toolCache, "uv", version, arch); fs.mkdirSync(cachedUv, { recursive: true }); fs.writeFileSync(`${cachedUv}.complete`, ""); if (fromConfig) { fs.writeFileSync( path.join(dir, "uv.toml"), `required-version = "==${version}"\n`, ); } const outputFile = path.join(dir, "output"); fs.writeFileSync(outputFile, ""); const stdout = execFileSync(process.execPath, [bundle], { encoding: "utf8", env: { GITHUB_OUTPUT: outputFile, "INPUT_ACTIVATE-ENVIRONMENT": "false", // Keep the test offline even if the tool-cache lookup misses. "INPUT_MANIFEST-FILE": "data:application/x-ndjson,", "INPUT_NO-PROJECT": "false", // Skip Python discovery so the action never executes the cached uv. "INPUT_PYTHON-VERSION": "3.13", INPUT_QUIET: "true", "INPUT_REQUIRE-CHECKSUMS": "false", INPUT_VERSION: fromConfig ? "" : version, "INPUT_WORKING-DIRECTORY": dir, PATH: process.env.PATH, RUNNER_TEMP: dir, RUNNER_TOOL_CACHE: toolCache, SystemRoot: process.env.SystemRoot, UV_NO_MODIFY_PATH: "1", UV_PYTHON_INSTALL_DIR: path.join(dir, "python"), }, timeout: 10_000, }); const warnings = stdout .split(/\r?\n/) .filter( (line) => line.startsWith("::warning::") && line.includes("eMudhra"), ); expect(warnings).toEqual( warns ? [ `::warning::uv ${version} predates the fix that blocks the compromised eMudhra intermediate keys. Upgrade to uv 0.13.5 or later.`, ] : [], ); const outputs = fs.readFileSync(outputFile, "utf8"); expect(outputs.match(/^uv-version<<[^\r\n]+\r?\n([^\r\n]+)/m)?.[1]).toBe( version, ); } finally { fs.rmSync(dir, { force: true, recursive: true }); } }, );