[UPDATE PRIMITIVE] sarif_diff_by_commits — refRange validation, file path improvement, test mock fix#242
Merged
data-douser merged 3 commits intocopilot/add-sarif-to-git-diff-toolfrom Apr 12, 2026
Conversation
…ol' into copilot/fix-code-for-review-comments Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
…le, test mocking 1. Validate refRange in sarif_diff_by_commits to reject strings starting with '-' or containing whitespace (prevents git option injection). 2. Use matchingDiff.path for ClassifiedResult.file when a diff match exists, falling back to normalizeUri(uri) only for unmatched results (produces repo-relative paths instead of long file:// URI paths). 3. Replace vi.doMock with module-scope vi.mock + shared mockExecuteCLICommand to prevent module-cache flakiness in sarif_diff_by_commits handler tests. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1960960b-9658-44b5-87d8-bc29cc55a5ef Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix code according to review comments
[UPDATE PRIMITIVE] Apr 12, 2026
sarif_diff_by_commits — refRange validation, file path improvement, test mock fix
data-douser
added a commit
that referenced
this pull request
Apr 13, 2026
…e path improvement, test mock fix (#242) * Initial plan * Fix PR #236 review comments: refRange validation, ClassifiedResult.file, test mocking 1. Validate refRange in sarif_diff_by_commits to reject strings starting with '-' or containing whitespace (prevents git option injection). 2. Use matchingDiff.path for ClassifiedResult.file when a diff match exists, falling back to normalizeUri(uri) only for unmatched results (produces repo-relative paths instead of long file:// URI paths). 3. Replace vi.doMock with module-scope vi.mock + shared mockExecuteCLICommand to prevent module-cache flakiness in sarif_diff_by_commits handler tests. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1960960b-9658-44b5-87d8-bc29cc55a5ef Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
data-douser
added a commit
that referenced
this pull request
Apr 13, 2026
…on tool (#236) * Initial plan * feat: add sarif_diff_by_commits tool for SARIF-to-git-diff correlation Implements a new MCP tool that accepts a SARIF file path and git ref range, partitions SARIF results into "new" vs "pre-existing" based on file-level or line-level overlap with the git diff, and returns structured output for triage workflows. - Add diffSarifByCommits() pure utility in sarif-utils.ts with types - Register sarif_diff_by_commits tool in sarif-tools.ts - Add parseGitDiffOutput() helper for unified diff parsing - Add 14 unit tests for diffSarifByCommits() utility - Add 5 unit tests for sarif_diff_by_commits tool handler - Update server-tools.md documentation - Update tool registration count from 7 to 8 Closes #209 Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/8abb21bb-8877-4628-90da-36ffc8eeb742 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * feat: add client integration test for sarif_diff_by_commits - Add sarif_diff_by_commits case to Go params.go test runner - Add Go unit test for param resolution (params_test.go) - Create file_level_classification integration test fixture with: - SARIF with 3 results across 2 rules - HEAD..HEAD ref range (empty diff → all pre-existing) - Assertions validating totalNew=0, totalPreExisting=3 - before/after directories with SARIF and monitoring state Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/edb1fae4-1f49-44f9-af31-71483b674da7 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Apply lint/format & rebuild server/dist/ * [UPDATE PRIMITIVE] `sarif_diff_by_commits` — refRange validation, file path improvement, test mock fix (#242) * Initial plan * Fix PR #236 review comments: refRange validation, ClassifiedResult.file, test mocking 1. Validate refRange in sarif_diff_by_commits to reject strings starting with '-' or containing whitespace (prevents git option injection). 2. Use matchingDiff.path for ClassifiedResult.file when a diff match exists, falling back to normalizeUri(uri) only for unmatched results (produces repo-relative paths instead of long file:// URI paths). 3. Replace vi.doMock with module-scope vi.mock + shared mockExecuteCLICommand to prevent module-cache flakiness in sarif_diff_by_commits handler tests. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1960960b-9658-44b5-87d8-bc29cc55a5ef Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> * Extend client tests -> sarif_diff_by_commits tool * fix: address unresolved PR review comments - Fix deletion-only hunk misclassification in line-level granularity by adding hunksParsed flag to DiffFileEntry; parseGitDiffOutput sets it when @@ headers are seen, and diffSarifByCommits uses it to distinguish "no hunk info" from "deletion-only" diffs - Precompute normalized diff paths once before the results loop, removing the unused diffPathMatchesSarifUri wrapper - Migrate all params_test.go from t.TempDir() to project-local .tmp/ - Add regression tests for deletion-only diffs in unit and handler tests --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com> Co-authored-by: Nathan Randall <data-douser@github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Update Information
Primitive Details
sarif_diff_by_commitssarif_diff_by_commits— SARIF-to-git-diff correlation tool #236)✅ ALLOWED FILES:
server/src/**/*.ts)server/src/lib/*.ts)server/test/**/*.ts)🚫 FORBIDDEN FILES: None included.
🛑 MANDATORY PR VALIDATION CHECKLIST
🎯 Changes Description
Addresses three review comments from PR #236 review.
Current Behavior
refRangepassed directly togit diffwithout validation — a value like--optionis interpreted as a git flagClassifiedResult.filealways usesnormalizeUri(uri), producinghome/user/project/src/db.jsforfile:///URIs even when a diff match provides the repo-relative pathvi.doMockper-test forcli-executor, but the dynamicimport()in the handler caches the module after the first call — later tests may silently reuse stale mocksUpdated Behavior
refRangeis validated before use: rejects values starting with-or containing whitespaceClassifiedResult.fileusesmatchingDiff.pathwhen matched (repo-relative), falls back tonormalizeUri(uri)only for unmatched resultsvi.mockwith sharedmockExecuteCLICommandconfigured per-testMotivation
Review feedback on PR #236.
🔄 Before vs. After Comparison
Functionality Changes
🧪 Testing & Validation
Test Coverage Updates
file://URI test to assert diff path is usedTest Results
📋 Implementation Details
Files Modified
server/src/tools/sarif-tools.ts— refRange validationserver/src/lib/sarif-utils.ts—ClassifiedResult.filepath logicserver/test/src/tools/sarif-tools.test.ts— mock pattern + validation testsserver/test/src/lib/sarif-utils.test.ts— file path assertionsDependencies
🔗 References
Related Issues/PRs
sarif_diff_by_commits— SARIF-to-git-diff correlation tool #236🚀 Compatibility & Migration
Backward Compatibility
ClassifiedResult.filenow returns shorter repo-relative paths when a diff match exists. Consumers comparing againstnormalizeUri()output for matched results may see different values — but the new values are strictly more useful (and what the PR description already documented as the expected format).API Evolution
refRange👥 Review Guidelines
For Reviewers
Testing Instructions
npm run build-and-test # Targeted tests npx vitest run server/test/src/tools/sarif-tools.test.ts server/test/src/lib/sarif-utils.test.ts📊 Impact Assessment
Server Impact
🔄 Deployment Strategy
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
update.code.visualstudio.com/opt/hostedtoolcache/node/24.13.0/x64/bin/node node scripts/download-vscode.js -tests/primitive--unified=0(dns block)If you need me to access, download, or install something from one of these locations, you can either: