Qoder's and Qoder CN's sessions were on the Sessions page and nowhere in
Usage: callSources never listed their files. They are Claude Code's
lines, and are now read for calls as Claude Code's are (ccCallAgent:
claudeCallLine, the call cache, continuations and revisions).
Qoder writes a reply on its own models ("auto" among them) with every
token count 0 unless QODER_EXPOSE_TOKEN_USAGE is set: the transcript
writer (vUl in qodercli, the same in Qoder.app's worker, qoder-agent-sdk)
zeroes them unless the model is a custom one, from qodercli 1.1.0 on. It
keeps the reply's credits. So such a call carries Credits (new on
sessions.Call, passed to the ledger's Record), counted with no tokens
and no price; "auto" names no model, so nothing is priced for it. A
model of the user's own, whose counts are written, is read and priced
as before. The GUI's direct section already shows credits (ledCredits).
Fixture: testdata/qoder-1.1.89 is lines as qodercli 1.1.89's writer
lays them out (key order, zeroed usage, credits/original_credits/
billable, a reply with no usage), read from its npm bundle; the ids are
made up. The older invented qoder fixtures got message ids of their own
(Calls counts a message id once across agents, and they shared
WorkBuddy's m1/m2).
Run (on mica, at f07e3e067's tree, rebased on 269e54de5):
- go test -count=1 -timeout 45m ./internal/sessions ./internal/usage
./internal/gui: ok
- GOOS=linux and GOOS=windows go vet of both packages: ok; gofmt -l clean
- red on the old code (origin/main's calls.go, call_cache.go,
call_continuation.go, call_revisions.go, ledger.go with the new tests):
TestQoderCalls got 0 calls, TestDirectQoderCallsByCredits Credits 0
Credited 0
Not tried: no real Qoder transcript was captured (qodercli needs a
signed-in account here); the format comes from the bundle's writer. No
GUI change, so no GUI suite. A reply Qoder writes with no usage at all
is not counted. The tokens of Qoder's own models can't be shown: Qoder
doesn't write them.
79 lines
3.0 KiB
Go
79 lines
3.0 KiB
Go
package sessions
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Qoder's and Qoder CN's own calls reach the usage ledger (eating_dream on
|
|
// X: Qoder's sessions were on the Sessions page and nowhere in Usage). The
|
|
// files in testdata/qoder-1.1.89 are lines as qodercli 1.1.89 writes them
|
|
// (its transcript writer, Xj and vUl, read from the npm bundle; the ids are
|
|
// made up): its own model is "auto", and a reply's usage has every count 0
|
|
// with what it cost in Qoder's credits, as QODER_EXPOSE_TOKEN_USAGE unset
|
|
// leaves it. A reply whose usage named no credits is written with none at
|
|
// all, and is no call here. The fixture in testdata/qoder, with counts, is
|
|
// what a model of the user's own writes.
|
|
func TestQoderCalls(t *testing.T) {
|
|
home := setupAgents(t)
|
|
copyTree(t, "testdata/qoder-1.1.89/qoder", filepath.Join(home, ".qoder"))
|
|
copyTree(t, "testdata/qoder-1.1.89/qoder-cn", filepath.Join(home, ".qoder-cn"))
|
|
const qoderAuto, qoderCNAuto = "5f0c9a3e-2b7d-4c1a-9e8f-3a6b1d2c4e51", "7a2e4c6b-8d1f-4a3e-b5c7-9e0d2f4a6b83"
|
|
got := map[string][]Call{}
|
|
for _, c := range Calls(time.Time{}) {
|
|
if c.Agent == "qoder" || c.Agent == "qoder-cn" {
|
|
got[c.Agent+" "+c.Session] = append(got[c.Agent+" "+c.Session], c)
|
|
}
|
|
}
|
|
at := func(s string) time.Time {
|
|
v, _ := time.Parse(time.RFC3339Nano, s)
|
|
return v
|
|
}
|
|
for _, w := range []struct {
|
|
key string
|
|
msgs []string
|
|
times []string
|
|
credits []float64
|
|
}{
|
|
// newest first
|
|
{"qoder " + qoderAuto, []string{"msg_q2", "msg_q1"}, []string{"2026-11-15T08:12:09.330Z", "2026-11-15T08:12:05.871Z"}, []float64{0.18, 0.42}},
|
|
{"qoder-cn " + qoderCNAuto, []string{"msg_c1"}, []string{"2026-11-15T09:00:03.250Z"}, []float64{1.5}},
|
|
} {
|
|
cs := got[w.key]
|
|
if len(cs) != len(w.msgs) {
|
|
t.Fatalf("%s: want %d calls, got %d: %+v", w.key, len(w.msgs), len(cs), cs)
|
|
}
|
|
for i, c := range cs {
|
|
if c.Msg != w.msgs[i] || !c.Time.Equal(at(w.times[i])) || c.Model != "auto" || c.Tokens != (Tokens{}) || c.Credits == nil || *c.Credits != w.credits[i] {
|
|
t.Fatalf("%s call %d: %+v (credits %v)", w.key, i, c, c.Credits)
|
|
}
|
|
}
|
|
}
|
|
// a model of the user's own, its counts written: Qoder's subagent's
|
|
// reply is a call too
|
|
var tokens Tokens
|
|
for _, c := range got["qoder "+qoderID] {
|
|
tokens.Input += c.Input
|
|
tokens.Output += c.Output
|
|
tokens.CacheRead += c.CacheRead
|
|
if c.Model != "qwen3-coder-plus" || c.Credits != nil {
|
|
t.Fatalf("qoder %s: %+v", qoderID, c)
|
|
}
|
|
}
|
|
if tokens.Input == 0 || tokens.Output == 0 {
|
|
t.Fatalf("qoder %s: no tokens read from its counts: %+v", qoderID, got["qoder "+qoderID])
|
|
}
|
|
}
|
|
|
|
// A count that isn't a number loses only itself, not the reply's line.
|
|
func TestQoderCreditsOfAnotherType(t *testing.T) {
|
|
var l ccCall
|
|
if err := ccDecode([]byte(`{"type":"assistant","timestamp":"2026-11-15T08:12:05.871Z","message":{"id":"m","model":"auto","content":[],"usage":{"input_tokens":3,"credits":"0.4"}}}`), &l); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if l.Message.Usage == nil || l.Message.Usage.Input != 3 || l.Message.Usage.Credits.Set {
|
|
t.Fatalf("%+v", l.Message.Usage)
|
|
}
|
|
}
|