feat(chat): per-chat permission modes for Claude, Codex and OpenCode
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package codex
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestModePresetRidesOnTheNextTurn(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
var turns []map[string]any
|
||||
chat := modelTestChat(t, func(method string, raw json.RawMessage) any {
|
||||
if method != "turn/start" {
|
||||
t.Errorf("unexpected operation: %s", method)
|
||||
return map[string]any{}
|
||||
}
|
||||
var params map[string]any
|
||||
_ = json.Unmarshal(raw, ¶ms)
|
||||
mu.Lock()
|
||||
turns = append(turns, params)
|
||||
mu.Unlock()
|
||||
return json.RawMessage(`{"turn":{"id":"turn-fixture","status":"inProgress","items":[]}}`)
|
||||
})
|
||||
ctx := context.Background()
|
||||
if err := chat.SetMode(ctx, fixtureThread, "yolo"); err == nil {
|
||||
t.Fatal("an unlisted mode was accepted")
|
||||
}
|
||||
if err := chat.Prompt(ctx, fixtureThread, "plain"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := chat.SetMode(ctx, fixtureThread, "auto"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := chat.Prompt(ctx, fixtureThread, "auto"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := chat.SetMode(ctx, fixtureThread, "full"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := chat.Prompt(ctx, fixtureThread, "full"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(turns) != 3 {
|
||||
t.Fatalf("turns = %d", len(turns))
|
||||
}
|
||||
if turns[0]["approvalPolicy"] != nil || turns[0]["sandboxPolicy"] != nil {
|
||||
t.Fatalf("no mode chosen, yet overrides were sent: %v", turns[0])
|
||||
}
|
||||
sandbox := func(turn map[string]any) any { return turn["sandboxPolicy"].(map[string]any)["type"] }
|
||||
if turns[1]["approvalPolicy"] != "never" || sandbox(turns[1]) != "workspaceWrite" {
|
||||
t.Fatalf("auto turn = %v", turns[1])
|
||||
}
|
||||
if turns[2]["approvalPolicy"] != "never" || sandbox(turns[2]) != "dangerFullAccess" {
|
||||
t.Fatalf("full turn = %v", turns[2])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user