Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit d84f0ca

Browse files
committed
fix: Tool order test
1 parent c31f880 commit d84f0ca

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

internal/llm/system_prompt_template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ You are an interactive CLI agent specializing in software engineering tasks. You
136136
137137
## Caution
138138
- You cannot test tui programs directly by default
139+
- Do not use 'exec.Command' or 'os/exec' to execute commands in the sandbox
139140
`
140141

141142
var systemPrompt = template.Must(template.New("systemPrompt").Parse(systemPromptTemplate))
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package orchestrator
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
"time"
8+
9+
"github.com/codefionn/scriptschnell/internal/progress"
10+
"github.com/codefionn/scriptschnell/internal/session"
11+
"github.com/codefionn/scriptschnell/internal/tools"
12+
)
13+
14+
func TestProcessToolCallsPreservesOrder(t *testing.T) {
15+
ctx := context.Background()
16+
sess := session.NewSession("test", ".")
17+
18+
toolCalls := []map[string]interface{}{
19+
{
20+
"id": "call-1",
21+
"type": "function",
22+
"function": map[string]interface{}{
23+
"name": "fast-tool",
24+
"arguments": "{}",
25+
},
26+
},
27+
{
28+
"id": "call-2",
29+
"type": "function",
30+
"function": map[string]interface{}{
31+
"name": "slow-tool",
32+
"arguments": "{}",
33+
},
34+
},
35+
}
36+
37+
orch := &Orchestrator{}
38+
39+
// Run calls with different latencies to ensure ordering is dictated by the
40+
// original call index, not completion time.
41+
execFn := func(ctx context.Context, call *tools.ToolCall, toolName string, progressCb progress.Callback, toolCallCb ToolCallCallback, toolResultCb ToolResultCallback, approved bool) (*tools.ToolResult, error) {
42+
if toolName == "slow-tool" {
43+
time.Sleep(15 * time.Millisecond)
44+
}
45+
return &tools.ToolResult{
46+
ID: call.ID,
47+
Result: fmt.Sprintf("result-%s", call.ID),
48+
}, nil
49+
}
50+
51+
if err := orch.processToolCalls(ctx, toolCalls, sess, nil, nil, nil, nil, execFn); err != nil {
52+
t.Fatalf("processToolCalls returned error: %v", err)
53+
}
54+
55+
messages := sess.GetMessages()
56+
if len(messages) != 2 {
57+
t.Fatalf("expected 2 tool messages, got %d", len(messages))
58+
}
59+
60+
if messages[0].ToolID != "call-1" || messages[0].ToolName != "fast-tool" || messages[0].Content != "result-call-1" {
61+
t.Fatalf("unexpected first tool message: %+v", messages[0])
62+
}
63+
64+
if messages[1].ToolID != "call-2" || messages[1].ToolName != "slow-tool" || messages[1].Content != "result-call-2" {
65+
t.Fatalf("unexpected second tool message: %+v", messages[1])
66+
}
67+
}

0 commit comments

Comments
 (0)