Skip to content

Commit 5f0c784

Browse files
committed
ci(ui): prove the timings reporter loads by absolute path, overwrite on re-run, main-only refresh dispatch
- test-file-timings.test.ts spawns the vitest CLI with the reporter by absolute path over one fixture test and asserts exit 0 and a schema-tagged report (a PR runs Test UI at the affected speed, so nothing else proves it). - The per-shard timings upload sets overwrite: true, so a re-run shard replaces its report; its comment now says retention is over-provisioned against the selector's window rather than measuring it. - ui-test-timings-refresh.yml refuses a workflow_dispatch on any ref but main before anything else runs. Claude-Session: https://claude.ai/code/session_01JQwxbXf3xRiPQrLhrgsFzw Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 82d9d26 commit 5f0c784

3 files changed

Lines changed: 60 additions & 4 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,10 +3918,12 @@ jobs:
39183918
# a missing report is a warning, not an error (the refresh's selector
39193919
# then skips this run by name). Uploaded on the full battery's events
39203920
# only, the deny-list of THE TWO SPEEDS above `jobs:`; a pull request that
3921-
# failed open to the whole suite writes a report and uploads nothing. The
3922-
# refresh reads the newest fifty completed runs of this workflow on
3923-
# `main`, so a push run's report needs two days and a scheduled run's a
3924-
# week, which also covers a quiet weekend of scheduled runs alone.
3921+
# failed open to the whole suite writes a report and uploads nothing.
3922+
# `overwrite: true` so a re-run shard replaces its report, as the
3923+
# shard-attestation uploads do. The refresh reads only the newest
3924+
# completed `push` / `schedule` runs of this workflow on `main`, as many
3925+
# as its selector's own cap examines, so the retention below is
3926+
# deliberately more than that window needs; it is not a measurement of it.
39253927
- name: Publish this shard's per-file test timings
39263928
if: ${{ always() && github.event_name != 'pull_request' && github.event_name != 'merge_group' }}
39273929
continue-on-error: true
@@ -3931,6 +3933,7 @@ jobs:
39313933
path: ${{ runner.temp }}/test-file-timings/
39323934
if-no-files-found: warn
39333935
retention-days: ${{ github.event_name == 'schedule' && 7 || 2 }}
3936+
overwrite: true
39343937

39353938
test-ui-gate:
39363939
# Stable required-check name for the sharded Test UI matrix (#26460, ruling

‎.github/workflows/ui-test-timings-refresh.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ jobs:
101101
UI_TEST_SHARDS: '16'
102102
RUN_LIMIT: '6'
103103
steps:
104+
# A dispatch from another branch would regenerate from that branch's
105+
# scripts and open a PR against `main` from them; only `main` runs the
106+
# write path. Refused before anything else runs.
107+
- name: Refuse a dispatch on any ref but main
108+
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
109+
env:
110+
REF: ${{ github.ref }}
111+
run: |
112+
echo "::error title=UI test timings refresh::workflow_dispatch runs only on refs/heads/main, not '$REF'. Nothing was regenerated or pushed."
113+
exit 1
114+
104115
- name: Checkout repository
105116
uses: actions/checkout@v7
106117
with:

‎ui/scripts/__tests__/test-file-timings.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { spawnSync } from 'node:child_process';
23
import fs from 'node:fs';
4+
import { createRequire } from 'node:module';
35
import os from 'node:os';
46
import path from 'node:path';
7+
import { fileURLToPath } from 'node:url';
58

69
// Plain-JS CI helpers; their types are INFERRED from the .mjs source by
710
// `tsconfig.scripts.json` (`allowJs`), so no `@ts-expect-error` here.
@@ -23,6 +26,7 @@ import { TIMINGS_SCHEMA, datasetWeights, pathKey } from '../test-shard-partition
2326
import { parse as parseYaml } from 'yaml';
2427
import { shardTotal } from '../../../scripts/ci-shard-matrix.mjs';
2528
import { UI_JOBS, rootCi, rootWorkflow, rootWorkflowsDir } from './helpers/root-ci';
29+
import { childVitestEnv } from './helpers/child-vitest-env';
2630

2731
/**
2832
* The per-file timing pipeline (objectui#12208): the reporter that measures on
@@ -94,6 +98,44 @@ describe('the writer', () => {
9498
});
9599
});
96100

101+
/**
102+
* The writer as the real vitest CLI loads it: by ABSOLUTE path, the spelling
103+
* the root `ci.yml` passes. A pull request runs Test UI at the affected speed,
104+
* which passes no reporter, so nothing else on a PR proves the load; a load
105+
* failure would red every full-battery Test UI shard on `main`. One fixture
106+
* test in a scratch root with its own empty config (never this tree's, whose
107+
* projects and invocation guard are not what is under test).
108+
*/
109+
describe('the writer, loaded by the vitest CLI from an absolute path', () => {
110+
const reporterPath = fileURLToPath(new URL('../test-file-timings.mjs', import.meta.url));
111+
const vitestCli = (() => {
112+
const require = createRequire(import.meta.url);
113+
const pkgPath = require.resolve('vitest/package.json');
114+
const bin = (JSON.parse(fs.readFileSync(pkgPath, 'utf8')) as { bin: { vitest: string } }).bin.vitest;
115+
return path.resolve(path.dirname(pkgPath), bin);
116+
})();
117+
let dir: string;
118+
beforeEach(() => {
119+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'file-timings-load-'));
120+
});
121+
afterEach(() => fs.rmSync(dir, { recursive: true, force: true }));
122+
123+
it('exits 0 and writes a schema-tagged report naming the fixture file', () => {
124+
fs.writeFileSync(path.join(dir, 'vitest.config.mjs'), 'export default {};\n');
125+
fs.writeFileSync(path.join(dir, 'smoke.test.mjs'), "test('runs', () => { expect(1).toBe(1); });\n");
126+
const out = path.join(dir, 'report', 'shard-1.json');
127+
const child = spawnSync(
128+
process.execPath,
129+
[vitestCli, 'run', '--root', dir, '--config', path.join(dir, 'vitest.config.mjs'), '--globals', '--reporter=default', `--reporter=${reporterPath}`],
130+
{ cwd: dir, encoding: 'utf8', env: childVitestEnv({ [OUT_ENV]: out }), timeout: 120_000 },
131+
);
132+
expect(child.status, `${child.stdout ?? ''}${child.stderr ?? ''}`).toBe(0);
133+
const report = JSON.parse(fs.readFileSync(out, 'utf8'));
134+
expect(report.schema).toBe(REPORT_SCHEMA);
135+
expect(report.files.map((f: { file: string }) => f.file)).toEqual(['smoke.test.mjs']);
136+
}, 180_000);
137+
});
138+
97139
describe('the generator', () => {
98140
let dir: string;
99141
beforeEach(() => {

0 commit comments

Comments
 (0)