@indigoai-us/hq-cli 5.77.14 → 5.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/assets/scaffold/core/scripts/archive-old-threads.sh +86 -0
  3. package/assets/scaffold/core/scripts/backfill-company-skill-mirrors.sh +73 -0
  4. package/assets/scaffold/core/scripts/backfill-workspace-mirror.sh +51 -0
  5. package/assets/scaffold/core/scripts/codex-skill-bridge.sh +550 -0
  6. package/assets/scaffold/core/scripts/detect-stale-core-policy-mirror.sh +185 -0
  7. package/assets/scaffold/core/scripts/hq-status-summary.sh +187 -0
  8. package/assets/scaffold/core/scripts/ontology-readme-drift.sh +264 -0
  9. package/assets/scaffold/core/scripts/qmd-reindex-after-sync.sh +93 -0
  10. package/assets/scaffold/core/scripts/rebuild-all-indexes.sh +69 -0
  11. package/assets/scaffold/core/scripts/rebuild-companies-index.sh +206 -0
  12. package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +127 -0
  13. package/assets/scaffold/core/scripts/rebuild-orchestrator-index.sh +86 -0
  14. package/assets/scaffold/core/scripts/rebuild-projects-index.sh +105 -0
  15. package/assets/scaffold/core/scripts/rebuild-public-knowledge-index.sh +83 -0
  16. package/assets/scaffold/core/scripts/rebuild-reports-index.sh +114 -0
  17. package/assets/scaffold/core/scripts/rebuild-social-drafts-index.sh +135 -0
  18. package/assets/scaffold/core/scripts/rebuild-threads-index.sh +82 -0
  19. package/assets/scaffold/core/scripts/rebuild-workers-index.sh +97 -0
  20. package/assets/scaffold/core/scripts/resize-screenshot.sh +47 -0
  21. package/assets/scaffold/core/scripts/token-usage-report.sh +254 -0
  22. package/assets/scaffold/core/scripts/worktree.sh +136 -0
  23. package/dist/commands/agents.js +28 -12
  24. package/dist/commands/api-keys.js +100 -20
  25. package/dist/commands/core.d.ts +90 -0
  26. package/dist/commands/core.js +279 -0
  27. package/dist/commands/files-browse.d.ts +21 -0
  28. package/dist/commands/files-browse.js +145 -24
  29. package/dist/commands/files.js +33 -7
  30. package/dist/commands/meetings.js +16 -9
  31. package/dist/commands/members.js +16 -5
  32. package/dist/commands/pack-install.d.ts +14 -0
  33. package/dist/commands/pack-install.js +42 -2
  34. package/dist/commands/pkg-install.js +39 -2
  35. package/dist/commands/run.js +6 -2
  36. package/dist/commands/secrets.js +120 -65
  37. package/dist/main.js +6 -0
  38. package/dist/utils/api-key-command-gate.d.ts +45 -0
  39. package/dist/utils/api-key-command-gate.js +51 -0
  40. package/dist/utils/hq-roots.d.ts +91 -0
  41. package/dist/utils/hq-roots.js +212 -0
  42. package/dist/utils/resolve-vault-credential.d.ts +63 -3
  43. package/dist/utils/resolve-vault-credential.js +152 -6
  44. package/dist/utils/run-bundled-script.d.ts +66 -0
  45. package/dist/utils/run-bundled-script.js +80 -0
  46. package/dist/utils/vault-api.d.ts +21 -0
  47. package/dist/utils/vault-api.js +74 -3
  48. package/package.json +7 -1
  49. package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
  50. package/.github/workflows/ci.yml +0 -46
  51. package/.github/workflows/publish.yml +0 -36
  52. package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
  53. package/e2e/cli.test.ts +0 -128
  54. package/eslint.config.js +0 -37
  55. package/pnpm-workspace.yaml +0 -4
  56. package/scripts/chmod-bins.mjs +0 -49
  57. package/scripts/generate-dsn.mjs +0 -26
  58. package/scripts/generate-scan-packages-table.mjs +0 -113
  59. package/scripts/smoke-sources-signals.sh +0 -103
  60. package/src/bin/hq-auth-refresh.ts +0 -43
  61. package/src/cli-version.ts +0 -13
  62. package/src/commands/__fixtures__/make-tar.ts +0 -126
  63. package/src/commands/_patterns.ts +0 -10
  64. package/src/commands/add.ts +0 -75
  65. package/src/commands/agents.test.ts +0 -527
  66. package/src/commands/agents.ts +0 -923
  67. package/src/commands/api-keys.test.ts +0 -291
  68. package/src/commands/api-keys.ts +0 -382
  69. package/src/commands/artifact-verify.test.ts +0 -177
  70. package/src/commands/auth.test.ts +0 -82
  71. package/src/commands/auth.ts +0 -213
  72. package/src/commands/billing.test.ts +0 -158
  73. package/src/commands/billing.ts +0 -146
  74. package/src/commands/channels.test.ts +0 -74
  75. package/src/commands/channels.ts +0 -91
  76. package/src/commands/cloud-demote.test.ts +0 -401
  77. package/src/commands/cloud-demote.ts +0 -278
  78. package/src/commands/cloud-provision.test.ts +0 -1117
  79. package/src/commands/cloud-provision.ts +0 -942
  80. package/src/commands/cloud.pull-all.test.ts +0 -711
  81. package/src/commands/cloud.pull-per-company.test.ts +0 -188
  82. package/src/commands/cloud.push-all.test.ts +0 -485
  83. package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
  84. package/src/commands/cloud.selectors.test.ts +0 -208
  85. package/src/commands/cloud.status.test.ts +0 -160
  86. package/src/commands/cloud.test.ts +0 -41
  87. package/src/commands/cloud.ts +0 -2130
  88. package/src/commands/company.test.ts +0 -202
  89. package/src/commands/company.ts +0 -148
  90. package/src/commands/creators.test.ts +0 -60
  91. package/src/commands/creators.ts +0 -117
  92. package/src/commands/crm.test.ts +0 -179
  93. package/src/commands/crm.ts +0 -236
  94. package/src/commands/db-migrate.ts +0 -55
  95. package/src/commands/db-provision.ts +0 -114
  96. package/src/commands/db-sql.ts +0 -124
  97. package/src/commands/db-status.ts +0 -108
  98. package/src/commands/db.ts +0 -26
  99. package/src/commands/dm.test.ts +0 -748
  100. package/src/commands/dm.ts +0 -1226
  101. package/src/commands/feedback.test.ts +0 -413
  102. package/src/commands/feedback.ts +0 -169
  103. package/src/commands/files-browse.test.ts +0 -1249
  104. package/src/commands/files-browse.ts +0 -1506
  105. package/src/commands/files-delete.test.ts +0 -484
  106. package/src/commands/files-recovery.test.ts +0 -370
  107. package/src/commands/files.test.ts +0 -722
  108. package/src/commands/files.ts +0 -1446
  109. package/src/commands/group-grants.test.ts +0 -330
  110. package/src/commands/group-grants.ts +0 -455
  111. package/src/commands/groups.test.ts +0 -44
  112. package/src/commands/groups.ts +0 -368
  113. package/src/commands/integrations.test.ts +0 -633
  114. package/src/commands/integrations.ts +0 -507
  115. package/src/commands/list.ts +0 -85
  116. package/src/commands/login.ts +0 -52
  117. package/src/commands/logout.ts +0 -30
  118. package/src/commands/marketplace-install.test.ts +0 -543
  119. package/src/commands/marketplace-security.test.ts +0 -646
  120. package/src/commands/mcp-registration.test.ts +0 -2787
  121. package/src/commands/mcp-registration.ts +0 -2612
  122. package/src/commands/mcp-status.test.ts +0 -483
  123. package/src/commands/mcp-status.ts +0 -575
  124. package/src/commands/mcp-status.us011.test.ts +0 -243
  125. package/src/commands/meetings.test.ts +0 -522
  126. package/src/commands/meetings.ts +0 -789
  127. package/src/commands/members.test.ts +0 -1474
  128. package/src/commands/members.ts +0 -1181
  129. package/src/commands/onboard-identity-guard.test.ts +0 -99
  130. package/src/commands/onboard-identity-guard.ts +0 -103
  131. package/src/commands/onboard-join.test.ts +0 -96
  132. package/src/commands/onboard-join.ts +0 -101
  133. package/src/commands/onboard-warning.test.ts +0 -26
  134. package/src/commands/onboard-warning.ts +0 -12
  135. package/src/commands/onboard.ts +0 -267
  136. package/src/commands/outposts-heartbeat.test.ts +0 -299
  137. package/src/commands/outposts-heartbeat.ts +0 -310
  138. package/src/commands/outposts-replica-sync.test.ts +0 -272
  139. package/src/commands/outposts-self-deploy.test.ts +0 -243
  140. package/src/commands/outposts.test.ts +0 -1039
  141. package/src/commands/outposts.ts +0 -1935
  142. package/src/commands/pack-install-secret-authorization.test.ts +0 -115
  143. package/src/commands/pack-install.test.ts +0 -1469
  144. package/src/commands/pack-install.ts +0 -2256
  145. package/src/commands/pack-update-cache.test.ts +0 -149
  146. package/src/commands/packs-update-api-key.test.ts +0 -105
  147. package/src/commands/packs.test.ts +0 -88
  148. package/src/commands/packs.ts +0 -622
  149. package/src/commands/people.test.ts +0 -807
  150. package/src/commands/people.ts +0 -422
  151. package/src/commands/pkg-install.dispatch.test.ts +0 -103
  152. package/src/commands/pkg-install.ts +0 -221
  153. package/src/commands/pkg-list.test.ts +0 -79
  154. package/src/commands/pkg-list.ts +0 -13
  155. package/src/commands/pkg-remove.ts +0 -71
  156. package/src/commands/pkg-update.ts +0 -189
  157. package/src/commands/publish.test.ts +0 -650
  158. package/src/commands/publish.ts +0 -580
  159. package/src/commands/reindex.test.ts +0 -259
  160. package/src/commands/reindex.ts +0 -274
  161. package/src/commands/rescue.test.ts +0 -39
  162. package/src/commands/rescue.ts +0 -210
  163. package/src/commands/run.env-local.test.ts +0 -88
  164. package/src/commands/run.test.ts +0 -45
  165. package/src/commands/run.ts +0 -190
  166. package/src/commands/safe-extract.test.ts +0 -459
  167. package/src/commands/safe-extract.ts +0 -444
  168. package/src/commands/secrets-scope.test.ts +0 -56
  169. package/src/commands/secrets-scope.ts +0 -32
  170. package/src/commands/secrets.parse-destination.test.ts +0 -38
  171. package/src/commands/secrets.test.ts +0 -2050
  172. package/src/commands/secrets.ts +0 -2249
  173. package/src/commands/signals.ts +0 -351
  174. package/src/commands/skill.test.ts +0 -770
  175. package/src/commands/skill.ts +0 -796
  176. package/src/commands/sources.ts +0 -362
  177. package/src/commands/sync-mode.test.ts +0 -366
  178. package/src/commands/sync-mode.ts +0 -387
  179. package/src/commands/sync-narrow.test.ts +0 -633
  180. package/src/commands/sync-narrow.ts +0 -555
  181. package/src/commands/sync.ts +0 -165
  182. package/src/commands/team-sync.ts +0 -628
  183. package/src/commands/update.ts +0 -71
  184. package/src/commands/whoami.ts +0 -83
  185. package/src/commands/workers.test.ts +0 -158
  186. package/src/commands/workers.ts +0 -301
  187. package/src/index.test.ts +0 -32
  188. package/src/index.ts +0 -20
  189. package/src/lib/db/control-plane.test.ts +0 -59
  190. package/src/lib/db/control-plane.ts +0 -113
  191. package/src/lib/db/local.test.ts +0 -81
  192. package/src/lib/db/local.ts +0 -148
  193. package/src/lib/db/migrate.test.ts +0 -133
  194. package/src/lib/db/migrate.ts +0 -137
  195. package/src/lib/db/paths.test.ts +0 -112
  196. package/src/lib/db/paths.ts +0 -128
  197. package/src/lib/db/remote-engine.test.ts +0 -44
  198. package/src/lib/db/remote-engine.ts +0 -148
  199. package/src/lib/db/remote-sql.test.ts +0 -32
  200. package/src/lib/db/remote-sql.ts +0 -62
  201. package/src/lib/db/sql.test.ts +0 -106
  202. package/src/lib/db/sql.ts +0 -192
  203. package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
  204. package/src/lib/local-tree-diff.test.ts +0 -301
  205. package/src/lib/local-tree-diff.ts +0 -362
  206. package/src/lib/narrow-hint-banner.test.ts +0 -235
  207. package/src/lib/narrow-hint-banner.ts +0 -212
  208. package/src/lib/plan-limit-nag.test.ts +0 -317
  209. package/src/lib/plan-limit-nag.ts +0 -264
  210. package/src/main.ts +0 -371
  211. package/src/node-preflight.test.ts +0 -60
  212. package/src/node-preflight.ts +0 -67
  213. package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
  214. package/src/outpost/session-heartbeat-guard.test.ts +0 -105
  215. package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
  216. package/src/outpost/session-heartbeat-publisher.ts +0 -186
  217. package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
  218. package/src/outpost/session-heartbeat.test.ts +0 -459
  219. package/src/outpost/session-heartbeat.ts +0 -877
  220. package/src/packaging.test.ts +0 -109
  221. package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
  222. package/src/run/discover-schemas.test.ts +0 -153
  223. package/src/run/discover-schemas.ts +0 -79
  224. package/src/run/hq-plugin.test.ts +0 -371
  225. package/src/run/hq-plugin.ts +0 -277
  226. package/src/run/varlock-shape.test.ts +0 -57
  227. package/src/schemas/hq-package.schema.json +0 -155
  228. package/src/sentry-before-send.test.ts +0 -359
  229. package/src/sentry-before-send.ts +0 -221
  230. package/src/sentry-epipe.test.ts +0 -37
  231. package/src/sentry-release.test.ts +0 -54
  232. package/src/sentry.test.ts +0 -24
  233. package/src/sentry.ts +0 -54
  234. package/src/strategies/link.ts +0 -62
  235. package/src/strategies/merge.ts +0 -142
  236. package/src/types.ts +0 -146
  237. package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
  238. package/src/utils/auth-error.test.ts +0 -40
  239. package/src/utils/auth-error.ts +0 -42
  240. package/src/utils/billing-gate.test.ts +0 -95
  241. package/src/utils/billing-gate.ts +0 -228
  242. package/src/utils/breadcrumb-buffer.ts +0 -18
  243. package/src/utils/cli-telemetry.test.ts +0 -153
  244. package/src/utils/cli-telemetry.ts +0 -61
  245. package/src/utils/cognito-session.machine.test.ts +0 -109
  246. package/src/utils/cognito-session.refresh.test.ts +0 -84
  247. package/src/utils/cognito-session.test.ts +0 -328
  248. package/src/utils/cognito-session.ts +0 -448
  249. package/src/utils/company-selection-error.test.ts +0 -42
  250. package/src/utils/company-selection-error.ts +0 -45
  251. package/src/utils/contribution-table.ts +0 -83
  252. package/src/utils/environmental-error.test.ts +0 -45
  253. package/src/utils/environmental-error.ts +0 -39
  254. package/src/utils/epipe.test.ts +0 -28
  255. package/src/utils/epipe.ts +0 -29
  256. package/src/utils/expected-cli-error.test.ts +0 -28
  257. package/src/utils/expected-cli-error.ts +0 -39
  258. package/src/utils/feedback-diagnostics.test.ts +0 -183
  259. package/src/utils/feedback-diagnostics.ts +0 -123
  260. package/src/utils/feedback-screenshots.test.ts +0 -134
  261. package/src/utils/feedback-screenshots.ts +0 -124
  262. package/src/utils/feedback-versions.test.ts +0 -98
  263. package/src/utils/feedback-versions.ts +0 -68
  264. package/src/utils/git.ts +0 -74
  265. package/src/utils/integrity.ts +0 -59
  266. package/src/utils/intercepted-process-exit.test.ts +0 -37
  267. package/src/utils/intercepted-process-exit.ts +0 -36
  268. package/src/utils/login-provider.test.ts +0 -42
  269. package/src/utils/login-provider.ts +0 -30
  270. package/src/utils/manifest.test.ts +0 -167
  271. package/src/utils/manifest.ts +0 -131
  272. package/src/utils/pack-contributions.test.ts +0 -603
  273. package/src/utils/pack-contributions.ts +0 -450
  274. package/src/utils/people.ts +0 -215
  275. package/src/utils/registry-client.ts +0 -204
  276. package/src/utils/registry.ts +0 -90
  277. package/src/utils/resolve-vault-credential.test.ts +0 -69
  278. package/src/utils/resolve-vault-credential.ts +0 -60
  279. package/src/utils/sandbox-runner-client.test.ts +0 -279
  280. package/src/utils/sandbox-runner-client.ts +0 -260
  281. package/src/utils/secrets-cache.ts +0 -183
  282. package/src/utils/sentry-identity.ts +0 -45
  283. package/src/utils/settle-with-timeout.test.ts +0 -21
  284. package/src/utils/settle-with-timeout.ts +0 -22
  285. package/src/utils/user-yaml-error.test.ts +0 -24
  286. package/src/utils/user-yaml-error.ts +0 -30
  287. package/src/utils/vault-api.test.ts +0 -536
  288. package/src/utils/vault-api.ts +0 -382
  289. package/src/utils/version-check.test.ts +0 -176
  290. package/src/utils/version-check.ts +0 -155
  291. package/src/utils/version-gate.test.ts +0 -1024
  292. package/src/utils/version-gate.ts +0 -702
  293. package/test/commands/db-tenant-isolation.test.ts +0 -94
  294. package/test/commands/db.test.ts +0 -85
  295. package/test/commands/signals.test.ts +0 -207
  296. package/test/commands/sources.test.ts +0 -231
  297. package/test/e2e/smoke-install-mcp.sh +0 -113
  298. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
  299. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
  300. package/test/fixtures/signals/action_item/sample.md +0 -16
  301. package/test/fixtures/signals/summary/sample.md +0 -12
  302. package/test/fixtures/sources/meetings/sample.md +0 -25
  303. package/test/helpers/cli-runner.ts +0 -150
  304. package/test/helpers/s3-list-mock.ts +0 -79
  305. package/test/helpers/vault-service-mock.ts +0 -295
  306. package/test/sources-signals/smoke.test.ts +0 -228
  307. package/tsconfig.json +0 -20
  308. package/vitest.config.ts +0 -11
  309. package/vitest.e2e.config.ts +0 -7
