chore: 项目基线(基于 WeKnora 定制版,整理文件忽略规则)

This commit is contained in:
runny committed 2026-11-13 17:54:56 +08:00
commit 9097ee699d
5769 files changed
+1446466

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
package agent
import (
"testing"
"github.com/Tencent/WeKnora/internal/types"
)
func TestTurnUsageNilWhenNothingReported(t *testing.T) {
if turnUsage(nil) != nil {
t.Fatal("nil state must yield no usage")
}
if turnUsage(&types.AgentState{}) != nil {
t.Fatal("a turn whose rounds reported no usage must omit the field entirely")
}
}
func TestTurnUsageCopiesTheAggregate(t *testing.T) {
state := &types.AgentState{}
state.TurnUsage.Accumulate(types.TokenUsage{PromptTokens: 100, CompletionTokens: 20, TotalTokens: 120})
usage := turnUsage(state)
if usage == nil || usage.TotalTokens != 120 {
t.Fatalf("aggregate not propagated: %+v", usage)
}
// The returned pointer must be a copy: later state mutation must not
// reach an event that has already been emitted.
state.TurnUsage.Accumulate(types.TokenUsage{PromptTokens: 1, TotalTokens: 1})
if usage.TotalTokens != 120 {
t.Fatalf("emitted usage must be detached from state: %+v", usage)
}
}
// A token scale is worth persisting on its own: it calibrates the next turn's
// history loading even when the provider reported no token counts.
func TestTurnUsageKeepsAScaleWithoutTokenCounts(t *testing.T) {
usage := turnUsage(&types.AgentState{TurnUsage: types.TokenUsage{ContextTokenScale: 0.7}})
if usage == nil || usage.ContextTokenScale != 0.7 {
t.Fatalf("scale-only usage must be kept: %+v", usage)
}
}