| 1 | package serve |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "net/http" |
| 6 | "path/filepath" |
| 7 | "sync/atomic" |
| 8 | "testing" |
| 9 | |
| 10 | "reasonix/internal/agent" |
| 11 | ) |
| 12 | |
| 13 | func TestSessionsReportsForeignWriterAsTakenOver(t *testing.T) { |
| 14 | f := newOwnershipFixture(t) |
| 15 | other := filepath.Join(f.dir, "other.jsonl") |
| 16 | saveServeTestSession(t, other) |
| 17 | |
| 18 | var held atomic.Bool |
| 19 | held.Store(true) |
| 20 | withForeignWriterLease(t, other, &held) |
| 21 | |
| 22 | status, body := f.get(t, "/sessions") |
| 23 | if status != http.StatusOK { |
| 24 | t.Fatalf("sessions status = %d (body %q)", status, body) |
| 25 | } |
| 26 | var rows []sessionListEntry |
| 27 | if err := json.Unmarshal([]byte(body), &rows); err != nil { |
| 28 | t.Fatalf("decode sessions: %v (body %q)", err, body) |
| 29 | } |
| 30 | for _, row := range rows { |
| 31 | if agent.CanonicalSessionPath(row.Path) == agent.CanonicalSessionPath(other) { |
| 32 | if !row.TakenOver { |
| 33 | t.Fatalf("foreign-held session row = %+v, want takenOver", row) |
| 34 | } |
| 35 | return |
| 36 | } |
| 37 | } |
| 38 | t.Fatalf("foreign-held session %q missing from %+v", other, rows) |
| 39 | } |
| 40 |