From e4f8b2c00faf3e4442247352436bc39d8c2a0e15 Mon Sep 17 00:00:00 2001 From: Dimitri Kennedy Date: Sat, 24 Oct 2026 17:54:08 -0400 Subject: [PATCH] fix(ci): accept a commented jobs: line in the Bun crash census workflow parser workflowJobBunVersion matched the jobs: line with trimEnd() === "jobs:", so a workflow whose jobs: line carried a trailing YAML comment (jobs: # all jobs) had no jobs and every job read as having no Bun version. Strip a whitespace-led trailing comment before matching. The blank-line clause in the job scan was dead code: a blank line starts with no non-space character and matches no job key, name: or bun-version pattern, so removing the clause changed no result. Remove it and correct the JSDoc, which claimed blank lines were skipped. Refs HACK-1462 Co-Authored-By: Claude Opus 5.5 --- scripts/ci-bun-crash-census.ts | 15 +++++++++++---- tests/ci-bun-crash-census.test.ts | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/scripts/ci-bun-crash-census.ts b/scripts/ci-bun-crash-census.ts index bfc6d465..c38a337c 100644 --- a/scripts/ci-bun-crash-census.ts +++ b/scripts/ci-bun-crash-census.ts @@ -116,6 +116,8 @@ const WORKFLOW_JOB_KEY = /^ {2}([A-Za-z0-9_-]+):\s*$/; const WORKFLOW_JOB_NAME = /^ {4}name:\s*(.+?)\s*$/; const WORKFLOW_EXPRESSION = /\$\{\{.*?\}\}/; const WORKFLOW_BUN_VERSION = /^\s+bun-version:\s*["']?([^"'\s]+)["']?\s*$/; +/** A YAML comment after a value: `#` preceded by whitespace, to end of line. */ +const YAML_TRAILING_COMMENT = /\s+#.*$/; const SHA = /^[0-9a-f]{40}$/; /** The runs endpoint returns at most 1000 results for one `created` query. */ const MAX_WINDOW_RUNS = 1000; @@ -173,21 +175,26 @@ function workflowJobNamed(opts: { * `jobs:` to the next one. Its display name is its `name:` template, or its * key when it has none, so `test shard 2/4` finds the `test-shard` matrix job. * A job with no `bun-version`, such as the `test` fan-in, returns null. - * Blank lines and column-0 `#` comments inside `jobs:` are skipped; any other - * column-0 line is the next top-level key and ends the jobs. + * The `jobs:` line may carry a trailing comment (`jobs: # all jobs`). + * Column-0 `#` comments inside `jobs:` are skipped; any other column-0 line is + * the next top-level key and ends the jobs. Blank lines need no skip: they + * start with no non-space character and match no key, `name:` or + * `bun-version`, so they neither end the jobs nor change a block. */ export function workflowJobBunVersion( workflow: string, job: string ): string | null { const lines = workflow.split(/\r?\n/); - const jobsAt = lines.findIndex((line) => line.trimEnd() === "jobs:"); + const jobsAt = lines.findIndex( + (line) => line.replace(YAML_TRAILING_COMMENT, "").trimEnd() === "jobs:" + ); if (jobsAt === -1) { return null; } const blocks: { readonly key: string; readonly lines: string[] }[] = []; for (const line of lines.slice(jobsAt + 1)) { - if (line.trim() === "" || line.startsWith("#")) { + if (line.startsWith("#")) { continue; } if (/^\S/.test(line)) { diff --git a/tests/ci-bun-crash-census.test.ts b/tests/ci-bun-crash-census.test.ts index 78ebca9a..d6fffdc1 100644 --- a/tests/ci-bun-crash-census.test.ts +++ b/tests/ci-bun-crash-census.test.ts @@ -729,6 +729,23 @@ describe("workflow reads (HACK-1441)", () => { expect(workflowJobBunVersion(WORKFLOW, "late")).toBeNull(); }); + test("a trailing comment on the jobs: line still opens the jobs (HACK-1462)", () => { + const commented = [ + "name: CI", + "jobs: # all jobs", + " test:", + " ", + " steps:", + " - with:", + ' bun-version: "1.4.2"', + ].join("\n"); + expect(workflowJobBunVersion(commented, "test")).toBe("1.4.2"); + // `#` without leading whitespace is part of the key, not a comment. + expect( + workflowJobBunVersion(commented.replace("jobs: #", "jobs:#"), "test") + ).toBeNull(); + }); + const SHA_SHARED = "d".repeat(40); const SHA_OTHER = "e".repeat(40);