| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "reasonix/internal/provider" |
| 7 | ) |
| 8 | |
| 9 | func TestLineageKeyCompatibleNativeSuffix(t *testing.T) { |
| 10 | current := "ws|sess|model" |
| 11 | stored := current + "|context-editing-native-anthropic" |
| 12 | got, ok := lineageKeyCompatible(stored, current) |
| 13 | if !ok || got != current { |
| 14 | t.Fatalf("lineageKeyCompatible(%q,%q)=(%q,%v), want (%q,true)", stored, current, got, ok, current) |
| 15 | } |
| 16 | if _, ok := lineageKeyCompatible("other|sess|model", current); ok { |
| 17 | t.Fatal("foreign lineage must not match") |
| 18 | } |
| 19 | if got, ok := lineageKeyCompatible(current, current); !ok || got != current { |
| 20 | t.Fatalf("exact key: got (%q,%v)", got, ok) |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | func TestProjectionValidAcceptsLegacyNativeKey(t *testing.T) { |
| 25 | msgs := []provider.Message{ |
| 26 | {Role: provider.RoleSystem, Content: "sys"}, |
| 27 | {Role: provider.RoleUser, Content: "u"}, |
| 28 | } |
| 29 | hash := coveredPrefixHash(msgs, len(msgs)) |
| 30 | st := CompactionState{ |
| 31 | PromptCacheKey: "ws|s|m|context-editing-native-x", |
| 32 | Projection: ContextProjection{ |
| 33 | Messages: msgs, |
| 34 | CoveredCount: len(msgs), |
| 35 | CoveredPrefixHash: hash, |
| 36 | ProjectionVersion: 1, |
| 37 | }, |
| 38 | TranscriptVersion: 1, |
| 39 | } |
| 40 | if !projectionValid(st, msgs, "ws|s|m") { |
| 41 | t.Fatal("projectionValid rejected legacy native lineage key") |
| 42 | } |
| 43 | } |
| 44 |