Skip to content

test: lock in v5 group route method-handling (405 + OPTIONS)#3003

Merged
vishr merged 4 commits into
masterfrom
group-405-regression-tests
Jun 13, 2026
Merged

test: lock in v5 group route method-handling (405 + OPTIONS)#3003
vishr merged 4 commits into
masterfrom
group-405-regression-tests

Conversation

@vishr

@vishr vishr commented Jun 13, 2026

Copy link
Copy Markdown
Member

What

Adds group_method_handling_test.go: tests that lock in v5's method-handling semantics for routes registered through a Group, and act as a regression gate for changes that would reintroduce an implicit per-group catch-all (e.g. #2996, which restores it to fix CORS-on-group preflight).

Behavior asserted (verified on master)

Request on a GET-only group route v5 today
POST /api/users 405 + Allow: OPTIONS, GET
OPTIONS /api/users 204 + Allow: OPTIONS, GET (preflight-relevant)
GET /api/users 200
GET /health (root) 200, unaffected by the group

Why these are real gates

A group-level catch-all — whether registered manually via g.RouteNotFound("/*", …) or automatically (as in #2996) — matches every method, which masks both the 405 and the automatic OPTIONS response as 404. Verified empirically: with such a catch-all, POST and OPTIONS on /api/users both return 404. The first two tests would catch that regression.

Note

This replaces an earlier version of this PR whose comments described a middleware-triggered "auto catch-all" that does not exist on master (v5) — the tests passed for the wrong reason. Reworked after review to assert the actual, verified behavior and drop the inert no-op middleware. All four tests pass; gofmt- and vet-clean.

🤖 Generated with Claude Code

Adds regression tests around automatic group catch-all (404) route
registration. v5 removed that auto-registration; if it is restored
(e.g. PR #2996) these tests ensure it does not bring back the issues
that motivated the removal:

- wrong HTTP method on an existing group route must still return 405
  (with Allow header), not be masked to 404 by the catch-all;
- the group catch-all must not shadow concrete sibling routes, root
  routes, or other sibling groups' routes.

All four pass on current master (v5). The 405 test fails against the
restore-v4-behavior approach in #2996, pinning down that tradeoff.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
vishr and others added 2 commits June 13, 2026 12:35
Addresses review of the original regression file (PR #3003): its comments
described an automatic group catch-all "triggered by middleware" that does
not exist on master (v5), so the tests passed for the wrong reason and the
no-op middleware was inert.

Rewrite to assert v5's actual, verified behavior:
- method mismatch on a group route -> 405 with full Allow header
- OPTIONS on a registered group route -> 204 with Allow (preflight-relevant)
- concrete routes resolve; group prefix does not affect root routes

The 405 and OPTIONS tests are real gates: a group-level catch-all (manual or
the auto-registration proposed in #2996) masks both as 404, which these tests
would then catch. Drops the false premise, the inert middleware, and the
in-comment PR reference.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The previous commit recorded only the deletion of the old file; this adds
the rewritten suite (group_method_handling_test.go).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vishr vishr changed the title test: guard group catch-all against 405-masking and route shadowing test: lock in v5 group route method-handling (405 + OPTIONS) Jun 13, 2026
Addresses final review: converts the "verified empirically" comment into an
actual test. TestGroupRoute_catchAllMasksMethodHandling registers a group-wide
catch-all and asserts it masks both the 405 method-mismatch and the automatic
OPTIONS (204) response as 404 — the regression the 405/OPTIONS gate tests guard
against. Makes the rationale self-proving in-repo.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vishr vishr merged commit 4f5ac60 into master Jun 13, 2026
7 checks passed
@vishr vishr deleted the group-405-regression-tests branch June 13, 2026 19:44
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.

1 participant