mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +00:00
Three structural pieces of the move off web. SSE. The chat-completions stream and the single-chunk reply now run inside SendStreamWriter: zip hands the handler a writer and flushes each frame as it is written, so a chunk reaches the client when it is produced. The billing capture runs inside that same closure, so the usage it settles on is the usage of the bytes the client actually received. Pagination. NewPaginator wanted an *http.Request for exactly one thing: reading "p". It takes the page as a number now, and the parameter name is read by the caller — 22 call sites, and util no longer imports net/http for this. pageAsked is a pure function so the name and the not-a-number cases are assertable without a live request; its table moved with it. Per-request values. Input.SetParam/GetData are Locals, which is where a request carries something for a later filter to read. 909 compile errors down to 76. Left: 14 bare Request values, 28 ResponseWriter in the remaining streamers, the session, and routers/ + app.go + the tests.
32 lines
1.0 KiB
Go
32 lines
1.0 KiB
Go
package controllers
|
|
|
|
import "testing"
|
|
|
|
// TestPageAskedReadsParamP locks the page parameter name to "p". The paginator
|
|
// used to read it itself; now the caller does, so the name is asserted here —
|
|
// a "page" parameter is ignored and the caller stays on the first page.
|
|
//
|
|
// It is a table over the raw query value because that is what varies: absent,
|
|
// non-numeric and negative all have to land on something the paginator clamps
|
|
// to page 1, and none of them may be an error.
|
|
func TestPageAskedReadsParamP(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
query string
|
|
want int
|
|
}{
|
|
{"p=3", 3},
|
|
{"p=1", 1},
|
|
{"page=3", 0}, // the other spelling names nothing
|
|
{"pageSize=10", 0}, //
|
|
{"", 0}, // absent
|
|
{"p=abc", 0}, // non-numeric is page 1, never an error
|
|
{"p=-3", -3}, // the paginator clamps, this does not
|
|
{"p=3&page=9", 3}, // "p" wins
|
|
} {
|
|
got := pageAsked(tc.query)
|
|
if got != tc.want {
|
|
t.Errorf("query %q: page = %d, want %d", tc.query, got, tc.want)
|
|
}
|
|
}
|
|
}
|