-
Notifications
You must be signed in to change notification settings - Fork 431
Guard startup terminal probing on Windows when stderr is redirected #37823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
764cde5
0f71a7e
fbed8bc
103f7be
0406514
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,63 @@ func TestConfigureLipglossCompatUsesStderr(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestShouldConfigureLipglossCompat(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| goos string | ||
| stderrMode os.FileMode | ||
| statErr error | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "windows character device", | ||
| goos: "windows", | ||
| stderrMode: os.ModeDevice | os.ModeCharDevice, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "windows redirected pipe", | ||
| goos: "windows", | ||
| stderrMode: os.ModeNamedPipe, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "windows zero mode stat success", | ||
| goos: "windows", | ||
| stderrMode: os.FileMode(0), | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "windows stat error", | ||
| goos: "windows", | ||
| statErr: os.ErrPermission, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "windows ErrInvalid fallback", | ||
| goos: "windows", | ||
| statErr: os.ErrInvalid, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "non-windows still configures", | ||
| goos: "linux", | ||
| stderrMode: os.ModeNamedPipe, | ||
| statErr: os.ErrPermission, | ||
| want: true, | ||
| }, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/tdd] Consider adding a "windows stat succeeds, zero mode" case: 💡 Suggested test case{
name: "windows zero mode stat success",
goos: "windows",
stderrMode: os.FileMode(0),
want: false,
},Since
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test case for 💡 Suggested additionThe {
name: "windows unknown mode (zero) no error",
goos: "windows",
stderrMode: os.FileMode(0),
statErr: nil,
want: false,
},Without this, a refactor that treats zero-mode as "assume TTY" would go undetected. |
||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := shouldConfigureLipglossCompat(tt.goos, tt.stderrMode, tt.statErr) | ||
| if got != tt.want { | ||
| t.Fatalf("shouldConfigureLipglossCompat(%q, %v, %v) = %v, want %v", tt.goos, tt.stderrMode, tt.statErr, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestBordersExist verifies that all expected border definitions are defined | ||
| func TestBordersExist(t *testing.T) { | ||
| borders := map[string]lipgloss.Border{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/diagnose] The nil-nil →
os.ErrInvalidconversion here cannot be exercised from theshouldConfigureLipglossCompattest table — the pure function always receives already-converted values. The existing"windows stat error"case usesos.ErrPermission, which is equivalent at runtime, but the traceability from thisinit()fallback to its test coverage is invisible.💡 Options to close the gap
Option A — add an
os.ErrInvalidcase to the test table with a comment linking it to this path:{ name: "windows ErrInvalid (init nil-nil fallback)", goos: "windows", statErr: os.ErrInvalid, want: false, },Option B — hoist the nil-nil guard into
shouldConfigureLipglossCompatby passingstderrInfodirectly (or a(mode, modeValid bool)pair), making the entire decision testable through the pure function.Option A is a lower-effort win; Option B is structurally cleaner.