package router

import (
	"strings"
	"testing"
)

func TestEmbedderIDFromModelPath(t *testing.T) {
	got := modelIDFromPath("/opt/maven/models/embedder/multilingual-e5-small.onnx")
	if got != "multilingual-e5-small@384/tok2" {
		t.Fatalf("modelIDFromPath = %q", got)
	}
	// A different model file must produce a different id, even at 384 dim.
	old := modelIDFromPath("/opt/maven/models/embedder/paraphrase-multilingual-MiniLM-L12-v2.onnx")
	if old == got {
		t.Fatal("two different models share one id")
	}
	// The tokenizer is half of what makes a vector, and it changes under a
	// model file whose name never moves (V-664). An id that ignored it would
	// leave stored passages in one space and every new query in another, with
	// nothing to trigger the re-embed.
	if !strings.Contains(got, "/tok") {
		t.Fatalf("id %q does not name the tokenizer revision", got)
	}
}

func TestEmbedderIDIncludesDim(t *testing.T) {
	if id := EmbedderID(NewHashEmbedder(1024)); id != "hash@1024" {
		t.Fatalf("EmbedderID = %q", id)
	}
	if EmbedderID(NewHashEmbedder(1024)) == EmbedderID(NewHashEmbedder(384)) {
		t.Fatal("dimension not part of the id")
	}
}
