Files
callstack__agent-device/scripts/mutation/selection.test.ts
Michał Pierzchała b15121ffc8 test(ios): establish snapshot convergence baselines and permanent evidence (#2204)
* test(ios): add snapshot convergence evidence harness

* fix(ios): satisfy benchmark CI guards

* fix(ios): constrain benchmark proxy routes

* fix(ios-benchmark): enforce cell admission evidence

* fix(ios-benchmark): protect benchmark state ownership

* fix(ios-benchmark): use proxy port flag

* fix(ios-benchmark): let proxy choose an ephemeral port

* test(ios-benchmark): keep CLI process seam local

* fix(ios-benchmark): parse proxy startup envelope

* fix(ios-benchmark): bind proxy lease to simulator

* fix(ios-benchmark): keep fresh proxy CLI sessions isolated

* fix(ios-benchmark): preserve async timeout evidence

* docs(ios-benchmark): retain exact-head evidence

* test(ios): reveal offscreen alert fixture controls

* test(ios): reset alert between relaunch samples

* test(ios): admit native alert snapshots

* docs(ios): publish snapshot convergence corpus

* chore(ios): format benchmark evidence

* fix(ios-benchmark): admit proxy fixture anchors

* docs(ios): republish exact-head benchmark corpus

* fix(size): make publish asset evidence hermetic

* style(size): format package evidence test

* test(size): update publish preparation contracts

* fix: retire stale utils layering zone

* test: pin shared publish asset owner

* test: verify preserved size reporter closure

* fix: move mutation ownership to snapshot module

* test(ios): add snapshot convergence evidence harness

* fix(ios): satisfy benchmark CI guards

* fix(ios): constrain benchmark proxy routes

* fix(ios-benchmark): enforce cell admission evidence

* fix(ios-benchmark): protect benchmark state ownership

* fix(ios-benchmark): use proxy port flag

* fix(ios-benchmark): let proxy choose an ephemeral port

* test(ios-benchmark): keep CLI process seam local

* fix(ios-benchmark): parse proxy startup envelope

* fix(ios-benchmark): bind proxy lease to simulator

* fix(ios-benchmark): keep fresh proxy CLI sessions isolated

* fix(ios-benchmark): preserve async timeout evidence

* docs(ios-benchmark): retain exact-head evidence

* test(ios): reveal offscreen alert fixture controls

* test(ios): reset alert between relaunch samples

* test(ios): admit native alert snapshots

* docs(ios): publish snapshot convergence corpus

* chore(ios): format benchmark evidence

* fix(ios-benchmark): admit proxy fixture anchors

* docs(ios): republish exact-head benchmark corpus

* fix(size): make publish asset evidence hermetic

* test(size): update publish preparation contracts

* fix: keep git-state gates out of mutation sandboxes
2026-09-01 21:39:05 +02:00

91 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: a kernel diff selects nothing (the
// weekly sweep is the kernel report), and 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 '@agent-device/host-kit/command';
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', () => {
const dir = worktreeWithCommit('tooling', ['scripts/mutation/run.ts']);
// The lane's own sources own no kernel, so derivation alone yields nothing:
// without the canary a harness change would run zero mutants.
assert.deepEqual(listAffected(dir), shardMatrix([LANE_CANARY]));
});
// The weekly sweep is the kernel report; selecting on derived ownership would
// run the full ten-shard sweep on most PRs for a report nobody gates on.
test('a kernel diff selects nothing — only a harness diff spends mutants', () => {
const dir = worktreeWithCommit('kernel', ['src/snapshot/scroll-edge-state.ts']);
assert.deepEqual(listAffected(dir), []);
assert.deepEqual(affectedMatrixFor(['src/snapshot/scroll-edge-state.ts']), []);
});
test('a docs-only diff selects nothing', () => {
assert.deepEqual(affectedMatrixFor(['docs/agents/testing.md']), []);
});