Reject empty and truncated answers and expose complete tool calls

This commit is contained in:
sausheong committed 2026-09-11 23:48:25 +08:00
1 parent 019a38f111
commit 3ca0994437
14 files changed
+278 -7

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
package runtime
import (
"context"
"github.com/sausheong/harness/llm"
"github.com/sausheong/harness/session"
"testing"
)
func TestToolReadyCarriesArgumentsBeforeResult(t *testing.T) {
provider := &emptyResponseProvider{responses: [][]llm.ChatEvent{
{{Type: llm.EventToolCallStart, ToolCall: &llm.ToolCall{ID: "one", Name: "noop"}}, {Type: llm.EventToolCallDone, ToolCall: &llm.ToolCall{ID: "one", Name: "noop", Input: []byte(`{"command":"echo hi"}`)}}, {Type: llm.EventDone}},
{{Type: llm.EventTextDelta, Text: "Done"}, {Type: llm.EventDone}},
}}
rt := &Runtime{LLM: provider, Tools: usageNoopExecutor{}, Session: session.NewSession("test", "ready"), Model: "fixture", MaxTurns: 2}
stream, err := rt.Run(context.Background(), "go", nil)
if err != nil {
t.Fatal(err)
}
ready, results := 0, 0
for e := range stream {
switch e.Type {
case EventToolCallReady:
ready++
if e.ToolCall == nil || string(e.ToolCall.Input) != `{"command":"echo hi"}` {
t.Fatalf("%+v", e)
}
case EventToolResult:
results++
if ready != 1 {
t.Fatal("result before arguments")
}
case EventError:
t.Fatal(e.Error)
}
}
if ready != 1 || results != 1 {
t.Fatalf("ready=%d results=%d", ready, results)
}
}