Skip to content

fix(ci): run the vale-autofix scope helper from dev, not the PR branch - #1938

Merged
jth-nw merged 1 commit into
devfrom
james/vale-scope-from-dev
Dec 1, 2026
Merged

jth-nw merged 1 commit into
devfrom
james/vale-scope-from-dev

Conversation

@jth-nw

@jth-nw jth-nw commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

#1937 made vale-autofix.yml run scripts/vale-scope.mjs from the checked-out PR branch. A branch cut before #1937 merged doesn't have that file, so the first new step fails with Cannot find module '.../scripts/vale-scope.mjs'. Every later step is skipped, so the autofix doesn't run at all.

This turns the check red on every open docs PR that was branched before #1937 merged, until the author updates their branch from dev. I found it by reopening a backfill PR as a test (#1919).

Change

The workflow now extracts scripts/vale-scope.mjs and its one dependency (scripts/quality/lib/scope.mjs) from origin/dev with git archive, and runs that copy. It no longer depends on the PR branch having the files.

This also means the job, which has a write token and pushes commits, no longer runs a script that the PR itself supplies.

Testing

  • Reproduced the failure in CI conditions: checked out the old backfill branch, which has no scripts/vale-scope.mjs, and ran the helper from dev's copy. It computed the changed lines of all 22 changed pages.
  • New test in scripts/test-vale-scope.mjs reads the workflow and fails if any call goes back to the repo path, or if the extraction isn't before the first use.
  • npm run test:scripts passes.

After this merges, I'll close and reopen #1919 to confirm the autofix runs and leaves the rest of each page alone.

🤖 Generated with Claude Code

#1937 made the vale-autofix workflow call scripts/vale-scope.mjs from the
checked-out PR branch. A branch cut before that merged does not have the file, so
the first new step failed with "Cannot find module" and every later step was
skipped. Every open docs PR branched earlier would show a failed vale-autofix
check, and the autofix would not run at all. Found by reopening a backfill PR as a
test.

The workflow now extracts the helper and its one dependency from origin/dev
(git archive) and runs that copy. This also means the job, which has a write
token, no longer runs a script the PR itself supplies.

A test reads the workflow and fails if any call goes back to the repo path.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Code Review

No blocking issues found.

What I checked

  • Extraction is self-contained. scripts/vale-scope.mjs imports only Node built-ins plus ./quality/lib/scope.mjs, and scope.mjs imports only built-ins. The git archive origin/dev <both files> | tar -x -C /tmp/vale-scope keeps the relative layout, so the import resolves from /tmp/vale-scope/scripts/. Every file and git path in both modules depends on the working directory, not on where the script lives. The steps still run from the repo root, so git diff and fs.existsSync(c.file) behave as before.
  • origin/dev exists. The checkout uses fetch-depth: 0, and the existing git diff origin/dev...HEAD step already depends on that ref.
  • Step ordering and conditions. The extraction is in the changed-lines step (if: count > 0). Every later caller (violation filter, phase 2 re-scope, scope-guard) is gated on the same changed-files.outputs.count > 0, so /tmp/vale-scope always exists when a step uses it. mkdir -p comes before tar -C.
  • Old branches. For pull_request events the workflow file comes from the merge ref, so branches cut before fix(ci): vale-autofix acts only on lines the PR changed #1937 run this workflow too and get dev's copy of the helper. That fixes the reported Cannot find module failure.
  • Test. It only inspects the workflow text, but it catches a regression back to node scripts/vale-scope.mjs and checks that extraction comes before first use. readFileSync and fileURLToPath are already imported.

Non-blocking notes

  • The PR body says the write-token job "no longer runs a script that the PR itself supplies." That's true for vale-scope.mjs, but the same job still runs scripts/check-anchors.sh from the PR branch (chmod +x plus execute in the "Check anchor links" step), and the Claude step can run it as well. Fork PRs are excluded, so the risk is limited to collaborators. If the goal is to avoid running PR-supplied scripts in this job, apply the same git archive origin/dev treatment to check-anchors.sh. Otherwise, narrow the wording of the claim.
  • A PR that changes vale-scope.mjs or scope.mjs won't use its own version in this workflow until it merges to dev. That's expected with this design, and test-scripts still covers the code itself. It's worth knowing when debugging scope changes.

@jth-nw
jth-nw merged commit 566bf5d into dev Dec 1, 2026
13 checks passed
@jth-nw
jth-nw deleted the james/vale-scope-from-dev branch December 1, 2026 00:49

This branch was previously deployed

1 inactive deployment
development — 7d6e6b71 Deployed Dec 1, 2026 by jth-nw via build-and-deploy #5394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant