package main import ( "bytes" "encoding/json" "math" "testing" "go.maximumdirect.net/promptkit" ) func TestObserveExample(t *testing.T) { var output bytes.Buffer if err := execute(&output); err != nil { t.Fatal(err) } var got struct { ProposalAttempts *int `json:"proposal_attempts"` ProposalRetries *int `json:"proposal_transient_retries"` UsageComplete *bool `json:"proposal_usage_complete"` AssessmentAttempts *int `json:"assessment_attempts"` AssessmentRetries *int `json:"assessment_transient_retries"` Outcome string `json:"assessment_outcome"` CoordinationOutcome string `json:"coordination_outcome"` ExhaustedOutcome string `json:"exhausted_outcome"` GroupMembers int `json:"group_members"` GroupAttempts int `json:"group_attempts"` GroupCost promptkit.ObservedCost `json:"group_cost"` GroupReasoning promptkit.ObservedTokenCount `json:"group_reasoning"` GroupCacheRatioAvailable bool `json:"group_cache_ratio_available"` AssessmentCacheRatio float64 `json:"assessment_cache_ratio"` PreparedMessages int `json:"prepared_messages"` PreparedParentMatches bool `json:"prepared_parent_matches"` } if err := json.Unmarshal(output.Bytes(), &got); err != nil { t.Fatal(err) } if got.ProposalAttempts == nil || *got.ProposalAttempts != 2 || got.ProposalRetries == nil || *got.ProposalRetries != 1 || got.UsageComplete == nil || *got.UsageComplete || got.AssessmentAttempts == nil || *got.AssessmentAttempts != 1 || got.AssessmentRetries == nil || *got.AssessmentRetries != 0 || got.Outcome != "accepted" || got.CoordinationOutcome != "stopped" || got.ExhaustedOutcome != "exhausted" || got.GroupMembers != 3 || got.GroupAttempts != 4 || got.PreparedMessages < 3 || !got.PreparedParentMatches { t.Fatalf("unexpected observation summary: %+v", got) } if !got.GroupCost.Known || !got.GroupCost.Complete || got.GroupCost.Source != promptkit.CostSourceMixed || math.Abs(got.GroupCost.Value-.03) > 1e-12 || got.GroupReasoning.Value != 3 || got.GroupReasoning.Complete || got.GroupCacheRatioAvailable || math.Abs(got.AssessmentCacheRatio-2.0/7.0) > 1e-12 { t.Fatalf("unexpected usage summary: %+v", got) } }