@indigoai-us/hq-cli 5.12.4 → 5.13.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.
@@ -0,0 +1,96 @@
1
+ import {
2
+ afterEach,
3
+ beforeEach,
4
+ describe,
5
+ expect,
6
+ it,
7
+ vi,
8
+ type MockInstance,
9
+ } from "vitest";
10
+
11
+ vi.mock("../utils/cognito-session.js", async (importOriginal) => {
12
+ const original = (await importOriginal()) as Record<string, unknown>;
13
+ return {
14
+ ...original,
15
+ ensureCognitoToken: vi.fn(async () => "test-token"),
16
+ };
17
+ });
18
+
19
+ vi.mock("../utils/vault-api.js", async (importOriginal) => {
20
+ const original = (await importOriginal()) as Record<string, unknown>;
21
+ return {
22
+ ...original,
23
+ getEntityUid: vi.fn(async () => "prs_alice"),
24
+ vaultApiFetch: vi.fn(async () =>
25
+ new Response(
26
+ JSON.stringify({
27
+ url: "https://hq.example/secrets-input/tok_secret",
28
+ expiresAt: "2026-05-12T12:00:00.000Z",
29
+ secretName: "MY_KEY",
30
+ }),
31
+ { status: 200, headers: { "Content-Type": "application/json" } },
32
+ ),
33
+ ),
34
+ };
35
+ });
36
+
37
+ import { Command } from "commander";
38
+ import { registerSecretsCommand } from "./secrets.js";
39
+ import { getEntityUid, vaultApiFetch } from "../utils/vault-api.js";
40
+
41
+ let logSpy: MockInstance<typeof console.log>;
42
+ let errSpy: MockInstance<typeof console.error>;
43
+
44
+ beforeEach(() => {
45
+ vi.clearAllMocks();
46
+ logSpy = vi.spyOn(console, "log").mockImplementation(() => undefined);
47
+ errSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
48
+ });
49
+
50
+ afterEach(() => {
51
+ vi.restoreAllMocks();
52
+ });
53
+
54
+ function buildProgram(): Command {
55
+ const program = new Command();
56
+ program.exitOverride();
57
+ program.configureOutput({
58
+ writeOut: () => undefined,
59
+ writeErr: () => undefined,
60
+ });
61
+ registerSecretsCommand(program);
62
+ return program;
63
+ }
64
+
65
+ describe("secrets generate-link", () => {
66
+ it("mints one-time submission links for personal secrets", async () => {
67
+ const program = buildProgram();
68
+
69
+ await program.parseAsync([
70
+ "node",
71
+ "hq",
72
+ "secrets",
73
+ "--personal",
74
+ "generate-link",
75
+ "MY_KEY",
76
+ "--expires",
77
+ "30m",
78
+ ]);
79
+
80
+ expect(getEntityUid).toHaveBeenCalledWith("test-token", {
81
+ personal: true,
82
+ companySlug: undefined,
83
+ });
84
+ expect(vaultApiFetch).toHaveBeenCalledWith({
85
+ token: "test-token",
86
+ path: "/secrets/prs_alice/name/MY_KEY",
87
+ method: "POST",
88
+ body: { expiresInMs: 30 * 60 * 1000 },
89
+ query: { action: "generate-token" },
90
+ });
91
+ expect(logSpy).toHaveBeenCalledWith(
92
+ expect.stringContaining("Secret input link generated"),
93
+ );
94
+ expect(errSpy).not.toHaveBeenCalled();
95
+ });
96
+ });
@@ -615,8 +615,6 @@ export function registerSecretsCommand(program: Command): void {
615
615
  .option("--expires <duration>", "Token expiry duration (e.g. 24h, 2d, 30m)", "24h")
616
616
  .action(async (name: string, opts: { expires: string }) => {
617
617
  try {
618
- rejectIfPersonal(secrets.opts(), "generate-link");
619
-
620
618
  if (!SECRET_NAME_PATTERN.test(name)) {
621
619
  console.error(chalk.red(`Invalid secret name '${name}': must match ^[A-Z][A-Z0-9_]*(/[A-Z][A-Z0-9_]+)*$ (e.g. MY_API_KEY or DEV/MY_KEY)`));
622
620
  process.exit(1);
package/src/index.ts CHANGED
@@ -35,6 +35,16 @@ import {
35
35
  refreshVersionCache,
36
36
  } from "./utils/version-check.js";
37
37
 
38
+ // Swallow EPIPE when a downstream reader (e.g. `source <(…)`, `| head`) closes the pipe early.
39
+ const onPipeError = (err: NodeJS.ErrnoException): void => {
40
+ if (err.code === "EPIPE") {
41
+ process.exit(0);
42
+ }
43
+ throw err;
44
+ };
45
+ process.stdout.on("error", onPipeError);
46
+ process.stderr.on("error", onPipeError);
47
+
38
48
  initSentry();
39
49
  maybeWarnNewVersion();
40
50