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
This commit is contained in:
1 parent
a819fa3230
commit
f782b612ec
213 files changed
+37401
-2
No files matched your search
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
package hook
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPreToolUseBlockAndRewrite(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
r.On(PreToolUse, func(_ context.Context, ev Event) Result {
|
||||
if ev.ToolName == "Bash" {
|
||||
return Result{Decision: "block", Message: "no bash"}
|
||||
}
|
||||
return Result{UpdatedInput: []byte(`{"x":1}`)}
|
||||
})
|
||||
if block, msg, _ := r.PreToolUse(context.Background(), "Bash", nil); !block || msg != "no bash" {
|
||||
t.Fatalf("expected block, got %v %q", block, msg)
|
||||
}
|
||||
if block, _, upd := r.PreToolUse(context.Background(), "Read", nil); block || string(upd) != `{"x":1}` {
|
||||
t.Fatalf("expected rewrite, got block=%v upd=%s", block, upd)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStopHookBlockingContinues(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
calls := 0
|
||||
r.On(Stop, func(_ context.Context, _ Event) Result {
|
||||
calls++
|
||||
if calls == 1 {
|
||||
return Result{Decision: "block", AdditionalContext: "keep going"}
|
||||
}
|
||||
return Result{}
|
||||
})
|
||||
// First call: a "block" decision → continue with an injected message.
|
||||
prevent, blocking, _ := r.Stop(context.Background(), nil)
|
||||
if prevent || len(blocking) != 1 || blocking[0] != "keep going" {
|
||||
t.Fatalf("blocking path wrong: prevent=%v blocking=%v", prevent, blocking)
|
||||
}
|
||||
// Second call: no decision → allow stop.
|
||||
if prevent, blocking, _ := r.Stop(context.Background(), nil); prevent || len(blocking) != 0 {
|
||||
t.Fatalf("second Stop should allow: prevent=%v blocking=%v", prevent, blocking)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStopHookPreventTerminates(t *testing.T) {
|
||||
r := NewRegistry()
|
||||
r.On(Stop, func(_ context.Context, _ Event) Result {
|
||||
return Result{PreventContinuation: true, Message: "halt"}
|
||||
})
|
||||
prevent, _, msg := r.Stop(context.Background(), nil)
|
||||
if !prevent || msg != "halt" {
|
||||
t.Fatalf("prevent path wrong: prevent=%v msg=%q", prevent, msg)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user