Skip to content

Commit 070433c

Browse files
committed
fix(watcher): allow debounce 0 and harden test
1 parent 2d78110 commit 070433c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ async function main() {
747747
if (process.env.CODEBASE_CONTEXT_DEBUG) console.error('[DEBUG] Server ready');
748748

749749
// Auto-refresh: watch for file changes and trigger incremental reindex
750-
const debounceMs = parseInt(process.env.CODEBASE_CONTEXT_DEBOUNCE_MS ?? '', 10) || 2000;
750+
const debounceEnv = Number.parseInt(process.env.CODEBASE_CONTEXT_DEBOUNCE_MS ?? '', 10);
751+
const debounceMs = Number.isFinite(debounceEnv) && debounceEnv >= 0 ? debounceEnv : 2000;
751752
const stopWatcher = startFileWatcher({
752753
rootPath: ROOT_PATH,
753754
debounceMs,

tests/file-watcher.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ describe('FileWatcher', () => {
7777
// Give chokidar a moment to finish initializing before the first write
7878
await new Promise((resolve) => setTimeout(resolve, 100));
7979
await fs.writeFile(path.join(tempDir, 'cancel.ts'), 'export const y = 99;');
80-
// Let chokidar detect the event but stop before debounce fires
81-
await new Promise((resolve) => setTimeout(resolve, 150));
80+
// Let chokidar detect the event (including awaitWriteFinish stabilityThreshold)
81+
// but stop before the debounce window expires.
82+
await new Promise((resolve) => setTimeout(resolve, 350));
8283
stop();
8384
// Wait past where debounce would have fired
8485
await new Promise((resolve) => setTimeout(resolve, debounceMs + 200));

0 commit comments

Comments
 (0)