feat(matching): rank with semantic embeddings and explain matches by evidence

This commit is contained in:
shira committed 2026-10-11 10:39:46 +03:00
1 parent facc1789b1
commit 24b64d698a
215 files changed
+16951 -327

No files matched your search

@@ -13,9 +13,10 @@ import (
)
type extenderFake struct {
result policy.MatchingResult
err error
author domain.PolicyAuthor
result policy.MatchingResult
err error
author domain.PolicyAuthor
semantic bool
}
func (extender *extenderFake) EnsureDemoMatchingSection(_ context.Context, author domain.PolicyAuthor) (policy.MatchingResult, error) {
@@ -23,11 +24,21 @@ func (extender *extenderFake) EnsureDemoMatchingSection(_ context.Context, autho
return extender.result, extender.err
}
func (extender *extenderFake) EnsureDemoSemanticMatchingSection(_ context.Context, author domain.PolicyAuthor) (policy.MatchingResult, error) {
extender.author = author
extender.semantic = true
return extender.result, extender.err
}
func TestParseRequiresTheMatchingTrackAndAnOperatorHandle(t *testing.T) {
command, err := Parse([]string{"matching", "--actor", "operator:night"})
if err != nil || command.Author != "operator:night" {
if err != nil || command.Author != "operator:night" || command.Track != TrackMatching {
t.Fatalf("Parse(valid) = %+v, %v", command, err)
}
semantic, err := Parse([]string{"semantic", "--actor", "operator:night"})
if err != nil || semantic.Track != TrackSemantic {
t.Fatalf("Parse(semantic) = %+v, %v", semantic, err)
}
for _, args := range [][]string{
nil, {"list"}, {"matching"}, {"matching", "--actor", "alice"}, {"matching", "--actor", "system:demo-seed"},
{"matching", "--actor", "operator:night", "extra"},
@@ -62,3 +73,14 @@ func TestExecutePrintsOnlyTheVersionAndMapsFailuresToSafeMessages(t *testing.T)
}
}
}
func TestExecuteSemanticTrackPublishesTheSemanticSection(t *testing.T) {
var output bytes.Buffer
extender := &extenderFake{}
if err := Execute(context.Background(), Command{Track: TrackSemantic, Author: "operator:night"}, extender, &output); err != nil {
t.Fatalf("Execute() error = %v", err)
}
if !extender.semantic || !strings.Contains(output.String(), "the semantic matching section") {
t.Fatalf("output = %q, semantic called %v", output.String(), extender.semantic)
}
}