@indigoai-us/hq-cloud 6.15.0 → 6.15.2

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 (329) hide show
  1. package/dist/bin/sync-mutation.d.ts +16 -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 +165 -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/sync.d.ts +35 -0
  34. package/dist/cli/sync.d.ts.map +1 -1
  35. package/dist/cli/sync.js +100 -0
  36. package/dist/cli/sync.js.map +1 -1
  37. package/dist/cli/sync.test.js +85 -1
  38. package/dist/cli/sync.test.js.map +1 -1
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/skill-telemetry.d.ts +6 -0
  44. package/dist/skill-telemetry.d.ts.map +1 -1
  45. package/dist/skill-telemetry.js +14 -2
  46. package/dist/skill-telemetry.js.map +1 -1
  47. package/dist/skill-telemetry.test.js +79 -0
  48. package/dist/skill-telemetry.test.js.map +1 -1
  49. package/dist/sync/candidate-uploader.d.ts +88 -0
  50. package/dist/sync/candidate-uploader.d.ts.map +1 -0
  51. package/dist/sync/candidate-uploader.js +212 -0
  52. package/dist/sync/candidate-uploader.js.map +1 -0
  53. package/dist/sync/candidate-uploader.test.d.ts +2 -0
  54. package/dist/sync/candidate-uploader.test.d.ts.map +1 -0
  55. package/dist/sync/candidate-uploader.test.js +132 -0
  56. package/dist/sync/candidate-uploader.test.js.map +1 -0
  57. package/dist/sync/delta-client.d.ts +73 -0
  58. package/dist/sync/delta-client.d.ts.map +1 -0
  59. package/dist/sync/delta-client.js +201 -0
  60. package/dist/sync/delta-client.js.map +1 -0
  61. package/dist/sync/delta-client.test.d.ts +2 -0
  62. package/dist/sync/delta-client.test.d.ts.map +1 -0
  63. package/dist/sync/delta-client.test.js +97 -0
  64. package/dist/sync/delta-client.test.js.map +1 -0
  65. package/dist/sync/durable-apply.d.ts +76 -0
  66. package/dist/sync/durable-apply.d.ts.map +1 -0
  67. package/dist/sync/durable-apply.js +530 -0
  68. package/dist/sync/durable-apply.js.map +1 -0
  69. package/dist/sync/durable-apply.test.d.ts +2 -0
  70. package/dist/sync/durable-apply.test.d.ts.map +1 -0
  71. package/dist/sync/durable-apply.test.js +180 -0
  72. package/dist/sync/durable-apply.test.js.map +1 -0
  73. package/dist/sync/event-sync.d.ts +33 -1
  74. package/dist/sync/event-sync.d.ts.map +1 -1
  75. package/dist/sync/event-sync.js +149 -1
  76. package/dist/sync/event-sync.js.map +1 -1
  77. package/dist/sync/event-sync.test.js +142 -1
  78. package/dist/sync/event-sync.test.js.map +1 -1
  79. package/dist/sync/index.d.ts +2 -0
  80. package/dist/sync/index.d.ts.map +1 -1
  81. package/dist/sync/index.js +1 -0
  82. package/dist/sync/index.js.map +1 -1
  83. package/dist/sync/multipart-uploader.d.ts +99 -0
  84. package/dist/sync/multipart-uploader.d.ts.map +1 -0
  85. package/dist/sync/multipart-uploader.js +447 -0
  86. package/dist/sync/multipart-uploader.js.map +1 -0
  87. package/dist/sync/multipart-uploader.test.d.ts +2 -0
  88. package/dist/sync/multipart-uploader.test.d.ts.map +1 -0
  89. package/dist/sync/multipart-uploader.test.js +119 -0
  90. package/dist/sync/multipart-uploader.test.js.map +1 -0
  91. package/dist/sync/mutation-client.d.ts +85 -0
  92. package/dist/sync/mutation-client.d.ts.map +1 -0
  93. package/dist/sync/mutation-client.js +245 -0
  94. package/dist/sync/mutation-client.js.map +1 -0
  95. package/dist/sync/mutation-client.test.d.ts +2 -0
  96. package/dist/sync/mutation-client.test.d.ts.map +1 -0
  97. package/dist/sync/mutation-client.test.js +51 -0
  98. package/dist/sync/mutation-client.test.js.map +1 -0
  99. package/dist/sync/push-receiver.d.ts +45 -0
  100. package/dist/sync/push-receiver.d.ts.map +1 -1
  101. package/dist/sync/push-receiver.js +101 -0
  102. package/dist/sync/push-receiver.js.map +1 -1
  103. package/dist/sync/push-receiver.test.js +54 -2
  104. package/dist/sync/push-receiver.test.js.map +1 -1
  105. package/dist/sync/scope-inventory-client.d.ts +69 -0
  106. package/dist/sync/scope-inventory-client.d.ts.map +1 -0
  107. package/dist/sync/scope-inventory-client.js +210 -0
  108. package/dist/sync/scope-inventory-client.js.map +1 -0
  109. package/dist/sync/scope-inventory-client.test.d.ts +2 -0
  110. package/dist/sync/scope-inventory-client.test.d.ts.map +1 -0
  111. package/dist/sync/scope-inventory-client.test.js +94 -0
  112. package/dist/sync/scope-inventory-client.test.js.map +1 -0
  113. package/dist/sync/snapshot-client.d.ts +98 -0
  114. package/dist/sync/snapshot-client.d.ts.map +1 -0
  115. package/dist/sync/snapshot-client.js +402 -0
  116. package/dist/sync/snapshot-client.js.map +1 -0
  117. package/dist/sync/snapshot-client.test.d.ts +2 -0
  118. package/dist/sync/snapshot-client.test.d.ts.map +1 -0
  119. package/dist/sync/snapshot-client.test.js +169 -0
  120. package/dist/sync/snapshot-client.test.js.map +1 -0
  121. package/dist/sync/uploader-finalization.d.ts +97 -0
  122. package/dist/sync/uploader-finalization.d.ts.map +1 -0
  123. package/dist/sync/uploader-finalization.js +273 -0
  124. package/dist/sync/uploader-finalization.js.map +1 -0
  125. package/dist/sync/uploader-finalization.test.d.ts +2 -0
  126. package/dist/sync/uploader-finalization.test.d.ts.map +1 -0
  127. package/dist/sync/uploader-finalization.test.js +92 -0
  128. package/dist/sync/uploader-finalization.test.js.map +1 -0
  129. package/dist/telemetry.d.ts +11 -1
  130. package/dist/telemetry.d.ts.map +1 -1
  131. package/dist/telemetry.js +21 -2
  132. package/dist/telemetry.js.map +1 -1
  133. package/dist/telemetry.test.js +80 -0
  134. package/dist/telemetry.test.js.map +1 -1
  135. package/package.json +6 -1
  136. package/.claude/policies/hq-cloud-esm-cannot-spy-fs-builtins.md +0 -30
  137. package/.claude/policies/hq-cloud-strip-types-no-parameter-properties.md +0 -22
  138. package/.github/workflows/ci.yml +0 -84
  139. package/.github/workflows/publish.yml +0 -56
  140. package/.github/workflows/unreleased-commits-nag.yml +0 -256
  141. package/eslint.config.js +0 -67
  142. package/pnpm-workspace.yaml +0 -2
  143. package/scripts/presign-transport-e2e.mjs +0 -250
  144. package/scripts/vault-rebaseline.sh +0 -323
  145. package/scripts/vault-rescue.sh +0 -332
  146. package/src/active-company.test.ts +0 -188
  147. package/src/active-company.ts +0 -168
  148. package/src/agent-codex-instructions.test.ts +0 -332
  149. package/src/agent-codex-instructions.ts +0 -309
  150. package/src/auth.ts +0 -146
  151. package/src/backup-prune.test.ts +0 -98
  152. package/src/backup-prune.ts +0 -182
  153. package/src/bin/backup-prune-runner.ts +0 -33
  154. package/src/bin/rescue-runner.ts +0 -25
  155. package/src/bin/sync-runner-company.ts +0 -695
  156. package/src/bin/sync-runner-events.test.ts +0 -143
  157. package/src/bin/sync-runner-events.ts +0 -55
  158. package/src/bin/sync-runner-planning.test.ts +0 -311
  159. package/src/bin/sync-runner-planning.ts +0 -258
  160. package/src/bin/sync-runner-rollup.test.ts +0 -37
  161. package/src/bin/sync-runner-rollup.ts +0 -97
  162. package/src/bin/sync-runner-telemetry.ts +0 -15
  163. package/src/bin/sync-runner-watch-loop.ts +0 -1235
  164. package/src/bin/sync-runner-watch-routes.test.ts +0 -71
  165. package/src/bin/sync-runner-watch-routes.ts +0 -184
  166. package/src/bin/sync-runner.test.ts +0 -8767
  167. package/src/bin/sync-runner.ts +0 -2190
  168. package/src/cli/accept.ts +0 -124
  169. package/src/cli/conflict.ts +0 -119
  170. package/src/cli/doctor.test.ts +0 -581
  171. package/src/cli/doctor.ts +0 -642
  172. package/src/cli/index.ts +0 -49
  173. package/src/cli/invite.test.ts +0 -250
  174. package/src/cli/invite.ts +0 -214
  175. package/src/cli/promote.ts +0 -157
  176. package/src/cli/reindex-knowledge.test.ts +0 -307
  177. package/src/cli/reindex-knowledge.ts +0 -450
  178. package/src/cli/reindex.test.ts +0 -957
  179. package/src/cli/reindex.ts +0 -979
  180. package/src/cli/rescue-classify-ordering.test.ts +0 -548
  181. package/src/cli/rescue-clone-diagnostics.test.ts +0 -120
  182. package/src/cli/rescue-core.ts +0 -3011
  183. package/src/cli/rescue-drift-reconcile.test.ts +0 -179
  184. package/src/cli/rescue-drop-dir-symlink.test.ts +0 -224
  185. package/src/cli/rescue-exec-bit-preserve.test.ts +0 -187
  186. package/src/cli/rescue-hq-root-guard.test.ts +0 -232
  187. package/src/cli/rescue-journal-reconcile.test.ts +0 -215
  188. package/src/cli/rescue-mtime-preserve.test.ts +0 -203
  189. package/src/cli/rescue-settings-reconcile.test.ts +0 -637
  190. package/src/cli/rescue-snapshot.test.ts +0 -57
  191. package/src/cli/rescue-snapshot.ts +0 -51
  192. package/src/cli/rescue.reindex.test.ts +0 -63
  193. package/src/cli/rescue.test.ts +0 -131
  194. package/src/cli/rescue.ts +0 -182
  195. package/src/cli/share.test.ts +0 -7843
  196. package/src/cli/share.ts +0 -3663
  197. package/src/cli/sync-scope.test.ts +0 -652
  198. package/src/cli/sync.test.ts +0 -5207
  199. package/src/cli/sync.ts +0 -3470
  200. package/src/cli/tombstones.ts +0 -106
  201. package/src/cli/watch-event-push-conflict.test.ts +0 -234
  202. package/src/client-info.test.ts +0 -214
  203. package/src/client-info.ts +0 -121
  204. package/src/cognito-auth.test.ts +0 -712
  205. package/src/cognito-auth.ts +0 -1422
  206. package/src/company-resolver.test.ts +0 -618
  207. package/src/company-resolver.ts +0 -521
  208. package/src/context.test.ts +0 -583
  209. package/src/context.ts +0 -378
  210. package/src/daemon-worker.ts +0 -26
  211. package/src/daemon.ts +0 -99
  212. package/src/entity-resolver.test.ts +0 -315
  213. package/src/entity-resolver.ts +0 -180
  214. package/src/ignore.test.ts +0 -466
  215. package/src/ignore.ts +0 -469
  216. package/src/index.ts +0 -439
  217. package/src/journal.test.ts +0 -968
  218. package/src/journal.ts +0 -765
  219. package/src/lib/cloud-authoritative.test.ts +0 -45
  220. package/src/lib/cloud-authoritative.ts +0 -59
  221. package/src/lib/conflict-file.ts +0 -86
  222. package/src/lib/conflict-index.ts +0 -289
  223. package/src/lib/conflict.test.ts +0 -348
  224. package/src/lib/describe-error.test.ts +0 -100
  225. package/src/lib/describe-error.ts +0 -58
  226. package/src/lib/exit-codes.ts +0 -24
  227. package/src/lib/machine-id.test.ts +0 -231
  228. package/src/lib/machine-id.ts +0 -175
  229. package/src/lib/net-errors.test.ts +0 -65
  230. package/src/lib/net-errors.ts +0 -86
  231. package/src/lib/readlink-safe.test.ts +0 -43
  232. package/src/lib/readlink-safe.ts +0 -29
  233. package/src/local-path-codec.test.ts +0 -138
  234. package/src/local-path-codec.ts +0 -161
  235. package/src/machine-auth.test.ts +0 -1323
  236. package/src/manifest-reconcile.test.ts +0 -1123
  237. package/src/manifest-reconcile.ts +0 -518
  238. package/src/object-io.test.ts +0 -1221
  239. package/src/object-io.ts +0 -1306
  240. package/src/operation-lock.test.ts +0 -484
  241. package/src/operation-lock.ts +0 -680
  242. package/src/outcome-telemetry.test.ts +0 -498
  243. package/src/outcome-telemetry.ts +0 -639
  244. package/src/personal-vault-exclusions.test.ts +0 -308
  245. package/src/personal-vault-exclusions.ts +0 -354
  246. package/src/personal-vault.test.ts +0 -756
  247. package/src/personal-vault.ts +0 -496
  248. package/src/prefix-coalesce.test.ts +0 -240
  249. package/src/prefix-coalesce.ts +0 -273
  250. package/src/public-surface.test.ts +0 -117
  251. package/src/qmd-reindex.test.ts +0 -877
  252. package/src/qmd-reindex.ts +0 -842
  253. package/src/read-only-state-dir.test.ts +0 -188
  254. package/src/remote-pull.test.ts +0 -1130
  255. package/src/remote-pull.ts +0 -618
  256. package/src/s3.symlink-materialize.test.ts +0 -492
  257. package/src/s3.test.ts +0 -1789
  258. package/src/s3.ts +0 -1532
  259. package/src/schemas/signal-types.test.ts +0 -82
  260. package/src/schemas/signal-types.ts +0 -38
  261. package/src/schemas/source-channels.test.ts +0 -82
  262. package/src/schemas/source-channels.ts +0 -53
  263. package/src/scope-shrink.test.ts +0 -633
  264. package/src/scope-shrink.ts +0 -481
  265. package/src/signals/get.test.ts +0 -310
  266. package/src/signals/get.ts +0 -75
  267. package/src/signals/internals.ts +0 -195
  268. package/src/signals/list.test.ts +0 -420
  269. package/src/signals/list.ts +0 -79
  270. package/src/signals/parse.ts +0 -8
  271. package/src/signals/types.ts +0 -91
  272. package/src/skill-telemetry.test.ts +0 -1825
  273. package/src/skill-telemetry.ts +0 -1439
  274. package/src/sources/get.test.ts +0 -293
  275. package/src/sources/get.ts +0 -66
  276. package/src/sources/internals.ts +0 -198
  277. package/src/sources/list.test.ts +0 -402
  278. package/src/sources/list.ts +0 -84
  279. package/src/sources/parse.ts +0 -43
  280. package/src/sources/types.ts +0 -84
  281. package/src/sync/event-sync.test.ts +0 -594
  282. package/src/sync/event-sync.ts +0 -545
  283. package/src/sync/feature-flags.test.ts +0 -378
  284. package/src/sync/feature-flags.ts +0 -62
  285. package/src/sync/index.ts +0 -76
  286. package/src/sync/lease-client.test.ts +0 -128
  287. package/src/sync/lease-client.ts +0 -207
  288. package/src/sync/logger.test.ts +0 -242
  289. package/src/sync/logger.ts +0 -79
  290. package/src/sync/metrics.test.ts +0 -462
  291. package/src/sync/metrics.ts +0 -213
  292. package/src/sync/pull-scope.ts +0 -265
  293. package/src/sync/push-event.test.ts +0 -266
  294. package/src/sync/push-event.ts +0 -224
  295. package/src/sync/push-receiver.test.ts +0 -566
  296. package/src/sync/push-receiver.ts +0 -1048
  297. package/src/sync/push-transport.ts +0 -231
  298. package/src/sync/realtime-rollout.test.ts +0 -86
  299. package/src/sync/realtime-rollout.ts +0 -262
  300. package/src/sync/state-store.test.ts +0 -194
  301. package/src/sync/state-store.ts +0 -727
  302. package/src/sync-core.ts +0 -58
  303. package/src/sync-progress.test.ts +0 -94
  304. package/src/sync-progress.ts +0 -140
  305. package/src/telemetry-events.test.ts +0 -88
  306. package/src/telemetry-events.ts +0 -205
  307. package/src/telemetry.test.ts +0 -1280
  308. package/src/telemetry.ts +0 -1109
  309. package/src/types.ts +0 -314
  310. package/src/vault-client.test.ts +0 -1380
  311. package/src/vault-client.ts +0 -1694
  312. package/src/version.ts +0 -24
  313. package/src/watch-roots.test.ts +0 -278
  314. package/src/watch-roots.ts +0 -162
  315. package/src/watcher-event-gate.test.ts +0 -212
  316. package/src/watcher.test.ts +0 -1079
  317. package/src/watcher.ts +0 -1741
  318. package/test/e2e/sync/cross-tenant-isolation.test.ts +0 -630
  319. package/test/e2e/sync/skill-telemetry-oversized-transcript.test.ts +0 -124
  320. package/test/e2e/sync/transient-company-leg.test.ts +0 -384
  321. package/test/e2e/sync/windows-unreadable-link-leg.test.ts +0 -191
  322. package/test/e2e/watcher-real-chokidar.test.ts +0 -165
  323. package/test/e2e/watcher-recursive-backend.test.ts +0 -181
  324. package/test/e2e/watcher-scoped-coverage.test.ts +0 -381
  325. package/test/invite-flow.integration.test.ts +0 -244
  326. package/test/joiner-manifest-reconcile.integration.test.ts +0 -322
  327. package/test/share-sync.integration.test.ts +0 -213
  328. package/tsconfig.json +0 -19
  329. package/vitest.config.ts +0 -22
