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

51 lines
1.9 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
// WHAT MOUNTING MEANS NOW.
//
// Three tests used to live here and all three drove the strangler: a stub handler
// installed through SetHandler, and assertions that a /v1/* request reached it with
// its path unchanged and its trace context intact. Every part of that is gone —
// there is no stub to install, no glob to forward through, and no net/http boundary
// to carry a context across, because each address is its own route reaching its own
// controller.
//
// What is left worth holding is the honest answer before the runtime exists.
import (
"net/http"
"net/http/httptest"
"testing"
)
// A request that arrives before the app is built is answered 503, not 500 and not a
// silence.
//
// This is the ZAP transports' door — they take the HTTP surface as an http.Handler
// — and it can be asked before ai.App has stored anything. The honest answer is that
// the service cannot answer yet, which a caller can retry; the failure to avoid is a
// nil dereference dressed as a 500.
func TestHandlerRefusesBeforeTheAppIsBuilt(t *testing.T) {
built.Store(nil)
rec := httptest.NewRecorder()
Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodPost, "/v1/chat/completions", nil))
if rec.Code != http.StatusServiceUnavailable {
t.Fatalf("status = %d, want 503 before the runtime exists", rec.Code)
}
}