diff options
| author | Adam Malczewski <[email protected]> | 2026-06-04 16:16:45 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-04 16:16:45 +0900 |
| commit | 81a9cdbadf8c9d940d4fe9a2a0de607dee1f5f1a (patch) | |
| tree | dff8ce0e55f27b490445ddaf9fb6536d1313ffcf /packages/core/tests | |
| parent | 24bdaa6ca0333b91369ac50b23e929f83af01c3a (diff) | |
| download | dispatch-v2-deprecated.tar.gz dispatch-v2-deprecated.zip | |
feat(config): add subdirectory LSP config watchers and fix permission orderingv2-deprecated
- Add watchDirConfig() for per-directory config watching
- Register watchers for subdirectories with their own dispatch.toml
- Fix permission ordering: move "*" wildcard to front so findLast
reaches specific rules first (was silently breaking all specific
bash permission rules)
- Add comprehensive tests for watcher functionality
- Update mocks in test files
Diffstat (limited to 'packages/core/tests')
| -rw-r--r-- | packages/core/tests/config/watcher.test.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/core/tests/config/watcher.test.ts b/packages/core/tests/config/watcher.test.ts new file mode 100644 index 0000000..9388c8a --- /dev/null +++ b/packages/core/tests/config/watcher.test.ts @@ -0,0 +1,50 @@ +import { mkdirSync, rmSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { watchDirConfig } from "../../src/config/watcher.js"; + +const TMP = join("/tmp/opencode", "dispatch-watchdir-test"); + +beforeEach(() => { + mkdirSync(TMP, { recursive: true }); +}); + +afterEach(() => { + rmSync(TMP, { recursive: true, force: true }); +}); + +function wait(ms: number): Promise<void> { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +describe("watchDirConfig", () => { + it("fires onChange (debounced) when <dir>/dispatch.toml changes", async () => { + let calls = 0; + const handle = watchDirConfig(TMP, () => { + calls++; + }); + // Let chokidar finish its initial scan before mutating the file. + await wait(200); + + writeFileSync(join(TMP, "dispatch.toml"), `[permissions]\nread = "allow"\n`, "utf-8"); + // 300ms debounce + chokidar latency. + await wait(700); + + handle.close(); + expect(calls).toBeGreaterThanOrEqual(1); + }); + + it("does not fire after close()", async () => { + let calls = 0; + const handle = watchDirConfig(TMP, () => { + calls++; + }); + await wait(200); + handle.close(); + + writeFileSync(join(TMP, "dispatch.toml"), `[permissions]\nedit = "deny"\n`, "utf-8"); + await wait(700); + + expect(calls).toBe(0); + }); +}); |
