Skip to content

fix(ci-formats): name annotation files from the checkout root for a subdirectory --path - #358

Merged
FROWNINGdev merged 2 commits into
FROWNINGdev:mainfrom
Xnadir:fix/ci-annotation-paths-subdir
Nov 24, 2026
Merged

FROWNINGdev merged 2 commits into
FROWNINGdev:mainfrom
Xnadir:fix/ci-annotation-paths-subdir

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

GitHub resolves the file of an annotation (and a SARIF artifactLocation.uri) against the checkout root, and the Action runs the CLI from there. When --path is a subdirectory, as with the Action's path: backend, the paths did not say so:

command --path backend --path /abs/checkout/backend
nplusone shop/views.py (wrong) shop/views.py (wrong)
migration-risk backend/shop/migrations/0002_drop.py shop/migrations/0002_drop.py (wrong)
blast-radius backend/shop/migrations/0002_drop.py shop/migrations/0002_drop.py (wrong)

So the N+1 annotations of a monorepo never reached the PR diff, and the other two depended on how the path was spelled. All of them should be backend/shop/....

ci_formats._rel_posix() now writes an absolute path under the working directory relative to that directory, and falls back to the root as before for a path outside it. NPlusOneFinding.file is relative to the scanned root, so nplusone_github() and nplusone_sarif() take an optional root (which cli.py passes) and join it to the file first. With the default path: . nothing changes.

Type of change

  • Bug fix (non-breaking, restores expected behaviour)

Test plan

  • New test_paths_under_a_subdirectory_root_stay_checkout_relative in tests/test_ci_formats.py changes into a temporary checkout and checks the GitHub and SARIF paths of both commands for backend and for the absolute path. It fails on main. On main, _rel_posix() turns the absolute case into orders/0002.py instead of backend/orders/0002.py.
  • test_github_annotations_point_at_the_migration_line in tests/test_blast_radius.py now runs from its fixture folder, which stands in for the checkout root, so it keeps its assertion file=blog/migrations/0002_drop_author.py. Run from cli/ it would now give tests/fixtures/blast_radius/blog/..., which is the right checkout-relative path from there.
  • By hand, from a folder holding backend/shop: nplusone, migration-risk and blast-radius --format github, with --path backend and with the absolute path, all print file=backend/shop/....
  • cd cli && python -m pytest -q: 1359 passed, 6 skipped. ruff check orm_lens tests and mypy orm_lens are clean.

Checklist

  • I ran the full test suite locally (cd cli && pytest -q for Python, npm test for TypeScript) and it is green
  • I added or updated tests that cover the change (bugfixes should get a regression test)
  • If the change is user-facing I updated the CHANGELOG under ## [Unreleased]
  • If the change touches the MCP tool contract (new tool, new arg, new error code) I updated the tool description in mcp_server.py and the relevant tests in test_mcp_server.py (not touched)
  • If this is a breaking change I called it out under ## Summary above and suggested a migration path (not breaking)

Related issues / discussions

This touches the same CHANGELOG.md section as #356 and #357, so whichever lands later may need a one-line rebase.

This change was written with the help of an AI assistant (Claude); I reviewed and tested it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • GitHub and SARIF reports now use paths relative to the working directory when scanning a subdirectory. This helps GitHub place annotations on the corresponding lines in a pull request.
    • Paths outside the working directory retain their existing fallback behavior.

…ubdirectory --path

GitHub resolves annotation and SARIF paths against the checkout root. With
--path backend, nplusone wrote shop/views.py, and an absolute --path did the
same for migration-risk and blast-radius. Write files under the working
directory relative to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The GitHub and SARIF formatters now resolve annotation paths relative to the working directory when possible. The CLI passes the selected scan path to the N+1 formatters. Tests cover relative and absolute subdirectory roots.

Changes: Annotation path handling

Layer / File(s) Summary
Path resolution and formatter output
cli/orm_lens/ci_formats.py
The formatters prefer checkout-relative paths for files within the working directory. N+1 formatter functions now accept an optional root and use it to resolve finding paths.
CLI wiring and path tests
cli/orm_lens/cli.py, cli/tests/test_ci_formats.py, cli/tests/test_blast_radius.py, CHANGELOG.md
The CLI passes args.path to the N+1 formatters. Tests cover relative and absolute subdirectory roots and run the blast-radius annotation test from its fixture directory. The changelog records the path behavior.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: frowningdev

Merge Risk: Minimal · up to 8f75b

This change makes GitHub and SARIF annotation paths checkout-relative when a subdirectory is scanned, so annotations can land on the PR diff. The default path behavior is unchanged, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: N+1 SARIF and GitHub annotation files are named from the checkout root when --path selects a subdirectory. The raw summary confirms the changes to ci_formats.py, cli.py, an…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: N+1 SARIF and GitHub annotation files are named from the checkout root when --path selects a subdirectory. The raw summary confirms the changes to ci_formats.py, cli.py, and the tests, and the objectives describe the same fix. The title is specific and follows the conventional-commit style, so it matches the primary change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 75eb68c3-a89f-4bc5-8ddc-278895354db4
Commits

Reviewing files that changed from the base of the PR and between 68faafa and 8f75bb8.

Files selected for processing: 5

  • CHANGELOG.md
  • cli/orm_lens/ci_formats.py
  • cli/orm_lens/cli.py
  • cli/tests/test_blast_radius.py
  • cli/tests/test_ci_formats.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@FROWNINGdev
FROWNINGdev merged commit 1b56083 into FROWNINGdev:main Nov 24, 2026
20 checks passed
FROWNINGdev added a commit that referenced this pull request Nov 24, 2026
py-1.18.4: migration-risk --only and the staged-files pre-commit hook (#355), positional operation arguments (#359), abstract-base fields in scan and ER (#354), ER fixes for SQLAlchemy keys and same-named models (#356, #357), checkout-relative annotation paths (#358).

0.22.4: the ER view and hover cards show fields from abstract bases (#354).

Co-authored-by: FROWNINGdev <[email protected]>
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