(t *testing.T)
| 1644 | } |
| 1645 | |
| 1646 | func TestEmitStartupInfo_WithSessionTokenData(t *testing.T) { |
| 1647 | t.Parallel() |
| 1648 | |
| 1649 | // When restoring a session that already has token data, |
| 1650 | // EmitStartupInfo should emit a TokenUsageEvent with the context limit |
| 1651 | // looked up from the model store so the sidebar can display context %. |
| 1652 | prov := &mockProvider{id: "test/startup-model", stream: &mockStream{}} |
| 1653 | root := agent.New("startup-test-agent", "You are a startup test agent", |
| 1654 | agent.WithModel(prov), |
| 1655 | agent.WithDescription("Startup agent"), |
| 1656 | ) |
| 1657 | tm := team.New(team.WithAgents(root)) |
| 1658 | |
| 1659 | rt, err := NewLocalRuntime(t.Context(), tm, WithCurrentAgent("startup-test-agent"), |
| 1660 | WithModelStore(mockModelStoreWithLimit{limit: 200_000})) |
| 1661 | require.NoError(t, err) |
| 1662 | |
| 1663 | // Create a session with existing token data (simulating session restore) |
| 1664 | sess := session.New() |
| 1665 | sess.InputTokens = 5000 |
| 1666 | sess.OutputTokens = 1000 |
| 1667 | |
| 1668 | events := make(chan Event, 20) |
| 1669 | rt.EmitStartupInfo(t.Context(), sess, NewChannelSink(events)) |
| 1670 | close(events) |
| 1671 | |
| 1672 | // Collect events and find the TokenUsageEvent |
| 1673 | var tokenEvent *TokenUsageEvent |
| 1674 | for event := range events { |
| 1675 | if te, ok := event.(*TokenUsageEvent); ok { |
| 1676 | tokenEvent = te |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | require.NotNil(t, tokenEvent, "EmitStartupInfo should emit a TokenUsageEvent for a session with token data") |
| 1681 | assert.Equal(t, sess.ID, tokenEvent.SessionID) |
| 1682 | assert.Equal(t, int64(5000), tokenEvent.Usage.InputTokens) |
| 1683 | assert.Equal(t, int64(1000), tokenEvent.Usage.OutputTokens) |
| 1684 | assert.Equal(t, int64(6000), tokenEvent.Usage.ContextLength) |
| 1685 | assert.Equal(t, int64(200_000), tokenEvent.Usage.ContextLimit) |
| 1686 | } |
| 1687 | |
| 1688 | func TestEmitStartupInfo_CostIncludesSubSessions(t *testing.T) { |
| 1689 | t.Parallel() |
nothing calls this directly
no test coverage detected