Skip to content

[Test Improver] Add tests for posixSingleQuote and editor.Preferred/Command #41

@github-actions

Description

@github-actions

🤖 This was created by Test Improver, an automated AI assistant focused on improving tests for this repository.

Goal and Rationale

Two pure/deterministic functions lack direct test coverage:

  • posixSingleQuote (internal/autostart/shell.go): wraps strings in POSIX shell single quotes with correct ''\'' escaping. Used when building remote shell commands — incorrect escaping silently breaks remote sh -c execution.
  • Preferred() (internal/editor/editor.go): returns the preferred editor based on VISUAL, then EDITOR, then a platform default. Determines which editor opens config files.

Approach

internal/autostart/shell_test.goTest_posixSingleQuote (7 table-driven cases):

  • Empty string, simple strings, single-quote escaping, consecutive single-quotes

internal/editor/editor_test.goTestPreferred (3 cases) + TestCommand_usesPreferred:

  • VISUAL/EDITOR priority, default vim fallback (non-Windows skip), Command arg construction

Reproducibility

# Download the artifact from the workflow run
gh run download 24629908609 -n agent -D /tmp/agent-24629908609

# Create a new branch
git checkout -b test-assist/posixsinglequote-editor-preferred-2026-04-19

# Apply the patch
git am --3way /tmp/agent-24629908609/aw-test-assist-posixsinglequote-editor-preferred-2026-04-19.patch

# Push and create PR
git push origin test-assist/posixsinglequote-editor-preferred-2026-04-19
gh pr create --title '[Test Improver] Add tests for posixSingleQuote and editor.Preferred/Command' --base main

Show patch (137 lines)

From d7096f9c94fa29a36fae35c563bd30008e409c25 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]`@users`.noreply.github.com>
Date: Sun, 19 Apr 2026 13:17:09 +0000
Subject: [PATCH] test: add posixSingleQuote and editor.Preferred/Command tests

- Add Test_posixSingleQuote in internal/autostart/shell_test.go (7 cases)
- Add TestPreferred and TestCommand_usesPreferred in internal/editor/editor_test.go

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 internal/autostart/shell_test.go | 32 +++++++++++++++
 internal/editor/editor_test.go   | 69 ++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100644 internal/autostart/shell_test.go
 create mode 100644 internal/editor/editor_test.go

diff --git a/internal/autostart/shell_test.go b/internal/autostart/shell_test.go
new file mode 100644
index 0000000..0feab44
--- /dev/null
+++ b/internal/autostart/shell_test.go
@@ -0,0 +1,32 @@
+package autostart
+
+import "testing"
+
+func Test_posixSingleQuote(t *testing.T) {
+	t.Parallel()
+	cases := []struct {
+		input string
+		want  string
+	}{
+		// Empty string produces empty single-quoted string
+		{"", "''"},
+		// Simple strings pass through unchanged inside quotes
+		{"hello", "'hello'"},
+		{"no spaces", "'no spaces'"},
+		{"path/to/file", "'path/to/file'"},
+		// Single quotes are escaped via the POSIX idiom ' → '\''
+		{"it's", "'it'\\''s'"},
+		{"a'b'c", "'a'\\''b'\\''c'"},
+		// Two consecutive single quotes
+		{"''", "''\\'''\\'''"},
+	}
+	for _, tc := range cases {
+		t.Run(tc.input, func(t *testing.T) {
+			t.Parallel()
+			got := posixSingleQuote(tc.input)
+			if got != tc.want {
+				t.Errorf("posixSingleQuote(%q) = %q, want %q", tc.input, got, tc.want)
+			}
+		})
+	}
+}
diff --git a/internal/editor/editor_test.go b/internal/editor/editor_test.go
new file mode 100644
index 0000000..42fcb6a
--- /dev/null
+++ b/internal/editor/editor_test.go
@@ -0,0 +1,69 @@
+package editor
+
+import (
+	"runtime"
+	"testing"
+)
+
+func TestPreferred(t *testing.T) {
+	t.Parallel()
+	cases := []struct {
+		name   string
+		visual string
+		editor string
+		want   string
+		// skip when the expected result depends on GOOS and we're not on that OS
+		onlyOS string
+	}{
+		{
+			name:   "VISUAL takes priority over EDITOR",
+			visual: "emacs",
+			editor: "nano",
+			want:   "emacs",
+		},
+		{
+			name:   "EDITOR used when VISUAL is unset",
+			visual: "",
+			editor: "nano",
+			want:   "nano",
+		},
+		{
+			name:   "default vim on non-Windows",
+			visual: "",
+			editor: "",
+			want:   "vim",
+			onlyOS: "!windows",
+		},
+	}
+	for _, tc := range cases {
+		t.Run(tc.name, func(t *testing.T) {
+			t.Parallel()
+			if tc.onlyOS == "!windows" && runtime.GOOS == "windows" {
+				t.Skip("default editor differs on Windows")
+			}
+			t.Setenv("VISUAL", tc.visual)
+			t.Setenv("EDITOR", tc.editor)
+			got := Preferred()
+			if got != tc.want {
+				t.Errorf("Preferred() = %q, want %q", got, tc.want)
+			}
+		})
+	}
+}
+
+func TestCommand_usesPreferred(t *testing.T) {
+	t.Parallel()
+	t.Setenv("VISUAL", "myvim")
+	t.Setenv("EDITOR", "")
+	cmd := Command("/some/file")
+	if cmd == nil {
+		t.Fatal("Command returned nil")
+	}
+	if cmd.Path == "" {
+		t.Fatal("Command returned cmd with empty Path")
+	}
+	// Args[0] is the resolved binary path; Args[1] should be the file path
+	if len(cmd.Args) < 2 || cmd.Args[1] != "/some/file" {
+		t.Errorf("Command args = %v, want last arg to be /some/file", cmd.Args)
+	}
+}

Generated by Daily Test Improver · ● 2.7M ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/daily-test-improver.md@97143ac59cb3a13ef2a77581f929f06719c7402a

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions