@indigoai-us/hq-cloud 6.14.44 → 6.14.45
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/watch-roots.d.ts +72 -0
- package/dist/watch-roots.d.ts.map +1 -0
- package/dist/watch-roots.js +115 -0
- package/dist/watch-roots.js.map +1 -0
- package/dist/watch-roots.test.d.ts +18 -0
- package/dist/watch-roots.test.d.ts.map +1 -0
- package/dist/watch-roots.test.js +236 -0
- package/dist/watch-roots.test.js.map +1 -0
- package/dist/watcher-event-gate.test.d.ts +16 -0
- package/dist/watcher-event-gate.test.d.ts.map +1 -0
- package/dist/watcher-event-gate.test.js +191 -0
- package/dist/watcher-event-gate.test.js.map +1 -0
- package/dist/watcher.d.ts +21 -0
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +312 -54
- package/dist/watcher.js.map +1 -1
- package/package.json +1 -1
- package/src/watch-roots.test.ts +278 -0
- package/src/watch-roots.ts +162 -0
- package/src/watcher-event-gate.test.ts +212 -0
- package/src/watcher.ts +363 -65
- package/test/e2e/watcher-scoped-coverage.test.ts +381 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch-root planner — reduce the in-scope tree to the smallest set of OS
|
|
3
|
+
* watches that covers exactly the paths that can upload.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: on macOS/Windows the watcher used to place ONE recursive
|
|
6
|
+
* `fs.watch` on hqRoot. That is cheap in handles but the OS then delivers every
|
|
7
|
+
* event in the tree, including the buckets sync never uploads — on a real HQ
|
|
8
|
+
* root that is `repos/` (~26k directories) and `workspace/worktrees/` (~62k),
|
|
9
|
+
* where agent builds, installs, and checkouts churn constantly. Every one of
|
|
10
|
+
* those events woke the runner, cost a `path.resolve` (plus a synchronous
|
|
11
|
+
* `lstat` for renames), and was then dropped by the emit filter. The result was
|
|
12
|
+
* a node process pinned above 100% CPU doing nothing but allocating and
|
|
13
|
+
* garbage-collecting discarded paths.
|
|
14
|
+
*
|
|
15
|
+
* The planner walks the exclusion filter ONCE at start and returns:
|
|
16
|
+
* - `recursive`: directories whose entire subtree is in scope. One recursive
|
|
17
|
+
* watch each; the OS never reports an excluded path under them.
|
|
18
|
+
* - `shallow`: directories that contain an excluded descendant. Watched
|
|
19
|
+
* non-recursively so their own files still fire, with their in-scope
|
|
20
|
+
* children planned separately.
|
|
21
|
+
*
|
|
22
|
+
* The walk is post-order: whether a directory can collapse to a single
|
|
23
|
+
* recursive watch depends on its whole subtree, not just its direct children
|
|
24
|
+
* (`workspace/` looks clean until you reach `workspace/worktrees/`).
|
|
25
|
+
*/
|
|
26
|
+
import type { WatchPathFilter } from "./watcher.js";
|
|
27
|
+
export interface WatchRootPlan {
|
|
28
|
+
/** Directories to watch recursively — their whole subtree is in scope. */
|
|
29
|
+
recursive: string[];
|
|
30
|
+
/** Directories to watch non-recursively — they contain excluded children. */
|
|
31
|
+
shallow: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface PlanWatchRootsOptions {
|
|
34
|
+
/**
|
|
35
|
+
* Optional depth at which the walk stops splitting and takes a recursive
|
|
36
|
+
* watch even if the subtree still holds exclusions. Unbounded by default:
|
|
37
|
+
* the walk costs about what {@link TreeWatcher}'s known-kinds seed walk
|
|
38
|
+
* already cost on every start, and the two are fused via `onDirectory`, so
|
|
39
|
+
* paying for full pruning is free. A bound trades pruning for walk time on
|
|
40
|
+
* pathologically deep trees; the per-event filter drops whatever residue it
|
|
41
|
+
* admits, so this is a performance dial, never a correctness one.
|
|
42
|
+
*/
|
|
43
|
+
maxDepth?: number;
|
|
44
|
+
/** Directory reader seam — defaults to a real `readdirSync`. */
|
|
45
|
+
listChildDirs?: (dir: string) => string[];
|
|
46
|
+
/**
|
|
47
|
+
* Invoked once for every in-scope directory the walk visits. Lets a caller
|
|
48
|
+
* populate its own directory index in the SAME pass instead of walking the
|
|
49
|
+
* tree a second time.
|
|
50
|
+
*/
|
|
51
|
+
onDirectory?: (absolutePath: string) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Plan the watch roots for `hqRoot` under `shouldEmit`.
|
|
55
|
+
*
|
|
56
|
+
* `shouldEmit(dir, true)` is the same directory predicate the watcher uses at
|
|
57
|
+
* event time, so the plan and the emit filter can never disagree about what is
|
|
58
|
+
* in scope.
|
|
59
|
+
*/
|
|
60
|
+
export declare function planWatchRoots(hqRoot: string, shouldEmit: WatchPathFilter, opts?: PlanWatchRootsOptions): WatchRootPlan;
|
|
61
|
+
/**
|
|
62
|
+
* True when `absolutePath` already falls under one of `recursiveRoots`.
|
|
63
|
+
*
|
|
64
|
+
* Walks the path's own ancestors rather than scanning the root set: this runs
|
|
65
|
+
* on every rename event, in the hot path of a backend whose entire purpose is
|
|
66
|
+
* cutting per-event cost, and a real HQ tree plans ~685 roots. Ancestor-walking
|
|
67
|
+
* is O(path depth) — about ten set lookups — instead of O(roots) string
|
|
68
|
+
* comparisons. It also cannot fall into the shared-prefix trap, where `/hq/a/bc`
|
|
69
|
+
* looks like it sits under the root `/hq/a/b`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isCoveredByRecursiveRoot(absolutePath: string, recursiveRoots: ReadonlySet<string>): boolean;
|
|
72
|
+
//# sourceMappingURL=watch-roots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-roots.d.ts","sourceRoot":"","sources":["../src/watch-roots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,MAAM,WAAW,aAAa;IAC5B,0EAA0E;IAC1E,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,6EAA6E;IAC7E,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAC1C;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C;AAeD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,eAAe,EAC3B,IAAI,GAAE,qBAA0B,GAC/B,aAAa,CAsDf;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,GAClC,OAAO,CAST"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch-root planner — reduce the in-scope tree to the smallest set of OS
|
|
3
|
+
* watches that covers exactly the paths that can upload.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: on macOS/Windows the watcher used to place ONE recursive
|
|
6
|
+
* `fs.watch` on hqRoot. That is cheap in handles but the OS then delivers every
|
|
7
|
+
* event in the tree, including the buckets sync never uploads — on a real HQ
|
|
8
|
+
* root that is `repos/` (~26k directories) and `workspace/worktrees/` (~62k),
|
|
9
|
+
* where agent builds, installs, and checkouts churn constantly. Every one of
|
|
10
|
+
* those events woke the runner, cost a `path.resolve` (plus a synchronous
|
|
11
|
+
* `lstat` for renames), and was then dropped by the emit filter. The result was
|
|
12
|
+
* a node process pinned above 100% CPU doing nothing but allocating and
|
|
13
|
+
* garbage-collecting discarded paths.
|
|
14
|
+
*
|
|
15
|
+
* The planner walks the exclusion filter ONCE at start and returns:
|
|
16
|
+
* - `recursive`: directories whose entire subtree is in scope. One recursive
|
|
17
|
+
* watch each; the OS never reports an excluded path under them.
|
|
18
|
+
* - `shallow`: directories that contain an excluded descendant. Watched
|
|
19
|
+
* non-recursively so their own files still fire, with their in-scope
|
|
20
|
+
* children planned separately.
|
|
21
|
+
*
|
|
22
|
+
* The walk is post-order: whether a directory can collapse to a single
|
|
23
|
+
* recursive watch depends on its whole subtree, not just its direct children
|
|
24
|
+
* (`workspace/` looks clean until you reach `workspace/worktrees/`).
|
|
25
|
+
*/
|
|
26
|
+
import * as fs from "fs";
|
|
27
|
+
import * as path from "path";
|
|
28
|
+
function defaultListChildDirs(dir) {
|
|
29
|
+
return fs
|
|
30
|
+
.readdirSync(dir, { withFileTypes: true })
|
|
31
|
+
.filter((entry) => entry.isDirectory())
|
|
32
|
+
.map((entry) => path.join(dir, entry.name));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Plan the watch roots for `hqRoot` under `shouldEmit`.
|
|
36
|
+
*
|
|
37
|
+
* `shouldEmit(dir, true)` is the same directory predicate the watcher uses at
|
|
38
|
+
* event time, so the plan and the emit filter can never disagree about what is
|
|
39
|
+
* in scope.
|
|
40
|
+
*/
|
|
41
|
+
export function planWatchRoots(hqRoot, shouldEmit, opts = {}) {
|
|
42
|
+
const maxDepth = opts.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
43
|
+
const listChildDirs = opts.listChildDirs ?? defaultListChildDirs;
|
|
44
|
+
const onDirectory = opts.onDirectory;
|
|
45
|
+
const root = path.resolve(hqRoot);
|
|
46
|
+
const visit = (dir, depth) => {
|
|
47
|
+
let children;
|
|
48
|
+
try {
|
|
49
|
+
children = listChildDirs(dir);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Unreadable (permissions, or a race with a concurrent delete). We cannot
|
|
53
|
+
// prove the subtree is clean, but dropping it would silently stop syncing
|
|
54
|
+
// it — take the recursive watch and let the per-event filter sort it out.
|
|
55
|
+
return { clean: true, plan: { recursive: [dir], shallow: [] } };
|
|
56
|
+
}
|
|
57
|
+
const included = [];
|
|
58
|
+
let hasExcludedChild = false;
|
|
59
|
+
for (const child of children) {
|
|
60
|
+
if (shouldEmit(child, true)) {
|
|
61
|
+
included.push(child);
|
|
62
|
+
onDirectory?.(path.resolve(child));
|
|
63
|
+
}
|
|
64
|
+
else
|
|
65
|
+
hasExcludedChild = true;
|
|
66
|
+
}
|
|
67
|
+
// At the depth bound we stop splitting. `clean` still reports what we can
|
|
68
|
+
// see one level down so an ancestor does not collapse over a known
|
|
69
|
+
// exclusion it could have pruned.
|
|
70
|
+
if (depth >= maxDepth) {
|
|
71
|
+
return {
|
|
72
|
+
clean: !hasExcludedChild,
|
|
73
|
+
plan: { recursive: [dir], shallow: [] },
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const childResults = included.map((child) => visit(child, depth + 1));
|
|
77
|
+
const clean = !hasExcludedChild && childResults.every((result) => result.clean);
|
|
78
|
+
// A clean subtree collapses to a single recursive watch here, discarding
|
|
79
|
+
// the per-child watches the recursion built below it.
|
|
80
|
+
if (clean)
|
|
81
|
+
return { clean: true, plan: { recursive: [dir], shallow: [] } };
|
|
82
|
+
return {
|
|
83
|
+
clean: false,
|
|
84
|
+
plan: {
|
|
85
|
+
recursive: childResults.flatMap((result) => result.plan.recursive),
|
|
86
|
+
shallow: [dir, ...childResults.flatMap((result) => result.plan.shallow)],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
return visit(root, 0).plan;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* True when `absolutePath` already falls under one of `recursiveRoots`.
|
|
94
|
+
*
|
|
95
|
+
* Walks the path's own ancestors rather than scanning the root set: this runs
|
|
96
|
+
* on every rename event, in the hot path of a backend whose entire purpose is
|
|
97
|
+
* cutting per-event cost, and a real HQ tree plans ~685 roots. Ancestor-walking
|
|
98
|
+
* is O(path depth) — about ten set lookups — instead of O(roots) string
|
|
99
|
+
* comparisons. It also cannot fall into the shared-prefix trap, where `/hq/a/bc`
|
|
100
|
+
* looks like it sits under the root `/hq/a/b`.
|
|
101
|
+
*/
|
|
102
|
+
export function isCoveredByRecursiveRoot(absolutePath, recursiveRoots) {
|
|
103
|
+
if (recursiveRoots.size === 0)
|
|
104
|
+
return false;
|
|
105
|
+
let current = path.resolve(absolutePath);
|
|
106
|
+
for (;;) {
|
|
107
|
+
if (recursiveRoots.has(current))
|
|
108
|
+
return true;
|
|
109
|
+
const parent = path.dirname(current);
|
|
110
|
+
if (parent === current)
|
|
111
|
+
return false;
|
|
112
|
+
current = parent;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=watch-roots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-roots.js","sourceRoot":"","sources":["../src/watch-roots.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAgC7B,SAAS,oBAAoB,CAAC,GAAW;IACvC,OAAO,EAAE;SACN,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SACzC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;SACtC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAQD;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,UAA2B,EAC3B,OAA8B,EAAE;IAEhC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,iBAAiB,CAAC;IAC3D,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,oBAAoB,CAAC;IACjE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAElC,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,KAAa,EAAe,EAAE;QACxD,IAAI,QAAkB,CAAC;QACvB,IA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E,IAAI,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC;QAE3E,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,IAAI,EAAE;gBACJ,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;gBAClE,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACzE;SACF,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CACtC,YAAoB,EACpB,cAAmC;IAEnC,IAAI,cAAc,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACzC,SAAS,CAAC;QACR,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE,OAAO,IAAI,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;QACrC,OAAO,GAAG,MAAM,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the watch-root planner.
|
|
3
|
+
*
|
|
4
|
+
* The invariant under test is the one the whole change exists for: the watcher
|
|
5
|
+
* must only register OS watches over paths that can actually upload. Before
|
|
6
|
+
* this planner, macOS/Windows placed ONE recursive `fs.watch` on hqRoot, so the
|
|
7
|
+
* OS delivered every event in the tree — including `repos/` (~26k dirs on a
|
|
8
|
+
* real HQ) and `workspace/worktrees/` (~62k dirs) — and each one was filtered
|
|
9
|
+
* out only AFTER it had already cost a syscall and an allocation.
|
|
10
|
+
*
|
|
11
|
+
* The planner walks the exclusion filter up front and returns the minimum set
|
|
12
|
+
* of watch roots that covers exactly the in-scope tree:
|
|
13
|
+
* - `recursive`: the dir's entire subtree is in scope → one recursive watch.
|
|
14
|
+
* - `shallow`: the dir contains an excluded child → watch the dir itself
|
|
15
|
+
* non-recursively and descend into its in-scope children.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=watch-roots.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch-roots.test.d.ts","sourceRoot":"","sources":["../src/watch-roots.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the watch-root planner.
|
|
3
|
+
*
|
|
4
|
+
* The invariant under test is the one the whole change exists for: the watcher
|
|
5
|
+
* must only register OS watches over paths that can actually upload. Before
|
|
6
|
+
* this planner, macOS/Windows placed ONE recursive `fs.watch` on hqRoot, so the
|
|
7
|
+
* OS delivered every event in the tree — including `repos/` (~26k dirs on a
|
|
8
|
+
* real HQ) and `workspace/worktrees/` (~62k dirs) — and each one was filtered
|
|
9
|
+
* out only AFTER it had already cost a syscall and an allocation.
|
|
10
|
+
*
|
|
11
|
+
* The planner walks the exclusion filter up front and returns the minimum set
|
|
12
|
+
* of watch roots that covers exactly the in-scope tree:
|
|
13
|
+
* - `recursive`: the dir's entire subtree is in scope → one recursive watch.
|
|
14
|
+
* - `shallow`: the dir contains an excluded child → watch the dir itself
|
|
15
|
+
* non-recursively and descend into its in-scope children.
|
|
16
|
+
*/
|
|
17
|
+
import { mkdtemp, mkdir, rm } from "node:fs/promises";
|
|
18
|
+
import { tmpdir } from "node:os";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { describe, expect, it } from "vitest";
|
|
21
|
+
import { isCoveredByRecursiveRoot, planWatchRoots } from "./watch-roots.js";
|
|
22
|
+
const ROOT = path.resolve("/hq");
|
|
23
|
+
/** Build the `listChildDirs` seam over a literal `absDir -> childNames` map. */
|
|
24
|
+
function treeLister(tree) {
|
|
25
|
+
return (dir) => (tree[dir] ?? []).map((name) => path.join(dir, name));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build a filter shaped like the real one: `prefixes` are exact vault-relative
|
|
29
|
+
* prefixes (`repos`, `workspace/worktrees` — position-sensitive), `anySegment`
|
|
30
|
+
* names are excluded at any depth (`node_modules`, `.git`).
|
|
31
|
+
*/
|
|
32
|
+
function makeFilter(opts) {
|
|
33
|
+
const prefixes = opts.prefixes ?? [];
|
|
34
|
+
const anySegment = new Set(opts.anySegment ?? []);
|
|
35
|
+
return (absolutePath) => {
|
|
36
|
+
const rel = path.relative(ROOT, absolutePath).split(path.sep).join("/");
|
|
37
|
+
if (rel === "" || rel.startsWith(".."))
|
|
38
|
+
return false;
|
|
39
|
+
if (prefixes.some((p) => rel === p || rel.startsWith(p + "/")))
|
|
40
|
+
return false;
|
|
41
|
+
if (rel.split("/").some((seg) => anySegment.has(seg)))
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Every dir the plan asks the OS to watch, recursive roots and shallow alike. */
|
|
47
|
+
function allWatched(plan) {
|
|
48
|
+
return [...plan.recursive, ...plan.shallow];
|
|
49
|
+
}
|
|
50
|
+
describe("planWatchRoots — minimal cover of the in-scope tree", () => {
|
|
51
|
+
it("collapses a fully in-scope tree to ONE recursive watch at the root", () => {
|
|
52
|
+
const plan = planWatchRoots(ROOT, makeFilter({}), {
|
|
53
|
+
listChildDirs: treeLister({
|
|
54
|
+
[ROOT]: ["companies", "core"],
|
|
55
|
+
[path.join(ROOT, "companies")]: ["acme"],
|
|
56
|
+
}),
|
|
57
|
+
});
|
|
58
|
+
expect(plan.recursive).toEqual([ROOT]);
|
|
59
|
+
expect(plan.shallow).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
it("never registers a watch on an excluded dir, and never covers one from a recursive root", () => {
|
|
62
|
+
const filter = makeFilter({
|
|
63
|
+
prefixes: ["repos"],
|
|
64
|
+
anySegment: ["node_modules"],
|
|
65
|
+
});
|
|
66
|
+
const plan = planWatchRoots(ROOT, filter, {
|
|
67
|
+
listChildDirs: treeLister({
|
|
68
|
+
[ROOT]: ["companies", "repos", "node_modules"],
|
|
69
|
+
[path.join(ROOT, "companies")]: ["acme"],
|
|
70
|
+
[path.join(ROOT, "repos")]: ["hq-cloud"],
|
|
71
|
+
}),
|
|
72
|
+
});
|
|
73
|
+
// The root has excluded children, so it cannot be a recursive root.
|
|
74
|
+
expect(plan.shallow).toContain(ROOT);
|
|
75
|
+
expect(plan.recursive).not.toContain(ROOT);
|
|
76
|
+
// `companies/` is clean, so it collapses to one recursive watch.
|
|
77
|
+
expect(plan.recursive).toContain(path.join(ROOT, "companies"));
|
|
78
|
+
// The point of the whole change: excluded trees are never watched at all.
|
|
79
|
+
for (const watched of allWatched(plan)) {
|
|
80
|
+
expect(watched).not.toContain(`${path.sep}repos`);
|
|
81
|
+
expect(watched).not.toContain("node_modules");
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
it("descends through a partially-excluded dir to reach its in-scope children", () => {
|
|
85
|
+
// `workspace/` is in scope but `workspace/worktrees/` (the 62k-dir bucket)
|
|
86
|
+
// is not — so `workspace` must be shallow and its siblings recursive.
|
|
87
|
+
const filter = makeFilter({ prefixes: ["workspace/worktrees"] });
|
|
88
|
+
const plan = planWatchRoots(ROOT, filter, {
|
|
89
|
+
listChildDirs: treeLister({
|
|
90
|
+
[ROOT]: ["workspace"],
|
|
91
|
+
[path.join(ROOT, "workspace")]: ["agency", "threads", "worktrees"],
|
|
92
|
+
[path.join(ROOT, "workspace", "worktrees")]: ["feature-a"],
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
expect(plan.shallow).toEqual(expect.arrayContaining([ROOT, path.join(ROOT, "workspace")]));
|
|
96
|
+
expect(plan.recursive).toEqual(expect.arrayContaining([
|
|
97
|
+
path.join(ROOT, "workspace", "agency"),
|
|
98
|
+
path.join(ROOT, "workspace", "threads"),
|
|
99
|
+
]));
|
|
100
|
+
expect(allWatched(plan)).not.toContain(path.join(ROOT, "workspace", "worktrees"));
|
|
101
|
+
});
|
|
102
|
+
it("holds the invariant: no excluded path lies under any recursive root", () => {
|
|
103
|
+
const filter = makeFilter({
|
|
104
|
+
prefixes: ["repos", "workspace/worktrees"],
|
|
105
|
+
anySegment: ["node_modules", ".git"],
|
|
106
|
+
});
|
|
107
|
+
const tree = {
|
|
108
|
+
[ROOT]: [
|
|
109
|
+
"companies",
|
|
110
|
+
"core",
|
|
111
|
+
"workspace",
|
|
112
|
+
"repos",
|
|
113
|
+
".git",
|
|
114
|
+
"node_modules",
|
|
115
|
+
],
|
|
116
|
+
[path.join(ROOT, "companies")]: ["acme", "indigo"],
|
|
117
|
+
[path.join(ROOT, "core")]: ["skills"],
|
|
118
|
+
[path.join(ROOT, "workspace")]: ["agency", "worktrees"],
|
|
119
|
+
[path.join(ROOT, "workspace", "worktrees")]: ["wt-1"],
|
|
120
|
+
[path.join(ROOT, "repos")]: ["hq-cloud"],
|
|
121
|
+
};
|
|
122
|
+
const plan = planWatchRoots(ROOT, filter, {
|
|
123
|
+
listChildDirs: treeLister(tree),
|
|
124
|
+
});
|
|
125
|
+
const excludedDirs = Object.keys(tree)
|
|
126
|
+
.flatMap((dir) => (tree[dir] ?? []).map((n) => path.join(dir, n)))
|
|
127
|
+
.filter((p) => !filter(p, true));
|
|
128
|
+
expect(excludedDirs.length).toBeGreaterThan(0);
|
|
129
|
+
for (const excluded of excludedDirs) {
|
|
130
|
+
// Not watched directly...
|
|
131
|
+
expect(allWatched(plan)).not.toContain(excluded);
|
|
132
|
+
// ...and not swept in as a descendant of some recursive root either.
|
|
133
|
+
for (const root of plan.recursive) {
|
|
134
|
+
expect(excluded.startsWith(root + path.sep)).toBe(false);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
it("stops descending at maxDepth and takes a recursive watch there", () => {
|
|
139
|
+
const filter = makeFilter({ anySegment: ["node_modules"] });
|
|
140
|
+
const plan = planWatchRoots(ROOT, filter, {
|
|
141
|
+
maxDepth: 1,
|
|
142
|
+
listChildDirs: treeLister({
|
|
143
|
+
[ROOT]: ["a", "node_modules"],
|
|
144
|
+
[path.join(ROOT, "a")]: ["b", "node_modules"],
|
|
145
|
+
[path.join(ROOT, "a", "b")]: ["c"],
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
148
|
+
// Depth 0 has an excluded child → shallow. Depth 1 is the bound, so `a`
|
|
149
|
+
// takes a recursive watch even though it still contains node_modules; the
|
|
150
|
+
// per-event filter drops that residue. This bounds handle count on trees
|
|
151
|
+
// with deeply scattered exclusions.
|
|
152
|
+
expect(plan.shallow).toEqual([ROOT]);
|
|
153
|
+
expect(plan.recursive).toEqual([path.join(ROOT, "a")]);
|
|
154
|
+
});
|
|
155
|
+
it("skips a directory it cannot read instead of throwing", () => {
|
|
156
|
+
const plan = planWatchRoots(ROOT, makeFilter({ prefixes: ["repos"] }), {
|
|
157
|
+
listChildDirs: (dir) => {
|
|
158
|
+
if (dir === path.join(ROOT, "denied")) {
|
|
159
|
+
throw Object.assign(new Error("EACCES"), { code: "EACCES" });
|
|
160
|
+
}
|
|
161
|
+
return dir === ROOT
|
|
162
|
+
? [path.join(ROOT, "denied"), path.join(ROOT, "repos")]
|
|
163
|
+
: [];
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
// The unreadable dir is still watched (we cannot see inside it to decide
|
|
167
|
+
// better) and the walk completes rather than crashing start().
|
|
168
|
+
expect(allWatched(plan)).toContain(path.join(ROOT, "denied"));
|
|
169
|
+
expect(allWatched(plan)).not.toContain(path.join(ROOT, "repos"));
|
|
170
|
+
});
|
|
171
|
+
it("reports every in-scope directory through onDirectory, and no excluded one", () => {
|
|
172
|
+
// TreeWatcher builds its known-kinds index from this callback instead of
|
|
173
|
+
// walking the same tree a second time, so the callback must cover every
|
|
174
|
+
// in-scope directory — including ones inside a collapsed recursive root.
|
|
175
|
+
const filter = makeFilter({ prefixes: ["repos"] });
|
|
176
|
+
const seen = [];
|
|
177
|
+
planWatchRoots(ROOT, filter, {
|
|
178
|
+
onDirectory: (dir) => seen.push(dir),
|
|
179
|
+
listChildDirs: treeLister({
|
|
180
|
+
[ROOT]: ["companies", "repos"],
|
|
181
|
+
[path.join(ROOT, "companies")]: ["acme"],
|
|
182
|
+
[path.join(ROOT, "companies", "acme")]: ["knowledge"],
|
|
183
|
+
[path.join(ROOT, "repos")]: ["hq-cloud"],
|
|
184
|
+
}),
|
|
185
|
+
});
|
|
186
|
+
expect(seen).toEqual([
|
|
187
|
+
path.join(ROOT, "companies"),
|
|
188
|
+
path.join(ROOT, "companies", "acme"),
|
|
189
|
+
path.join(ROOT, "companies", "acme", "knowledge"),
|
|
190
|
+
]);
|
|
191
|
+
expect(seen).not.toContain(path.join(ROOT, "repos"));
|
|
192
|
+
expect(seen).not.toContain(path.join(ROOT, "repos", "hq-cloud"));
|
|
193
|
+
});
|
|
194
|
+
it("resolves coverage by walking ancestors, not by scanning every root", () => {
|
|
195
|
+
// This runs on EVERY rename event, in the hot path of a change whose whole
|
|
196
|
+
// point is cutting per-event cost. A linear scan is O(number of roots) —
|
|
197
|
+
// 685 on a real HQ tree — where an ancestor walk is O(path depth), ~10.
|
|
198
|
+
// The behavior must be identical, including the prefix trap below.
|
|
199
|
+
const roots = new Set([path.join(ROOT, "a", "b"), path.join(ROOT, "c")]);
|
|
200
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "a", "b"), roots)).toBe(true);
|
|
201
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "a", "b", "deep", "x.md"), roots)).toBe(true);
|
|
202
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "a"), roots)).toBe(false);
|
|
203
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "d"), roots)).toBe(false);
|
|
204
|
+
// The prefix trap: `/hq/a/bc` shares a string prefix with root `/hq/a/b`
|
|
205
|
+
// but is NOT under it. A naive startsWith without the separator would say
|
|
206
|
+
// covered, and the whole subtree would go unwatched.
|
|
207
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "a", "bc"), roots)).toBe(false);
|
|
208
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "a", "bc", "x.md"), roots)).toBe(false);
|
|
209
|
+
});
|
|
210
|
+
it("reports nothing as covered when there are no recursive roots", () => {
|
|
211
|
+
expect(isCoveredByRecursiveRoot(path.join(ROOT, "a", "b"), new Set())).toBe(false);
|
|
212
|
+
});
|
|
213
|
+
it("plans over a real directory tree using the default reader", async () => {
|
|
214
|
+
const root = await mkdtemp(path.join(tmpdir(), "hqcloud-planroots-"));
|
|
215
|
+
try {
|
|
216
|
+
await mkdir(path.join(root, "companies", "acme"), { recursive: true });
|
|
217
|
+
await mkdir(path.join(root, "repos", "hq-cloud", "src"), {
|
|
218
|
+
recursive: true,
|
|
219
|
+
});
|
|
220
|
+
const filter = (abs) => {
|
|
221
|
+
const rel = path.relative(root, abs).split(path.sep).join("/");
|
|
222
|
+
if (rel === "" || rel.startsWith(".."))
|
|
223
|
+
return false;
|
|
224
|
+
return rel !== "repos" && !rel.startsWith("repos/");
|
|
225
|
+
};
|
|
226
|
+
const plan = planWatchRoots(root, filter);
|
|
227
|
+
expect(plan.shallow).toContain(root);
|
|
228
|
+
expect(plan.recursive).toContain(path.join(root, "companies"));
|
|
229
|
+
expect(allWatched(plan)).not.toContain(path.join(root, "repos"));
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
await rm(root, { recursive: true, force: true });
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});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C,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACnE,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The emit filter must run BEFORE handleEvent pays for a stat.
|
|
3
|
+
*
|
|
4
|
+
* The recursive backend hands every OS event to handleEvent, and a `rename`
|
|
5
|
+
* used to be lstat'd before the exclusion filter was consulted. On a real HQ
|
|
6
|
+
* that is one synchronous syscall for every file touched anywhere under
|
|
7
|
+
* `repos/` or `workspace/worktrees/` — build, install, and checkout churn the
|
|
8
|
+
* watcher immediately throws away. Scoped watch roots (see watch-roots.ts) keep
|
|
9
|
+
* most of that traffic from being delivered at all; this gate makes whatever
|
|
10
|
+
* still arrives cost a string compare instead of a syscall.
|
|
11
|
+
*
|
|
12
|
+
* This lives in its own file because it mocks `fs` module-wide, which would
|
|
13
|
+
* otherwise perturb the 53 tests in watcher.test.ts.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=watcher-event-gate.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watcher-event-gate.test.d.ts","sourceRoot":"","sources":["../src/watcher-event-gate.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|