@indigoai-us/hq-cloud 6.14.50 → 6.15.1

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 (340) hide show
  1. package/dist/bin/sync-mutation.d.ts +14 -0
  2. package/dist/bin/sync-mutation.d.ts.map +1 -0
  3. package/dist/bin/sync-mutation.js +60 -0
  4. package/dist/bin/sync-mutation.js.map +1 -0
  5. package/dist/bin/sync-mutation.test.d.ts +2 -0
  6. package/dist/bin/sync-mutation.test.d.ts.map +1 -0
  7. package/dist/bin/sync-mutation.test.js +64 -0
  8. package/dist/bin/sync-mutation.test.js.map +1 -0
  9. package/dist/bin/sync-runner-company.d.ts +8 -0
  10. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  11. package/dist/bin/sync-runner-company.js +16 -0
  12. package/dist/bin/sync-runner-company.js.map +1 -1
  13. package/dist/bin/sync-runner-company.test.d.ts +2 -0
  14. package/dist/bin/sync-runner-company.test.d.ts.map +1 -0
  15. package/dist/bin/sync-runner-company.test.js +36 -0
  16. package/dist/bin/sync-runner-company.test.js.map +1 -0
  17. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  18. package/dist/bin/sync-runner-watch-loop.js +98 -8
  19. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  20. package/dist/bin/sync-runner.d.ts +17 -0
  21. package/dist/bin/sync-runner.d.ts.map +1 -1
  22. package/dist/bin/sync-runner.js.map +1 -1
  23. package/dist/bin/sync-runner.test.js +109 -0
  24. package/dist/bin/sync-runner.test.js.map +1 -1
  25. package/dist/cli/conflict-recovery.test.d.ts +2 -0
  26. package/dist/cli/conflict-recovery.test.d.ts.map +1 -0
  27. package/dist/cli/conflict-recovery.test.js +201 -0
  28. package/dist/cli/conflict-recovery.test.js.map +1 -0
  29. package/dist/cli/conflict.d.ts +60 -0
  30. package/dist/cli/conflict.d.ts.map +1 -1
  31. package/dist/cli/conflict.js +333 -0
  32. package/dist/cli/conflict.js.map +1 -1
  33. package/dist/cli/reindex-knowledge.d.ts +7 -0
  34. package/dist/cli/reindex-knowledge.d.ts.map +1 -0
  35. package/dist/cli/reindex-knowledge.js +389 -0
  36. package/dist/cli/reindex-knowledge.js.map +1 -0
  37. package/dist/cli/reindex-knowledge.test.d.ts +12 -0
  38. package/dist/cli/reindex-knowledge.test.d.ts.map +1 -0
  39. package/dist/cli/reindex-knowledge.test.js +260 -0
  40. package/dist/cli/reindex-knowledge.test.js.map +1 -0
  41. package/dist/cli/reindex.d.ts.map +1 -1
  42. package/dist/cli/reindex.js +8 -0
  43. package/dist/cli/reindex.js.map +1 -1
  44. package/dist/cli/rescue-settings-reconcile.test.js +47 -0
  45. package/dist/cli/rescue-settings-reconcile.test.js.map +1 -1
  46. package/dist/cli/sync.d.ts +27 -0
  47. package/dist/cli/sync.d.ts.map +1 -1
  48. package/dist/cli/sync.js +52 -0
  49. package/dist/cli/sync.js.map +1 -1
  50. package/dist/cli/sync.test.js +31 -1
  51. package/dist/cli/sync.test.js.map +1 -1
  52. package/dist/index.d.ts +2 -0
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +1 -0
  55. package/dist/index.js.map +1 -1
  56. package/dist/skill-telemetry.d.ts +6 -0
  57. package/dist/skill-telemetry.d.ts.map +1 -1
  58. package/dist/skill-telemetry.js +14 -2
  59. package/dist/skill-telemetry.js.map +1 -1
  60. package/dist/skill-telemetry.test.js +79 -0
  61. package/dist/skill-telemetry.test.js.map +1 -1
  62. package/dist/sync/candidate-uploader.d.ts +88 -0
  63. package/dist/sync/candidate-uploader.d.ts.map +1 -0
  64. package/dist/sync/candidate-uploader.js +212 -0
  65. package/dist/sync/candidate-uploader.js.map +1 -0
  66. package/dist/sync/candidate-uploader.test.d.ts +2 -0
  67. package/dist/sync/candidate-uploader.test.d.ts.map +1 -0
  68. package/dist/sync/candidate-uploader.test.js +132 -0
  69. package/dist/sync/candidate-uploader.test.js.map +1 -0
  70. package/dist/sync/delta-client.d.ts +73 -0
  71. package/dist/sync/delta-client.d.ts.map +1 -0
  72. package/dist/sync/delta-client.js +201 -0
  73. package/dist/sync/delta-client.js.map +1 -0
  74. package/dist/sync/delta-client.test.d.ts +2 -0
  75. package/dist/sync/delta-client.test.d.ts.map +1 -0
  76. package/dist/sync/delta-client.test.js +97 -0
  77. package/dist/sync/delta-client.test.js.map +1 -0
  78. package/dist/sync/durable-apply.d.ts +76 -0
  79. package/dist/sync/durable-apply.d.ts.map +1 -0
  80. package/dist/sync/durable-apply.js +530 -0
  81. package/dist/sync/durable-apply.js.map +1 -0
  82. package/dist/sync/durable-apply.test.d.ts +2 -0
  83. package/dist/sync/durable-apply.test.d.ts.map +1 -0
  84. package/dist/sync/durable-apply.test.js +180 -0
  85. package/dist/sync/durable-apply.test.js.map +1 -0
  86. package/dist/sync/event-sync.d.ts +33 -1
  87. package/dist/sync/event-sync.d.ts.map +1 -1
  88. package/dist/sync/event-sync.js +149 -1
  89. package/dist/sync/event-sync.js.map +1 -1
  90. package/dist/sync/event-sync.test.js +142 -1
  91. package/dist/sync/event-sync.test.js.map +1 -1
  92. package/dist/sync/index.d.ts +2 -0
  93. package/dist/sync/index.d.ts.map +1 -1
  94. package/dist/sync/index.js +1 -0
  95. package/dist/sync/index.js.map +1 -1
  96. package/dist/sync/multipart-uploader.d.ts +99 -0
  97. package/dist/sync/multipart-uploader.d.ts.map +1 -0
  98. package/dist/sync/multipart-uploader.js +447 -0
  99. package/dist/sync/multipart-uploader.js.map +1 -0
  100. package/dist/sync/multipart-uploader.test.d.ts +2 -0
  101. package/dist/sync/multipart-uploader.test.d.ts.map +1 -0
  102. package/dist/sync/multipart-uploader.test.js +119 -0
  103. package/dist/sync/multipart-uploader.test.js.map +1 -0
  104. package/dist/sync/mutation-client.d.ts +82 -0
  105. package/dist/sync/mutation-client.d.ts.map +1 -0
  106. package/dist/sync/mutation-client.js +221 -0
  107. package/dist/sync/mutation-client.js.map +1 -0
  108. package/dist/sync/mutation-client.test.d.ts +2 -0
  109. package/dist/sync/mutation-client.test.d.ts.map +1 -0
  110. package/dist/sync/mutation-client.test.js +51 -0
  111. package/dist/sync/mutation-client.test.js.map +1 -0
  112. package/dist/sync/push-receiver.d.ts +45 -0
  113. package/dist/sync/push-receiver.d.ts.map +1 -1
  114. package/dist/sync/push-receiver.js +101 -0
  115. package/dist/sync/push-receiver.js.map +1 -1
  116. package/dist/sync/push-receiver.test.js +54 -2
  117. package/dist/sync/push-receiver.test.js.map +1 -1
  118. package/dist/sync/scope-inventory-client.d.ts +69 -0
  119. package/dist/sync/scope-inventory-client.d.ts.map +1 -0
  120. package/dist/sync/scope-inventory-client.js +210 -0
  121. package/dist/sync/scope-inventory-client.js.map +1 -0
  122. package/dist/sync/scope-inventory-client.test.d.ts +2 -0
  123. package/dist/sync/scope-inventory-client.test.d.ts.map +1 -0
  124. package/dist/sync/scope-inventory-client.test.js +94 -0
  125. package/dist/sync/scope-inventory-client.test.js.map +1 -0
  126. package/dist/sync/snapshot-client.d.ts +98 -0
  127. package/dist/sync/snapshot-client.d.ts.map +1 -0
  128. package/dist/sync/snapshot-client.js +402 -0
  129. package/dist/sync/snapshot-client.js.map +1 -0
  130. package/dist/sync/snapshot-client.test.d.ts +2 -0
  131. package/dist/sync/snapshot-client.test.d.ts.map +1 -0
  132. package/dist/sync/snapshot-client.test.js +169 -0
  133. package/dist/sync/snapshot-client.test.js.map +1 -0
  134. package/dist/sync/uploader-finalization.d.ts +97 -0
  135. package/dist/sync/uploader-finalization.d.ts.map +1 -0
  136. package/dist/sync/uploader-finalization.js +273 -0
  137. package/dist/sync/uploader-finalization.js.map +1 -0
  138. package/dist/sync/uploader-finalization.test.d.ts +2 -0
  139. package/dist/sync/uploader-finalization.test.d.ts.map +1 -0
  140. package/dist/sync/uploader-finalization.test.js +92 -0
  141. package/dist/sync/uploader-finalization.test.js.map +1 -0
  142. package/dist/telemetry.d.ts +11 -1
  143. package/dist/telemetry.d.ts.map +1 -1
  144. package/dist/telemetry.js +21 -2
  145. package/dist/telemetry.js.map +1 -1
  146. package/dist/telemetry.test.js +80 -0
  147. package/dist/telemetry.test.js.map +1 -1
  148. package/package.json +6 -1
  149. package/.claude/policies/hq-cloud-esm-cannot-spy-fs-builtins.md +0 -30
  150. package/.claude/policies/hq-cloud-strip-types-no-parameter-properties.md +0 -22
  151. package/.github/workflows/ci.yml +0 -84
  152. package/.github/workflows/publish.yml +0 -56
  153. package/.github/workflows/unreleased-commits-nag.yml +0 -256
  154. package/eslint.config.js +0 -67
  155. package/pnpm-workspace.yaml +0 -2
  156. package/scripts/presign-transport-e2e.mjs +0 -250
  157. package/scripts/vault-rebaseline.sh +0 -323
  158. package/scripts/vault-rescue.sh +0 -332
  159. package/src/active-company.test.ts +0 -188
  160. package/src/active-company.ts +0 -168
  161. package/src/agent-codex-instructions.test.ts +0 -332
  162. package/src/agent-codex-instructions.ts +0 -309
  163. package/src/auth.ts +0 -146
  164. package/src/backup-prune.test.ts +0 -98
  165. package/src/backup-prune.ts +0 -182
  166. package/src/bin/backup-prune-runner.ts +0 -33
  167. package/src/bin/rescue-runner.ts +0 -25
  168. package/src/bin/sync-runner-company.ts +0 -695
  169. package/src/bin/sync-runner-events.test.ts +0 -143
  170. package/src/bin/sync-runner-events.ts +0 -55
  171. package/src/bin/sync-runner-planning.test.ts +0 -311
  172. package/src/bin/sync-runner-planning.ts +0 -258
  173. package/src/bin/sync-runner-rollup.test.ts +0 -37
  174. package/src/bin/sync-runner-rollup.ts +0 -97
  175. package/src/bin/sync-runner-telemetry.ts +0 -15
  176. package/src/bin/sync-runner-watch-loop.ts +0 -1235
  177. package/src/bin/sync-runner-watch-routes.test.ts +0 -71
  178. package/src/bin/sync-runner-watch-routes.ts +0 -184
  179. package/src/bin/sync-runner.test.ts +0 -8767
  180. package/src/bin/sync-runner.ts +0 -2190
  181. package/src/cli/accept.ts +0 -124
  182. package/src/cli/conflict.ts +0 -119
  183. package/src/cli/doctor.test.ts +0 -581
  184. package/src/cli/doctor.ts +0 -642
  185. package/src/cli/index.ts +0 -49
  186. package/src/cli/invite.test.ts +0 -250
  187. package/src/cli/invite.ts +0 -214
  188. package/src/cli/promote.ts +0 -157
  189. package/src/cli/reindex.test.ts +0 -957
  190. package/src/cli/reindex.ts +0 -970
  191. package/src/cli/rescue-classify-ordering.test.ts +0 -548
  192. package/src/cli/rescue-clone-diagnostics.test.ts +0 -120
  193. package/src/cli/rescue-core.ts +0 -3011
  194. package/src/cli/rescue-drift-reconcile.test.ts +0 -179
  195. package/src/cli/rescue-drop-dir-symlink.test.ts +0 -224
  196. package/src/cli/rescue-exec-bit-preserve.test.ts +0 -187
  197. package/src/cli/rescue-hq-root-guard.test.ts +0 -232
  198. package/src/cli/rescue-journal-reconcile.test.ts +0 -215
  199. package/src/cli/rescue-mtime-preserve.test.ts +0 -203
  200. package/src/cli/rescue-settings-reconcile.test.ts +0 -583
  201. package/src/cli/rescue-snapshot.test.ts +0 -57
  202. package/src/cli/rescue-snapshot.ts +0 -51
  203. package/src/cli/rescue.reindex.test.ts +0 -63
  204. package/src/cli/rescue.test.ts +0 -131
  205. package/src/cli/rescue.ts +0 -182
  206. package/src/cli/share.test.ts +0 -7843
  207. package/src/cli/share.ts +0 -3663
  208. package/src/cli/sync-scope.test.ts +0 -652
  209. package/src/cli/sync.test.ts +0 -5207
  210. package/src/cli/sync.ts +0 -3470
  211. package/src/cli/tombstones.ts +0 -106
  212. package/src/cli/watch-event-push-conflict.test.ts +0 -234
  213. package/src/client-info.test.ts +0 -214
  214. package/src/client-info.ts +0 -121
  215. package/src/cognito-auth.test.ts +0 -712
  216. package/src/cognito-auth.ts +0 -1422
  217. package/src/company-resolver.test.ts +0 -618
  218. package/src/company-resolver.ts +0 -521
  219. package/src/context.test.ts +0 -583
  220. package/src/context.ts +0 -378
  221. package/src/daemon-worker.ts +0 -26
  222. package/src/daemon.ts +0 -99
  223. package/src/entity-resolver.test.ts +0 -315
  224. package/src/entity-resolver.ts +0 -180
  225. package/src/ignore.test.ts +0 -466
  226. package/src/ignore.ts +0 -469
  227. package/src/index.ts +0 -439
  228. package/src/journal.test.ts +0 -968
  229. package/src/journal.ts +0 -765
  230. package/src/lib/cloud-authoritative.test.ts +0 -45
  231. package/src/lib/cloud-authoritative.ts +0 -59
  232. package/src/lib/conflict-file.ts +0 -86
  233. package/src/lib/conflict-index.ts +0 -289
  234. package/src/lib/conflict.test.ts +0 -348
  235. package/src/lib/describe-error.test.ts +0 -100
  236. package/src/lib/describe-error.ts +0 -58
  237. package/src/lib/exit-codes.ts +0 -24
  238. package/src/lib/machine-id.test.ts +0 -231
  239. package/src/lib/machine-id.ts +0 -175
  240. package/src/lib/net-errors.test.ts +0 -65
  241. package/src/lib/net-errors.ts +0 -86
  242. package/src/lib/readlink-safe.test.ts +0 -43
  243. package/src/lib/readlink-safe.ts +0 -29
  244. package/src/local-path-codec.test.ts +0 -138
  245. package/src/local-path-codec.ts +0 -161
  246. package/src/machine-auth.test.ts +0 -1323
  247. package/src/manifest-reconcile.test.ts +0 -1123
  248. package/src/manifest-reconcile.ts +0 -518
  249. package/src/object-io.test.ts +0 -1221
  250. package/src/object-io.ts +0 -1306
  251. package/src/operation-lock.test.ts +0 -484
  252. package/src/operation-lock.ts +0 -680
  253. package/src/outcome-telemetry.test.ts +0 -498
  254. package/src/outcome-telemetry.ts +0 -639
  255. package/src/personal-vault-exclusions.test.ts +0 -308
  256. package/src/personal-vault-exclusions.ts +0 -354
  257. package/src/personal-vault.test.ts +0 -756
  258. package/src/personal-vault.ts +0 -496
  259. package/src/prefix-coalesce.test.ts +0 -240
  260. package/src/prefix-coalesce.ts +0 -273
  261. package/src/public-surface.test.ts +0 -117
  262. package/src/qmd-reindex.test.ts +0 -877
  263. package/src/qmd-reindex.ts +0 -842
  264. package/src/read-only-state-dir.test.ts +0 -188
  265. package/src/remote-pull.test.ts +0 -1130
  266. package/src/remote-pull.ts +0 -618
  267. package/src/s3.symlink-materialize.test.ts +0 -492
  268. package/src/s3.test.ts +0 -1789
  269. package/src/s3.ts +0 -1532
  270. package/src/schemas/signal-types.test.ts +0 -82
  271. package/src/schemas/signal-types.ts +0 -38
  272. package/src/schemas/source-channels.test.ts +0 -82
  273. package/src/schemas/source-channels.ts +0 -53
  274. package/src/scope-shrink.test.ts +0 -633
  275. package/src/scope-shrink.ts +0 -481
  276. package/src/signals/get.test.ts +0 -310
  277. package/src/signals/get.ts +0 -75
  278. package/src/signals/internals.ts +0 -195
  279. package/src/signals/list.test.ts +0 -420
  280. package/src/signals/list.ts +0 -79
  281. package/src/signals/parse.ts +0 -8
  282. package/src/signals/types.ts +0 -91
  283. package/src/skill-telemetry.test.ts +0 -1825
  284. package/src/skill-telemetry.ts +0 -1439
  285. package/src/sources/get.test.ts +0 -293
  286. package/src/sources/get.ts +0 -66
  287. package/src/sources/internals.ts +0 -198
  288. package/src/sources/list.test.ts +0 -402
  289. package/src/sources/list.ts +0 -84
  290. package/src/sources/parse.ts +0 -43
  291. package/src/sources/types.ts +0 -84
  292. package/src/sync/event-sync.test.ts +0 -594
  293. package/src/sync/event-sync.ts +0 -545
  294. package/src/sync/feature-flags.test.ts +0 -378
  295. package/src/sync/feature-flags.ts +0 -62
  296. package/src/sync/index.ts +0 -76
  297. package/src/sync/lease-client.test.ts +0 -128
  298. package/src/sync/lease-client.ts +0 -207
  299. package/src/sync/logger.test.ts +0 -242
  300. package/src/sync/logger.ts +0 -79
  301. package/src/sync/metrics.test.ts +0 -462
  302. package/src/sync/metrics.ts +0 -213
  303. package/src/sync/pull-scope.ts +0 -265
  304. package/src/sync/push-event.test.ts +0 -266
  305. package/src/sync/push-event.ts +0 -224
  306. package/src/sync/push-receiver.test.ts +0 -566
  307. package/src/sync/push-receiver.ts +0 -1048
  308. package/src/sync/push-transport.ts +0 -231
  309. package/src/sync/realtime-rollout.test.ts +0 -86
  310. package/src/sync/realtime-rollout.ts +0 -262
  311. package/src/sync/state-store.test.ts +0 -194
  312. package/src/sync/state-store.ts +0 -727
  313. package/src/sync-core.ts +0 -58
  314. package/src/sync-progress.test.ts +0 -94
  315. package/src/sync-progress.ts +0 -140
  316. package/src/telemetry-events.test.ts +0 -88
  317. package/src/telemetry-events.ts +0 -205
  318. package/src/telemetry.test.ts +0 -1280
  319. package/src/telemetry.ts +0 -1109
  320. package/src/types.ts +0 -314
  321. package/src/vault-client.test.ts +0 -1380
  322. package/src/vault-client.ts +0 -1694
  323. package/src/version.ts +0 -24
  324. package/src/watch-roots.test.ts +0 -278
  325. package/src/watch-roots.ts +0 -162
  326. package/src/watcher-event-gate.test.ts +0 -212
  327. package/src/watcher.test.ts +0 -1079
  328. package/src/watcher.ts +0 -1741
  329. package/test/e2e/sync/cross-tenant-isolation.test.ts +0 -630
  330. package/test/e2e/sync/skill-telemetry-oversized-transcript.test.ts +0 -124
  331. package/test/e2e/sync/transient-company-leg.test.ts +0 -384
  332. package/test/e2e/sync/windows-unreadable-link-leg.test.ts +0 -191
  333. package/test/e2e/watcher-real-chokidar.test.ts +0 -165
  334. package/test/e2e/watcher-recursive-backend.test.ts +0 -181
  335. package/test/e2e/watcher-scoped-coverage.test.ts +0 -381
  336. package/test/invite-flow.integration.test.ts +0 -244
  337. package/test/joiner-manifest-reconcile.integration.test.ts +0 -322
  338. package/test/share-sync.integration.test.ts +0 -213
  339. package/tsconfig.json +0 -19
  340. package/vitest.config.ts +0 -22
