mirror of
https://github.com/hanzoai/ai.git
synced 2026-11-20 14:13:23 +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.
133 lines
3.9 KiB
Go
133 lines
3.9 KiB
Go
// Copyright 2023-2025 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 log
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
luxlog "github.com/luxfi/log"
|
|
)
|
|
|
|
// reference reproduces the controller layer/logs.formatLog verbatim. format must agree with
|
|
// it on every input so the migrated call sites render identically.
|
|
func reference(f any, v ...any) string {
|
|
var msg string
|
|
switch f.(type) {
|
|
case string:
|
|
msg = f.(string)
|
|
if len(v) == 0 {
|
|
return msg
|
|
}
|
|
if strings.Contains(msg, "%") && !strings.Contains(msg, "%%") {
|
|
// format string
|
|
} else {
|
|
msg += strings.Repeat(" %v", len(v))
|
|
}
|
|
default:
|
|
msg = fmt.Sprint(f)
|
|
if len(v) == 0 {
|
|
return msg
|
|
}
|
|
msg += strings.Repeat(" %v", len(v))
|
|
}
|
|
return fmt.Sprintf(msg, v...)
|
|
}
|
|
|
|
func TestFormatMatchesUpstream(t *testing.T) {
|
|
err := errors.New("boom")
|
|
cases := []struct {
|
|
f any
|
|
v []any
|
|
}{
|
|
{"plain message no args", nil},
|
|
{"format with verb: %v", []any{err}},
|
|
{"format with verb: %d and %s", []any{42, "x"}},
|
|
{"no verb but has args", []any{err}},
|
|
{"no verb two args", []any{"a", 2}},
|
|
{"literal percent %% only", []any{err}},
|
|
{"mixed %% and %v", []any{err}},
|
|
{"CLOUD_REPLICAS=%d refusing", []any{3}},
|
|
{"", []any{err}},
|
|
{"", nil},
|
|
{errors.New("error as leading value"), nil},
|
|
{errors.New("error leading with args"), []any{1, 2}},
|
|
{123, []any{"tail"}},
|
|
{"percent at end %", nil},
|
|
}
|
|
for _, c := range cases {
|
|
got := format(c.f, c.v...)
|
|
want := reference(c.f, c.v...)
|
|
if got != want {
|
|
t.Errorf("format(%v, %v) = %q, the router reference = %q", c.f, c.v, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestLevelHelpersDoNotPanic exercises each public level so a formatting or
|
|
// backend regression surfaces as a test failure rather than a runtime crash.
|
|
func TestLevelHelpersDoNotPanic(t *testing.T) {
|
|
Info("info %v", 1)
|
|
Warning("warning %v", 2)
|
|
Warn("warn %v", 3)
|
|
Error("error %v", 4)
|
|
Info("plain")
|
|
Error(errors.New("bare error"))
|
|
}
|
|
|
|
// TestSetLoggerLevelAndReset confirms SetLogger honors a JSON "level" and
|
|
// that malformed config and the legacy file/console adapters are accepted
|
|
// without error, and Reset returns to info.
|
|
func TestSetLoggerLevelAndReset(t *testing.T) {
|
|
if err := SetLogger("console", `{"level":"error"}`); err != nil {
|
|
t.Fatalf("SetLogger level: %v", err)
|
|
}
|
|
if err := SetLogger("file", `{"adapter":"file","filename":"x.log"}`); err != nil {
|
|
t.Fatalf("SetLogger file adapter: %v", err)
|
|
}
|
|
if err := SetLogger("file", `not json`); err != nil {
|
|
t.Fatalf("SetLogger malformed config must not error: %v", err)
|
|
}
|
|
Reset()
|
|
}
|
|
|
|
// TestParseLevel covers the string and historical-numeric level forms so a
|
|
// numeric {"level":7} configures debug instead of silently no-opping.
|
|
func TestParseLevel(t *testing.T) {
|
|
cases := []struct {
|
|
v any
|
|
want luxlog.Level
|
|
ok bool
|
|
}{
|
|
{"debug", luxlog.DebugLevel, true},
|
|
{"ERROR", luxlog.ErrorLevel, true},
|
|
{float64(7), luxlog.DebugLevel, true}, // JSON numbers decode as float64
|
|
{float64(6), luxlog.InfoLevel, true},
|
|
{float64(4), luxlog.WarnLevel, true},
|
|
{float64(3), luxlog.ErrorLevel, true},
|
|
{float64(0), luxlog.ErrorLevel, true}, // clamp: errors always emit
|
|
{"nonsense", luxlog.InfoLevel, false},
|
|
{nil, luxlog.InfoLevel, false},
|
|
}
|
|
for _, c := range cases {
|
|
got, ok := parseLevel(c.v)
|
|
if ok != c.ok || (ok && got != c.want) {
|
|
t.Errorf("parseLevel(%v) = (%v, %v), want (%v, %v)", c.v, got, ok, c.want, c.ok)
|
|
}
|
|
}
|
|
}
|