Skip to content

test(logs): route /logs/search stubs by content + document hand-marshal bypass (issue #21)#28

Open
tkkhq wants to merge 1 commit into
mainfrom
chore/log-search-test-routing
Open

test(logs): route /logs/search stubs by content + document hand-marshal bypass (issue #21)#28
tkkhq wants to merge 1 commit into
mainfrom
chore/log-search-test-routing

Conversation

@tkkhq

@tkkhq tkkhq commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Addresses the low-risk, verified parts of #21 after re-scoping (the stale apiclient concern is already resolved on main — LogSearchRequest.Resource is the nested union).

Changes

  • Content-based test routing (client_test.go, frontends_test.go): the /logs/search stub now returns the build vs runtime response based on whether the request body carries a resource.deployments selector, via a shared logSearchIsBuild helper — instead of the brittle len(logSearchBodies)==1 call-order check. Matches the approach already used in command-level tests.
  • Document the intentional bypass (logs.go): comment explaining why we hand-marshal a flat logSearchRequest and call SearchProjectLogsWithBodyWithResponse rather than the typed SearchProjectLogsWithResponse. The generated LogRequestResource is an oapi-codegen oneOf union (From.../As... constructors); the flat struct yields the identical wire format but keeps call sites readable. This is issue tech-debt(apiclient): regenerate log-search client; remove hand-marshalled bypass #21's checkbox feat(cli): add environment contexts #3, and resolves its checkbox chore(repo): add pull request template #2 as a deliberate 'keep' (union constructors would make the call site less clear, and the typed path now serializes correctly, so the only remaining argument was consistency).

Not included (by design)

Tests: go test ./internal/api green; go tool golangci-lint run ./internal/api clean.

Copilot AI review requested due to automatic review settings July 3, 2026 18:38
@tkkhq tkkhq requested a review from a team as a code owner July 3, 2026 18:38

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

This PR makes the /logs/search API test stubs more robust by routing responses based on request content (instead of call order), and documents why internal/api/logs.go intentionally bypasses the generated typed request model for log search due to the generated oneOf union ergonomics.

Changes:

  • Route /projects/{id}/logs/search test responses by presence of a resource.deployments selector via a shared logSearchIsBuild helper.
  • Add an explanatory comment documenting the intentional hand-marshalled logSearchRequest + SearchProjectLogsWithBodyWithResponse path in logs.go.

Reviewed changes

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

File Description
internal/api/logs.go Documents the intentional hand-marshalling approach for log-search requests.
internal/api/frontends_test.go Uses content-based routing for /logs/search stub responses (build vs runtime).
internal/api/client_test.go Uses content-based routing and introduces the shared logSearchIsBuild helper.

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

Comment thread internal/api/logs.go
Comment on lines +20 to +26
// logSearchRequest is a hand-marshalled body for POST /projects/{id}/logs/search,
// sent via SearchProjectLogsWithBodyWithResponse rather than the typed
// SearchProjectLogsWithResponse. The generated apiclient models the request's
// `resource` selector as an oapi-codegen oneOf union (apiclient.LogRequestResource),
// built through From.../As... accessors; this flat struct produces the identical
// wire format while keeping the call sites readable. Intentional — do not
// "simplify" it back to the typed union call.
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