chore: 初始化仓库,导入项目基线代码

Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
This commit is contained in:
runny committed 2026-11-16 18:12:23 +08:00
commit 7ec21f35b0
5767 files changed
+1436788

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
package agent
import (
"testing"
"academy/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)
}
}