Refactor duplicated DIFC LabeledResource parsing in WASM guard response handling by Copilot · Pull Request #8194 · github/gh-aw-mcpg · GitHub
Skip to content

Refactor duplicated DIFC LabeledResource parsing in WASM guard response handling#8194

Merged
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-labeledresource-parsing
Jun 27, 2026
Merged

Refactor duplicated DIFC LabeledResource parsing in WASM guard response handling#8194
lpcox merged 2 commits into
mainfrom
copilot/duplicate-code-labeledresource-parsing

Conversation

Copilot AI commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

internal/guard/wasm_parse.go had duplicated logic for populating description, secrecy, and integrity on difc.LabeledResource in both resource-level and collection-level parsing paths. In a DIFC enforcement path, this duplication increases drift risk when parsing behavior changes.

  • Parsing logic consolidation

    • Added fillLabeledResourceFromMap(rawData map[string]any, resource *difc.LabeledResource) to centralize description/secrecy/integrity extraction and default label initialization.
  • Call-site simplification

    • Updated parseResourceResponse to delegate resource field population to the helper.
    • Updated parseCollectionLabeledData item-label parsing to reuse the same helper.
  • Behavior lock-in via focused tests

    • Added TestFillLabeledResourceFromMap cases for:
      • full population (description, secrecy, integrity)
      • default empty labels when fields are missing or typed incorrectly
resource := &difc.LabeledResource{}
fillLabeledResourceFromMap(resourceData, resource)

// ...

labels := &difc.LabeledResource{}
fillLabeledResourceFromMap(labelsData, labels)

GitHub Advanced Security started work on behalf of lpcox June 27, 2026 15:53 View session
GitHub Advanced Security finished work on behalf of lpcox June 27, 2026 15:55
Copilot AI changed the title [WIP] Refactor duplicate code for LabeledResource field parsing Refactor duplicated DIFC LabeledResource parsing in WASM guard response handling Jun 27, 2026
Copilot finished work on behalf of lpcox June 27, 2026 15:59
Copilot AI requested a review from lpcox June 27, 2026 15:59
GitHub Advanced Security started work on behalf of lpcox June 27, 2026 16:00 View session
GitHub Advanced Security finished work on behalf of lpcox June 27, 2026 16:00
@lpcox lpcox marked this pull request as ready for review June 27, 2026 16:30
Copilot AI review requested due to automatic review settings June 27, 2026 16:30

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.

Pull request overview

This PR refactors WASM guard response parsing to eliminate duplicated DIFC LabeledResource field-extraction logic, reducing drift risk between single-resource and collection parsing paths.

Changes:

  • Introduces fillLabeledResourceFromMap to centralize description/secrecy/integrity extraction and default label initialization.
  • Updates both parseResourceResponse and parseCollectionLabeledData to delegate label population to the shared helper.
  • Adds focused unit tests to lock in helper behavior for fully-populated and missing/invalid fields.
Show a summary per file
File Description
internal/guard/wasm_parse.go Consolidates labeled resource field parsing into a shared helper and updates both parsing call sites to reuse it.
internal/guard/wasm_response_parse_test.go Adds unit tests covering the new helper’s population and defaulting behavior.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@lpcox lpcox merged commit 0efa506 into main Jun 27, 2026
34 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-labeledresource-parsing branch June 27, 2026 16:37
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.

3 participants