Skip to content

Skip content exclusion checks for apply_patch Add File - #337324

Merged
Logan Ramos (lramos15) merged 4 commits into
microsoft:mainfrom
monil-patel:fix-apply-patch-add-exclusion
Sep 24, 2026
Merged

Logan Ramos (lramos15) merged 4 commits into
microsoft:mainfrom
monil-patel:fix-apply-patch-add-exclusion

Conversation

@monil-patel

@monil-patel monil-patel commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

apply_patch can reject *** Add File operations when a repository has Copilot exclusions configured because the target does not exist yet.

This change makes apply_patch Add File behavior consistent with create_file:

  • Continue to enforce allowedEditUris for every target.
  • Reject Add File when the target already exists.
  • Skip content-exclusion checks only after confirming that the Add File target does not exist.
  • Preserve existing exclusion checks for UPDATE, DELETE, and move operations.

Testing

  • npm run typecheck
  • npm run test:unit -- src/extension/tools/test/node/applyPatch/applyPatch.spec.tsx

Added focused unit tests that verify:

  • Add File succeeds without calling IIgnoreService.isCopilotIgnored.
  • Add File outside allowedEditUris remains rejected before edits.
  • Add File rejects an existing target without emitting edits.
  • UPDATE operations continue to call the ignore service.
  • Existing move tests continue to pass.
Test Files  1 passed
Tests       13 passed

Fixes #337528

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 22, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The critical exclusion bypass for existing files must be fixed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Updates apply_patch to permit new-file additions under content-based exclusion rules while retaining URI restrictions.

Changes:

  • Skips exclusion checks for non-move ADD actions.
  • Adds focused regression tests.
File Review
extensions/​copilot/​src/​extension/​tools/​test/​node/​applyPatch/​applyPatch.spec.tsx Adds coverage for additions, URI restrictions, updates, and moves.
extensions/​copilot/​src/​extension/​tools/​node/​applyPatchTool.tsx Critical: ADD can target an existing excluded file and bypass exclusion checks; verify nonexistence or reject the operation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 290 to 294
// Match create_file: model-created files skip content exclusion checks.
if (!movePath && changes.type === ActionType.ADD) {
continue;
}
await this.instantiationService.invokeFunction(accessor => assertFileNotContentExcluded(accessor, uri, undefined, contents));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 94e948a. Add File now checks the target with IFileSystemService.stat() and rejects an existing file before skipping content exclusion. I also added a regression test with the existing target registered in the mock filesystem. The focused suite passes all 13 tests.

monil-patel and others added 2 commits September 22, 2026 14:59
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@monil-patel

Copy link
Copy Markdown
Contributor Author

The remaining Linux / Electron-Smoke failure is an infrastructure timeout: the smoke-test step reached the workflow 20-minute limit without an assertion or code error. All compile, Copilot, unit, browser, remote, macOS, and Windows checks passed. I cannot rerun the job from a fork because GitHub requires repository admin rights. Please rerun the failed job when convenient.

@monil-patel
monil-patel marked this pull request as ready for review September 23, 2026 21:02
@monil-patel monil-patel changed the title Fix apply_patch Add File content exclusion Skip content exclusion checks for apply_patch Add File Sep 23, 2026
@lramos15
Logan Ramos (lramos15) enabled auto-merge (squash) September 24, 2026 15:19
@lramos15
Logan Ramos (lramos15) merged commit 13dcab0 into microsoft:main Sep 24, 2026
33 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.140.0 milestone Sep 24, 2026
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.

apply_patch cannot create files when exclusions are configured

5 participants