fix(watcher-tests): await ready + harden Windows cleanup#55
fix(watcher-tests): await ready + harden Windows cleanup#55PatrickSys merged 2 commits intomasterfrom
Conversation
Greptile SummaryThis PR improves test reliability by replacing arbitrary sleep timings with deterministic ready callbacks and adding retry logic for Windows filesystem cleanup issues.
Issues found:
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| tests/file-watcher.test.ts | Updated tests to await watcher ready event, but missing Windows cleanup hardening |
| tests/auto-refresh-e2e.test.ts | Replaced sleep with ready callback, but missing Windows cleanup hardening |
| tests/impact-2hop.test.ts | Added retry logic with exponential backoff for Windows filesystem cleanup |
Last reviewed commit: 87e7434
tests/impact-2hop.test.ts
Outdated
| async function rmWithRetries(targetPath: string): Promise<void> { | ||
| const maxAttempts = 8; | ||
| let delayMs = 25; | ||
|
|
||
| for (let attempt = 1; attempt <= maxAttempts; attempt++) { | ||
| try { | ||
| await fs.rm(targetPath, { recursive: true, force: true }); | ||
| return; | ||
| } catch (error) { | ||
| const code = (error as { code?: string }).code; | ||
| const retryable = code === 'ENOTEMPTY' || code === 'EPERM' || code === 'EBUSY'; | ||
| if (!retryable || attempt === maxAttempts) throw error; | ||
| await new Promise((r) => setTimeout(r, delayMs)); | ||
| delayMs *= 2; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
consider extracting rmWithRetries to a shared test utility file since it's duplicated in search-snippets.test.ts and will likely be needed in other test files
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Additional Comments (2)
|
|
Greptile feedback addressed in ebf15db: extracted |
What / Why
Phase 2d (auto-refresh file watcher) is merged, but a full-suite run on Windows exposed intermittent flakes that make CI/local verification unreliable:
ENOTEMPTY/EPERM/EBUSY.This PR hardens the watcher tests (and adds a tiny optional hook) so the test suite is deterministic and accurately validates 2d behavior.
Changes
src/core/file-watcher.ts: add optionalonReady?: () => voidand fire it on chokidar'ready'.tests/file-watcher.test.ts: wait for watcher readiness; adjust debounce test timing to avoid double-fire flakes.tests/auto-refresh-e2e.test.ts: wait for watcher readiness instead of sleeping.tests/search-snippets.test.ts: retryfs.rmon Windows + bump hook timeouts.tests/impact-2hop.test.ts: retryfs.rm+ useos.tmpdir()for temp roots (avoid repo/gitrepo side effects + sporadicEPERM lstat).Non-goals / Notes
onReadyis optional).--jsonCLI commands still print extra non-JSON to stdout.Validation
pnpm test(full suite) green on Windows after these changes.Release notes