fix(middleware): resolve CompileToolResponseFilter/WithVars structural duplication by Copilot · Pull Request #8602 · github/gh-aw-mcpg · GitHub
Skip to content

fix(middleware): resolve CompileToolResponseFilter/WithVars structural duplication#8602

Closed
lpcox with Copilot wants to merge 1 commit into
mainfrom
copilot/duplicate-code-analysis-d3050f7
Closed

fix(middleware): resolve CompileToolResponseFilter/WithVars structural duplication#8602
lpcox with Copilot wants to merge 1 commit into
mainfrom
copilot/duplicate-code-analysis-d3050f7

Conversation

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

The duplicate code analysis (#8552) flagged CompileToolResponseFilter and CompileToolResponseFilterWithVars in internal/middleware/jqschema.go for sharing an identical ~20-line cache → parse → compile → store → return body.

Resolution

The private generic helper compileToolResponseFilterInternal[K comparable] has been extracted and both public functions now delegate to it:

// Simple case: cache key is the filter string itself
func CompileToolResponseFilter(filter string) (*gojq.Code, error) {
    return compileToolResponseFilterInternal(filter, filter, secureCompileOpts, ...)
}

// Parameterized case: cache key is a composite struct
func CompileToolResponseFilterWithVars(filter string, varNames []string) (*gojq.Code, error) {
    cacheKey := toolResponseFilterVarsCacheKey{filter, buildVarNamesCacheKey(varNames)}
    return compileToolResponseFilterInternal(cacheKey, filter, compileOptsWithVariables(varNames), ...)
}

The generic K comparable type parameter lets both call sites use distinct cache key types (string vs toolResponseFilterVarsCacheKey) while sharing a single implementation of the caching, parsing, and compilation logic.

Copilot AI linked an issue Jul 3, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix duplicate code issue in jqschema.go fix(middleware): resolve CompileToolResponseFilter/WithVars structural duplication Jul 3, 2026
Copilot finished work on behalf of lpcox July 3, 2026 17:41
Copilot AI requested a review from lpcox July 3, 2026 17:41
@lpcox lpcox marked this pull request as ready for review July 3, 2026 18:03
Copilot AI review requested due to automatic review settings July 3, 2026 18:03

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 wasn't able to review any files in this pull request.

@lpcox

lpcox commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

@lpcox lpcox closed this Jul 3, 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.

[duplicate-code] 🔍 Duplicate Code Analysis Report — commit d3050f7

3 participants