okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
85b721f
main
1package tui 2 3// These tests catch cancellation blocked by a descendant's inherited stdout. 4// The daemon E2E suite cannot drive the TUI's local clipboard subprocesses. 5 6import ( 7"context" 8"errors" 9"os" 10"os/exec" 11"strconv" 12"strings" 13"testing" 14"time" 15) 16 17func TestClipboardCancellationClosesDescendantStdout (t * testing.T ) { 18shell ,err := exec .LookPath ("sh" ) 19if err != nil { 20t .Skip ("requires sh" ) 21 } 22for _ ,parent := range []string {"wait" ,"exit 0" } { 23t .Run (parent ,func (t * testing.T ) { 24ctx ,cancel := context .WithTimeout (context .Background (),50 * time .Millisecond ) 25defer cancel () 26 27start := time .Now () 28out ,err := execClipboardCommand (ctx ,shell ,"-c" ,`sleep 2 & printf '%s\n' "$!"; ` + parent ) 29elapsed := time .Since (start ) 30// Kill the fixture's descendant promptly even when an assertion fails. 31pid ,parseErr := strconv .Atoi (strings .TrimSpace (string (out ))) 32if parseErr != nil { 33t .Fatalf ("descendant did not report its PID: %q: %v" ,out ,parseErr ) 34 } 35process ,findErr := os .FindProcess (pid ) 36if findErr != nil { 37t .Fatal (findErr ) 38 } 39_ = process .Kill () 40 41if ! errors .Is (err ,context .DeadlineExceeded ) { 42t .Fatalf ("expected deadline error, got %v" ,err ) 43 } 44if elapsed >= time .Second { 45t .Fatalf ("cancellation took %s with a 50 ms deadline" ,elapsed ) 46 } 47 }) 48 } 49}