feat(chat): per-chat permission modes for Claude, Codex and OpenCode
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOperatorChatModeMigratesAndPersists(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
path := filepath.Join(t.TempDir(), "old.db")
|
||||
db, err := sql.Open("sqlite", path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = db.Exec(`CREATE TABLE operator_sessions (session_id TEXT PRIMARY KEY, directory TEXT NOT NULL, title TEXT NOT NULL DEFAULT '', tag TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL, last_used_at INTEGER NOT NULL)`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
db.Close()
|
||||
store, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.RecordOperatorSession(ctx, "chat", "/fixture", "title", "operator"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode, err := store.ChatMode(ctx, "chat"); err != nil || mode != "" {
|
||||
t.Fatalf("fresh mode %q: %v", mode, err)
|
||||
}
|
||||
if err := store.SetChatMode(ctx, "missing", "auto"); err == nil {
|
||||
t.Fatal("unregistered chat accepted a mode")
|
||||
}
|
||||
before, _, err := store.OperatorSession(ctx, "chat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.SetChatMode(ctx, "chat", "auto"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store.Close()
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if mode, err := store.ChatMode(ctx, "chat"); err != nil || mode != "auto" {
|
||||
t.Fatalf("restored mode %q: %v", mode, err)
|
||||
}
|
||||
if mode, err := store.ChatMode(ctx, "missing"); err != nil || mode != "" {
|
||||
t.Fatalf("missing chat mode %q: %v", mode, err)
|
||||
}
|
||||
after, _, err := store.OperatorSession(ctx, "chat")
|
||||
if err != nil || before.UpdatedAt != after.UpdatedAt {
|
||||
t.Fatal("mode changed recency", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user