| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strconv" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/provider" |
| 10 | ) |
| 11 | |
| 12 | func TestLegacyMigrationKeepsUnknownOriginForFallback(t *testing.T) { |
| 13 | path := filepath.Join(t.TempDir(), "legacy.jsonl") |
| 14 | content := CompletionValidationContinuationPrefix + " the last message did not deliver a self-contained final result." |
| 15 | if err := os.WriteFile(path, []byte(`{"type":"user.message","text":`+strconv.Quote(content)+`}`+"\n"), 0o600); err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | msgs, err := reconstructSession(path) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if len(msgs) != 1 || msgs[0].Origin != "" || !IsHostGeneratedUserMessage(msgs[0]) { |
| 23 | t.Fatalf("migrated legacy message = %+v, want unknown origin classified by fallback", msgs) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func TestLegacyCoalescedSummaryKeepsUnknownTailOrigin(t *testing.T) { |
| 28 | combined := formatSummaryMessage("prior context") |
| 29 | combined.Content += "\n\n" + CompletionValidationContinuationPrefix + " the last message did not deliver a self-contained final result." |
| 30 | _, tail, ok := splitLegacyCoalescedSummary(combined) |
| 31 | if !ok || tail.Role != provider.RoleUser || tail.Origin != "" || !IsHostGeneratedUserMessage(tail) { |
| 32 | t.Fatalf("split legacy tail = %+v, ok=%v, want unknown origin with fallback", tail, ok) |
| 33 | } |
| 34 | } |
| 35 |