diff --git a/src/utils/roll-spec-weights.ts b/src/utils/roll-spec-weights.ts index a679d11..05bd205 100644 --- a/src/utils/roll-spec-weights.ts +++ b/src/utils/roll-spec-weights.ts @@ -109,18 +109,19 @@ export async function computeRefresh( const runs: Weights[] = []; const usedRunIds: number[] = []; for (const runId of runIds) { - let jobs: JobTimings[]; + let run: Weights; try { - jobs = await fetchRunTimings(octokit, runId); + const jobs = await fetchRunTimings(octokit, runId); + if (!jobs.length) { + d(`run ${runId} has no timing artifacts (expired?) - ignoring`); + continue; + } + run = aggregateRun(jobs); } catch (e) { d(`run ${runId}: could not read its timing artifacts (${e.message}) - ignoring`); continue; } - if (!jobs.length) { - d(`run ${runId} has no timing artifacts (expired?) - ignoring`); - continue; - } - runs.push(aggregateRun(jobs)); + runs.push(run); usedRunIds.push(runId); } if (!runs.length) { diff --git a/src/utils/spec-weights.ts b/src/utils/spec-weights.ts index f4758a9..ee0528f 100644 --- a/src/utils/spec-weights.ts +++ b/src/utils/spec-weights.ts @@ -258,7 +258,11 @@ export function timingsFromArtifactZip(zip: Buffer): SpecTimings[] { const data = zip.subarray(dataStart, dataStart + compressedSize); const raw = method === 0 ? data : method === 8 ? inflateRawSync(data) : null; if (!raw) throw new Error(`unsupported zip compression method ${method} for ${name}`); - found.push(JSON.parse(raw.toString('utf8'))); + const timings = JSON.parse(raw.toString('utf8')); + if (!timings || typeof timings.files !== 'object' || timings.files === null) { + throw new Error(`${name} carries no per-file timings`); + } + found.push(timings); } return found; } diff --git a/tests/fixtures/spec-weights/test_artifacts_truncated_1.zip b/tests/fixtures/spec-weights/test_artifacts_truncated_1.zip new file mode 100644 index 0000000..e1b1051 Binary files /dev/null and b/tests/fixtures/spec-weights/test_artifacts_truncated_1.zip differ diff --git a/tests/utils/spec-weights.spec.ts b/tests/utils/spec-weights.spec.ts index 06d3026..e9586db 100644 --- a/tests/utils/spec-weights.spec.ts +++ b/tests/utils/spec-weights.spec.ts @@ -28,6 +28,11 @@ describe('spec-weights', () => { expect(timings[0].files['spec/api-browser-window-spec.ts']).toBeCloseTo(364.971, 3); }); + it('rejects a timings file with no per-file data', () => { + const zip = readFileSync(join(fixtures, 'test_artifacts_truncated_1.zip')); + expect(() => timingsFromArtifactZip(zip)).toThrow(/no per-file timings/); + }); + it('rejects something that is not a zip', () => { expect(() => timingsFromArtifactZip(Buffer.from('nope'))).toThrow(/not a zip/); });