Skip to content

Commit 29443f9

Browse files
gtsiolisclaude
andcommitted
test: fix flaky Windows temp-dir cleanup in az stop-interception test
TestAzStopInterceptionNoOpWhenNotIntercepting is the only az test that runs the real az binary against a temp HOME on Windows. az spawns background processes that hold handles open under HOME\.azure, so t.TempDir()'s auto RemoveAll fails with "being used by another process" and fails an otherwise-passing test. Use a best-effort temp HOME (azTempHome) that ignores cleanup errors instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 29a25f7 commit 29443f9

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

test/integration/az_interception_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestAzStopInterceptionNoOpWhenNotIntercepting(t *testing.T) {
5656
requireAzCLI(t)
5757
t.Parallel()
5858
workDir := azureWorkDir(t)
59-
home := t.TempDir() // fresh ~/.azure: active cloud is the default AzureCloud
59+
home := azTempHome(t) // fresh ~/.azure: active cloud is the default AzureCloud
6060

6161
stdout, _, err := runLstk(t, testContext(t), workDir,
6262
env.With(env.Home, home),

test/integration/setup_azure_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ func requireAzCLI(t *testing.T) {
2222
}
2323
}
2424

25+
// azTempHome returns a temporary HOME directory whose cleanup tolerates Windows
26+
// failures. The Azure CLI spawns background processes that keep handles open
27+
// under HOME\.azure, so Go's t.TempDir() auto-cleanup can fail with "being used
28+
// by another process" on Windows and wrongly fail an otherwise-passing test.
29+
// We remove it best-effort instead.
30+
func azTempHome(t *testing.T) string {
31+
t.Helper()
32+
dir, err := os.MkdirTemp("", "lstk-az-home-")
33+
require.NoError(t, err)
34+
t.Cleanup(func() { _ = os.RemoveAll(dir) })
35+
return dir
36+
}
37+
2538
// azureWorkDir prepares a fresh workDir with a project-local `.lstk/config.toml`
2639
// containing an Azure container, and returns its path. Tests run `lstk` with
2740
// `cmd.Dir = workDir` so the project-local config search finds this file —

0 commit comments

Comments
 (0)