Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

The formatPatch function's headerOptions parameter was only tested indirectly through createTwoFilesPatch. This adds explicit tests for consumers calling formatPatch directly.

Changes

  • Added 7 test cases under #formatPatchwith headerOptions parameter:
    • INCLUDE_HEADERS with different file names (no Index line)
    • INCLUDE_HEADERS with same file name (includes Index line)
    • FILE_HEADERS_ONLY (file headers only, no Index/underline)
    • OMIT_HEADERS (hunks only)
    • Array handling for each of the three options
  • Extracted shared test data to reduce duplication

Example

const patch = structuredPatch('old', 'new', 'foo\n', 'bar\n');

formatPatch(patch, INCLUDE_HEADERS);
// Index: old
// ===================================================================
// --- old
// +++ new
// @@ -1,1 +1,1 @@
// -foo
// +bar

formatPatch(patch, FILE_HEADERS_ONLY);
// --- old
// +++ new
// @@ -1,1 +1,1 @@
// -foo
// +bar

formatPatch(patch, OMIT_HEADERS);
// @@ -1,1 +1,1 @@
// -foo
// +bar

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI self-assigned this Dec 31, 2025
Copilot AI and others added 2 commits December 31, 2025 14:39
Co-authored-by: ExplodingCabbage <2358339+ExplodingCabbage@users.noreply.github.com>
Co-authored-by: ExplodingCabbage <2358339+ExplodingCabbage@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on custom file headers in patches PR Add direct test coverage for formatPatch with headerOptions parameter Dec 31, 2025
Comment on lines 1208 to 1214
'@@ -1,1 +1,1 @@\n' +
'-a\n' +
'+b\n' +
'\n' +
'@@ -1,1 +1,1 @@\n' +
'-x\n' +
'+y\n';
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is obviously stupid, but @copilot writing it was nonetheless useful in that it brought the obviously stupid behaviour to my attention. I should be throwing an error in this scenario.

@ExplodingCabbage ExplodingCabbage marked this pull request as ready for review December 31, 2025 15:09
@ExplodingCabbage ExplodingCabbage merged commit 537210e into omit-headers Dec 31, 2025
ExplodingCabbage added a commit that referenced this pull request Dec 31, 2025
* Add support for omitting headers

* Fix some wonky pre-existing formatting

* Document new options

* Proofread & tweak

* Further proofread

* Another tweak - I guess not every Unix machine uses GNU patch, and I am quoting from the docs for the GNU version

* Language tweak

* More detail

* Export HeaderOptions interface

* Fix docs gap

* Add direct test coverage for formatPatch with headerOptions parameter (#642)

* Initial plan

* Add direct test coverage for formatPatch with headerOptions

Co-authored-by: ExplodingCabbage <2358339+ExplodingCabbage@users.noreply.github.com>

* Refactor: Extract common patch array to reduce duplication

Co-authored-by: ExplodingCabbage <2358339+ExplodingCabbage@users.noreply.github.com>

* Remove redundant test (covered entirely below)

* Make test for multiple patches with OMIT_HEADERS demand sensible behaviour (which we don't yet provide)

* Fix behaviour

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ExplodingCabbage <2358339+ExplodingCabbage@users.noreply.github.com>
Co-authored-by: Mark Amery <markrobertamery@gmail.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ExplodingCabbage <2358339+ExplodingCabbage@users.noreply.github.com>
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.

2 participants