Skip to content

fix(constraints): floor-guard reference reads hunk lines as content and runs from the top - #614

Merged
addyosmani merged 1 commit into
addyosmani:mainfrom
mavericksea-ai:fix/floor-guard-diff-headers-and-subfolder
Oct 2, 2026
Merged

addyosmani merged 1 commit into
addyosmani:mainfrom
mavericksea-ai:fix/floor-guard-diff-headers-and-subfolder

Conversation

@mavericksea-ai

Copy link
Copy Markdown
Contributor

Follow-up to #600: the two issues from the review there, both already on main before it, plus the macOS/Windows matrix entry.

Lines inside a hunk read as headers. The diff walk treated any line starting with --- or +++ as a file header. Inside a hunk those lines are content:

Change Diff line Before After
added ++n; // eslint-disable-line no-plusplus +++n; ... dropped, exit 0 silenced-checker, exit 1
added ++ n;, then an assertion removed further down the same test file +++ n; read as a header, so the removed assertion was filed under n;, exit 0 assertion-removed, exit 1
removed --n; assert.equal(n, 0); from a test ---n; ... dropped, exit 0 assertion-removed, exit 1

Headers are now read only between a file's diff line and its first @@.

Run from a subfolder. git ls-files --others lists only the current directory's subtree, relative to it, while git diff covers the whole tree from the top. From sub/, an untracked suppression at the top of the repository was missed (exit 0), and one inside sub/ was reported as new.js rather than sub/new.js. The guard now changes to git rev-parse --show-toplevel first, so both lists share one root (a .constraintsignore read by an adapted guard resolves from there too), and exits 2 outside a work tree, as the contract already says.

Tests. Six new cases in scripts/floor-guard-reference-test.js: five fail on main, and the sixth (outside a work tree) passes on both and covers the new exit-2 path. 28 pass. The file is added to the validate-platforms matrix list.

Run locally on Linux, also with core.autocrlf=true set system-wide as Git for Windows does; the macOS and Windows jobs on this PR are its first run there. The other CI steps pass locally.

…nd runs from the top

Two follow-ups from the review on addyosmani#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.

@addyosmani addyosmani left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: exactly the follow-ups from #600, and the fix is the right shape: ---/+++ count as headers only between a diff line and the first @@, and the guard runs from the top of the work tree. Six tests, including both subfolder cases and the exit-2 path outside a repo. Merging.

@addyosmani
addyosmani merged commit bbe1f98 into addyosmani:main Oct 2, 2026
7 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.

2 participants