f2d445b891
CI / detect-changes (pull_request) Successful in 13s
CI / branch-name (pull_request) Successful in 1s
CI / guardrail-integrity (pull_request) Successful in 9s
CI / secret-scan (pull_request) Successful in 10s
CI / dep-audit (pull_request) Failing after 56s
CI / sbom-scan (pull_request) Failing after 59s
CI / build-sha-integrity (pull_request) Successful in 5s
CI / validate-canonical-controls (pull_request) Successful in 3s
CI / test-python-document-crawler (pull_request) Successful in 15s
CI / test-python-dsms-gateway (pull_request) Successful in 13s
CI / loc-budget (pull_request) Successful in 23s
CI / go-lint (pull_request) Failing after 51s
CI / python-lint (pull_request) Failing after 18s
CI / nodejs-lint (pull_request) Failing after 1m8s
CI / nodejs-build (pull_request) Successful in 3m6s
CI / test-go (pull_request) Successful in 1m3s
CI / iace-gt-coverage (pull_request) Successful in 18s
CI / test-python-backend (pull_request) Successful in 28s
Der einzige offene Retrieval-Haertefall: eine Query mit >=2 genannten Regelwerken
("CRA und Maschinenverordnung") lieferte nur die keyword-dominante Domaene (CRA),
MaschVO fiel raus. Drei zusammenwirkende Ursachen, alle behoben:
1. CodeValues-Mismatch: MaschVO heisst je Collection anders (Slice MASCHVO ·
gesetze MVO · ce MACHINERY/MASCHINENVO), der Catalog hatte nur ["MASCHVO","MaschVO"]
→ Filter fand MaschVO nur in der Slice. Jetzt alle Varianten als CodeValues.
2. Per-Collection-Truncation: der Router gab perColl=3 → searchMultiRegulation holte
3+3=6, schnitt auf 3 → konnte eine Domaene je Collection verlieren. Multi-Reg-Queries
bekommen jetzt perColl = 3*len(regs).
3. Router-Score-Merge starvte die nicht-dominante Domaene. Neue balanceByRegulation()
gruppiert den gemergten Pool per Regelwerk (exakter regulation_code-Match) und nimmt
round-robin ueber die genannten Domaenen → jede Domaene mit Treffern ist im Top-K.
Generisch ueber jede genannte Menge; Single-Domain-Pfad unveraendert.
Validierung: Go-Unit (balanceByRegulation: dominante CRA verdraengt MaschVO NICHT mehr);
0070-e2e gegen dev (Retrieve() → [CRA MVO CRA MVO CRA MVO CRA MASCHINENVO] = beide
Domaenen, vorher nur CRA); CB-100-Stichprobe REGR 0 (Gain-Profil unveraendert).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
100 lines
3.3 KiB
Go
100 lines
3.3 KiB
Go
package ucca
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestRouterBaseCollections(t *testing.T) {
|
|
c := &LegalRAGClient{}
|
|
os.Unsetenv("RAG_ROUTER_COLLECTIONS")
|
|
def := c.routerBaseCollections()
|
|
if len(def) != 6 || def[1] != "bp_compliance_ce" {
|
|
t.Fatalf("default base collections unexpected: %v", def)
|
|
}
|
|
|
|
os.Setenv("RAG_ROUTER_COLLECTIONS", " bp_compliance_ce , kb_2026_1_build ,, ")
|
|
defer os.Unsetenv("RAG_ROUTER_COLLECTIONS")
|
|
got := c.routerBaseCollections()
|
|
if len(got) != 2 || got[0] != "bp_compliance_ce" || got[1] != "kb_2026_1_build" {
|
|
t.Fatalf("env override parse failed (trim/empty): %v", got)
|
|
}
|
|
}
|
|
|
|
func TestRouterSliceSelection(t *testing.T) {
|
|
// The router appends the slice exactly when the query is in scope (inKBScope) and routing is on.
|
|
// Mirror the selection logic so a regression in either is caught without a live Qdrant.
|
|
c := &LegalRAGClient{kbSliceCollection: "kb_2026_1_build", kbScopeRoutingEnabled: true}
|
|
sel := func(q string) bool {
|
|
colls := c.routerBaseCollections()
|
|
if c.kbScopeRoutingEnabled && c.kbSliceCollection != "" && inKBScope(q) {
|
|
colls = append(colls, c.kbSliceCollection)
|
|
}
|
|
for _, x := range colls {
|
|
if x == c.kbSliceCollection {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
if !sel("Welche neun Kriterien nennt WP248 fuer ein hohes Risiko?") {
|
|
t.Error("in-scope guidance query must include the slice")
|
|
}
|
|
if sel("Was sagt NIST SP 800-53 zu Access Control?") {
|
|
t.Error("out-of-scope query must NOT include the slice")
|
|
}
|
|
c.kbScopeRoutingEnabled = false
|
|
if sel("Welche Kriterien nennt WP248?") {
|
|
t.Error("routing disabled => slice never included")
|
|
}
|
|
}
|
|
|
|
func TestBalanceByRegulation(t *testing.T) {
|
|
regs := []detectedRegulation{
|
|
{Canonical: "CRA", CodeValues: []string{"CRA"}},
|
|
{Canonical: "MaschVO", CodeValues: []string{"MASCHVO", "MVO", "MACHINERY"}},
|
|
}
|
|
// CRA dominates by score; without balancing the top-4 would be all CRA + NIST.
|
|
pool := []LegalSearchResult{
|
|
{RegulationCode: "CRA", Score: 0.99},
|
|
{RegulationCode: "CRA", Score: 0.98},
|
|
{RegulationCode: "CRA", Score: 0.97},
|
|
{RegulationCode: "NIST", Score: 0.96},
|
|
{RegulationCode: "MACHINERY", Score: 0.70},
|
|
{RegulationCode: "MVO", Score: 0.65},
|
|
}
|
|
out := balanceByRegulation(pool, regs, 4)
|
|
var hasCRA, hasMasch bool
|
|
for _, r := range out {
|
|
switch r.RegulationCode {
|
|
case "CRA":
|
|
hasCRA = true
|
|
case "MACHINERY", "MVO":
|
|
hasMasch = true
|
|
}
|
|
}
|
|
if !hasCRA || !hasMasch {
|
|
t.Errorf("both named domains must be represented: CRA=%v MaschVO=%v out=%v", hasCRA, hasMasch, out)
|
|
}
|
|
if out[0].RegulationCode != "CRA" || !(out[1].RegulationCode == "MACHINERY" || out[1].RegulationCode == "MVO") {
|
|
t.Errorf("round-robin should alternate domains, got %s then %s", out[0].RegulationCode, out[1].RegulationCode)
|
|
}
|
|
}
|
|
|
|
func TestDedupResults(t *testing.T) {
|
|
in := []LegalSearchResult{
|
|
{RegulationCode: "EDPB WP248", ArticleLabel: "III.B", Text: "lorem", Score: 0.7},
|
|
{RegulationCode: "EDPB WP248", ArticleLabel: "III.B", Text: "lorem", Score: 0.9}, // dup, higher score
|
|
{RegulationCode: "DSGVO", ArticleLabel: "Art. 35", Text: "ipsum", Score: 0.8},
|
|
}
|
|
out := dedupResults(in)
|
|
if len(out) != 2 {
|
|
t.Fatalf("expected 2 deduped, got %d", len(out))
|
|
}
|
|
for _, r := range out {
|
|
if r.RegulationCode == "EDPB WP248" && r.Score != 0.9 {
|
|
t.Errorf("dedup must keep highest score, got %v", r.Score)
|
|
}
|
|
}
|
|
}
|