MCPcopy Create free account
hub / github.com/adobe/react-spectrum / confirm

Function confirm

perf/confirm.mjs:19–71  ·  view source on GitHub ↗
({results, scenario, runs})

Source from the content-addressed store, hash-verified

17// new seeds, so arm order, scenario order, and launch gaps differ. The number of runs
18// is fixed before any of them start; all of them run, whatever the early results.
19export async function confirm({results, scenario, runs}) {
20 let originalDir = path.isAbsolute(results) ? results : path.join(local, 'results', results);
21 let original = JSON.parse(await fs.readFile(path.join(originalDir, 'results.json'), 'utf8'));
22 if (original.status !== 'complete' || !original.builds.candidate || !original.comparisons) {
23 throw new Error('confirm needs a completed compare run.');
24 }
25 let available = original.scenarios.map(scenario => scenario.id);
26 let ids = scenario
27 ? available.filter(id =>
28 scenario.split(',').some(filter => id === filter || id.startsWith(`${filter}.`))
29 )
30 : available.filter(id => detected(original.comparisons[id].verdict));
31 if (!ids.length) {
32 throw new Error(
33 scenario
34 ? `None of those scenarios were in that run. It measured: ${available.join(', ')}.`
35 : 'No scenario in that run reported an improvement or regression. Pass --scenario to choose which to repeat.'
36 );
37 }
38 for (let arm of ['base', 'candidate']) {
39 let current = await loadBuild(original.options[arm]);
40 let expected = original.builds[arm];
41 if (
42 ['artifactHash', 'harnessHash', 'lockHash'].some(key => current[key] !== expected[key]) ||
43 !isDeepStrictEqual(current.versions, expected.versions)
44 ) {
45 throw new Error(
46 `Snapshot ${current.name} no longer matches the ${arm} build in the original comparison. Start a new comparison instead of confirming these results.`
47 );
48 }
49 }
50 let experiments = [];
51 for (let i = 0; i < runs; i++) {
52 console.log(`\nConfirmation run ${i + 1}/${runs}`);
53 let {result, dir} = await run({
54 ...original.options,
55 scenario: ids.join(','),
56 seed: original.options.seed + 1 + i,
57 trace: false
58 });
59 experiments.push({dir, seed: result.options.seed, comparisons: result.comparisons});
60 }
61 let markdown = summarizeConfirmation(original, originalDir, experiments, ids);
62 let dir = path.join(
63 local,
64 'results',
65 `confirmation-${new Date().toISOString().replaceAll(/[:.]/g, '-')}`
66 );
67 await fs.mkdir(dir, {recursive: true});
68 await fs.writeFile(path.join(dir, 'summary.md'), markdown);
69 console.log(`\n${markdown}\nSaved ${dir}`);
70 return {dir, markdown};
71}
72
73// A scenario is confirmed when every confirmation run reaches the original verdict,
74// not confirmed when any run contradicts it, and unresolved otherwise.

Callers 2

cli.mjsFile · 0.90
confirm.test.mjsFile · 0.90

Calls 7

loadBuildFunction · 0.90
runFunction · 0.90
detectedFunction · 0.85
summarizeConfirmationFunction · 0.85
pushMethod · 0.80
filterMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected