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
73 lines
2.6 KiB
Go
73 lines
2.6 KiB
Go
package runmgr
|
||
|
||
// EXT-13 红测(提案 2026-10-09-ext-g1-b1-b3 §1):回合内检索(knowledge_search
|
||
// 工具与 @knowledge 注入的同一入口 runCtx.Retrieve)在适配器放行后吃到共享命中;
|
||
// 未放行/未注册谓词时保持本人两路、零泄露。
|
||
|
||
import (
|
||
"context"
|
||
"testing"
|
||
|
||
core "git-ssh.u1680832.nyat.app/weichen/Agent-System-Core.git"
|
||
)
|
||
|
||
type sharedFakeRetriever struct {
|
||
own []core.RetrievalHit
|
||
shared []core.RetrievalHit
|
||
gotAlt bool
|
||
}
|
||
|
||
func (f *sharedFakeRetriever) Retrieve(ctx context.Context, owner core.ID, q core.RetrievalQuery) ([]core.RetrievalHit, error) {
|
||
return f.own, nil
|
||
}
|
||
|
||
func (f *sharedFakeRetriever) RetrieveShared(ctx context.Context, owner core.ID, q core.RetrievalQuery, allow func(docOwner, projectID core.ID) bool) ([]core.RetrievalHit, error) {
|
||
f.gotAlt = true
|
||
out := append([]core.RetrievalHit{}, f.own...) // 对齐 rag.Pipeline:本人两路如常
|
||
for _, h := range f.shared {
|
||
if allow(h.Doc.Owner, h.Doc.ProjectID) {
|
||
out = append(out, h)
|
||
}
|
||
}
|
||
return out, nil
|
||
}
|
||
|
||
func TestRunContextRetrieveShared(t *testing.T) {
|
||
m := New(nil, nil, nil, nil, nil, nil, nil, nil, nil)
|
||
fr := &sharedFakeRetriever{
|
||
own: []core.RetrievalHit{{Doc: core.KnowledgeDoc{Ref: "own-1", Chunk: "本人命中"}}},
|
||
shared: []core.RetrievalHit{{Doc: core.KnowledgeDoc{Ref: "sh-1", Chunk: "共享命中", Owner: "alice", ProjectID: "p-1"}}},
|
||
}
|
||
m.SetRetriever(fr)
|
||
rc := &runCtx{mgr: m, run: core.Run{Owner: "bob"}}
|
||
|
||
// 未注册共享谓词:本人两路如常,不触碰共享通道。
|
||
hits, err := rc.Retrieve(core.RetrievalQuery{Text: "命中"})
|
||
if err != nil || len(hits) != 1 || hits[0].Doc.Ref != "own-1" {
|
||
t.Fatalf("no predicate: hits=%+v err=%v", hits, err)
|
||
}
|
||
if fr.gotAlt {
|
||
t.Fatal("no predicate: must not call RetrieveShared(未注册=现状)")
|
||
}
|
||
|
||
// 注册谓词(放行 bob×p-1)→ 本人 + 共享。
|
||
m.SetSharedKnowledgeAllow(func(owner string, projectID core.ID) bool {
|
||
return owner == "bob" && string(projectID) == "p-1"
|
||
})
|
||
fr.gotAlt = false
|
||
hits, err = rc.Retrieve(core.RetrievalQuery{Text: "命中"})
|
||
if err != nil || len(hits) != 2 {
|
||
t.Fatalf("with predicate: hits=%+v err=%v, want own+shared", hits, err)
|
||
}
|
||
if !fr.gotAlt {
|
||
t.Fatal("with predicate: RetrieveShared not consulted(EXT-13)")
|
||
}
|
||
|
||
// 谓词拒绝 → 只剩本人。
|
||
m.SetSharedKnowledgeAllow(func(owner string, projectID core.ID) bool { return false })
|
||
hits, err = rc.Retrieve(core.RetrievalQuery{Text: "命中"})
|
||
if err != nil || len(hits) != 1 || hits[0].Doc.Ref != "own-1" {
|
||
t.Fatalf("denied: hits=%+v err=%v, want own only", hits, err)
|
||
}
|
||
}
|