Files
callstack__agent-device/scripts/mutation/score.ts
devin-ai-integration[bot] 8cce0ef6b8 test: ratchet mutation score over enumerated decision kernels (#1441)
* test: ratchet mutation score over enumerated decision kernels

Adds a Stryker (vitest runner) mutation lane scoped to the decision kernels,
a per-module baseline with tool/config provenance, and a ratchet that only
lets scores rise. Non-gating until two consecutive stable weekly sweeps.

Refs #1415

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* chore: declare the mutation test-scope seam for production-export analysis

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test: own kernel tests in the mutation registry and ship the #1430 lane envelope

- restore bench:help-conformance, broken by a formatting-path edit
- kernel test files select their module on PRs (registry `tests` + workflow paths),
  asserted to reach the kernel through the import graph
- every mutation run writes the standard scheduled-lane artifact envelope
- move src/utils/__tests__/errors.test.ts beside its source per the mirror rule

Refs #1415, #1430

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test: derive kernel test ownership and land the scheduled-lane health monitor

Ownership of a kernel's tests is now computed from the static import graph
(scripts/mutation/ownership.ts) instead of a hand-listed set, so a test that
reaches a kernel indirectly -- src/__tests__/daemon-error.test.ts through
src/daemon.ts -- selects that kernel on a PR. The PR lane triggers on every src
test and shards the derived modules, keeping wall clock at one module.

The lane envelope (#1430) is now written on every exit path with the stage it
reached, so a crash before any mutant runs is distinguishable from a lane that
never ran. Adds the derived cadence monitor (scripts/lane-health, daily
workflow): scheduled lanes are enumerated from .github/workflows/ and reported
dark, failing, or never-run against their own cron cadence.

* fix: merge only Stryker reports from a shard directory

The shard artifacts now carry the lane envelope beside mutation.json, and the
merge globbed every .json under the download path, so the ratchet job fed the
envelope to the report parser and died after the mutants had already run.

* fix(mutation): fail on incomplete shard sets and envelope pre-run failures

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(mutation): downgrade a passing envelope when a later lane step fails

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* refactor(mutation): shard by registry, defer the PR lane, drop the bundled watcher

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* docs: describe registry sharding and the deferred PR mutation lane

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(mutation): make the pre-graduation tooling exception select real mutants

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* test(mutation): give the worktree fixture commits their own identity

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

---------

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-07-28 10:07:14 +02:00

104 lines
3.4 KiB
TypeScript

// Per-module mutation scores derived from a Stryker JSON report.
import { ALL_MODULE_IDS, moduleForFile, normalizePath, type ModuleId } from './modules.ts';
/** The subset of Stryker's JSON report schema this lane reads. */
export type StrykerMutant = {
readonly mutatorName?: string;
readonly status: string;
readonly location?: { readonly start?: { readonly line?: number } };
};
export type StrykerReport = {
readonly files: Record<string, { readonly mutants: readonly StrykerMutant[] }>;
};
export type SurvivingMutant = {
readonly file: string;
readonly line: number;
readonly mutator: string;
};
export type ModuleScore = {
readonly module: ModuleId;
readonly score: number;
readonly killed: number;
readonly survived: number;
readonly total: number;
readonly surviving: readonly SurvivingMutant[];
};
// Stryker counts a timeout as killed. `NoCoverage` counts as survived here: an
// uncovered mutant is precisely the "decorative test" signal this lane exists to
// surface. Every other status (Ignored, CompileError, RuntimeError) leaves the
// denominator, so tool-side noise cannot move the score.
const KILLED_STATUSES = new Set(['Killed', 'Timeout']);
const SURVIVED_STATUSES = new Set(['Survived', 'NoCoverage']);
/**
* Merge sharded Stryker reports into one. The weekly sweep runs one shard per
* kernel module so no single job approaches its time budget; the ratchet still
* evaluates a single full-sweep report.
*/
export function mergeReports(reports: readonly StrykerReport[]): StrykerReport {
const files: Record<string, { mutants: StrykerMutant[] }> = {};
for (const report of reports) {
for (const [file, entry] of Object.entries(report.files)) {
const existing = files[file];
if (existing) existing.mutants.push(...entry.mutants);
else files[file] = { mutants: [...entry.mutants] };
}
}
return { files };
}
export function roundScore(value: number): number {
return Math.round(value * 100) / 100;
}
function compareMutants(a: SurvivingMutant, b: SurvivingMutant): number {
return a.file.localeCompare(b.file) || a.line - b.line || a.mutator.localeCompare(b.mutator);
}
export function summarizeReport(
report: StrykerReport,
ids: readonly ModuleId[] = ALL_MODULE_IDS,
): ModuleScore[] {
const buckets = new Map<
ModuleId,
{ killed: number; survived: number; surviving: SurvivingMutant[] }
>();
for (const id of ids) buckets.set(id, { killed: 0, survived: 0, surviving: [] });
for (const [file, entry] of Object.entries(report.files)) {
const id = moduleForFile(file);
if (!id) continue;
const bucket = buckets.get(id);
if (!bucket) continue;
for (const mutant of entry.mutants) {
if (KILLED_STATUSES.has(mutant.status)) {
bucket.killed += 1;
} else if (SURVIVED_STATUSES.has(mutant.status)) {
bucket.survived += 1;
bucket.surviving.push({
file: normalizePath(file),
line: mutant.location?.start?.line ?? 0,
mutator: mutant.mutatorName ?? 'unknown',
});
}
}
}
return [...buckets].map(([module, bucket]) => {
const total = bucket.killed + bucket.survived;
return {
module,
score: total === 0 ? 0 : roundScore((bucket.killed / total) * 100),
killed: bucket.killed,
survived: bucket.survived,
total,
surviving: bucket.surviving.sort(compareMutants),
};
});
}