mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-21 02:36:49 +00:00
The paid lane capped every paid-lane call together at PAID_LANE_DAILY ($10 a UTC
day by default) and each org at PAID_LANE_ORG_SHARE (25% of it), and counted
wallet-paid calls against both: a customer with $1,000 prepaid was held to $2.50 a
day, and every payer together to $10. The rule is no ceiling but what a payer
prepays, or their usage. Free users get free models; payers spend their own money.
Deleted: the platform day and the org share (paidLaneDaily, orgShare, the day,
spent and per-org accounting in laneBook), the paid_day store (object.PaidDay, its
table registration, the writer, flush, drain, load and turn), Settled's drain of
it, laneSpend, PaidLaneOpen (the gate reads !FreeOnly()), and the refusals only the
day produced ("closed", "after 00:00 UTC"). paid_lane_ceiling named a platform
ceiling that no longer exists: a payer the lane has no room for is told
paid_lane_full, the code its refusal already carried, in X-Hanzo-Lane-Reason and
X-Hanzo-Usage-Reason. Stores keep an orphan paid_day table nothing reads.
Kept: the wallet hold (reserveFor), the plan class's LimitGrant.Spend less the
payer's calls in flight, quote sizing against it, 8 seats a payer, lapse and
stream-idle give-back, race losers holding the seat, BYO, and the free-model
hand-off for a payer with no room.
The replica guard. The lane was closed unless CLOUD_API_REPLICAS=1 because the day
lived in this process. No deployment sets CLOUD_API_REPLICAS: the cloud chart
injects CLOUD_REPLICAS (1 in production). So the boot assertion meant to stop a
second replica double-spending the in-pod wallet ledger never fired, and the lane
guard was the one live check; it also kept the paid lane closed in production. The
plan holds that remain are in-pod exactly as the wallet ledger is, so they take its
guard: SinglePodReplicaHint reads CLOUD_REPLICAS, and bootstrap refuses to start
when the deployment states more than one replica. A declared second replica stops
the process instead of closing the lane, and no switch is left whose only purpose
was the day.
52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/ai/object"
|
|
)
|
|
|
|
// The paid lane is on for this package's tests, which exercise it, and every request
|
|
// they build is seated on it (visit, paidSeat); a test of the free lane closes it
|
|
// itself and opens it again when it ends, and a test of the lanes themselves
|
|
// (lane_test.go) seats each caller.
|
|
//
|
|
// The vendor accounts are the ones a test sets, never one the shell running the suite
|
|
// holds: a real key in the environment is one more account the pool walks, which a
|
|
// test vendor benches on its first refusal.
|
|
func TestMain(m *testing.M) {
|
|
FreeOnly = func() bool { return false }
|
|
for _, k := range object.OpenRouterKeys {
|
|
_ = os.Unsetenv(k)
|
|
}
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
// With the paid lane off, a call to any provider but a family's own service is one
|
|
// that spends, and is refused; with it on, none is.
|
|
func TestPayingIsEveryProviderButAFamilys(t *testing.T) {
|
|
ctx := paidSeat(context.Background())
|
|
FreeOnly = func() bool { return true }
|
|
t.Cleanup(func() { FreeOnly = func() bool { return false } })
|
|
for typ, want := range map[string]bool{"Zen": false, "Enso": false, "OpenAI": true, "OpenRouter": true, "": true} {
|
|
if got := paying(ctx, &object.Provider{Type: typ}); got != want {
|
|
t.Fatalf("paying(%q) = %v, want %v", typ, got, want)
|
|
}
|
|
}
|
|
// Our own speech service pays no vendor; an org's row that borrows its name does.
|
|
if paying(ctx, &object.Provider{Owner: "admin", Name: "speech", Type: "OpenAI"}) {
|
|
t.Fatal("the paid lane being off refused our own speech service")
|
|
}
|
|
if !paying(ctx, &object.Provider{Owner: "acme", Name: "speech", Type: "OpenAI"}) {
|
|
t.Fatal("an org's provider named speech was taken for ours")
|
|
}
|
|
FreeOnly = func() bool { return false }
|
|
if paying(ctx, &object.Provider{Type: "OpenAI"}) {
|
|
t.Fatal("a paid lane that is on refused a priced provider")
|
|
}
|
|
}
|