feat(matching): rank with semantic embeddings and explain matches by evidence
This commit is contained in:
1 parent
facc1789b1
commit
24b64d698a
215 files changed
+16951
-327
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package semanticbackfill
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/usecase/semantic"
|
||||
)
|
||||
|
||||
type runnerFake struct {
|
||||
scopes []semantic.BackfillScope
|
||||
err error
|
||||
}
|
||||
|
||||
func (runner *runnerFake) Run(_ context.Context, scope semantic.BackfillScope, _ string, after uuid.UUID, report func(semantic.BackfillProgress) error) error {
|
||||
runner.scopes = append(runner.scopes, scope)
|
||||
if runner.err != nil {
|
||||
return runner.err
|
||||
}
|
||||
return report(semantic.BackfillProgress{Scope: scope, Scheduled: 2, After: after, Done: true})
|
||||
}
|
||||
|
||||
func TestParseRequiresAScopeAndARunLabel(t *testing.T) {
|
||||
command, err := Parse([]string{"all", "--run", "2026-10-11"})
|
||||
if err != nil || len(command.Scopes) != 2 || command.Run != "2026-10-11" {
|
||||
t.Fatalf("Parse(all) = %+v, %v", command, err)
|
||||
}
|
||||
after := uuid.New()
|
||||
command, err = Parse([]string{"needs", "--run", "r1", "--after", after.String()})
|
||||
if err != nil || command.After != after {
|
||||
t.Fatalf("Parse(needs --after) = %+v, %v", command, err)
|
||||
}
|
||||
for _, args := range [][]string{
|
||||
nil, {"vectors"}, {"candidates"}, {"all", "--run", "r1", "--after", after.String()},
|
||||
{"needs", "--run", "r1", "--after", "x"}, {"needs", "--run", "r1", "extra"},
|
||||
} {
|
||||
if _, err := Parse(args); err == nil {
|
||||
t.Errorf("Parse(%v) accepted invalid arguments", args)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteReportsEveryScopeAndHidesStorageErrors(t *testing.T) {
|
||||
var output bytes.Buffer
|
||||
runner := &runnerFake{}
|
||||
command := Command{Scopes: []semantic.BackfillScope{semantic.BackfillCandidates, semantic.BackfillNeeds}, Run: "r1"}
|
||||
if err := Execute(context.Background(), command, runner, &output); err != nil {
|
||||
t.Fatalf("Execute() error = %v", err)
|
||||
}
|
||||
if len(runner.scopes) != 2 || !strings.Contains(output.String(), "needs: done, 2 jobs scheduled") {
|
||||
t.Fatalf("output = %q", output.String())
|
||||
}
|
||||
failing := &runnerFake{err: errors.New("pq: password authentication failed for user x")}
|
||||
err := Execute(context.Background(), command, failing, &bytes.Buffer{})
|
||||
if err == nil || strings.Contains(err.Error(), "password") {
|
||||
t.Fatalf("Execute(failing) error = %v, want a safe message", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user