|
1 | 1 | import assert from 'node:assert/strict'; |
| 2 | +import { spawnSync } from 'node:child_process'; |
| 3 | +import fs from 'node:fs'; |
| 4 | +import os from 'node:os'; |
| 5 | +import path from 'node:path'; |
2 | 6 | import { test } from 'node:test'; |
| 7 | +import { fileURLToPath } from 'node:url'; |
3 | 8 | import { COMMENT_MARKER, compareSuite, mergeRounds, renderReport } from './pr-report.mjs'; |
4 | 9 |
|
| 10 | +const reportScript = path.join(path.dirname(fileURLToPath(import.meta.url)), 'pr-report.mjs'); |
| 11 | + |
5 | 12 | const bytes = (value) => ({ median: value, min: value, samples: 1 }); |
6 | 13 | const timed = (score, min, rme) => ({ score, median: score, min, rme, scoreRme: rme, samples: 8 }); |
7 | 14 | const suite = (name, targets) => ({ suite: name, iterations: 1, harnessExit: 0, targets }); |
@@ -65,6 +72,20 @@ test('a failed round fails the merged suite', () => { |
65 | 72 | assert.equal(mergeRounds([ok, { ...ok, harnessExit: 1, failed: 'gate' }]).failed, 'gate'); |
66 | 73 | }); |
67 | 74 |
|
| 75 | +test('a missing round fails the merged suite instead of leaving the survivor', () => { |
| 76 | + const ok = suite('js-framework', [{ name: 'octane-tsrx', ops: { run: timed(10, 9, 3) } }]); |
| 77 | + const merged = mergeRounds([ok, null]); |
| 78 | + assert.match(merged.failed, /1 round failed before writing a result/); |
| 79 | + assert.equal(merged.harnessExit, 1); |
| 80 | + const body = renderReport({ |
| 81 | + suites: ['js-framework'], |
| 82 | + base: { 'js-framework': merged }, |
| 83 | + head: { 'js-framework': ok }, |
| 84 | + }); |
| 85 | + assert.match(body, /⚠️ js-framework failed on the base commit and was not compared/); |
| 86 | + assert.doesNotMatch(body, /🟢 No size increases/); |
| 87 | +}); |
| 88 | + |
68 | 89 | test('timing verdicts never turn the headline red', () => { |
69 | 90 | const base = { |
70 | 91 | 'js-framework': suite('js-framework', [{ name: 'octane-tsrx', ops: { run: timed(10, 9, 2) } }]), |
@@ -108,6 +129,88 @@ test('a suite that failed on the base commit keeps the headline from reporting g |
108 | 129 | assert.doesNotMatch(body, /🟢 No size increases/); |
109 | 130 | }); |
110 | 131 |
|
| 132 | +function writeJson(dir, name, value) { |
| 133 | + fs.mkdirSync(dir, { recursive: true }); |
| 134 | + fs.writeFileSync(path.join(dir, name), JSON.stringify(value)); |
| 135 | +} |
| 136 | + |
| 137 | +function renderDirectories(baseDirs, headDirs) { |
| 138 | + const out = spawnSync( |
| 139 | + process.execPath, |
| 140 | + [reportScript, `--base=${baseDirs}`, `--head=${headDirs}`], |
| 141 | + { |
| 142 | + encoding: 'utf8', |
| 143 | + }, |
| 144 | + ); |
| 145 | + assert.equal(out.status, 0, out.stderr); |
| 146 | + return out.stdout; |
| 147 | +} |
| 148 | + |
| 149 | +const byteSuites = (dir) => { |
| 150 | + writeJson( |
| 151 | + dir, |
| 152 | + 'bundle-size.json', |
| 153 | + suite('bundle-size', [{ name: 'octane-tsrx', ops: { js_gzip: bytes(1000) } }]), |
| 154 | + ); |
| 155 | + writeJson( |
| 156 | + dir, |
| 157 | + 'bundle-reachability.json', |
| 158 | + suite('bundle-reachability', [{ name: 'octane', ops: { raw: bytes(1000) } }]), |
| 159 | + ); |
| 160 | +}; |
| 161 | + |
| 162 | +test('a js-framework round that dies before writing JSON is not compared alone', () => { |
| 163 | + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pr-report-')); |
| 164 | + try { |
| 165 | + const base = path.join(root, 'base'); |
| 166 | + const baseRound = path.join(root, 'base-js-1'); |
| 167 | + const crashed = path.join(root, 'base-js-2'); |
| 168 | + const head = path.join(root, 'head'); |
| 169 | + byteSuites(base); |
| 170 | + byteSuites(head); |
| 171 | + const timing = suite('js-framework', [{ name: 'octane-tsrx', ops: { run: timed(10, 9, 3) } }]); |
| 172 | + writeJson(baseRound, 'js-framework.json', timing); |
| 173 | + fs.mkdirSync(crashed); |
| 174 | + fs.writeFileSync(path.join(crashed, 'build-octane-tsrx-jsbench.log'), 'build failed'); |
| 175 | + writeJson(head, 'js-framework.json', timing); |
| 176 | + const body = renderDirectories([base, baseRound, crashed].join(','), head); |
| 177 | + assert.match(body, /js-framework failed before writing a result \(base-js-2\)/); |
| 178 | + assert.match(body, /⚠️ js-framework failed on the base commit and was not compared/); |
| 179 | + assert.doesNotMatch(body, /bundle-size failed/); |
| 180 | + assert.doesNotMatch(body, /🟢 No size increases/); |
| 181 | + } finally { |
| 182 | + fs.rmSync(root, { recursive: true, force: true }); |
| 183 | + } |
| 184 | +}); |
| 185 | + |
| 186 | +test('startup logs in a round directory are not a failed byte suite', () => { |
| 187 | + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'pr-report-')); |
| 188 | + try { |
| 189 | + const base = path.join(root, 'base'); |
| 190 | + const round1 = path.join(root, 'base-js-1'); |
| 191 | + const round2 = path.join(root, 'base-js-2'); |
| 192 | + const head = path.join(root, 'head'); |
| 193 | + byteSuites(base); |
| 194 | + byteSuites(head); |
| 195 | + const round = (score) => |
| 196 | + suite('js-framework', [{ name: 'octane-tsrx', ops: { run: timed(score, score - 0.5, 3) } }]); |
| 197 | + writeJson(round1, 'js-framework.json', round(10)); |
| 198 | + fs.writeFileSync(path.join(round1, 'server-5176.log'), 'ready'); |
| 199 | + writeJson(round2, 'js-framework.json', round(13)); |
| 200 | + writeJson(head, 'js-framework.json', round(11.5)); |
| 201 | + const empty = path.join(root, 'empty'); |
| 202 | + fs.mkdirSync(empty); |
| 203 | + const body = renderDirectories( |
| 204 | + [base, round1, round2, empty, path.join(root, 'missing')].join(','), |
| 205 | + head, |
| 206 | + ); |
| 207 | + assert.match(body, /🟢 No size increases and no timing regressions outside noise\./); |
| 208 | + assert.doesNotMatch(body, /failed before writing a result/); |
| 209 | + } finally { |
| 210 | + fs.rmSync(root, { recursive: true, force: true }); |
| 211 | + } |
| 212 | +}); |
| 213 | + |
111 | 214 | test('an unchanged pull request reports no regressions', () => { |
112 | 215 | const results = { |
113 | 216 | 'bundle-size': suite('bundle-size', [{ name: 'octane-tsrx', ops: { js_gzip: bytes(1000) } }]), |
|
0 commit comments