fix: Interactive pty identification for proxy mode (#174)

This commit is contained in:
Abhisek Datta
2026-03-04 06:56:06 +00:00
committed by GitHub
parent 601ba315c2
commit 0c09988776
3 changed files with 66 additions and 11 deletions
+10 -2
View File
@@ -36,13 +36,21 @@ type InteractiveSession interface {
// IsInteractiveTerminal returns true if stdin is a real terminal (TTY).
// Returns false in CI environments (when the "CI" env var set to "true"),
// when input is piped, or in non-interactive shells.
// when input or output is piped, or in non-interactive shells.
func IsInteractiveTerminal() bool {
if ci := os.Getenv("CI"); ci != "" && strings.ToLower(ci) == "true" {
return false
}
return term.IsTerminal(int(os.Stdin.Fd()))
if !term.IsTerminal(int(os.Stdout.Fd())) {
return false
}
if !term.IsTerminal(int(os.Stdin.Fd())) {
return false
}
return true
}
var _ InteractiveSession = &session{}
+49
View File
@@ -0,0 +1,49 @@
package pty
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsInteractiveTerminal(t *testing.T) {
tests := []struct {
name string
ciEnv string
expected bool
}{
{
name: "returns false when CI env is set to true",
ciEnv: "true",
expected: false,
},
{
name: "returns false when CI env is set to TRUE (case insensitive)",
ciEnv: "TRUE",
expected: false,
},
{
name: "returns false when CI env is set to True (mixed case)",
ciEnv: "True",
expected: false,
},
{
name: "returns false in test runner (stdin/stdout are pipes)",
ciEnv: "",
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.ciEnv != "" {
t.Setenv("CI", tt.ciEnv)
} else {
t.Setenv("CI", "")
}
result := IsInteractiveTerminal()
assert.Equal(t, tt.expected, result)
})
}
}