MCPcopy Index your code
hub / github.com/docker/docker-agent / TestEstimateMessageTokens

Function TestEstimateMessageTokens

pkg/compaction/compaction_test.go:13–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestEstimateMessageTokens(t *testing.T) {
14 t.Parallel()
15
16 tests := []struct {
17 name string
18 msg chat.Message
19 expected int64
20 }{
21 {
22 name: "empty message returns overhead only",
23 msg: chat.Message{},
24 expected: 5, // perMessageOverhead
25 },
26 {
27 name: "text-only message",
28 msg: chat.Message{Content: "Hello, world!"}, // 13 chars → 13/4 = 3 + 5 = 8
29 expected: 8,
30 },
31 {
32 name: "multi-content text parts",
33 msg: chat.Message{
34 MultiContent: []chat.MessagePart{
35 {Type: chat.MessagePartTypeText, Text: "first part"}, // 10 chars
36 {Type: chat.MessagePartTypeText, Text: "second part"}, // 11 chars
37 },
38 },
39 // 21 total chars → 21/4 = 5 + 5 overhead = 10
40 expected: 10,
41 },
42 {
43 name: "message with tool calls",
44 msg: chat.Message{
45 ToolCalls: []tools.ToolCall{
46 {
47 Function: tools.FunctionCall{
48 Name: "read_file", // 9 chars
49 Arguments: `{"path":"/tmp/test.txt"}`, // 24 chars
50 },
51 },
52 },
53 },
54 // 33 chars → 33/4 = 8 + 5 overhead = 13
55 expected: 13,
56 },
57 {
58 name: "message with reasoning content",
59 msg: chat.Message{
60 Content: "answer", // 6 chars
61 ReasoningContent: "Let me think about this carefully step by step", // 47 chars
62 },
63 // 53 chars → 53/4 = 13 + 5 overhead = 18
64 expected: 18,
65 },
66 {
67 name: "combined content types",
68 msg: chat.Message{
69 Content: "result", // 6 chars
70 ReasoningContent: "thinking", // 8 chars

Callers

nothing calls this directly

Calls 2

EstimateMessageTokensFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected