package agent import ( "fmt" "strings" "testing" ) // TestDiscoveredInstructionsSection:按路径去重、限制总量,并渲染成可读段落。 func TestDiscoveredInstructionsSection(t *testing.T) { a := &Agent{} a.AddInstructions("/repo/sub/AGENTS.md", "SUB-RULES") a.AddInstructions("/repo/sub/AGENTS.md", "SUB-RULES") sec := a.InstructionsSection() if strings.Count(sec, "SUB-RULES") != 1 { t.Fatalf("dedupe failed: %q", sec) } if !strings.Contains(sec, "discovered for the subtree") || !strings.Contains(sec, "AGENTS.md") { t.Fatalf("section shape: %q", sec) } for i := 0; i < maxDiscoveredFiles+4; i++ { a.AddInstructions(fmt.Sprintf("/repo/s%d/AGENTS.md", i), "X") } if len(a.discoveredInstructions) != maxDiscoveredFiles { t.Fatalf("files = %d, want cap %d", len(a.discoveredInstructions), maxDiscoveredFiles) } if got := a.InstructionsSection(); strings.Count(got, "X") > maxDiscoveredFiles { t.Fatalf("cap not applied to rendered section") } // 空 agent 不产生额外 system 文本。 empty := &Agent{} if got := empty.InstructionsSection(); got != "" { t.Fatalf("empty section = %q", got) } }