Skip to content

refactor(test): one workflow parser for internal/config (#504) - #540

Merged
scttfrdmn merged 3 commits into
mainfrom
refactor/504-one-workflow-parser
Sep 20, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
refactor/504-one-workflow-parser

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #504.

.github/workflows was being read seven different ways in internal/config. #504 was filed when there
were two; the fourth arrived with #531's timeout gate, and counting the text walks properly there were
seven:

Reader File
workflowFile/workflowJobDef struct release_gate_test.go
signingWorkflow struct, for one job's two keys release_signing_test.go
map[any]any walk job_timeouts_test.go
map[any]any walk pull_request_triggers_test.go
text walk over the directory, own floor action_pins_test.go
text walk over the directory, own floor workflow_expressions_test.go
text walk over the directory, own floor release_checksums_test.go

Everything now goes through the new internal/config/workflow_test.go: workflowFile /
workflowJobDef, needsOf, triggerSection, readWorkflow, workflowSource, readWorkflowTexts,
readWorkflows, cutStep, jobStep, jobNamed, and one workflowFileFloor in place of four copies
of the number 4.

The two facts that cost a bug each

Both are comments on the shared code now, because every copy had to rediscover them:

  • On is a struct field tagged yaml:"on". yaml.v2 implements YAML 1.1, where on is a
    boolean literal — so a bare on: key unmarshals as true, a map[string]any lookup finds no
    triggers at all, and a test that walks triggers passes on every file having inspected nothing.
    triggerSection keeps the []any{true, "on"} spelling documented for the map form.
  • A step-scoped assertion has to cut the step out first. cosign verify-blob appears twice in
    release.yml and only one of them runs; an assertion over the whole file was satisfied by the release
    notes' echo of the command, and a mutation deleting the executed verification passed.

Four behaviour changes, all in the strict direction

  • triggerSection returns (cfg, present). pull_request: with no body is the wanted shape and
    unmarshals to nil, so one nil result cannot tell "present, unfiltered" from "absent".
  • cutStep is a line scan. The strings.Index version matched a step name as a prefix — a step
    named Sign would have returned Sign and verify's body — and ended the step at a hardcoded
    four-space - name:, so re-indenting a workflow would silently extend a step to end of file.
  • readWorkflowTexts accepts .yaml as well as .yml. workflow_expressions_test.go filtered on
    filepath.Ext(name) != ".yml", so a .yaml workflow was exempt from the expression gate while the
    other three walks checked it. Skipping looks like passing.
  • release_packages_test.go reads publish's dependencies through needsOf instead of
    substring-matching the raw [artifacts, docker-build-push, security-scan], which a job named
    artifacts-summary would have satisfied with the real dependency gone.

Also drops the //nolint:gocognit on TestEveryActionIsPinnedToASha: gocognit is not in
.golangci.yml's enabled set and nothing else in the tree runs it, and the nesting its explanation
defended left with the walk.

Mutation-verified, and it found something

Eight mutations of the shared parser, each confirmed to still compile:

Mutation Result
drop the yaml:"on" tag CAUGHT — TestCIWorkflowIsReusable, TestNoPullRequestTriggerFiltersItsBaseBranch
point the walk at a directory that is not there CAUGHT — three tests
make the walk return one file CAUGHT — the shared floor
collapse triggerSection to return cfg, cfg != nil SURVIVED → fixed, see below
make cutStep never end a step CAUGHT — TestTheSigningPathIsKeyless
drop needsOf's bare-string case CAUGHT — TestReleaseIsGatedByCI
make jobNamed match on the job id CAUGHT — TestReleaseAttachesTheLinuxPackages
make jobs: never parse CAUGHT — three tests

The survivor is the interesting one, and it was a real gap rather than a harness artifact. Collapsing
triggerSection's two return values took TestNoPullRequestTriggerFiltersItsBaseBranch from 3 triggers
to 1, and it passed — because the 2 it lost were ci.yml's and security.yml's, the two files that
had #512. An empty pull_request: is a nil mapping, so "present" meaning "I got a mapping back" exempts
every correct file and keeps only the ones already carrying a filter, and a triggers == 0 floor
cannot see that.

Second commit counts the unfiltered triggers separately and floors them too. Same mutation re-run:
CAUGHT, naming the cause.

Verification

  • go build ./..., go vet ./... clean
  • go test -count=1 -race ./internal/config/ passes
  • counts logged by the tests themselves are unchanged: 63 action references, 3 pull-request triggers
    (2 unfiltered), 23 timed jobs plus 1 exempt reusable-workflow caller, 5 workflow files
  • net −304 lines

golangci-lint was not run locally: the installed binary is built against go1.25 and refuses a
go1.26.6 target. CI's pinned v2.12.2 is the measurement that counts.

Closes #504.

`.github/workflows` was being read seven different ways in this package. #504 was filed when there
were two; the fourth arrived with #531's timeout gate, and counting the text walks properly there
were seven:

- two struct parsers — `release_gate_test.go`'s `workflowFile`/`workflowJobDef`, and
  `release_signing_test.go`'s `signingWorkflow` for one job's two keys
- two `map[any]any` walks — `job_timeouts_test.go` and `pull_request_triggers_test.go`
- three text walks over the directory — `action_pins_test.go`, `workflow_expressions_test.go` and
  `release_checksums_test.go`, each with its own extension filter and its own copy of the floor

Everything now goes through `internal/config/workflow_test.go`: `workflowFile`/`workflowJobDef`,
`needsOf`, `triggerSection`, `readWorkflow`, `workflowSource`, `readWorkflowTexts`, `readWorkflows`,
`cutStep`, `jobStep`, `jobNamed`, and one `workflowFileFloor`.

The two facts that cost a bug each are comments on the shared code, because each copy had to
rediscover them:

- `On` is a **struct field tagged `yaml:"on"`**. yaml.v2 reads YAML 1.1, where `on` is a boolean
  literal, so a bare `on:` key unmarshals as `true` and a `map[string]any` lookup finds no triggers
  at all — every file then passes having inspected nothing. `triggerSection` keeps the
  `[]any{true, "on"}` spelling documented for the map form.
- a step-scoped assertion has to **cut the step out first**. `cosign verify-blob` appears twice in
  release.yml and only one of them runs; an assertion over the whole file was satisfied by the
  release notes' `echo` of the command, and a mutation deleting the executed verification passed.

Four behaviour changes fell out of converging, all in the strict direction:

- `triggerSection` returns `(cfg, present)`. `pull_request:` with no body is the wanted shape and
  unmarshals to nil, so a single nil result cannot tell "present, unfiltered" from "absent" — and
  the trigger counter that is #512's non-vacuity guard depends on exactly that distinction.
- `cutStep` is a line scan. The `strings.Index` version matched a step name as a *prefix*, so a step
  named `Sign` would have returned `Sign and verify`'s body, and it ended the step at a hardcoded
  four-space `- name:`, so re-indenting a workflow would silently extend a step to end of file.
- `readWorkflowTexts` accepts `.yaml` as well as `.yml`. `workflow_expressions_test.go` filtered on
  `filepath.Ext(name) != ".yml"`, so a `.yaml` workflow was exempt from the expression gate while
  the other three walks checked it — and skipping looks like passing.
- `release_packages_test.go` reads `publish`'s dependencies through `needsOf` instead of
  substring-matching the raw `[artifacts, docker-build-push, security-scan]` text, which a job named
  `artifacts-summary` would have satisfied with the real dependency gone.

Also removes the `//nolint:gocognit` on `TestEveryActionIsPinnedToASha`: gocognit is not in
.golangci.yml's enabled set and nothing else in the tree runs it, and the nesting its explanation
defended left with the walk.

Net −304 lines. Counts unchanged and logged by the tests themselves: 63 action references, 3
pull-request triggers, 23 timed jobs plus 1 exempt caller, 5 workflow files.
…tal (#504)

Mutation-verifying #504's shared parser found the one gate the convergence did not already cover.
Collapsing `triggerSection`'s two return values into `return cfg, cfg != nil` — the exact simplification
the doc comment warns against — took TestNoPullRequestTriggerFiltersItsBaseBranch from 3 triggers to 1,
and it passed.

The 2 it lost were ci.yml's and security.yml's, which are the two files that had #512. An empty
`pull_request:` is the *wanted* shape and unmarshals to a nil mapping, so a presence check that means
"I got a mapping back" exempts every correct file and keeps only the ones already carrying a filter —
and a `triggers == 0` floor cannot see that, because the filtered ones are still counted.

So count the unfiltered ones separately and floor them too. Re-run of the same mutation: CAUGHT.
@scttfrdmn scttfrdmn added type: technical-debt Code refactoring, cleanup, or architecture improvements priority: low Nice to have, low urgency area: tests Test infrastructure and test suite area: ci-cd CI workflows, gates, and release automation effort: small Small effort - 2-4 hours labels Sep 20, 2026
@scttfrdmn
scttfrdmn merged commit 4cdea39 into main Sep 20, 2026
42 checks passed
@scttfrdmn
scttfrdmn deleted the refactor/504-one-workflow-parser branch September 20, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci-cd CI workflows, gates, and release automation area: tests Test infrastructure and test suite effort: small Small effort - 2-4 hours priority: low Nice to have, low urgency type: technical-debt Code refactoring, cleanup, or architecture improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Converge the two workflow YAML parsers in internal/config

1 participant