The weekly test-time recording can land again on its own (GST-3303) (#4581)

The weekly job that re-records how long each test file takes can land
its update again without someone fixing it by hand. Free Tests uses
those times to split the suite evenly.

It had not landed an update since 11-09: the Windows half kept failing,
and its pull request waited for a maintainer whenever a new file ran
past 60 seconds.

Nothing to do. The bot's commit and pull-request step runs for real only
on the weekly schedule, so the next Monday run is its first live test.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Refs: GST-3303
This commit is contained in:
Garry Tanandcapy-ai[bot] authored and GitHub committed 2026-11-21 00:13:49 +00:00
1 parent ef4a7f5cbf
commit 507ebfc16d
8 files changed
+146 -9

No files matched your search

+7 -3
View File
@@ -77,10 +77,13 @@ test('both recorders list exactly the files the recorder reported red, and more
expect(script).toContain('Files that failed while recording (durations kept; this PR\'s own free checks decide): $failed_line');
});
test('the propose step touches only the two seeds, never the allowlist, on one bot branch', () => {
test('the propose step reconciles the allowlist before the ratchet runs and commits it with the two seeds, on one bot branch', () => {
const script: string = proposeStep.run;
expect(script).toContain('git add scripts/free-test-durations.json scripts/free-test-durations-windows.json\n');
expect(script).not.toContain('free-test-seed-allowlist.json');
expect(script).toContain('git add scripts/free-test-durations.json scripts/free-test-durations-windows.json scripts/free-test-seed-allowlist.json\n');
const reconcile = script.indexOf('bun --no-env-file --config=/dev/null run scripts/free-seed-allowlist.ts --reconcile --recording "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"');
expect(reconcile).toBeGreaterThan(script.indexOf('cp "$RUNNER_TEMP/linux/free-test-durations.json" scripts/free-test-durations.json'));
expect(reconcile).toBeLessThan(script.indexOf('bun test test/free-seed-ratchet.test.ts'));
expect(script).toContain('- Seed allowlist (each new file over 60 s is admitted with a todo to split it; files back under 60 s leave): $allowlist_line');
expect(script).toContain('branch=bot/free-duration-seeds');
expect(script).toContain('bun test test/free-seed-ratchet.test.ts');
for (const workflow of ['free-tests.yml', 'windows-smoke.yml', 'quality-gate.yml']) {
@@ -146,6 +149,7 @@ test('a refresh keeps a maintainer\'s commits on the open seed PR and leases the
spawnSync('mkdir', ['-p', path.join(work, 'scripts')], { timeout: 10_000 });
writeFileSync(path.join(work, 'scripts/free-test-durations.json'), `{"run":${Date.now()}}`);
writeFileSync(path.join(work, 'scripts/free-test-durations-windows.json'), '{}');
writeFileSync(path.join(work, 'scripts/free-test-seed-allowlist.json'), '{"entries": []}');
const result = spawnSync('bash', ['-c', `set -euo pipefail\n${publish}`], { cwd: work, encoding: 'utf8', timeout: 20_000,
env: { ...env, PATH: `${stub}:${process.env.PATH}`, GITHUB_STEP_SUMMARY: path.join(dir, 'summary.md') } });
expect(result.status, result.stderr).toBe(0);
+51
View File
@@ -14,7 +14,9 @@ import * as path from 'node:path';
import {
ciHealthSummary,
overrunWarning,
formatSeedAllowlist,
parseSeedAllowlist,
reconcileSeedAllowlist,
readBaseSeedAllowlist,
SEED_ALLOWLIST_FILE,
SEED_DOCS_ANCHOR,
@@ -24,6 +26,7 @@ import {
unseededWarning,
} from '../scripts/lib/free-ci-health';
import { FREE_TEST_DURATIONS_FILE, type FreeCiPlan, type FreeCiResult, type FreeShardOutcome } from '../scripts/test-free-shards';
import { bunIsolationArgs } from '../lib/bun-isolation';
const ROOT = path.resolve(import.meta.dir, '..');
const git = (cwd: string, ...args: string[]) => spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 10_000 });
@@ -178,3 +181,51 @@ describe('free lane CI warnings', () => {
expect(summary[0]).not.toContain('shard 2');
});
});
describe('the recorder reconciles the allowlist with a fresh recording (GST-3303)', () => {
const admit = (file: string, ms: number) => ({ file, reason: `${Math.round(ms / 1000)}s in run X`, todo: 'split it' });
test('admits each unlisted file over the ceiling, drops entries back under it or gone, and keeps the rest as written', () => {
const durations = { 'test/kept.test.ts': 90_000, 'test/new-slow.test.ts': 65_000, 'test/back-under.test.ts': 59_000, 'test/edge.test.ts': 60_000, 'test/fast.test.ts': 1_000 };
const allowlist = [
{ file: 'test/kept.test.ts', reason: 'real setup per host' },
{ file: 'test/back-under.test.ts', reason: 'was 70s', todo: 'split' },
{ file: 'test/gone.test.ts', reason: 'deleted file' },
];
const { entries, admitted, pruned } = reconcileSeedAllowlist(durations, allowlist, admit);
expect(admitted).toEqual(['test/new-slow.test.ts']);
expect(pruned).toEqual(['test/back-under.test.ts', 'test/gone.test.ts']);
expect(entries).toEqual([allowlist[0], { file: 'test/new-slow.test.ts', reason: '65s in run X', todo: 'split it' }]);
expect(seedRatchet({ durations, allowlist: entries, baseAllowlist: allowlist }).violations).toEqual([]);
});
test('a seed that already holds the ratchet changes nothing, and the file layout round-trips', () => {
const raw = fs.readFileSync(path.join(ROOT, SEED_ALLOWLIST_FILE), 'utf8');
const allowlist = parseSeedAllowlist(raw);
const seed = JSON.parse(fs.readFileSync(path.join(ROOT, FREE_TEST_DURATIONS_FILE), 'utf8')) as { durations: Record<string, number> };
expect(formatSeedAllowlist(allowlist)).toBe(raw);
const { entries, admitted, pruned } = reconcileSeedAllowlist(seed.durations, allowlist, admit);
expect([admitted, pruned]).toEqual([[], []]);
expect(formatSeedAllowlist(entries)).toBe(raw);
});
test('the recorder command rewrites the allowlist file and prints one line per change', () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'seed-allowlist-'));
try {
fs.mkdirSync(path.join(root, 'scripts/lib'), { recursive: true });
for (const file of ['scripts/free-seed-allowlist.ts', 'scripts/lib/free-ci-health.ts']) fs.copyFileSync(path.join(ROOT, file), path.join(root, file));
fs.writeFileSync(path.join(root, FREE_TEST_DURATIONS_FILE), JSON.stringify({ durations: { 'test/new-slow.test.ts': 65_000, 'test/back-under.test.ts': 59_000 } }));
fs.writeFileSync(path.join(root, SEED_ALLOWLIST_FILE), formatSeedAllowlist([{ file: 'test/back-under.test.ts', reason: 'was 70s', todo: 'split' }]));
const run = spawnSync(process.execPath, [...bunIsolationArgs(), path.join(root, 'scripts/free-seed-allowlist.ts'), '--reconcile', '--recording', 'https://example.test/runs/1'], { cwd: root, encoding: 'utf8', timeout: 30_000 });
expect(run.status).toBe(0);
expect(run.stdout.trim().split('\n')).toEqual(['ADMITTED test/new-slow.test.ts 65s', 'PRUNED test/back-under.test.ts']);
expect(parseSeedAllowlist(fs.readFileSync(path.join(root, SEED_ALLOWLIST_FILE), 'utf8'))).toEqual([{
file: 'test/new-slow.test.ts',
reason: '65s in the weekly recording https://example.test/runs/1; admitted by the recorder so the refreshed seed can land',
todo: 'split or speed up until it runs under 60 s, then delete this entry',
}]);
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
});
});