Skip to content

fix: typed-nil guard and _response_handled parity for PipelineRunner fallback path#121

Merged
intel352 merged 2 commits intorefactor/issue-58-route-pipeline-setter-interfacefrom
copilot/sub-pr-116
Feb 23, 2026
Merged

fix: typed-nil guard and _response_handled parity for PipelineRunner fallback path#121
intel352 merged 2 commits intorefactor/issue-58-route-pipeline-setter-interfacefrom
copilot/sub-pr-116

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

routePipelines maps string → interfaces.PipelineRunner, so a caller can store a typed-nil *Pipeline as the interface value. The previous pipeline != nil guard passes for typed-nil interfaces, and the subsequent type assertion succeeds yielding a nil pointer — causing a panic on concretePipeline.Metadata = ….

The Run() fallback for non-*Pipeline implementations also lacked the _response_handled sentinel check present in the *Pipeline path, risking double-writes when a custom runner writes directly to the ResponseWriter.

Changes

  • Typed-nil guard (command_handler.go, query_handler.go): Hoist the type assertion before the branch so both cases are covered with a single assertion:

    concretePipeline, isConcrete := pipeline.(*Pipeline)
    if isConcrete && concretePipeline != nil {
        // concrete *Pipeline path
    } else if !isConcrete {
        // PipelineRunner.Run() fallback
    }
    // typed-nil *Pipeline falls through to delegate/404
  • _response_handled parity in Run() fallback: After pipeline.Run() returns, check result["_response_handled"] == true and skip JSON encoding if set — matching the behaviour of the *Pipeline path.

  • Tests (command_handler_test.go, query_handler_test.go): Added mockPipelineRunner (shared across package module tests) and four new cases per handler:

    • mock runner result is JSON-encoded correctly
    • _response_handled=true suppresses the response body
    • Run() error yields a 500
    • typed-nil *Pipeline does not panic and falls through to 404

💡 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.

…tests

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor RoutePipelineSetter to use interfaces.PipelineRunner fix: typed-nil guard and _response_handled parity for PipelineRunner fallback path Feb 23, 2026
Copilot AI requested a review from intel352 February 23, 2026 09:11
@intel352 intel352 marked this pull request as ready for review February 23, 2026 09:19
@intel352 intel352 merged commit 783f094 into refactor/issue-58-route-pipeline-setter-interface Feb 23, 2026
@intel352 intel352 deleted the copilot/sub-pr-116 branch February 23, 2026 09:19
intel352 added a commit that referenced this pull request Feb 23, 2026
* refactor: use interfaces.PipelineRunner in RoutePipelineSetter (closes #58)

Replace the concrete *module.Pipeline type in the RoutePipelineSetter interface
and the CommandHandler/QueryHandler routePipelines map with interfaces.PipelineRunner.

This decouples the engine's route-pipeline wiring contract from the concrete
Pipeline implementation, allowing test doubles and future plugin-provided
pipelines to satisfy the interface without importing the module package.

Changes:
- engine.go: RoutePipelineSetter.SetRoutePipeline now takes interfaces.PipelineRunner
- module/command_handler.go: routePipelines map and SetRoutePipeline use interfaces.PipelineRunner;
  ServeHTTP type-asserts to *Pipeline for concrete field access (Metadata, RoutePattern, Execute)
  with a Run()-based fallback for non-*Pipeline implementations
- module/query_handler.go: same as command_handler

*module.Pipeline already satisfies PipelineRunner, so engine.go callers pass
*module.Pipeline unchanged — no call-site changes required there.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: typed-nil guard and _response_handled parity for PipelineRunner fallback path (#121)

* Initial plan

* fix: typed-nil guard, _response_handled fallback, add route pipeline tests

Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: intel352 <77607+intel352@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