mirror of
https://github.com/callstack/agent-device.git
synced 2026-09-14 20:06:34 +08:00
8cce0ef6b8
* 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>
93 lines
3.2 KiB
TypeScript
93 lines
3.2 KiB
TypeScript
// Selection is what the PR lane spends money on, so both halves of the rule are
|
|
// asserted end to end through the real CLI: nothing runs before graduation, and
|
|
// the "prove the gate" exception for a lane-tooling diff selects real mutants
|
|
// rather than an empty matrix that proves nothing.
|
|
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { after, test } from 'node:test';
|
|
import { runCmdSync } from '../../src/utils/exec.ts';
|
|
import { LANE_CANARY, shardMatrix, type ShardSpec } from './modules.ts';
|
|
import { affectedMatrixFor } from './run.ts';
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, '../..');
|
|
const worktrees: string[] = [];
|
|
|
|
after(() => {
|
|
for (const dir of worktrees) {
|
|
runCmdSync('git', ['worktree', 'remove', '--force', dir], { cwd: repoRoot });
|
|
}
|
|
});
|
|
|
|
/**
|
|
* A throwaway worktree holding one commit that touches only the given files, so
|
|
* `--list-affected` runs against a real `git diff` rather than a stubbed list.
|
|
*/
|
|
function worktreeWithCommit(name: string, files: readonly string[]): string {
|
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), `mutation-${name}-`));
|
|
fs.rmSync(dir, { recursive: true });
|
|
runCmdSync('git', ['worktree', 'add', '--detach', '--quiet', dir, 'HEAD'], { cwd: repoRoot });
|
|
worktrees.push(dir);
|
|
for (const file of files) {
|
|
fs.appendFileSync(path.join(dir, file), '\n');
|
|
}
|
|
runCmdSync('git', ['add', ...files], { cwd: dir });
|
|
// CI runners have no committer identity configured, and this commit is a
|
|
// fixture, so it carries its own rather than depending on the environment.
|
|
runCmdSync(
|
|
'git',
|
|
[
|
|
'-c',
|
|
'user.name=mutation-selection-test',
|
|
'-c',
|
|
'user.email=mutation-selection-test@invalid',
|
|
'commit',
|
|
'--quiet',
|
|
'--no-verify',
|
|
'-m',
|
|
`touch ${name}`,
|
|
],
|
|
{ cwd: dir },
|
|
);
|
|
return dir;
|
|
}
|
|
|
|
function listAffected(cwd: string): ShardSpec[] {
|
|
const result = runCmdSync(
|
|
'node',
|
|
[
|
|
'--experimental-strip-types',
|
|
path.join(repoRoot, 'scripts/mutation/run.ts'),
|
|
'--list-affected',
|
|
'--base',
|
|
'HEAD~1',
|
|
],
|
|
{ cwd },
|
|
);
|
|
assert.equal(result.exitCode, 0, result.stderr);
|
|
return JSON.parse(result.stdout.trim().split('\n').at(-1)!) as ShardSpec[];
|
|
}
|
|
|
|
test('a lane-tooling diff selects real mutants even before graduation', () => {
|
|
const dir = worktreeWithCommit('tooling', ['scripts/mutation/ratchet.ts']);
|
|
// The lane's own sources own no kernel, so derivation alone yields nothing:
|
|
// without the canary this exception would run zero mutants.
|
|
assert.deepEqual(listAffected(dir), shardMatrix([LANE_CANARY]));
|
|
});
|
|
|
|
test('a kernel diff selects nothing until the baseline graduates', () => {
|
|
const dir = worktreeWithCommit('kernel', ['src/utils/scroll-edge-state.ts']);
|
|
assert.deepEqual(listAffected(dir), []);
|
|
// …and the same diff selects that module once gating is on.
|
|
assert.deepEqual(
|
|
affectedMatrixFor(['src/utils/scroll-edge-state.ts'], true),
|
|
shardMatrix(['scroll-edge-state']),
|
|
);
|
|
});
|
|
|
|
test('a docs-only diff selects nothing even once gating is on', () => {
|
|
assert.deepEqual(affectedMatrixFor(['docs/agents/testing.md'], true), []);
|
|
});
|