Skip to content

Commit 2811c1f

Browse files
senamakelmedullabot
andcommitted
test(host): pin the embedding signature to its persisted form
The host held a byte-identical copy of this file and the two diverged once already; the guard that would have caught it lived only in the copy, which is now deleted. Golden strings, so it outlives any second implementation. Co-authored-by: Medulla <medulla@tinyhumans.ai>
1 parent ad3fa94 commit 2811c1f

2 files changed

Lines changed: 104 additions & 8 deletions

File tree

api/src/host/embeddings.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,49 @@ pub fn format_embedding_signature(name: &str, model_id: &str, dims: usize) -> St
2525
format!("provider={name};model={model_id};dims={dims}")
2626
}
2727

28+
#[cfg(test)]
29+
mod embedding_signature_tests {
30+
use super::format_embedding_signature;
31+
32+
/// The signature format is a **persisted key**, pinned to literal values.
33+
///
34+
/// Written against golden strings rather than against another copy of the
35+
/// function on purpose: the host used to hold a byte-identical duplicate of
36+
/// this file and the two silently diverged once already. A guard that
37+
/// compares two implementations stops protecting anything the moment one of
38+
/// them goes away — which is exactly what happened when the duplicate was
39+
/// removed. Literals outlive that.
40+
///
41+
/// Every vector on disk is keyed by one of these strings, so a change here
42+
/// is a migration, never an edit.
43+
#[test]
44+
fn signature_format_is_pinned_to_its_persisted_form() {
45+
assert_eq!(
46+
format_embedding_signature("ollama", "nomic-embed-text", 768),
47+
"provider=ollama;model=nomic-embed-text;dims=768"
48+
);
49+
assert_eq!(
50+
format_embedding_signature("none", "none", 0),
51+
"provider=none;model=none;dims=0"
52+
);
53+
}
54+
55+
/// A known defect, recorded rather than hidden: the delimiters are not
56+
/// escaped, so a provider or model name containing `;model=` can produce
57+
/// the same signature as a different (name, model) pair — two distinct
58+
/// embedding spaces sharing one key.
59+
///
60+
/// Left `#[ignore]`d because fixing it changes the persisted format, which
61+
/// is a migration. No provider name in use today contains the delimiters.
62+
#[test]
63+
#[ignore = "known defect: fixing the escaping changes a persisted key, so it needs a migration"]
64+
fn delimiter_characters_cannot_make_distinct_spaces_collide() {
65+
let first = format_embedding_signature("a;model=b", "c", 3);
66+
let second = format_embedding_signature("a", "b;model=c", 3);
67+
assert_ne!(first, second);
68+
}
69+
}
70+
2871
/// Converts text into numerical vectors.
2972
#[async_trait]
3073
pub trait EmbeddingProvider: Send + Sync {

crates/tinymemory-module/Cargo.lock

Lines changed: 61 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)