Lands L3 of the agent-first coverage architecture (ADR-020) — the
mutation-testing layer. Stryker on entities + use-cases (the pure
business-logic surface) catches the third dimension of test quality:
tests that exist + execute the code but assert nothing.
Deps (root devDependencies):
- @stryker-mutator/core ^8.7.0
- @stryker-mutator/vitest-runner ^8.7.0
Shared base: packages/core-testing/stryker.base.json
- testRunner: vitest (uses each feature's vitest.config.ts)
- mutate: src/entities/** + src/application/use-cases/** (excludes
tests, factories, contracts)
- thresholds: high 90 / low 80 / break 80
- reporters: progress + html + json (reports/mutation/{index.html,
mutation.json})
- incremental mode enabled, concurrency 4, timeout 10s
- exposed via @repo/core-testing/stryker.base.json subpath export
Per-feature config: packages/auth/stryker.config.json
- 4-line file that extends the shared base
- Proof-of-concept; other features get a config when L0 unification
closes their existing test gaps
Driver: scripts/coverage/mutate.mjs (zero-dep Node ESM)
- discoverStrykerConfigs: walks packages/* and apps/* for
stryker.config.json
- Supports --filter <name>, --since <ref> (incremental), --json
- Runs Stryker per-feature via node_modules/.bin/stryker run
- Surfaces per-package pass/fail summary; exits 1 on any failure
- Tests: scripts/coverage/mutate.test.mjs (3 tests, all green)
CI: .github/workflows/mutation-nightly.yml
- Cron at 02:30 UTC + workflow_dispatch with filter input
- Uploads reports/mutation/** as artifact (30-day retention)
- On failure, opens a tracking issue labelled mutation-testing
- permissions: contents: read, issues: write
- 60-min timeout (Stryker is slow by design)
Generator: turbo gen feature now scaffolds stryker.config.json from
turbo/generators/templates/feature/stryker.config.json.hbs — new
features ship mutation-ready out of the box.
Guide: docs/guides/coverage.md L3 section fleshed out with run
syntax, config shape, base config inventory, CI behavior, and a
"what you're looking for" primer on mutation scores.
Lockfile churn: pnpm regenerated the lockfile for the new deps;
~5K-line net reduction is collateral (pnpm version drift) but
mechanical.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
import { test, describe } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import os from "node:os";
|
|
import { discoverStrykerConfigs } from "./mutate.mjs";
|
|
|
|
describe("discoverStrykerConfigs", () => {
|
|
test("finds stryker.config.json under packages/* and apps/*", () => {
|
|
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mutate-disc-"));
|
|
try {
|
|
fs.mkdirSync(path.join(tmpRoot, "packages", "p1"), { recursive: true });
|
|
fs.mkdirSync(path.join(tmpRoot, "apps", "a1"), { recursive: true });
|
|
fs.mkdirSync(path.join(tmpRoot, "packages", "no-stryker"), {
|
|
recursive: true,
|
|
});
|
|
fs.writeFileSync(
|
|
path.join(tmpRoot, "packages", "p1", "stryker.config.json"),
|
|
"{}",
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(tmpRoot, "packages", "p1", "package.json"),
|
|
JSON.stringify({ name: "@repo/p1" }),
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(tmpRoot, "apps", "a1", "stryker.config.json"),
|
|
"{}",
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(tmpRoot, "apps", "a1", "package.json"),
|
|
JSON.stringify({ name: "@repo/a1" }),
|
|
);
|
|
|
|
const found = discoverStrykerConfigs(tmpRoot);
|
|
assert.equal(found.length, 2);
|
|
const names = found.map((f) => f.packageName).sort();
|
|
assert.deepEqual(names, ["@repo/a1", "@repo/p1"]);
|
|
} finally {
|
|
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("falls back to packageDir when no package.json", () => {
|
|
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mutate-disc2-"));
|
|
try {
|
|
fs.mkdirSync(path.join(tmpRoot, "packages", "no-pkg-json"), {
|
|
recursive: true,
|
|
});
|
|
fs.writeFileSync(
|
|
path.join(tmpRoot, "packages", "no-pkg-json", "stryker.config.json"),
|
|
"{}",
|
|
);
|
|
|
|
const found = discoverStrykerConfigs(tmpRoot);
|
|
assert.equal(found.length, 1);
|
|
assert.equal(found[0].packageName, "packages/no-pkg-json");
|
|
} finally {
|
|
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("returns empty when nothing matches", () => {
|
|
const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "mutate-disc3-"));
|
|
try {
|
|
const found = discoverStrykerConfigs(tmpRoot);
|
|
assert.deepEqual(found, []);
|
|
} finally {
|
|
fs.rmSync(tmpRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|