@indigoai-us/hq-cloud 5.26.0 → 5.28.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.
Files changed (70) hide show
  1. package/.github/workflows/ci.yml +34 -0
  2. package/dist/bin/sync-runner.d.ts +38 -0
  3. package/dist/bin/sync-runner.d.ts.map +1 -1
  4. package/dist/bin/sync-runner.js +75 -1
  5. package/dist/bin/sync-runner.js.map +1 -1
  6. package/dist/index.d.ts +4 -2
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +4 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/sync/feature-flags.d.ts +136 -0
  11. package/dist/sync/feature-flags.d.ts.map +1 -0
  12. package/dist/sync/feature-flags.js +160 -0
  13. package/dist/sync/feature-flags.js.map +1 -0
  14. package/dist/sync/feature-flags.test.d.ts +24 -0
  15. package/dist/sync/feature-flags.test.d.ts.map +1 -0
  16. package/dist/sync/feature-flags.test.js +330 -0
  17. package/dist/sync/feature-flags.test.js.map +1 -0
  18. package/dist/sync/index.d.ts +10 -2
  19. package/dist/sync/index.d.ts.map +1 -1
  20. package/dist/sync/index.js +5 -1
  21. package/dist/sync/index.js.map +1 -1
  22. package/dist/sync/logger.d.ts +61 -0
  23. package/dist/sync/logger.d.ts.map +1 -0
  24. package/dist/sync/logger.js +51 -0
  25. package/dist/sync/logger.js.map +1 -0
  26. package/dist/sync/logger.test.d.ts +19 -0
  27. package/dist/sync/logger.test.d.ts.map +1 -0
  28. package/dist/sync/logger.test.js +199 -0
  29. package/dist/sync/logger.test.js.map +1 -0
  30. package/dist/sync/metrics.d.ts +89 -0
  31. package/dist/sync/metrics.d.ts.map +1 -0
  32. package/dist/sync/metrics.js +105 -0
  33. package/dist/sync/metrics.js.map +1 -0
  34. package/dist/sync/metrics.test.d.ts +19 -0
  35. package/dist/sync/metrics.test.d.ts.map +1 -0
  36. package/dist/sync/metrics.test.js +280 -0
  37. package/dist/sync/metrics.test.js.map +1 -0
  38. package/dist/sync/push-receiver.d.ts +442 -0
  39. package/dist/sync/push-receiver.d.ts.map +1 -0
  40. package/dist/sync/push-receiver.js +782 -0
  41. package/dist/sync/push-receiver.js.map +1 -0
  42. package/dist/sync/push-receiver.test.d.ts +25 -0
  43. package/dist/sync/push-receiver.test.d.ts.map +1 -0
  44. package/dist/sync/push-receiver.test.js +477 -0
  45. package/dist/sync/push-receiver.test.js.map +1 -0
  46. package/dist/sync/push-transport.d.ts +84 -1
  47. package/dist/sync/push-transport.d.ts.map +1 -1
  48. package/dist/sync/push-transport.js +84 -0
  49. package/dist/sync/push-transport.js.map +1 -1
  50. package/dist/watcher.d.ts +127 -11
  51. package/dist/watcher.d.ts.map +1 -1
  52. package/dist/watcher.js +294 -57
  53. package/dist/watcher.js.map +1 -1
  54. package/package.json +9 -5
  55. package/src/bin/sync-runner.ts +102 -1
  56. package/src/index.ts +21 -0
  57. package/src/sync/feature-flags.test.ts +392 -0
  58. package/src/sync/feature-flags.ts +229 -0
  59. package/src/sync/index.ts +57 -2
  60. package/src/sync/logger.test.ts +241 -0
  61. package/src/sync/logger.ts +79 -0
  62. package/src/sync/metrics.test.ts +380 -0
  63. package/src/sync/metrics.ts +158 -0
  64. package/src/sync/push-receiver.test.ts +545 -0
  65. package/src/sync/push-receiver.ts +1077 -0
  66. package/src/sync/push-transport.ts +148 -1
  67. package/src/watcher.ts +408 -51
  68. package/test/e2e/sync/cross-tenant-isolation.test.ts +502 -0
  69. package/test/e2e/watcher-real-chokidar.test.ts +105 -0
  70. package/test/e2e/watcher-recursive-backend.test.ts +115 -0
