Repository navigation
fix(doctor): commit the --deep probe file so scan_file's git diff succeeds (PPSC-1799) - #347
Conversation
…ceeds (PPSC-1799) The --deep scratch repo was created with git init only, so the scanner's git diff HEAD failed with "bad revision 'HEAD'" on every run, logged a warning to server.log, and skipped the changed-line path an editor scan takes. Commit an empty probe file, then write the probe code as an uncommitted edit. The scratch commit ignores the user's identity, signing and hooks settings so they can't break it.
There was a problem hiding this comment.
🟢 Approval recommended
It is a small, isolated, best-effort bug fix whose core behavior and cross-platform -c config handling I verified directly, with accompanying test coverage and no identified issues.
No open issues 🎉
What changed in this PR
This PR fixes a bug in armis-cli mcp doctor --deep. The deep probe scans a throwaway file to exercise the MCP server's real scan_file path, which runs git diff HEAD -- <file> to find edited lines. Previously the scratch repo was created with only git init (no commit), so git diff HEAD failed with fatal: bad revision 'HEAD', the scan silently fell back to scanning the whole file, and users watching mcp doctor --watch saw a spurious git failure originating from the doctor's own probe. The fix seeds the scratch repo with an empty committed probe file before writing the probe code as an uncommitted change, so git diff HEAD succeeds and returns the probe's lines as additions.
Changes:
- Extract repo setup into
initDeepProbeRepo, which runsgit init, commits an emptyarmis_doctor_probe.py, then lets the probe content be written as an uncommitted edit. - Harden the scratch commit against hostile global git config via
-coverrides (identity,commit.gpgsign=false, nonexistentcore.hooksPath) and--no-verify; keep setup best-effort with a single 10s context covering all three git calls. - Add
TestDeepProbeFileDiffsAgainstHEAD, which forces a signing-required global config plus a failing pre-commit hook and assertsgit diff HEADsucceeds with the probe content as added lines and thatclose()removes the dir.
| File | Description |
|---|---|
| internal/install/doctor.go | Adds deepProbeName + initDeepProbeRepo to commit an empty probe file so git diff HEAD succeeds; updates the deepProbeFile doc comment. |
| internal/install/doctor_stall_test.go | New test verifying the probe repo diffs against HEAD under a hostile global git config and that close() cleans up. |
Review effort: Balanced
Related Issue
Type of Change
Problem
mcp doctor --deepscans a throwaway file to test the realscan_filepath. The scratch repo was created withgit initonly, so it had no commit. The scanner runsgit diff HEAD -- <file>to find the changed lines, and that failed on every run:The scan then fell back to scanning the whole file. So the probe never took the path an editor scan takes for an edited file in a repo, and anyone following
mcp doctor --watchsaw a git failure that came from the doctor's own probe. I found this while verifying main against v1.25.0.Solution
initDeepProbeReponow runsgit init, commits an emptyarmis_doctor_probe.py, and then the probe code is written as an uncommitted change.git diff HEADnow succeeds and returns the probe's two lines as additions.The scratch commit sets its own identity,
commit.gpgsign=false, a nonexistentcore.hooksPath, and--no-verify. That way a machine with no git identity, required signing, or global hooks (including an Armis scan hook) can't break it. Setup is still best effort: if git is missing or a step fails, the scan falls back as before.Testing
Automated Tests
TestDeepProbeFileDiffsAgainstHEADpointsGIT_CONFIG_GLOBALat a config that requires signing and has a pre-commit hook that always fails. It then checks thatgit diff HEADin the probe repo exits 0 and shows the probe content as added lines, and thatclose()removes the directory. On unfixed main the test fails withfatal: bad revision 'HEAD'.go test ./...: 3695 passed, 0 failed, 4 skipped.make lint: 0 issues.make build: OK.Manual Testing
Built the branch and ran it in a sandboxed HOME (no
.gitconfig) against the prod API, with MCP server v1.4.1 installed for Cursor:armis-cli install cursor --non-interactive, thenarmis-cli mcp doctor --deep --verbose: 15 passed, 0 warnings, 0 failed, andscan_file succeeded in 2.32s.server.logshowsRunning: git diff HEAD --diff-filter=d --no-ext-diff -U0 -- armis_doctor_probe.pywith nogit diff failedwarning. Before the fix, every--deeprun logged that warning once per editor..armis-doctor-*scratch directory is gone after the run.Reviewer Notes
--deephasn't been released yet and is already under Unreleased in the CHANGELOG, so this PR doesn't add a separate entry.git initcall now covers all three git calls.Checklist
Screenshots (if applicable)
N/A