feat(acp/handlers): session/request_permission auto-reject

This commit is contained in:
2026-05-07 12:21:18 +08:00
parent b9f38b6e94
commit 6da1dc5a40
3 changed files with 135 additions and 3 deletions
@@ -0,0 +1,68 @@
package handlers_test
import (
"context"
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/yan1h/agent-coding-workflow/internal/acp/handlers"
)
func TestPermission_AutoReject(t *testing.T) {
t.Parallel()
h := handlers.NewPermissionHandler()
params := mustJSON(t, map[string]any{
"sessionId": "x",
"toolCall": map[string]any{"name": "shell.exec"},
"options": []any{
map[string]any{"id": "allow_once"},
map[string]any{"id": "reject_once"},
},
})
res := h.Handle(context.Background(), handlers.SessionContext{}, params)
require.Nil(t, res.Err)
var out struct {
Outcome struct {
Selected struct {
ID string `json:"id"`
} `json:"selected"`
} `json:"outcome"`
}
require.NoError(t, json.Unmarshal(res.OK, &out))
assert.Equal(t, "reject_once", out.Outcome.Selected.ID)
}
func TestPermission_NoRejectOption_FallbackFirst(t *testing.T) {
t.Parallel()
h := handlers.NewPermissionHandler()
params := mustJSON(t, map[string]any{
"sessionId": "x",
"options": []any{
map[string]any{"id": "allow_once"},
map[string]any{"id": "allow_session"},
},
})
res := h.Handle(context.Background(), handlers.SessionContext{}, params)
var out struct {
Outcome struct {
Selected struct {
ID string `json:"id"`
} `json:"selected"`
} `json:"outcome"`
}
require.NoError(t, json.Unmarshal(res.OK, &out))
assert.Equal(t, "allow_once", out.Outcome.Selected.ID)
}
func TestPermission_NoOptions_EmptyOutcome(t *testing.T) {
t.Parallel()
h := handlers.NewPermissionHandler()
params := mustJSON(t, map[string]any{"sessionId": "x"})
res := h.Handle(context.Background(), handlers.SessionContext{}, params)
require.Nil(t, res.Err)
assert.JSONEq(t, `{"outcome":{}}`, string(res.OK))
}