Repository navigation
🤖 feat: mutation gate (make mutate-check, Quality / Mutation) on unclebob/mutator #7148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9604313
feat: mutation gate (make mutate-check, Quality / Mutation) on uncleb…
ThomasK33 7971f19
fix: mutation runner review fixes (baseline worker queue, deadline, C…
ThomasK33 93f248f
fix: one crashing mutant costs one error row, not the mutation report
ThomasK33 83d6601
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 1011048
fix: mutation gate review round 1 (no-coverage fallback, capped tests…
ThomasK33 2579f4d
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 b575414
fix: mutation gate review round 2 (parsed imports, no-coverage tests,…
ThomasK33 dc94cbe
fix: mutation gate review round 3 (POSIX only, error rows in the CI s…
ThomasK33 991dfe6
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 5f4e8d9
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 72be907
fix: a retired mutation worker leaves the remaining sites to healthy …
ThomasK33 c5c0621
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 6998e5d
fix: the mutation import graph reads every tsconfig alias and Bun ?qu…
ThomasK33 31bc4f7
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 e3f7626
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 132597a
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 3273eb5
Merge branch 'gauntlet/dry-gate' into gauntlet/mutation-gate
ThomasK33 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // End-to-end tests of `scripts/mutate/check.ts` in throwaway git repos, with | ||
| // real `bun test` processes. They need uv (the runner goes through `uv run`), | ||
| // which the Test / Unit runners do not install, so `make test-mutate-scripts` | ||
| // (static-check-full) runs this file and scripts/test-unit-ci.sh skips it. | ||
| import { afterEach, beforeEach, expect, test } from "bun:test"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { dirname, join } from "node:path"; | ||
| import type { MutateReport } from "./check"; | ||
|
|
||
| const CHECK = join(import.meta.dir, "check.ts"); | ||
| // Hermetic git: CI has no identity, and host config (hooks, signing) must not leak in. | ||
| const GIT_ENV = { ...process.env, GIT_CONFIG_GLOBAL: "/dev/null", GIT_CONFIG_NOSYSTEM: "1" }; | ||
|
|
||
| let repo: string; | ||
|
|
||
| function git(...args: string[]): void { | ||
| const result = spawnSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", ...args], { | ||
| cwd: repo, | ||
| env: GIT_ENV, | ||
| }); | ||
| expect(result.status).toBe(0); | ||
| } | ||
|
|
||
| function write(path: string, text: string): void { | ||
| mkdirSync(dirname(join(repo, path)), { recursive: true }); | ||
| writeFileSync(join(repo, path), text); | ||
| } | ||
|
|
||
| function check(): { status: number | null; report: MutateReport | null } { | ||
| const result = spawnSync(process.execPath, [CHECK, "--base", "HEAD", "--json"], { | ||
| cwd: repo, | ||
| env: GIT_ENV, | ||
| encoding: "utf8", | ||
| }); | ||
| return { status: result.status, report: result.status === 2 ? null : JSON.parse(result.stdout) }; | ||
| } | ||
|
|
||
| function outcomes(report: MutateReport | null): string[] { | ||
| return (report?.mutants ?? []).map((m) => `${m.original}>${m.mutant}:${m.outcome}`).sort(); | ||
| } | ||
|
|
||
| // Each test starts real bun processes (baseline plus mutants), so allow more | ||
| // than bun's 5 s default on a loaded host. | ||
| const SLOW = 60_000; | ||
|
|
||
| const AGE = "export const isAdult = (age: number) => age >= 18;\n"; | ||
|
|
||
| beforeEach(() => { | ||
| repo = mkdtempSync(join(tmpdir(), "mutate-check-test-")); | ||
| git("init", "-q", "-b", "main"); | ||
| // The real script lists the Bun unit lane; this one lists the fixture's tests, | ||
| // all with coverage. | ||
| write( | ||
| "scripts/test-unit-ci.sh", | ||
| "[ \"$1\" = --list-no-coverage ] && exit 0\ngit ls-files -- '*.test.ts' | sed 's#^#./#'\n" | ||
| ); | ||
| write("src/age.ts", AGE); | ||
| write( | ||
| "src/age.test.ts", | ||
| 'import { expect, test } from "bun:test";\nimport { isAdult } from "./age";\ntest("adult", () => expect(isAdult(30)).toBe(true));\n' | ||
| ); | ||
| git("add", "."); | ||
| git("commit", "-q", "-m", "base"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| rmSync(repo, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| test( | ||
| "a mutant at an untested boundary survives", | ||
| () => { | ||
| write("src/age.ts", AGE.replace("age >= 18", "age >= 18 /* touched */")); | ||
|
|
||
| const { status, report } = check(); | ||
|
|
||
| expect(status).toBe(1); | ||
| expect(outcomes(report)).toEqual([">=>>:survived"]); | ||
| expect(report?.tests["src/age.ts"]).toEqual(["src/age.test.ts"]); | ||
| }, | ||
| SLOW | ||
| ); | ||
|
|
||
| test( | ||
| "a test at the boundary kills it, also through an @/ import", | ||
| () => { | ||
| write("src/age.ts", AGE.replace("age >= 18", "age >= 18 /* touched */")); | ||
| write( | ||
| "src/edge.test.ts", | ||
| 'import { expect, test } from "bun:test";\nimport { isAdult } from "@/age";\ntest("18", () => expect(isAdult(18)).toBe(true));\n' | ||
| ); | ||
| write("tsconfig.json", '{ "compilerOptions": { "paths": { "@/*": ["./src/*"] } } }\n'); | ||
| git("add", "."); | ||
| git("commit", "-q", "-m", "edge test"); | ||
| write("src/age.ts", AGE.replace("age >= 18", "age >= 18 /* again */")); | ||
|
|
||
| const { status, report } = check(); | ||
|
|
||
| expect(status).toBe(0); | ||
| expect(outcomes(report)).toEqual([">=>>:killed"]); | ||
| expect(report?.tests["src/age.ts"]).toEqual(["src/age.test.ts", "src/edge.test.ts"]); | ||
| }, | ||
| SLOW | ||
| ); | ||
|
|
||
| test( | ||
| "a test that fails without a mutant is a baseline failure, not a pass", | ||
| () => { | ||
| write("src/age.ts", AGE.replace("age >= 18", "age >= 18 /* touched */")); | ||
| write( | ||
| "src/age.test.ts", | ||
| 'import { expect, test } from "bun:test";\ntest("broken", () => expect(1).toBe(2));\nimport "./age";\n' | ||
| ); | ||
|
|
||
| const { status, report } = check(); | ||
|
|
||
| expect(status).toBe(3); | ||
| expect(report?.droppedTests.map((d) => d.path)).toEqual(["src/age.test.ts"]); | ||
| expect(outcomes(report)).toEqual([">=>>:no-test"]); | ||
| }, | ||
| SLOW | ||
| ); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.