@@ -0,0 +1,115 @@
1
+ /**
2
+ * REAL-fs regression E2E for the single-recursive-watch backend.
3
+ *
4
+ * Why this exists:
5
+ * chokidar 4 dropped its `fsevents` backend, so on macOS it watches via kqueue
6
+ * — ~1 open fd PER watched path. Over a real HQ tree (~11k files+dirs) that
7
+ * exhausts the default soft `ulimit -n` (256) with EMFILE, silently killing the
8
+ * watcher so instant sync degrades to the 10-min poll. The fix replaces the
9
+ * per-path chokidar watch with a SINGLE recursive `fs.watch` on macOS/Windows
10
+ * (1 OS handle for the whole tree), filtering events per-path at emit time.
11
+ *
12
+ * These tests pin the two load-bearing behaviors of that backend (both also
13
+ * hold for the chokidar Linux fallback, so the suite is backend-agnostic):
14
+ * 1. A file created under a subtree that DID NOT EXIST when the watcher
15
+ * started still fires — i.e. coverage doesn't depend on per-directory
16
+ * watch registration at start time.
17
+ * 2. An out-of-scope edit (`repos/`, excluded by DEFAULT_IGNORES) does NOT
18
+ * fire — the OS reports it under a recursive watch, and it must be dropped
19
+ * by the emit filter, not woken on.
20
+ */
21
+
22
+ import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
23
+ import { tmpdir } from "node:os";
24
+ import path from "node:path";
25
+
26
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
27
+
28
+ import { TreeWatcher } from "../../src/watcher.js";
29
+
30
+ let hqRoot: string;
31
+ let watcher: TreeWatcher | null = null;
32
+
33
+ beforeEach(async () => {
34
+ hqRoot = await mkdtemp(path.join(tmpdir(), "hqcloud-recwatch-e2e-"));
35
+ await writeFile(path.join(hqRoot, ".hqinclude"), "companies/*/knowledge/\n");
36
+ // Only the `acme` company exists at start; `newco` is created later to prove
37
+ // the recursive watch covers subtrees born after start().
38
+ await mkdir(path.join(hqRoot, "companies", "acme", "knowledge"), {
39
+ recursive: true,
40
+ });
41
+ });
42
+
43
+ afterEach(async () => {
44
+ watcher?.dispose();
45
+ watcher = null;
46
+ await rm(hqRoot, { recursive: true, force: true });
47
+ });
48
+
49
+ /** Resolve true if the watcher emits a debounced change within `ms`, else false. */
50
+ function waitForEmit(w: TreeWatcher, ms: number): Promise<boolean> {
51
+ return new Promise((resolve) => {
52
+ let settled = false;
53
+ const off = w.onChange(() => {
54
+ if (settled) return;
55
+ settled = true;
56
+ off();
57
+ clearTimeout(t);
58
+ resolve(true);
59
+ });
60
+ const t = setTimeout(() => {
61
+ if (settled) return;
62
+ settled = true;
63
+ off();
64
+ resolve(false);
65
+ }, ms);
66
+ });
67
+ }
68
+
69
+ describe("event-push watcher -- single recursive watch backend", () => {
70
+ it(
71
+ "FIRES for an in-scope file created under a subtree that did not exist at start",
72
+ async () => {
73
+ watcher = new TreeWatcher({ hqRoot, debounceMs: 250, personalMode: false });
74
+ watcher.start();
75
+ // Let the recursive watch establish before any mutation.
76
+ await new Promise((r) => setTimeout(r, 600));
77
+
78
+ // Create a brand-new company subtree AFTER the watcher started. A
79
+ // per-directory watcher would only catch this if it dynamically
80
+ // registered the new dirs; the recursive watch covers it inherently.
81
+ await mkdir(path.join(hqRoot, "companies", "newco", "knowledge"), {
82
+ recursive: true,
83
+ });
84
+
85
+ const emitted = waitForEmit(watcher, 4000);
86
+ await writeFile(
87
+ path.join(hqRoot, "companies", "newco", "knowledge", "fresh.md"),
88
+ "# fresh\n",
89
+ );
90
+ expect(await emitted).toBe(true);
91
+ },
92
+ 8000,
93
+ );
94
+
95
+ it(
96
+ "does NOT fire for an out-of-scope edit the OS reports under the recursive watch (repos/)",
97
+ async () => {
98
+ watcher = new TreeWatcher({ hqRoot, debounceMs: 250, personalMode: false });
99
+ watcher.start();
100
+ await new Promise((r) => setTimeout(r, 600));
101
+
102
+ // `repos/` is excluded by DEFAULT_IGNORES. Under a recursive OS watch the
103
+ // event is still delivered, so the emit filter — not watch-time pruning —
104
+ // is what must drop it.
105
+ await mkdir(path.join(hqRoot, "repos", "some-repo"), { recursive: true });
106
+ const emitted = waitForEmit(watcher, 2500);
107
+ await writeFile(
108
+ path.join(hqRoot, "repos", "some-repo", "code.ts"),
109
+ "export const x = 1;\n",
110
+ );
111
+ expect(await emitted).toBe(false);
112
+ },
113
+ 8000,
114
+ );
115
+ });