@@ -1,492 +0,0 @@
1
- /**
2
- * Regression tests for US-001 (hq-sync-windows-skill-symlink-collision):
3
- * Windows-safe, idempotent symlink materialization in downloadFile.
4
- *
5
- * Background: the .claude/skills/<ns>:<skill> link farm is materialized from
6
- * `hq-symlink:<target>` records. Pre-fix, downloadFile always did
7
- * symlinkSync(temp) + renameSync(temp, dest). On Windows that is doubly
8
- * broken: (1) rename() can never replace an existing directory — and a
9
- * directory symlink counts as one — so every pull over the farm EPERM'd,
10
- * never journaled, and re-downloaded forever; (2) a bare symlinkSync mints a
11
- * FILE-type link, which is broken for directory targets on Windows.
12
- *
13
- * Windows semantics are exercised via the injectable `win32` option (the
14
- * local-path-codec.ts convention) plus scripted fs fakes, so these tests are
15
- * deterministic on POSIX CI and on a real Windows host alike.
16
- */
17
-
18
- import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
19
- import * as fs from "fs";
20
- import * as os from "os";
21
- import * as path from "path";
22
-
23
- // Re-export node:fs as a plain mutable object so vi.spyOn can instrument
24
- // individual functions (the frozen ESM namespace of a builtin cannot be
25
- // spied on directly). Every copied function still delegates to the real
26
- // implementation until a test overrides it.
27
- vi.mock("fs", async (importOriginal) => {
28
- const actual = await importOriginal<typeof import("fs")>();
29
- return { ...actual };
30
- });
31
-
32
- import { downloadFile, SYMLINK_BODY_PREFIX, SYMLINK_MARKER_META_VALUE } from "./s3.js";
33
- import { localPathForVaultKey } from "./local-path-codec.js";
34
- import { setObjectIOFactory, type ObjectIO } from "./object-io.js";
35
- import type { EntityContext } from "./types.js";
36
-
37
- function makeCtx(): EntityContext {
38
- return {
39
- uid: "cmp_TEST",
40
- slug: "acme",
41
- bucketName: "hq-vault-acme-123",
42
- region: "us-east-1",
43
- credentials: {
44
- accessKeyId: "ASIA_TEST",
45
- secretAccessKey: "secret",
46
- sessionToken: "session",
47
- },
48
- expiresAt: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
49
- };
50
- }
51
-
52
- /** ObjectIO stub serving a single symlink record (marker + prefixed body). */
53
- function symlinkRecordIO(target: string): ObjectIO {
54
- return {
55
- putObject: async () => ({ etag: '"unused"' }),
56
- getObject: async () => ({
57
- body: Buffer.from(SYMLINK_BODY_PREFIX + target, "utf-8"),
58
- metadata: { "hq-symlink-target": SYMLINK_MARKER_META_VALUE },
59
- }),
60
- listObjects: async () => ({ objects: [] }),
61
- deleteObject: async () => undefined,
62
- headObject: async () => null,
63
- };
64
- }
65
-
66
- function errnoError(code: string): NodeJS.ErrnoException {
67
- const err = new Error(`${code}: scripted test failure`) as NodeJS.ErrnoException;
68
- err.code = code;
69
- return err;
70
- }
71
-
72
- /** Minimal fs.Stats fake — only the predicates downloadFile consults. */
73
- function fakeStats(shape: {
74
- symlink?: boolean;
75
- dir?: boolean;
76
- file?: boolean;
77
- }): fs.Stats {
78
- return {
79
- isSymbolicLink: () => shape.symlink ?? false,
80
- isDirectory: () => shape.dir ?? false,
81
- isFile: () => shape.file ?? false,
82
- } as unknown as fs.Stats;
83
- }
84
-
85
- describe("downloadFile symlink materialization (US-001)", () => {
86
- let tmpRoot: string;
87
-
88
- beforeEach(() => {
89
- tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "s3-symlink-mat-test-"));
90
- });
91
-
92
- afterEach(() => {
93
- vi.restoreAllMocks();
94
- setObjectIOFactory(null);
95
- fs.rmSync(tmpRoot, { recursive: true, force: true });
96
- });
97
-
98
- it("fast path: an unchanged symlink is a success WITHOUT touching disk", async () => {
99
- // The perpetual-churn half of the bug: an already-correct link went
100
- // through temp+rename anyway, EPERM'd on Windows, never journaled, and
101
- // re-downloaded every pass. A pull whose incoming target matches the
102
- // existing link must return success (so the caller journals it) with
103
- // zero writes — no temp link, no rename, no beforeReplace.
104
- const target = "../real-target.md";
105
- const localPath = path.join(tmpRoot, "skills", "link.md");
106
- fs.mkdirSync(path.dirname(localPath), { recursive: true });
107
- // Real target on disk: the win32 fast path stat-follows the link to
108
- // confirm it functions as the desired type (a dangling link would
109
- // deliberately fall through to replacement).
110
- fs.writeFileSync(path.join(tmpRoot, "real-target.md"), "target body");
111
- fs.symlinkSync(target, localPath);
112
- setObjectIOFactory(() => symlinkRecordIO(target));
113
-
114
- const symlinkSpy = vi.spyOn(fs, "symlinkSync");
115
- const renameSpy = vi.spyOn(fs, "renameSync");
116
- const beforeReplace = vi.fn();
117
-
118
- const res = await downloadFile(makeCtx(), "skills/link.md", localPath, {
119
- beforeReplace,
120
- });
121
-
122
- // Success shape matches a materializing pull, so the caller journals it.
123
- expect(res.metadata?.["hq-symlink-target"]).toBe(SYMLINK_MARKER_META_VALUE);
124
- expect(symlinkSpy).not.toHaveBeenCalled();
125
- expect(renameSpy).not.toHaveBeenCalled();
126
- expect(beforeReplace).not.toHaveBeenCalled();
127
- expect(fs.lstatSync(localPath).isSymbolicLink()).toBe(true);
128
- });
129
-
130
- it("fast path compares readlink() separator-insensitively on win32", async () => {
131
- // Windows stores the substitute path with backslashes (Node converts
132
- // '/' at symlink() time), so readlink() of a link created from the
133
- // POSIX-slashed wire target returns '..\\dir\\target'. The comparison
134
- // must treat that as equal to the incoming '../dir/target' or the fast
135
- // path would never fire for any multi-segment target on Windows.
136
- const wireTarget = "../companies/indigo/skills/call-prep-brief";
137
- const localPath = path.join(tmpRoot, "farm", "indigo%3Acall-prep-brief");
138
- fs.mkdirSync(path.dirname(localPath), { recursive: true });
139
- // Real directory at the resolved target: the link farm's normal shape,
140
- // and what makes the desired flavor directory-ish (a junction, post-#219).
141
- fs.mkdirSync(path.resolve(path.dirname(localPath), wireTarget), {
142
- recursive: true,
143
- });
144
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
145
-
146
- vi.spyOn(fs, "lstatSync").mockImplementation(() =>
147
- fakeStats({ symlink: true }),
148
- );
149
- // A RELATIVE substitute path — the spelling an older client's 'dir'
150
- // symlink left behind. It still resolves to the same target, so the
151
- // fast path must accept it rather than churn the link.
152
- vi.spyOn(fs, "readlinkSync").mockImplementation(
153
- () => "..\\companies\\indigo\\skills\\call-prep-brief",
154
- );
155
- const realStatSync = fs.statSync.bind(fs) as (p: fs.PathLike) => fs.Stats;
156
- // The follow-probe on the link itself reports a traversable directory,
157
- // matching the flavor createStagedSymlink would mint — fast path holds.
158
- vi.spyOn(fs, "statSync").mockImplementation(((p: fs.PathLike) =>
159
- p === localPath
160
- ? fakeStats({ dir: true })
161
- : realStatSync(p)) as typeof fs.statSync);
162
- const symlinkSpy = vi.spyOn(fs, "symlinkSync");
163
- const renameSpy = vi.spyOn(fs, "renameSync");
164
-
165
- const res = await downloadFile(
166
- makeCtx(),
167
- ".claude/skills/indigo:call-prep-brief",
168
- localPath,
169
- { win32: true },
170
- );
171
-
172
- expect(res.metadata).toBeDefined();
173
- expect(symlinkSpy).not.toHaveBeenCalled();
174
- expect(renameSpy).not.toHaveBeenCalled();
175
- });
176
-
177
- it("fast path accepts a JUNCTION's absolute substitute path against a relative wire target", async () => {
178
- // Post-#219, win32 directory overlays are materialized as junctions, and
179
- // a junction can only store an ABSOLUTE substitute path. readlink() of a
180
- // link this client itself created therefore returns
181
- // 'C:\\...\\companies\\indigo\\skills\\call-prep-brief' while the wire
182
- // target stays '../companies/...'. If equality were a raw string compare
183
- // the fast path could never fire for the link farm on Windows — every
184
- // pull would re-stage the whole farm, which is precisely the perpetual
185
- // churn US-001 exists to kill. Both sides must be resolved before compare.
186
- const wireTarget = "../companies/indigo/skills/call-prep-brief";
187
- const localPath = path.join(tmpRoot, "farm", "indigo%3Acall-prep-brief");
188
- fs.mkdirSync(path.dirname(localPath), { recursive: true });
189
- const absTarget = path.resolve(path.dirname(localPath), wireTarget);
190
- fs.mkdirSync(absTarget, { recursive: true });
191
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
192
-
193
- vi.spyOn(fs, "lstatSync").mockImplementation(() =>
194
- fakeStats({ symlink: true }),
195
- );
196
- vi.spyOn(fs, "readlinkSync").mockImplementation(() =>
197
- absTarget.split("/").join("\\"),
198
- );
199
- const realStatSync = fs.statSync.bind(fs) as (p: fs.PathLike) => fs.Stats;
200
- vi.spyOn(fs, "statSync").mockImplementation(((p: fs.PathLike) =>
201
- p === localPath
202
- ? fakeStats({ dir: true })
203
- : realStatSync(p)) as typeof fs.statSync);
204
- const symlinkSpy = vi.spyOn(fs, "symlinkSync");
205
- const renameSpy = vi.spyOn(fs, "renameSync");
206
-
207
- const res = await downloadFile(
208
- makeCtx(),
209
- ".claude/skills/indigo:call-prep-brief",
210
- localPath,
211
- { win32: true },
212
- );
213
-
214
- expect(res.metadata).toBeDefined();
215
- expect(symlinkSpy).not.toHaveBeenCalled();
216
- expect(renameSpy).not.toHaveBeenCalled();
217
- });
218
-
219
- it("win32: a FILE-flavor link at a DIRECTORY target is broken despite a matching target string — recreated as a junction, never fast-pathed", async () => {
220
- // Round-3 review P1: flavors matter on Windows. An older client (or a
221
- // pull that ran while the target dir was absent) can leave a file-type
222
- // link whose target string matches the incoming record exactly; it
223
- // still cannot be traversed. The fast path must fall through and the
224
- // materializer must mint the correct directory flavor — post-#219 that
225
- // is a junction (unprivileged) rather than a 'dir' NTFS symlink.
226
- const wireTarget = "../companies/indigo/skills/call-prep-brief";
227
- const localPath = path.join(tmpRoot, "farm", "indigo%3Acall-prep-brief");
228
- fs.mkdirSync(path.dirname(localPath), { recursive: true });
229
- const resolvedTarget = path.resolve(path.dirname(localPath), wireTarget);
230
- fs.mkdirSync(resolvedTarget, { recursive: true });
231
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
232
-
233
- const realStatSync = fs.statSync.bind(fs) as (p: fs.PathLike) => fs.Stats;
234
- vi.spyOn(fs, "lstatSync").mockImplementation(((p: fs.PathLike) =>
235
- p === localPath
236
- ? fakeStats({ symlink: true })
237
- : fakeStats({})) as typeof fs.lstatSync);
238
- vi.spyOn(fs, "readlinkSync").mockImplementation(
239
- (() => "..\\companies\\indigo\\skills\\call-prep-brief") as unknown as typeof fs.readlinkSync,
240
- );
241
- // Windows refuses to traverse the wrong-flavor link: stat on the link
242
- // throws, while the resolved target itself stats as a real directory.
243
- vi.spyOn(fs, "statSync").mockImplementation(((p: fs.PathLike) => {
244
- if (p === localPath) throw errnoError("EINVAL");
245
- return realStatSync(p);
246
- }) as typeof fs.statSync);
247
- const symlinkSpy = vi
248
- .spyOn(fs, "symlinkSync")
249
- .mockImplementation(() => undefined);
250
- vi.spyOn(fs, "unlinkSync").mockImplementation(() => undefined);
251
- vi.spyOn(fs, "renameSync").mockImplementation(() => undefined);
252
-
253
- await downloadFile(makeCtx(), ".claude/skills/indigo:call-prep-brief", localPath, {
254
- win32: true,
255
- });
256
-
257
- // Fell through the fast path and minted the correct flavor: a junction,
258
- // which requires an absolute substitute path.
259
- expect(symlinkSpy).toHaveBeenCalledTimes(1);
260
- expect(symlinkSpy.mock.calls[0]![2]).toBe("junction");
261
- expect(symlinkSpy.mock.calls[0]![0]).toBe(resolvedTarget);
262
- });
263
-
264
- it("win32: replaces a directory symlink via backup-swap, minting a junction temp link", async () => {
265
- // Failure signature 1 from the incident: EPERM on rename over
266
- // '...\\indigo%3Acall-prep-brief\\scripts' — the destination was a
267
- // directory symlink, which Windows rename() can never replace.
268
- // replaceStagedPath (upstream #193) swaps a symlink destination out to
269
- // a sibling backup, installs the staged link, then removes the backup.
270
- const wireTarget = "../companies/indigo/skills/call-prep-brief";
271
- const localPath = path.join(tmpRoot, "farm", "indigo%3Acall-prep-brief");
272
- fs.mkdirSync(path.dirname(localPath), { recursive: true });
273
- // Real directory at the resolved target so the type probe picks 'dir'.
274
- fs.mkdirSync(path.resolve(path.dirname(localPath), wireTarget), {
275
- recursive: true,
276
- });
277
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
278
-
279
- const realLstatSync = fs.lstatSync.bind(fs) as (p: fs.PathLike) => fs.Stats;
280
- const realStatSync = fs.statSync.bind(fs) as (p: fs.PathLike) => fs.Stats;
281
- // Destination is scripted as a live directory symlink to a STALE target.
282
- vi.spyOn(fs, "lstatSync").mockImplementation(((p: fs.PathLike) =>
283
- p === localPath
284
- ? fakeStats({ symlink: true })
285
- : realLstatSync(p)) as typeof fs.lstatSync);
286
- vi.spyOn(fs, "readlinkSync").mockImplementation(
287
- (() => "..\\stale\\old-skill") as unknown as typeof fs.readlinkSync,
288
- );
289
- vi.spyOn(fs, "statSync").mockImplementation(((p: fs.PathLike) =>
290
- p === localPath
291
- ? fakeStats({ dir: true })
292
- : realStatSync(p)) as typeof fs.statSync);
293
- const symlinkSpy = vi
294
- .spyOn(fs, "symlinkSync")
295
- .mockImplementation(() => undefined);
296
- const unlinkSpy = vi
297
- .spyOn(fs, "unlinkSync")
298
- .mockImplementation(() => undefined);
299
- const renameSpy = vi
300
- .spyOn(fs, "renameSync")
301
- .mockImplementation(() => undefined);
302
-
303
- await downloadFile(makeCtx(), ".claude/skills/indigo:call-prep-brief", localPath, {
304
- win32: true,
305
- });
306
-
307
- // Typed temp link: directory target ⇒ junction with an ABSOLUTE
308
- // substitute path (#219 — a bare symlinkSync mints a broken file-type
309
- // link, and a 'dir' NTFS symlink EPERMs without Developer Mode).
310
- expect(symlinkSpy).toHaveBeenCalledTimes(1);
311
- expect(symlinkSpy.mock.calls[0]![0]).toBe(
312
- path.resolve(path.dirname(localPath), wireTarget),
313
- );
314
- expect(String(symlinkSpy.mock.calls[0]![1])).toContain(".hq-tmp-");
315
- expect(symlinkSpy.mock.calls[0]![2]).toBe("junction");
316
- // Backup-swap: old link → .hq-backup-*, staged link → destination,
317
- // backup removed. The destination itself is never rm'd in place.
318
- expect(renameSpy).toHaveBeenCalledTimes(2);
319
- expect(renameSpy.mock.calls[0]![0]).toBe(localPath);
320
- expect(String(renameSpy.mock.calls[0]![1])).toContain(".hq-backup-");
321
- expect(String(renameSpy.mock.calls[1]![0])).toContain(".hq-tmp-");
322
- expect(renameSpy.mock.calls[1]![1]).toBe(localPath);
323
- expect(unlinkSpy).not.toHaveBeenCalledWith(localPath);
324
- expect(
325
- unlinkSpy.mock.calls.some((c) => String(c[0]).includes(".hq-backup-")),
326
- ).toBe(true);
327
- });
328
-
329
- it("win32: replaces a file symlink via backup-swap, minting a 'file'-type temp link", async () => {
330
- const wireTarget = "../personal/skills/dm/SKILL.md";
331
- const localPath = path.join(tmpRoot, "farm", "personal%3Adm");
332
- fs.mkdirSync(path.dirname(localPath), { recursive: true });
333
- // A GENUINE regular file at the resolved target — the only shape that
334
- // still earns a real 'file' symlink post-#219. An unresolvable target is
335
- // deliberately materialized as a junction instead (vault overlays are
336
- // directories, and a junction needs no Windows symlink privilege).
337
- const resolvedTarget = path.resolve(path.dirname(localPath), wireTarget);
338
- fs.mkdirSync(path.dirname(resolvedTarget), { recursive: true });
339
- fs.writeFileSync(resolvedTarget, "# dm skill");
340
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
341
-
342
- const realLstatSync = fs.lstatSync.bind(fs) as (p: fs.PathLike) => fs.Stats;
343
- vi.spyOn(fs, "lstatSync").mockImplementation(((p: fs.PathLike) =>
344
- p === localPath
345
- ? fakeStats({ symlink: true })
346
- : realLstatSync(p)) as typeof fs.lstatSync);
347
- vi.spyOn(fs, "readlinkSync").mockImplementation(
348
- (() => "..\\stale\\dm.md") as unknown as typeof fs.readlinkSync,
349
- );
350
- const symlinkSpy = vi
351
- .spyOn(fs, "symlinkSync")
352
- .mockImplementation(() => undefined);
353
- const rmdirSpy = vi.spyOn(fs, "rmdirSync");
354
- const unlinkSpy = vi
355
- .spyOn(fs, "unlinkSync")
356
- .mockImplementation(() => undefined);
357
- const renameSpy = vi
358
- .spyOn(fs, "renameSync")
359
- .mockImplementation(() => undefined);
360
-
361
- await downloadFile(makeCtx(), ".claude/skills/personal:dm", localPath, {
362
- win32: true,
363
- });
364
-
365
- expect(symlinkSpy.mock.calls[0]![2]).toBe("file");
366
- // Backup-swap: two renames (old→backup, staged→destination) and the
367
- // backup removed; the destination is never unlinked in place.
368
- expect(renameSpy).toHaveBeenCalledTimes(2);
369
- expect(unlinkSpy).not.toHaveBeenCalledWith(localPath);
370
- expect(
371
- unlinkSpy.mock.calls.some((c) => String(c[0]).includes(".hq-backup-")),
372
- ).toBe(true);
373
- expect(rmdirSpy).not.toHaveBeenCalledWith(localPath);
374
- });
375
-
376
- it("win32: NEVER deletes a real (non-symlink) directory — the rename failure surfaces", async () => {
377
- // The engine-level guarantee behind the caller's "manual reconciliation
378
- // required" warning: a real directory at the destination is the user's
379
- // data. The replace path may only remove SYMLINK destinations; a real
380
- // dir is left in place and the (scripted, Windows-faithful) EPERM from
381
- // rename-over-dir propagates.
382
- const wireTarget = "../companies/indigo/skills/capture";
383
- const localPath = path.join(tmpRoot, "farm", "indigo%3Acapture");
384
- fs.mkdirSync(localPath, { recursive: true }); // REAL directory
385
- fs.mkdirSync(path.resolve(path.dirname(localPath), wireTarget), {
386
- recursive: true,
387
- });
388
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
389
-
390
- vi.spyOn(fs, "symlinkSync").mockImplementation(() => undefined);
391
- const rmdirSpy = vi.spyOn(fs, "rmdirSync");
392
- const unlinkSpy = vi.spyOn(fs, "unlinkSync");
393
- const renameSpy = vi.spyOn(fs, "renameSync").mockImplementation(() => {
394
- throw errnoError("EPERM");
395
- });
396
-
397
- await expect(
398
- downloadFile(makeCtx(), ".claude/skills/indigo:capture", localPath, {
399
- win32: true,
400
- }),
401
- ).rejects.toThrow(/EPERM/);
402
-
403
- // Surfaced on the first failure — never silently swallowed, and a
404
- // non-symlink destination gets no backup-swap (nothing to roll back).
405
- expect(renameSpy).toHaveBeenCalledTimes(1);
406
- // The real directory was never removed (temp cleanup may touch the
407
- // .hq-tmp- path, but the destination itself is untouchable).
408
- expect(rmdirSpy).not.toHaveBeenCalledWith(localPath);
409
- expect(unlinkSpy).not.toHaveBeenCalledWith(localPath);
410
- expect(fs.statSync(localPath).isDirectory()).toBe(true);
411
- });
412
-
413
- it("POSIX: symlink destination is replaced cleanly — fresh target installed, no temp/backup litter", async () => {
414
- // replaceStagedPath backup-swaps symlink destinations on every
415
- // platform; the observable contract is a clean replacement with no
416
- // .hq-tmp-/.hq-backup- litter and a bare (no type hint) staged link.
417
- const localPath = path.join(tmpRoot, "posix-link.md");
418
- fs.symlinkSync("stale-target.md", localPath);
419
- setObjectIOFactory(() => symlinkRecordIO("fresh-target.md"));
420
-
421
- const symlinkSpy = vi.spyOn(fs, "symlinkSync");
422
-
423
- await downloadFile(makeCtx(), "posix-link.md", localPath, {
424
- win32: false,
425
- });
426
-
427
- expect(symlinkSpy).toHaveBeenCalledTimes(1);
428
- expect(symlinkSpy.mock.calls[0]![2]).toBeUndefined();
429
- expect(fs.readlinkSync(localPath)).toBe("fresh-target.md");
430
- const litter = fs
431
- .readdirSync(tmpRoot)
432
- .filter((n) => n.startsWith(".hq-tmp-") || n.startsWith(".hq-backup-"));
433
- expect(litter).toEqual([]);
434
- });
435
-
436
- it("2026-07-16 ENOENT mode (US-002): parents are created at the ENCODED local path, never the raw-colon path", async () => {
437
- // Failure signature 2 from the incident:
438
- // ENOENT mkdir 'C:\...\skills\indigo:team-agent-telemetry-report'
439
- // — the pre-codec caller handed downloadFile a RAW-key local path, and
440
- // Windows cannot mkdir a colon segment. The pull pipeline now derives
441
- // localPath through the codec (sync.ts resolveContainedVaultPath →
442
- // localPathForVaultKey); this pins the contract end-to-end: pulling the
443
- // incident's exact key with a codec-derived localPath materializes the
444
- // parent chain at `indigo%3Ateam-agent-telemetry-report`, and no
445
- // raw-colon sibling ever appears.
446
- const key = ".claude/skills/indigo:team-agent-telemetry-report/agents";
447
- const wireTarget =
448
- "../../../companies/indigo/skills/team-agent-telemetry-report/agents";
449
- const localPath = localPathForVaultKey(tmpRoot, key, true);
450
- setObjectIOFactory(() => symlinkRecordIO(wireTarget));
451
- // Leaf materialization is exercised by the suites above; this test is
452
- // about the parent chain, so the link+rename pair is inert.
453
- vi.spyOn(fs, "symlinkSync").mockImplementation(() => undefined);
454
- vi.spyOn(fs, "renameSync").mockImplementation(() => undefined);
455
-
456
- await downloadFile(makeCtx(), key, localPath, { win32: true });
457
-
458
- const encodedParent = path.join(
459
- tmpRoot,
460
- ".claude",
461
- "skills",
462
- "indigo%3Ateam-agent-telemetry-report",
463
- );
464
- expect(fs.existsSync(encodedParent)).toBe(true);
465
- expect(fs.statSync(encodedParent).isDirectory()).toBe(true);
466
- // The raw-colon spelling must not exist anywhere in the farm.
467
- expect(
468
- fs.readdirSync(path.join(tmpRoot, ".claude", "skills")),
469
- ).toEqual(["indigo%3Ateam-agent-telemetry-report"]);
470
- });
471
-
472
- it("POSIX: fast path also fires with exact string equality", async () => {
473
- // Separator normalization is win32-only; POSIX equality is exact (a
474
- // backslash is an ordinary filename character there). A separator-free
475
- // target makes this deterministic on any host platform.
476
- const target = "plain-target.md";
477
- const localPath = path.join(tmpRoot, "posix-noop.md");
478
- fs.symlinkSync(target, localPath);
479
- setObjectIOFactory(() => symlinkRecordIO(target));
480
-
481
- const symlinkSpy = vi.spyOn(fs, "symlinkSync");
482
- const renameSpy = vi.spyOn(fs, "renameSync");
483
-
484
- const res = await downloadFile(makeCtx(), "posix-noop.md", localPath, {
485
- win32: false,
486
- });
487
-
488
- expect(res.metadata).toBeDefined();
489
- expect(symlinkSpy).not.toHaveBeenCalled();
490
- expect(renameSpy).not.toHaveBeenCalled();
491
- });
492
- });