Skip to content

feat: add --gate-on-change pre-change CRAP gate (#268) - #293

Merged
jflowers merged 14 commits into
unbound-force:mainfrom
jflowers:opsx/gate-on-change
Oct 1, 2026
Merged

jflowers merged 14 commits into
unbound-force:mainfrom
jflowers:opsx/gate-on-change

Conversation

@jflowers

Copy link
Copy Markdown
Collaborator

Summary

Add --gate-on-change flag to gaze crap that compares CRAP scores against the current working tree baseline, failing the gate when any function's score worsens beyond the configured epsilon. This enables pre-commit/pre-push CI checks that catch CRAP regressions before they reach main.

Closes #268
RFC: https://github.com/orgs/unbound-force/discussions/483

How to Test

# Build
go build ./cmd/gaze

# Unit + integration tests
go test -race -count=1 -short ./...

# E2E self-check
go test -race -count=1 -run 'TestRunSelfCheck' -timeout 30m ./cmd/gaze/...

# Manual verification — gate should pass on clean tree:
go run ./cmd/gaze crap ./... --gate-on-change

# Manual verification — gate should fail when CRAP worsens:
# (introduce a complexity regression in a function, then re-run)

How to Demo

  1. Run gaze crap ./... --gate-on-change on a clean working tree — should pass with no regressions.
  2. Introduce a complexity increase (e.g., add a branch to a function).
  3. Re-run gaze crap ./... --gate-on-change — should fail with a clear message showing which function regressed and by how much.

Key Files Changed

  • internal/diff/ — new package for git diff parsing (unified diff parser + git invocation wrapper)
  • internal/crap/gatechange.go — new core gate logic: baseline comparison, epsilon thresholding, regression detection
  • internal/crap/gatechange_test.go — new unit tests for gate logic
  • internal/diff/diff.go, internal/diff/git.go — new diff parser and git integration with tests
  • cmd/gaze/main.go — wire --gate-on-change flag into gaze crap command
  • cmd/gaze/main_test.go — integration tests for the new flag
  • internal/crap/analyze.go, internal/crap/crap.go, internal/crap/provider.go — expose changed-file set through analysis pipeline
  • internal/crap/report.go — text report output for gate results
  • internal/provider/goprovider/complexity.go — filter complexity analysis to changed files
  • docs/reference/cli/crap.md — CLI reference documentation for the new flag
  • README.md — mention of the new flag
  • openspec/changes/gate-on-change/ — OpenSpec change artifacts (proposal, design, spec, tasks)

Documentation website issue already filed: unbound-force/website#290

This PR was generated by /uf.finale (AI-assisted).

@jflowers jflowers left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

AI-assisted review of the --gate-on-change feature (#268). All CI checks pass and all six acceptance criteria are covered; the implementation is clean (pure-function diff parser, isolated gate logic, interface-based git invocation).

Summary of findings (full detail in inline comments):

  • [MEDIUM] JSON Schema not updated for new changed_functions fields
  • [MEDIUM] --gate-on-change silently ignored when combined with --analyzer
  • [MEDIUM] fileMatches basename fallback can false-positive on same-named files
  • [LOW] strconv.Atoi errors discarded in parseHunkHeader
  • [LOW] buildEndLineMap silently swallows parse errors

None are blocking; verdict is COMMENT.

This review was generated by /uf.review-pr (AI-assisted).

Comment thread cmd/gaze/main.go Resolved
Comment thread internal/crap/gatechange.go Resolved
Comment thread internal/diff/diff.go Resolved
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Remove the basename-only short-circuit in fileMatches that could
false-positive on same-named files in different directories, and check
strconv.Atoi errors when parsing hunk headers instead of discarding them.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Log a warning when os.Stat or parser.ParseFile fails instead of silently
continuing, which previously forced single-line fallback and could hide
coverage false negatives.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Add an exported CrapSchema documenting the CRAP report JSON contract,
including the changed_functions and changed_functions_summary fields
added by --gate-on-change.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Sep 30, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers jflowers self-assigned this Oct 1, 2026
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Remove the basename-only short-circuit in fileMatches that could
false-positive on same-named files in different directories, and check
strconv.Atoi errors when parsing hunk headers instead of discarding them.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Log a warning when os.Stat or parser.ParseFile fails instead of silently
continuing, which previously forced single-line fallback and could hide
coverage false negatives.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Add an exported CrapSchema documenting the CRAP report JSON contract,
including the changed_functions and changed_functions_summary fields
added by --gate-on-change.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers
jflowers force-pushed the opsx/gate-on-change branch from ad1aac6 to e35dd1e Compare October 1, 2026 20:49
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Remove the basename-only short-circuit in fileMatches that could
false-positive on same-named files in different directories, and check
strconv.Atoi errors when parsing hunk headers instead of discarding them.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Log a warning when os.Stat or parser.ParseFile fails instead of silently
continuing, which previously forced single-line fallback and could hide
coverage false negatives.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers
jflowers force-pushed the opsx/gate-on-change branch from e35dd1e to ab49273 Compare October 1, 2026 21:48
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Add an exported CrapSchema documenting the CRAP report JSON contract,
including the changed_functions and changed_functions_summary fields
added by --gate-on-change.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit to jflowers/gaze that referenced this pull request Oct 1, 2026
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Add a new flag to gaze crap that compares CRAP scores against the
current working tree baseline, failing the gate when any function's
score worsens beyond the configured epsilon. Includes a new
internal/diff package for git diff parsing and integration tests.

Assisted-by: qwen3.7-plus
Generated with AI assistance (qwen3.7-plus)
Assisted-by: qwen3.7-plus
Generated with AI assistance (qwen3.7-plus)
The --gate-on-change PR introduced two functions in internal/diff
that pushed GazeCRAPload from 6 to 7, failing the CI threshold check
(GazeCRAPload: 7/6).

- Decompose Parse (complexity 17 -> 9) into pure path/hunk helpers.
- Extract diffArgs from (*GitDiffer).Diff (complexity 4 -> 3).

GazeCRAPload: 7 -> 5, both new offenders below the GazeCRAP threshold.
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Remove the basename-only short-circuit in fileMatches that could
false-positive on same-named files in different directories, and check
strconv.Atoi errors when parsing hunk headers instead of discarding them.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Log a warning when os.Stat or parser.ParseFile fails instead of silently
continuing, which previously forced single-line fallback and could hide
coverage false negatives.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Add an exported CrapSchema documenting the CRAP report JSON contract,
including the changed_functions and changed_functions_summary fields
added by --gate-on-change.

Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
Addresses PR unbound-force#293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers
jflowers force-pushed the opsx/gate-on-change branch from ab49273 to e7f09bd Compare October 1, 2026 22:19

@jflowers jflowers left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note: Could not post as APPROVE due to insufficient permissions (GitHub prohibits self-approval — the PR author cannot approve their own pull request). Posted as COMMENT instead. Original verdict: APPROVE.


Clean implementation of the --gate-on-change feature that scopes CRAP gate evaluation to functions changed in the working tree. All prior review findings (from the earlier COMMENT round) have been addressed in follow-up commits. Build and tests pass locally (go build ./..., go test -race -count=1 -short ./...); MegaLinter is SUCCESS in CI.

Alignment [LOW] — buildEndLineMap in GoComplexityProvider.Analyze runs unconditionally even when --gate-on-change is not active, adding minor parse overhead to the common path. Documented design trade-off (D7); acceptable as-is, no change required.

Security — No issues. GitDiffer.Diff uses exec.CommandContext (no shell), rejects leading-- refs, uses --no-ext-diff, and enforces a 30s timeout.

This review was generated by /uf.review-pr (AI-assisted).

@jflowers
jflowers merged commit ccb30bc into unbound-force:main Oct 1, 2026
5 checks passed
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Remove the basename-only short-circuit in fileMatches that could
false-positive on same-named files in different directories, and check
strconv.Atoi errors when parsing hunk headers instead of discarding them.

Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Log a warning when os.Stat or parser.ParseFile fails instead of silently
continuing, which previously forced single-line fallback and could hide
coverage false negatives.

Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Add an exported CrapSchema documenting the CRAP report JSON contract,
including the changed_functions and changed_functions_summary fields
added by --gate-on-change.

Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
jflowers added a commit that referenced this pull request Oct 1, 2026
Addresses PR #293 review feedback from @jflowers.

Signed-off-by: Jay Flowers <[email protected]>
Assisted-by: deepseek-v4-pro
@jflowers
jflowers deleted the opsx/gate-on-change branch November 15, 2026 21:35
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.

Pre-change CRAP gate: --gate-on-change flag (Group 2b)

1 participant