Implement the following plan: Fix: Impact evaluation ignores remediation patch…
- User
Implement the following plan:
Fix: Impact evaluation ignores remediation patch (re-clones fresh repo)
Context
When clicking "Evaluate Impact" on a remediation, the impact evaluation finds only pre-existing repo files and misses all 8 files created by the remediation patch. The root cause is that the evaluation engine re-clones the repo from scratch instead of using the already-patched local directory.
Two bugs identified:
-
Primary:
engine.tsprioritizesrepositoryUrloverlocalPath. The impact evaluation submits both (localPath=patched clone, repositoryUrl=for metadata), but the engine re-clones from the URL, creating a fresh repo without the patch. -
Secondary: File finder glob
*.instructions.mddoesn't match remediation-generated.mdfiles in.github/instructions/. Even after fix #1, 5 of 8 Copilot instruction files won't be discovered.
Fix 1: Engine should prioritize
localPathoverrepositoryUrlFile:
src/shared/evaluation/engine.ts(line 680)Change the order of checks so
localPathtakes precedence:typescript// Before (buggy): if (request.repositoryUrl) { // Clones fresh — ignores localPath entirely } else if (request.localPath) { workingDir = resolve(request.localPath); } // After (fixed): if (request.localPath) { workingDir = resolve(request.localPath); } else if (request.repositoryUrl) { // Clone repository to temp directory const cloneResult = await cloneRepository(...); workingDir = cloneResult.path; cleanup = cloneResult.cleanup; }Also update the
gitMetadatablock (lines 704-712) to still capturerepositoryUrlfrom the request even when localPath is used, since the impact evaluation needs it for the evaluation record.Fix 2: Update remediation prompt to use
.instructions.mdextensionFile:
src/shared/remediation/prompt-generator.ts(line 356) -
Assistant
I'll start by reading the three files that need modification in parallel.
Assistant
Now let me read the
isCopilotInstructionsFilefunction.Assistant
Good, I have all the context I need. Let me now create the task list and implement all three fixes.
Assistant
Fix 1: Engine — prioritize
localPathoverrepositoryUrlAssistant
Let me read the exact content with proper indentation.
Assistant
Now update the
gitMetadatablock to capturerepositoryUrleven whenlocalPathis used.Assistant
The
gitMetadatablock already correctly capturesrepositoryUrlfrom the request regardless of which path is used, andlocalPathis set fromrequest.localPathwhen present. No change needed there.Assistant
Fix 2: Prompt generator — use
.instructions.mdextensionAssistant
Fix 3: File finder — add
.mdglob and updateisCopilotInstructionsFileAssistant
Now update the
allFilescombination to include the new glob results (deduplicated).Assistant
Now update
isCopilotInstructionsFileto also match plain.mdfiles in.github/instructions/.Assistant
Task 4: Add tests and verify
Let me find existing test files for these modules.
Assistant
Let me read the existing test files for file-finder and prompt-generator to understand the patterns.
Assistant
Good. Now I know the test patterns. I need to:
- Add a test for
.mdfiles in.github/instructions/tofile-finder.test.ts - Update the prompt-generator test that checks for
.mdextension to expect.instructions.md - No engine test file exists — but the fix is straightforward and tested by verifying the behavior through the file-finder tests
Let me read the specific prompt-generator test that needs updating.
- Add a test for
Assistant
Now let me add tests in
file-finder.test.tsfor plain.mdfiles in.github/instructions/. Let me find where the existing copilot instructions tests end.Assistant
I'll add the new test for plain
.mdfiles right after the existing instructions tests (before line 593).Assistant
Now let's run the tests to verify everything passes.
Assistant
All 1321 tests pass. Let me also run lint.
Assistant
Now verify lint and tests pass.
Assistant
All 1321 tests pass and lint is clean.
Assistant
All three fixes are implemented and verified:
Fix 1 —
engine.ts: Swapped thelocalPath/repositoryUrlpriority so when both are provided (impact evaluation), the engine uses the already-patched local directory instead of re-cloning a fresh repo.Fix 2 —
prompt-generator.ts: Changed the GitHub Copilot remediation prompt to generate files with.instructions.mdextension (matching the file finder's glob and GitHub Copilot convention).Fix 3 —
file-finder.ts: Added a second glob for**/.github/instructions/**/*.md(backward compat for older patches that used plain.md), with deduplication viaSetto avoid double-counting files that match both globs. Also updatedisCopilotInstructionsFile()to recognize plain.mdfiles in.github/instructions/.Tests: Added 2 new test cases for plain
.mddiscovery in.github/instructions/, updated the prompt-generator test expectation. All 1321 tests pass, lint clean.