test(shellcmd): pin exact stderr truncation length
TestRunnerBoundsStderr used LessOrEqual, which also passes when StderrLimit silently stops being propagated and stderr is never captured. Pin the assertion to exactly 64 bytes so the test can actually fail for the bug it exists to catch. Also clarify the CommandResult.ExitCode doc comment: -1 covers both "could not be started" and "terminated by a signal" (the timeout path SIGKILLs the process group, which also yields -1 from *exec.ExitError even though the process did run).
- commit
- 3b5f32b8590aaae2fab053305e536458f71cef7d
- author
- brice · · 2026-07-20 08:05 UTC
- parent
- 456b0b1
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +3 -2
M internal/adapters/shellcmd/runner_test.go +1 -1
| @@ -166,5 +166,5 @@ func TestRunnerBoundsStderr(t *testing.T) { | |||
| 166 | 166 | StdoutLimit: 1024, | |
| 167 | 167 | StderrLimit: 64, | |
| 168 | 168 | }) | |
| 169 | - | require.LessOrEqual(t, len(res.Stderr), 64) | |
| 169 | + | require.Equal(t, 64, len(res.Stderr), "stderr must be captured and truncated to StderrLimit") | |
| 170 | 170 | } | |
| @@ -166,5 +166,5 @@ func TestRunnerBoundsStderr(t *testing.T) { | |||||
| 166 | StdoutLimit: 1024, | 166 | StdoutLimit: 1024, | ||
| 167 | StderrLimit: 64, | 167 | StderrLimit: 64, | ||
| 168 | }) | 168 | }) | ||
| 169 | - | require.LessOrEqual(t, len(res.Stderr), 64) | 169 | + | require.Equal(t, 64, len(res.Stderr), "stderr must be captured and truncated to StderrLimit") |
| 170 | } | 170 | } | ||
M internal/ports/shell.go +2 -1
| @@ -16,7 +16,8 @@ type CommandSpec struct { | |||
| 16 | 16 | ||
| 17 | 17 | // CommandResult carries bounded output and the process exit status. ExitCode is | |
| 18 | 18 | // 0 when the command ran to completion successfully, the process exit code when | |
| 19 | - | // it ran and failed, and -1 when the command could not be run at all. | |
| 19 | + | // it ran and failed, and -1 when the command could not be started or was | |
| 20 | + | // terminated by a signal. | |
| 20 | 21 | type CommandResult struct { | |
| 21 | 22 | Stdout []byte | |
| 22 | 23 | Stderr []byte | |
| @@ -16,7 +16,8 @@ type CommandSpec struct { | |||||
| 16 | 16 | ||||
| 17 | // CommandResult carries bounded output and the process exit status. ExitCode is | 17 | // CommandResult carries bounded output and the process exit status. ExitCode is | ||
| 18 | // 0 when the command ran to completion successfully, the process exit code when | 18 | // 0 when the command ran to completion successfully, the process exit code when | ||
| 19 | - | // it ran and failed, and -1 when the command could not be run at all. | 19 | + | // it ran and failed, and -1 when the command could not be started or was |
| 20 | + | // terminated by a signal. | |||
| 20 | type CommandResult struct { | 21 | type CommandResult struct { | ||
| 21 | Stdout []byte | 22 | Stdout []byte | ||
| 22 | Stderr []byte | 23 | Stderr []byte | ||