@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,722 +0,0 @@
1
- /**
2
- * Unit tests for `hq files share` (files.ts).
3
- *
4
- * Coverage:
5
- * - parseDuration — pure parser
6
- * - mintShareSession — happy path + error mapping (401, 403 with path)
7
- * - formatShareSessionError — status → user copy
8
- * - registerFilesCommand share action — fork by --with presence:
9
- * * no --with: calls mint endpoint, prints URL, --no-open suppresses launch
10
- * * with --with: calls existing direct-grant endpoint, NEVER mints
11
- * * no paths: prints usage and exits non-zero
12
- */
13
-
14
- import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from "vitest";
15
-
16
- // Mock the `open` package BEFORE importing files.ts so the action handler
17
- // resolves to the mock. Returning a resolved promise mirrors open()'s real
18
- // signature without launching a real browser.
19
- vi.mock("open", () => ({
20
- default: vi.fn(() => Promise.resolve({ pid: 0 })),
21
- }));
22
-
23
- // `ensureCognitoToken` hits a real keychain/disk path otherwise. Stub it so
24
- // the action runs without I/O and we can assert pure behavior.
25
- vi.mock("../utils/cognito-session.js", async (importOriginal) => {
26
- const original = (await importOriginal()) as Record<string, unknown>;
27
- return {
28
- ...original,
29
- ensureCognitoToken: vi.fn(async () => "test-token"),
30
- };
31
- });
32
-
33
- import { Command } from "commander";
34
- import open from "open";
35
- import {
36
- MAX_SHARE_SESSION_EXPIRY_MS,
37
- ShareSessionHttpError,
38
- formatShareSessionError,
39
- mintShareSession,
40
- parseDuration,
41
- registerFilesCommand,
42
- } from "./files.js";
43
-
44
- function jsonResponse(status: number, body: unknown): Response {
45
- return new Response(JSON.stringify(body), {
46
- status,
47
- headers: { "Content-Type": "application/json" },
48
- });
49
- }
50
-
51
- let fetchSpy: MockInstance<typeof fetch>;
52
- let exitSpy: MockInstance<typeof process.exit>;
53
- let logSpy: MockInstance<typeof console.log>;
54
- let errSpy: MockInstance<typeof console.error>;
55
-
56
- beforeEach(() => {
57
- fetchSpy = vi.spyOn(globalThis, "fetch");
58
- // process.exit gets thrown so the action's try/catch doesn't keep running
59
- // after a failure path — mirrors how Commander aborts in real usage.
60
- exitSpy = vi
61
- .spyOn(process, "exit")
62
- .mockImplementation(((code?: number) => {
63
- throw new Error(`__EXIT__:${code ?? 0}`);
64
- }) as never);
65
- logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
66
- errSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
67
- });
68
-
69
- afterEach(() => {
70
- vi.restoreAllMocks();
71
- vi.mocked(open).mockClear();
72
- });
73
-
74
- // ---------------------------------------------------------------------------
75
- // parseDuration
76
- // ---------------------------------------------------------------------------
77
-
78
- describe("parseDuration", () => {
79
- it("parses minutes/hours/days into ms", () => {
80
- expect(parseDuration("15m")).toBe(15 * 60 * 1000);
81
- expect(parseDuration("1h")).toBe(60 * 60 * 1000);
82
- expect(parseDuration("24h")).toBe(24 * 60 * 60 * 1000);
83
- expect(parseDuration("2d")).toBe(2 * 24 * 60 * 60 * 1000);
84
- });
85
-
86
- it("returns null for invalid formats", () => {
87
- expect(parseDuration("15")).toBeNull();
88
- expect(parseDuration("abc")).toBeNull();
89
- expect(parseDuration("15s")).toBeNull();
90
- expect(parseDuration("")).toBeNull();
91
- });
92
-
93
- it("agrees with the documented 24h ceiling constant", () => {
94
- expect(parseDuration("24h")).toBe(MAX_SHARE_SESSION_EXPIRY_MS);
95
- });
96
- });
97
-
98
- // ---------------------------------------------------------------------------
99
- // mintShareSession
100
- // ---------------------------------------------------------------------------
101
-
102
- describe("mintShareSession", () => {
103
- it("POSTs paths to /files/{companyUid}/share-session and returns the response", async () => {
104
- fetchSpy.mockResolvedValueOnce(
105
- jsonResponse(200, {
106
- url: "https://share.hq/abc",
107
- token: "tok_share_xyz",
108
- expiresAt: "2026-05-11T12:00:00Z",
109
- nonce: "nnnnnn",
110
- paths: ["docs/", "reports/q1.pdf"],
111
- maxPermissionByPath: { "docs/": "read", "reports/q1.pdf": "read" },
112
- }),
113
- );
114
-
115
- const session = await mintShareSession({
116
- token: "test-token",
117
- companyUid: "cmp_acme",
118
- paths: ["docs/", "reports/q1.pdf"],
119
- });
120
-
121
- expect(session.url).toBe("https://share.hq/abc");
122
- expect(session.expiresAt).toBe("2026-05-11T12:00:00Z");
123
-
124
- const call = fetchSpy.mock.calls[0];
125
- expect(String(call[0])).toMatch(/\/files\/cmp_acme\/share-session$/);
126
- expect(call[1]?.method).toBe("POST");
127
- const body = JSON.parse((call[1]?.body as string) ?? "{}");
128
- expect(body).toEqual({ paths: ["docs/", "reports/q1.pdf"] });
129
- });
130
-
131
- it("includes expiresInMs only when supplied", async () => {
132
- fetchSpy.mockResolvedValueOnce(
133
- jsonResponse(200, { url: "https://share.hq/x", expiresAt: "now" }),
134
- );
135
-
136
- await mintShareSession({
137
- token: "test-token",
138
- companyUid: "cmp_acme",
139
- paths: ["foo"],
140
- expiresInMs: 15 * 60 * 1000,
141
- });
142
-
143
- const body = JSON.parse(
144
- (fetchSpy.mock.calls[0][1]?.body as string) ?? "{}",
145
- );
146
- expect(body).toEqual({ paths: ["foo"], expiresInMs: 15 * 60 * 1000 });
147
- });
148
-
149
- it("throws ShareSessionHttpError on 401", async () => {
150
- fetchSpy.mockResolvedValueOnce(jsonResponse(401, { error: "unauth" }));
151
- await expect(
152
- mintShareSession({
153
- token: "bad",
154
- companyUid: "cmp_acme",
155
- paths: ["foo"],
156
- }),
157
- ).rejects.toBeInstanceOf(ShareSessionHttpError);
158
- });
159
-
160
- it("propagates the offending path on 403 forbidden-per-path", async () => {
161
- fetchSpy.mockResolvedValueOnce(
162
- jsonResponse(403, { error: "forbidden", path: "secrets/" }),
163
- );
164
- try {
165
- await mintShareSession({
166
- token: "test-token",
167
- companyUid: "cmp_acme",
168
- paths: ["secrets/"],
169
- });
170
- expect.fail("should have thrown");
171
- } catch (err) {
172
- expect(err).toBeInstanceOf(ShareSessionHttpError);
173
- expect((err as ShareSessionHttpError).status).toBe(403);
174
- expect((err as ShareSessionHttpError).path).toBe("secrets/");
175
- }
176
- });
177
- });
178
-
179
- // ---------------------------------------------------------------------------
180
- // formatShareSessionError
181
- // ---------------------------------------------------------------------------
182
-
183
- describe("formatShareSessionError", () => {
184
- it("maps 401 to a login hint", () => {
185
- expect(
186
- formatShareSessionError(new ShareSessionHttpError(401, "unauth")),
187
- ).toMatch(/run `hq login`/);
188
- });
189
-
190
- it("maps 403 with a path to a per-path message", () => {
191
- const err = new ShareSessionHttpError(403, "forbidden", "secrets/");
192
- expect(formatShareSessionError(err)).toMatch(/'secrets\/'/);
193
- });
194
-
195
- it("maps 403 without a path to a generic membership hint", () => {
196
- expect(
197
- formatShareSessionError(new ShareSessionHttpError(403, "forbidden")),
198
- ).toMatch(/company member/);
199
- });
200
-
201
- it("prefixes 5xx with 'Server error:'", () => {
202
- expect(
203
- formatShareSessionError(new ShareSessionHttpError(500, "boom")),
204
- ).toMatch(/^Server error: boom/);
205
- });
206
-
207
- it("falls through to the message for unmapped statuses", () => {
208
- expect(
209
- formatShareSessionError(new ShareSessionHttpError(418, "tea")),
210
- ).toMatch(/tea/);
211
- });
212
- });
213
-
214
- // ---------------------------------------------------------------------------
215
- // Command action — share fork: no --with → mint, with --with → direct grant
216
- // ---------------------------------------------------------------------------
217
-
218
- /** Build a fresh program + register `files` so each test gets a clean parser. */
219
- function buildProgram(): Command {
220
- const program = new Command();
221
- // exitOverride keeps Commander from killing the process on parse errors —
222
- // we want any failure to surface as a thrown error or a process.exit spy.
223
- program.exitOverride();
224
- registerFilesCommand(program);
225
- return program;
226
- }
227
-
228
- describe("hq files share — browser-launch fork (no --with)", () => {
229
- it("PRD scenario 1: --no-open prints URL, exits 0, does not call open()", async () => {
230
- // 1) /membership/me — used by getCompanyUid fallback
231
- fetchSpy.mockResolvedValueOnce(
232
- jsonResponse(200, {
233
- memberships: [
234
- {
235
- membershipKey: "k1",
236
- companyUid: "cmp_acme",
237
- role: "member",
238
- status: "active",
239
- },
240
- ],
241
- }),
242
- );
243
- // 2) POST /files/cmp_acme/share-session
244
- fetchSpy.mockResolvedValueOnce(
245
- jsonResponse(200, {
246
- url: "https://share.hq/fixture-url",
247
- expiresAt: "2026-05-11T13:00:00Z",
248
- }),
249
- );
250
-
251
- const program = buildProgram();
252
- await program.parseAsync(
253
- ["files", "share", "fooPath", "--no-open"],
254
- { from: "user" },
255
- );
256
-
257
- // Mint endpoint was called, with the right body.
258
- const mintCall = fetchSpy.mock.calls.find((c) =>
259
- String(c[0]).includes("/share-session"),
260
- );
261
- expect(mintCall).toBeDefined();
262
- const body = JSON.parse((mintCall![1]?.body as string) ?? "{}");
263
- expect(body).toEqual({ paths: ["fooPath"] });
264
-
265
- // URL printed to stdout.
266
- const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
267
- expect(printed).toContain("https://share.hq/fixture-url");
268
-
269
- // Browser was NOT launched.
270
- expect(open).not.toHaveBeenCalled();
271
-
272
- // No process.exit on the success path.
273
- expect(exitSpy).not.toHaveBeenCalled();
274
- });
275
-
276
- it("forwards --expires as ms to the mint endpoint", async () => {
277
- fetchSpy.mockResolvedValueOnce(
278
- jsonResponse(200, {
279
- memberships: [
280
- {
281
- membershipKey: "k1",
282
- companyUid: "cmp_acme",
283
- role: "member",
284
- status: "active",
285
- },
286
- ],
287
- }),
288
- );
289
- fetchSpy.mockResolvedValueOnce(
290
- jsonResponse(200, {
291
- url: "https://share.hq/x",
292
- expiresAt: "2026-05-11T13:00:00Z",
293
- }),
294
- );
295
-
296
- const program = buildProgram();
297
- await program.parseAsync(
298
- ["files", "share", "foo", "--expires", "1h", "--no-open"],
299
- { from: "user" },
300
- );
301
-
302
- const mintCall = fetchSpy.mock.calls.find((c) =>
303
- String(c[0]).includes("/share-session"),
304
- )!;
305
- const body = JSON.parse((mintCall[1]?.body as string) ?? "{}");
306
- expect(body).toEqual({ paths: ["foo"], expiresInMs: 60 * 60 * 1000 });
307
- });
308
-
309
- it("rejects --expires beyond the 24h CLI ceiling", async () => {
310
- const program = buildProgram();
311
- await expect(
312
- program.parseAsync(
313
- ["files", "share", "foo", "--expires", "2d", "--no-open"],
314
- { from: "user" },
315
- ),
316
- ).rejects.toThrow(/__EXIT__:1/);
317
-
318
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
319
- expect(errs).toMatch(/Maximum share-session expiry is 24h/);
320
- // No fetch should have happened — pre-validation rejected early.
321
- expect(fetchSpy).not.toHaveBeenCalled();
322
- });
323
-
324
- it("prints a usage message when no paths are supplied", async () => {
325
- const program = buildProgram();
326
- await expect(
327
- program.parseAsync(["files", "share"], { from: "user" }),
328
- ).rejects.toThrow(/__EXIT__:1/);
329
-
330
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
331
- expect(errs).toMatch(/usage: hq files share <paths\.\.\.>/);
332
- expect(fetchSpy).not.toHaveBeenCalled();
333
- });
334
-
335
- it("surfaces a 401 from the mint endpoint as an actionable error", async () => {
336
- fetchSpy.mockResolvedValueOnce(
337
- jsonResponse(200, {
338
- memberships: [
339
- {
340
- membershipKey: "k1",
341
- companyUid: "cmp_acme",
342
- role: "member",
343
- status: "active",
344
- },
345
- ],
346
- }),
347
- );
348
- fetchSpy.mockResolvedValueOnce(jsonResponse(401, { error: "unauth" }));
349
-
350
- const program = buildProgram();
351
- await expect(
352
- program.parseAsync(
353
- ["files", "share", "foo", "--no-open"],
354
- { from: "user" },
355
- ),
356
- ).rejects.toThrow(/__EXIT__:1/);
357
-
358
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
359
- expect(errs).toMatch(/run `hq login`/);
360
- });
361
- });
362
-
363
- describe("hq files share — direct-grant fork (with --with)", () => {
364
- it("PRD scenario 2: --with email --permission read writes a direct grant and never calls the mint endpoint", async () => {
365
- // 1) /membership/me for company resolution
366
- fetchSpy.mockResolvedValueOnce(
367
- jsonResponse(200, {
368
- memberships: [
369
- {
370
- membershipKey: "k1",
371
- companyUid: "cmp_acme",
372
- role: "member",
373
- status: "active",
374
- },
375
- ],
376
- }),
377
- );
378
- // 2) POST /files/cmp_acme/acl/grant
379
- fetchSpy.mockResolvedValueOnce(
380
- jsonResponse(200, { acl: { path: "fooPath" } }),
381
- );
382
-
383
- const program = buildProgram();
384
- await program.parseAsync(
385
- [
386
- "files",
387
- "share",
388
- "fooPath",
389
- "--with",
390
- "user@example.com",
391
- "--permission",
392
- "read",
393
- ],
394
- { from: "user" },
395
- );
396
-
397
- // The mint endpoint MUST NOT have been called.
398
- const mintCalls = fetchSpy.mock.calls.filter((c) =>
399
- String(c[0]).includes("/share-session"),
400
- );
401
- expect(mintCalls).toHaveLength(0);
402
-
403
- // The grant endpoint WAS called with the right body.
404
- const grantCall = fetchSpy.mock.calls.find((c) =>
405
- String(c[0]).includes("/acl/grant"),
406
- );
407
- expect(grantCall).toBeDefined();
408
- const body = JSON.parse((grantCall![1]?.body as string) ?? "{}");
409
- expect(body).toEqual({
410
- prefix: "fooPath",
411
- granteeType: "email",
412
- granteeId: "user@example.com",
413
- permission: "read",
414
- });
415
-
416
- // Browser must not have launched in the direct-grant flow.
417
- expect(open).not.toHaveBeenCalled();
418
- });
419
-
420
- it("rejects multiple paths when --with is set", async () => {
421
- const program = buildProgram();
422
- await expect(
423
- program.parseAsync(
424
- [
425
- "files",
426
- "share",
427
- "a",
428
- "b",
429
- "--with",
430
- "user@example.com",
431
- "--permission",
432
- "read",
433
- ],
434
- { from: "user" },
435
- ),
436
- ).rejects.toThrow(/__EXIT__:1/);
437
-
438
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
439
- expect(errs).toMatch(/exactly one prefix/);
440
- expect(fetchSpy).not.toHaveBeenCalled();
441
- });
442
-
443
- it("US-001 regression: --with @all writes a company-wide grant (granteeType:'company-wide', granteeId:'')", async () => {
444
- // 1) /membership/me for company resolution
445
- fetchSpy.mockResolvedValueOnce(
446
- jsonResponse(200, {
447
- memberships: [
448
- {
449
- membershipKey: "k1",
450
- companyUid: "cmp_acme",
451
- role: "member",
452
- status: "active",
453
- },
454
- ],
455
- }),
456
- );
457
- // 2) POST /files/cmp_acme/acl/grant
458
- fetchSpy.mockResolvedValueOnce(
459
- jsonResponse(200, { acl: { path: "fooPath" } }),
460
- );
461
-
462
- const program = buildProgram();
463
- await program.parseAsync(
464
- ["files", "share", "fooPath", "--with", "@all", "--permission", "write"],
465
- { from: "user" },
466
- );
467
-
468
- // Mint endpoint MUST NOT have been called — direct-grant fork only.
469
- const mintCalls = fetchSpy.mock.calls.filter((c) =>
470
- String(c[0]).includes("/share-session"),
471
- );
472
- expect(mintCalls).toHaveLength(0);
473
-
474
- // Grant endpoint received a company-wide entry per US-001.
475
- const grantCall = fetchSpy.mock.calls.find((c) =>
476
- String(c[0]).includes("/acl/grant"),
477
- );
478
- expect(grantCall).toBeDefined();
479
- const body = JSON.parse((grantCall![1]?.body as string) ?? "{}");
480
- expect(body).toEqual({
481
- prefix: "fooPath",
482
- granteeType: "company-wide",
483
- granteeId: "",
484
- permission: "write",
485
- });
486
-
487
- // Browser must not have launched in the direct-grant flow.
488
- expect(open).not.toHaveBeenCalled();
489
- });
490
-
491
- it("rejects --with without --permission", async () => {
492
- const program = buildProgram();
493
- await expect(
494
- program.parseAsync(
495
- ["files", "share", "foo", "--with", "user@example.com"],
496
- { from: "user" },
497
- ),
498
- ).rejects.toThrow(/__EXIT__:1/);
499
-
500
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
501
- expect(errs).toMatch(/--permission is required/);
502
- expect(fetchSpy).not.toHaveBeenCalled();
503
- });
504
-
505
- it("--full --with email grants the '*' wildcard at the default write permission (no glob to quote)", async () => {
506
- // 1) /membership/me for company resolution
507
- fetchSpy.mockResolvedValueOnce(
508
- jsonResponse(200, {
509
- memberships: [
510
- {
511
- membershipKey: "k1",
512
- companyUid: "cmp_acme",
513
- role: "member",
514
- status: "active",
515
- },
516
- ],
517
- }),
518
- );
519
- // 2) POST /files/cmp_acme/acl/grant
520
- fetchSpy.mockResolvedValueOnce(
521
- jsonResponse(200, { acl: { path: "*" } }),
522
- );
523
-
524
- const program = buildProgram();
525
- // No positional path, no --permission — --full supplies prefix '*' and
526
- // defaults permission to write.
527
- await program.parseAsync(
528
- ["files", "share", "--full", "--with", "user@example.com"],
529
- { from: "user" },
530
- );
531
-
532
- const mintCalls = fetchSpy.mock.calls.filter((c) =>
533
- String(c[0]).includes("/share-session"),
534
- );
535
- expect(mintCalls).toHaveLength(0);
536
-
537
- const grantCall = fetchSpy.mock.calls.find((c) =>
538
- String(c[0]).includes("/acl/grant"),
539
- );
540
- expect(grantCall).toBeDefined();
541
- const body = JSON.parse((grantCall![1]?.body as string) ?? "{}");
542
- expect(body).toEqual({
543
- prefix: "*",
544
- granteeType: "email",
545
- granteeId: "user@example.com",
546
- permission: "write",
547
- });
548
-
549
- const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
550
- expect(printed).toMatch(/ENTIRE vault/);
551
- expect(open).not.toHaveBeenCalled();
552
- });
553
-
554
- it("--full honors an explicit --permission read (read-only full vault)", async () => {
555
- fetchSpy.mockResolvedValueOnce(
556
- jsonResponse(200, {
557
- memberships: [
558
- { membershipKey: "k1", companyUid: "cmp_acme", role: "member", status: "active" },
559
- ],
560
- }),
561
- );
562
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { acl: { path: "*" } }));
563
-
564
- const program = buildProgram();
565
- await program.parseAsync(
566
- ["files", "share", "--full", "--with", "user@example.com", "--permission", "read"],
567
- { from: "user" },
568
- );
569
-
570
- const grantCall = fetchSpy.mock.calls.find((c) =>
571
- String(c[0]).includes("/acl/grant"),
572
- );
573
- const body = JSON.parse((grantCall![1]?.body as string) ?? "{}");
574
- expect(body).toEqual({
575
- prefix: "*",
576
- granteeType: "email",
577
- granteeId: "user@example.com",
578
- permission: "read",
579
- });
580
- });
581
-
582
- it("--full composes with @all (whole vault for the whole company → company-wide '*')", async () => {
583
- fetchSpy.mockResolvedValueOnce(
584
- jsonResponse(200, {
585
- memberships: [
586
- { membershipKey: "k1", companyUid: "cmp_acme", role: "member", status: "active" },
587
- ],
588
- }),
589
- );
590
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { acl: { path: "*" } }));
591
-
592
- const program = buildProgram();
593
- await program.parseAsync(
594
- ["files", "share", "--full", "--with", "@all"],
595
- { from: "user" },
596
- );
597
-
598
- const grantCall = fetchSpy.mock.calls.find((c) =>
599
- String(c[0]).includes("/acl/grant"),
600
- );
601
- const body = JSON.parse((grantCall![1]?.body as string) ?? "{}");
602
- expect(body).toEqual({
603
- prefix: "*",
604
- granteeType: "company-wide",
605
- granteeId: "",
606
- permission: "write",
607
- });
608
- });
609
-
610
- it("rejects --full without --with (and never calls the network)", async () => {
611
- const program = buildProgram();
612
- await expect(
613
- program.parseAsync(["files", "share", "--full"], { from: "user" }),
614
- ).rejects.toThrow(/__EXIT__:1/);
615
-
616
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
617
- expect(errs).toMatch(/--full.*requires --with/);
618
- expect(fetchSpy).not.toHaveBeenCalled();
619
- });
620
-
621
- it("rejects --full when file paths are also passed", async () => {
622
- const program = buildProgram();
623
- await expect(
624
- program.parseAsync(
625
- ["files", "share", "somePath", "--full", "--with", "user@example.com"],
626
- { from: "user" },
627
- ),
628
- ).rejects.toThrow(/__EXIT__:1/);
629
-
630
- const errs = errSpy.mock.calls.map((c) => String(c[0])).join("\n");
631
- expect(errs).toMatch(/entire vault; do not also pass file paths/);
632
- expect(fetchSpy).not.toHaveBeenCalled();
633
- });
634
- });
635
-
636
- // ---------------------------------------------------------------------------
637
- // hq files unshare — never reports a false "removed" on a zero-row revoke
638
- // (Ridge / Connor #5, CLI side)
639
- // ---------------------------------------------------------------------------
640
-
641
- describe("hq files unshare", () => {
642
- function mockCompanyResolution() {
643
- // /membership/me for getCompanyUid
644
- fetchSpy.mockResolvedValueOnce(
645
- jsonResponse(200, {
646
- memberships: [
647
- { membershipKey: "k1", companyUid: "cmp_acme", role: "member", status: "active" },
648
- ],
649
- }),
650
- );
651
- }
652
-
653
- it("prints a green success ONLY when the server actually removed a grant (200)", async () => {
654
- mockCompanyResolution();
655
- fetchSpy.mockResolvedValueOnce(jsonResponse(200, { acl: { path: "fooPath" } }));
656
-
657
- const program = buildProgram();
658
- await program.parseAsync(
659
- ["files", "unshare", "fooPath", "--with", "user@example.com"],
660
- { from: "user" },
661
- );
662
-
663
- const logs = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
664
- expect(logs).toMatch(/Removed grant for user@example.com on 'fooPath'/);
665
- });
666
-
667
- it("#5: does NOT print a green 'removed' success when the revoke matched zero rows (GRANT_NOT_FOUND)", async () => {
668
- mockCompanyResolution();
669
- fetchSpy.mockResolvedValueOnce(
670
- jsonResponse(404, { error: "grant not found", code: "GRANT_NOT_FOUND" }),
671
- );
672
- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
673
-
674
- const program = buildProgram();
675
- // Must NOT exit non-zero (idempotent no-op), and must NOT throw.
676
- await program.parseAsync(
677
- ["files", "unshare", "fooPath", "--with", "user@example.com"],
678
- { from: "user" },
679
- );
680
-
681
- const logs = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
682
- const warns = warnSpy.mock.calls.map((c) => String(c[0])).join("\n");
683
- // The dangerous false-success line must be absent.
684
- expect(logs).not.toMatch(/Removed grant/);
685
- // A truthful "nothing was removed" warning is surfaced instead.
686
- expect(warns).toMatch(/nothing was removed/i);
687
- });
688
-
689
- it("treats a prefix with no ACL (ACL_NOT_FOUND) as benignly absent, not a removal", async () => {
690
- mockCompanyResolution();
691
- fetchSpy.mockResolvedValueOnce(
692
- jsonResponse(404, { error: "ACL not found", code: "ACL_NOT_FOUND" }),
693
- );
694
-
695
- const program = buildProgram();
696
- await program.parseAsync(
697
- ["files", "unshare", "never-shared", "--with", "user@example.com"],
698
- { from: "user" },
699
- );
700
-
701
- const logs = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
702
- expect(logs).not.toMatch(/Removed grant/);
703
- expect(logs).toMatch(/has no sharing grants/);
704
- });
705
-
706
- it("falls back to a warning for an older server that returns 404 without a code", async () => {
707
- mockCompanyResolution();
708
- fetchSpy.mockResolvedValueOnce(jsonResponse(404, { error: "grant not found" }));
709
- const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => undefined);
710
-
711
- const program = buildProgram();
712
- await program.parseAsync(
713
- ["files", "unshare", "fooPath", "--with", "user@example.com"],
714
- { from: "user" },
715
- );
716
-
717
- const logs = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
718
- const warns = warnSpy.mock.calls.map((c) => String(c[0])).join("\n");
719
- expect(logs).not.toMatch(/Removed grant/);
720
- expect(warns).toMatch(/nothing was removed/i);
721
- });
722
- });