@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,548 +0,0 @@
1
- /**
2
- * Integration tests for the rescue classifier's fail-safe ordering and its
3
- * handling of nested directory symlinks (src/cli/rescue-core.ts).
4
- *
5
- * Regression for DEV-1767 (feedback_aa768683): `hq rescue` choked on a
6
- * symlinked DIRECTORY under core/ — a reindex artifact such as
7
- * `core/knowledge/ad-creative-engine -> ../../personal/knowledge/...` — throwing
8
- * `Error: Path is a directory` mid-pass *after* it had already deleted ~10 core
9
- * scaffold files, leaving HQ half-applied. `--check` classified the same tree
10
- * cleanly, so the dry-run gave false confidence.
11
- *
12
- * Two invariants are locked here:
13
- * 1. A directory symlink under core/ is classified as a droppable reindex
14
- * symlink (never followed, never file-read, never a crash) — exactly like
15
- * a file symlink. The personal/ target it points at is left untouched.
16
- * 2. Classification is read-only and runs to completion BEFORE any destructive
17
- * apply. A classifier exception therefore deletes NOTHING (no half-applied
18
- * wipe), and the same classify code path backs both the live run and the
19
- * `--dry-run` plan (parity).
20
- *
21
- * Like the sibling rescue tests, the source clone is shimmed to a local fixture
22
- * repo and the rescue runs in-process so we can assert its on-disk effects.
23
- */
24
- import { describe, it, expect, beforeAll, afterAll } from "vitest";
25
- import { execFileSync } from "child_process";
26
- import * as fs from "fs";
27
- import * as os from "os";
28
- import * as path from "path";
29
- import { runRescue } from "./rescue-core.js";
30
-
31
- function hasGit(): boolean {
32
- try {
33
- execFileSync("git", ["--version"], { stdio: "ignore" });
34
- return true;
35
- } catch {
36
- return false;
37
- }
38
- }
39
-
40
- const gitAvailable = hasGit();
41
-
42
- function runRescueCapture(argv: string[], env: NodeJS.ProcessEnv) {
43
- let stdout = "";
44
- let stderr = "";
45
- const origOut = process.stdout.write.bind(process.stdout);
46
- const origErr = process.stderr.write.bind(process.stderr);
47
- process.stdout.write = ((chunk: unknown) => {
48
- stdout += String(chunk);
49
- return true;
50
- }) as typeof process.stdout.write;
51
- process.stderr.write = ((chunk: unknown) => {
52
- stderr += String(chunk);
53
- return true;
54
- }) as typeof process.stderr.write;
55
- let status: number | undefined;
56
- let threw: unknown;
57
- try {
58
- status = runRescue(argv, { env }).status;
59
- } catch (e) {
60
- threw = e;
61
- } finally {
62
- process.stdout.write = origOut;
63
- process.stderr.write = origErr;
64
- }
65
- return { status, stdout, stderr, threw };
66
- }
67
-
68
- const lexists = (p: string) => {
69
- try {
70
- fs.lstatSync(p);
71
- return true;
72
- } catch {
73
- return false;
74
- }
75
- };
76
-
77
- function hasRecoveryManifestFor(root: string, rel: string): boolean {
78
- let found = false;
79
- const interesting = /(recover|recovery|rollback|transaction|manifest|resume|rescue)/i;
80
- const walk = (dir: string) => {
81
- if (found) return;
82
- let entries: fs.Dirent[];
83
- try {
84
- entries = fs.readdirSync(dir, { withFileTypes: true });
85
- } catch {
86
- return;
87
- }
88
- entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
89
- for (const ent of entries) {
90
- if (found) return;
91
- const abs = path.join(dir, ent.name);
92
- if (ent.isDirectory()) {
93
- walk(abs);
94
- continue;
95
- }
96
- if (!ent.isFile()) continue;
97
- const relPath = abs.slice(root.length + 1);
98
- if (!interesting.test(relPath)) continue;
99
- let body = "";
100
- try {
101
- body = fs.readFileSync(abs, "utf-8");
102
- } catch {
103
- body = "";
104
- }
105
- found = body.includes(rel) && interesting.test(`${relPath}\n${body}`);
106
- }
107
- };
108
- walk(root);
109
- return found;
110
- }
111
-
112
- describe.skipIf(!gitAvailable)("rescue classify-before-delete + dir-symlink handling", () => {
113
- let workDir: string;
114
- let upstream: string;
115
- let shimDir: string;
116
- let floorSha: string;
117
- let baseEnv: NodeJS.ProcessEnv;
118
- let caseSeq = 0;
119
-
120
- const git = (cwd: string, ...args: string[]) =>
121
- execFileSync("git", args, {
122
- cwd,
123
- stdio: ["ignore", "pipe", "pipe"],
124
- env: {
125
- ...process.env,
126
- GIT_AUTHOR_NAME: "t",
127
- GIT_AUTHOR_EMAIL: "t@t",
128
- GIT_COMMITTER_NAME: "t",
129
- GIT_COMMITTER_EMAIL: "t@t",
130
- },
131
- })
132
- .toString()
133
- .trim();
134
-
135
- beforeAll(() => {
136
- workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-ordering-"));
137
-
138
- // Upstream: floor has core/a.md="v1"; HEAD advances it to "v2". core/b.md is
139
- // stable across both. The symlink fixtures never appear upstream — they only
140
- // exist in the local HQ root as reindex artifacts.
141
- upstream = path.join(workDir, "upstream");
142
- fs.mkdirSync(path.join(upstream, "core"), { recursive: true });
143
- git(workDir, "init", "-b", "main", "upstream");
144
- fs.writeFileSync(path.join(upstream, "core/a.md"), "v1\n");
145
- fs.writeFileSync(path.join(upstream, "core/b.md"), "beta\n");
146
- // `.claude/settings.json` is intentionally not supplied by a personal
147
- // vault pull. Rescue must lay it down from the release scaffold instead.
148
- fs.mkdirSync(path.join(upstream, ".claude"), { recursive: true });
149
- fs.writeFileSync(path.join(upstream, ".claude/settings.json"), '{"release":true}\n');
150
- fs.mkdirSync(path.join(upstream, "core/blocker"), { recursive: true });
151
- fs.writeFileSync(path.join(upstream, "core/blocker/second.md"), "upstream\n");
152
- git(upstream, "add", "-A");
153
- git(upstream, "commit", "-m", "floor");
154
- floorSha = git(upstream, "rev-parse", "HEAD");
155
- fs.writeFileSync(path.join(upstream, "core/a.md"), "v2\n");
156
- git(upstream, "add", "-A");
157
- git(upstream, "commit", "-m", "head");
158
-
159
- const realGit =
160
- execFileSync("bash", ["-lc", "command -v git"]).toString().trim() || "/usr/bin/git";
161
- shimDir = path.join(workDir, "shim");
162
- fs.mkdirSync(shimDir, { recursive: true });
163
- const shim = `#!/usr/bin/env bash
164
- if [ "$1" = "clone" ]; then
165
- args=()
166
- for a in "$@"; do
167
- case "$a" in
168
- https://github.com/*) a=${JSON.stringify(upstream)} ;;
169
- esac
170
- args+=("$a")
171
- done
172
- exec ${JSON.stringify(realGit)} "\${args[@]}"
173
- fi
174
- exec ${JSON.stringify(realGit)} "$@"
175
- `;
176
- fs.writeFileSync(path.join(shimDir, "git"), shim, { mode: 0o755 });
177
- baseEnv = { ...process.env, PATH: `${shimDir}:${process.env.PATH ?? ""}` };
178
- });
179
-
180
- afterAll(() => {
181
- if (workDir) fs.rmSync(workDir, { recursive: true, force: true });
182
- });
183
-
184
- /**
185
- * Fresh HQ root per case (live runs mutate). core/a.md matches the floor
186
- * (unchanged vs baseline, differs from HEAD -> "delete + replace"); core/b.md
187
- * is byte-identical to upstream ("unchanged, preserved in place"). The caller
188
- * adds whatever symlink/extra files the case needs.
189
- */
190
- function makeHqRoot(): string {
191
- caseSeq += 1;
192
- const hqRoot = path.join(workDir, `hq-${caseSeq}`);
193
- fs.mkdirSync(path.join(hqRoot, "core"), { recursive: true });
194
- fs.mkdirSync(path.join(hqRoot, "companies"), { recursive: true });
195
- fs.mkdirSync(path.join(hqRoot, "personal/knowledge"), { recursive: true });
196
- fs.writeFileSync(path.join(hqRoot, "core/a.md"), "v1\n");
197
- fs.writeFileSync(path.join(hqRoot, "core/b.md"), "beta\n");
198
- return hqRoot;
199
- }
200
-
201
- const liveArgs = (hqRoot: string, extra: string[] = []) => [
202
- "--hq-root", hqRoot,
203
- "--source", "test/repo",
204
- "--ref", "main",
205
- "--floor-sha", floorSha,
206
- "--paths", "core",
207
- "--yes",
208
- "--no-backup",
209
- ...extra,
210
- ];
211
-
212
- it("drops a DIRECTORY symlink under core/ as a reindex artifact (no crash, no half-apply)", () => {
213
- const hqRoot = makeHqRoot();
214
- // The exact DEV-1767 shape: a directory symlink nested under core/ pointing
215
- // into personal/. Its target exists and must survive untouched.
216
- const target = path.join(hqRoot, "personal/knowledge/ad-creative-engine");
217
- fs.mkdirSync(target, { recursive: true });
218
- fs.writeFileSync(path.join(target, "keep.md"), "owned by personal\n");
219
- fs.mkdirSync(path.join(hqRoot, "core/knowledge"), { recursive: true });
220
- const link = path.join(hqRoot, "core/knowledge/ad-creative-engine");
221
- fs.symlinkSync("../../personal/knowledge/ad-creative-engine", link);
222
-
223
- const r = runRescueCapture(liveArgs(hqRoot), baseEnv);
224
- const out = `${r.stdout}\n${r.stderr}`;
225
-
226
- expect(r.threw, out).toBeUndefined();
227
- expect(r.status, out).toBe(0);
228
- // The bash-era failure signature must never appear.
229
- expect(out).not.toMatch(/Path is a directory/);
230
- expect(out).not.toMatch(/EISDIR/);
231
- // Classified + dropped as exactly one reindex symlink.
232
- expect(out).toMatch(/reindex symlinks dropped:\s+1 entries/);
233
- // Symlink itself is gone; its personal/ target is untouched.
234
- expect(lexists(link)).toBe(false);
235
- expect(fs.readFileSync(path.join(target, "keep.md"), "utf-8")).toBe("owned by personal\n");
236
- // Real core files still classified correctly around it.
237
- expect(fs.existsSync(path.join(hqRoot, "core/a.md"))).toBe(true);
238
- expect(fs.existsSync(path.join(hqRoot, "core/b.md"))).toBe(true);
239
- });
240
-
241
- it("classifies a NON-personal DIRECTORY symlink under core/ without following it (no crash, left in place)", () => {
242
- // A directory symlink whose target is NOT a reindex/personal artifact —
243
- // e.g. a user-made alias `core/aliasdir -> realdir`. It is not a
244
- // master-sync symlink, so rescue must NOT drop it, but it also must never
245
- // be followed/read (the EISDIR / "Path is a directory" trap from DEV-1767
246
- // applies to ANY directory symlink the walk meets, not just personal ones).
247
- const hqRoot = makeHqRoot();
248
- fs.mkdirSync(path.join(hqRoot, "core/realdir"), { recursive: true });
249
- fs.writeFileSync(path.join(hqRoot, "core/realdir/x.md"), "real\n");
250
- const link = path.join(hqRoot, "core/aliasdir");
251
- fs.symlinkSync("realdir", link); // points at a sibling DIRECTORY
252
-
253
- const r = runRescueCapture(liveArgs(hqRoot), baseEnv);
254
- const out = `${r.stdout}\n${r.stderr}`;
255
-
256
- expect(r.threw, out).toBeUndefined();
257
- expect(r.status, out).toBe(0);
258
- // The crash signatures must never appear for a dir-symlink of any flavour.
259
- expect(out).not.toMatch(/Path is a directory/);
260
- expect(out).not.toMatch(/EISDIR/);
261
- // Not a reindex artifact → not counted as a dropped symlink, left on disk,
262
- // and its directory target is untouched.
263
- expect(out).toMatch(/reindex symlinks dropped:\s+0 entries/);
264
- expect(lexists(link)).toBe(true);
265
- expect(fs.lstatSync(link).isSymbolicLink()).toBe(true);
266
- expect(fs.readFileSync(path.join(hqRoot, "core/realdir/x.md"), "utf-8")).toBe("real\n");
267
- });
268
-
269
- it("drops a FILE symlink under core/ the same way (file-symlink behavior unchanged)", () => {
270
- const hqRoot = makeHqRoot();
271
- fs.writeFileSync(path.join(hqRoot, "personal/knowledge/note.md"), "personal note\n");
272
- const link = path.join(hqRoot, "core/note.md");
273
- fs.symlinkSync("../personal/knowledge/note.md", link);
274
-
275
- const r = runRescueCapture(liveArgs(hqRoot), baseEnv);
276
- const out = `${r.stdout}\n${r.stderr}`;
277
-
278
- expect(r.threw, out).toBeUndefined();
279
- expect(r.status, out).toBe(0);
280
- expect(out).toMatch(/reindex symlinks dropped:\s+1 entries/);
281
- expect(lexists(link)).toBe(false);
282
- expect(fs.readFileSync(path.join(hqRoot, "personal/knowledge/note.md"), "utf-8")).toBe(
283
- "personal note\n",
284
- );
285
- });
286
-
287
- it("a classifier exception deletes NOTHING (classify fully before any destructive apply)", () => {
288
- const hqRoot = makeHqRoot();
289
- // core/a.md is classified BEFORE core/zzz.md (sorted walk) as a
290
- // "delete + replace". core/zzz.md then throws during classification. If the
291
- // wipe were interleaved (old behavior), a.md would already be gone.
292
- fs.writeFileSync(path.join(hqRoot, "core/zzz.md"), "trigger\n");
293
-
294
- const r = runRescueCapture(liveArgs(hqRoot), {
295
- ...baseEnv,
296
- HQ_RESCUE_FAULT_AT_REL: "core/zzz.md",
297
- });
298
- const out = `${r.stdout}\n${r.stderr}`;
299
-
300
- // The injected classifier fault aborts the run.
301
- expect(r.threw, out).toBeDefined();
302
- expect(String(r.threw)).toMatch(/fault injected at core\/zzz\.md/);
303
- // Crucially: the file that was already classified for deletion still exists,
304
- // untouched — no half-applied wipe.
305
- expect(fs.existsSync(path.join(hqRoot, "core/a.md"))).toBe(true);
306
- expect(fs.readFileSync(path.join(hqRoot, "core/a.md"), "utf-8")).toBe("v1\n");
307
- expect(fs.existsSync(path.join(hqRoot, "core/b.md"))).toBe(true);
308
- expect(fs.existsSync(path.join(hqRoot, "core/zzz.md"))).toBe(true);
309
- });
310
-
311
- it("dry-run emits prior plan lines before a classifier fault aborts the walk", () => {
312
- const hqRoot = makeHqRoot();
313
- fs.writeFileSync(path.join(hqRoot, "core/zzz.md"), "trigger\n");
314
-
315
- const r = runRescueCapture(liveArgs(hqRoot, ["--dry-run"]), {
316
- ...baseEnv,
317
- HQ_RESCUE_FAULT_AT_REL: "core/zzz.md",
318
- });
319
- const out = `${r.stdout}\n${r.stderr}`;
320
-
321
- expect(r.threw, out).toBeDefined();
322
- expect(String(r.threw)).toMatch(/fault injected at core\/zzz\.md/);
323
- expect(out).toContain("unchanged (delete + replace): core/a.md");
324
- expect(out).toContain("unchanged (preserved in place): core/b.md");
325
- expect(out).not.toMatch(/DRY RUN classification summary/);
326
- expect(fs.existsSync(path.join(hqRoot, "core/a.md"))).toBe(true);
327
- expect(fs.readFileSync(path.join(hqRoot, "core/a.md"), "utf-8")).toBe("v1\n");
328
- expect(fs.existsSync(path.join(hqRoot, "core/zzz.md"))).toBe(true);
329
- });
330
-
331
- it("F12: rolls back or records recovery when an apply action fails after earlier destructive actions", () => {
332
- const hqRoot = makeHqRoot();
333
- fs.mkdirSync(path.join(hqRoot, "core/blocker"), { recursive: true });
334
- fs.writeFileSync(path.join(hqRoot, "core/blocker/second.md"), "local edit\n");
335
- fs.writeFileSync(path.join(hqRoot, "personal/blocker"), "not a directory\n");
336
-
337
- const firstDeletedByApply = path.join(hqRoot, "core/a.md");
338
- const firstOriginal = fs.readFileSync(firstDeletedByApply, "utf-8");
339
- const r = runRescueCapture(liveArgs(hqRoot), baseEnv);
340
- const out = `${r.stdout}\n${r.stderr}\n${String(r.threw ?? "")}`;
341
-
342
- const applyFailed = r.threw !== undefined || (r.status !== undefined && r.status !== 0);
343
- expect(applyFailed, out).toBe(true);
344
- expect(fs.existsSync(path.join(hqRoot, "core/blocker/second.md")), out).toBe(true);
345
-
346
- const firstActionRolledBack =
347
- fs.existsSync(firstDeletedByApply) &&
348
- fs.readFileSync(firstDeletedByApply, "utf-8") === firstOriginal;
349
- expect(
350
- firstActionRolledBack || hasRecoveryManifestFor(hqRoot, "core/a.md"),
351
- `${out}\ncore/a.md was deleted without rollback or a recovery/transaction manifest`,
352
- ).toBe(true);
353
- });
354
-
355
- it("dry-run classifies the dir-symlink identically to the live run and changes nothing", () => {
356
- const hqRoot = makeHqRoot();
357
- const target = path.join(hqRoot, "personal/knowledge/ad-creative-engine");
358
- fs.mkdirSync(target, { recursive: true });
359
- fs.mkdirSync(path.join(hqRoot, "core/knowledge"), { recursive: true });
360
- const link = path.join(hqRoot, "core/knowledge/ad-creative-engine");
361
- fs.symlinkSync("../../personal/knowledge/ad-creative-engine", link);
362
-
363
- const r = runRescueCapture(liveArgs(hqRoot, ["--dry-run"]), baseEnv);
364
- const out = `${r.stdout}\n${r.stderr}`;
365
-
366
- expect(r.threw, out).toBeUndefined();
367
- expect(r.status, out).toBe(0);
368
- // Dry-run surfaces the SAME classification the live pass acts on.
369
- expect(out).toContain("drop reindex symlink: core/knowledge/ad-creative-engine");
370
- expect(out).toMatch(/reindex symlinks dropped:\s+1 entries/);
371
- expect(out).toMatch(/DRY RUN complete\. No filesystem changes made\./);
372
- // ...but touches nothing: the symlink (and everything else) is still on disk.
373
- expect(lexists(link)).toBe(true);
374
- expect(fs.existsSync(path.join(hqRoot, "core/a.md"))).toBe(true);
375
- });
376
-
377
- it("fails with a typed state-change error when reindex replaces a classified symlink before apply", () => {
378
- const hqRoot = makeHqRoot();
379
- const target = path.join(hqRoot, "personal/skills/foreman/tests");
380
- fs.mkdirSync(target, { recursive: true });
381
- const link = path.join(hqRoot, ".claude/skills/personal:foreman/tests");
382
- fs.mkdirSync(path.dirname(link), { recursive: true });
383
- fs.symlinkSync("../../../personal/skills/foreman/tests", link);
384
-
385
- const args = [
386
- "--hq-root", hqRoot,
387
- "--source", "test/repo",
388
- "--ref", "main",
389
- "--floor-sha", floorSha,
390
- "--yes",
391
- "--no-backup",
392
- ];
393
- const r = runRescueCapture(args, {
394
- ...baseEnv,
395
- HQ_RESCUE_FAULT_BEFORE_APPLY_REL: ".claude/skills/personal:foreman/tests",
396
- HQ_RESCUE_FAULT_BEFORE_APPLY_KIND: "directory",
397
- });
398
- const out = `${r.stdout}\n${r.stderr}\n${String(r.threw ?? "")}`;
399
-
400
- expect(r.threw, out).toBeInstanceOf(Error);
401
- expect(out).toContain("changed after classification");
402
- expect(out).toContain("expected symlink, found directory");
403
- expect(out).not.toContain("EISDIR");
404
- expect(fs.readFileSync(path.join(hqRoot, "core/a.md"), "utf-8")).toBe("v1\n");
405
- });
406
-
407
- it("keeps the full default wipe set out of worktrees and omits transient build state from the snapshot", () => {
408
- const hqRoot = makeHqRoot();
409
- const backupRoot = path.join(workDir, `backups-${caseSeq}`);
410
- const writeTransient = (rel: string) => {
411
- const dest = path.join(hqRoot, rel, "large.bin");
412
- fs.mkdirSync(path.dirname(dest), { recursive: true });
413
- fs.writeFileSync(dest, "reproducible\n");
414
- };
415
- for (const rel of [
416
- "worktrees/repo",
417
- ".worktrees/repo",
418
- ".sst-sandbox-home/runtime",
419
- ".tmp-codex-asar/cache",
420
- ".claude/worktrees/agent/repo",
421
- ".claude/skills/demo/node_modules/pkg",
422
- ".claude/skills/demo/.pnpm-store/v3",
423
- ".claude/skills/demo/.sst/build",
424
- ".claude/skills/demo/.next/cache",
425
- ".claude/skills/demo/target/debug",
426
- ]) {
427
- writeTransient(rel);
428
- }
429
-
430
- const r = runRescueCapture(
431
- [
432
- "--hq-root", hqRoot,
433
- "--source", "test/repo",
434
- "--ref", "main",
435
- "--floor-sha", floorSha,
436
- "--backup-dir", backupRoot,
437
- "--yes",
438
- ],
439
- baseEnv,
440
- );
441
- const out = `${r.stdout}\n${r.stderr}\n${String(r.threw ?? "")}`;
442
-
443
- expect(r.threw, out).toBeUndefined();
444
- expect(r.status, out).toBe(0);
445
- for (const rel of ["worktrees", ".worktrees", ".sst-sandbox-home", ".tmp-codex-asar"]) {
446
- expect(fs.existsSync(path.join(hqRoot, rel, "repo", "large.bin")) ||
447
- fs.existsSync(path.join(hqRoot, rel, "runtime", "large.bin")) ||
448
- fs.existsSync(path.join(hqRoot, rel, "cache", "large.bin")), rel).toBe(true);
449
- }
450
-
451
- const snapshots = fs.readdirSync(backupRoot).filter((name) => name.startsWith("pre-update-"));
452
- expect(snapshots).toHaveLength(1);
453
- const snapshot = path.join(backupRoot, snapshots[0]);
454
- expect(fs.existsSync(path.join(snapshot, "core/a.md"))).toBe(true);
455
- expect(fs.existsSync(path.join(snapshot, "RECOVERY.md"))).toBe(true);
456
- for (const rel of [
457
- "worktrees",
458
- ".worktrees",
459
- ".sst-sandbox-home",
460
- ".tmp-codex-asar",
461
- ".claude/worktrees",
462
- ".claude/skills/demo/node_modules",
463
- ".claude/skills/demo/.pnpm-store",
464
- ".claude/skills/demo/.sst",
465
- ".claude/skills/demo/.next",
466
- ".claude/skills/demo/target",
467
- ]) {
468
- expect(lexists(path.join(snapshot, rel)), `snapshot unexpectedly contains ${rel}`).toBe(false);
469
- }
470
- });
471
-
472
- it("preserves unreadable machine-local state while overlaying release-owned .claude files", () => {
473
- const hqRoot = makeHqRoot();
474
- const backupRoot = path.join(workDir, `local-state-backups-${caseSeq}`);
475
- const deviceId = path.join(hqRoot, ".local/state/gh/device-id");
476
- fs.mkdirSync(path.dirname(deviceId), { recursive: true });
477
- fs.writeFileSync(deviceId, "machine-specific\n");
478
- // SSM previously ran as root with an empty HOME, so gh could leave this
479
- // exact path root-owned and unreadable to the outpost user. A mode-000
480
- // fixture exercises the same copy failure without requiring root in CI.
481
- fs.chmodSync(deviceId, 0o000);
482
-
483
- try {
484
- const r = runRescueCapture(
485
- [
486
- "--hq-root", hqRoot,
487
- "--source", "test/repo",
488
- "--ref", "main",
489
- "--floor-sha", floorSha,
490
- "--backup-dir", backupRoot,
491
- "--yes",
492
- ],
493
- baseEnv,
494
- );
495
- const out = `${r.stdout}\n${r.stderr}\n${String(r.threw ?? "")}`;
496
-
497
- expect(r.threw, out).toBeUndefined();
498
- expect(r.status, out).toBe(0);
499
- // The core fixture proves a real rescue apply occurred, while this
500
- // release-owned setting proves `.claude` reached the outpost. The
501
- // post-overlay settings reconcile keeps the release baseline (`release:
502
- // true`) and additionally composes the machine env.PATH onto it (see
503
- // reconcileClaudeSettings), so the file is the release marker plus a
504
- // machine-specific env.PATH rather than the verbatim template.
505
- expect(fs.readFileSync(path.join(hqRoot, "core/a.md"), "utf-8")).toBe("v2\n");
506
- const laidSettings = JSON.parse(
507
- fs.readFileSync(path.join(hqRoot, ".claude/settings.json"), "utf-8"),
508
- );
509
- expect(laidSettings.release).toBe(true);
510
- expect(typeof laidSettings.env?.PATH).toBe("string");
511
- // `.local` survives untouched and is not copied into the safety snapshot.
512
- expect(fs.statSync(deviceId).mode & 0o777).toBe(0o000);
513
- const snapshots = fs.readdirSync(backupRoot).filter((name) => name.startsWith("pre-update-"));
514
- expect(snapshots).toHaveLength(1);
515
- expect(lexists(path.join(backupRoot, snapshots[0], ".local"))).toBe(false);
516
- } finally {
517
- // The fixture is owned by the test process, so restore readability before
518
- // the enclosing temp-tree cleanup even when an assertion fails.
519
- fs.chmodSync(deviceId, 0o600);
520
- }
521
- });
522
-
523
- it("dry-run never allocates or prunes snapshots", () => {
524
- const hqRoot = makeHqRoot();
525
- const backupRoot = path.join(workDir, `dry-backups-${caseSeq}`);
526
- const existing = path.join(backupRoot, "pre-update-existing");
527
- fs.mkdirSync(existing, { recursive: true });
528
- fs.writeFileSync(path.join(existing, "keep.txt"), "do not prune\n");
529
-
530
- const r = runRescueCapture(
531
- [
532
- "--hq-root", hqRoot,
533
- "--source", "test/repo",
534
- "--ref", "main",
535
- "--floor-sha", floorSha,
536
- "--backup-dir", backupRoot,
537
- "--dry-run",
538
- ],
539
- baseEnv,
540
- );
541
- const out = `${r.stdout}\n${r.stderr}\n${String(r.threw ?? "")}`;
542
-
543
- expect(r.threw, out).toBeUndefined();
544
- expect(r.status, out).toBe(0);
545
- expect(fs.readdirSync(backupRoot)).toEqual(["pre-update-existing"]);
546
- expect(fs.readFileSync(path.join(existing, "keep.txt"), "utf-8")).toBe("do not prune\n");
547
- });
548
- });
@@ -1,120 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from "vitest";
2
- import * as fs from "fs";
3
- import * as os from "os";
4
- import * as path from "path";
5
- import { runRescue } from "./rescue-core.js";
6
-
7
- function runRescueCapture(argv: string[], env: NodeJS.ProcessEnv) {
8
- let stdout = "";
9
- let stderr = "";
10
- const origOut = process.stdout.write.bind(process.stdout);
11
- const origErr = process.stderr.write.bind(process.stderr);
12
- process.stdout.write = ((chunk: unknown) => {
13
- stdout += String(chunk);
14
- return true;
15
- }) as typeof process.stdout.write;
16
- process.stderr.write = ((chunk: unknown) => {
17
- stderr += String(chunk);
18
- return true;
19
- }) as typeof process.stderr.write;
20
- let status: number;
21
- try {
22
- status = runRescue(argv, { env }).status;
23
- } finally {
24
- process.stdout.write = origOut;
25
- process.stderr.write = origErr;
26
- }
27
- return { status, stdout, stderr };
28
- }
29
-
30
- describe("rescue clone diagnostics", () => {
31
- let workDir: string;
32
- let hqRoot: string;
33
-
34
- beforeAll(() => {
35
- workDir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-rescue-clone-diagnostics-"));
36
- hqRoot = path.join(workDir, "hq");
37
- fs.mkdirSync(path.join(hqRoot, "companies"), { recursive: true });
38
- fs.mkdirSync(path.join(hqRoot, "core"), { recursive: true });
39
- });
40
-
41
- afterAll(() => {
42
- if (workDir) fs.rmSync(workDir, { recursive: true, force: true });
43
- });
44
-
45
- function envWithGit(name: string, script: string): NodeJS.ProcessEnv {
46
- const shimDir = path.join(workDir, name);
47
- fs.mkdirSync(shimDir, { recursive: true });
48
- fs.writeFileSync(path.join(shimDir, "git"), script, { mode: 0o755 });
49
- return {
50
- ...process.env,
51
- GH_TOKEN: "ghp_clone_secret_123",
52
- PATH: `${shimDir}:${process.env.PATH ?? ""}`,
53
- };
54
- }
55
-
56
- function rescueArgs(extra: string[] = []): string[] {
57
- return [
58
- "--hq-root", hqRoot,
59
- "--source", "test/repo",
60
- "--ref", "main",
61
- "--dry-run",
62
- "--yes",
63
- "--no-backup",
64
- ...extra,
65
- ];
66
- }
67
-
68
- it("surfaces redacted stderr when the full-history clone fails", () => {
69
- const env = envWithGit(
70
- "full-history",
71
- `#!/usr/bin/env bash
72
- printf 'fatal: clone args: %s\n' "$*" >&2
73
- printf 'mirror: https://user:url-secret@example.com/repo.git\n' >&2
74
- printf 'Authorization: Bearer header-secret\n' >&2
75
- exit 42
76
- `,
77
- );
78
-
79
- const r = runRescueCapture(rescueArgs(), env);
80
-
81
- expect(r.status).toBe(5);
82
- expect(r.stderr).toContain("fatal: clone args:");
83
- expect(r.stderr).toContain("https://***@github.com/test/repo.git");
84
- expect(r.stderr).toContain("mirror: https://***@example.com/repo.git");
85
- expect(r.stderr).toContain("Authorization: ***");
86
- expect(r.stderr).toContain("error: clone failed");
87
- expect(r.stderr.indexOf("fatal: clone args:")).toBeLessThan(
88
- r.stderr.indexOf("error: clone failed"),
89
- );
90
- expect(r.stderr).not.toContain("ghp_clone_secret_123");
91
- expect(r.stderr).not.toContain("url-secret");
92
- expect(r.stderr).not.toContain("header-secret");
93
- });
94
-
95
- it("surfaces stderr from the shallow attempt and stdout from the failed fallback", () => {
96
- const env = envWithGit(
97
- "shallow-fallback",
98
- `#!/usr/bin/env bash
99
- if [ "$2" = "--depth" ]; then
100
- printf 'fatal: shallow clone diagnostic\n' >&2
101
- exit 41
102
- fi
103
- printf 'fatal: fallback clone diagnostic for %s\n' "$*"
104
- exit 42
105
- `,
106
- );
107
-
108
- const r = runRescueCapture(rescueArgs(["--no-history-check"]), env);
109
-
110
- expect(r.status).toBe(5);
111
- expect(r.stderr).toContain("fatal: shallow clone diagnostic");
112
- expect(r.stderr).toContain("fatal: fallback clone diagnostic");
113
- expect(r.stderr).toContain("https://***@github.com/test/repo.git");
114
- expect(r.stderr).toContain("error: clone failed");
115
- expect(r.stderr.indexOf("fatal: fallback clone diagnostic")).toBeLessThan(
116
- r.stderr.indexOf("error: clone failed"),
117
- );
118
- expect(r.stderr).not.toContain("ghp_clone_secret_123");
119
- });
120
- });