Skip to content

end-of-file-fixer is on by default and rewrites byte-exact test golden fixtures #2097

Backlog

Description

@gerchowl

Found while running devkit 1.19.2's pre-commit hook stack on nerdmachines/ee (ee#25).

Problem

The scaffolded .pre-commit-config.yaml enables end-of-file-fixer with no excludes:

  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b  # v5.0.0
    hooks:
      - id: end-of-file-fixer

On a repo with byte-exact golden-file test fixtures, this hook silently rewrites them on the first prek run --all-files. Our Rust parity tests broke immediately: the cyberphone JCS vectors under crates/ee-route/tests/fixtures/jcs/ and the pinned-input traces under crates/ee-route/tests/fixtures/pinned/ all got a trailing \n appended, which made the fixture content no longer match what the canonical-JSON implementation produces — because the test is "byte-exact", expected: b'…}\\n' vs got: b'…}'.

The same happens to mixed-line-ending and trailing-whitespace on a repo with Windows-line-ending golden files or trailing-whitespace-significant fixtures (though we did not hit those).

Impact

The failure is noisy (6 tests failed in our case), but it's downstream of a scaffold-time rewrite that happened quietly. A consumer who runs prek run --all-files the first time and then commits sees a 10-file diff touching test data, whose cause they then have to track down.

We added a narrow exclude per hook:

- id: end-of-file-fixer
  exclude: |
    (?x)^(
      crates/ee-route/tests/fixtures/(jcs|pinned)/.+
      | tests/fixtures/jcs/.+
    )$

Suggested

Three options, in order of ambition:

  1. Keep the hook on, but add a convention for a scaffold-preserved .pre-commit-config.project.yaml where a consumer's own excludes live (parity with .gitignore.project, [BUG] Managed .gitignore rewrite (#1024) drops consumer-required ignores with no durable committed extension point for repo-root paths #1092). Right now, the config is managed and any exclude is either hand-added to the managed file (lost on upgrade) or belongs in the generator — neither is documented.
  2. Have init-workspace.sh default exclude: to common test-fixture roots (**/tests/fixtures/, **/testdata/) when the hook is first scaffolded. A repo that WANTS end-of-file-fixing on its fixtures can delete it.
  3. Document in SOLO_ADOPTION.md / MIGRATION.md that end-of-file-fixer will rewrite golden fixtures, with the exclude-pattern example.

Related: SOLO_ADOPTION doesn't mention the prek run --all-files first-run cost at all; a new adopter is told to adopt and then hit N auto-fixes on the first commit (around 49 auto-fixed files + 30 manual items on our tree). A one-line "expect a sizeable first-pass diff; commit it separately" note would set the expectation.

Not blocking, one-line fix per repo once you know, but the first-run surprise on a fixture-heavy repo is noisy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions