Why: Higher-ranked private rows could exhaust SQL candidate limits and hide an otherwise authorized published slice from a member's current-project search. Evidence: SELF TestAuthorizedKnowledgeFiltersBeforeTopK failed with no shared hits before the change and passed after it. SELF go test ./... and the isolated PostgreSQL Store suite passed; independent replay and current-HEAD CI remain owner gates. Impact: Scan the resource-authorized shared fulltext path until enough allowed results are found. Preserve ordinary legacy retrieval candidate limits and semantics. Refs: Dev project-member-access plan r1 Task 1; R5 published knowledge availability
23 lines
974 B
Go
23 lines
974 B
Go
package store
|
|
|
|
import (
|
|
core "agent-system-core"
|
|
"testing"
|
|
)
|
|
|
|
func TestAuthorizedKnowledgeFiltersBeforeTopK(t *testing.T) {
|
|
st := openTestStore(t)
|
|
docs := []core.KnowledgeDoc{}
|
|
for i := 0; i < 20; i++ {
|
|
docs = append(docs, core.KnowledgeDoc{Owner: "alice", ProjectID: "domain", Source: "private", Chunk: "sharedterm sharedterm sharedterm sharedterm"})
|
|
}
|
|
docs = append(docs, core.KnowledgeDoc{ID: "published", Owner: "alice", ProjectID: "domain", Source: "plugin:rdm:published", Chunk: "sharedterm plus additional explanatory words for this lower scoring published source"})
|
|
if err := st.AddKnowledge(docs...); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
hits, err := st.SearchKnowledgeSharedAuthorized("bob", core.RetrievalQuery{Text: "sharedterm", ProjectID: "domain", TopK: 1}, func(d core.KnowledgeDoc) bool { return d.ID == "published" })
|
|
if err != nil || len(hits) != 1 || hits[0].Doc.ID != "published" {
|
|
t.Fatalf("denied rows consumed top-k: %+v %v", hits, err)
|
|
}
|
|
}
|