mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-23 08:31:44 +01:00
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:
1 parent
ef4a7f5cbf
commit
507ebfc16d
8 files changed
+146
-9
No files matched your search
@@ -137,6 +137,12 @@ jobs:
|
||||
fi
|
||||
cp "$RUNNER_TEMP/linux/free-test-durations.json" scripts/free-test-durations.json
|
||||
cp "$RUNNER_TEMP/windows/free-test-durations-windows.json" scripts/free-test-durations-windows.json
|
||||
# New files over the 60 s ceiling become annotated exceptions naming
|
||||
# this recording, and files back under it leave the allowlist, so the
|
||||
# seed PR passes the ratchet without a maintainer edit (GST-3303).
|
||||
allowlist=$(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")
|
||||
if [ -n "$allowlist" ]; then allowlist_line=$(printf '%s\n' "$allowlist" | paste -sd, - | sed 's/,/, /g'); else allowlist_line=unchanged; fi
|
||||
echo "Seed allowlist: $allowlist_line" | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
if ratchet=$(GSTACK_FREE_SEED_BASE="$(git rev-parse HEAD)" bun test test/free-seed-ratchet.test.ts 2>&1); then
|
||||
ratchet_line="passes"
|
||||
else
|
||||
@@ -163,7 +169,7 @@ jobs:
|
||||
git switch -C "$branch"
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
git add scripts/free-test-durations.json scripts/free-test-durations-windows.json
|
||||
git add scripts/free-test-durations.json scripts/free-test-durations-windows.json scripts/free-test-seed-allowlist.json
|
||||
git commit -m "$subject"
|
||||
git push --force-with-lease="refs/heads/$branch:$remote_head" origin "HEAD:refs/heads/$branch"
|
||||
cat > pr-body.md <<EOF
|
||||
@@ -172,6 +178,7 @@ jobs:
|
||||
- Linux seed (ubicloud-standard-8): +$linux_added / -$linux_removed files
|
||||
- Windows seed (windows-latest): +$windows_added / -$windows_removed files
|
||||
- Files that failed while recording (durations kept; this PR's own free checks decide): $failed_line
|
||||
- Seed allowlist (each new file over 60 s is admitted with a todo to split it; files back under 60 s leave): $allowlist_line
|
||||
- Seed growth ratchet (60 s ceiling, shrink-only allowlist): $ratchet_line
|
||||
|
||||
Data only. This run dispatched Free Tests (the required free-tests check), Windows Smoke and Quality gate on this branch; those are this PR's checks. The pull_request runs wait as "action required" because a token-opened PR never starts them without approval. Stamp and merge per docs/ship-policy.md; the stamp push runs the full PR checks.
|
||||
|
||||
@@ -310,7 +310,7 @@ jobs:
|
||||
windows-record-durations:
|
||||
if: ${{ inputs.record_durations }}
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 30
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
||||
with:
|
||||
@@ -334,12 +334,18 @@ jobs:
|
||||
# Records into this checkout's default seed path: GSTACK_FREE_TEST_DURATIONS
|
||||
# would leak into every timed test, and seed-reading tests would then read
|
||||
# the half-written recording instead of their fixtures.
|
||||
# Two workers, not the four a windows-latest runner offers: at four, files
|
||||
# that pass in the nightly run failed under the recording load (assertion and
|
||||
# JSON-parse errors) and the whole recording outran its 30-minute job (runs
|
||||
# 43802987074 and 44830554276); at two it timed all 921 files cleanly in 38
|
||||
# minutes (44830546810).
|
||||
- name: Time every Windows-safe file alone
|
||||
id: record
|
||||
shell: bash
|
||||
env:
|
||||
TEMP: ${{ runner.temp }}
|
||||
TMP: ${{ runner.temp }}
|
||||
GSTACK_FREE_JOBS: '2'
|
||||
run: |
|
||||
set -o pipefail
|
||||
bun run test:windows --record-durations --wall-timeout 1200 2>&1 | tee "$RUNNER_TEMP/record.log"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
**The weekly test-time recording can land again on its own.** Free Tests splits the suite using recorded test times, and the weekly job that refreshes them had not landed a refresh since 11-09. Its Windows half ran four files at once on a four-core runner, so tests that pass in the nightly run failed under the load, and the recording had outgrown its 30-minute limit. Its seed pull request also waited on a maintainer whenever a new file ran past 60 seconds. The Windows recording now runs two files at a time with an hour's limit; a trial timed all 921 files cleanly in 38 minutes. The bot now lists each new slow file in the allowlist with a follow-up to split it, and drops files that are back under 60 seconds, so its pull request passes the seed check without a hand edit and its description names every file it listed.
|
||||
@@ -1625,7 +1625,9 @@ refresh to a maintainer.
|
||||
- `free-durations-record.yml` (Mondays 04:00 UTC, before test-health, and on
|
||||
dispatch) records the Linux seed on `ubicloud-standard-8` with
|
||||
`scripts/ubicloud/setup-free-suite.sh` and the Windows seed through
|
||||
`windows-free-tests.yml`'s `record_durations` path. The recorder stays on
|
||||
`windows-free-tests.yml`'s `record_durations` path, at two workers
|
||||
(`GSTACK_FREE_JOBS=2`, 60-minute job): at four, files that pass nightly failed
|
||||
under the load and the recording outran its old 30-minute job. The recorder stays on
|
||||
`ubicloud-standard-8` while the free-suite shards run on `FREE_SUITE_RUNNER`
|
||||
(`ubicloud-standard-8`); both are Ubicloud standard runners. When either recording adds
|
||||
or drops a test file, it force-updates the `bot/free-duration-seeds` branch,
|
||||
@@ -1637,9 +1639,15 @@ refresh to a maintainer.
|
||||
job red but keeps its duration, and the PR body names it; the seed PR's own
|
||||
free checks decide whether the tree is healthy. An interrupted recording
|
||||
uploads no seed, and more than 5 red files on either OS proposes nothing. The
|
||||
bot never edits the allowlist: a ratchet failure is fixed on the branch by a
|
||||
maintainer before the PR merges, and while the open seed PR holds any commit
|
||||
besides the bot's one refresh commit, later runs leave it alone. Only runs on
|
||||
bot reconciles the allowlist with the recording
|
||||
(`scripts/free-seed-allowlist.ts --reconcile`): each new file over 60 seconds
|
||||
is admitted as an annotated exception that names the recording run and carries
|
||||
a todo to split it, and entries for files back under 60 seconds are dropped,
|
||||
so the seed PR passes the ratchet without a maintainer edit and the PR body
|
||||
lists every admission. Before GST-3303 the bot left a ratchet failure for a
|
||||
maintainer to fix by hand, and the seed went stale from 11-09 to 11-20 while
|
||||
its PR waited. While the open seed PR holds any commit besides the bot's one
|
||||
refresh commit, later runs leave it alone. Only runs on
|
||||
`main` push the branch; a dispatch from another ref reports only.
|
||||
|
||||
### Sub-shards inside one CI job
|
||||
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
||||
/**
|
||||
* free-seed-allowlist — bring the seed allowlist in line with a fresh recording
|
||||
* (docs/TESTING_INTERNALS.md#free-suite-duration-seed).
|
||||
*
|
||||
* bun run scripts/free-seed-allowlist.ts --reconcile --recording <run url>
|
||||
*
|
||||
* Reads scripts/free-test-durations.json, drops allowlist entries for files no
|
||||
* longer over the 60 s ceiling, admits each unlisted file over it as an
|
||||
* annotated exception naming the recording, rewrites the allowlist, and prints
|
||||
* one ADMITTED or PRUNED line per change. The weekly recorder runs it so its
|
||||
* seed PR passes the ratchet; the admitted files stay listed for splitting.
|
||||
*/
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { formatSeedAllowlist, parseSeedAllowlist, reconcileSeedAllowlist, SEED_ALLOWLIST_FILE } from './lib/free-ci-health';
|
||||
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
|
||||
if (import.meta.main) {
|
||||
const args = process.argv.slice(2);
|
||||
const recording = args[args.indexOf('--recording') + 1];
|
||||
if (args[0] !== '--reconcile' || args.length !== 3 || args[1] !== '--recording' || !recording) {
|
||||
console.error('usage: free-seed-allowlist.ts --reconcile --recording <run url>');
|
||||
process.exit(2);
|
||||
}
|
||||
const durations = (JSON.parse(fs.readFileSync(path.join(ROOT, 'scripts/free-test-durations.json'), 'utf8')) as { durations: Record<string, number> }).durations;
|
||||
const file = path.join(ROOT, SEED_ALLOWLIST_FILE);
|
||||
const { entries, admitted, pruned } = reconcileSeedAllowlist(durations, parseSeedAllowlist(fs.readFileSync(file, 'utf8')), (name, ms) => ({
|
||||
file: name,
|
||||
reason: `${Math.round(ms / 1000)}s in the weekly recording ${recording}; 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',
|
||||
}));
|
||||
if (admitted.length || pruned.length) fs.writeFileSync(file, formatSeedAllowlist(entries));
|
||||
for (const name of admitted) console.log(`ADMITTED ${name} ${Math.round(durations[name] / 1000)}s`);
|
||||
for (const name of pruned) console.log(`PRUNED ${name}`);
|
||||
}
|
||||
@@ -148,6 +148,29 @@ export function seedRatchet({ durations, allowlist, baseAllowlist }: SeedRatchet
|
||||
return { violations, exceptions };
|
||||
}
|
||||
|
||||
/**
|
||||
* The allowlist a fresh recording needs, for the weekly recorder's seed PR: drop
|
||||
* entries for files now at or under the ceiling or gone from the seed, and admit
|
||||
* every unlisted file over it with `admit`'s annotated entry (a todo is required).
|
||||
* Other entries keep their text. Returns the new entries and what changed.
|
||||
*/
|
||||
export function reconcileSeedAllowlist(
|
||||
durations: Record<string, number>, allowlist: SeedAllowlistEntry[],
|
||||
admit: (file: string, ms: number) => SeedAllowlistEntry & { todo: string },
|
||||
): { entries: SeedAllowlistEntry[]; admitted: string[]; pruned: string[] } {
|
||||
const pruned = allowlist.filter(entry => !(durations[entry.file] > SEED_CEILING_MS)).map(entry => entry.file);
|
||||
const kept = allowlist.filter(entry => !pruned.includes(entry.file));
|
||||
const listed = new Set(kept.map(entry => entry.file));
|
||||
const admitted = Object.keys(durations).filter(file => durations[file] > SEED_CEILING_MS && !listed.has(file)).sort();
|
||||
return { entries: [...kept, ...admitted.map(file => admit(file, durations[file]))], admitted, pruned };
|
||||
}
|
||||
|
||||
/** The allowlist file's own layout: one entry per line. */
|
||||
export function formatSeedAllowlist(entries: SeedAllowlistEntry[]): string {
|
||||
const line = (entry: SeedAllowlistEntry) => `{${Object.entries(entry).map(([key, value]) => `${JSON.stringify(key)}: ${JSON.stringify(value)}`).join(', ')}}`;
|
||||
return `{\n "entries": [\n${entries.map(entry => ` ${line(entry)}`).join(',\n')}\n ]\n}\n`;
|
||||
}
|
||||
|
||||
export type BaseAllowlistRead =
|
||||
| { status: 'ok'; entries: SeedAllowlistEntry[] | null }
|
||||
| { status: 'unavailable'; reason: string };
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user