MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestPackDropsOrphanToolMessage

Function TestPackDropsOrphanToolMessage

internal/ctx/ctx_test.go:132–150  ·  view source on GitHub ↗

TestPackDropsOrphanToolMessage: if budget-trimming cuts the assistant whose tool_calls spawned a tool message, that orphan must be dropped, else OpenAI-compat servers 400 with "tool message without preceding tool_calls".

(t *testing.T)

Source from the content-addressed store, hash-verified

130 t.Fatal("newest should have been kept even if over budget")
131 }
132}
133
134// TestPackDropsOrphanToolMessage: if budget-trimming cuts the assistant whose
135// tool_calls spawned a tool message, that orphan must be dropped, else
136// OpenAI-compat servers 400 with "tool message without preceding tool_calls".
137func TestPackDropsOrphanToolMessage(t *testing.T) {
138 fortyX := strings.Repeat("x", 40)
139 history := []Message{
140 {Role: RoleAssistant, ToolCalls: []ToolCall{{ID: "c1", Name: "bash"}}},
141 {Role: RoleTool, ToolCallID: "c1", Content: fortyX},
142 {Role: RoleAssistant, Content: "reply"},
143 }
144 // Tight enough to drop the first assistant, loose enough that the tool
145 // message would otherwise survive. Tuned against the +8 per-message overhead.
146 r := Pack(history, 30)
147 for _, m := range r.Messages {
148 if m.Role == RoleTool {
149 t.Fatalf("orphan tool message survived pack: %+v", r.Messages)
150 }
151 }
152 if len(r.Messages) == 0 {
153 t.Fatal("newest assistant should have survived")

Callers

nothing calls this directly

Calls 1

PackFunction · 0.85

Tested by

no test coverage detected