Skip to content

Commit 93cb94b

Browse files
authored
ci: the minimum-Node CLI tests run in four legs, and a run with no verdict never closes the issue or calls the CLI failed (#11712)
* ci: the minimum-Node CLI tests run in four legs, and a run with no verdict never closes the issue or calls the CLI failed * ci: the minimum-Node legs pack by their own record, keep each run's times and a refreshed record, and name the files past it * Merge remote-tracking branch 'origin/main' into ci/min-node-legs * ci: a failed test wins over a watchdog stop, the minimum-Node legs use the Node legs' drift rule, and wholly skipped files record 0 * ci: the verdict step reads the leg's log without colour codes, and the refreshed record names its run and drops a deleted file * ci: a test file that failed to load or whose hook threw is a failure, the seed's fallback uses 1.15 (idle slices left out), and a refreshed record rewrites its comment * ci: the version job checks out the drift module the script imports, proven by running its step in that tree alone; comments follow the record * Merge remote-tracking branch 'origin/main' into ci/min-node-legs # Conflicts: # scripts/vitest-shard-sequencer.mjs * ci: both durations records refresh by one mergeRecord, in the dependency-free duration-split module the minimum-Node jobs check out * Merge remote-tracking branch 'origin/main' into ci/min-node-legs # Conflicts: # scripts/vitest-shard-sequencer.d.mts # scripts/vitest-shard-sequencer.mjs * ci: the minimum-Node record books the split CLI test files, and the sequencer drops a re-export main removed The six files split out of door-conformance, global-local and packed-gather-cache, the two kept files, and five more files the main record has get rows at the main record x 1.15, the seed's rule, until a refresh measures them. The deleted door-conformance.test.mjs row goes. PER_FILE_SECONDS is no longer re-exported from the sequencer; callers import it from vitest-node-legs.mjs.
1 parent c87cb0c commit 93cb94b

10 files changed

Lines changed: 1816 additions & 64 deletions

‎.github/scripts/cli-minimum-node.mjs‎

Lines changed: 181 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,26 @@
44
* @file The CLI's declared minimum Node, and the one issue that reports a run
55
* on it.
66
* @input `minimum --package <package.json>` prints the lowest Node version its
7-
* `engines.node` range allows. `reportIssue` takes actions/github-script's
8-
* `github` and `context`, whether the run passed, the version and the run
9-
* link.
7+
* `engines.node` range allows; `slow --times <file> --record <file>` names
8+
* one leg's files past their minimum-Node record. `reportIssue` takes
9+
* actions/github-script's `github` and `context`, the run's verdict (pass,
10+
* fail or none), the version and the run link.
1011
* @output The version on stdout (exit 1 when the range has no lower bound this
11-
* reads); an issue opened, commented on or closed.
12+
* reads); warning lines and a step summary for slow files; an issue opened,
13+
* commented on or closed.
1214
* @position .github/workflows/cli-minimum-node.yml: the daily main-only run of
1315
* the CLI's tests and global-mode smoke on that version. The version comes
1416
* from the CLI's own `engines.node`, not from .nvmrc, which names the
1517
* version the rest of CI uses.
1618
*/
1719

1820
import fs from 'node:fs';
21+
import path from 'node:path';
1922
import {fileURLToPath} from 'node:url';
2023

24+
import {mergeRecord} from '../../scripts/lib/duration-split.mjs';
25+
import {drifted} from './node-time-drift.mjs';
26+
2127
export const ISSUE_TITLE = 'CLI fails on its minimum Node';
2228
const BOT = 'github-actions[bot]';
2329

@@ -91,13 +97,153 @@ async function findOpenIssue(github, context) {
9197
);
9298
}
9399

100+
/**
101+
* Each leg's verdict from the files the CLI test legs upload
102+
* (`{"shard": <n>, "verdict": "pass" | "fail" | "none"}`): "none" for a leg
103+
* with no file, which the job limit cancelled before it could write one.
104+
* @param {string} dir
105+
* @param {number} count legs
106+
* @returns {Array<'pass' | 'fail' | 'none'>}
107+
*/
108+
export function readLegVerdicts(dir, count) {
109+
const verdicts = Array.from({length: count}, () => 'none');
110+
let names = [];
111+
try {
112+
names = fs.readdirSync(dir);
113+
} catch {
114+
// No verdict was uploaded at all.
115+
}
116+
for (const name of names) {
117+
try {
118+
const {shard, verdict} = JSON.parse(
119+
fs.readFileSync(path.join(dir, name), 'utf8'),
120+
);
121+
if (
122+
Number.isInteger(shard) &&
123+
shard >= 1 &&
124+
shard <= count &&
125+
['pass', 'fail', 'none'].includes(verdict)
126+
)
127+
verdicts[shard - 1] = verdict;
128+
} catch {
129+
// An unreadable file leaves that leg without a verdict.
130+
}
131+
}
132+
return verdicts;
133+
}
134+
135+
/** Seconds past its expected time a file must also run before it is named. */
136+
export const SLOW_MARGIN_S = 10;
137+
138+
/**
139+
* The files that ran past their minimum-Node record, by the Node legs' own
140+
* drift rule (node-time-drift.mjs `drifted`): every timed file is judged, the
141+
* run's own slowdown is taken out, and a file must also run SLOW_MARGIN_S
142+
* past its expected time. A file the record lacks is not judged.
143+
* @param {Record<string, number>} times seconds per test file, this run
144+
* @param {Record<string, number>} recorded seconds per test file, the record
145+
* @returns {{file: string, recorded: number, measured: number}[]}
146+
*/
147+
export function slowFiles(times, recorded) {
148+
return drifted(times, recorded, [], {all: true, margin: SLOW_MARGIN_S}).map(
149+
({file, recorded: before, measured}) => ({
150+
file,
151+
recorded: before,
152+
measured,
153+
}),
154+
);
155+
}
156+
157+
/**
158+
* The record with this run's times in it, by the same rule as the Node legs'
159+
* record (duration-split.mjs `mergeRecord`): each measured file takes its new
160+
* time, every other file keeps its own, a swizzle-proof slice keeps its
161+
* largest time, and a file `exists` no longer finds leaves it. `source` names
162+
* the run the times came from.
163+
* @param {{seconds?: Record<string, number>}} record
164+
* @param {Record<string, number>} times
165+
* @param {{source?: string, exists?: (file: string) => boolean}} [options]
166+
*/
167+
export function refreshRecord(
168+
record,
169+
times,
170+
{source, exists = () => true} = {},
171+
) {
172+
return {
173+
...record,
174+
...(source
175+
? {
176+
$comment:
177+
"Seconds per CLI test file on the CLI's minimum Node, which the \"CLI on minimum Node\" workflow packs its legs by (VITEST_DURATIONS_FILE). Refreshed from that workflow's run named in `source`; refresh it from the latest run's min-node-record artifact.",
178+
source,
179+
}
180+
: {}),
181+
seconds: mergeRecord(record.seconds ?? {}, times, exists),
182+
};
183+
}
184+
185+
/**
186+
* Every leg's per-file times, as one map, from the files the legs upload:
187+
* each artifact downloads into its own folder under `dir`.
188+
* @param {string} dir
189+
* @returns {Record<string, number>}
190+
*/
191+
export function readLegTimes(dir) {
192+
const times = {};
193+
let files = [];
194+
try {
195+
files = fs
196+
.readdirSync(dir, {recursive: true, withFileTypes: true})
197+
.filter(entry => entry.isFile() && entry.name.endsWith('.json'))
198+
.map(entry => path.join(entry.parentPath ?? entry.path, entry.name));
199+
} catch {
200+
// No leg uploaded its times.
201+
}
202+
for (const file of files) {
203+
try {
204+
Object.assign(times, JSON.parse(fs.readFileSync(file, 'utf8')));
205+
} catch {
206+
// An unreadable file adds no times.
207+
}
208+
}
209+
return times;
210+
}
211+
212+
/** A job's result as a verdict: only success passes and only failure fails. */
213+
const jobVerdict = result =>
214+
result === 'success' ? 'pass' : result === 'failure' ? 'fail' : 'none';
215+
216+
/**
217+
* The run's verdict: "fail" when any part failed a check, else "none" when
218+
* any part judged nothing (stopped, cancelled or skipped), else "pass".
219+
* @param {{version: string, legs: Array<'pass' | 'fail' | 'none'>, pack: string, smoke: string}} parts
220+
* @returns {'pass' | 'fail' | 'none'}
221+
*/
222+
export function runVerdict({version, legs, pack, smoke}) {
223+
if (version !== 'success') return 'none';
224+
const all = [...legs, jobVerdict(pack), jobVerdict(smoke)];
225+
if (all.includes('fail')) return 'fail';
226+
return all.includes('none') ? 'none' : 'pass';
227+
}
228+
94229
/**
95230
* A failed run opens the issue, or comments on the open one; a passing run
96-
* closes an open issue this job opened. Returns what it did.
231+
* closes an open issue this job opened; a run with no verdict only notes it
232+
* on an open issue. Returns what it did.
97233
*/
98-
export async function reportIssue({github, context, ok, version, runUrl}) {
234+
export async function reportIssue({github, context, verdict, version, runUrl}) {
99235
const issue = await findOpenIssue(github, context);
100-
if (ok) {
236+
// No verdict neither closes the issue nor says the CLI failed.
237+
if (verdict === 'none') {
238+
if (!issue) return 'none';
239+
await github.rest.issues.createComment({
240+
...context.repo,
241+
issue_number: issue.number,
242+
body: `No verdict on Node ${version}: part of the run stopped, was cancelled or was skipped before it judged anything ([run](${runUrl})). This issue stays as it is.`,
243+
});
244+
return 'no verdict noted';
245+
}
246+
if (verdict === 'pass') {
101247
if (!issue) return 'none';
102248
await github.rest.issues.createComment({
103249
...context.repo,
@@ -133,10 +279,36 @@ if (
133279
process.argv[1] &&
134280
fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)
135281
) {
136-
const [, , command, flag, file] = process.argv;
282+
const [, , command, flag, file, recordFlag, recordFile] = process.argv;
283+
if (command === 'slow' && flag === '--times' && recordFlag === '--record') {
284+
// One leg's files past their minimum-Node record: a warning each, and a
285+
// line in the step summary. Never a failure.
286+
let times = {};
287+
try {
288+
times = JSON.parse(fs.readFileSync(file, 'utf8'));
289+
} catch {
290+
console.log(`No per-file times at ${file}.`);
291+
process.exit(0);
292+
}
293+
const recorded =
294+
JSON.parse(fs.readFileSync(recordFile, 'utf8')).seconds ?? {};
295+
const slow = slowFiles(times, recorded);
296+
for (const {file: test, recorded: before, measured} of slow)
297+
console.log(
298+
`::warning file=${test},title=Past its minimum-Node time::${test} ran ${measured} s; ${recordFile} records ${before} s.`,
299+
);
300+
if (slow.length && process.env.GITHUB_STEP_SUMMARY)
301+
fs.appendFileSync(
302+
process.env.GITHUB_STEP_SUMMARY,
303+
`### Files past their minimum-Node time\n\n${slow.map(({file: test, recorded: before, measured}) => `- \`${test}\`: ${measured} s (recorded ${before} s)`).join('\n')}\n`,
304+
);
305+
if (!slow.length)
306+
console.log('Every file ran within its minimum-Node time.');
307+
process.exit(0);
308+
}
137309
if (command !== 'minimum' || flag !== '--package' || !file) {
138310
console.error(
139-
'usage: cli-minimum-node.mjs minimum --package <package.json>',
311+
'usage: cli-minimum-node.mjs minimum --package <package.json>\n cli-minimum-node.mjs slow --times <file> --record <file>',
140312
);
141313
process.exit(2);
142314
}

0 commit comments

Comments
 (0)