From 8179ce768fea6b9b1f5b8dc0771fcf8d114d653a Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 06:52:42 +0800 Subject: [PATCH] usage: a test that a row's own cost and its hidden reasoning are read back apart (#1463, #1874) #1874 (d4c2512d2) gave the packed row's Flags bit 256 to rowOwnCost while the #1463 rebase gave the same bit to rowReasoningHidden; the rebase onto it moved rowReasoningHidden to 512. With both on 256 a reported call that said its cost read back as hidden reasoning (its speed dropped) and every hidden-reasoning row as having said its own cost. TestRowFlagsApart checks both rows raw, priced and packed, and that no Flags bit is used twice. Run: go test -tags nogui -count=1 ./... ok on macOS at this head (rebased on d4c2512d2); gofmt and vet clean. Broken by hand: rowReasoningHidden back to 256 turns both subtests and the bit check red. Co-authored-by: congee949 --- internal/usage/reasoning_stream_speed_test.go | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/usage/reasoning_stream_speed_test.go b/internal/usage/reasoning_stream_speed_test.go index 648b09a4b..b74a6479f 100644 --- a/internal/usage/reasoning_stream_speed_test.go +++ b/internal/usage/reasoning_stream_speed_test.go @@ -112,3 +112,49 @@ func TestPricedRowKeepsReasoningEvidence(t *testing.T) { }) } } + +// A row's Flags bits are each its own: a reported call's own cost isn't +// read back as hidden reasoning, nor hidden reasoning as an own cost +// (rowOwnCost and rowReasoningHidden both took 256 when #1463 and #1874 +// landed apart). +func TestRowFlagsApart(t *testing.T) { + cost := 0.5 + own := Record{Time: time.Now(), Source: SourceReported, OwnCost: &cost, Provider: "deepseek", Model: "deepseek-chat", Output: 1500, Reasoning: 1400, Millis: 15000, TTFT: 1000, FirstReasoning: 1000, Flow: 12000, Status: 200} + hidden := own + hidden.OwnCost, hidden.ReasoningHidden = nil, true + for _, c := range []struct { + name string + r Record + hidden bool + own bool + }{ + {"own cost", own, false, true}, + {"hidden reasoning", hidden, true, false}, + } { + t.Run(c.name, func(t *testing.T) { + made := func() *rowChunk { + var chunk rowChunk + for i := 0; i < 80; i++ { + chunk.add(Row{Record: c.r, Source: SourceReported}, "", int64(i), false) + } + return &chunk + } + b := newBlockPricer(nil, nil, func(Record) *catalog.Price { return nil }) + defer b.release() + raw := made() + for _, row := range []Row{raw.row(0), b.block(raw).row(0), b.block(made().pack()).row(0)} { + if row.ReasoningHidden != c.hidden || (row.OwnCost != nil) != c.own { + t.Fatalf("hidden %v, own cost %v; want %v, %v", row.ReasoningHidden, row.OwnCost, c.hidden, c.own) + } + } + }) + } + bits := []uint16{1, 2, 4, 8, 16, 32, swapKnown, rowHandedOn, rowReasoningHidden, rowOwnCost} + var all uint16 + for _, b := range bits { + if all&b != 0 { + t.Fatalf("Flags bit %d is taken twice", b) + } + all |= b + } +}