Skip to content

Commit ebf15db

Browse files
committed
test(windows): reuse rmWithRetries in watcher suites
1 parent 87e7434 commit ebf15db

5 files changed

Lines changed: 25 additions & 38 deletions

File tree

tests/auto-refresh-e2e.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'path';
55
import { startFileWatcher } from '../src/core/file-watcher.js';
66
import { createAutoRefreshController } from '../src/core/auto-refresh.js';
77
import { CodebaseIndexer } from '../src/core/indexer.js';
8+
import { rmWithRetries } from './test-helpers.js';
89
import {
910
CODEBASE_CONTEXT_DIRNAME,
1011
KEYWORD_INDEX_FILENAME
@@ -72,7 +73,7 @@ describe('Auto-refresh E2E', () => {
7273
});
7374

7475
afterEach(async () => {
75-
await fs.rm(tempDir, { recursive: true, force: true });
76+
await rmWithRetries(tempDir);
7677
});
7778

7879
it('updates index after a file edit without manual refresh_index', async () => {

tests/file-watcher.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { promises as fs } from 'fs';
33
import path from 'path';
44
import os from 'os';
55
import { startFileWatcher } from '../src/core/file-watcher.js';
6+
import { rmWithRetries } from './test-helpers.js';
67

78
describe('FileWatcher', () => {
89
let tempDir: string;
@@ -12,7 +13,7 @@ describe('FileWatcher', () => {
1213
});
1314

1415
afterEach(async () => {
15-
await fs.rm(tempDir, { recursive: true, force: true });
16+
await rmWithRetries(tempDir);
1617
});
1718

1819
it('triggers onChanged after debounce window', async () => {

tests/impact-2hop.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'path';
55
import { CodebaseIndexer } from '../src/core/indexer.js';
66
import { dispatchTool } from '../src/tools/index.js';
77
import type { ToolContext } from '../src/tools/types.js';
8+
import { rmWithRetries } from './test-helpers.js';
89
import {
910
CODEBASE_CONTEXT_DIRNAME,
1011
INTELLIGENCE_FILENAME,
@@ -18,24 +19,6 @@ describe('Impact candidates (2-hop)', () => {
1819
let tempRoot: string | null = null;
1920
const token = 'UNIQUETOKEN123';
2021

21-
async function rmWithRetries(targetPath: string): Promise<void> {
22-
const maxAttempts = 8;
23-
let delayMs = 25;
24-
25-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
26-
try {
27-
await fs.rm(targetPath, { recursive: true, force: true });
28-
return;
29-
} catch (error) {
30-
const code = (error as { code?: string }).code;
31-
const retryable = code === 'ENOTEMPTY' || code === 'EPERM' || code === 'EBUSY';
32-
if (!retryable || attempt === maxAttempts) throw error;
33-
await new Promise((r) => setTimeout(r, delayMs));
34-
delayMs *= 2;
35-
}
36-
}
37-
}
38-
3922
beforeEach(async () => {
4023
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'impact-2hop-'));
4124
const srcDir = path.join(tempRoot, 'src');

tests/search-snippets.test.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,11 @@ import { promises as fs } from 'fs';
33
import os from 'os';
44
import path from 'path';
55
import { CodebaseIndexer } from '../src/core/indexer.js';
6+
import { rmWithRetries } from './test-helpers.js';
67

78
describe('Search Snippets with Scope Headers', () => {
89
let tempRoot: string | null = null;
910

10-
async function rmWithRetries(targetPath: string): Promise<void> {
11-
const maxAttempts = 8;
12-
let delayMs = 25;
13-
14-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
15-
try {
16-
await fs.rm(targetPath, { recursive: true, force: true });
17-
return;
18-
} catch (error) {
19-
const code = (error as { code?: string }).code;
20-
const retryable = code === 'ENOTEMPTY' || code === 'EPERM' || code === 'EBUSY';
21-
if (!retryable || attempt === maxAttempts) throw error;
22-
await new Promise((r) => setTimeout(r, delayMs));
23-
delayMs *= 2;
24-
}
25-
}
26-
}
27-
2811
beforeEach(async () => {
2912
vi.resetModules();
3013
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'search-snippets-test-'));

tests/test-helpers.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { promises as fs } from 'fs';
2+
3+
export async function rmWithRetries(targetPath: string): Promise<void> {
4+
const maxAttempts = 8;
5+
let delayMs = 25;
6+
7+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
8+
try {
9+
await fs.rm(targetPath, { recursive: true, force: true });
10+
return;
11+
} catch (error) {
12+
const code = (error as { code?: string }).code;
13+
const retryable = code === 'ENOTEMPTY' || code === 'EPERM' || code === 'EBUSY';
14+
if (!retryable || attempt === maxAttempts) throw error;
15+
await new Promise((resolve) => setTimeout(resolve, delayMs));
16+
delayMs *= 2;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)