Skip to content

Commit 9c73fce

Browse files
akoclaude
andcommitted
fix: make macOS Applications dir mockable to fix test isolation
resolveStudioProDirMacOS and mendixSearchPaths hardcoded /Applications/, so tests that set up fake cached binaries failed on dev machines with a real Studio Pro installation — the resolver found the real app before reaching the cache. Introduce package-level macOSApplicationsDir (default /Applications) and use it in both scan sites. Tests that verify cache-preference behaviour now call setTestApplicationsDir(t, t.TempDir()) to redirect the scan to an empty directory, eliminating the host-machine dependency. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 446ba69 commit 9c73fce

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

cmd/mxcli/docker/check_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func TestCheck_SkipUpdateWidgetsFlag(t *testing.T) {
122122
func TestResolveMxForVersion_PrefersExactCachedVersion(t *testing.T) {
123123
dir := t.TempDir()
124124
setTestHomeDir(t, dir)
125+
setTestApplicationsDir(t, t.TempDir()) // prevent real macOS Studio Pro from matching
125126
// Point PATH at an empty temp dir (rather than clearing it) so exec.LookPath
126127
// still works for any other testing infrastructure but can't find mx.
127128
t.Setenv("PATH", t.TempDir())

cmd/mxcli/docker/detect.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import (
3636
"strings"
3737
)
3838

39+
// macOSApplicationsDir is the root directory scanned for Studio Pro .app bundles
40+
// on macOS. It is a package-level variable so tests can redirect it to a temp dir
41+
// to avoid interference from real Studio Pro installations on the test host.
42+
var macOSApplicationsDir = "/Applications"
43+
3944
// mxbuildBinaryName returns the platform-specific mxbuild binary name.
4045
func mxbuildBinaryName() string {
4146
if runtime.GOOS == "windows" {
@@ -164,7 +169,7 @@ func ResolveStudioProDir(version string) string {
164169
// where X.Y.Z is the base version (e.g., "11.10.0-rc.7 Beta" for 11.10.0).
165170
// Returns the bundle's Contents directory, or "" if not found.
166171
func resolveStudioProDirMacOS(version string) string {
167-
matches, _ := filepath.Glob("/Applications/Mendix Studio Pro *.app")
172+
matches, _ := filepath.Glob(filepath.Join(macOSApplicationsDir, "Mendix Studio Pro *.app"))
168173
re := regexp.MustCompile(`^Mendix Studio Pro (\d+\.\d+\.\d+)`)
169174
for _, match := range matches {
170175
base := strings.TrimSuffix(filepath.Base(match), ".app")
@@ -217,7 +222,7 @@ func mendixSearchPaths(binaryName string) []string {
217222
}
218223
return paths
219224
case "darwin":
220-
return []string{"/Applications/Mendix Studio Pro *.app/Contents/modeler/" + binaryName}
225+
return []string{filepath.Join(macOSApplicationsDir, "Mendix Studio Pro *.app", "Contents", "modeler", binaryName)}
221226
default: // linux
222227
paths := []string{filepath.Join("/opt/mendix/*/modeler", binaryName)}
223228
if home, err := os.UserHomeDir(); err == nil {

cmd/mxcli/docker/detect_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func TestResolveMxBuild_PrefersStudioProOverCache(t *testing.T) {
284284
func TestResolveMxBuild_PrefersExactCachedVersion(t *testing.T) {
285285
dir := t.TempDir()
286286
setTestHomeDir(t, dir)
287+
setTestApplicationsDir(t, t.TempDir()) // prevent real macOS Studio Pro from matching
287288
// Point PATH at an empty temp dir (rather than clearing it) so exec.LookPath
288289
// still works for any other testing infrastructure but can't find mxbuild.
289290
t.Setenv("PATH", t.TempDir())

cmd/mxcli/docker/download_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ func setTestHomeDir(t *testing.T, dir string) {
1818
}
1919
}
2020

21+
// setTestApplicationsDir redirects the macOS Applications directory scan to dir
22+
// so tests that set up cached binaries are not confused by real Studio Pro installs.
23+
func setTestApplicationsDir(t *testing.T, dir string) {
24+
t.Helper()
25+
prev := macOSApplicationsDir
26+
macOSApplicationsDir = dir
27+
t.Cleanup(func() { macOSApplicationsDir = prev })
28+
}
29+
2130
func TestMxBuildCDNURL_ARM64(t *testing.T) {
2231
url := MxBuildCDNURL("11.6.3", "arm64")
2332
expected := "https://cdn.mendix.com/runtime/arm64-mxbuild-11.6.3.tar.gz"

0 commit comments

Comments
 (0)