Skip to content

Commit 1a1cf36

Browse files
committed
fix(cmd): resolve test state leakage and flakiness
Fix global variable modification in runDeactivate and TestRunLockCheck which caused unpredictable test failures in parallel or randomized testing environments (e.g. CI).
1 parent 86ebba7 commit 1a1cf36

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

cmd/10.deactivate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,17 @@ func runDeactivate(cmd *cobra.Command, args []string) error {
6565

6666
// Detect shell if not specified
6767
// Detect shell if not specified in flags
68-
if deactivateShell == "" && len(args) > 0 {
68+
shellToUse := deactivateShell
69+
if shellToUse == "" && len(args) > 0 {
6970
firstArg := strings.ToLower(args[0])
7071
// Check if first arg is a known shell name
7172
if firstArg == "bash" || firstArg == "zsh" || firstArg == "fish" || firstArg == "powershell" || firstArg == "pwsh" {
72-
deactivateShell = firstArg
73+
shellToUse = firstArg
7374
args = args[1:] // Shift args
7475
}
7576
}
7677

77-
shellType, err := resolveShellType(deactivateShell)
78+
shellType, err := resolveShellType(shellToUse)
7879
if err != nil {
7980
formatter.Error("Failed to detect shell", map[string]interface{}{
8081
"error": err.Error(),

cmd/31.lock_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func TestRunLockCheck(t *testing.T) {
1818
t.Setenv("UNIRTM_DATA_DIR", tmpDir)
1919
t.Setenv("UNIRTM_CONFIG_DIR", tmpDir)
2020

21+
// Reset global flags to prevent leakage from other tests
22+
lockCheck = false
23+
2124
// Since there is no config file, it should just return no error
2225
err := lockCmd.RunE(lockCmd, []string{})
2326
assert.NoError(t, err)

0 commit comments

Comments
 (0)