| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "runtime" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | |
| 11 | "reasonix/internal/session" |
| 12 | ) |
| 13 | |
| 14 | func TestFailedSessionRebindReleasesPreviousWriter(t *testing.T) { |
| 15 | root := t.TempDir() |
| 16 | oldPath := filepath.Join(root, "old.jsonl") |
| 17 | c := newOwnedTestController(t, Options{SessionPath: oldPath}) |
| 18 | if c.sessionEventStore() == nil { |
| 19 | t.Fatal("initial writer not opened") |
| 20 | } |
| 21 | blocked := filepath.Join(root, "blocked") |
| 22 | if err := os.WriteFile(blocked, []byte("not a directory"), 0600); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | c.rebindTurnEvents(filepath.Join(blocked, "new.jsonl")) |
| 26 | if c.sessionEventStore() != nil { |
| 27 | t.Fatal("failed rebind retained an execution store") |
| 28 | } |
| 29 | reopened, err := session.Open(sessionDirectory(oldPath), "old") |
| 30 | if err != nil { |
| 31 | t.Fatalf("failed rebind leaked old writer: %v", err) |
| 32 | } |
| 33 | if err := reopened.Close(context.Background()); err != nil { |
| 34 | t.Fatal(err) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | func TestWindowsSessionDirectoryIgnoresPathCase(t *testing.T) { |
| 39 | if runtime.GOOS != "windows" { |
| 40 | t.Skip("Windows path identity") |
| 41 | } |
| 42 | path := filepath.Join(t.TempDir(), "active.jsonl") |
| 43 | if sessionDirectory(path) != sessionDirectory(strings.ToLower(path)) { |
| 44 | t.Fatal("case variants select different shared writer identities") |
| 45 | } |
| 46 | } |
| 47 |