Files
xscapes/internal/event/current_since_test.go
donlucasandClaude Fable 5.1 b405adc580 A resumed session binds: the launchers take the first session pointer written after launch, whatever id it carries
Both launchers waited for a pointer that differed from the one they found
at launch, and a resumed session (--resume, --continue) writes the same
id again, so it was never bound: a restart by id showed the output
watcher instead of the hooks, and the next SessionStart from another
window could bind the scape to that window's session (F1, session 38; a
scape in this very window held a dead session's socket for an evening).
event.CurrentSince answers by the pointer's write time, not its text.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-18 13:23:21 -07:00

33 lines
1.1 KiB
Go

package event
import (
"testing"
"time"
)
// A launcher must bind to the session that starts AFTER it, and a resumed
// session writes the same id the pointer already held: waiting for a
// different id never bound it (F1, session 38). CurrentSince answers by the
// pointer's write time, not its text.
func TestAResumedSessionIsCurrentSinceTheLaunch(t *testing.T) {
t.Setenv("XSCAPES_HOME", t.TempDir())
if err := SetCurrent("abc-123"); err != nil {
t.Fatal(err)
}
time.Sleep(20 * time.Millisecond)
launched := time.Now()
if got := CurrentSince(launched); got != "" {
t.Fatalf("the pointer written before the launch counts as current: %q", got)
}
time.Sleep(20 * time.Millisecond)
if err := SetCurrent("abc-123"); err != nil { // the same id again: a resume
t.Fatal(err)
}
if got := CurrentSince(launched); got != "abc-123" {
t.Fatalf("the pointer written after the launch, same id, is not current: %q", got)
}
if got := CurrentSince(time.Now().Add(time.Hour)); got != "" {
t.Fatalf("a pointer older than the moment asked about counts as current: %q", got)
}
}