This commit is contained in:
2026-06-09 21:19:30 +08:00
parent 8b41ff9360
commit 0484e79978
66 changed files with 4043 additions and 533 deletions
+11 -16
View File
@@ -11,9 +11,10 @@ import (
"github.com/yan1h/agent-coding-workflow/internal/acp/handlers"
)
// 无 decider(nil)时回退到「默认拒绝」逻辑:优先选 reject 类选项。
func TestPermission_AutoReject(t *testing.T) {
t.Parallel()
h := handlers.NewPermissionHandler()
h := handlers.NewPermissionHandler(nil)
params := mustJSON(t, map[string]any{
"sessionId": "x",
"toolCall": map[string]any{"name": "shell.exec"},
@@ -22,7 +23,7 @@ func TestPermission_AutoReject(t *testing.T) {
map[string]any{"id": "reject_once"},
},
})
res := h.Handle(context.Background(), handlers.SessionContext{}, params)
res := h.Handle(context.Background(), handlers.SessionContext{}, "", params)
require.Nil(t, res.Err)
var out struct {
@@ -36,9 +37,10 @@ func TestPermission_AutoReject(t *testing.T) {
assert.Equal(t, "reject_once", out.Outcome.Selected.ID)
}
func TestPermission_NoRejectOption_FallbackFirst(t *testing.T) {
// 无 reject 类选项且无 decider 时,默认拒绝(返回空 outcome,不再误选 allow)。
func TestPermission_NoRejectOption_DefaultsToReject(t *testing.T) {
t.Parallel()
h := handlers.NewPermissionHandler()
h := handlers.NewPermissionHandler(nil)
params := mustJSON(t, map[string]any{
"sessionId": "x",
"options": []any{
@@ -46,23 +48,16 @@ func TestPermission_NoRejectOption_FallbackFirst(t *testing.T) {
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)
res := h.Handle(context.Background(), handlers.SessionContext{}, "", params)
require.Nil(t, res.Err)
assert.JSONEq(t, `{"outcome":{}}`, string(res.OK))
}
func TestPermission_NoOptions_EmptyOutcome(t *testing.T) {
t.Parallel()
h := handlers.NewPermissionHandler()
h := handlers.NewPermissionHandler(nil)
params := mustJSON(t, map[string]any{"sessionId": "x"})
res := h.Handle(context.Background(), handlers.SessionContext{}, params)
res := h.Handle(context.Background(), handlers.SessionContext{}, "", params)
require.Nil(t, res.Err)
assert.JSONEq(t, `{"outcome":{}}`, string(res.OK))
}