fix(chat): recover web approvals and questions across clients and reconnects

This commit is contained in:
2026-10-20 17:23:07 +01:00
parent ed0abb976d
commit c78def70dd
16 changed files with 420 additions and 54 deletions
@@ -0,0 +1,24 @@
package opencode
import (
"context"
"net/http"
"net/http/httptest"
"testing"
)
func TestChatFormsReadbackUsesSessionOwnership(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/session/ses_otherdir/form" {
t.Errorf("wrong session path: %s", r.URL.Path)
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"data":[{"id":"f_1","sessionID":"ses_otherdir","title":"Pending before connect","metadata":{"kind":"question"},"fields":[{"key":"answer","type":"text","required":true}]},{"id":"foreign","sessionID":"ses_foreign"}]}`))
}))
defer srv.Close()
chat := NewChat(&Connection{Backend: "v2", URL: srv.URL, Directory: "/unrelated"})
forms, err := chat.Forms(context.Background(), "ses_otherdir")
if err != nil || len(forms) != 1 || forms[0].ID != "f_1" || len(forms[0].Fields) != 1 || !forms[0].Fields[0].Required {
t.Fatalf("forms=%+v err=%v", forms, err)
}
}