fix: close workspace preprocessing contract gaps

This commit is contained in:
2026-08-11 01:18:29 +02:00
parent 05a6e8cc2d
commit de27275bb1
15 changed files with 516 additions and 87 deletions
@@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
@@ -123,6 +124,35 @@ func TestRunnerBoundedCancellationWinsOverChildKill(t *testing.T) {
}
}
func TestRunnerBoundedKillsGrandchildProcess(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("shell process-group fixture is Unix-specific")
}
pidFile := filepath.Join(t.TempDir(), "grandchild.pid")
script := "#!/bin/sh\n(sleep 30) &\nprintf '%s' $! > '" + pidFile + "'\nwhile :; do printf x; done\n"
runner := NewRunner(writeExecutable(t, script))
_, err := runner.RunBounded(context.Background(), nil, nil, CaptureLimits{StdoutBytes: 64, StderrBytes: 64})
if !errors.Is(err, ErrOutputLimit) {
t.Fatalf("err = %v", err)
}
pidBytes, readErr := os.ReadFile(pidFile)
if readErr != nil {
t.Fatal(readErr)
}
pid, err := strconv.Atoi(strings.TrimSpace(string(pidBytes)))
if err != nil {
t.Fatal(err)
}
deadline := time.Now().Add(2 * time.Second)
for time.Now().Before(deadline) {
if !processExists(pid) {
return
}
time.Sleep(20 * time.Millisecond)
}
t.Fatalf("grandchild pid %d remained alive after owned-process termination", pid)
}
func TestRunnerBoundedTerminatesGrandchildHoldingPipe(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("shell process-group fixture is Unix-specific")