From 936a00b23df31e02c4e33bfac636e229594c9f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowotnik?= Date: Sun, 19 Oct 2025 17:33:05 +0200 Subject: [PATCH 1/5] Add functional tests for return-all and replacement flows --- tests/functional/completions_test.go | 44 ++++++++++++++++++++++ tests/functional/fixtures/replacement.yaml | 6 +++ tests/functional/fixtures/simple.yaml | 3 ++ 3 files changed, 53 insertions(+) create mode 100644 tests/functional/completions_test.go create mode 100644 tests/functional/fixtures/replacement.yaml create mode 100644 tests/functional/fixtures/simple.yaml diff --git a/tests/functional/completions_test.go b/tests/functional/completions_test.go new file mode 100644 index 0000000..4c71535 --- /dev/null +++ b/tests/functional/completions_test.go @@ -0,0 +1,44 @@ +package functional_test + +import ( + "path/filepath" + "testing" +) + +func TestReturnAllOutputsAllItems(t *testing.T) { + configPath := filepath.Join(repoRoot, "tests", "functional", "fixtures", "simple.yaml") + + result := runFzshell(t, []string{"--config", configPath, "--all", "simple"}, "", nil) + + if result.ExitCode != 0 { + t.Fatalf("expected exit code 0, got %d (stderr: %q)", result.ExitCode, result.Stderr) + } + + const expectedOutput = "alpha\nbeta\n" + if result.Stdout != expectedOutput { + t.Fatalf("unexpected stdout: got %q, want %q", result.Stdout, expectedOutput) + } + + if result.Stderr != "" { + t.Fatalf("expected empty stderr, got %q", result.Stderr) + } +} + +func TestReplacementRendersLineBuffer(t *testing.T) { + configPath := filepath.Join(repoRoot, "tests", "functional", "fixtures", "replacement.yaml") + + result := runFzshell(t, []string{"--config", configPath, "ticket 42/build"}, "", nil) + + if result.ExitCode != 0 { + t.Fatalf("expected exit code 0, got %d (stderr: %q)", result.ExitCode, result.Stderr) + } + + const expectedOutput = "ticket 42/build -> 42|build|command:42:build" + if result.Stdout != expectedOutput { + t.Fatalf("unexpected stdout: got %q, want %q", result.Stdout, expectedOutput) + } + + if result.Stderr != "" { + t.Fatalf("expected empty stderr, got %q", result.Stderr) + } +} diff --git a/tests/functional/fixtures/replacement.yaml b/tests/functional/fixtures/replacement.yaml new file mode 100644 index 0000000..7bd4745 --- /dev/null +++ b/tests/functional/fixtures/replacement.yaml @@ -0,0 +1,6 @@ +completions: + - pattern: "ticket (?P[0-9]+)/(\\w+)$" + cmd: "printf 'command:%s:%s\\n' \"$ID\" \"$1\"" + map: "{{ printf \"%s|%s|%s\" .ID ._1 .item }}" + replacement: "ticket {{.ID}}/{{._1}} -> {{.item}}" + selectOne: true diff --git a/tests/functional/fixtures/simple.yaml b/tests/functional/fixtures/simple.yaml new file mode 100644 index 0000000..f6dd023 --- /dev/null +++ b/tests/functional/fixtures/simple.yaml @@ -0,0 +1,3 @@ +completions: + - pattern: "simple$" + cmd: "printf 'alpha\\nbeta\\n'" From 1bf067ad4a52acf87cb9d5d6540ee9ae65605022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowotnik?= Date: Mon, 5 Jan 2026 13:52:40 +0100 Subject: [PATCH 2/5] Update staticcheck action to avoid cache v2 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 761d017..ffc0cbc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: with: fetch-depth: 0 - name: lint - uses: dominikh/staticcheck-action@v1.2.0 + uses: dominikh/staticcheck-action@v1.3.0 with: version: "2022.1" install-go: false From 1866ae2cb0444aadff2505743e714414c9a42d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowotnik?= Date: Mon, 5 Jan 2026 14:00:23 +0100 Subject: [PATCH 3/5] Use fzf filter mode without a TTY --- internal/compl/source.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/compl/source.go b/internal/compl/source.go index d9eb6c3..38bb330 100644 --- a/internal/compl/source.go +++ b/internal/compl/source.go @@ -3,12 +3,12 @@ package compl import ( "os" "os/exec" - "text/template" fzf "github.com/mnowotnik/fzf/src" "github.com/mnowotnik/fzshell/internal/utils" "github.com/pkg/errors" + "golang.org/x/term" ) type CompletionSource struct { @@ -110,7 +110,7 @@ func (cs *CompletionSource) pipeCommandToFzf(args []string, kwargs map[string]st } } options.Select1 = cs.SelectOne - if returnAll { + if returnAll || !term.IsTerminal(int(os.Stdout.Fd())) || !term.IsTerminal(int(os.Stdin.Fd())) { var filter string = "" options.Filter = &filter } From 4392edf038bee70756228c4b3f64debaeed2a664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowotnik?= Date: Tue, 6 Jan 2026 21:46:09 +0100 Subject: [PATCH 4/5] Treat stderr as non-tty for fzf filter mode --- internal/compl/source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/compl/source.go b/internal/compl/source.go index 38bb330..f546a86 100644 --- a/internal/compl/source.go +++ b/internal/compl/source.go @@ -110,7 +110,7 @@ func (cs *CompletionSource) pipeCommandToFzf(args []string, kwargs map[string]st } } options.Select1 = cs.SelectOne - if returnAll || !term.IsTerminal(int(os.Stdout.Fd())) || !term.IsTerminal(int(os.Stdin.Fd())) { + if returnAll || !term.IsTerminal(int(os.Stdout.Fd())) || !term.IsTerminal(int(os.Stdin.Fd())) || !term.IsTerminal(int(os.Stderr.Fd())) { var filter string = "" options.Filter = &filter } From 741232fc7ec96668e86bcc0bbe0d03fc987143cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Nowotnik?= Date: Tue, 6 Jan 2026 21:46:19 +0100 Subject: [PATCH 5/5] Update CI to Go 1.25 with setup-go v6 --- .github/workflows/test.yml | 4 ++-- go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ffc0cbc..9f1d9b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,11 +10,11 @@ jobs: strategy: matrix: os: [ "ubuntu-latest", "macos-latest" ] - go-version: [ "1.18" ] + go-version: [ "1.25.x" ] runs-on: ${{ matrix.os }} steps: - name: setup Go ${{ matrix.go-version }} - uses: actions/setup-go@v3 + uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} - name: checkout diff --git a/go.mod b/go.mod index e07083e..67ee159 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/mnowotnik/fzshell -go 1.18 +go 1.25 require ( github.com/Masterminds/sprig/v3 v3.0.2