69 lines
2.4 KiB
Go
69 lines
2.4 KiB
Go
package windsurf
|
|
|
|
import "testing"
|
|
|
|
func TestFingerprintBefore_BackwardCompatibleForTextOnly(t *testing.T) {
|
|
msgs := []ChatMessage{
|
|
{Role: "user", Content: "hello"},
|
|
{Role: "assistant", Content: "hi"},
|
|
{Role: "user", Content: "again"},
|
|
}
|
|
// 无图场景 hash 必须与 ImageDigests=nil 时一致(向后兼容)
|
|
fp := FingerprintBefore(msgs, "claude-opus-4-7", "key-A")
|
|
if fp == "" {
|
|
t.Fatal("unexpected empty fingerprint")
|
|
}
|
|
}
|
|
|
|
func TestFingerprintBefore_DifferentImagesDiffer(t *testing.T) {
|
|
base := []ChatMessage{
|
|
{Role: "user", Content: "describe", ImageDigests: []ImageDigest{{MimeType: "image/png", SHA256: "aaa", ByteLen: 100}}},
|
|
{Role: "assistant", Content: "ok"},
|
|
{Role: "user", Content: "next"},
|
|
}
|
|
diffImg := []ChatMessage{
|
|
{Role: "user", Content: "describe", ImageDigests: []ImageDigest{{MimeType: "image/png", SHA256: "bbb", ByteLen: 100}}},
|
|
{Role: "assistant", Content: "ok"},
|
|
{Role: "user", Content: "next"},
|
|
}
|
|
fp1 := FingerprintBefore(base, "claude-opus-4-7", "key-A")
|
|
fp2 := FingerprintBefore(diffImg, "claude-opus-4-7", "key-A")
|
|
if fp1 == fp2 {
|
|
t.Errorf("expected different fingerprints when image sha256 differs")
|
|
}
|
|
}
|
|
|
|
func TestFingerprintBefore_SameImageDifferentCaptionDiffers(t *testing.T) {
|
|
a := []ChatMessage{
|
|
{Role: "user", Content: "x", ImageDigests: []ImageDigest{{MimeType: "image/png", SHA256: "z", ByteLen: 10, Caption: "cat"}}},
|
|
{Role: "assistant", Content: "ok"},
|
|
{Role: "user", Content: "y"},
|
|
}
|
|
b := []ChatMessage{
|
|
{Role: "user", Content: "x", ImageDigests: []ImageDigest{{MimeType: "image/png", SHA256: "z", ByteLen: 10, Caption: "dog"}}},
|
|
{Role: "assistant", Content: "ok"},
|
|
{Role: "user", Content: "y"},
|
|
}
|
|
fp1 := FingerprintBefore(a, "claude-opus-4-7", "key-A")
|
|
fp2 := FingerprintBefore(b, "claude-opus-4-7", "key-A")
|
|
if fp1 == fp2 {
|
|
t.Errorf("expected different fingerprints when caption differs")
|
|
}
|
|
}
|
|
|
|
func TestFingerprintBefore_NoImagesSameAsAbsent(t *testing.T) {
|
|
a := []ChatMessage{
|
|
{Role: "user", Content: "hello"},
|
|
{Role: "assistant", Content: "hi"},
|
|
{Role: "user", Content: "again"},
|
|
}
|
|
b := []ChatMessage{
|
|
{Role: "user", Content: "hello", Images: nil, ImageDigests: nil},
|
|
{Role: "assistant", Content: "hi"},
|
|
{Role: "user", Content: "again"},
|
|
}
|
|
if FingerprintBefore(a, "m", "k") != FingerprintBefore(b, "m", "k") {
|
|
t.Errorf("no-image variants should hash identically (backward compat)")
|
|
}
|
|
}
|