Skip to content

fix: keep data-shape grep paths color-stable#860

Merged
RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
pollychen-lab:fix/issue-858-grep-no-color
Jul 21, 2026
Merged

fix: keep data-shape grep paths color-stable#860
RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
pollychen-lab:fix/issue-858-grep-no-color

Conversation

@pollychen-lab

@pollychen-lab pollychen-lab commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add --no-color to the parsed git grep -l call used by data-shape mining, with a comment explaining why the flag is load-bearing
  • add a regression test for repositories with color.ui=always
  • include the test-only import subprocess, move build_exclude_spec above the repowise.server import to satisfy isort, and rewrite one existing assertion into the conventional left-hand actual form

Why

_grep_identifier_files parses git grep -l output as repo-relative paths. When a user has color.ui=always, Git can wrap those paths in ANSI escape codes, which prevents exclusion checks and file reads from matching the real paths.

Fixes #858.

Validation

  • .venv/bin/python -m pytest tests/unit/server/mcp/test_answer_data_shape.py
  • .venv/bin/python -m ruff check packages/server/src/repowise/server/mcp_server/tool_answer/data_shape.py tests/unit/server/mcp/test_answer_data_shape.py
  • git diff --check

@repowise-bot

repowise-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

✅ Health: 7.5 (unchanged)

📋 At a glance
2 hotspots touched · 1 new finding introduced · 2 files with recent fix history.

Files & modules (2)
  • packages (1 file)
    • .../tool_answer/data_shape.py
  • tests (1 file)
    • .../mcp/test_answer_data_shape.py

🗺️ Change map

flowchart LR
  subgraph PR ["Changed in this PR (1 with dependents)"]
    f_packages_server_src_repowise_server_mcp_server_tool_answer_data_shape_py[".../tool_answer/data_shape.py 🔥"]:::changed
  end
  f_packages_server_src_repowise_server_mcp_server_tool_answer_answer_py[".../tool_answer/answer.py"]
  f_packages_server_src_repowise_server_mcp_server_tool_answer_data_shape_py --> f_packages_server_src_repowise_server_mcp_server_tool_answer_answer_py
  classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
  classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
  classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Loading

Solid arrows: code that imports the changed files (1 direct dependent, from the last indexed snapshot). Dashed: history/tests.

🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)

🔎 More signals (1)

🔥 Hotspots touched (2)

  • .../mcp/test_answer_data_shape.py — 3 commits/90d, 0 dependents · primary owner: Raghav Chamadiya (86%)
  • .../tool_answer/data_shape.py — 3 commits/90d, 2 dependents · primary owner: Raghav Chamadiya (96%)

📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-20 12:58 UTC
Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot

@RaghavChamadiya

Copy link
Copy Markdown
Member

Thanks for this, and good catch on the two ruff errors while you were in here. The Yoda flip and the import sort look like unrelated drive-bys but they're pre-existing violations that came in with #856, so this PR is currently the only thing standing between main and a clean ruff check on that file. Happy to take them.

I verified the fix reverts cleanly: with the --no-color line taken back out, your new test fails, and it passes with it in. I also confirmed the underlying behaviour independently. git grep -l returns ^[[35mpkg/models.py^[[m under color.ui=always, and putting the flag before *args means it covers the --no-index retry path too, which is the branch the exclusion filter from #856 actually depends on.

One ask before I merge. Could you add the comment from #825 alongside the flag?

# --no-color: this output is parsed, so a user's
# ``color.ui=always`` git config must not wrap paths in ANSI
# escapes (which would corrupt the path split below).
"--no-color",

The reason I'm fussy about it: this flag is load-bearing for the #856 exclusion filter, and when it's missing the failure is silent rather than loud. A comment-free --no-color in an arg list is exactly the kind of thing that gets tidied away by someone who has no reason to think it matters, which is how the sibling call site survived #825 in the first place. Cheap insurance against a third round of this.

Push that up and I'll merge. Thanks again.

"git",
"--no-pager",
"grep",
"--no-color",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix itself is correct, and I verified by hand that this flag suppresses the escape codes both for color.ui = always and for the narrower color.grep = always, and that it also covers the --no-index fallback on line 198, because both paths run through this same helper.

Could you add a short comment explaining why the flag is here, in the same style as the surrounding code? The comment on lines 152 to 154 explains why --no-pager and the stdin redirect are load-bearing, and the sibling call site in _code_rationale.py explains its own --no-color on lines 390 to 392. Something like the following would match both:

                # --no-color: this output is parsed, so a user's
                # ``color.ui=always`` git config must not wrap paths in ANSI
                # escapes (which would corrupt exclusion filtering and reads).
                "--no-color",

Without it there is nothing stopping a future clean-up from deleting the flag and silently reintroducing this bug, which is more or less how we ended up with issue #858 in the first place.

@swati510

Copy link
Copy Markdown
Collaborator

Your branch is currently eighty-two commits behind main. Everything passes as it stands, but would you mind rebasing onto current main so continuous integration runs against the tree this will actually land on?

Also, a small note for the description: alongside the fix, this pull request adds an import subprocess that the new test needs, moves the from repowise.core.exclusion import build_exclude_spec import above the repowise.server import, and rewrites one existing assertion into a more conventional form. The import move is worth having, because main currently fails ruff's isort rule on that block, so the change is a lint fix rather than a matter of taste. All three are fine and I am happy to keep them, but they are worth calling out so a reviewer is not surprised by the extra lines in the diff.

@pollychen-lab
pollychen-lab force-pushed the fix/issue-858-grep-no-color branch from 8cbe465 to c956e98 Compare July 20, 2026 12:58

@RaghavChamadiya RaghavChamadiya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@RaghavChamadiya
RaghavChamadiya merged commit 42d7e83 into repowise-dev:main Jul 21, 2026
7 checks passed
@pollychen-lab

Copy link
Copy Markdown
Contributor Author

@swati510 @RaghavChamadiya thank you

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.

[Bug] data_shape live-grep: add --no-color so exclusion filter survives color.ui=always

3 participants