@indigoai-us/hq-cloud 5.24.0 → 5.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/sync-runner.d.ts +151 -17
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +280 -18
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +429 -15
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts +9 -0
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +54 -1
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +6 -3
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +21 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/personal-vault-exclusions.d.ts +128 -0
- package/dist/personal-vault-exclusions.d.ts.map +1 -0
- package/dist/personal-vault-exclusions.js +231 -0
- package/dist/personal-vault-exclusions.js.map +1 -0
- package/dist/personal-vault-exclusions.test.d.ts +22 -0
- package/dist/personal-vault-exclusions.test.d.ts.map +1 -0
- package/dist/personal-vault-exclusions.test.js +198 -0
- package/dist/personal-vault-exclusions.test.js.map +1 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +9 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/push-event.d.ts +110 -0
- package/dist/sync/push-event.d.ts.map +1 -0
- package/dist/sync/push-event.js +153 -0
- package/dist/sync/push-event.js.map +1 -0
- package/dist/sync/push-event.test.d.ts +15 -0
- package/dist/sync/push-event.test.d.ts.map +1 -0
- package/dist/sync/push-event.test.js +188 -0
- package/dist/sync/push-event.test.js.map +1 -0
- package/dist/sync/push-transport.d.ts +67 -0
- package/dist/sync/push-transport.d.ts.map +1 -0
- package/dist/sync/push-transport.js +66 -0
- package/dist/sync/push-transport.js.map +1 -0
- package/dist/watcher.d.ts +160 -0
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +298 -0
- package/dist/watcher.js.map +1 -1
- package/dist/watcher.test.d.ts +2 -0
- package/dist/watcher.test.d.ts.map +1 -0
- package/dist/watcher.test.js +334 -0
- package/dist/watcher.test.js.map +1 -0
- package/package.json +3 -2
- package/src/bin/sync-runner.test.ts +557 -15
- package/src/bin/sync-runner.ts +404 -27
- package/src/cli/share.test.ts +8 -3
- package/src/cli/share.ts +66 -1
- package/src/cli/sync.ts +22 -0
- package/src/index.ts +27 -0
- package/src/personal-vault-exclusions.test.ts +256 -0
- package/src/personal-vault-exclusions.ts +277 -0
- package/src/sync/index.ts +19 -0
- package/src/sync/push-event.test.ts +224 -0
- package/src/sync/push-event.ts +208 -0
- package/src/sync/push-transport.ts +84 -0
- package/src/watcher.test.ts +388 -0
- package/src/watcher.ts +386 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, it, expect, vi } from "vitest";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as os from "os";
|
|
4
|
+
import * as path from "path";
|
|
5
|
+
import {
|
|
6
|
+
FakeClock,
|
|
7
|
+
WatchPushDriver,
|
|
8
|
+
TreeWatcher,
|
|
9
|
+
createWatchPathFilter,
|
|
10
|
+
} from "./watcher.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* US-001 — Phase 1 test harness: watch-triggered push seam + latency assertion.
|
|
14
|
+
*
|
|
15
|
+
* These tests drive the debounce/coalesce core ({@link WatchPushDriver}) with an
|
|
16
|
+
* injected {@link FakeClock} and an injected spy push fn — no real chokidar
|
|
17
|
+
* watcher, no real S3, no real 10-minute sleep. US-002/US-003 build the real
|
|
18
|
+
* watcher + targeted-push fn on top of this same seam, so the tests here also
|
|
19
|
+
* serve as regression guards for the contract those stories depend on.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const DEBOUNCE = 2000;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build a driver wired to a FakeClock and a spy push fn. Returns everything a
|
|
26
|
+
* test needs to drive and assert against the seam. This helper is the reusable
|
|
27
|
+
* "test harness" the story asks for.
|
|
28
|
+
*/
|
|
29
|
+
function makeHarness(opts?: { debounceMs?: number }) {
|
|
30
|
+
const clock = new FakeClock();
|
|
31
|
+
const push = vi.fn(() => {});
|
|
32
|
+
const driver = new WatchPushDriver({
|
|
33
|
+
debounceMs: opts?.debounceMs ?? DEBOUNCE,
|
|
34
|
+
clock,
|
|
35
|
+
push,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
clock,
|
|
39
|
+
push,
|
|
40
|
+
driver,
|
|
41
|
+
/** Emit a synthetic file-change event into the driver. */
|
|
42
|
+
emitChange: () => driver.notifyChange(),
|
|
43
|
+
/** Advance virtual time. */
|
|
44
|
+
advance: (ms: number) => clock.advance(ms),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe("FakeClock", () => {
|
|
49
|
+
it("fires a timer exactly when its deadline is reached", () => {
|
|
50
|
+
const clock = new FakeClock();
|
|
51
|
+
const fn = vi.fn();
|
|
52
|
+
clock.setTimeout(fn, 100);
|
|
53
|
+
clock.advance(99);
|
|
54
|
+
expect(fn).not.toHaveBeenCalled();
|
|
55
|
+
clock.advance(1);
|
|
56
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("does not fire a cleared timer", () => {
|
|
60
|
+
const clock = new FakeClock();
|
|
61
|
+
const fn = vi.fn();
|
|
62
|
+
const handle = clock.setTimeout(fn, 100);
|
|
63
|
+
clock.clearTimeout(handle);
|
|
64
|
+
clock.advance(1000);
|
|
65
|
+
expect(fn).not.toHaveBeenCalled();
|
|
66
|
+
expect(clock.pendingTimerCount()).toBe(0);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("reports pending timer count for leak checks", () => {
|
|
70
|
+
const clock = new FakeClock();
|
|
71
|
+
clock.setTimeout(() => {}, 100);
|
|
72
|
+
clock.setTimeout(() => {}, 200);
|
|
73
|
+
expect(clock.pendingTimerCount()).toBe(2);
|
|
74
|
+
clock.advance(100);
|
|
75
|
+
expect(clock.pendingTimerCount()).toBe(1);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("US-001: WatchPushDriver — debounced push seam", () => {
|
|
80
|
+
it("calls the injected push fn exactly once within debounce+grace after a synthetic change", async () => {
|
|
81
|
+
const h = makeHarness();
|
|
82
|
+
|
|
83
|
+
h.emitChange();
|
|
84
|
+
// Before the window elapses, no push.
|
|
85
|
+
h.advance(DEBOUNCE - 1);
|
|
86
|
+
expect(h.push).not.toHaveBeenCalled();
|
|
87
|
+
|
|
88
|
+
// Crossing the debounce boundary fires the push exactly once.
|
|
89
|
+
h.advance(1);
|
|
90
|
+
await Promise.resolve();
|
|
91
|
+
expect(h.push).toHaveBeenCalledTimes(1);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("coalesces N rapid changes within the window to exactly 1 push", async () => {
|
|
95
|
+
const h = makeHarness();
|
|
96
|
+
|
|
97
|
+
// 5 synthetic changes spread across less than one debounce window.
|
|
98
|
+
for (let i = 0; i < 5; i++) {
|
|
99
|
+
h.emitChange();
|
|
100
|
+
h.advance(100); // total 500ms << 2000ms debounce
|
|
101
|
+
}
|
|
102
|
+
// Window has not fully elapsed since the LAST change yet.
|
|
103
|
+
expect(h.push).not.toHaveBeenCalled();
|
|
104
|
+
|
|
105
|
+
// Let the quiet window after the final change elapse.
|
|
106
|
+
h.advance(DEBOUNCE);
|
|
107
|
+
await Promise.resolve();
|
|
108
|
+
expect(h.push).toHaveBeenCalledTimes(1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("treats two separate bursts as two pushes", async () => {
|
|
112
|
+
const h = makeHarness();
|
|
113
|
+
|
|
114
|
+
h.emitChange();
|
|
115
|
+
h.advance(DEBOUNCE);
|
|
116
|
+
await Promise.resolve();
|
|
117
|
+
expect(h.push).toHaveBeenCalledTimes(1);
|
|
118
|
+
|
|
119
|
+
h.emitChange();
|
|
120
|
+
h.advance(DEBOUNCE);
|
|
121
|
+
await Promise.resolve();
|
|
122
|
+
expect(h.push).toHaveBeenCalledTimes(2);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("never overlaps an in-flight push; a mid-push change re-triggers one follow-up pass", async () => {
|
|
126
|
+
const clock = new FakeClock();
|
|
127
|
+
let release!: () => void;
|
|
128
|
+
const inFlight = new Promise<void>((r) => {
|
|
129
|
+
release = r;
|
|
130
|
+
});
|
|
131
|
+
let calls = 0;
|
|
132
|
+
const push = vi.fn(() => {
|
|
133
|
+
calls += 1;
|
|
134
|
+
// First push hangs until released; later pushes resolve immediately.
|
|
135
|
+
return calls === 1 ? inFlight : Promise.resolve();
|
|
136
|
+
});
|
|
137
|
+
const driver = new WatchPushDriver({ debounceMs: DEBOUNCE, clock, push });
|
|
138
|
+
|
|
139
|
+
// First burst -> first push starts and hangs.
|
|
140
|
+
driver.notifyChange();
|
|
141
|
+
clock.advance(DEBOUNCE);
|
|
142
|
+
await Promise.resolve();
|
|
143
|
+
expect(push).toHaveBeenCalledTimes(1);
|
|
144
|
+
expect(driver.isPushing()).toBe(true);
|
|
145
|
+
|
|
146
|
+
// A change arrives while the first push is in flight: must NOT start a
|
|
147
|
+
// concurrent push.
|
|
148
|
+
driver.notifyChange();
|
|
149
|
+
clock.advance(DEBOUNCE);
|
|
150
|
+
await Promise.resolve();
|
|
151
|
+
expect(push).toHaveBeenCalledTimes(1);
|
|
152
|
+
|
|
153
|
+
// Release the first push; the collapsed mid-push change re-arms.
|
|
154
|
+
release();
|
|
155
|
+
await inFlight;
|
|
156
|
+
await Promise.resolve();
|
|
157
|
+
// Re-armed window must elapse before the follow-up push fires.
|
|
158
|
+
clock.advance(DEBOUNCE);
|
|
159
|
+
await Promise.resolve();
|
|
160
|
+
expect(push).toHaveBeenCalledTimes(2);
|
|
161
|
+
|
|
162
|
+
driver.dispose();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("respects a custom debounce window", async () => {
|
|
166
|
+
const h = makeHarness({ debounceMs: 500 });
|
|
167
|
+
h.emitChange();
|
|
168
|
+
h.advance(499);
|
|
169
|
+
expect(h.push).not.toHaveBeenCalled();
|
|
170
|
+
h.advance(1);
|
|
171
|
+
await Promise.resolve();
|
|
172
|
+
expect(h.push).toHaveBeenCalledTimes(1);
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
describe("US-001: WatchPushDriver — teardown leaves no leaked timers", () => {
|
|
177
|
+
it("dispose() cancels a pending debounce timer", () => {
|
|
178
|
+
const h = makeHarness();
|
|
179
|
+
h.emitChange();
|
|
180
|
+
expect(h.clock.pendingTimerCount()).toBe(1);
|
|
181
|
+
|
|
182
|
+
h.driver.dispose();
|
|
183
|
+
expect(h.clock.pendingTimerCount()).toBe(0);
|
|
184
|
+
|
|
185
|
+
// A push must not fire after dispose, even if time advances.
|
|
186
|
+
h.advance(DEBOUNCE * 10);
|
|
187
|
+
expect(h.push).not.toHaveBeenCalled();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("notifyChange() after dispose is a no-op and schedules nothing", () => {
|
|
191
|
+
const h = makeHarness();
|
|
192
|
+
h.driver.dispose();
|
|
193
|
+
h.emitChange();
|
|
194
|
+
expect(h.clock.pendingTimerCount()).toBe(0);
|
|
195
|
+
h.advance(DEBOUNCE * 10);
|
|
196
|
+
expect(h.push).not.toHaveBeenCalled();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("dispose() is idempotent", () => {
|
|
200
|
+
const h = makeHarness();
|
|
201
|
+
h.emitChange();
|
|
202
|
+
h.driver.dispose();
|
|
203
|
+
h.driver.dispose();
|
|
204
|
+
expect(h.clock.pendingTimerCount()).toBe(0);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("a fully drained burst leaves zero pending timers", async () => {
|
|
208
|
+
const h = makeHarness();
|
|
209
|
+
for (let i = 0; i < 5; i++) h.emitChange();
|
|
210
|
+
h.advance(DEBOUNCE);
|
|
211
|
+
await Promise.resolve();
|
|
212
|
+
expect(h.push).toHaveBeenCalledTimes(1);
|
|
213
|
+
expect(h.clock.pendingTimerCount()).toBe(0);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* US-002 — file-watcher module (debounced, ignore-aware, exclusion-aware).
|
|
219
|
+
*
|
|
220
|
+
* `createWatchPathFilter` is pure (no chokidar) so the exclusion logic is
|
|
221
|
+
* tested directly against absolute paths. `TreeWatcher` is then exercised via
|
|
222
|
+
* its `handleEvent` seam + FakeClock so debounce/coalesce/lifecycle assert
|
|
223
|
+
* deterministically without spinning a real chokidar instance.
|
|
224
|
+
*/
|
|
225
|
+
|
|
226
|
+
const ROOT = "/tmp/hq-root";
|
|
227
|
+
|
|
228
|
+
describe("US-002: createWatchPathFilter — ignore-list matching", () => {
|
|
229
|
+
const filter = createWatchPathFilter(ROOT, false);
|
|
230
|
+
|
|
231
|
+
it("emits for an ordinary tracked file", () => {
|
|
232
|
+
expect(filter(path.join(ROOT, "personal/notes.md"))).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("does NOT emit for a .env file (DEFAULT_IGNORES secret)", () => {
|
|
236
|
+
expect(filter(path.join(ROOT, ".env"))).toBe(false);
|
|
237
|
+
expect(filter(path.join(ROOT, "personal/.env.local"))).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("does NOT emit for node_modules / dist build artifacts", () => {
|
|
241
|
+
expect(filter(path.join(ROOT, "node_modules/foo/index.js"))).toBe(false);
|
|
242
|
+
expect(filter(path.join(ROOT, "dist/bundle.js"))).toBe(false);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("does NOT emit for the watched root itself or paths outside it", () => {
|
|
246
|
+
expect(filter(ROOT)).toBe(false);
|
|
247
|
+
expect(filter("/some/other/place/file.txt")).toBe(false);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe("US-002: createWatchPathFilter — personal-vault exclusions", () => {
|
|
252
|
+
const personal = createWatchPathFilter(ROOT, true);
|
|
253
|
+
const nonPersonal = createWatchPathFilter(ROOT, false);
|
|
254
|
+
|
|
255
|
+
it("does NOT emit for PERSONAL_VAULT_DEFAULT_EXCLUSIONS in personalMode (output/, .beads/)", () => {
|
|
256
|
+
expect(personal(path.join(ROOT, "personal/output/x.txt"))).toBe(false);
|
|
257
|
+
expect(personal(path.join(ROOT, "personal/.beads/issues.db"))).toBe(false);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("does NOT emit for PERSONAL_VAULT_EXCLUDED_TOP_LEVEL in personalMode (.git/companies/repos/workspace)", () => {
|
|
261
|
+
expect(personal(path.join(ROOT, "companies/indigo/board.json"))).toBe(false);
|
|
262
|
+
expect(personal(path.join(ROOT, "workspace/threads/x.json"))).toBe(false);
|
|
263
|
+
expect(personal(path.join(ROOT, "repos/private/foo/file.ts"))).toBe(false);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("DOES emit for an included top-level personal path in personalMode", () => {
|
|
267
|
+
expect(personal(path.join(ROOT, "personal/notes.md"))).toBe(true);
|
|
268
|
+
expect(personal(path.join(ROOT, "core/policies/x.md"))).toBe(true);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("non-personal mode does NOT apply the excluded-top-level buckets", () => {
|
|
272
|
+
// companies/ is only excluded by the personal-vault layer; in non-personal
|
|
273
|
+
// mode the ignore stack alone governs and lets it through.
|
|
274
|
+
expect(nonPersonal(path.join(ROOT, "companies/indigo/board.json"))).toBe(true);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe("US-002: TreeWatcher — debounce coalesce (FakeClock seam)", () => {
|
|
279
|
+
function makeWatcher(opts?: { debounceMs?: number; personalMode?: boolean }) {
|
|
280
|
+
const clock = new FakeClock();
|
|
281
|
+
const changed = vi.fn();
|
|
282
|
+
const watcher = new TreeWatcher({
|
|
283
|
+
hqRoot: ROOT,
|
|
284
|
+
debounceMs: opts?.debounceMs ?? DEBOUNCE,
|
|
285
|
+
personalMode: opts?.personalMode ?? false,
|
|
286
|
+
clock,
|
|
287
|
+
});
|
|
288
|
+
watcher.onChange(changed);
|
|
289
|
+
return { clock, changed, watcher };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
it("coalesces 5 rapid changes within the window into exactly 1 changed signal", () => {
|
|
293
|
+
const { clock, changed, watcher } = makeWatcher();
|
|
294
|
+
for (let i = 0; i < 5; i++) {
|
|
295
|
+
watcher.handleEvent(path.join(ROOT, `personal/file-${i}.md`));
|
|
296
|
+
clock.advance(20); // 100ms total << 2000ms debounce
|
|
297
|
+
}
|
|
298
|
+
expect(changed).not.toHaveBeenCalled();
|
|
299
|
+
clock.advance(DEBOUNCE);
|
|
300
|
+
expect(changed).toHaveBeenCalledTimes(1);
|
|
301
|
+
expect(watcher.pendingTimerCount()).toBe(0);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("fires once after the quiet window for a single change", () => {
|
|
305
|
+
const { clock, changed, watcher } = makeWatcher();
|
|
306
|
+
watcher.handleEvent(path.join(ROOT, "personal/a.md"));
|
|
307
|
+
clock.advance(DEBOUNCE - 1);
|
|
308
|
+
expect(changed).not.toHaveBeenCalled();
|
|
309
|
+
clock.advance(1);
|
|
310
|
+
expect(changed).toHaveBeenCalledTimes(1);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("does NOT emit for an ignored / excluded path", () => {
|
|
314
|
+
const { clock, changed, watcher } = makeWatcher({ personalMode: true });
|
|
315
|
+
watcher.handleEvent(path.join(ROOT, ".env"));
|
|
316
|
+
watcher.handleEvent(path.join(ROOT, "personal/output/big.bin"));
|
|
317
|
+
watcher.handleEvent(path.join(ROOT, "companies/indigo/board.json"));
|
|
318
|
+
clock.advance(DEBOUNCE * 2);
|
|
319
|
+
expect(changed).not.toHaveBeenCalled();
|
|
320
|
+
expect(watcher.pendingTimerCount()).toBe(0);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("treats two separate bursts as two changed signals", () => {
|
|
324
|
+
const { clock, changed, watcher } = makeWatcher();
|
|
325
|
+
watcher.handleEvent(path.join(ROOT, "personal/a.md"));
|
|
326
|
+
clock.advance(DEBOUNCE);
|
|
327
|
+
expect(changed).toHaveBeenCalledTimes(1);
|
|
328
|
+
watcher.handleEvent(path.join(ROOT, "personal/b.md"));
|
|
329
|
+
clock.advance(DEBOUNCE);
|
|
330
|
+
expect(changed).toHaveBeenCalledTimes(2);
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe("US-002: TreeWatcher — lifecycle (real chokidar over a temp dir)", () => {
|
|
335
|
+
let dir: string;
|
|
336
|
+
|
|
337
|
+
beforeEach(() => {
|
|
338
|
+
// realpathSync resolves macOS's /var -> /private/var symlink so chokidar's
|
|
339
|
+
// canonicalized event paths stay inside hqRoot (path.relative would
|
|
340
|
+
// otherwise yield a `..`-prefixed path and the filter would reject them).
|
|
341
|
+
dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "treewatcher-")));
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
afterEach(() => {
|
|
345
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("start() is idempotent — a second start does not open a second watcher", () => {
|
|
349
|
+
const w = new TreeWatcher({ hqRoot: dir });
|
|
350
|
+
w.start();
|
|
351
|
+
expect(w.isWatching()).toBe(true);
|
|
352
|
+
w.start(); // no throw, no second instance
|
|
353
|
+
expect(w.isWatching()).toBe(true);
|
|
354
|
+
w.stop();
|
|
355
|
+
expect(w.isWatching()).toBe(false);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("stop() closes the watcher and clears pending timers; dispose() is permanent", () => {
|
|
359
|
+
const clock = new FakeClock();
|
|
360
|
+
const w = new TreeWatcher({ hqRoot: dir, clock });
|
|
361
|
+
w.start();
|
|
362
|
+
w.handleEvent(path.join(dir, "x.md"));
|
|
363
|
+
expect(w.pendingTimerCount()).toBe(1);
|
|
364
|
+
w.stop();
|
|
365
|
+
expect(w.pendingTimerCount()).toBe(0);
|
|
366
|
+
expect(w.isWatching()).toBe(false);
|
|
367
|
+
|
|
368
|
+
// After dispose, events are inert and start is a no-op.
|
|
369
|
+
w.dispose();
|
|
370
|
+
w.handleEvent(path.join(dir, "y.md"));
|
|
371
|
+
expect(w.pendingTimerCount()).toBe(0);
|
|
372
|
+
w.start();
|
|
373
|
+
expect(w.isWatching()).toBe(false);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("emits a debounced changed signal for a real file write", async () => {
|
|
377
|
+
const w = new TreeWatcher({ hqRoot: dir, debounceMs: 50 });
|
|
378
|
+
const changed = vi.fn();
|
|
379
|
+
w.onChange(changed);
|
|
380
|
+
w.start();
|
|
381
|
+
// Give chokidar a beat to set up its watch before writing.
|
|
382
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
383
|
+
fs.writeFileSync(path.join(dir, "hello.md"), "hi");
|
|
384
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
385
|
+
expect(changed).toHaveBeenCalled();
|
|
386
|
+
w.dispose();
|
|
387
|
+
}, 10_000);
|
|
388
|
+
});
|