| 1 | package sessioninbox |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/store" |
| 8 | ) |
| 9 | |
| 10 | func TestOpenAtSeparatesLocatorFromStorageWithoutChangingFormat(t *testing.T) { |
| 11 | storagePath := filepath.Join(t.TempDir(), "runtime-inbox.jsonl") |
| 12 | dir := store.SessionInboxDir(storagePath) |
| 13 | const locator = "session-id:canonical.with.dots" |
| 14 | s, err := OpenAt(locator, dir, Limits{}) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | t.Cleanup(s.Close) |
| 19 | receipt, err := s.Enqueue(EnqueueRequest{Intent: IntentFollowup, Idempotency: "request", Envelope: PromptEnvelope{SubmitText: "queued"}}) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | if s.SessionPath() != locator || s.Snapshot().SessionPath != locator || s.Dir() != dir { |
| 24 | t.Fatal("logical locator was replaced by its storage path") |
| 25 | } |
| 26 | if meta, _, err := s.ReadItem(receipt.ItemID); err != nil || meta.SessionID != "canonical.with.dots" { |
| 27 | t.Fatalf("default metadata lost the canonical session identity: %+v %v", meta, err) |
| 28 | } |
| 29 | s.Close() |
| 30 | // An old path-based reader can still read the same manifest and blobs. |
| 31 | legacy, err := Open(storagePath, Limits{}) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | defer legacy.Close() |
| 36 | if got, found := legacy.LookupReceipt("request"); !found || got.ItemID != receipt.ItemID { |
| 37 | t.Fatalf("legacy reader lost receipt: %+v %v", got, found) |
| 38 | } |
| 39 | if _, env, err := legacy.ReadItem(receipt.ItemID); err != nil || env.SubmitText != "queued" { |
| 40 | t.Fatalf("legacy reader lost body: %+v %v", env, err) |
| 41 | } |
| 42 | } |
| 43 |