Files
ARTEX/third_party/norma/permission/permission_test.go
T
wangdefa f782b612ec build: 内置 norma 模块,构建不再依赖上游仓库
把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到
third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或
改写 tag 都不再影响本仓库构建。

- 已验证 GOPROXY=off 下可完整编译并打出发行包
- go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希)
- 升级方法与授权注意事项见 third_party/README.md
2026-10-20 21:10:41 -07:00

59 lines
1.6 KiB
Go

package permission
import (
"context"
"encoding/json"
"testing"
)
func eval(req Request) Behavior {
return Evaluate(context.Background(), req).Behavior
}
func TestDenyPriorityOverBypass(t *testing.T) {
req := Request{ToolName: "Bash", Ctx: Context{Mode: ModeBypass, Disallowed: []string{"Bash"}}}
if b := eval(req); b != Deny {
t.Fatalf("deny must beat bypass, got %v", b)
}
}
func TestReadOnlyAutoAllow(t *testing.T) {
if b := eval(Request{ToolName: "Read", IsReadOnly: true, Ctx: Context{Mode: ModeDefault}}); b != Allow {
t.Fatalf("read-only should allow, got %v", b)
}
}
func TestPlanModeDeniesWrites(t *testing.T) {
if b := eval(Request{ToolName: "Write", IsReadOnly: false, Ctx: Context{Mode: ModePlan}}); b != Deny {
t.Fatalf("plan mode should deny writes, got %v", b)
}
}
func TestAcceptEditsAllowsEdit(t *testing.T) {
if b := eval(Request{ToolName: "Edit", Ctx: Context{Mode: ModeAcceptEdits}}); b != Allow {
t.Fatalf("acceptEdits should allow Edit, got %v", b)
}
}
func TestAskReachesCallback(t *testing.T) {
called := false
req := Request{
ToolName: "Bash", IsReadOnly: false,
ToolDecision: AskUser("?"),
Ctx: Context{Mode: ModeDefault},
Ask: func(_ context.Context, _ string, _ json.RawMessage, _ Context) Decision {
called = true
return Allowed()
},
}
if b := eval(req); b != Allow || !called {
t.Fatalf("ask callback not honored: b=%v called=%v", b, called)
}
}
func TestAllowRuleMatchesParenForm(t *testing.T) {
if b := eval(Request{ToolName: "Bash", Ctx: Context{Mode: ModeDefault, Allowed: []string{"Bash(git:*)"}}}); b != Allow {
t.Fatalf("paren allow rule should match tool name, got %v", b)
}
}