test(quality): complementary gate and TIA cases for path-literal edges (#16068) (#16265)

Follow-up to #16129: test-only delta covering the artifact-edge finding shape, an unpinned artifact producing no output, an impact map predating the artifacts key, and hub precedence over path-literal hits in TIA.

Refs #16068
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-10-13 07:43:16 -03:00
committed by GitHub
parent 7f3cbb046b
commit 4833845bda
2 changed files with 156 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
// Direct path-literal edges in the forgotten-sibling gate (#16068): a changed workflow / root
// config has no import "consumer" — the pinning test reads the file itself. The gate treats
// `impactMap.artifacts[changedFile]` as a direct edge with the same diff/masking/allowlist
// semantics as the import edges. Incident that motivated this: a quality.yml edit broke the
// `#7307` guard in tests/unit/build/check-workflows.test.ts and the gate stayed silent.
//
// Complements tests/unit/path-literal-edges.test.ts with the edge cases it does not pin:
// exact finding shape, an unpinned artifact producing no output at all, and an impact map
// predating the `artifacts` key.
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test, { after } from "node:test";
import { analyzeForgottenSiblingTests } from "../../scripts/check/check-forgotten-sibling-tests.mjs";
const fixtureRoots: string[] = [];
after(() => {
for (const root of fixtureRoots) fs.rmSync(root, { recursive: true, force: true });
});
function fixture(files: Record<string, string>) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "forgotten-sibling-literal-"));
fixtureRoots.push(root);
for (const [file, contents] of Object.entries(files)) {
const absolute = path.join(root, file);
fs.mkdirSync(path.dirname(absolute), { recursive: true });
fs.writeFileSync(absolute, contents);
}
return root;
}
const WORKFLOW = ".github/workflows/sibling-fixture.yml";
const GUARD = "tests/unit/build/check-workflows.test.ts";
const impactMap = { sources: {}, artifacts: { [WORKFLOW]: [GUARD] } };
function run(changedEntries: { status: string; file: string }[], extra = {}) {
const root = fixture({ [WORKFLOW]: "name: q\n", [GUARD]: "" });
return analyzeForgottenSiblingTests({ root, changedEntries, impactMap, allowlist: [], ...extra });
}
test("a changed workflow whose pinning test is absent from the diff is a finding", () => {
const result = run([{ status: "M", file: WORKFLOW }]);
assert.deepEqual(result.findings, [
{
changedModule: WORKFLOW,
changedSymbols: [],
consumer: WORKFLOW,
candidateTest: GUARD,
reason: "candidate sibling test is absent from the PR diff",
},
]);
assert.equal(result.diagnostics.length, 0);
});
test("updating the pinning test alongside the workflow clears the finding", () => {
const result = run([
{ status: "M", file: WORKFLOW },
{ status: "M", file: GUARD },
]);
assert.deepEqual(result.findings, []);
assert.deepEqual(result.maskingRisks, []);
});
test("deleting the pinning test is a masking risk, not a clean pass", () => {
const result = run([
{ status: "M", file: WORKFLOW },
{ status: "D", file: GUARD },
]);
assert.deepEqual(result.findings, []);
assert.equal(result.maskingRisks.length, 1);
assert.equal(result.maskingRisks[0].candidateTest, GUARD);
assert.equal(result.maskingRisks[0].reason, "candidate sibling test was deleted");
});
test("an allowlist entry suppresses a path-literal finding like any other", () => {
const root = fixture({ [WORKFLOW]: "name: q\n", [GUARD]: "" });
const result = analyzeForgottenSiblingTests({
root,
changedEntries: [{ status: "M", file: WORKFLOW }],
impactMap,
allowlist: [
{
consumer: WORKFLOW,
candidateTest: GUARD,
rationale: "guard is regenerated by a separate job, reviewed in #1",
reference: "#1",
},
],
});
assert.deepEqual(result.findings, []);
assert.equal(result.suppressed.length, 1);
});
test("a changed artifact nobody pins produces nothing (no false RUN_ALL-style noise)", () => {
const result = run([{ status: "M", file: ".github/workflows/sibling-other.yml" }]);
assert.deepEqual(result.findings, []);
assert.deepEqual(result.diagnostics, []);
});
test("an old impact map without `artifacts` still works (backward compatible)", () => {
const root = fixture({ [WORKFLOW]: "name: q\n", [GUARD]: "" });
const result = analyzeForgottenSiblingTests({
root,
changedEntries: [{ status: "M", file: WORKFLOW }],
impactMap: { sources: {} },
allowlist: [],
});
assert.deepEqual(result.findings, []);
});

View File

@@ -0,0 +1,44 @@
// TIA: a changed non-source artifact (workflow, root config) selects the tests that pin it
// by path literal — additively. It must NEVER force __RUN_ALL__ (an unpinned artifact is
// not an "unmapped source"), and hub files keep their existing RUN_ALL semantics.
import test from "node:test";
import assert from "node:assert/strict";
import { selectImpacted } from "../../scripts/quality/select-impacted-tests.mjs";
const map = {
sources: { "src/lib/a.ts": ["tests/unit/a.test.ts"] },
artifacts: {
".github/workflows/sibling-fixture.yml": ["tests/unit/build/check-workflows.test.ts"],
},
};
test("changed pinned artifact → its pinning test(s)", () => {
assert.deepEqual(selectImpacted({ changed: [".github/workflows/sibling-fixture.yml"], map }), [
"tests/unit/build/check-workflows.test.ts",
]);
});
test("changed unpinned artifact → nothing (never __RUN_ALL__)", () => {
assert.deepEqual(selectImpacted({ changed: [".github/workflows/sibling-other.yml"], map }), []);
});
test("artifact + source changes merge additively", () => {
assert.deepEqual(
selectImpacted({ changed: [".github/workflows/sibling-fixture.yml", "src/lib/a.ts"], map }),
["tests/unit/a.test.ts", "tests/unit/build/check-workflows.test.ts"]
);
});
test("hub artifacts keep RUN_ALL precedence over path-literal hits", () => {
const hubMap = { ...map, artifacts: { "package.json": ["tests/unit/x.test.ts"] } };
assert.deepEqual(selectImpacted({ changed: ["package.json"], map: hubMap }), ["__RUN_ALL__"]);
});
test("map without `artifacts` is tolerated", () => {
assert.deepEqual(
selectImpacted({ changed: [".github/workflows/sibling-fixture.yml"], map: { sources: {} } }),
[]
);
});