Files
ai/object/priced_test.go
zeekay 5a1101df24 rates: Enso sells at one fixed price, and a guard holds its route under it
Owner, 2026-10-15: no adaptive or dynamic Enso pricing. Each paid Enso
SKU lists and bills at one price, 2 to 3 times the list price of the
upstream its served route typically answers on, and well under Claude
Fable and GPT-6 Astra ($10 / $50): enso-flash 0.33 / 1.65 (GPT-6 Luna,
3x), enso-pro 4.40 / 22.00 (GPT-6.1 Sol, 2x), enso-ultra 5.50 / 27.50
(Claude Sonnet 5.5, 2.5x). The family's listing carries the price (fix),
so /v1/models, the bill, the hold and the price list read one number. A
SKU the service prices that the list does not is neither listed nor
served; the free SKUs stay free.

- The guard sends a SKU only while every arm of its route, read from the
  engine's admin catalog once a minute, costs us no more than the SKU
  bills in every class, at a long prompt's price and with OpenRouter's
  fee. What cannot be checked is not sent. A refusal is a 503 that names
  no upstream, and a stand-in that does not fit is skipped. An answer on
  an arm the route as read does not hold reads it again.
- The ledger is a report: a SuperAdmin's Prices says how each price was
  set, holds each arm against it, and reads the last day by model, arm
  and vendor, with the margin the fixed price made, as one grouped query.
- Gone: the from / typical / up-to quote, Price, Blend, Reprice,
  StartRates and the daily measure, the hold at up to, and pricing.from,
  up_to, fee and window on /v1/models. The platform's fee on pass-through
  models and the stated resolution order stay.
2026-10-15 18:49:31 -07:00

70 lines
2.3 KiB
Go

// Copyright 2026 Hanzo AI Inc. All Rights Reserved.
package object
import (
"regexp"
"strings"
"testing"
"time"
)
// A grouped row reads whatever native types the driver decoded.
func TestARoutedRowReadsTheDriversTypes(t *testing.T) {
r := routed(map[string]any{
"model": "enso-flash", "served": "openai/gpt-6-luna", "vendor": "openrouter", "status": "success",
"requests": uint64(3), "uncosted": uint64(1), "losses": uint64(0), "cost": int64(1_392_600),
"billed": int64(1_980_000), "loss": int64(0), "known": int64(1_320_000),
})
want := Routed{
Model: "enso-flash", Served: "openai/gpt-6-luna", Vendor: "openrouter", Status: "success",
Requests: 3, Uncosted: 1, CostNano: 1_392_600, BilledNano: 1_980_000, KnownNano: 1_320_000,
}
if r != want {
t.Errorf("row = %+v, want %+v", r, want)
}
}
// The read dedups by id below its grouping, filters by family and time before the
// dedup, and names the dedup's columns apart from the aggregates' aliases.
func TestTheRoutedReadDedupsBeforeItGroups(t *testing.T) {
if !strings.Contains(routedQuery, "WHERE provider = ? AND timestamp >= ?) GROUP BY id) GROUP BY model, served, vendor, status") {
t.Errorf("the read groups before its dedup or filters after it: %s", routedQuery)
}
outer, inner, ok := strings.Cut(routedQuery, " FROM (SELECT id, ")
if !ok {
t.Fatalf("no dedup in %s", routedQuery)
}
inner, _, _ = strings.Cut(inner, " FROM (SELECT * ")
named := map[string]bool{}
for _, m := range aliases.FindAllStringSubmatch(inner, -1) {
named[m[1]] = true
}
for _, m := range aliases.FindAllStringSubmatch(outer, -1) {
if named[m[1]] {
t.Errorf("an aggregate is named %s, as a column of the dedup is", m[1])
}
}
for _, col := range []string{"served", "vendor", "loss_nano", "cost_nano", "billed_nano", "uncosted"} {
found := false
for _, c := range CloudUsageColumns {
found = found || c == col
}
if !found {
t.Errorf("the ledger writes no %s", col)
}
}
}
var aliases = regexp.MustCompile(`AS (\w+)`)
// Without the datastore the read says so rather than answering nothing.
func TestTheRoutedReadNeedsTheLedger(t *testing.T) {
if DatastoreEnabled() {
t.Skip("a datastore is connected")
}
if _, err := RoutedRows(t.Context(), "enso", time.Now()); err == nil {
t.Error("a read with no ledger answered")
}
}