chat: reconcile history by canonical message identity

This commit is contained in:
2026-10-19 00:08:30 +01:00
parent 3187b0c06e
commit 7da3d54013
13 changed files with 189 additions and 15 deletions
+19
View File
@@ -64,6 +64,25 @@ func TestChatV2PromptShapeAndAuth(t *testing.T) {
}
}
func TestChatV2PromptWithMessageID(t *testing.T) {
var body map[string]string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
t.Fatal(err)
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":{"id":"msg_canonical","sessionID":"ses_1","type":"user"}}`))
}))
defer srv.Close()
chat := NewChat(&Connection{Backend: "v2", URL: srv.URL})
if err := chat.PromptWithMessageID(context.Background(), "ses_1", "same text", "msg_canonical"); err != nil {
t.Fatal(err)
}
if body["id"] != "msg_canonical" || body["text"] != "same text" {
t.Fatalf("prompt body = %+v", body)
}
}
// TestChatStreamRealV2Shapes replays the exact event frames the installed 2.0.20
// service emitted on /api/event during a live turn (captured, not documented):
// a step start, token text delta, usage and a step end whose data carries no