Files
ai/routers/pathparam_test.go
zeekay 3674dda05b the filters pass their own tests, and two ceilings were missing
routers/ and every test in it is green. That is the first real check on the filter
work, and running it found two defects and one habit worth naming.

THE HEADER CEILING WAS UNSET, and it is the twin of the body one. fasthttp's
per-connection read buffer is 4 KiB by default and that buffer caps the TOTAL
request headers, so a request whose headers do not fit is refused at the socket
before any handler — with a message naming a buffer size. Every authenticated
request here carries a signed IAM bearer and the gateway's identity set beside it,
which clears 4 KiB together. zip states the ceiling and names the seam in its own
comment; ai set BodyLimit and never set this. Found because a test signed a real
token and the request would not parse.

A FILTER IS MIDDLEWARE, so it is tested through an app. It ends in Continue(), and
Continue means "the next handler" — which a detached context does not have, so
calling one on a TestCtx panics inside fiber's Next. zip's own doc says TestCtx is
for calling ONE handler and a chain belongs to an app. probe.through does that, and
it puts each filter in the position it actually occupies, ahead of a handler.

A FIBER CTX IS POOLED. The harness first captured the Ctx the handler was reached
with and read it after the request; fiber releases its Ctx at the end, so that read
returns a recycled object with nothing of the request on it — and the tenant
attribution tests failed reporting an empty project, which reads exactly like the
filter never ran. Capture the VALUE, never the Ctx.

Two more honest corrections to the tests themselves:

  - A "*" mapping claims every verb, and the live table lists them one at a time
    because the router registers a handler per method. The doc-table check now
    asserts the PATH is served for a "*" row, which is what "*" says.
  - The probe never returns a silent zero on a failed run. It did, and a status of 0
    reads as "the filter answered nothing" — which sent three assertions looking for
    a bug in the filter that was in the harness.

And the tests that had nothing left to test are gone rather than adapted: the
auto-signin and static filter tests went with the filters, and the session
nil-safety test is recast onto the property that survived — no credential resolves
to nobody, and bills nobody, because the filters ask that before any controller.
2026-08-17 09:23:43 -07:00

45 lines
1.2 KiB
Go

package routers
import (
"regexp"
"testing"
)
// A templated segment names a parameter a caller has to supply. When the
// document omits the declaration the generator still emits the method — named
// for the value it cannot take — so `get_videos_by_id(self)` requested the
// literal "{id}". The spelling half of that was already fixed (openAPIPath);
// this holds the other half.
func TestTemplatedSegmentsAreDeclared(t *testing.T) {
doc := Document(built())
paths, _ := doc["paths"].(map[string]any)
re := regexp.MustCompile(`\{(\w+)\}`)
bad := 0
for p, item := range paths {
want := re.FindAllStringSubmatch(p, -1)
if len(want) == 0 {
continue
}
methods, _ := item.(map[string]any)
for verb, op := range methods {
o, _ := op.(map[string]any)
have := map[string]bool{}
params, _ := o["parameters"].([]any)
for _, q := range params {
m, _ := q.(map[string]any)
if m["in"] == "path" {
n, _ := m["name"].(string)
have[n] = true
}
}
for _, w := range want {
if !have[w[1]] {
t.Errorf("%s %s: path param %q undeclared", verb, p, w[1])
bad++
}
}
}
}
t.Logf("templated paths checked; undeclared = %d", bad)
}