Attribute OpenCode code-mode tool calls, keep same-instant shown items in order, and record the chat tools notes
This commit is contained in:
@@ -292,3 +292,39 @@ func TestInstanceTokenCallsNeedOneMatchingRunningToolCall(t *testing.T) {
|
||||
t.Fatalf("two chats running the same call must be refused: %v", r)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenCode V2 calls MCP tools from its code-mode "execute" script, so the
|
||||
// stream shows the script, not a tool part of the Pipelines tool's own name.
|
||||
func TestInstanceTokenCallsMatchOpenCodeCodeModeScripts(t *testing.T) {
|
||||
f := newChatToolFixture(t)
|
||||
token := f.token(t, chatToolInstanceScope+"opencode")
|
||||
saved := chatToolCorrelationWait
|
||||
chatToolCorrelationWait = 100 * time.Millisecond
|
||||
t.Cleanup(func() { chatToolCorrelationWait = saved })
|
||||
script := func(sessionID, part, code string) {
|
||||
input, _ := json.Marshal(map[string]string{"code": code})
|
||||
f.hub.apply(protocol.ChatEventFrame{SessionID: sessionID, MessageID: "msg_" + sessionID, Kind: protocol.ChatEventTool,
|
||||
Part: &protocol.ChatPart{Type: "tool", ID: part, Name: "execute", State: &protocol.ChatToolState{Status: protocol.ChatToolRunning, Input: input}}})
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(f.home, "a.png"), []byte("\x89PNG\r\n\x1a\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(f.home, "b.png"), []byte("\x89PNG\r\n\x1a\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
script("ses_p", "prt_p", `return tools.pipelines.show_file({ path: "~/a.png", title: "Checker" })`)
|
||||
script("ses_q", "prt_q", `return tools.other.show_file({ path: "~/a.png" })`)
|
||||
if r := f.call(token, "show_file", `{"path":"~/a.png","title":"Checker"}`); r.IsError {
|
||||
t.Fatal(r.Text)
|
||||
}
|
||||
if len(f.items(t, "ses_p")) != 1 || len(f.items(t, "ses_q")) != 0 {
|
||||
t.Fatal("the script calling the Pipelines tool owns the call")
|
||||
}
|
||||
script("ses_q", "prt_q2", `await tools.pipelines.show_file({ path: "~/b.png" })`)
|
||||
if r := f.call(token, "show_file", `{"path":"~/b.png"}`); r.IsError || len(f.items(t, "ses_q")) != 1 {
|
||||
t.Fatalf("two scripts are told apart by their arguments: %v", r)
|
||||
}
|
||||
if r := f.call(token, "show_file", `{"path":"~/c.png"}`); !r.IsError {
|
||||
t.Fatal("arguments neither script contains must not be guessed into a chat")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user