Skip to content

Commit 5e1c467

Browse files
committed
test: Update interactive fuzzy-finder tests to check for TTY availability in CI
1 parent f578646 commit 5e1c467

5 files changed

Lines changed: 37 additions & 23 deletions

File tree

internal/appflow/anime_data_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/alvarorichard/Goanime/internal/models"
88
"github.com/stretchr/testify/assert"
9+
"golang.org/x/term"
910
)
1011

1112
// TestGetAnimeEpisodes_EmptyResult verifies that GetAnimeEpisodes returns an
@@ -41,8 +42,8 @@ func TestSearchAnime_InvalidName(t *testing.T) {
4142
// SearchAnime may open an interactive fuzzy finder (tcell-based TUI) if
4243
// results are returned. On CI there is no TTY, so tcell panics (Windows)
4344
// or hangs waiting for terminal input.
44-
if os.Getenv("CI") != "" {
45-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
45+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
46+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
4647
}
4748

4849
anime, err := SearchAnime("zzzzz_nonexistent_anime_99999")
@@ -61,8 +62,8 @@ func TestSearchAnimeEnhanced_InvalidName(t *testing.T) {
6162
// SearchAnimeEnhanced may open an interactive fuzzy finder (tcell-based TUI)
6263
// if results are returned. On CI there is no TTY, so tcell panics (Windows)
6364
// or hangs waiting for terminal input.
64-
if os.Getenv("CI") != "" {
65-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
65+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
66+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
6667
}
6768

6869
anime, err := SearchAnimeEnhanced("zzzzz_nonexistent_anime_99999")

internal/playback/common_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/alvarorichard/Goanime/internal/models"
88
"github.com/stretchr/testify/assert"
9+
"golang.org/x/term"
910
)
1011

1112
// TestSelectEpisodeWithFuzzy_EmptyList verifies that passing an empty episode
@@ -23,8 +24,8 @@ func TestFindEpisodeByNumber_NotFound(t *testing.T) {
2324
// This test falls back to SelectEpisodeWithFuzzy which opens an interactive
2425
// fuzzy finder (tcell-based TUI). On CI there is no TTY, so the fuzzy finder
2526
// either panics (Windows) or hangs indefinitely waiting for terminal input.
26-
if os.Getenv("CI") != "" {
27-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
27+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
28+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
2829
}
2930

3031
episodes := []models.Episode{

internal/player/download_pure_test.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/alvarorichard/Goanime/internal/util"
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
16+
"golang.org/x/term"
1617
)
1718

1819
func TestIsAnimeFireVideoAPIURL(t *testing.T) {
@@ -79,24 +80,24 @@ func TestSafePartPath(t *testing.T) {
7980

8081
t.Run("valid", func(t *testing.T) {
8182
t.Parallel()
82-
got, err := safePartPath("/tmp/video.mp4", 1)
83+
got, err := safePartPath(filepath.FromSlash("/tmp/video.mp4"), 1)
8384
require.NoError(t, err)
84-
assert.Equal(t, "/tmp/video.mp4.part1", got)
85+
assert.Equal(t, filepath.FromSlash("/tmp/video.mp4.part1"), got)
8586
})
8687

8788
t.Run("subdir ok", func(t *testing.T) {
8889
t.Parallel()
89-
got, err := safePartPath("/tmp/sub/video.mp4", 7)
90+
got, err := safePartPath(filepath.FromSlash("/tmp/sub/video.mp4"), 7)
9091
require.NoError(t, err)
9192
assert.Contains(t, got, "video.mp4.part7")
9293
})
9394

9495
t.Run("part embedded in dir name still resolves correctly", func(t *testing.T) {
9596
t.Parallel()
9697
// Use a path whose basename uniquely identifies the part file.
97-
got, err := safePartPath("/tmp/dir.with.dots/video.mp4", 0)
98+
got, err := safePartPath(filepath.FromSlash("/tmp/dir.with.dots/video.mp4"), 0)
9899
require.NoError(t, err)
99-
assert.Equal(t, "/tmp/dir.with.dots/video.mp4.part0", got)
100+
assert.Equal(t, filepath.FromSlash("/tmp/dir.with.dots/video.mp4.part0"), got)
100101
})
101102
}
102103

@@ -586,8 +587,8 @@ func TestHandleBatchDownloadRange_AllEpisodesAlreadyDownloaded(t *testing.T) {
586587
// handleExistingEpisodes opens an interactive fuzzy finder. Outside a TTY
587588
// it errors on Linux but blocks indefinitely on Windows (tcell winTty
588589
// getConsoleInput syscall), which deadlocks CI. Skip when no TTY.
589-
if os.Getenv("CI") != "" {
590-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
590+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
591+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
591592
}
592593
util.InitLogger()
593594
SetAnimeName("HandleBatchRangeAllExistingTest", 1)
@@ -629,8 +630,8 @@ func TestHandleExistingEpisodes_WithDownloadedFilesEntersFuzzyFinder(t *testing.
629630
// handleExistingEpisodes opens an interactive fuzzy finder. Outside a TTY
630631
// it errors on Linux but blocks indefinitely on Windows (tcell winTty
631632
// getConsoleInput syscall), which deadlocks CI. Skip when no TTY.
632-
if os.Getenv("CI") != "" {
633-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
633+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
634+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
634635
}
635636
SetAnimeName("HandleExistingDownloadedTest", 1)
636637
t.Cleanup(func() { SetAnimeName("", 0) })
@@ -655,8 +656,8 @@ func TestAskAndPlayDownloadedEpisode_WithDownloadedFilesEntersFuzzyFinder(t *tes
655656
// askAndPlayDownloadedEpisode opens an interactive fuzzy finder. Outside a
656657
// TTY it errors on Linux but blocks indefinitely on Windows (tcell winTty
657658
// getConsoleInput syscall), which deadlocks CI. Skip when no TTY.
658-
if os.Getenv("CI") != "" {
659-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
659+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
660+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
660661
}
661662
SetAnimeName("AskAndPlayDownloadedExistingTest", 1)
662663
t.Cleanup(func() { SetAnimeName("", 0) })

internal/player/player.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/alvarorichard/Goanime/internal/util"
3333
"github.com/ktr0731/go-fuzzyfinder"
3434
"github.com/pkg/errors"
35+
"golang.org/x/term"
3536
)
3637

3738
// Cached mpv path — avoids repeated filesystem searches on every episode play
@@ -1248,6 +1249,9 @@ func downloadAndPlayEpisode(
12481249

12491250
// askForDownload presents a prompt for the user to choose a download option.
12501251
func askForDownload() int {
1252+
if !term.IsTerminal(int(os.Stdin.Fd())) {
1253+
return 4 // no TTY: default to play online
1254+
}
12511255
// Build the upscale option label with current status
12521256
upscaleStatus := upscaler.GetShaderModeName(upscaler.CurrentShaderMode)
12531257
upscaleLabel := fmt.Sprintf("Real-time Upscale [%s]", upscaleStatus)
@@ -1291,6 +1295,9 @@ func askForDownload() int {
12911295
}
12921296

12931297
func askForPlayOffline() bool {
1298+
if !term.IsTerminal(int(os.Stdin.Fd())) {
1299+
return false // no TTY: default to no
1300+
}
12941301
items := []string{"Yes", "No"}
12951302
idx, err := tui.Find(items, func(i int) string {
12961303
return items[i]
@@ -1467,6 +1474,9 @@ func GetCurrentSubtitleTrack(socketPath string) (int, error) {
14671474

14681475
// handleUpscaleFromMenu shows the real-time upscaling options menu
14691476
func handleUpscaleFromMenu() error {
1477+
if !term.IsTerminal(int(os.Stdin.Fd())) {
1478+
return fmt.Errorf("no TTY available for interactive menu")
1479+
}
14701480
// Check if shaders are installed
14711481
shadersInstalled := upscaler.ShadersInstalled()
14721482
currentMode := upscaler.GetShaderModeName(upscaler.CurrentShaderMode)

internal/player/player_pure_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/alvarorichard/Goanime/internal/util"
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
13+
"golang.org/x/term"
1314
)
1415

1516
func TestSanitizeMediaTarget(t *testing.T) {
@@ -193,8 +194,8 @@ func TestHandleUpscaleFromMenu_DoesNotPanic(t *testing.T) {
193194
// handleUpscaleFromMenu opens an interactive fuzzy finder. Outside a TTY
194195
// it errors on Linux but blocks indefinitely on Windows (tcell winTty
195196
// getConsoleInput syscall), which deadlocks CI. Skip when no TTY.
196-
if os.Getenv("CI") != "" {
197-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
197+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
198+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
198199
}
199200
assert.NotPanics(t, func() { _ = handleUpscaleFromMenu() })
200201
}
@@ -203,8 +204,8 @@ func TestAskForDownload_ReturnsValidMarker(t *testing.T) {
203204
// askForDownload opens an interactive fuzzy finder. Outside a TTY it
204205
// errors on Linux but blocks indefinitely on Windows (tcell winTty
205206
// getConsoleInput syscall), which deadlocks CI. Skip when no TTY.
206-
if os.Getenv("CI") != "" {
207-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
207+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
208+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
208209
}
209210
got := askForDownload()
210211
assert.GreaterOrEqual(t, got, 1)
@@ -214,8 +215,8 @@ func TestAskForPlayOffline_DoesNotPanic(t *testing.T) {
214215
// askForPlayOffline opens an interactive fuzzy finder. Outside a TTY it
215216
// errors on Linux but blocks indefinitely on Windows (tcell winTty
216217
// getConsoleInput syscall), which deadlocks CI. Skip when no TTY.
217-
if os.Getenv("CI") != "" {
218-
t.Skip("Skipping interactive fuzzy-finder test in CI (no TTY available)")
218+
if os.Getenv("CI") != "" || !term.IsTerminal(int(os.Stdin.Fd())) {
219+
t.Skip("Skipping interactive fuzzy-finder test: requires a real TTY")
219220
}
220221
assert.NotPanics(t, func() { _ = askForPlayOffline() })
221222
}

0 commit comments

Comments
 (0)