| 1 | package boot |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "testing" |
| 6 | "time" |
| 7 | |
| 8 | "reasonix/internal/provider" |
| 9 | ) |
| 10 | |
| 11 | // mainConversationRequests is retained as a test helper name for callers that |
| 12 | // predate the removal of the completion validator. All provider requests now |
| 13 | // belong to the main deterministic Agent loop. |
| 14 | func mainConversationRequests(reqs []provider.Request) []provider.Request { |
| 15 | return append([]provider.Request(nil), reqs...) |
| 16 | } |
| 17 | |
| 18 | // robustTempDir is a drop-in for t.TempDir whose cleanup retries RemoveAll for a |
| 19 | // short window. Tests here build a full Controller (Build / control.New); at |
| 20 | // teardown a background resource — a job goroutine draining after its context is |
| 21 | // cancelled, or an MCP stats/schema writer flushing — can still hold a file |
| 22 | // under the dir for a few milliseconds after Close returns. On Windows that |
| 23 | // surfaces as "being used by another process"; on Linux a write racing RemoveAll |
| 24 | // surfaces as "directory not empty". Plain t.TempDir turns that teardown race |
| 25 | // into a red test even though every assertion passed (this is the recurring |
| 26 | // main-v2 CI flake that #3371 only papered over). Retrying absorbs the race; a |
| 27 | // dir that never frees is logged, not fatal, so a genuine leak stays visible |
| 28 | // without reintroducing the flake. |
| 29 | func robustTempDir(t *testing.T) string { |
| 30 | t.Helper() |
| 31 | dir, err := os.MkdirTemp("", "reasonix-test-*") |
| 32 | if err != nil { |
| 33 | t.Fatalf("robustTempDir: %v", err) |
| 34 | } |
| 35 | t.Cleanup(func() { |
| 36 | var rmErr error |
| 37 | for range 100 { |
| 38 | if rmErr = os.RemoveAll(dir); rmErr == nil { |
| 39 | return |
| 40 | } |
| 41 | time.Sleep(20 * time.Millisecond) |
| 42 | } |
| 43 | t.Logf("robustTempDir: cleanup did not converge for %s: %v", dir, rmErr) |
| 44 | }) |
| 45 | return dir |
| 46 | } |
| 47 |