mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
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>
33 lines
1.1 KiB
Go
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)
|
|
}
|
|
}
|