ci / vet-and-test (pull_request) Successful in 57s
Why: RDM KTD4 dual-layer admin requires base isAdmin visibility (superuser slot); KTD5 host-project binding needs trusted current-project context. Evidence: SELF 4 ext18 tests pass + surface snapshot regenerated + full pkg/extension + internal/app suites green. Impact: extension.Request gains HostProjectID; optional AdminProvider interface (EXT-17 pattern); inprocHost implements IsAdmin via GetUserAuthState; three dispatch sites set HostProjectID from conversation. Refs: RDM docs/proposals U1 base extension requests
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package app
|
||
|
||
// EXT-18 AdminProvider 正负例:admin 主体 → true;非 admin / 空 actor(scoped
|
||
// host)→ false;store 查询失败 → false(fail-closed)。
|
||
|
||
import (
|
||
"testing"
|
||
|
||
"agent-system-backend/internal/store"
|
||
)
|
||
|
||
func TestExt18AdminProviderPositive(t *testing.T) {
|
||
st, err := store.OpenSQLite(t.TempDir() + "/t.db")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if err := st.CreateAccount("boss", "Boss", "pw", true); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
h := inprocHost{caps: hostcaps{st: st}, pluginID: "tst", owner: "boss", actor: "boss"}
|
||
if !h.IsAdmin() {
|
||
t.Fatal("admin 主体应返回 true")
|
||
}
|
||
}
|
||
|
||
func TestExt18AdminProviderNegative(t *testing.T) {
|
||
st, err := store.OpenSQLite(t.TempDir() + "/t.db")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if err := st.CreateAccount("user", "User", "pw", false); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
h := inprocHost{caps: hostcaps{st: st}, pluginID: "tst", owner: "user", actor: "user"}
|
||
if h.IsAdmin() {
|
||
t.Fatal("非 admin 主体应返回 false")
|
||
}
|
||
}
|
||
|
||
func TestExt18AdminProviderEmptyActor(t *testing.T) {
|
||
st, err := store.OpenSQLite(t.TempDir() + "/t.db")
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
if err := st.CreateAccount("boss", "Boss", "pw", true); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
h := inprocHost{caps: hostcaps{st: st}, pluginID: "tst", owner: "boss", actor: ""} // scoped host(无 dispatch)
|
||
if h.IsAdmin() {
|
||
t.Fatal("空 actor(非 dispatch 上下文)恒 false")
|
||
}
|
||
}
|
||
|
||
func TestExt18RequestHostProjectIDField(t *testing.T) {
|
||
// 编译期断言:Request 有 HostProjectID 字段。
|
||
_ = ""
|
||
var r struct{ HostProjectID string }
|
||
r.HostProjectID = "proj-1"
|
||
if r.HostProjectID != "proj-1" {
|
||
t.Fatal("字段赋值失败")
|
||
}
|
||
}
|