From b83fe6f7dc45c07f3bc573187e06cabdbdcd4502 Mon Sep 17 00:00:00 2001 From: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com> Date: Wed, 15 Jul 2026 23:49:09 -0300 Subject: [PATCH] =?UTF-8?q?test(ci):=20make=20#6634=20selfref=20guard=20he?= =?UTF-8?q?rmetic=20=E2=80=94=20read=20file=20from=20disk,=20no=20git=20re?= =?UTF-8?q?f=20(#7327)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit check-test-masking-selfref-6634.test.ts did git I/O inside a unit test (`git show origin/main:`), the single most common red across today's babysit sweep — GitHub-hosted runners use shallow/single-ref checkouts with no origin/main, so the show fails with "fatal: invalid object name". The prior hotfix (2e42b8efc, #7174) wrapped it in try/catch + on-demand fetch + t.skip() on failure, but t.skip() itself trips the PR Test Policy weakened-assert gate (confirmed today on #7300), and origin/main was the wrong ref anyway — PRs target release/v3.8.49, not main. Ported the hermetic version proven on PR #7300 (@growab): read the real current source of check-test-masking.test.ts from disk instead of diffing against a git ref, and use an empty-string base (baseTaut/baseExtTaut = 0) instead of the pre-#6404 git snapshot — this maximizes headTaut - baseTaut, the strictest input for the exclusion under test, so the guard is exercised at least as hard as before. No git ref, no skip, no CI-shape dependency. Verified both directions locally: - SELF_TEST_FIXTURE_RE neutralized in check-test-masking.mjs -> test FAILS (10 new bare tautologies + 28 new extended tautologies reported) - restored -> test PASSES, and the full check-test-masking.test.ts suite (55 tests) stays green, confirming the #6634 self-referential-fixture regression this guard exists for is still covered. Co-authored-by: growab --- .../check-test-masking-selfref-6634.test.ts | 38 +++++++------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/unit/check-test-masking-selfref-6634.test.ts b/tests/unit/check-test-masking-selfref-6634.test.ts index 97171e07ba..b233a008f2 100644 --- a/tests/unit/check-test-masking-selfref-6634.test.ts +++ b/tests/unit/check-test-masking-selfref-6634.test.ts @@ -14,12 +14,14 @@ * (`if (file.endsWith("check-test-masking.test.ts")) continue;` in * scripts/check/check-test-masking.mjs) for precisely this reason — this test * asserts evaluateMasking() now applies the same exclusion for its diff-based - * tautology counters, using the real base(origin/main)/head(HEAD) diff of + * tautology counters, against the REAL current source of * tests/unit/check-test-masking.test.ts. */ import test from "node:test"; import assert from "node:assert/strict"; -import { execFileSync } from "node:child_process"; +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; import { countTautologies, @@ -28,29 +30,17 @@ import { } from "../../scripts/check/check-test-masking.mjs"; const FILE = "tests/unit/check-test-masking.test.ts"; +const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); -function git(args: string[]): string { - return execFileSync("git", args, { encoding: "utf8" }); -} - -test("#6634: check-test-masking.test.ts's own tautology fixtures must not self-flag as weakening", (t) => { - // origin/main predates the #6404 fixtures (countBareTautologies/scanBareTautologies - // tests) that legitimately embed tautology-pattern literals as string fixtures. - // Shallow/single-ref checkouts (GitHub-hosted runners) have no origin/main — - // fetch it on demand; skip (never fail) when the ref is unreachable offline. - let baseSrc: string; - try { - baseSrc = git(["show", "origin/main:" + FILE]); - } catch { - try { - git(["fetch", "--depth=1", "origin", "main"]); - baseSrc = git(["show", "origin/main:" + FILE]); - } catch { - t.skip("origin/main unavailable (shallow checkout, offline) — nothing to compare against"); - return; - } - } - const headSrc = git(["show", "HEAD:" + FILE]); +test("#6634: check-test-masking.test.ts's own tautology fixtures must not self-flag as weakening", () => { + // Read the REAL current source from disk rather than a git ref: the Unit Tests + // job checks out a shallow/single-ref tree with no origin/main, so `git show + // origin/main:` failed the shard before it ever exercised the masking + // behavior under test. An empty base models the file's pre-#6404 state (no + // fixtures), which maximizes headTaut - baseTaut — the strictest input for the + // exclusion this test asserts. + const baseSrc = ""; + const headSrc = fs.readFileSync(path.join(REPO_ROOT, FILE), "utf8"); const perFile = [ {