Files
ai/mount_named_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

70 lines
2.6 KiB
Go

// Copyright 2023-2026 Hanzo AI Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ai
import (
"strings"
"testing"
"github.com/zap-proto/zip"
"github.com/hanzoai/ai/routers"
)
// EVERY ADDRESS IS ITS OWN ROUTE — which is what makes it describable.
//
// There used to be a hand-written "promoted" list beside a /v1/* glob: three
// addresses re-registered specifically so the host could name them, because a glob
// tells a host a prefix and nothing under it. Three operations were authenticated,
// reachable and answering in production with no generated SDK, no MCP tool, no CLI
// command, and nothing saying who served them.
//
// The list is gone because there is nothing left to promote, and this holds the
// property it was reaching for: the table names real patterns, and no glob stands in
// for them.
func TestEveryAddressIsItsOwnRoute(t *testing.T) {
app := zip.New(zip.Config{DisableStartupMessage: true, ReadBufferSize: 32 << 10})
routes(app)
patterns := routers.Patterns(app)
if len(patterns) == 0 {
t.Fatal("the app registered no addresses at all")
}
// The three the old list named. They are ordinary entries now, which is the
// point: nothing distinguishes them from the other ~190.
for _, pattern := range []string{
"/v1/models",
"/v1/models/providers",
"/v1/models/:model/access",
} {
if len(patterns[pattern]) == 0 {
t.Errorf("%s is not a route; the table cannot describe what it does not register", pattern)
}
}
// And no glob. One would make every address under it undescribable again.
for pattern := range patterns {
if strings.HasSuffix(pattern, "/*") || strings.Contains(pattern, "/*/") {
t.Errorf("%s is a glob — the addresses under it have no description", pattern)
}
}
}
// The test that used to sit here installed a stub handler and asserted a promoted
// address reached the same one as the glob. Both halves are gone: there is no stub
// to install and no glob to compare against, because each address reaches its own
// controller through its own route. That is the property, and it is above.