feat(chat): per-chat permission modes for Claude, Codex and OpenCode

This commit is contained in:
2026-10-24 18:16:10 +01:00
parent ef575898f2
commit 6d430948a6
29 changed files with 1512 additions and 3 deletions
+45
View File
@@ -0,0 +1,45 @@
package opencode
import (
"context"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
)
func TestChosenAgentRidesOnEveryPrompt(t *testing.T) {
for _, backend := range []string{"v2", "v1"} {
t.Run(backend, func(t *testing.T) {
var bodies []map[string]any
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
raw, _ := io.ReadAll(r.Body)
var body map[string]any
_ = json.Unmarshal(raw, &body)
bodies = append(bodies, body)
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"data":{"id":"msg_1","sessionID":"ses_1","type":"user"}}`))
}))
defer srv.Close()
conn := &Connection{Backend: backend, URL: srv.URL, Directory: "/repo", models: map[string]map[string]string{}, responses: map[string][]byte{}}
chat := NewChat(conn)
ctx := context.Background()
if err := chat.SetMode(ctx, "ses_1", "auto"); err == nil {
t.Fatal("an unknown agent was accepted")
}
if err := chat.Prompt(ctx, "ses_1", "before"); err != nil {
t.Fatal(err)
}
if err := chat.SetMode(ctx, "ses_1", "plan"); err != nil {
t.Fatal(err)
}
if err := chat.Prompt(ctx, "ses_1", "after"); err != nil {
t.Fatal(err)
}
if len(bodies) != 2 || bodies[0]["agent"] != nil || bodies[1]["agent"] != "plan" {
t.Fatalf("prompt bodies = %v", bodies)
}
})
}
}