Files
zip/headshadow_test.go
zeekayandHanzo Dev 5f71d2496b The router is three nouns, and every one of them is concrete
App, Group, Operation. A group is a prefix and what holds under it, an operation
is one typed route declared there, and the verb methods are generic methods —
which Go 1.27 allows on a concrete type and still refuses on an interface. So In
and Out come from the handler and the caller writes no type arguments:

	users := app.Group("/v1/users")
	users.Post("/", api.Create)

	mint := users.Group("/mint").With(middleware.Mint(gate))
	mint.Post("/deposit", api.Deposit)

A Group is a CLOSED HANDLE: two unexported fields, and no method that hands back
the app, the parent or the fiber underneath. A subsystem given the group at its
own prefix cannot reach above it, so confinement is a property of the type
instead of a rule something has to police — which is what a host needs in order
to hand out a bounded surface and know what comes back.

That is bought by giving up the router interface, deliberately. Router and
OpTarget are gone, and with them the ability to implement a route table outside
this package: a decorator is no longer a router, a gate is middleware on a group,
and a bound is a path. The five package-level verb functions go the same way —
a registration is a method on the thing it registers into.

Raw carries what is not a typed operation: a stream, an upgrade, a probe, a
foreign subtree. It names its method, and it is the longer spelling because
opting out of the typed model is the exception and should read like one.



Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 01:39:17 -07:00

35 lines
1015 B
Go

package zip
import "testing"
// Does the HEAD filter distinguish a SHADOW from a declared door?
func TestHeadShadow_ExplicitHeadSurvivesTheFilter(t *testing.T) {
a := quiet("svc")
a.Raw("GET", "/thing", func(c *Ctx) error { return nil }) // fiber shadows this with HEAD
a.Raw("HEAD", "/probe", func(c *Ctx) error { return nil }) // an explicitly declared door
d := a.Declaration()
var gotGet, gotHead bool
for _, r := range d.Routes {
if r.Method == "GET" && r.Pattern == "/thing" {
gotGet = true
}
if r.Method == "HEAD" && r.Pattern == "/probe" {
gotHead = true
}
}
if !gotGet {
t.Error("GET /thing missing from the declaration")
}
if !gotHead {
t.Error("HEAD /probe missing — an explicitly declared HEAD is a door a host must route, " +
"not a shadow fiber generated")
}
// And the shadow itself must NOT be there.
for _, r := range d.Routes {
if r.Method == "HEAD" && r.Pattern == "/thing" {
t.Error("HEAD /thing is a fiber shadow and must not be declared")
}
}
}