Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Overview

This PR implements the x-copy behavior changes from OAI Overlay Specification PR #150, which requires that the copy JSON path expression must match exactly one result, and all targets receive the same source value.

Changes

Behavioral Changes

Previous behavior:

  • Copy JSON path could match multiple results
  • Targets and copy sources were paired sequentially (1-to-1 matching)
  • Example: If target matched 2 nodes and copy matched 2 nodes, they were paired as target[0]←copy[0], target[1]←copy[1]

New behavior:

  • Copy JSON path must match exactly one result
  • All matching targets receive the same source value
  • Example: If target matches 3 nodes and copy matches 1 node, all targets receive that single source: target[0]←copy[0], target[1]←copy[0], target[2]←copy[0]

Implementation Details

Modified CopyNodes method in src/lib/Models/OverlayAction.cs:

  • Added validation to ensure copyParseResult.Matches.Count == 1
  • Removed sequential pairing logic
  • Simplified copy operation to use single source for all targets
  • Updated error messages to clearly indicate exact match requirement
// New validation
if (copyParseResult.Matches.Count != 1)
{
    overlayDiagnostic.Errors.Add(new OpenApiError(GetPointer(index), 
        $"Copy JSON Path '{Copy}' must match exactly one result, but matched {copyParseResult.Matches.Count}"));
    return false;
}

// Simplified copy logic - single source to all targets
foreach (var match in matchValues)
{
    MergeJsonNode(match!, copyMatch, overlayDiagnostic);
}

Test Updates

Updated existing tests (4):

  • Modified ApplyToDocument_ShouldCopyMultipleMatches to test single source → multiple targets
  • Renamed and repurposed ApplyToDocument_CopyShouldFailWhenMatchCountsDiffer to ApplyToDocument_CopyShouldFailWhenCopyHasMultipleMatches
  • Updated error message expectations in ApplyToDocument_CopyShouldFailWhenCopyTargetHasNoMatches and ApplyToDocument_CopyShouldFailWhenCopyTargetNotFound

Added new tests (4):

  • ApplyToDocument_CopyShouldCopySingleSourceToMultipleTargets - Validates copying single source to 3 targets
  • ApplyToDocument_CopyShouldFailWhenCopyMatchesZeroResults - Validates rejection when copy path matches 0 results
  • ApplyToDocument_CopyShouldFailWhenCopyMatchesTwoResults - Validates rejection when copy path matches 2 results
  • ApplyToDocument_CopyShouldSucceedWithExactlyOneMatch - Validates success with exactly 1 match

Testing

  • ✅ All 55 tests passing (53 library + 2 CLI)
  • ✅ CodeQL security scan: 0 vulnerabilities
  • ✅ Clean build with no warnings

Breaking Change

This is a breaking change for users who rely on the previous sequential copy behavior with multiple copy source matches. The copy JSON path expression must now match exactly one result.

Closes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>x-copy behavior changes</issue_title>
<issue_description>The specification PR OAI/Overlay-Specification#150 is making good progress.

One of the notable behavior changes is that the copy JSON path expression MUST only match a single object/array, and there's no sequential copy of copy results to target results anymore. (all targets will use the same source)

We need to update the implementation to reflect that:

  • throw an error of the copy json path expression results in anything else than a single result.
  • add unit tests to validate that behavior.
  • replace the sequential copy in copy nodes by a single source
  • update impacted unit tests</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #120


💡 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 and others added 2 commits October 21, 2025 19:43
- Modified CopyNodes method to enforce exactly one copy source match
- Updated error messages to reflect new validation requirements
- Changed logic to copy same source to all targets (removed sequential pairing)
- Updated existing tests that expected old sequential copy behavior
- Added 4 new unit tests to validate single copy source requirement
- All 53 tests now passing

Co-authored-by: baywet <[email protected]>
Copilot AI changed the title [WIP] Update x-copy behavior for JSON path expression Update x-copy behavior to require single source match per specification PR #150 Oct 21, 2025
Copilot AI requested a review from baywet October 21, 2025 19:52
Copilot finished work on behalf of baywet October 21, 2025 19:52
@baywet baywet marked this pull request as ready for review October 21, 2025 19:55
@baywet baywet requested a review from a team as a code owner October 21, 2025 19:55
@baywet baywet enabled auto-merge October 21, 2025 19:55
@baywet baywet disabled auto-merge October 21, 2025 19:57
@baywet baywet enabled auto-merge (squash) October 21, 2025 19:58
@baywet baywet merged commit 8263215 into main Oct 21, 2025
8 checks passed
@baywet baywet deleted the copilot/update-x-copy-behavior branch October 21, 2025 20:03
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.

x-copy behavior changes

3 participants