Commit 3285ac1
fix(baseline): file_pattern glob matching + jq scoping bugs (#180)
## Summary
Two latent jq scoping bugs in baseline `file_pattern` matching:
1. **`f.file` re-evaluates the identity** inside `map(select(...))` —
`.` rebinds to each baseline entry, so `f.file` returned the baseline
entry's `.file` field instead of the finding's. Fix: `f as $finding |
...` before entering the map.
2. **`.file_pattern` inside `test(arg)`** — `test`'s argument is
evaluated in the input's scope (the file string), so `.file_pattern`
errored with "Cannot index string", silently swallowed by `select()` and
treated truthy. This made `file_pattern` entries always-match. Fix:
`(.file_pattern? // null) as $pat | ...` capture before `test()`.
Both `scripts/apply-baseline.sh` and the inline `in_baseline()` helper
in `governance-reusable.yml` had these bugs. Both now mirror the same
corrected `**` → `.*` / `*` → `[^/]*` glob → regex translation.
Adds `scripts/tests/apply-baseline-test.sh` — six regression cases that
pin both bugs so they can't recur (exact match, glob match, over-match
guard, single-* segment, slash-crossing, empty baseline).
## Why this matters
The absolute-zero language-demo repo carries ~30 legitimate
banned-language example files under `examples/` (Java, Kotlin, Swift,
Dart, Cobol, Erlang, Fortran, Lisp, …). Its `main` branch currently
fails governance on every push because `.hypatia-baseline.json`
`file_pattern` doesn't actually exempt anything. Same blocker:
maa-framework #69 (Dependabot rust-toolchain bump) — vendored
`absolute-zero/examples/{java,kotlin}/*.{java,kt}` files trip the
language-policy step.
After this lands, both can use a single `file_pattern: "examples/**"`
entry instead of per-file `.hypatia-ignore` enumeration.
## Test plan
- [x] `scripts/tests/apply-baseline-test.sh` — 6/6 pass locally
- [x] End-to-end simulation of language-policy step against a fixture
with `examples/` baseline-exempted (Java enforce fails on
`src/RealCode.java`, Swift enforce passes on `examples/swift/*`)
- [ ] CI on this PR
- [ ] Downstream: file follow-up PRs to absolute-zero
(`.hypatia-baseline.json` with `file_pattern`) and maa-framework
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 3e4bd4c commit 3285ac1
3 files changed
Lines changed: 138 additions & 14 deletions
File tree
- .github/workflows
- scripts
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
252 | 254 | | |
253 | 255 | | |
254 | 256 | | |
255 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
256 | 263 | | |
257 | 264 | | |
258 | 265 | | |
259 | 266 | | |
260 | | - | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
261 | 283 | | |
262 | 284 | | |
263 | 285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
77 | 88 | | |
78 | | - | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | | - | |
81 | | - | |
82 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
83 | 95 | | |
84 | | - | |
| 96 | + | |
85 | 97 | | |
86 | | - | |
87 | | - | |
88 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
89 | 102 | | |
90 | 103 | | |
91 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
0 commit comments