diff --git a/scripts/ci/job-timings.mjs b/scripts/ci/job-timings.mjs index 60c6f78582..24e3dc0eaa 100644 --- a/scripts/ci/job-timings.mjs +++ b/scripts/ci/job-timings.mjs @@ -8,10 +8,29 @@ const execFileAsync = promisify(execFile); const MAX_BUFFER = 16 * 1024 * 1024; const TIMEOUT_MS = 30_000; const OUTPUT_DIRECTORY = join(".cache", "ci-job-timings"); +// The jobs API returns display names, without the action reference. Tests +// check these exceptions against the CI and Release workflow definitions. const STEP_COSTS = [ { key: "npmCi", pattern: /\bnpm ci\b/iu }, - { key: "artifactUpload", pattern: /upload.*artifact/iu }, - { key: "artifactDownload", pattern: /download.*artifact/iu }, + { + key: "artifactUpload", + pattern: /upload.*artifact/iu, + names: new Set([ + "Upload complete static diagnostics", + "Upload complete deep static diagnostics", + "Retain available reverse tools diagnostics", + "Publish successful timing history", + "Retain the exact qualified release package", + ]), + }, + { + key: "artifactDownload", + pattern: /download.*artifact/iu, + names: new Set([ + "Download previous timing report", + "Download the original qualified package", + ]), + }, ]; /** Fetch and summarize one workflow attempt without turning telemetry into a gate. */ @@ -221,7 +240,9 @@ function normalizeStep(step) { typeof step.name !== "string" ) throw new Error("GitHub jobs API contains a malformed job step"); - const cost = STEP_COSTS.find(({ pattern }) => pattern.test(step.name)); + const cost = STEP_COSTS.find( + ({ pattern, names }) => names?.has(step.name) || pattern.test(step.name), + ); return { name: step.name, costKey: cost?.key ?? null, diff --git a/tests/boundary/filesystem/ciJobTimings.test.ts b/tests/boundary/filesystem/ciJobTimings.test.ts index 85a2ddd1fc..a38c3d7025 100644 --- a/tests/boundary/filesystem/ciJobTimings.test.ts +++ b/tests/boundary/filesystem/ciJobTimings.test.ts @@ -3,6 +3,8 @@ import { delimiter, join } from "node:path"; import { fileURLToPath } from "node:url"; import { expect, it } from "vitest"; +import { parse } from "yaml"; +import { z } from "zod"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; import { @@ -147,6 +149,77 @@ it("merges paginated jobs, reports elapsed metrics, and preserves raw responses" ]); }); +const workflowSteps = z.object({ + jobs: z.record( + z.string(), + z.object({ + steps: z + .array( + z.object({ + name: z.string().optional(), + uses: z.string().optional(), + }), + ) + .optional(), + }), + ), +}); + +it.each(["ci.yml", "release.yml"])( + "counts artifact actions from %s under their jobs API names", + async (filename) => { + const { jobs } = workflowSteps.parse( + parse( + await readFile( + new URL(`../../../.github/workflows/${filename}`, import.meta.url), + "utf8", + ), + ), + ); + const steps = Object.values(jobs).flatMap(({ steps }) => steps ?? []); + const namesFor = (action: string) => + steps + .filter(({ uses }) => uses?.startsWith(`actions/${action}-artifact@`)) + .map(({ name, uses }) => name ?? `Run ${uses}`); + const uploads = namesFor("upload"); + const downloads = namesFor("download"); + expect(uploads.length + downloads.length).toBeGreaterThan(0); + const fixture = await createFixture([ + { + jobs: [ + { + name: filename, + status: "completed", + steps: [ + ...uploads, + ...downloads, + "Cache npm package downloads", + ].map((name) => ({ + name, + started_at: "2026-10-13T00:00:00Z", + completed_at: "2026-10-13T00:00:01Z", + })), + }, + ], + }, + ]); + await runReporter(fixture); + const report = JSON.parse( + await readFile(join(fixture.outputDirectory, "report.json"), "utf8"), + ); + expect(report.stepCosts).toMatchObject({ + artifactUpload: uploads.map((name) => ({ + name, + duration: { seconds: 1 }, + })), + artifactDownload: downloads.map((name) => ({ + name, + duration: { seconds: 1 }, + })), + }); + }, +); + it("marks invalid and out-of-order timestamps unknown instead of emitting negative durations", async () => { const fixture = await createFixture([ {