From d51ae07840f745feaedeefa175b85e489e144029 Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Mon, 16 Mar 2026 20:41:10 +0400 Subject: [PATCH 1/2] ci: test fix for mise --- internal/sandbox/tools/mise_test.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/sandbox/tools/mise_test.go b/internal/sandbox/tools/mise_test.go index a1756b7..7edb585 100644 --- a/internal/sandbox/tools/mise_test.go +++ b/internal/sandbox/tools/mise_test.go @@ -73,14 +73,34 @@ func TestMise_DockerBindings_NoCacheDirs(t *testing.T) { } } -// isolateMiseConfig points mise at empty config/data directories so tests -// are not affected by host or CI mise settings (e.g. trusted_config_paths). +// isolateMiseConfig points mise at empty config/data directories and unsets +// trust-related env vars so tests are not affected by host or CI settings. func isolateMiseConfig(t *testing.T) { t.Helper() t.Setenv("MISE_CONFIG_DIR", t.TempDir()) t.Setenv("MISE_DATA_DIR", t.TempDir()) - t.Setenv("MISE_TRUSTED_CONFIG_PATHS", "") - t.Setenv("MISE_YES", "") + // Must fully unset (not set to empty) — mise checks var presence, not value. + unsetForTest(t, "MISE_TRUSTED_CONFIG_PATHS") + unsetForTest(t, "MISE_YES") +} + +// unsetForTest removes an env var for the duration of the test, restoring it on cleanup. +func unsetForTest(t *testing.T, key string) { + t.Helper() + if orig, ok := os.LookupEnv(key); ok { + if err := os.Unsetenv(key); err != nil { + t.Fatalf("failed to unset %s: %v", key, err) + } + t.Cleanup(func() { + if err := os.Setenv(key, orig); err != nil { + t.Errorf("failed to restore %s: %v", key, err) + } + }) + } else { + if err := os.Unsetenv(key); err != nil { + t.Fatalf("failed to unset %s: %v", key, err) + } + } } func TestCheckMiseTrust_NoMise(t *testing.T) { From 3e8e635ea22ea1caf2a57f5ec9e7b3311cbca744 Mon Sep 17 00:00:00 2001 From: Zakhar Bessarab Date: Mon, 16 Mar 2026 20:46:45 +0400 Subject: [PATCH 2/2] tests: move mise local test to integration --- .../sandbox/tools/mise_integration_test.go | 100 ++++++++++++++++++ internal/sandbox/tools/mise_test.go | 96 ----------------- 2 files changed, 100 insertions(+), 96 deletions(-) create mode 100644 internal/sandbox/tools/mise_integration_test.go diff --git a/internal/sandbox/tools/mise_integration_test.go b/internal/sandbox/tools/mise_integration_test.go new file mode 100644 index 0000000..3c332c4 --- /dev/null +++ b/internal/sandbox/tools/mise_integration_test.go @@ -0,0 +1,100 @@ +//go:build integration + +package tools + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "testing" +) + +// isolateMiseConfig points mise at empty config/data/state directories and unsets +// trust-related env vars so tests are not affected by host settings. +func isolateMiseConfig(t *testing.T) { + t.Helper() + t.Setenv("MISE_CONFIG_DIR", t.TempDir()) + t.Setenv("MISE_DATA_DIR", t.TempDir()) + t.Setenv("MISE_STATE_DIR", t.TempDir()) + // Must fully unset (not set to empty) — mise checks var presence, not value. + unsetForTest(t, "MISE_TRUSTED_CONFIG_PATHS") + unsetForTest(t, "MISE_YES") +} + +// unsetForTest removes an env var for the duration of the test, restoring it on cleanup. +func unsetForTest(t *testing.T, key string) { + t.Helper() + if orig, ok := os.LookupEnv(key); ok { + if err := os.Unsetenv(key); err != nil { + t.Fatalf("failed to unset %s: %v", key, err) + } + t.Cleanup(func() { + if err := os.Setenv(key, orig); err != nil { + t.Errorf("failed to restore %s: %v", key, err) + } + }) + } else { + if err := os.Unsetenv(key); err != nil { + t.Fatalf("failed to unset %s: %v", key, err) + } + } +} + +func TestCheckMiseTrust_UntrustedConfig(t *testing.T) { + if _, err := exec.LookPath("mise"); err != nil { + t.Skip("mise not installed") + } + + isolateMiseConfig(t) + + dir := t.TempDir() + configPath := filepath.Join(dir, ".mise.toml") + if err := os.WriteFile(configPath, []byte("[tools]\n"), 0o644); err != nil { + t.Fatal(err) + } + + statuses, err := CheckMiseTrust(dir) + if err != nil { + t.Fatalf("CheckMiseTrust() error = %v", err) + } + + foundUntrusted := false + for _, s := range statuses { + if !s.Trusted && strings.Contains(s.Path, dir) { + foundUntrusted = true + } + } + if !foundUntrusted { + t.Errorf("expected untrusted status for %s, got: %v", dir, statuses) + } +} + +func TestTrustMiseConfig(t *testing.T) { + if _, err := exec.LookPath("mise"); err != nil { + t.Skip("mise not installed") + } + + isolateMiseConfig(t) + + dir := t.TempDir() + configPath := filepath.Join(dir, ".mise.toml") + if err := os.WriteFile(configPath, []byte("[tools]\n"), 0o644); err != nil { + t.Fatal(err) + } + + if err := TrustMiseConfig(dir); err != nil { + t.Fatalf("TrustMiseConfig() error = %v", err) + } + + statuses, err := CheckMiseTrust(dir) + if err != nil { + t.Fatalf("CheckMiseTrust() error = %v", err) + } + + for _, s := range statuses { + if strings.Contains(s.Path, dir) && !s.Trusted { + t.Errorf("expected trusted status for %s after TrustMiseConfig()", s.Path) + } + } +} diff --git a/internal/sandbox/tools/mise_test.go b/internal/sandbox/tools/mise_test.go index 7edb585..f552859 100644 --- a/internal/sandbox/tools/mise_test.go +++ b/internal/sandbox/tools/mise_test.go @@ -1,9 +1,7 @@ package tools import ( - "os" "os/exec" - "path/filepath" "strings" "testing" ) @@ -73,36 +71,6 @@ func TestMise_DockerBindings_NoCacheDirs(t *testing.T) { } } -// isolateMiseConfig points mise at empty config/data directories and unsets -// trust-related env vars so tests are not affected by host or CI settings. -func isolateMiseConfig(t *testing.T) { - t.Helper() - t.Setenv("MISE_CONFIG_DIR", t.TempDir()) - t.Setenv("MISE_DATA_DIR", t.TempDir()) - // Must fully unset (not set to empty) — mise checks var presence, not value. - unsetForTest(t, "MISE_TRUSTED_CONFIG_PATHS") - unsetForTest(t, "MISE_YES") -} - -// unsetForTest removes an env var for the duration of the test, restoring it on cleanup. -func unsetForTest(t *testing.T, key string) { - t.Helper() - if orig, ok := os.LookupEnv(key); ok { - if err := os.Unsetenv(key); err != nil { - t.Fatalf("failed to unset %s: %v", key, err) - } - t.Cleanup(func() { - if err := os.Setenv(key, orig); err != nil { - t.Errorf("failed to restore %s: %v", key, err) - } - }) - } else { - if err := os.Unsetenv(key); err != nil { - t.Fatalf("failed to unset %s: %v", key, err) - } - } -} - func TestCheckMiseTrust_NoMise(t *testing.T) { // If mise is not installed, CheckMiseTrust should return nil if _, err := exec.LookPath("mise"); err != nil { @@ -133,67 +101,3 @@ func TestCheckMiseTrust_NoConfig(t *testing.T) { } } } - -func TestCheckMiseTrust_UntrustedConfig(t *testing.T) { - if _, err := exec.LookPath("mise"); err != nil { - t.Skip("mise not installed") - } - - // Isolate mise from host config to get consistent trust behavior in CI. - // jdx/mise-action may configure trusted_config_paths in mise's settings file. - isolateMiseConfig(t) - - dir := t.TempDir() - configPath := filepath.Join(dir, ".mise.toml") - if err := os.WriteFile(configPath, []byte("[tools]\n"), 0o644); err != nil { - t.Fatal(err) - } - - statuses, err := CheckMiseTrust(dir) - if err != nil { - t.Fatalf("CheckMiseTrust() error = %v", err) - } - - // Should have at least one untrusted entry for the temp dir - foundUntrusted := false - for _, s := range statuses { - if !s.Trusted && strings.Contains(s.Path, dir) { - foundUntrusted = true - } - } - if !foundUntrusted { - t.Errorf("expected untrusted status for %s, got: %v", dir, statuses) - } -} - -func TestTrustMiseConfig(t *testing.T) { - if _, err := exec.LookPath("mise"); err != nil { - t.Skip("mise not installed") - } - - // Isolate mise from host config to get consistent trust behavior in CI. - isolateMiseConfig(t) - - dir := t.TempDir() - configPath := filepath.Join(dir, ".mise.toml") - if err := os.WriteFile(configPath, []byte("[tools]\n"), 0o644); err != nil { - t.Fatal(err) - } - - // Trust the config - if err := TrustMiseConfig(dir); err != nil { - t.Fatalf("TrustMiseConfig() error = %v", err) - } - - // Verify it's now trusted - statuses, err := CheckMiseTrust(dir) - if err != nil { - t.Fatalf("CheckMiseTrust() error = %v", err) - } - - for _, s := range statuses { - if strings.Contains(s.Path, dir) && !s.Trusted { - t.Errorf("expected trusted status for %s after TrustMiseConfig()", s.Path) - } - } -}