mirror of
https://github.com/donlucasx/xscapes.git
synced 2026-10-20 08:43:32 +02:00
It failed silently and it cost a whole occurrence of the scrollback defect: he started a session to trace it, the scape came up, the defect reproduced on screen, and nothing was captured, because openTrace returned in silence when the open failed. A debugging tool you point at a file deliberately has to say when it cannot write there. XSCAPES_TRACE=1 now picks the path itself (~/.config/xscapes/traces/<timestamp>.bin) so there is none to get wrong; the parent directory is created; and a failure prints "TRACING IS OFF -- <path>: <err>" and never stops the session. A trace grows about 7 MB a minute -- the scape redraws 12x/s and every byte goes through h.write. 179 MB in 24 minutes, measured. Do not leave one running. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015GQLYhGnSpasru9xeJbJry
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package host
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A trace that was ASKED FOR and is not happening has to say so.
|
|
//
|
|
// On 2026-09-07 he started a session to trace the scrollback defect, the scape
|
|
// came up, the defect reproduced on screen, and nothing was captured: the open
|
|
// had failed and openTrace returned in silence. The cost was a whole
|
|
// occurrence of a defect that has only ever been seen four times.
|
|
func TestAFailedTraceIsNotSilent(t *testing.T) {
|
|
t.Setenv("XSCAPES_TRACE", "/nope/cannot/write.bin")
|
|
r, w, _ := os.Pipe()
|
|
old := os.Stderr
|
|
os.Stderr = w
|
|
h := &Host{}
|
|
h.openTrace()
|
|
w.Close()
|
|
os.Stderr = old
|
|
var b strings.Builder
|
|
buf := make([]byte, 4096)
|
|
for {
|
|
n, err := r.Read(buf)
|
|
b.Write(buf[:n])
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
if h.trace != nil {
|
|
t.Fatal("a trace was opened on an unwritable path")
|
|
}
|
|
if !strings.Contains(b.String(), "TRACING IS OFF") {
|
|
t.Fatalf("nothing said about the failure; stderr was %q", b.String())
|
|
}
|
|
}
|
|
|
|
// A directory that does not exist yet must not quietly turn tracing off.
|
|
func TestATraceMakesItsOwnDirectory(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "a", "b", "trace.bin")
|
|
t.Setenv("XSCAPES_TRACE", path)
|
|
h := &Host{}
|
|
h.openTrace()
|
|
if h.trace == nil {
|
|
t.Fatal("no trace opened")
|
|
}
|
|
h.trace.Close()
|
|
if _, err := os.Stat(path); err != nil {
|
|
t.Fatalf("the trace file is not there: %v", err)
|
|
}
|
|
}
|
|
|
|
// XSCAPES_TRACE=1 picks the path, so there is none to get wrong.
|
|
func TestTheShorthandPicksItsOwnPath(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("XSCAPES_TRACE", "1")
|
|
h := &Host{}
|
|
h.openTrace()
|
|
if h.trace == nil {
|
|
t.Fatal("XSCAPES_TRACE=1 opened nothing")
|
|
}
|
|
h.trace.Close()
|
|
dir := filepath.Join(home, ".config", "xscapes", "traces")
|
|
ents, err := os.ReadDir(dir)
|
|
if err != nil || len(ents) == 0 {
|
|
t.Fatalf("nothing written under %s (err %v)", dir, err)
|
|
}
|
|
if !strings.HasSuffix(ents[0].Name(), ".bin") {
|
|
t.Errorf("wrote %q, want a .bin", ents[0].Name())
|
|
}
|
|
}
|