@@ -1,381 +0,0 @@
1
- /**
2
- * REAL-fs regressions for the scoped watch-root backend.
3
- *
4
- * These assert on what the OS DELIVERS, not on what TreeWatcher emits. That
5
- * distinction is the whole point of this backend: the emit filter has always
6
- * dropped excluded paths correctly, so emissions look identical whether or not
7
- * the watch set is scoped. What changes is whether the event reaches the
8
- * process at all — which is the CPU cost this backend exists to remove, and
9
- * the only way these regressions are observable.
10
- *
11
- * So each test drives `startScopedRecursiveWatch` directly and counts raw
12
- * `onEvent` calls.
13
- *
14
- * Checked against the pre-fix backend, three of these fail without their fix —
15
- * the new-exclusion firehose, the attach-failure report, and the mid-plan
16
- * window. The mid-plan case only became meaningful once the walk was made
17
- * deliberately slow: with a microsecond-wide window it was racing FSEvents
18
- * stream warm-up and flapped between runs, which is a flaky test rather than
19
- * a regression test.
20
- *
21
- * The delete/recreate case passes either way on macOS, because FSEvents
22
- * watches by PATH — a recreated directory keeps reporting through the stale
23
- * handle. That does not hold on Windows (`ReadDirectoryChangesW` is
24
- * handle-based) and is not guaranteed by any API contract, so dropping stale
25
- * handles is deliberate belt-and-braces and this test is kept as a guard: it
26
- * pins that the re-plan did not BREAK behavior that already worked.
27
- */
28
-
29
- import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
30
- import { tmpdir } from "node:os";
31
- import path from "node:path";
32
-
33
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
34
-
35
- import {
36
- startScopedRecursiveWatch,
37
- type ScopedWatchBackend,
38
- } from "../../src/watcher.js";
39
-
40
- let hqRoot: string;
41
- let backend: ScopedWatchBackend | null = null;
42
-
43
- /** `excluded/` anywhere in the tree is out of scope, like `node_modules/`. */
44
- const makeFilter = (root: string) => (abs: string): boolean => {
45
- const rel = path.relative(root, abs);
46
- if (rel === "" || rel.startsWith("..")) return false;
47
- return !rel.split(path.sep).includes("excluded");
48
- };
49
-
50
- beforeEach(async () => {
51
- hqRoot = await mkdtemp(path.join(tmpdir(), "hqcloud-scoped-cov-"));
52
- });
53
-
54
- afterEach(async () => {
55
- backend?.close();
56
- backend = null;
57
- await rm(hqRoot, { recursive: true, force: true });
58
- });
59
-
60
- const settle = (ms = 800) => new Promise((r) => setTimeout(r, ms));
61
-
62
- /** Raw events the OS delivered for paths under `prefix`. */
63
- function eventsUnder(onEvent: ReturnType<typeof vi.fn>, prefix: string): number {
64
- return onEvent.mock.calls.filter(
65
- ([p]) => typeof p === "string" && p.startsWith(prefix),
66
- ).length;
67
- }
68
-
69
- /**
70
- * Guard against a vacuous pass. Half of these tests assert that ZERO events
71
- * arrive, which is trivially true if the backend attached no watches at all —
72
- * so every test first proves the backend is actually live.
73
- */
74
- function expectLiveBackend(b: ScopedWatchBackend): void {
75
- expect(b.attachFailures).toBe(0);
76
- expect(b.watchedPathCount()).toBeGreaterThan(0);
77
- }
78
-
79
- /**
80
- * This backend is the macOS/Windows one: it is built entirely on recursive
81
- * `fs.watch`, which Linux does not implement (`startTreeWatch` routes Linux to
82
- * chokidar instead). Running these there watches nothing, which would let the
83
- * "expect zero events" cases pass for the wrong reason.
84
- */
85
- const SUPPORTS_RECURSIVE_WATCH =
86
- process.platform === "darwin" || process.platform === "win32";
87
-
88
- describe.skipIf(!SUPPORTS_RECURSIVE_WATCH)("scoped watch roots — the OS stops reporting excluded trees", () => {
89
- it(
90
- "stops delivering events from an excluded directory created AFTER planning",
91
- async () => {
92
- // The regression that would defeat the whole change: at plan time the
93
- // tree is clean, so it collapses to ONE recursive root at hqRoot.
94
- // Creating `work/excluded/` afterwards puts a high-churn bucket back
95
- // inside that root. Without re-planning, the creation event looks
96
- // "already covered" and every write beneath it is delivered again —
97
- // exactly the firehose this backend removes.
98
- await mkdir(path.join(hqRoot, "work", "keep"), { recursive: true });
99
- const onEvent = vi.fn();
100
- backend = startScopedRecursiveWatch(
101
- hqRoot,
102
- makeFilter(hqRoot),
103
- onEvent,
104
- () => {},
105
- );
106
- expectLiveBackend(backend);
107
- // Wait out the bootstrap drain window: the temporary whole-tree watch is
108
- // deliberately held open briefly after planning so in-flight events are
109
- // not dropped with the handle. This test measures the steady state.
110
- await settle(2600);
111
-
112
- const excluded = path.join(hqRoot, "work", "excluded");
113
- await mkdir(path.join(excluded, "deep"), { recursive: true });
114
- await settle();
115
-
116
- onEvent.mockClear();
117
- for (let i = 0; i < 5; i++) {
118
- await writeFile(path.join(excluded, "deep", `build-${i}.log`), "noise\n");
119
- }
120
- await settle();
121
-
122
- expect(eventsUnder(onEvent, excluded)).toBe(0);
123
- },
124
- 20000,
125
- );
126
-
127
- it(
128
- "still delivers in-scope siblings after re-planning around a new exclusion",
129
- async () => {
130
- // Re-planning must SPLIT the root, not tear coverage off the good part.
131
- const keep = path.join(hqRoot, "work", "keep");
132
- await mkdir(keep, { recursive: true });
133
- const onEvent = vi.fn();
134
- backend = startScopedRecursiveWatch(
135
- hqRoot,
136
- makeFilter(hqRoot),
137
- onEvent,
138
- () => {},
139
- );
140
- expectLiveBackend(backend);
141
- await settle();
142
-
143
- await mkdir(path.join(hqRoot, "work", "excluded"), { recursive: true });
144
- await settle();
145
-
146
- onEvent.mockClear();
147
- await writeFile(path.join(keep, "note.md"), "# hi\n");
148
- await settle();
149
-
150
- expect(eventsUnder(onEvent, keep)).toBeGreaterThan(0);
151
- },
152
- 20000,
153
- );
154
-
155
- it(
156
- "re-attaches after a watched directory is deleted and recreated",
157
- async () => {
158
- // A recreated directory has a NEW inode. A stale handle left in the watch
159
- // set makes the path look covered forever, so nothing under the
160
- // replacement is ever delivered again.
161
- const work = path.join(hqRoot, "work");
162
- const keep = path.join(work, "keep");
163
- await mkdir(keep, { recursive: true });
164
- // An exclusion at the root forces `hqRoot` to be SHALLOW, so `work/` is
165
- // its own recursive root — the handle that goes stale on delete.
166
- await mkdir(path.join(hqRoot, "excluded"), { recursive: true });
167
- const onEvent = vi.fn();
168
- backend = startScopedRecursiveWatch(
169
- hqRoot,
170
- makeFilter(hqRoot),
171
- onEvent,
172
- () => {},
173
- );
174
- expectLiveBackend(backend);
175
- await settle();
176
-
177
- await rm(work, { recursive: true, force: true });
178
- await settle();
179
- await mkdir(keep, { recursive: true });
180
- await settle();
181
-
182
- onEvent.mockClear();
183
- await writeFile(path.join(keep, "reborn.md"), "# back\n");
184
- await settle();
185
-
186
- expect(eventsUnder(onEvent, keep)).toBeGreaterThan(0);
187
- },
188
- 25000,
189
- );
190
-
191
- it(
192
- "delivers a change made while the planning walk is still running",
193
- async () => {
194
- // Planning is synchronous and takes seconds on a real tree. Without a
195
- // bootstrap watch over the root first, anything written during that
196
- // window is invisible to event-driven push until the next cadence poll.
197
- await mkdir(path.join(hqRoot, "work"), { recursive: true });
198
- await mkdir(path.join(hqRoot, "excluded"), { recursive: true });
199
- const target = path.join(hqRoot, "work", "during-plan.md");
200
-
201
- const onEvent = vi.fn();
202
- let fired = false;
203
- const filter = makeFilter(hqRoot);
204
- /** Block the walk so the planning window is wide and unambiguous. */
205
- const spin = (ms: number) => {
206
- const until = Date.now() + ms;
207
- while (Date.now() < until) {
208
- /* deliberately synchronous — this IS the planning walk */
209
- }
210
- };
211
- const slowFilter = (abs: string, isDir?: boolean): boolean => {
212
- // Mutate from inside the planning walk itself — the one moment the
213
- // tree is being traversed and no scoped watch exists yet.
214
- if (!fired) {
215
- fired = true;
216
- // Let the OS watch stream warm up first — a write in the same
217
- // microsecond as stream creation is genuinely racy on macOS and
218
- // would make this test flaky rather than meaningful. Then write, and
219
- // keep blocking so the write is unambiguously INSIDE the walk.
220
- spin(600);
221
- // eslint-disable-next-line @typescript-eslint/no-require-imports
222
- require("node:fs").writeFileSync(target, "# mid-plan\n");
223
- spin(400);
224
- }
225
- return filter(abs, isDir);
226
- };
227
-
228
- backend = startScopedRecursiveWatch(hqRoot, slowFilter, onEvent, () => {});
229
- expectLiveBackend(backend);
230
- await settle(1500);
231
-
232
- expect(fired).toBe(true);
233
- expect(eventsUnder(onEvent, target)).toBeGreaterThan(0);
234
- },
235
- 20000,
236
- );
237
-
238
- it(
239
- "drops watches BELOW a deleted directory, not just the directory itself",
240
- async () => {
241
- // The OS reports the removed directory, not each of its descendants, so
242
- // a drop that only removes the exact path leaks every watch underneath
243
- // it — open handles that never close, plus a stale recursive root that
244
- // will mark a later recreation as already-covered. These runners live
245
- // for many hours, so the leak accumulates.
246
- const outer = path.join(hqRoot, "outer");
247
- // `excluded` children make outer and outer/inner SHALLOW, so both they
248
- // and their in-scope children each hold their own watch.
249
- await mkdir(path.join(outer, "excluded"), { recursive: true });
250
- await mkdir(path.join(outer, "inner", "excluded"), { recursive: true });
251
- await mkdir(path.join(outer, "inner", "keep"), { recursive: true });
252
- await mkdir(path.join(hqRoot, "excluded"), { recursive: true });
253
-
254
- const onEvent = vi.fn();
255
- backend = startScopedRecursiveWatch(
256
- hqRoot,
257
- makeFilter(hqRoot),
258
- onEvent,
259
- () => {},
260
- );
261
- expectLiveBackend(backend);
262
- const before = backend.watchedPathCount();
263
- // hqRoot + outer + outer/inner + outer/inner/keep
264
- expect(before).toBeGreaterThanOrEqual(4);
265
- await settle(2600);
266
-
267
- await rm(outer, { recursive: true, force: true });
268
- await settle();
269
-
270
- // Every watch at or below `outer` must be gone — only hqRoot remains.
271
- expect(backend.watchedPathCount()).toBe(1);
272
- },
273
- 25000,
274
- );
275
-
276
- it(
277
- "keeps re-planning bounded when several exclusions appear at once",
278
- async () => {
279
- // Each newly-created excluded directory under a recursive root forces a
280
- // re-plan, and a re-plan walks that root's subtree synchronously — so an
281
- // install creating many excluded directories at once looks like it should
282
- // cost that walk once per directory, on the event loop.
283
- //
284
- // It does not, and this test pins WHY: the first re-plan SPLITS the
285
- // covering root, so each subsequent exclusion is re-planned against a
286
- // much smaller root. The work is self-limiting. This is a guard, not a
287
- // regression test — it passes without any coalescing precisely because
288
- // the splitting already bounds the cost, and it would start failing if a
289
- // future change made re-plans walk from the top each time.
290
- const work = path.join(hqRoot, "work");
291
- for (const n of ["p1", "p2", "p3", "p4"]) {
292
- await mkdir(path.join(work, n, "src"), { recursive: true });
293
- }
294
- const seen = vi.fn();
295
- backend = startScopedRecursiveWatch(
296
- hqRoot,
297
- makeFilter(hqRoot),
298
- () => {},
299
- () => {},
300
- seen,
301
- );
302
- expectLiveBackend(backend);
303
- await settle(2600);
304
-
305
- // One directory visit per in-scope dir per walk. Four exclusions
306
- // appearing together must cost ONE walk, not four.
307
- const perWalk = seen.mock.calls.length;
308
- expect(perWalk).toBeGreaterThan(0);
309
- seen.mockClear();
310
-
311
- await Promise.all(
312
- ["p1", "p2", "p3", "p4"].map((n) =>
313
- mkdir(path.join(work, n, "excluded"), { recursive: true }),
314
- ),
315
- );
316
- await settle(2000);
317
-
318
- // Allow one full walk plus slack; four independent walks would be ~4x.
319
- expect(seen.mock.calls.length).toBeLessThan(perWalk * 2);
320
- },
321
- 30000,
322
- );
323
-
324
- it(
325
- "does not report an error when a watched directory is simply deleted",
326
- async () => {
327
- // A deleted watched root could plausibly be re-added by a re-plan, with
328
- // fs.watch then throwing ENOENT and surfacing a watcher error plus a full
329
- // resync for an ordinary delete. It is not, because the stale-handle drop
330
- // returns before any re-plan is considered. A guard on that ordering:
331
- // deleting a directory must stay silent.
332
- const work = path.join(hqRoot, "work");
333
- await mkdir(path.join(work, "keep"), { recursive: true });
334
- await mkdir(path.join(hqRoot, "excluded"), { recursive: true });
335
-
336
- const errors: unknown[] = [];
337
- backend = startScopedRecursiveWatch(
338
- hqRoot,
339
- makeFilter(hqRoot),
340
- () => {},
341
- (e) => errors.push(e),
342
- );
343
- expectLiveBackend(backend);
344
- await settle(2600);
345
-
346
- await rm(work, { recursive: true, force: true });
347
- await settle(1500);
348
-
349
- expect(errors).toEqual([]);
350
- },
351
- 25000,
352
- );
353
-
354
- it("reports attach failures so the caller can reject a partial plan", async () => {
355
- // Real attach failure, no mocking: `b/` is planned during the walk, then
356
- // deleted before applyPlan reaches it, so its fs.watch throws ENOENT.
357
- // A planned root we could not attach is a permanent hole in coverage —
358
- // the caller must see it and fall back rather than run half-blind.
359
- const doomed = path.join(hqRoot, "b");
360
- await mkdir(path.join(hqRoot, "a"), { recursive: true });
361
- await mkdir(doomed, { recursive: true });
362
- // An exclusion at the root keeps hqRoot shallow, so `a/` and `b/` are
363
- // planned as their own recursive roots instead of collapsing into one.
364
- await mkdir(path.join(hqRoot, "excluded"), { recursive: true });
365
-
366
- const errors: unknown[] = [];
367
- const { rmSync } = await import("node:fs");
368
- backend = startScopedRecursiveWatch(
369
- hqRoot,
370
- makeFilter(hqRoot),
371
- () => {},
372
- (e) => errors.push(e),
373
- (dir) => {
374
- if (dir === doomed) rmSync(doomed, { recursive: true, force: true });
375
- },
376
- );
377
-
378
- expect(backend.attachFailures).toBeGreaterThan(0);
379
- expect(errors.length).toBeGreaterThan(0);
380
- }, 20000);
381
- });
@@ -1,244 +0,0 @@
1
- /**
2
- * Invite → Accept → Promote integration test (VLT-7 US-003).
3
- *
4
- * Mocks the vault-service HTTP API to test the full lifecycle round-trip:
5
- * admin creates invite → invitee accepts → admin promotes to guest with paths.
6
- *
7
- * Uses mocked fetch (not a real vault-service) to keep the test self-contained
8
- * and runnable offline. Real E2E tests against dev stage are in the e2eTests
9
- * section of the PRD.
10
- */
11
-
12
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
13
- import { invite } from "../src/cli/invite.js";
14
- import { accept, parseToken } from "../src/cli/accept.js";
15
- import { promote } from "../src/cli/promote.js";
16
- import type { VaultServiceConfig } from "../src/types.js";
17
- import type { Membership } from "../src/vault-client.js";
18
-
19
- // ---------------------------------------------------------------------------
20
- // Helpers
21
- // ---------------------------------------------------------------------------
22
-
23
- function jsonResponse(status: number, body: unknown): Response {
24
- return new Response(JSON.stringify(body), {
25
- status,
26
- headers: { "Content-Type": "application/json" },
27
- });
28
- }
29
-
30
- const VAULT_CONFIG: VaultServiceConfig = {
31
- apiUrl: "https://vault.test.example.com",
32
- authToken: "admin-jwt",
33
- };
34
-
35
- const INVITEE_CONFIG: VaultServiceConfig = {
36
- apiUrl: "https://vault.test.example.com",
37
- authToken: "invitee-jwt",
38
- };
39
-
40
- let fetchSpy: ReturnType<typeof vi.spyOn>;
41
-
42
- beforeEach(() => {
43
- fetchSpy = vi.spyOn(globalThis, "fetch");
44
- });
45
-
46
- afterEach(() => {
47
- vi.restoreAllMocks();
48
- });
49
-
50
- // ---------------------------------------------------------------------------
51
- // Token parsing
52
- // ---------------------------------------------------------------------------
53
-
54
- describe("parseToken", () => {
55
- it("extracts token from hq:// magic link", () => {
56
- expect(parseToken("hq://accept/tok_abc123")).toBe("tok_abc123");
57
- });
58
-
59
- it("extracts token from https:// URL", () => {
60
- expect(parseToken("https://example.com/accept/tok_xyz")).toBe("tok_xyz");
61
- });
62
-
63
- it("returns raw token unchanged", () => {
64
- expect(parseToken("tok_raw_token")).toBe("tok_raw_token");
65
- });
66
-
67
- it("trims whitespace", () => {
68
- expect(parseToken(" hq://accept/tok_abc ")).toBe("tok_abc");
69
- });
70
- });
71
-
72
- // ---------------------------------------------------------------------------
73
- // Full round-trip
74
- // ---------------------------------------------------------------------------
75
-
76
- describe("invite → accept → promote lifecycle", () => {
77
- const pendingMembership: Membership = {
78
- membershipKey: "psn_invitee#cmp_acme",
79
- personUid: "psn_invitee",
80
- companyUid: "cmp_acme",
81
- role: "member",
82
- status: "pending",
83
- inviteToken: "tok_secure_random_32bytes",
84
- invitedBy: "psn_admin",
85
- invitedAt: "2026-04-15T00:00:00Z",
86
- createdAt: "2026-04-15T00:00:00Z",
87
- updatedAt: "2026-04-15T00:00:00Z",
88
- };
89
-
90
- const activeMembership: Membership = {
91
- ...pendingMembership,
92
- status: "active",
93
- inviteToken: undefined,
94
- acceptedAt: "2026-04-15T00:01:00Z",
95
- updatedAt: "2026-04-15T00:01:00Z",
96
- };
97
-
98
- it("admin invites → invitee accepts → admin promotes to guest with paths", async () => {
99
- // --- Step 1: Admin creates invite ---
100
- fetchSpy
101
- // entity.findBySlug("company", "acme")
102
- .mockResolvedValueOnce(
103
- jsonResponse(200, { entity: { uid: "cmp_acme", slug: "acme", type: "company", status: "active" } }),
104
- )
105
- // createInvite
106
- .mockResolvedValueOnce(
107
- jsonResponse(200, {
108
- membership: pendingMembership,
109
- inviteToken: "tok_secure_random_32bytes",
110
- }),
111
- );
112
-
113
- const inviteResult = await invite({
114
- target: "alice@example.com",
115
- role: "member",
116
- company: "acme",
117
- vaultConfig: VAULT_CONFIG,
118
- callerUid: "psn_admin",
119
- });
120
-
121
- expect(inviteResult.magicLink).toBe("hq://accept/tok_secure_random_32bytes");
122
- expect(inviteResult.membership.status).toBe("pending");
123
-
124
- // --- Step 2: Invitee accepts ---
125
- fetchSpy
126
- // acceptInvite
127
- .mockResolvedValueOnce(
128
- jsonResponse(200, { membership: activeMembership }),
129
- )
130
- // entity.get for company slug resolution
131
- .mockResolvedValueOnce(
132
- jsonResponse(200, { entity: { uid: "cmp_acme", slug: "acme", type: "company", status: "active" } }),
133
- );
134
-
135
- const acceptResult = await accept({
136
- tokenOrLink: inviteResult.magicLink,
137
- callerUid: "psn_invitee",
138
- vaultConfig: INVITEE_CONFIG,
139
- });
140
-
141
- expect(acceptResult.membership.status).toBe("active");
142
- expect(acceptResult.membership.role).toBe("member");
143
- expect(acceptResult.companySlug).toBe("acme");
144
-
145
- // --- Step 3: Admin promotes member → guest with paths ---
146
- fetchSpy
147
- // entity.findBySlug for company resolution
148
- .mockResolvedValueOnce(
149
- jsonResponse(200, { entity: { uid: "cmp_acme", slug: "acme", type: "company", status: "active" } }),
150
- )
151
- // updateRole
152
- .mockResolvedValueOnce(
153
- jsonResponse(200, {
154
- membership: {
155
- ...activeMembership,
156
- role: "guest",
157
- allowedPrefixes: ["docs/"],
158
- updatedAt: "2026-04-15T00:02:00Z",
159
- },
160
- }),
161
- );
162
-
163
- const promoteResult = await promote({
164
- target: "psn_invitee",
165
- newRole: "guest",
166
- paths: "docs/",
167
- company: "acme",
168
- callerUid: "psn_admin",
169
- vaultConfig: VAULT_CONFIG,
170
- });
171
-
172
- expect(promoteResult.membership.role).toBe("guest");
173
- expect(promoteResult.membership.allowedPrefixes).toEqual(["docs/"]);
174
- });
175
-
176
- it("double-accept returns conflict error", async () => {
177
- fetchSpy.mockResolvedValueOnce(
178
- jsonResponse(409, { message: "Already accepted" }),
179
- );
180
-
181
- await expect(
182
- accept({
183
- tokenOrLink: "tok_already_accepted",
184
- callerUid: "psn_invitee",
185
- vaultConfig: INVITEE_CONFIG,
186
- }),
187
- ).rejects.toThrow("This invite was already accepted");
188
- });
189
-
190
- it("demoting last owner returns conflict error", async () => {
191
- fetchSpy
192
- // entity.findBySlug
193
- .mockResolvedValueOnce(
194
- jsonResponse(200, { entity: { uid: "cmp_acme", slug: "acme", type: "company", status: "active" } }),
195
- )
196
- // updateRole — 409 because last owner
197
- .mockResolvedValueOnce(
198
- jsonResponse(409, { message: "Cannot remove last owner" }),
199
- );
200
-
201
- await expect(
202
- promote({
203
- target: "psn_owner",
204
- newRole: "member",
205
- company: "acme",
206
- callerUid: "psn_owner",
207
- vaultConfig: VAULT_CONFIG,
208
- }),
209
- ).rejects.toThrow("Cannot leave company without an owner");
210
- });
211
-
212
- it("non-admin invite returns permission error", async () => {
213
- fetchSpy
214
- .mockResolvedValueOnce(
215
- jsonResponse(200, { entity: { uid: "cmp_acme", slug: "acme", type: "company", status: "active" } }),
216
- )
217
- .mockResolvedValueOnce(
218
- jsonResponse(403, { message: "Forbidden" }),
219
- );
220
-
221
- await expect(
222
- invite({
223
- target: "bob@example.com",
224
- company: "acme",
225
- vaultConfig: VAULT_CONFIG,
226
- callerUid: "psn_member",
227
- }),
228
- ).rejects.toThrow("Permission denied — only admins and owners can invite members");
229
- });
230
-
231
- it("accept with wrong person returns permission error", async () => {
232
- fetchSpy.mockResolvedValueOnce(
233
- jsonResponse(403, { message: "Identity mismatch" }),
234
- );
235
-
236
- await expect(
237
- accept({
238
- tokenOrLink: "tok_for_someone_else",
239
- callerUid: "psn_wrong",
240
- vaultConfig: INVITEE_CONFIG,
241
- }),
242
- ).rejects.toThrow("This invite was for a different person");
243
- });
244
- });