Repository navigation
fix(constraints): floor-guard reference sees untracked files, deletions and maximum thresholds - #600
Conversation
abhisheksharma2411
left a comment
There was a problem hiding this comment.
Hi @mavericksea-ai — this is a good fix, and the framing in #599 (fourteen cases, four causes) is the right way to have approached it. The git diff --no-index /dev/null trick for untracked files is neat, and making every other git failure exit 2 rather than reading as clean is the correctness call that matters most here — a guard that fails open is worse than no guard.
Your 17 tests pass for me on 4ee1eb6. I went after the threshold comparison specifically, because direction-from-surrounding-words is the kind of thing that works on the cases you wrote and surprises you on the fifteenth. Three results, one of which I think is worth fixing before merge.
1. A threshold deleted from a multi-threshold rule is silent — false negative
This is the one I'd prioritise, because it fails in the unsafe direction.
before.forEach((b, i) => {
const n = after[i];
if (verdict || !n || n.n === b.n) return; // ← `!n` returns earlyWhen the edit removes a number, after[i] is undefined and the loop returns quietly.
- Latency: p95 under 200 ms and p99 under 900 ms.
+ Latency: p95 under 200 ms.
floor-guard: clean ← exit 0
The p99 maximum is gone and the rule still matches by key, so nothing fires. Deleting the whole rule is caught (rule-removed, verified), so this is specifically the "rule survives, one of its thresholds doesn't" case. Given the reference's own stance — "staying quiet is the wrong default" when direction can't be read — a vanished threshold seems like it should get the same treatment.
2. Positional pairing misfires when a number is inserted — false positive
Thresholds are compared by index, so any number added earlier in the text shifts the alignment:
- Coverage: at least 80 percent.
+ Coverage: per ADR 7, at least 80 percent.
[threshold-loosened] ← exit 1
80 is now compared against 7, inherits min from the before side, 7 < 80, loosened. The rule didn't change. Citing an ADR, adding an issue number, a date, a footnote marker — all trip it.
Pairing on (direction, position-among-same-direction) would survive this, or matching on the surrounding token rather than the index. Either is more work than the !n fix, so I'd understand deferring it — but it's worth knowing, because the failure mode is a contributor being told they lowered a bar they didn't touch, and the fix they'll reach for is deleting the guard.
3. Renaming a rule reads as rule-removed — correct, misleading message
- Coverage: at least 80 percent.
+ Code coverage: at least 80 percent.
[rule-removed] ← exit 1
I don't think this is a bug — the key is the text before the colon, so a renamed rule genuinely can't be matched, and blocking is the safe default. But rule-removed on a rule that's plainly still there sends the reader hunting for a deletion that didn't happen. A separate flag, or just appending "(or its label changed — rename in one commit, change thresholds in another)" to the message, would save that trip.
How I checked
Extracted the fenced block the same way your test does and ran it against fresh repos with real git, with a control in each direction so a pass isn't a coincidence:
ok lowering a minimum is caught (exit 1, control)
ok deleting an entire rule is caught (exit 1, control)
FAIL deleting one threshold from a rule (expected 1, got 0)
FAIL a number added before the threshold (expected 0, got 1)
FAIL renaming a rule label (expected 0, got 1)
Happy to push these as three more cases in floor-guard-reference-test.js if you'd like — say the word and they're yours, no credit needed. Or if you'd rather land this as-is and take (1) as a follow-up, that seems reasonable too; the plumbing fixes here are clearly a net improvement over what's on main regardless.
…ns and maximum thresholds The reference guard in constraint-driven-development promised to include untracked files, catch deleted test files and weakened thresholds, and stay silent when constraints tighten. Run unchanged, it did none of those for ordinary local git changes: - `git diff --no-index /dev/null <file>` exits 1 whenever the sides differ, and the shared git() wrapper turned every nonzero exit into null, so every untracked file diffed as empty and no added-line rule could see it. - The filename came from the `+++` header only, so a deletion (`+++ /dev/null`) sliced to `ev/null` and matched nothing; there was no deletion rule, and staging did not help. - A number going down was treated as weaker, which is right for a minimum (coverage) and inverted for a maximum (size, latency, error budget). - A removed floor bullet was never reported, although the comment said it was. The wrapper now keeps stdout on the expected exit 1 and every other failure exits 2 rather than reading as clean; both diff headers name the file and a deleted test file is its own finding; each threshold carries a direction read from the words around it (>=, at least, must not fall; <=, at most, under, must not grow), a number with no readable direction is reported when it changes; a removed floor bullet or table row is reported, except an Exceptions row, whose removal tightens. The three language patterns are unchanged. scripts/floor-guard-reference-test.js extracts the fenced block and runs it with real git against fourteen fixtures plus three edge cases; eight of them fail on the previous reference and all pass now. The workflow runs it beside the other script tests.
… removed ones Review on addyosmani#600 (@abhisheksharma2411) found three cases in the threshold comparison: - Deleting one threshold from a rule that keeps others was silent: pairing was by position, and a threshold with no counterpart after the edit was skipped. It is now reported as threshold-removed. - A number inserted earlier in a rule shifted the pairing, so "per ADR 7, >= 80%" compared 80 against 7 and reported a loosened minimum. Numbers are now paired within their direction (minimum with minimum, maximum with maximum, undirected with undirected); an added number tightens and stays silent. - A renamed rule is still reported as rule-removed, since the key is the label and blocking is the safe default, and the output now says the label may have changed. The review's cases are in the test, plus a control that adding a threshold is silent: 21 pass, and the three review cases fail on the previous commit.
4ee1eb6 to
23f2052
Compare
|
Thanks @abhisheksharma2411 for going after the threshold comparison. You were right on all three, and each one reproduced before I changed anything. Pushed a follow-up commit:
Your cases are in I also re-authored the first commit under this account, so the branch was force-pushed; that commit's content is unchanged. |
|
Pulled the follow-up and re-ran my three cases — all fixed, and the On the trade-off you flagged:
I think that's the right call, and worth keeping deliberately rather than treating as a wart. The one thing I'd suggest is that the message say so, the way you did for the rename case. Something like "a Nothing blocking from me. Nice turnaround. |
…d its direction words Follow-up from the review on addyosmani#600 (@abhisheksharma2411): a number that gains or loses its direction words (">= 80%" becoming "80%", or the reverse) is paired within its direction and so reads as removed. That is kept on purpose, since the rule changed shape and a person should look once, but the output now says so, as it already does for a renamed rule, so the finding is not read as a literal deletion. One case added for a minimum losing its direction words: 22 pass, and the new case fails without the message.
|
Added in c1a5cf4: when a threshold-removed finding appears, the output now says it can also mean a number gained or lost its direction words, and to compare the two lines before assuming a deletion. One new case (">= 80%" becoming "80%"); 22 pass. Thanks for the careful review. |
addyosmani
left a comment
There was a problem hiding this comment.
praise: thanks for running the reference as shipped instead of trusting its comments. diff --no-index exiting 1 and the wrapper dropping its output was the real bug, and 12 of your 22 cases fail against main, so the tests earn their place. I wrote that reference, so doubly thanks. Merging.
suggestion (non-blocking): two small follow-ups, both already on main before this: an added line starting with ++ gets parsed as a file header, and untracked paths come out relative to the current directory when run from a subfolder. Also worth adding the new test to the macOS/Windows matrix list.
|
Thanks, Addy. Both follow-ups and the matrix entry are in #614. |
…nd runs from the top Two follow-ups from the review on #600, both already on main before it: - The diff walk treated any line starting with `---` or `+++` as a file header. Inside a hunk those lines are content. An added line that starts with `++` (`++n; // eslint-disable-line no-plusplus`) shows as `+++n; ...` and was dropped, so the suppression passed. An added line that starts with `++ ` was taken as a header, so the lines after it were filed under a made-up path and a removed assertion further down the same test file went unreported. A removed line starting with `--` never reached the removed list either. Headers are now read only between a file's `diff` line and its first `@@`. - Run from a subfolder, `git ls-files --others` listed only that subfolder's untracked files, relative to it, while `git diff` covers the whole tree from the top. An untracked suppression elsewhere in the repository was missed, and one inside the subfolder was reported under a different name from the tracked files. The guard now changes to `git rev-parse --show-toplevel` first, and exits 2 outside a work tree. The test gains six cases: five fail on main, and the sixth (outside a work tree) passes on both and covers the new exit-2 path; 28 pass. The test now also runs in the macOS/Windows matrix.
Fixes #599.
references/floor-guard.mdpromises to include untracked files, catch deleted test files and weakened thresholds, and stay silent when constraints tighten. Run unchanged it did none of those for ordinary local git changes; #599 has the fourteen-case table and the four causes. This PR fixes the plumbing and adds the cases as a test. The three language patterns are untouched.What changed in the reference
git diff --no-index /dev/null <file>exits 1 whenever the sides differ. Thegit()wrapper now keeps stdout on that exit, and every other failure (no merge base, a diff that cannot be read) exits 2 instead of reading as clean, which the contract already required.+++ /dev/nullkeeps the old path. A deleted test file is its own finding (test-deleted); the assertion rule skips files that no longer exist so a deletion is reported once.>=,at least,must not fallmark a minimum, loosened by going down;<=,at most,under,must not growmark a maximum, loosened by going up. A number with no readable direction is reported whenever it changes (threshold-changed), since the guard cannot tell tightening from loosening and staying quiet is the wrong default.rule-removed), except an Exceptions row, whose removal tightens.Test
scripts/floor-guard-reference-test.jsextracts the fenced block from the reference and runs it with real git against fourteen fixtures (fresh repositories with a source file, a test file and a CONSTRAINTS.md carrying a floor bullet, a coverage minimum, a bundle maximum and an Exceptions table) plus three edge cases: a removed exception row is silent, a missing merge base exits 2, an undirected number is reported when it changes. On the previous reference 8 of 17 fail; all 17 pass here. The workflow runs it beside the other script tests.Verification
node --test scripts/floor-guard-reference-test.js: 17 pass.node scripts/validate-skills.js: 25 skills, 0 errors;node scripts/validate-reference-links.js: passed;node --test scripts/lib/skill-lint-test.js: 35 pass.Limits
The reference stays regex-shallow on purpose, as its own note says. Direction words are read from a short window around each number, so an unusual phrasing falls into
threshold-changed(loud) rather than being misread. Removed-rule detection compares keys, so a reworded bullet is reported as removed and added; that is a review prompt, not a false pass. A removed line whose own text begins with--is read as a diff header, as it was before.