Skip to content

test(tools): add a pytest suite for check_patches.py#16

Merged
abtonmoy merged 1 commit into
tiliondev:mainfrom
abtonmoy:test/check-patches-tests
Jul 4, 2026
Merged

test(tools): add a pytest suite for check_patches.py#16
abtonmoy merged 1 commit into
tiliondev:mainfrom
abtonmoy:test/check-patches-tests

Conversation

@abtonmoy

@abtonmoy abtonmoy commented Jul 4, 2026

Copy link
Copy Markdown
Member

Summary

tools/check_patches.py gates every PR on patch-set integrity, but the linter itself had no tests. A regression in it could silently start passing bad patches — the one thing it exists to prevent. This PR adds a focused test suite and gates it in CI.

Approach

Each test builds a small fixture patch-set in a temp directory, then asserts that a given check fails on exactly the violation it targets, and that a clean set passes every check. The fixtures are generated by two helpers (make_patch, write_set) so each case perturbs a single property.

Coverage

Every check has a pass case and a fail case:

Check Fail cases exercised
series-sync missing-from-series, extra-in-series (no backing file), duplicate entry, wrong order
numbering gap, duplicate number, non-NNNN-*.patch name
single-surface a patch touching two files (two diff --git)
well-formed a patch missing a hunk; a patch missing file headers
uxr-only-switches an added non-uxr- HasSwitch(...)
no-brand-literals an added quoted brand string literal (plus a check that a brand token inside a // comment is allowed)

Refactor (the test seam)

The checks previously read the patch directory from a module global. This threads a patches_dir argument through the check functions and adds:

  • run_checks(patches_dir) — runs all checks against a given directory and returns the Report; this is what the tests call.
  • a --patches-dir CLI flag.

The default still resolves to patches/, so python tools/check_patches.py behaves exactly as before.

CI

Runs pytest tools/tests in the existing patch-integrity job.

Verification

$ python tools/check_patches.py          # default run, unchanged
OK: all patch-set checks passed

$ pytest tools/tests -q
14 passed

Closes #11

tools/check_patches.py gates every PR on patch-set integrity, but the
linter itself had no tests. A regression in it could silently start
passing bad patches, which is the one thing it exists to prevent.

Add tools/tests/test_check_patches.py: each test builds a small fixture
patch-set in a temp directory and asserts a given check fails on exactly
the violation it targets, with a clean set passing every check. Covers
all six checks with a pass case and a fail case each:

- series-sync: missing-from-series, extra-in-series (no backing file),
  duplicate entry, wrong order.
- numbering: gap, duplicate number, non-NNNN-*.patch name.
- single-surface: a patch touching two files (two diff --git headers).
- well-formed: a patch missing a hunk, and one missing file headers.
- uxr-only-switches: an added non-uxr HasSwitch(...).
- no-brand-literals: an added quoted brand string literal (plus a check
  that a brand token inside a // comment is allowed).

To let the checks run against a fixture directory, thread a patches_dir
argument through the check functions and add a run_checks(patches_dir)
seam plus a --patches-dir flag. The default resolves to patches/ exactly
as before, so behaviour is unchanged.

Wire pytest tools/tests into the patch-integrity CI job.

Closes tiliondev#11
@abtonmoy abtonmoy merged commit cd7ffda into tiliondev:main Jul 4, 2026
5 checks passed
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.

test(tools): add a pytest suite for tools/check_patches.py

1 participant