//go:build browser package thintest import ( "strings" "testing" "amadan.net/oficina/equipo/internal/wire" ) // The task page's spend follows an answer live: when a question about // the task is answered, the total and the Questions line show what the // answer used without a reload. func TestBrowserSpendFollowsAnswers(t *testing.T) { r := newToolRig(t) base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) id, _, _ := r.askableTask("b", base, cand) p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") p.open("/tasks/" + id) p.check(`document.querySelector('[data-spend]')===null && document.querySelector('#task-spend')!==null`, "spend before any usage") q, err := r.client.Ask(r.ctx, id, "What did you change?", "", "k1") if err != nil { t.Fatal(err) } r.expect(wire.FrameAsk) r.answer("b-q-run", wire.AnswerReport{TaskID: id, QuestionID: q.ID, Attempt: 1, State: wire.QuestionRunning}) used := []wire.Usage{{Provider: "codex", Connection: "codex-a", Model: "gpt-6-astra", Attempt: 1, Outcome: wire.OutcomeReplied, Complete: true, InputTokens: tokens(9000), CachedInputTokens: tokens(4000), OutputTokens: tokens(1000)}} r.answer("b-q-done", wire.AnswerReport{TaskID: id, QuestionID: q.ID, Attempt: 1, State: wire.QuestionAnswered, Text: "I fixed the typo.", Usage: used}) p.wait(`document.querySelector('[data-spend]')?.textContent==='Used 10k tokens (4k cached)'`, "the total after the answer") p.wait(`document.querySelector('[data-spend-step="questions"]')?.textContent==='Questions: 10k tokens (4k cached)'`, "the Questions line after the answer") }