From d52131e0d1c3452d60d0a59262dbbcd419bd2332 Mon Sep 17 00:00:00 2001 From: rcourtman <8825017+rcourtman@users.noreply.github.com> Date: Tue, 6 Oct 2026 10:21:05 +0100 Subject: [PATCH] Close the harness command client before Windows removes its state dir Since #2550, three command identity tests fail on Windows x64: TempDir cleanup cannot delete operation-receipts.db because the agent's command client still holds it open. Those tests never call run, so nothing closes the client that New built, and Windows refuses to delete an open file. Other platforms delete it anyway. Stop and close the command client in a harness cleanup. It is registered after the state TempDir, so it runs first, and Close is idempotent for the tests that do run the agent. Production already closes the client when Run exits or an identity supersedes it. --- internal/hostagent/command_client_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/hostagent/command_client_test.go b/internal/hostagent/command_client_test.go index e7934b327c..8f02f50bb7 100644 --- a/internal/hostagent/command_client_test.go +++ b/internal/hostagent/command_client_test.go @@ -601,6 +601,10 @@ func newCommandIdentityHarness(t *testing.T, presentedID string, interval time.D agent.httpClient = h.server.Client() agent.trimmedPulseURL = h.server.URL h.agent = agent + // Run closes the command client on exit, but several tests never call + // run. Close it here, before the state TempDir is removed: Windows cannot + // delete the open operation-receipts.db. + t.Cleanup(func() { agent.stopCommandClient(true) }) return h }