@indigoai-us/hq-cli 5.77.13 → 5.78.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 (307) hide show
  1. package/CHANGELOG.md +34 -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/members.js +16 -5
  31. package/dist/commands/pack-install.d.ts +14 -0
  32. package/dist/commands/pack-install.js +51 -2
  33. package/dist/commands/pkg-install.js +43 -0
  34. package/dist/commands/run.js +8 -0
  35. package/dist/commands/secrets.js +125 -65
  36. package/dist/main.js +6 -0
  37. package/dist/utils/api-key-command-gate.d.ts +45 -0
  38. package/dist/utils/api-key-command-gate.js +51 -0
  39. package/dist/utils/hq-roots.d.ts +91 -0
  40. package/dist/utils/hq-roots.js +212 -0
  41. package/dist/utils/resolve-vault-credential.d.ts +63 -3
  42. package/dist/utils/resolve-vault-credential.js +152 -6
  43. package/dist/utils/run-bundled-script.d.ts +66 -0
  44. package/dist/utils/run-bundled-script.js +80 -0
  45. package/dist/utils/vault-api.d.ts +21 -0
  46. package/dist/utils/vault-api.js +74 -3
  47. package/package.json +7 -1
  48. package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
  49. package/.github/workflows/ci.yml +0 -46
  50. package/.github/workflows/publish.yml +0 -36
  51. package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
  52. package/e2e/cli.test.ts +0 -128
  53. package/eslint.config.js +0 -37
  54. package/pnpm-workspace.yaml +0 -4
  55. package/scripts/chmod-bins.mjs +0 -49
  56. package/scripts/generate-dsn.mjs +0 -26
  57. package/scripts/generate-scan-packages-table.mjs +0 -113
  58. package/scripts/smoke-sources-signals.sh +0 -103
  59. package/src/bin/hq-auth-refresh.ts +0 -43
  60. package/src/cli-version.ts +0 -13
  61. package/src/commands/__fixtures__/make-tar.ts +0 -126
  62. package/src/commands/_patterns.ts +0 -10
  63. package/src/commands/add.ts +0 -75
  64. package/src/commands/agents.test.ts +0 -527
  65. package/src/commands/agents.ts +0 -923
  66. package/src/commands/api-keys.test.ts +0 -291
  67. package/src/commands/api-keys.ts +0 -382
  68. package/src/commands/artifact-verify.test.ts +0 -177
  69. package/src/commands/auth.test.ts +0 -82
  70. package/src/commands/auth.ts +0 -213
  71. package/src/commands/billing.test.ts +0 -158
  72. package/src/commands/billing.ts +0 -146
  73. package/src/commands/channels.test.ts +0 -74
  74. package/src/commands/channels.ts +0 -91
  75. package/src/commands/cloud-demote.test.ts +0 -401
  76. package/src/commands/cloud-demote.ts +0 -278
  77. package/src/commands/cloud-provision.test.ts +0 -1117
  78. package/src/commands/cloud-provision.ts +0 -942
  79. package/src/commands/cloud.pull-all.test.ts +0 -711
  80. package/src/commands/cloud.pull-per-company.test.ts +0 -188
  81. package/src/commands/cloud.push-all.test.ts +0 -485
  82. package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
  83. package/src/commands/cloud.selectors.test.ts +0 -208
  84. package/src/commands/cloud.status.test.ts +0 -160
  85. package/src/commands/cloud.test.ts +0 -41
  86. package/src/commands/cloud.ts +0 -2130
  87. package/src/commands/company.test.ts +0 -202
  88. package/src/commands/company.ts +0 -148
  89. package/src/commands/creators.test.ts +0 -60
  90. package/src/commands/creators.ts +0 -117
  91. package/src/commands/crm.test.ts +0 -179
  92. package/src/commands/crm.ts +0 -236
  93. package/src/commands/db-migrate.ts +0 -55
  94. package/src/commands/db-provision.ts +0 -114
  95. package/src/commands/db-sql.ts +0 -124
  96. package/src/commands/db-status.ts +0 -108
  97. package/src/commands/db.ts +0 -26
  98. package/src/commands/dm.test.ts +0 -748
  99. package/src/commands/dm.ts +0 -1226
  100. package/src/commands/feedback.test.ts +0 -413
  101. package/src/commands/feedback.ts +0 -169
  102. package/src/commands/files-browse.test.ts +0 -1249
  103. package/src/commands/files-browse.ts +0 -1506
  104. package/src/commands/files-delete.test.ts +0 -484
  105. package/src/commands/files-recovery.test.ts +0 -370
  106. package/src/commands/files.test.ts +0 -722
  107. package/src/commands/files.ts +0 -1446
  108. package/src/commands/group-grants.test.ts +0 -330
  109. package/src/commands/group-grants.ts +0 -455
  110. package/src/commands/groups.test.ts +0 -44
  111. package/src/commands/groups.ts +0 -368
  112. package/src/commands/integrations.test.ts +0 -633
  113. package/src/commands/integrations.ts +0 -507
  114. package/src/commands/list.ts +0 -85
  115. package/src/commands/login.ts +0 -52
  116. package/src/commands/logout.ts +0 -30
  117. package/src/commands/marketplace-install.test.ts +0 -543
  118. package/src/commands/marketplace-security.test.ts +0 -646
  119. package/src/commands/mcp-registration.test.ts +0 -2787
  120. package/src/commands/mcp-registration.ts +0 -2612
  121. package/src/commands/mcp-status.test.ts +0 -483
  122. package/src/commands/mcp-status.ts +0 -575
  123. package/src/commands/mcp-status.us011.test.ts +0 -243
  124. package/src/commands/meetings.test.ts +0 -522
  125. package/src/commands/meetings.ts +0 -789
  126. package/src/commands/members.test.ts +0 -1474
  127. package/src/commands/members.ts +0 -1181
  128. package/src/commands/onboard-identity-guard.test.ts +0 -99
  129. package/src/commands/onboard-identity-guard.ts +0 -103
  130. package/src/commands/onboard-join.test.ts +0 -96
  131. package/src/commands/onboard-join.ts +0 -101
  132. package/src/commands/onboard-warning.test.ts +0 -26
  133. package/src/commands/onboard-warning.ts +0 -12
  134. package/src/commands/onboard.ts +0 -267
  135. package/src/commands/outposts-heartbeat.test.ts +0 -299
  136. package/src/commands/outposts-heartbeat.ts +0 -310
  137. package/src/commands/outposts-replica-sync.test.ts +0 -272
  138. package/src/commands/outposts-self-deploy.test.ts +0 -243
  139. package/src/commands/outposts.test.ts +0 -1039
  140. package/src/commands/outposts.ts +0 -1935
  141. package/src/commands/pack-install-secret-authorization.test.ts +0 -115
  142. package/src/commands/pack-install.test.ts +0 -1469
  143. package/src/commands/pack-install.ts +0 -2247
  144. package/src/commands/pack-update-cache.test.ts +0 -149
  145. package/src/commands/packs.test.ts +0 -88
  146. package/src/commands/packs.ts +0 -622
  147. package/src/commands/people.test.ts +0 -807
  148. package/src/commands/people.ts +0 -422
  149. package/src/commands/pkg-install.dispatch.test.ts +0 -71
  150. package/src/commands/pkg-install.ts +0 -215
  151. package/src/commands/pkg-list.test.ts +0 -79
  152. package/src/commands/pkg-list.ts +0 -13
  153. package/src/commands/pkg-remove.ts +0 -71
  154. package/src/commands/pkg-update.ts +0 -189
  155. package/src/commands/publish.test.ts +0 -650
  156. package/src/commands/publish.ts +0 -580
  157. package/src/commands/reindex.test.ts +0 -259
  158. package/src/commands/reindex.ts +0 -274
  159. package/src/commands/rescue.test.ts +0 -39
  160. package/src/commands/rescue.ts +0 -210
  161. package/src/commands/run.env-local.test.ts +0 -88
  162. package/src/commands/run.test.ts +0 -45
  163. package/src/commands/run.ts +0 -184
  164. package/src/commands/safe-extract.test.ts +0 -459
  165. package/src/commands/safe-extract.ts +0 -444
  166. package/src/commands/secrets-scope.test.ts +0 -56
  167. package/src/commands/secrets-scope.ts +0 -32
  168. package/src/commands/secrets.parse-destination.test.ts +0 -38
  169. package/src/commands/secrets.test.ts +0 -2037
  170. package/src/commands/secrets.ts +0 -2240
  171. package/src/commands/signals.ts +0 -351
  172. package/src/commands/skill.test.ts +0 -770
  173. package/src/commands/skill.ts +0 -796
  174. package/src/commands/sources.ts +0 -362
  175. package/src/commands/sync-mode.test.ts +0 -366
  176. package/src/commands/sync-mode.ts +0 -387
  177. package/src/commands/sync-narrow.test.ts +0 -633
  178. package/src/commands/sync-narrow.ts +0 -555
  179. package/src/commands/sync.ts +0 -165
  180. package/src/commands/team-sync.ts +0 -628
  181. package/src/commands/update.ts +0 -71
  182. package/src/commands/whoami.ts +0 -83
  183. package/src/commands/workers.test.ts +0 -158
  184. package/src/commands/workers.ts +0 -301
  185. package/src/index.test.ts +0 -32
  186. package/src/index.ts +0 -20
  187. package/src/lib/db/control-plane.test.ts +0 -59
  188. package/src/lib/db/control-plane.ts +0 -113
  189. package/src/lib/db/local.test.ts +0 -81
  190. package/src/lib/db/local.ts +0 -148
  191. package/src/lib/db/migrate.test.ts +0 -133
  192. package/src/lib/db/migrate.ts +0 -137
  193. package/src/lib/db/paths.test.ts +0 -112
  194. package/src/lib/db/paths.ts +0 -128
  195. package/src/lib/db/remote-engine.test.ts +0 -44
  196. package/src/lib/db/remote-engine.ts +0 -148
  197. package/src/lib/db/remote-sql.test.ts +0 -32
  198. package/src/lib/db/remote-sql.ts +0 -62
  199. package/src/lib/db/sql.test.ts +0 -106
  200. package/src/lib/db/sql.ts +0 -192
  201. package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
  202. package/src/lib/local-tree-diff.test.ts +0 -301
  203. package/src/lib/local-tree-diff.ts +0 -362
  204. package/src/lib/narrow-hint-banner.test.ts +0 -235
  205. package/src/lib/narrow-hint-banner.ts +0 -212
  206. package/src/lib/plan-limit-nag.test.ts +0 -317
  207. package/src/lib/plan-limit-nag.ts +0 -264
  208. package/src/main.ts +0 -371
  209. package/src/node-preflight.test.ts +0 -60
  210. package/src/node-preflight.ts +0 -67
  211. package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
  212. package/src/outpost/session-heartbeat-guard.test.ts +0 -105
  213. package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
  214. package/src/outpost/session-heartbeat-publisher.ts +0 -186
  215. package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
  216. package/src/outpost/session-heartbeat.test.ts +0 -459
  217. package/src/outpost/session-heartbeat.ts +0 -877
  218. package/src/packaging.test.ts +0 -109
  219. package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
  220. package/src/run/discover-schemas.test.ts +0 -153
  221. package/src/run/discover-schemas.ts +0 -79
  222. package/src/run/hq-plugin.test.ts +0 -371
  223. package/src/run/hq-plugin.ts +0 -277
  224. package/src/run/varlock-shape.test.ts +0 -57
  225. package/src/schemas/hq-package.schema.json +0 -155
  226. package/src/sentry-before-send.test.ts +0 -359
  227. package/src/sentry-before-send.ts +0 -221
  228. package/src/sentry-epipe.test.ts +0 -37
  229. package/src/sentry-release.test.ts +0 -54
  230. package/src/sentry.test.ts +0 -24
  231. package/src/sentry.ts +0 -54
  232. package/src/strategies/link.ts +0 -62
  233. package/src/strategies/merge.ts +0 -142
  234. package/src/types.ts +0 -146
  235. package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
  236. package/src/utils/auth-error.test.ts +0 -40
  237. package/src/utils/auth-error.ts +0 -42
  238. package/src/utils/billing-gate.test.ts +0 -95
  239. package/src/utils/billing-gate.ts +0 -228
  240. package/src/utils/breadcrumb-buffer.ts +0 -18
  241. package/src/utils/cli-telemetry.test.ts +0 -153
  242. package/src/utils/cli-telemetry.ts +0 -61
  243. package/src/utils/cognito-session.machine.test.ts +0 -109
  244. package/src/utils/cognito-session.refresh.test.ts +0 -84
  245. package/src/utils/cognito-session.test.ts +0 -328
  246. package/src/utils/cognito-session.ts +0 -448
  247. package/src/utils/company-selection-error.test.ts +0 -42
  248. package/src/utils/company-selection-error.ts +0 -45
  249. package/src/utils/contribution-table.ts +0 -83
  250. package/src/utils/environmental-error.test.ts +0 -45
  251. package/src/utils/environmental-error.ts +0 -39
  252. package/src/utils/epipe.test.ts +0 -28
  253. package/src/utils/epipe.ts +0 -29
  254. package/src/utils/expected-cli-error.test.ts +0 -28
  255. package/src/utils/expected-cli-error.ts +0 -39
  256. package/src/utils/feedback-diagnostics.test.ts +0 -183
  257. package/src/utils/feedback-diagnostics.ts +0 -123
  258. package/src/utils/feedback-screenshots.test.ts +0 -134
  259. package/src/utils/feedback-screenshots.ts +0 -124
  260. package/src/utils/feedback-versions.test.ts +0 -98
  261. package/src/utils/feedback-versions.ts +0 -68
  262. package/src/utils/git.ts +0 -74
  263. package/src/utils/integrity.ts +0 -59
  264. package/src/utils/intercepted-process-exit.test.ts +0 -37
  265. package/src/utils/intercepted-process-exit.ts +0 -36
  266. package/src/utils/login-provider.test.ts +0 -42
  267. package/src/utils/login-provider.ts +0 -30
  268. package/src/utils/manifest.test.ts +0 -167
  269. package/src/utils/manifest.ts +0 -131
  270. package/src/utils/pack-contributions.test.ts +0 -603
  271. package/src/utils/pack-contributions.ts +0 -450
  272. package/src/utils/people.ts +0 -215
  273. package/src/utils/registry-client.ts +0 -204
  274. package/src/utils/registry.ts +0 -90
  275. package/src/utils/resolve-vault-credential.test.ts +0 -69
  276. package/src/utils/resolve-vault-credential.ts +0 -60
  277. package/src/utils/sandbox-runner-client.test.ts +0 -279
  278. package/src/utils/sandbox-runner-client.ts +0 -260
  279. package/src/utils/secrets-cache.ts +0 -183
  280. package/src/utils/sentry-identity.ts +0 -45
  281. package/src/utils/settle-with-timeout.test.ts +0 -21
  282. package/src/utils/settle-with-timeout.ts +0 -22
  283. package/src/utils/user-yaml-error.test.ts +0 -24
  284. package/src/utils/user-yaml-error.ts +0 -30
  285. package/src/utils/vault-api.test.ts +0 -536
  286. package/src/utils/vault-api.ts +0 -382
  287. package/src/utils/version-check.test.ts +0 -176
  288. package/src/utils/version-check.ts +0 -155
  289. package/src/utils/version-gate.test.ts +0 -1024
  290. package/src/utils/version-gate.ts +0 -702
  291. package/test/commands/db-tenant-isolation.test.ts +0 -94
  292. package/test/commands/db.test.ts +0 -85
  293. package/test/commands/signals.test.ts +0 -207
  294. package/test/commands/sources.test.ts +0 -231
  295. package/test/e2e/smoke-install-mcp.sh +0 -113
  296. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
  297. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
  298. package/test/fixtures/signals/action_item/sample.md +0 -16
  299. package/test/fixtures/signals/summary/sample.md +0 -12
  300. package/test/fixtures/sources/meetings/sample.md +0 -25
  301. package/test/helpers/cli-runner.ts +0 -150
  302. package/test/helpers/s3-list-mock.ts +0 -79
  303. package/test/helpers/vault-service-mock.ts +0 -295
  304. package/test/sources-signals/smoke.test.ts +0 -228
  305. package/tsconfig.json +0 -20
  306. package/vitest.config.ts +0 -11
  307. 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
- });