Files
magpie/internal/gui/terminal_apps_test.go
T
Karenandyetone 2693cd8828 feat(gui): choose macOS session terminal (#241)
* feat(gui): choose macOS session terminal

* session terminal: build the darwin CLI without cgo, drop the dead macOS 11 path, and open Terminal when the .command default is not a terminal

- terminal_apps_darwin.go imports "C" but had no cgo tag, and terminal_apps_other.go was !darwin only, so `CGO_ENABLED=0 GOOS=darwin go build -tags nogui .` (make release-cli's darwin targets) failed with undefined discoverTerminals. The cgo file and its test are now darwin && cgo; the stub is !darwin || !cgo.
- magpie needs macOS 12 (LSMinimumSystemVersion, -mmacosx-version-min=12.0), so the macOS 11 branch (temp .command file, deprecated LSCopyApplicationURLsForURL, CFRelease) never ran; it is gone along with the CoreServices link.
- With no saved choice, a default .command handler that is not a listed terminal, or a failed lookup, now opens Terminal as before the PR instead of failing; Settings labels the system option "System default (Terminal)" then, and the unused "System default (unavailable)" string is dropped.
- session-terminal.test.cjs covers an editor as the default in Chromium and WebKit, en and zh, and is on the README's node --test line.

---------

Co-authored-by: yetone <yetoneful@gmail.com>
2026-09-30 02:36:12 +08:00

48 lines
1.7 KiB
Go

package gui
import (
"reflect"
"strings"
"testing"
)
func TestTerminalOpenArgs(t *testing.T) {
found := terminalDiscovery{
Apps: []terminalApp{
{ID: terminalBundleID, Name: "Terminal", Path: "/System/Applications/Utilities/Terminal.app"},
{ID: "com.mitchellh.ghostty", Name: "Ghostty", Path: "/Applications/Ghostty.app"},
},
Default: "com.mitchellh.ghostty",
}
for _, tc := range []struct {
name, choice string
want []string
}{
{"system default", "", []string{"-a", "/Applications/Ghostty.app"}},
{"Terminal", terminalBundleID, []string{"-a", "Terminal"}},
{"explicit system", "system", []string{"-a", "/Applications/Ghostty.app"}},
{"chosen app", "com.mitchellh.ghostty", []string{"-a", "/Applications/Ghostty.app"}},
} {
t.Run(tc.name, func(t *testing.T) {
got, err := terminalOpenArgs(tc.choice, found)
if err != nil || !reflect.DeepEqual(got, tc.want) {
t.Fatalf("args = %q, %v; want %q", got, err, tc.want)
}
})
}
if _, err := terminalOpenArgs("org.missing.term", found); err == nil || !strings.Contains(err.Error(), "no longer available") {
t.Fatalf("missing app: %v", err)
}
found.Default = terminalBundleID
if got, err := terminalOpenArgs("", found); err != nil || !reflect.DeepEqual(got, []string{"-a", "/System/Applications/Utilities/Terminal.app"}) {
t.Fatalf("Terminal as system default: %q, %v", got, err)
}
found.Default = "org.editor"
if got, err := terminalOpenArgs("", found); err != nil || !reflect.DeepEqual(got, []string{"-a", "Terminal"}) {
t.Fatalf("editor as default: %q, %v", got, err)
}
if got, err := terminalOpenArgs("", terminalDiscovery{}); err != nil || !reflect.DeepEqual(got, []string{"-a", "Terminal"}) {
t.Fatalf("nothing found: %q, %v", got, err)
}
}