Skip to content

Commit 069a387

Browse files
committed
fix(test): use mkdtemp for unique temp dir in plan-manager contract tests
Static path 'plan-manager-contract-tests' caused EINVAL races when concurrent test workers cleaned up the shared directory while another test was still writing to it. Replace with mkdtemp per setup() call so each test run gets an isolated directory.
1 parent bdb01df commit 069a387

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

packages/core/test/unit/contracts/plan-manager-contract.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { describe, it, expect } from 'vitest';
99
import { tmpdir } from 'node:os';
1010
import { join } from 'node:path';
11+
import { mkdtemp } from 'node:fs/promises';
1112
import {
1213
BaseInterfaceContract,
1314
ValidationHelpers,
@@ -55,10 +56,12 @@ const mockStateMachine = {
5556
},
5657
};
5758

58-
// Create test paths using temp directory
59-
const testDir = join(tmpdir(), 'plan-manager-contract-tests');
60-
const testPlanPath = join(testDir, 'plan.md');
61-
const testProjectPath = join(testDir, 'project');
59+
// Paths are resolved lazily in setup() so each test run gets a unique directory.
60+
// Using a static path caused flakiness when cleanup in one test deleted the
61+
// directory while another concurrent test was still writing to it.
62+
let testDir = join(tmpdir(), 'plan-manager-contract-tests');
63+
let testPlanPath = join(testDir, 'plan.md');
64+
let testProjectPath = join(testDir, 'project');
6265

6366
/**
6467
* Plan Manager Contract Test Suite
@@ -315,9 +318,10 @@ describe('IPlanManager Interface Contract', () => {
315318
return new PlanManager();
316319
},
317320
setup: async (instance: IPlanManager) => {
318-
// Ensure test directory exists
319-
const { mkdir } = await import('node:fs/promises');
320-
await mkdir(testDir, { recursive: true });
321+
// Create a unique temp directory per test run to avoid concurrent-cleanup races
322+
testDir = await mkdtemp(join(tmpdir(), 'plan-manager-contract-'));
323+
testPlanPath = join(testDir, 'plan.md');
324+
testProjectPath = join(testDir, 'project');
321325

322326
// Set up state machine for PlanManager
323327
(

0 commit comments

Comments
 (0)