Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: re-mined weights drop older-run-only files only for complete runs; selected E2E keeps every run's median

garrytan5141ddeaa071
diff --git a/scripts/mine-shard-weights.ts b/scripts/mine-shard-weights.ts
index fa7507701d..fb9476998d 100644
--- a/scripts/mine-shard-weights.ts
+++ b/scripts/mine-shard-weights.ts
@@ -309,12 +309,14 @@ async function main(): Promise<void> {
mined = [{ run: null, commit: null, jobs: [], raw, measured: mineWeights(raw, lane, { e2eProfile }) }];
}
const { run, commit, attempt, jobs: fullJobs, expectedFiles, raw } = mined[0]!;
- // The newest run (the first --run) names the current files; one only older runs measured was deleted or renamed since.
- const measured = new Map([...medianWeights(mined.map(m => m.measured))].filter(([file]) => mined[0]!.measured.has(file)));
// Downloaded artifacts/stdin may cover only one shard. Only an authoritative
// complete GitHub unit/serial/full-E2E run replaces the full map; selected E2E always
// merges because its executed corpus depends on the diff.
const mergeExisting = !full && (!run || lane === "e2e");
+ // A complete newest run (the first --run) names the current files, so one only older runs measured was deleted or
+ // renamed since. A merging run's corpus is partial, so every run's median stands.
+ const median = medianWeights(mined.map(m => m.measured));
+ const measured = mergeExisting ? median : new Map([...median].filter(([file]) => mined[0]!.measured.has(file)));
const weights = mergeExisting && existsSync(out) ? loadWeights(out) : new Map<string, number>();
for (const [file, duration] of measured) weights.set(file, duration);
const metadata = { lane, unit: lane === "serial" ? "seconds" : "milliseconds", run: run ?? null, commit, source: run ? "github" : input ? "file" : "stdin",
diff --git a/test/scripts/mine-shard-weights.test.ts b/test/scripts/mine-shard-weights.test.ts
index dc634d6b76..1d4cb93375 100644
--- a/test/scripts/mine-shard-weights.test.ts
+++ b/test/scripts/mine-shard-weights.test.ts
@@ -518,6 +518,32 @@ it('a refresh from several GitHub runs takes each file\'s median, so one fast or
} finally { rmSync(dir, { recursive: true, force: true }); }
});
+it('selected E2E from several runs keeps the median of a file only an older run selected', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-mine-e2e-runs-'));
+ try {
+ const bin = join(dir, 'bin');
+ const fixtures = join(dir, 'fixtures');
+ mkdirSync(bin);
+ mkdirSync(fixtures);
+ writeFileSync(join(bin, 'gh'), '#!/bin/sh\ncase "$*" in\n "run view "*" --json conclusion,headSha,jobs") cat "$FIXTURE_GH/$3.json" ;;\n "run view "*" --log") cat "$FIXTURE_GH/$3.log" ;;\n *) exit 2 ;;\nesac\n', { mode: 0o755 });
+ const job = 'Selected E2E (diff-relevant) 1';
+ const line = (text: string) => job + '\tstep\t2026-10-30T12:00:00.000Z ' + text + '\n';
+ const run = (id: string, files: [string, number][]) => {
+ writeFileSync(join(fixtures, id + '.json'), JSON.stringify({ conclusion: 'success', headSha: 'commit-' + id, jobs: [{ name: job, conclusion: 'success' }] }));
+ writeFileSync(join(fixtures, id + '.log'), files.map(([name, ms]) => line('=== ' + name + ' ===') + line(' 0 fail') + line('Ran 1 test across 1 file. [' + ms + '.00ms]')).join('')
+ + line('Files: ' + files.length + ' total, ' + files.length + ' passed, 0 failed'));
+ };
+ run('201', [['alpha.test.ts', 1000]]);
+ run('202', [['alpha.test.ts', 3000], ['beta.test.ts', 800]]);
+ const out = join(dir, 'e2e-weights.json');
+ writeFileSync(out, '{"test/e2e/beta.test.ts":42}\n');
+ const result = spawnSync(process.execPath, [join(import.meta.dir, '../../scripts/mine-shard-weights.ts'), '--lane', 'e2e', '--run', '201', '--run', '202', '--out', out],
+ { env: { ...process.env, PATH: bin + ':' + process.env.PATH, FIXTURE_GH: fixtures }, encoding: 'utf8' });
+ expect(result.status, result.stderr).toBe(0);
+ expect(JSON.parse(readFileSync(out, 'utf8'))).toEqual({ 'test/e2e/alpha.test.ts': 2000, 'test/e2e/beta.test.ts': 800 });
+ } finally { rmSync(dir, { recursive: true, force: true }); }
+});
+
describe('medianWeights', () => {
it('takes each file\'s median over the runs that measured it, averaging the middle two of an even count', () => {
const runs = [new Map([['a', 1], ['b', 10]]), new Map([['a', 9], ['b', 30], ['c', 7]]), new Map([['a', 3]]), new Map([['a', 5], ['b', 20]])];