@@ -1,1024 +0,0 @@
1
- /**
2
- * Tests for the version-gate module. Hermetic — no network, no spawn.
3
- *
4
- * Pinning CLI_VERSION via the same mock pattern used by version-check.test.ts
5
- * (`vi.mock('../cli-version.js', …)`) so the gate request body is
6
- * deterministic.
7
- */
8
-
9
- import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
10
-
11
- vi.mock("../cli-version.js", () => ({
12
- CLI_VERSION: "5.10.0",
13
- CLI_NAME: "@indigoai-us/hq-cli",
14
- }));
15
-
16
- beforeEach(() => {
17
- vi.unstubAllEnvs();
18
- vi.restoreAllMocks();
19
- });
20
-
21
- afterEach(() => {
22
- vi.unstubAllEnvs();
23
- vi.restoreAllMocks();
24
- });
25
-
26
- async function loadModule() {
27
- vi.resetModules();
28
- return await import("./version-gate.js");
29
- }
30
-
31
- /**
32
- * `RunningInstall` fixtures. `resolveRunningInstall()` is the single
33
- * package-root walk the gate performs, so tests inject its result rather than
34
- * a manager and a prefix separately.
35
- */
36
- function npmInstall(prefix: string | null) {
37
- return { manager: "npm" as const, prefix, packageRoot: null };
38
- }
39
-
40
- function pnpmInstall() {
41
- // pnpm-managed installs never carry a prefix — see resolveRunningInstall().
42
- return {
43
- manager: "pnpm" as const,
44
- prefix: null,
45
- packageRoot:
46
- "/Users/x/Library/pnpm/global/5/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli",
47
- };
48
- }
49
-
50
- describe("shouldSkipGate", () => {
51
- it("returns true for --version", async () => {
52
- const { shouldSkipGate } = await loadModule();
53
- expect(shouldSkipGate(["node", "hq", "--version"])).toBe(true);
54
- });
55
-
56
- it("returns true for -V, -v, --help, -h", async () => {
57
- const { shouldSkipGate } = await loadModule();
58
- expect(shouldSkipGate(["node", "hq", "-V"])).toBe(true);
59
- expect(shouldSkipGate(["node", "hq", "-v"])).toBe(true);
60
- expect(shouldSkipGate(["node", "hq", "--help"])).toBe(true);
61
- expect(shouldSkipGate(["node", "hq", "-h"])).toBe(true);
62
- });
63
-
64
- it("returns false for a regular subcommand", async () => {
65
- const { shouldSkipGate } = await loadModule();
66
- expect(shouldSkipGate(["node", "hq", "sync"])).toBe(false);
67
- expect(shouldSkipGate(["node", "hq", "members", "list"])).toBe(false);
68
- });
69
- });
70
-
71
- describe("prefix install helpers", () => {
72
- it("derives the npm prefix from unix global package layouts", async () => {
73
- const { __test__ } = await loadModule();
74
- expect(
75
- __test__.npmPrefixFromPackageDir(
76
- "/Users/x/Library/Application Support/Indigo HQ/toolchain/npm-global/lib/node_modules/@indigoai-us/hq-cli",
77
- ),
78
- ).toBe("/Users/x/Library/Application Support/Indigo HQ/toolchain/npm-global");
79
- expect(
80
- __test__.npmPrefixFromPackageDir(
81
- "/usr/local/lib/node_modules/@indigoai-us/hq-cli",
82
- ),
83
- ).toBe("/usr/local");
84
- });
85
-
86
- it("derives the npm prefix from a windows-style package layout", async () => {
87
- const { __test__ } = await loadModule();
88
- expect(
89
- __test__.npmPrefixFromPackageDir(
90
- "C:\\Users\\x\\AppData\\Roaming\\npm\\node_modules\\@indigoai-us\\hq-cli",
91
- ),
92
- ).toBe("C:/Users/x/AppData/Roaming/npm");
93
- });
94
-
95
- it("returns null when the package path is not under node_modules", async () => {
96
- const { __test__ } = await loadModule();
97
- expect(
98
- __test__.npmPrefixFromPackageDir(
99
- "/Users/x/dev/hq/packages/hq-cli",
100
- ),
101
- ).toBeNull();
102
- });
103
-
104
- it("builds the prefixed npm install argv", async () => {
105
- const { __test__ } = await loadModule();
106
- expect(__test__.buildPrefixedInstallArgv("/tmp/npm-global")).toEqual([
107
- "install",
108
- "-g",
109
- "--prefix",
110
- "/tmp/npm-global",
111
- "@indigoai-us/hq-cli@latest",
112
- ]);
113
- });
114
- });
115
-
116
- describe("enforceVersionGate — opt-out + soft paths (no process.exit)", () => {
117
- it("is silent + no fetch when HQ_NO_UPDATE_CHECK=1", async () => {
118
- vi.stubEnv("HQ_NO_UPDATE_CHECK", "1");
119
- const fetchMock = vi.fn();
120
- vi.stubGlobal("fetch", fetchMock);
121
- const { enforceVersionGate } = await loadModule();
122
- await enforceVersionGate();
123
- expect(fetchMock).not.toHaveBeenCalled();
124
- });
125
-
126
- it("is silent on non-200 response (treats as no-gate)", async () => {
127
- vi.stubGlobal(
128
- "fetch",
129
- vi.fn().mockResolvedValue(
130
- new Response("", { status: 500 }),
131
- ),
132
- );
133
- // process.exit must HALT execution — mocking it as undefined lets code
134
- // fall through past the exit point and crash on later lines. Throwing a
135
- // sentinel error reproduces the "never returns" semantics in unit tests.
136
- const exitSpy = vi
137
- .spyOn(process, "exit")
138
- .mockImplementation(((code?: number) => {
139
- throw new Error(`__process_exit__:${code ?? 0}`);
140
- }) as never);
141
- const { enforceVersionGate } = await loadModule();
142
- await enforceVersionGate();
143
- expect(exitSpy).not.toHaveBeenCalled();
144
- });
145
-
146
- it("is silent on malformed response body", async () => {
147
- vi.stubGlobal(
148
- "fetch",
149
- vi.fn().mockResolvedValue(
150
- new Response(JSON.stringify({ ok: true }), { status: 200 }),
151
- ),
152
- );
153
- // process.exit must HALT execution — mocking it as undefined lets code
154
- // fall through past the exit point and crash on later lines. Throwing a
155
- // sentinel error reproduces the "never returns" semantics in unit tests.
156
- const exitSpy = vi
157
- .spyOn(process, "exit")
158
- .mockImplementation(((code?: number) => {
159
- throw new Error(`__process_exit__:${code ?? 0}`);
160
- }) as never);
161
- const { enforceVersionGate } = await loadModule();
162
- await enforceVersionGate();
163
- expect(exitSpy).not.toHaveBeenCalled();
164
- });
165
-
166
- it("is silent on fetch rejection (network down / timeout)", async () => {
167
- vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("network down")));
168
- // process.exit must HALT execution — mocking it as undefined lets code
169
- // fall through past the exit point and crash on later lines. Throwing a
170
- // sentinel error reproduces the "never returns" semantics in unit tests.
171
- const exitSpy = vi
172
- .spyOn(process, "exit")
173
- .mockImplementation(((code?: number) => {
174
- throw new Error(`__process_exit__:${code ?? 0}`);
175
- }) as never);
176
- const { enforceVersionGate } = await loadModule();
177
- await expect(enforceVersionGate()).resolves.toBeUndefined();
178
- expect(exitSpy).not.toHaveBeenCalled();
179
- });
180
-
181
- it("nudges on updateRecommended without exiting", async () => {
182
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
183
- // process.exit must HALT execution — mocking it as undefined lets code
184
- // fall through past the exit point and crash on later lines. Throwing a
185
- // sentinel error reproduces the "never returns" semantics in unit tests.
186
- const exitSpy = vi
187
- .spyOn(process, "exit")
188
- .mockImplementation(((code?: number) => {
189
- throw new Error(`__process_exit__:${code ?? 0}`);
190
- }) as never);
191
- vi.stubGlobal(
192
- "fetch",
193
- vi.fn().mockResolvedValue(
194
- new Response(
195
- JSON.stringify({
196
- clientId: "hq-cli",
197
- currentVersion: "5.10.0",
198
- minVersion: "5.0.0",
199
- latestVersion: "5.24.0",
200
- updateRequired: false,
201
- updateRecommended: true,
202
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
203
- }),
204
- { status: 200 },
205
- ),
206
- ),
207
- );
208
- const { enforceVersionGate } = await loadModule();
209
- await enforceVersionGate();
210
- expect(exitSpy).not.toHaveBeenCalled();
211
- const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
212
- expect(printed).toContain("5.24.0");
213
- });
214
-
215
- it("does NOT nudge or block when current = latest", async () => {
216
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
217
- // process.exit must HALT execution — mocking it as undefined lets code
218
- // fall through past the exit point and crash on later lines. Throwing a
219
- // sentinel error reproduces the "never returns" semantics in unit tests.
220
- const exitSpy = vi
221
- .spyOn(process, "exit")
222
- .mockImplementation(((code?: number) => {
223
- throw new Error(`__process_exit__:${code ?? 0}`);
224
- }) as never);
225
- vi.stubGlobal(
226
- "fetch",
227
- vi.fn().mockResolvedValue(
228
- new Response(
229
- JSON.stringify({
230
- clientId: "hq-cli",
231
- currentVersion: "5.10.0",
232
- minVersion: "5.0.0",
233
- latestVersion: "5.10.0",
234
- updateRequired: false,
235
- updateRecommended: false,
236
- }),
237
- { status: 200 },
238
- ),
239
- ),
240
- );
241
- const { enforceVersionGate } = await loadModule();
242
- await enforceVersionGate();
243
- expect(exitSpy).not.toHaveBeenCalled();
244
- expect(errSpy).not.toHaveBeenCalled();
245
- });
246
- });
247
-
248
- describe("enforceVersionGate — hard-update path", () => {
249
- it("calls process.exit when updateRequired is true and no updateCommand", async () => {
250
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
251
- // process.exit must HALT execution — mocking it as undefined lets code
252
- // fall through past the exit point and crash on later lines. Throwing a
253
- // sentinel error reproduces the "never returns" semantics in unit tests.
254
- const exitSpy = vi
255
- .spyOn(process, "exit")
256
- .mockImplementation(((code?: number) => {
257
- throw new Error(`__process_exit__:${code ?? 0}`);
258
- }) as never);
259
- vi.stubGlobal(
260
- "fetch",
261
- vi.fn().mockResolvedValue(
262
- new Response(
263
- JSON.stringify({
264
- clientId: "hq-cli",
265
- currentVersion: "5.10.0",
266
- minVersion: "5.20.0",
267
- latestVersion: "5.24.0",
268
- updateRequired: true,
269
- updateRecommended: false,
270
- // no updateCommand — exits with code 75 (manual update needed)
271
- }),
272
- { status: 200 },
273
- ),
274
- ),
275
- );
276
- const { enforceVersionGate } = await loadModule();
277
- await expect(enforceVersionGate()).rejects.toThrow(/__process_exit__:75/);
278
- expect(exitSpy).toHaveBeenCalledWith(75);
279
- const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
280
- expect(printed).toContain("below the minimum");
281
- });
282
-
283
- it("posts the expected request body to /v1/client-version/check", async () => {
284
- const fetchMock = vi.fn().mockResolvedValue(
285
- new Response(
286
- JSON.stringify({
287
- clientId: "hq-cli",
288
- currentVersion: "5.10.0",
289
- minVersion: "5.0.0",
290
- latestVersion: "5.10.0",
291
- updateRequired: false,
292
- updateRecommended: false,
293
- }),
294
- { status: 200 },
295
- ),
296
- );
297
- vi.stubGlobal("fetch", fetchMock);
298
- const { enforceVersionGate } = await loadModule();
299
- await enforceVersionGate();
300
-
301
- expect(fetchMock).toHaveBeenCalledTimes(1);
302
- const [url, init] = fetchMock.mock.calls[0]!;
303
- expect(String(url)).toContain("/v1/client-version/check");
304
- const body = JSON.parse((init as RequestInit).body as string);
305
- expect(body.clientId).toBe("hq-cli");
306
- expect(body.currentVersion).toBe("5.10.0");
307
- expect(typeof body.platform).toBe("string");
308
- });
309
-
310
- it("installs with the resolved running prefix instead of the bare server command", async () => {
311
- vi.spyOn(console, "error").mockImplementation(() => {});
312
- const exitSpy = vi
313
- .spyOn(process, "exit")
314
- .mockImplementation(((code?: number) => {
315
- throw new Error(`__process_exit__:${code ?? 0}`);
316
- }) as never);
317
- const runner = vi.fn().mockReturnValue({ ok: true });
318
- const { __test__ } = await loadModule();
319
- const prefix = "/Users/x/Library/Application Support/Indigo HQ/toolchain/npm-global";
320
-
321
- expect(() =>
322
- __test__.enforceUpdateRequired(
323
- {
324
- clientId: "hq-cli",
325
- currentVersion: "5.10.0",
326
- minVersion: "5.20.0",
327
- latestVersion: "5.24.0",
328
- updateRequired: true,
329
- updateRecommended: false,
330
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
331
- },
332
- {
333
- resolveInstall: () => npmInstall(prefix),
334
- runner,
335
- },
336
- ),
337
- ).toThrow(/__process_exit__:0/);
338
-
339
- expect(exitSpy).toHaveBeenCalledWith(0);
340
- expect(runner).toHaveBeenCalledWith("npm", [
341
- "install",
342
- "-g",
343
- "--prefix",
344
- prefix,
345
- "@indigoai-us/hq-cli@latest",
346
- ]);
347
- expect(runner).not.toHaveBeenCalledWith("npm", [
348
- "install",
349
- "-g",
350
- "@indigoai-us/hq-cli@latest",
351
- ]);
352
- });
353
-
354
- it("falls back to the server updateCommand when no running prefix resolves", async () => {
355
- vi.spyOn(console, "error").mockImplementation(() => {});
356
- const exitSpy = vi
357
- .spyOn(process, "exit")
358
- .mockImplementation(((code?: number) => {
359
- throw new Error(`__process_exit__:${code ?? 0}`);
360
- }) as never);
361
- const performUpdateString = vi.fn().mockReturnValue({ ok: true });
362
- const { __test__ } = await loadModule();
363
- const updateCommand = "npm install -g @indigoai-us/hq-cli@latest";
364
-
365
- expect(() =>
366
- __test__.enforceUpdateRequired(
367
- {
368
- clientId: "hq-cli",
369
- currentVersion: "5.10.0",
370
- minVersion: "5.20.0",
371
- latestVersion: "5.24.0",
372
- updateRequired: true,
373
- updateRecommended: false,
374
- updateCommand,
375
- },
376
- {
377
- performUpdateString,
378
- resolveInstall: () => npmInstall(null),
379
- },
380
- ),
381
- ).toThrow(/__process_exit__:0/);
382
-
383
- expect(exitSpy).toHaveBeenCalledWith(0);
384
- expect(performUpdateString).toHaveBeenCalledWith(updateCommand);
385
- });
386
-
387
- it("retries under `sudo -n` when the unprivileged install fails (root-owned global)", async () => {
388
- vi.spyOn(console, "error").mockImplementation(() => {});
389
- const exitSpy = vi
390
- .spyOn(process, "exit")
391
- .mockImplementation(((code?: number) => {
392
- throw new Error(`__process_exit__:${code ?? 0}`);
393
- }) as never);
394
- // First (unprivileged) npm install fails with EACCES; the sudo -n retry succeeds.
395
- const runner = vi
396
- .fn()
397
- .mockImplementation((cmd: string) =>
398
- cmd === "sudo" ? { ok: true } : { ok: false, detail: "EACCES" },
399
- );
400
- const { __test__ } = await loadModule();
401
- const prefix = "/usr";
402
-
403
- expect(() =>
404
- __test__.enforceUpdateRequired(
405
- {
406
- clientId: "hq-cli",
407
- currentVersion: "5.10.0",
408
- minVersion: "5.20.0",
409
- latestVersion: "5.24.0",
410
- updateRequired: true,
411
- updateRecommended: false,
412
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
413
- },
414
- { resolveInstall: () => npmInstall(prefix), runner },
415
- ),
416
- ).toThrow(/__process_exit__:0/); // succeeds after the sudo retry
417
-
418
- expect(exitSpy).toHaveBeenCalledWith(0);
419
- const installArgs = [
420
- "install",
421
- "-g",
422
- "--prefix",
423
- prefix,
424
- "@indigoai-us/hq-cli@latest",
425
- ];
426
- expect(runner).toHaveBeenCalledWith("npm", installArgs);
427
- expect(runner).toHaveBeenCalledWith("sudo", ["-n", "npm", ...installArgs]);
428
- });
429
-
430
- it("exits 75 when BOTH the unprivileged install and the sudo -n retry fail", async () => {
431
- vi.spyOn(console, "error").mockImplementation(() => {});
432
- const exitSpy = vi
433
- .spyOn(process, "exit")
434
- .mockImplementation(((code?: number) => {
435
- throw new Error(`__process_exit__:${code ?? 0}`);
436
- }) as never);
437
- const runner = vi.fn().mockReturnValue({ ok: false, detail: "EACCES" });
438
- const { __test__ } = await loadModule();
439
-
440
- expect(() =>
441
- __test__.enforceUpdateRequired(
442
- {
443
- clientId: "hq-cli",
444
- currentVersion: "5.10.0",
445
- minVersion: "5.20.0",
446
- latestVersion: "5.24.0",
447
- updateRequired: true,
448
- updateRecommended: false,
449
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
450
- },
451
- { resolveInstall: () => npmInstall("/usr"), runner },
452
- ),
453
- ).toThrow(/__process_exit__:75/);
454
-
455
- expect(exitSpy).toHaveBeenCalledWith(75);
456
- expect(runner).toHaveBeenCalledWith("sudo", expect.arrayContaining(["-n"]));
457
- });
458
-
459
- it("cleans a stale partial install and retries once when the unprivileged install fails with ENOTEMPTY", async () => {
460
- vi.spyOn(console, "error").mockImplementation(() => {});
461
- const exitSpy = vi
462
- .spyOn(process, "exit")
463
- .mockImplementation(((code?: number) => {
464
- throw new Error(`__process_exit__:${code ?? 0}`);
465
- }) as never);
466
- // The reported failure: `npm install -g --prefix <toolchain> …` fails with
467
- // ENOTEMPTY renaming a partial `hq-cli`. sudo does NOT fix a corrupt dir —
468
- // only removing the stale artifacts and reinstalling does. Before this fix
469
- // the gate exhausted npm→sudo→exit 75, leaving `hq` broken (ENOENT).
470
- let npmCalls = 0;
471
- const runner = vi.fn().mockImplementation((cmd: string) => {
472
- if (cmd === "sudo") return { ok: false, detail: "ENOTEMPTY" };
473
- npmCalls += 1;
474
- return npmCalls === 1 ? { ok: false, detail: "ENOTEMPTY" } : { ok: true };
475
- });
476
- const prefix =
477
- "/Users/x/Library/Application Support/Indigo HQ/toolchain/npm-global";
478
- const cleanStale = vi
479
- .fn()
480
- .mockReturnValue([`${prefix}/lib/node_modules/@indigoai-us/.hq-cli-0DY3ww6z`]);
481
- const { __test__ } = await loadModule();
482
-
483
- expect(() =>
484
- __test__.enforceUpdateRequired(
485
- {
486
- clientId: "hq-cli",
487
- currentVersion: "5.10.0",
488
- minVersion: "5.20.0",
489
- latestVersion: "5.24.0",
490
- updateRequired: true,
491
- updateRecommended: false,
492
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
493
- },
494
- { resolveInstall: () => npmInstall(prefix), runner, cleanStale },
495
- ),
496
- ).toThrow(/__process_exit__:0/); // recovers after the cleanup + retry
497
-
498
- expect(exitSpy).toHaveBeenCalledWith(0);
499
- expect(cleanStale).toHaveBeenCalledWith(prefix);
500
- const installArgs = [
501
- "install",
502
- "-g",
503
- "--prefix",
504
- prefix,
505
- "@indigoai-us/hq-cli@latest",
506
- ];
507
- // primary attempt + one retry after the stale artifacts were removed
508
- expect(
509
- runner.mock.calls.filter((c) => c[0] === "npm").length,
510
- ).toBe(2);
511
- expect(runner).toHaveBeenCalledWith("npm", installArgs);
512
- // sudo must NOT be reached — the ENOTEMPTY was fixed by cleanup, not perms
513
- expect(runner).not.toHaveBeenCalledWith("sudo", expect.anything());
514
- });
515
-
516
- it("does NOT reinstall-after-clean when nothing stale exists (plain EACCES falls straight to sudo)", async () => {
517
- vi.spyOn(console, "error").mockImplementation(() => {});
518
- const exitSpy = vi
519
- .spyOn(process, "exit")
520
- .mockImplementation(((code?: number) => {
521
- throw new Error(`__process_exit__:${code ?? 0}`);
522
- }) as never);
523
- const runner = vi
524
- .fn()
525
- .mockImplementation((cmd: string) =>
526
- cmd === "sudo" ? { ok: true } : { ok: false, detail: "EACCES" },
527
- );
528
- const cleanStale = vi.fn().mockReturnValue([]); // healthy prefix, nothing to remove
529
- const { __test__ } = await loadModule();
530
-
531
- expect(() =>
532
- __test__.enforceUpdateRequired(
533
- {
534
- clientId: "hq-cli",
535
- currentVersion: "5.10.0",
536
- minVersion: "5.20.0",
537
- latestVersion: "5.24.0",
538
- updateRequired: true,
539
- updateRecommended: false,
540
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
541
- },
542
- { resolveInstall: () => npmInstall("/usr"), runner, cleanStale },
543
- ),
544
- ).toThrow(/__process_exit__:0/); // sudo retry succeeds
545
-
546
- expect(exitSpy).toHaveBeenCalledWith(0);
547
- expect(cleanStale).toHaveBeenCalledWith("/usr");
548
- // exactly ONE npm attempt (no redundant reinstall), then sudo
549
- expect(runner.mock.calls.filter((c) => c[0] === "npm").length).toBe(1);
550
- expect(runner).toHaveBeenCalledWith("sudo", expect.arrayContaining(["-n"]));
551
- });
552
- });
553
-
554
- describe("cleanStalePartialInstall", () => {
555
- type FakeTree = {
556
- dirs: Record<string, string[]>;
557
- packageJson: Record<string, string | null>;
558
- existing: Set<string>;
559
- };
560
-
561
- function makeFakeFs(tree: FakeTree) {
562
- const removed: string[] = [];
563
- const fs = {
564
- readdirSync: (dir: string) => {
565
- if (dir in tree.dirs) return tree.dirs[dir]!;
566
- throw new Error(`ENOENT: ${dir}`);
567
- },
568
- existsSync: (target: string) => tree.existing.has(target),
569
- readFileSync: (target: string) => {
570
- const pkgDir = target.replace(/\/package\.json$/, "");
571
- const content = tree.packageJson[pkgDir];
572
- if (content == null) throw new Error(`ENOENT: ${target}`);
573
- return content;
574
- },
575
- rmSync: (target: string) => {
576
- removed.push(target);
577
- },
578
- };
579
- return { fs, removed };
580
- }
581
-
582
- it("removes the npm staging dir and a partial package dir, but keeps unrelated entries", async () => {
583
- const { __test__ } = await loadModule();
584
- const prefix = "/p";
585
- const scopeDir = "/p/lib/node_modules/@indigoai-us";
586
- const { fs, removed } = makeFakeFs({
587
- dirs: {
588
- [scopeDir]: [".hq-cli-0DY3ww6z", "hq-cli", "some-other-pkg"],
589
- },
590
- packageJson: { [`${scopeDir}/hq-cli`]: null }, // partial: package.json unreadable
591
- existing: new Set([`${scopeDir}/hq-cli`]),
592
- });
593
-
594
- const result = __test__.cleanStalePartialInstall(prefix, fs);
595
-
596
- expect(result).toContain(`${scopeDir}/.hq-cli-0DY3ww6z`);
597
- expect(result).toContain(`${scopeDir}/hq-cli`);
598
- expect(removed).not.toContain(`${scopeDir}/some-other-pkg`);
599
- });
600
-
601
- it("never touches a healthy install (valid package.json with matching name)", async () => {
602
- const { __test__ } = await loadModule();
603
- const scopeDir = "/p/lib/node_modules/@indigoai-us";
604
- const { fs, removed } = makeFakeFs({
605
- dirs: { [scopeDir]: ["hq-cli"] }, // no staging leftovers
606
- packageJson: {
607
- [`${scopeDir}/hq-cli`]: JSON.stringify({
608
- name: "@indigoai-us/hq-cli",
609
- version: "5.24.0",
610
- }),
611
- },
612
- existing: new Set([`${scopeDir}/hq-cli`]),
613
- });
614
-
615
- const result = __test__.cleanStalePartialInstall("/p", fs);
616
-
617
- expect(result).toEqual([]);
618
- expect(removed).toEqual([]);
619
- });
620
-
621
- it("also cleans a staging dir under the bare <prefix>/node_modules layout", async () => {
622
- const { __test__ } = await loadModule();
623
- const scopeDir = "/p/node_modules/@indigoai-us";
624
- const { fs } = makeFakeFs({
625
- dirs: { [scopeDir]: [".hq-cli-abc123"] },
626
- packageJson: {},
627
- existing: new Set(),
628
- });
629
-
630
- const result = __test__.cleanStalePartialInstall("/p", fs);
631
-
632
- expect(result).toEqual([`${scopeDir}/.hq-cli-abc123`]);
633
- });
634
- });
635
-
636
- // Regression coverage for feedback_812a6727: a pnpm-managed global install kept
637
- // reporting the old version after every "successful" self-update, because the
638
- // gate derived an npm --prefix from the pnpm store and installed into a
639
- // directory the pnpm PATH shim never reads.
640
- describe("pnpm-managed global installs", () => {
641
- const PNPM_STORE_DIR =
642
- "/Users/x/Library/pnpm/global/5/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli";
643
- const PNPM_LINK_DIR =
644
- "/Users/x/Library/pnpm/global/5/node_modules/@indigoai-us/hq-cli";
645
-
646
- it("recognises both the store and the symlinked pnpm global layouts", async () => {
647
- const { __test__ } = await loadModule();
648
- expect(__test__.isPnpmManagedPackageDir(PNPM_STORE_DIR)).toBe(true);
649
- expect(__test__.isPnpmManagedPackageDir(PNPM_LINK_DIR)).toBe(true);
650
- expect(
651
- __test__.isPnpmManagedPackageDir(
652
- "C:\\Users\\x\\AppData\\Local\\pnpm\\global\\5\\node_modules\\@indigoai-us\\hq-cli",
653
- ),
654
- ).toBe(true);
655
- });
656
-
657
- it("does not mistake an npm global layout for a pnpm one", async () => {
658
- const { __test__ } = await loadModule();
659
- expect(
660
- __test__.isPnpmManagedPackageDir(
661
- "/usr/local/lib/node_modules/@indigoai-us/hq-cli",
662
- ),
663
- ).toBe(false);
664
- expect(
665
- __test__.isPnpmManagedPackageDir(
666
- "/Users/x/.nvm/versions/node/v22.3.0/lib/node_modules/@indigoai-us/hq-cli",
667
- ),
668
- ).toBe(false);
669
- // A project that merely depends on pnpm-named packages is still npm-shaped.
670
- expect(
671
- __test__.isPnpmManagedPackageDir(
672
- "/Users/x/code/pnpm-tools/node_modules/@indigoai-us/hq-cli",
673
- ),
674
- ).toBe(false);
675
- });
676
-
677
- it("demonstrates the old bug: a pnpm store path yields a plausible-looking npm prefix", async () => {
678
- const { __test__ } = await loadModule();
679
- // npmPrefixFromPackageDir is layout-blind — it happily hands back the pnpm
680
- // store as if it were an npm prefix, which is exactly what made
681
- // `npm install -g --prefix <store>` exit 0 while changing nothing the shim
682
- // resolves. The manager check is what has to stop that.
683
- expect(__test__.npmPrefixFromPackageDir(PNPM_STORE_DIR)).not.toBeNull();
684
- expect(__test__.npmPrefixFromPackageDir(PNPM_LINK_DIR)).not.toBeNull();
685
- expect(__test__.isPnpmManagedPackageDir(PNPM_STORE_DIR)).toBe(true);
686
- expect(__test__.isPnpmManagedPackageDir(PNPM_LINK_DIR)).toBe(true);
687
- });
688
-
689
- it("builds the pnpm global install argv", async () => {
690
- const { __test__ } = await loadModule();
691
- expect(__test__.buildPnpmInstallArgv()).toEqual([
692
- "add",
693
- "-g",
694
- "@indigoai-us/hq-cli@latest",
695
- ]);
696
- });
697
-
698
- it("updates with `pnpm add -g` and never npm-installs into the pnpm store", async () => {
699
- vi.spyOn(console, "error").mockImplementation(() => {});
700
- const exitSpy = vi
701
- .spyOn(process, "exit")
702
- .mockImplementation(((code?: number) => {
703
- throw new Error(`__process_exit__:${code ?? 0}`);
704
- }) as never);
705
- const runner = vi.fn().mockReturnValue({ ok: true });
706
- const performUpdateString = vi.fn().mockReturnValue({ ok: true });
707
- const { __test__ } = await loadModule();
708
-
709
- expect(() =>
710
- __test__.enforceUpdateRequired(
711
- {
712
- clientId: "hq-cli",
713
- currentVersion: "5.10.0",
714
- minVersion: "5.20.0",
715
- latestVersion: "5.24.0",
716
- updateRequired: true,
717
- updateRecommended: false,
718
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
719
- },
720
- {
721
- resolveInstall: () => pnpmInstall(),
722
- performUpdateString,
723
- runner,
724
- },
725
- ),
726
- ).toThrow(/__process_exit__:0/);
727
-
728
- expect(exitSpy).toHaveBeenCalledWith(0);
729
- expect(runner).toHaveBeenCalledWith("pnpm", [
730
- "add",
731
- "-g",
732
- "@indigoai-us/hq-cli@latest",
733
- ]);
734
- // No npm anywhere: not the prefixed form, not the server's command.
735
- expect(runner).not.toHaveBeenCalledWith("npm", expect.anything());
736
- expect(performUpdateString).not.toHaveBeenCalled();
737
- });
738
-
739
- it("exits 75 without a sudo retry when the pnpm update fails", async () => {
740
- vi.spyOn(console, "error").mockImplementation(() => {});
741
- const exitSpy = vi
742
- .spyOn(process, "exit")
743
- .mockImplementation(((code?: number) => {
744
- throw new Error(`__process_exit__:${code ?? 0}`);
745
- }) as never);
746
- const runner = vi.fn().mockReturnValue({ ok: false, detail: "EACCES" });
747
- const cleanStale = vi.fn().mockReturnValue([]);
748
- const { __test__ } = await loadModule();
749
-
750
- expect(() =>
751
- __test__.enforceUpdateRequired(
752
- {
753
- clientId: "hq-cli",
754
- currentVersion: "5.10.0",
755
- minVersion: "5.20.0",
756
- latestVersion: "5.24.0",
757
- updateRequired: true,
758
- updateRecommended: false,
759
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
760
- },
761
- {
762
- resolveInstall: () => pnpmInstall(),
763
- runner,
764
- cleanStale,
765
- },
766
- ),
767
- ).toThrow(/__process_exit__:75/);
768
-
769
- expect(exitSpy).toHaveBeenCalledWith(75);
770
- // `sudo -n pnpm add -g` would install into root's PNPM_HOME and report
771
- // success while the user's shim stayed stale — the failure must surface.
772
- expect(runner).not.toHaveBeenCalledWith("sudo", expect.anything());
773
- expect(cleanStale).not.toHaveBeenCalled();
774
- expect(runner.mock.calls.every((c) => c[0] === "pnpm")).toBe(true);
775
- });
776
-
777
- it("still uses npm when the running install is npm-managed", async () => {
778
- vi.spyOn(console, "error").mockImplementation(() => {});
779
- vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
780
- throw new Error(`__process_exit__:${code ?? 0}`);
781
- }) as never);
782
- const runner = vi.fn().mockReturnValue({ ok: true });
783
- const { __test__ } = await loadModule();
784
- const prefix = "/usr/local";
785
-
786
- expect(() =>
787
- __test__.enforceUpdateRequired(
788
- {
789
- clientId: "hq-cli",
790
- currentVersion: "5.10.0",
791
- minVersion: "5.20.0",
792
- latestVersion: "5.24.0",
793
- updateRequired: true,
794
- updateRecommended: false,
795
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
796
- },
797
- { resolveInstall: () => npmInstall(prefix), runner },
798
- ),
799
- ).toThrow(/__process_exit__:0/);
800
-
801
- expect(runner).toHaveBeenCalledWith("npm", [
802
- "install",
803
- "-g",
804
- "--prefix",
805
- prefix,
806
- "@indigoai-us/hq-cli@latest",
807
- ]);
808
- expect(runner).not.toHaveBeenCalledWith("pnpm", expect.anything());
809
- });
810
- });
811
-
812
- // Second round of regression coverage for feedback_812a6727. The first fix made
813
- // only the HARD gate (updateRequired) pnpm-aware; everything below closes the
814
- // paths that could still reproduce the reported stale-shim loop, or that the
815
- // pnpm branch newly mis-handled.
816
- describe("pnpm-managed installs — soft nudge path", () => {
817
- const decision = {
818
- clientId: "hq-cli",
819
- currentVersion: "5.10.0",
820
- minVersion: "5.0.0",
821
- latestVersion: "5.24.0",
822
- updateRequired: false,
823
- updateRecommended: true,
824
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
825
- };
826
-
827
- it("never tells a pnpm-managed install to run an npm command", async () => {
828
- // updateRecommended fires for EVERY version below latest, while
829
- // updateRequired only fires below minVersion — so this is the path a real
830
- // user hits first. Printing the server's npm-shaped command here installs a
831
- // fresh copy under the npm global prefix while pnpm's PATH shim keeps
832
- // resolving the old build: the reported symptom, on a released build.
833
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
834
- const { __test__ } = await loadModule();
835
-
836
- __test__.nudgeUpdateRecommended(decision, pnpmInstall());
837
-
838
- const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
839
- expect(printed).toContain("5.24.0");
840
- expect(printed).toContain("pnpm add -g @indigoai-us/hq-cli@latest");
841
- expect(printed).not.toContain("npm install");
842
- });
843
-
844
- it("still prints the server updateCommand for an npm-managed install", async () => {
845
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
846
- const { __test__ } = await loadModule();
847
-
848
- __test__.nudgeUpdateRecommended(decision, npmInstall("/usr/local"));
849
-
850
- const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
851
- expect(printed).toContain("npm install -g @indigoai-us/hq-cli@latest");
852
- expect(printed).not.toContain("pnpm");
853
- });
854
- });
855
-
856
- describe("isPnpmManagedPackageDir — global layouts only", () => {
857
- it("rejects a LOCAL pnpm project dependency", async () => {
858
- // `pnpm add -g` would mutate the user's GLOBAL install as a side effect of
859
- // a non-global invocation, while the local copy actually running stayed
860
- // stale — so the gate would re-fire (and re-install globally) forever.
861
- const { __test__ } = await loadModule();
862
- expect(
863
- __test__.isPnpmManagedPackageDir(
864
- "/Users/x/code/my-app/node_modules/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli",
865
- ),
866
- ).toBe(false);
867
- expect(
868
- __test__.isPnpmManagedPackageDir(
869
- "/Users/x/code/my-app/node_modules/@indigoai-us/hq-cli",
870
- ),
871
- ).toBe(false);
872
- });
873
-
874
- it("rejects a `pnpm dlx` cache directory", async () => {
875
- const { __test__ } = await loadModule();
876
- expect(
877
- __test__.isPnpmManagedPackageDir(
878
- "/Users/x/Library/pnpm/store/v3/tmp/dlx-49281/node_modules/.pnpm/@indigoai-us+hq-cli@5.61.0/node_modules/@indigoai-us/hq-cli",
879
- ),
880
- ).toBe(false);
881
- });
882
-
883
- it("rejects a dlx cache even when it sits under PNPM_HOME", async () => {
884
- vi.stubEnv("PNPM_HOME", "/Users/x/Library/pnpm");
885
- const { __test__ } = await loadModule();
886
- expect(
887
- __test__.isPnpmManagedPackageDir(
888
- "/Users/x/Library/pnpm/store/v3/tmp/dlx-49281/node_modules/@indigoai-us/hq-cli",
889
- ),
890
- ).toBe(false);
891
- });
892
-
893
- it("accepts a PNPM_HOME global root whose store dir is not numeric", async () => {
894
- vi.stubEnv("PNPM_HOME", "/opt/pnpm-home");
895
- const { __test__ } = await loadModule();
896
- expect(
897
- __test__.isPnpmManagedPackageDir(
898
- "/opt/pnpm-home/global/next/node_modules/@indigoai-us/hq-cli",
899
- ),
900
- ).toBe(true);
901
- });
902
- });
903
-
904
- describe("buildSpawnPlan — Windows .cmd shims", () => {
905
- it("spawns through the shell on win32 (Node refuses bare .cmd since CVE-2024-27980)", async () => {
906
- const { __test__ } = await loadModule();
907
- const plan = __test__.buildSpawnPlan(
908
- "pnpm",
909
- ["add", "-g", "@indigoai-us/hq-cli@latest"],
910
- "win32",
911
- );
912
- expect(plan.shell).toBe(true);
913
- expect(plan.cmd).toBe("pnpm");
914
- expect(plan.args).toEqual(["add", "-g", "@indigoai-us/hq-cli@latest"]);
915
- });
916
-
917
- it("quotes a prefix containing spaces, because Node does not quote for shell:true", async () => {
918
- const { __test__ } = await loadModule();
919
- const plan = __test__.buildSpawnPlan(
920
- "npm",
921
- ["install", "-g", "--prefix", "C:/Program Files/npm", "pkg@latest"],
922
- "win32",
923
- );
924
- expect(plan.args).toEqual([
925
- "install",
926
- "-g",
927
- "--prefix",
928
- '"C:/Program Files/npm"',
929
- "pkg@latest",
930
- ]);
931
- });
932
-
933
- it("does not use a shell on posix", async () => {
934
- const { __test__ } = await loadModule();
935
- const plan = __test__.buildSpawnPlan("pnpm", ["add", "-g", "x"], "darwin");
936
- expect(plan).toEqual({ cmd: "pnpm", args: ["add", "-g", "x"], shell: false });
937
- });
938
- });
939
-
940
- describe("pnpm-managed installs — pnpm not spawnable", () => {
941
- it("exits 75 with an actionable message when pnpm is missing from PATH", async () => {
942
- // launchd/cron and other minimal-PATH parents never source the profile that
943
- // puts PNPM_HOME on PATH. spawnSync surfaces that as an ENOENT `error`, not
944
- // a throw and not a non-zero status.
945
- const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
946
- const exitSpy = vi
947
- .spyOn(process, "exit")
948
- .mockImplementation(((code?: number) => {
949
- throw new Error(`__process_exit__:${code ?? 0}`);
950
- }) as never);
951
- const runner = vi.fn().mockReturnValue({
952
- ok: false,
953
- code: "ENOENT",
954
- detail: "spawnSync pnpm ENOENT",
955
- });
956
- const { __test__ } = await loadModule();
957
-
958
- expect(() =>
959
- __test__.enforceUpdateRequired(
960
- {
961
- clientId: "hq-cli",
962
- currentVersion: "5.10.0",
963
- minVersion: "5.20.0",
964
- latestVersion: "5.24.0",
965
- updateRequired: true,
966
- updateRecommended: false,
967
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
968
- },
969
- { resolveInstall: () => pnpmInstall(), runner },
970
- ),
971
- ).toThrow(/__process_exit__:75/);
972
-
973
- expect(exitSpy).toHaveBeenCalledWith(75);
974
- const printed = errSpy.mock.calls.map((c) => c.join(" ")).join("\n");
975
- expect(printed).toContain("not found on PATH");
976
- expect(printed).toContain("Try manually: pnpm add -g @indigoai-us/hq-cli@latest");
977
- // The server's npm command may be shown, but only flagged as npm-only —
978
- // never as the thing to run for this layout.
979
- expect(printed).not.toMatch(/Try manually: npm/);
980
- // Still no sudo retry: it would install into root's PNPM_HOME.
981
- expect(runner).not.toHaveBeenCalledWith("sudo", expect.anything());
982
- });
983
- });
984
-
985
- describe("resolveRunningInstall", () => {
986
- it("is consulted exactly once per enforceUpdateRequired invocation", async () => {
987
- // Manager and prefix used to be resolved by two independent walks of the
988
- // directory tree, each reading and JSON-parsing a package.json per level,
989
- // and the two could disagree if the filesystem moved between them.
990
- vi.spyOn(console, "error").mockImplementation(() => {});
991
- vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
992
- throw new Error(`__process_exit__:${code ?? 0}`);
993
- }) as never);
994
- const resolveInstall = vi.fn(() => npmInstall("/usr/local"));
995
- const runner = vi.fn().mockReturnValue({ ok: true });
996
- const { __test__ } = await loadModule();
997
-
998
- expect(() =>
999
- __test__.enforceUpdateRequired(
1000
- {
1001
- clientId: "hq-cli",
1002
- currentVersion: "5.10.0",
1003
- minVersion: "5.20.0",
1004
- latestVersion: "5.24.0",
1005
- updateRequired: true,
1006
- updateRecommended: false,
1007
- updateCommand: "npm install -g @indigoai-us/hq-cli@latest",
1008
- },
1009
- { resolveInstall, runner },
1010
- ),
1011
- ).toThrow(/__process_exit__:0/);
1012
-
1013
- expect(resolveInstall).toHaveBeenCalledTimes(1);
1014
- });
1015
-
1016
- it("reports manager and prefix from a single resolution", async () => {
1017
- const { __test__ } = await loadModule();
1018
- const install = __test__.resolveRunningInstall();
1019
- expect(install.manager).toBe(__test__.resolveRunningManager());
1020
- expect(install.prefix).toBe(__test__.resolveRunningPrefix());
1021
- // A pnpm-managed install must never carry an npm prefix.
1022
- if (install.manager === "pnpm") expect(install.prefix).toBeNull();
1023
- });
1024
- });