mirror of
https://github.com/docker/docker-agent.git
synced 2026-11-04 18:30:09 +00:00
Adds Model+Usage to compactor.Result and session.Item (migration 25), threads them through SessionSummaryEvent, persistence, and the server AddSummary path so the TUI /cost By Model breakdown includes compaction spend instead of silently dropping it.
40 lines
1.5 KiB
Go
40 lines
1.5 KiB
Go
package runtime
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/docker/docker-agent/pkg/chat"
|
|
"github.com/docker/docker-agent/pkg/session"
|
|
)
|
|
|
|
// TestPersistenceObserver_PersistsSummaryCost verifies the cost carried by a
|
|
// SessionSummaryEvent reaches the persisted summary item. Without it, a
|
|
// reloaded session under-reports TotalCost by everything compaction billed.
|
|
func TestPersistenceObserver_PersistsSummaryCost(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
store := session.NewInMemorySessionStore()
|
|
obs := newPersistenceObserver(store)
|
|
require.NotNil(t, obs)
|
|
|
|
sess := session.New(session.WithID("s1"), session.WithUserMessage("hi"))
|
|
require.NoError(t, store.AddSession(t.Context(), sess))
|
|
|
|
obs.OnEvent(t.Context(), sess, SessionSummary(sess.ID, "the summary", "root", 1, 0.002, "openai/gpt-4o-mini", &chat.Usage{InputTokens: 100, OutputTokens: 20}))
|
|
|
|
reloaded, err := store.GetSession(t.Context(), sess.ID)
|
|
require.NoError(t, err)
|
|
|
|
last := reloaded.Messages[len(reloaded.Messages)-1]
|
|
require.Equal(t, "the summary", last.Summary)
|
|
assert.Equal(t, 1, last.FirstKeptEntry)
|
|
assert.InDelta(t, 0.002, last.Cost, 1e-9, "the event's cost must land on the summary item")
|
|
assert.Equal(t, "openai/gpt-4o-mini", last.Model, "the event's model must land on the summary item")
|
|
require.NotNil(t, last.Usage, "the event's usage must land on the summary item")
|
|
assert.Equal(t, int64(100), last.Usage.InputTokens)
|
|
assert.Equal(t, int64(20), last.Usage.OutputTokens)
|
|
}
|