From ddf2307c4c31d9c515241625b7feab758e755e9a Mon Sep 17 00:00:00 2001 From: cliffhall Date: Thu, 3 Sep 2026 22:20:15 -0400 Subject: [PATCH] test(scripts): stop the repo-guard test depending on the ambient env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `main refuses to run without a repo` called `main(undefined, …)` so the default parameter would fire, then asserted it throws. The default reads `process.env.GITHUB_REPOSITORY` — which GitHub Actions sets on every run — so the assertion held only where the variable happened to be unset. It passed locally and failed CI, the one environment where the default is always populated. The test now clears the variable and restores it, and a second test covers the other half of the default: with it set, `main(undefined, …)` uses it instead of throwing. Between them the default's behavior is pinned in both environments rather than inherited from whichever one is running. Verified both ways: 14 pass with the variable unset and with it set, and the full `test:scripts` suite is 411/411 under the CI environment shape. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01RWMJENjs1mExXE5XPJTEei Signed-off-by: cliffhall --- scripts/dependency-refresh.test.mjs | 38 ++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/scripts/dependency-refresh.test.mjs b/scripts/dependency-refresh.test.mjs index d0b94ad8..f180b863 100644 --- a/scripts/dependency-refresh.test.mjs +++ b/scripts/dependency-refresh.test.mjs @@ -228,5 +228,41 @@ test("main says Incoming, not Todo, when it files without a milestone", () => { }); test("main refuses to run without a repo", () => { - assert.throws(() => main(undefined, fakeSpawn()), /GITHUB_REPOSITORY unset/); + // `main`'s default reads process.env.GITHUB_REPOSITORY, which GitHub Actions + // sets on every run — so this has to clear the variable rather than assume + // the ambient environment lacks it. Relying on the ambient value passed + // locally and failed in CI, which is the one place the default is always + // populated. + const saved = process.env.GITHUB_REPOSITORY; + delete process.env.GITHUB_REPOSITORY; + try { + assert.throws( + () => main(undefined, fakeSpawn()), + /GITHUB_REPOSITORY unset/, + ); + } finally { + if (saved !== undefined) process.env.GITHUB_REPOSITORY = saved; + } +}); + +test("main falls back to GITHUB_REPOSITORY when no repo is passed", () => { + // The other half of the default: with the variable set, `main(undefined, …)` + // must use it rather than throw. Together the two tests pin the default's + // behavior in both environments instead of inheriting whichever one happens + // to be running. + const saved = process.env.GITHUB_REPOSITORY; + process.env.GITHUB_REPOSITORY = "env/repo"; + try { + const spawn = fakeSpawn({ + outdated: { + ".": { ajv: { current: "8.0.0", wanted: "8.1.0", latest: "8.1.0" } }, + }, + }); + captureLog(() => main(undefined, spawn)); + const create = ghCall(spawn, "create"); + assert.equal(create.args[create.args.indexOf("--repo") + 1], "env/repo"); + } finally { + if (saved === undefined) delete process.env.GITHUB_REPOSITORY; + else process.env.GITHUB_REPOSITORY = saved; + } });