管理台不再把开关值当成能力已接入。lineage 读取必须落在 URL 项目内,并按两端文档可见性裁剪,跨项目或不可见文档只返回空列表。 Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/projectworkflow"
|
|
)
|
|
|
|
func TestFilterLineageEdges_DropsForeignAndHiddenEndpoints(t *testing.T) {
|
|
t.Parallel()
|
|
rows := []*projectworkflow.DocumentLineage{
|
|
{ProjectID: 1, DownstreamDocID: "doc_proj1_test_manager", UpstreamDocID: "doc_proj1_system_reqs"},
|
|
{ProjectID: 2, DownstreamDocID: "doc_proj1_test_manager", UpstreamDocID: "doc_proj2_secret"},
|
|
{ProjectID: 1, DownstreamDocID: "doc_proj1_test_manager", UpstreamDocID: "doc_proj1_hidden"},
|
|
}
|
|
visible := map[string]bool{
|
|
"doc_proj1_test_manager": true,
|
|
"doc_proj1_system_reqs": true,
|
|
}
|
|
got := filterLineageEdges(rows, 1, func(docID string) bool { return visible[docID] })
|
|
if len(got) != 1 || got[0].UpstreamDocID != "doc_proj1_system_reqs" {
|
|
t.Fatalf("only the visible in-project edge should remain, got %+v", got)
|
|
}
|
|
}
|
|
|
|
func TestLineageTestManagerAlias_DoesNotRewriteArbitraryDocs(t *testing.T) {
|
|
t.Parallel()
|
|
if alt, ok := lineageTestManagerAlias(9, "doc_proj9_intake"); ok || alt != "" {
|
|
t.Fatalf("arbitrary doc must not alias, got %q ok=%v", alt, ok)
|
|
}
|
|
alt, ok := lineageTestManagerAlias(9, "doc_proj9_test_manager")
|
|
if !ok || alt != "doc-proj9-test_manager" {
|
|
t.Fatalf("canonical test_manager alias = %q ok=%v", alt, ok)
|
|
}
|
|
}
|
|
|
|
func TestParseHyphenProjectDocID(t *testing.T) {
|
|
t.Parallel()
|
|
id, ok := parseHyphenProjectDocID("doc-proj42-test_manager")
|
|
if !ok || id != 42 {
|
|
t.Fatalf("got (%d,%v)", id, ok)
|
|
}
|
|
if _, ok := parseHyphenProjectDocID("doc_proj42_test_manager"); ok {
|
|
t.Fatal("underscore form is not a hyphen id")
|
|
}
|
|
}
|