Document invocation observation and cost reporting

This commit is contained in:
2026-11-22 18:38:11 +00:00
parent d4509b163e
commit 20c5ea47af
22 changed files with 231 additions and 52 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"io"
"math"
"net/http"
"strings"
"testing"
@@ -62,6 +63,7 @@ func TestOrdinaryRunCostMatchesTerminalWithOrWithoutObserver(t *testing.T) {
func TestOrdinaryRunCostFailureAndFallback(t *testing.T) {
charge := .125
invalid := math.Inf(1)
for _, tc := range []struct {
name string
response *promptkit.GenerateResponse
@@ -70,6 +72,7 @@ func TestOrdinaryRunCostFailureAndFallback(t *testing.T) {
}{
{"reported takes precedence", &promptkit.GenerateResponse{Content: "ok", CostUSD: &charge}, nil, promptkit.ObservedCost{Value: .125, Known: true, Complete: true, Source: promptkit.CostSourceProvider}},
{"failed dispatch fallback", nil, errors.New("failure"), promptkit.ObservedCost{Known: true, Complete: true, Source: promptkit.CostSourceConfiguredZero}},
{"nonfinite report falls back", &promptkit.GenerateResponse{Content: "ok", CostUSD: &invalid}, nil, promptkit.ObservedCost{Known: true, Complete: true, Source: promptkit.CostSourceConfiguredZero}},
} {
t.Run(tc.name, func(t *testing.T) {
engine := costEngine(t, true, nil, promptkit.WithLLMClient(observationClientFunc(func(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {