Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements. Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate. Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable. Refs: Versioned dependencies U1/U3; feature/dependency-workspace
56 lines
2.1 KiB
Go
56 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/cmdbus"
|
|
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/store"
|
|
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/pkg/extension"
|
|
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
|
|
)
|
|
|
|
// fakeExtAuthz 进程内扩展:注册 EXT-8 适配器+一条命令——修复前适配器注册被
|
|
// 声明式分支拒绝,register() 中止导致命令全部丢失。
|
|
type fakeExtAuthz struct{}
|
|
|
|
func (f *fakeExtAuthz) Register(reg extension.Registry) error {
|
|
if err := reg.RegisterResourceAuthorizer(func(owner string, projectID core.ID) (bool, error) {
|
|
return owner == "alice", nil
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
return reg.AddCommandHandler([]byte(`{"id":"t.authz.ping","title":"t"}`),
|
|
func(ctx context.Context, h extension.Host, req extension.Request) (any, error) {
|
|
return map[string]any{"ok": true}, nil
|
|
})
|
|
}
|
|
|
|
func TestInprocPluginRegistersAuthorizerAndCommands(t *testing.T) {
|
|
extension.ResetCompiled()
|
|
extension.RegisterCompiled(extension.InProc{ID: "t", Register: (&fakeExtAuthz{}).Register})
|
|
defer extension.ResetCompiled()
|
|
st, err := store.OpenSQLite(t.TempDir() + "/t.db")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer st.Close()
|
|
bus := cmdbus.New(st, nil, func() time.Time { return time.Unix(1700000000, 0).UTC() })
|
|
caps := hostcaps{st: st, authz: &projectAuthz{}}
|
|
applyCompiled("", bus, caps)
|
|
// ① 命令已注册且可分发(修复前:适配器注册被拒 → register() 中止 →
|
|
// 命令全部丢失,rdm.* 全部 unknown command)。
|
|
if resp := bus.Dispatch(context.Background(), cmdbus.Request{
|
|
ID: "t.authz.ping", Entrance: "button", Owner: "alice"}); resp.Receipt.State != "committed" {
|
|
t.Fatalf("命令分发 = %+v(注册整体中止)", resp.Receipt)
|
|
}
|
|
// ② 适配器经共享槽生效:alice 放行、bob 拒绝。
|
|
if ok, _ := caps.authz.Authorize("alice", "p1"); !ok {
|
|
t.Fatal("alice 应放行")
|
|
}
|
|
if ok, _ := caps.authz.Authorize("bob", "p1"); ok {
|
|
t.Fatal("bob 应被拒绝")
|
|
}
|
|
}
|