Skip to content

[router]: Make routing logic testable without fx - #123

Merged
pseudomuto merged 1 commit into
mainfrom
router_refactor
Aug 10, 2026
Merged

[router]: Make routing logic testable without fx#123
pseudomuto merged 1 commit into
mainfrom
router_refactor

Conversation

@pseudomuto

Copy link
Copy Markdown
Collaborator

Rule compilation and the director both lived inside anonymous fx providers in fx.go. Exercising glob syntax or metadata key handling meant booting fx apps and asserting on app.Err() substrings, and testing the director meant hand-building struct literals that skipped the pool and socket wiring, which is the part worth exercising.

Lift both into their own files behind exported functions, CompileMux taking config.Routing and NewDirector taking its dependencies. The providers forward to them, so behaviour is unchanged.

@pseudomuto
pseudomuto requested a lite review from Copilot August 10, 2026 14:12
@pseudomuto
pseudomuto requested a review from a team as a code owner August 10, 2026 14:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Refactors the router module to make routing-rule compilation and request directing testable without booting an fx.App, by lifting them into exported constructors while keeping the fx providers as thin forwarding wrappers.

Changes:

  • Introduce CompileMux(config.Routing) to compile routing rules outside of fx wiring.
  • Introduce NewDirector(...) and move Director/Resolve implementation into director.go.
  • Update mux/director tests to use the new constructors and adjust matcher usage to pkg/match.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/router/mux.go Switch Rule matching to use pkg/match.Matcher directly.
internal/router/mux_test.go Update tests to use match.MustCompile and add a zero-matcher behavior test.
internal/router/handler.go Generalize Target.Conn to grpc.ClientConnInterface.
internal/router/fx.go Make fx providers delegate to CompileMux and NewDirector.
internal/router/fx_test.go Remove invalid-routing assertions from the fx module test (moved to compile_test.go).
internal/router/director.go New file: extracted Director interface + implementation and NewDirector constructor.
internal/router/director_test.go Rewrite tests to use CompileMux/NewDirector from router_test package.
internal/router/compile.go New file: CompileMux extracted from fx provider.
internal/router/compile_test.go New tests for routing compilation behavior and error cases.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/router/director_test.go
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

`Rule` compilation and the director both lived inside anonymous fx
providers in fx.go. Exercising glob syntax or metadata key handling
meant booting fx apps and asserting on app.Err() substrings, and testing
the director meant hand-building struct literals that skipped the pool
and socket wiring, which is the part worth exercising.

Lift both into their own files behind exported functions, `CompileMux`
taking `config.Routing` and `NewDirector` taking its dependencies. The
providers forward to them, so behaviour is unchanged.
@pseudomuto
pseudomuto merged commit 0b202b7 into main Aug 10, 2026
6 checks passed
@pseudomuto
pseudomuto deleted the router_refactor branch August 10, 2026 14:42
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