@indigoai-us/hq-cloud 6.15.4 → 6.15.5

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 (132) hide show
  1. package/dist/cli/push-scan-exclusions.test.d.ts +2 -0
  2. package/dist/cli/push-scan-exclusions.test.d.ts.map +1 -0
  3. package/dist/cli/push-scan-exclusions.test.js +87 -0
  4. package/dist/cli/push-scan-exclusions.test.js.map +1 -0
  5. package/dist/cli/share.d.ts.map +1 -1
  6. package/dist/cli/share.js +21 -1
  7. package/dist/cli/share.js.map +1 -1
  8. package/dist/cli/share.test.js +82 -0
  9. package/dist/cli/share.test.js.map +1 -1
  10. package/dist/cli/sync.d.ts +23 -0
  11. package/dist/cli/sync.d.ts.map +1 -1
  12. package/dist/cli/sync.js +9 -0
  13. package/dist/cli/sync.js.map +1 -1
  14. package/dist/outposts/billing.d.ts +41 -0
  15. package/dist/outposts/billing.d.ts.map +1 -0
  16. package/dist/outposts/billing.js +53 -0
  17. package/dist/outposts/billing.js.map +1 -0
  18. package/dist/outposts/cli-billing.d.ts +59 -0
  19. package/dist/outposts/cli-billing.d.ts.map +1 -0
  20. package/dist/outposts/cli-billing.js +93 -0
  21. package/dist/outposts/cli-billing.js.map +1 -0
  22. package/dist/outposts/cli.d.ts +13 -0
  23. package/dist/outposts/cli.d.ts.map +1 -0
  24. package/dist/outposts/cli.js +13 -0
  25. package/dist/outposts/cli.js.map +1 -0
  26. package/dist/outposts/client.d.ts +140 -0
  27. package/dist/outposts/client.d.ts.map +1 -0
  28. package/dist/outposts/client.js +271 -0
  29. package/dist/outposts/client.js.map +1 -0
  30. package/dist/outposts/client.test.d.ts +9 -0
  31. package/dist/outposts/client.test.d.ts.map +1 -0
  32. package/dist/outposts/client.test.js +226 -0
  33. package/dist/outposts/client.test.js.map +1 -0
  34. package/dist/outposts/command.d.ts +74 -0
  35. package/dist/outposts/command.d.ts.map +1 -0
  36. package/dist/outposts/command.js +661 -0
  37. package/dist/outposts/command.js.map +1 -0
  38. package/dist/outposts/command.test.d.ts +18 -0
  39. package/dist/outposts/command.test.d.ts.map +1 -0
  40. package/dist/outposts/command.test.js +933 -0
  41. package/dist/outposts/command.test.js.map +1 -0
  42. package/dist/outposts/errors.d.ts +32 -0
  43. package/dist/outposts/errors.d.ts.map +1 -0
  44. package/dist/outposts/errors.js +72 -0
  45. package/dist/outposts/errors.js.map +1 -0
  46. package/dist/outposts/heartbeat-command.d.ts +106 -0
  47. package/dist/outposts/heartbeat-command.d.ts.map +1 -0
  48. package/dist/outposts/heartbeat-command.js +186 -0
  49. package/dist/outposts/heartbeat-command.js.map +1 -0
  50. package/dist/outposts/host-deps.d.ts +49 -0
  51. package/dist/outposts/host-deps.d.ts.map +1 -0
  52. package/dist/outposts/host-deps.js +93 -0
  53. package/dist/outposts/host-deps.js.map +1 -0
  54. package/dist/outposts/index.d.ts +36 -0
  55. package/dist/outposts/index.d.ts.map +1 -0
  56. package/dist/outposts/index.js +32 -0
  57. package/dist/outposts/index.js.map +1 -0
  58. package/dist/outposts/node.d.ts +23 -0
  59. package/dist/outposts/node.d.ts.map +1 -0
  60. package/dist/outposts/node.js +22 -0
  61. package/dist/outposts/node.js.map +1 -0
  62. package/dist/outposts/remote-command.d.ts +30 -0
  63. package/dist/outposts/remote-command.d.ts.map +1 -0
  64. package/dist/outposts/remote-command.js +39 -0
  65. package/dist/outposts/remote-command.js.map +1 -0
  66. package/dist/outposts/replica-sync.d.ts +40 -0
  67. package/dist/outposts/replica-sync.d.ts.map +1 -0
  68. package/dist/outposts/replica-sync.js +188 -0
  69. package/dist/outposts/replica-sync.js.map +1 -0
  70. package/dist/outposts/replica-sync.test.d.ts +2 -0
  71. package/dist/outposts/replica-sync.test.d.ts.map +1 -0
  72. package/dist/outposts/replica-sync.test.js +224 -0
  73. package/dist/outposts/replica-sync.test.js.map +1 -0
  74. package/dist/outposts/self-deploy.d.ts +47 -0
  75. package/dist/outposts/self-deploy.d.ts.map +1 -0
  76. package/dist/outposts/self-deploy.js +188 -0
  77. package/dist/outposts/self-deploy.js.map +1 -0
  78. package/dist/outposts/self-deploy.test.d.ts +2 -0
  79. package/dist/outposts/self-deploy.test.d.ts.map +1 -0
  80. package/dist/outposts/self-deploy.test.js +186 -0
  81. package/dist/outposts/self-deploy.test.js.map +1 -0
  82. package/dist/outposts/session-heartbeat-bounds.test.d.ts +25 -0
  83. package/dist/outposts/session-heartbeat-bounds.test.d.ts.map +1 -0
  84. package/dist/outposts/session-heartbeat-bounds.test.js +156 -0
  85. package/dist/outposts/session-heartbeat-bounds.test.js.map +1 -0
  86. package/dist/outposts/session-heartbeat-guard.test.d.ts +16 -0
  87. package/dist/outposts/session-heartbeat-guard.test.d.ts.map +1 -0
  88. package/dist/outposts/session-heartbeat-guard.test.js +88 -0
  89. package/dist/outposts/session-heartbeat-guard.test.js.map +1 -0
  90. package/dist/outposts/session-heartbeat-publisher.d.ts +76 -0
  91. package/dist/outposts/session-heartbeat-publisher.d.ts.map +1 -0
  92. package/dist/outposts/session-heartbeat-publisher.js +117 -0
  93. package/dist/outposts/session-heartbeat-publisher.js.map +1 -0
  94. package/dist/outposts/session-heartbeat-publisher.test.d.ts +10 -0
  95. package/dist/outposts/session-heartbeat-publisher.test.d.ts.map +1 -0
  96. package/dist/outposts/session-heartbeat-publisher.test.js +153 -0
  97. package/dist/outposts/session-heartbeat-publisher.test.js.map +1 -0
  98. package/dist/outposts/session-heartbeat-retain-guard.test.d.ts +18 -0
  99. package/dist/outposts/session-heartbeat-retain-guard.test.d.ts.map +1 -0
  100. package/dist/outposts/session-heartbeat-retain-guard.test.js +106 -0
  101. package/dist/outposts/session-heartbeat-retain-guard.test.js.map +1 -0
  102. package/dist/outposts/session-heartbeat.d.ts +210 -0
  103. package/dist/outposts/session-heartbeat.d.ts.map +1 -0
  104. package/dist/outposts/session-heartbeat.js +657 -0
  105. package/dist/outposts/session-heartbeat.js.map +1 -0
  106. package/dist/outposts/session-heartbeat.test.d.ts +11 -0
  107. package/dist/outposts/session-heartbeat.test.d.ts.map +1 -0
  108. package/dist/outposts/session-heartbeat.test.js +370 -0
  109. package/dist/outposts/session-heartbeat.test.js.map +1 -0
  110. package/dist/outposts/ssh.d.ts +29 -0
  111. package/dist/outposts/ssh.d.ts.map +1 -0
  112. package/dist/outposts/ssh.js +66 -0
  113. package/dist/outposts/ssh.js.map +1 -0
  114. package/dist/outposts/transport.d.ts +76 -0
  115. package/dist/outposts/transport.d.ts.map +1 -0
  116. package/dist/outposts/transport.js +91 -0
  117. package/dist/outposts/transport.js.map +1 -0
  118. package/dist/outposts/transport.test.d.ts +10 -0
  119. package/dist/outposts/transport.test.d.ts.map +1 -0
  120. package/dist/outposts/transport.test.js +116 -0
  121. package/dist/outposts/transport.test.js.map +1 -0
  122. package/dist/outposts/types.d.ts +125 -0
  123. package/dist/outposts/types.d.ts.map +1 -0
  124. package/dist/outposts/types.js +13 -0
  125. package/dist/outposts/types.js.map +1 -0
  126. package/dist/personal-vault.d.ts +69 -0
  127. package/dist/personal-vault.d.ts.map +1 -1
  128. package/dist/personal-vault.js +100 -0
  129. package/dist/personal-vault.js.map +1 -1
  130. package/dist/personal-vault.test.js +140 -1
  131. package/dist/personal-vault.test.js.map +1 -1
  132. package/package.json +39 -3
@@ -0,0 +1,933 @@
1
+ /**
2
+ * Unit tests for the `outposts` command tree.
3
+ *
4
+ * Drives real Commander parses and spies on global `fetch`, asserting the
5
+ * `/outpost/*` request shape (method + path + query + body) plus the guards that
6
+ * matter: the destroy confirmation, the paid-provision gate, the teardown-incomplete
7
+ * retry, the per-person cap, the two 402 billing remediations, and the Lightsail
8
+ * SSH fallback.
9
+ *
10
+ * Ported from hq-cli when this surface moved into hq-cloud. The host seams the CLI
11
+ * used to own — token resolution and the cached session read — arrive through
12
+ * `OutpostsCommandDeps` here, so these tests inject them directly instead of
13
+ * module-mocking the CLI's internals.
14
+ *
15
+ * Outposts are caller-scoped, so there is no company resolution to mock.
16
+ */
17
+ import { Command } from "commander";
18
+ import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
19
+ // The SSH fallback shells out to `ssh` via spawnSync — stub it so tests don't
20
+ // touch a real box or need the ssh binary.
21
+ vi.mock("node:child_process", async (importOriginal) => {
22
+ const original = await importOriginal();
23
+ return { ...original, spawnSync: vi.fn() };
24
+ });
25
+ import { execFileSync, spawnSync } from "node:child_process";
26
+ import * as fs from "node:fs";
27
+ import * as path from "node:path";
28
+ import { OutpostsClient } from "./client.js";
29
+ import { registerOutpostsCommand } from "./command.js";
30
+ import { joinCommandParts, withRemoteHqDir } from "./remote-command.js";
31
+ import { createOutpostTransport } from "./transport.js";
32
+ const mockSpawnSync = vi.mocked(spawnSync);
33
+ const TEST_API_URL = "https://hqapi.test.invalid";
34
+ function jsonResponse(status, body) {
35
+ return new Response(JSON.stringify(body), {
36
+ status,
37
+ headers: { "Content-Type": "application/json" },
38
+ });
39
+ }
40
+ let fetchSpy;
41
+ let exitSpy;
42
+ let logSpy;
43
+ beforeEach(() => {
44
+ vi.clearAllMocks();
45
+ fetchSpy = vi.spyOn(globalThis, "fetch");
46
+ exitSpy = vi
47
+ .spyOn(process, "exit")
48
+ .mockImplementation((code) => {
49
+ throw new Error(`process.exit(${code})`);
50
+ });
51
+ logSpy = vi.spyOn(console, "log").mockImplementation(() => { });
52
+ vi.spyOn(console, "error").mockImplementation(() => { });
53
+ });
54
+ afterEach(() => {
55
+ vi.restoreAllMocks();
56
+ });
57
+ function testTransport() {
58
+ return createOutpostTransport({ baseUrl: TEST_API_URL });
59
+ }
60
+ function testDeps(overrides = {}) {
61
+ return {
62
+ transport: testTransport(),
63
+ getToken: async () => "test-token",
64
+ // Provision sends the cached refresh token to the box; stub the session read
65
+ // so tests never need a real login on disk.
66
+ loadCachedTokens: () => ({ refreshToken: "rt_test" }),
67
+ resolveCallerPersonUid: async () => "prs_test",
68
+ defaultApiBaseUrl: TEST_API_URL,
69
+ ...overrides,
70
+ };
71
+ }
72
+ function buildProgram(overrides = {}) {
73
+ const program = new Command();
74
+ program.name("hq").exitOverride();
75
+ registerOutpostsCommand(program, testDeps(overrides));
76
+ return program;
77
+ }
78
+ async function run(args, overrides = {}) {
79
+ await buildProgram(overrides).parseAsync(["node", "hq", ...args]);
80
+ }
81
+ describe("outposts list", () => {
82
+ it("GETs /outpost/list", async () => {
83
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
84
+ outposts: [
85
+ {
86
+ outpostId: "primary",
87
+ state: "running",
88
+ instanceName: "outpost-abc",
89
+ region: "us-east-1",
90
+ agentRuntime: "claude",
91
+ platform: "ec2",
92
+ createdAt: "2026-01-01T00:00:00Z",
93
+ },
94
+ ],
95
+ }));
96
+ await run(["outposts", "list"]);
97
+ const [url, init] = fetchSpy.mock.calls[0];
98
+ expect(String(url)).toContain("/outpost/list");
99
+ expect(init?.method ?? "GET").toBe("GET");
100
+ });
101
+ it("sends the resolved bearer token", async () => {
102
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { outposts: [] }));
103
+ await run(["outposts", "list"]);
104
+ const headers = fetchSpy.mock.calls[0][1]?.headers;
105
+ expect(headers.Authorization).toBe("Bearer test-token");
106
+ });
107
+ it("re-resolves the token per command so a refreshed session is picked up", async () => {
108
+ // The CLI passes `ensureCognitoToken`, which returns a NEW token once the old
109
+ // one nears expiry. Pinning the token at construction would send a stale one.
110
+ let calls = 0;
111
+ // A fresh Response per call — a Response body can only be read once, so a
112
+ // single reused object would fail the second command's `.json()`.
113
+ fetchSpy.mockImplementation(async () => jsonResponse(200, { outposts: [] }));
114
+ const deps = { getToken: async () => `token-${++calls}` };
115
+ await run(["outposts", "list"], deps);
116
+ await run(["outposts", "list"], deps);
117
+ const sent = fetchSpy.mock.calls.map(([, init]) => (init?.headers).Authorization);
118
+ expect(sent).toEqual(["Bearer token-1", "Bearer token-2"]);
119
+ });
120
+ it("emits raw JSON with --json", async () => {
121
+ const stdoutSpy = vi
122
+ .spyOn(process.stdout, "write")
123
+ .mockImplementation(() => true);
124
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { outposts: [] }));
125
+ await run(["outposts", "list", "--json"]);
126
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("\n");
127
+ expect(printed).toContain("[]");
128
+ });
129
+ });
130
+ describe("outposts status", () => {
131
+ it("GETs /outpost/status with the --id query param", async () => {
132
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { state: "running" }));
133
+ await run(["outposts", "status", "--id", "2"]);
134
+ const url = String(fetchSpy.mock.calls[0][0]);
135
+ expect(url).toContain("/outpost/status");
136
+ expect(url).toContain("outpostId=2");
137
+ });
138
+ it("omits outpostId when --id is not given", async () => {
139
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { state: "running" }));
140
+ await run(["outposts", "status"]);
141
+ expect(String(fetchSpy.mock.calls[0][0])).not.toContain("outpostId=");
142
+ });
143
+ });
144
+ describe("outposts codex-enable / login", () => {
145
+ it("POSTs /outpost/codex/enable", async () => {
146
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true }));
147
+ await run(["outposts", "codex-enable"]);
148
+ const [url, init] = fetchSpy.mock.calls[0];
149
+ expect(String(url)).toContain("/outpost/codex/enable");
150
+ expect(init?.method).toBe("POST");
151
+ });
152
+ it("POSTs /outpost/regenerate-login-url", async () => {
153
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true }));
154
+ await run(["outposts", "login"]);
155
+ const [url, init] = fetchSpy.mock.calls[0];
156
+ expect(String(url)).toContain("/outpost/regenerate-login-url");
157
+ expect(init?.method).toBe("POST");
158
+ });
159
+ it("login-code POSTs /outpost/login-code with the code in the body", async () => {
160
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true, userId: "u1" }));
161
+ await run(["outposts", "login-code", "ABC-123"]);
162
+ const [url, init] = fetchSpy.mock.calls[0];
163
+ expect(String(url)).toContain("/outpost/login-code");
164
+ expect(init?.method).toBe("POST");
165
+ expect(JSON.parse(String(init?.body))).toEqual({ code: "ABC-123" });
166
+ });
167
+ it("login-code targets a specific box via --id (outpostId query)", async () => {
168
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true, userId: "u1" }));
169
+ await run(["outposts", "login-code", "CODE", "--id", "3"]);
170
+ const [url] = fetchSpy.mock.calls[0];
171
+ expect(String(url)).toContain("outpostId=3");
172
+ });
173
+ it("login-code trims whitespace and refuses an empty code without calling the API", async () => {
174
+ await expect(run(["outposts", "login-code", " "])).rejects.toThrow("process.exit(1)");
175
+ expect(fetchSpy).not.toHaveBeenCalled();
176
+ });
177
+ it("login-code surfaces an awaiting-login not-found error", async () => {
178
+ fetchSpy.mockResolvedValueOnce(jsonResponse(404, {
179
+ error: true,
180
+ step: "not-found",
181
+ message: "no outpost",
182
+ }));
183
+ await expect(run(["outposts", "login-code", "CODE"])).rejects.toThrow("process.exit(1)");
184
+ });
185
+ });
186
+ describe("outposts destroy", () => {
187
+ it("refuses without --yes and does not call the API", async () => {
188
+ await expect(run(["outposts", "destroy"])).rejects.toThrow("process.exit(1)");
189
+ expect(fetchSpy).not.toHaveBeenCalled();
190
+ });
191
+ it("POSTs /outpost/destroy with --yes", async () => {
192
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true, userId: "u1" }));
193
+ await run(["outposts", "destroy", "--yes"]);
194
+ const [url, init] = fetchSpy.mock.calls[0];
195
+ expect(String(url)).toContain("/outpost/destroy");
196
+ expect(init?.method).toBe("POST");
197
+ });
198
+ it("treats a 409 teardown-incomplete as retryable (no exit)", async () => {
199
+ fetchSpy.mockResolvedValueOnce(jsonResponse(409, { error: true, step: "teardown-incomplete" }));
200
+ await run(["outposts", "destroy", "--id", "2", "--yes"]);
201
+ const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
202
+ expect(printed).toMatch(/still in progress/i);
203
+ expect(exitSpy).not.toHaveBeenCalled();
204
+ });
205
+ it("exits 1 on a genuine failure", async () => {
206
+ fetchSpy.mockResolvedValueOnce(jsonResponse(500, { error: "boom", step: "teardown" }));
207
+ await expect(run(["outposts", "destroy", "--yes"])).rejects.toThrow("process.exit(1)");
208
+ });
209
+ });
210
+ describe("outposts provision (billing gate)", () => {
211
+ it("refuses without --yes, prints the cost, and makes NO API call", async () => {
212
+ const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
213
+ await expect(run(["outposts", "provision"])).rejects.toThrow("process.exit(1)");
214
+ expect(fetchSpy).not.toHaveBeenCalled();
215
+ const printed = errSpy.mock.calls
216
+ .map((c) => c.map(String).join(" "))
217
+ .join("\n");
218
+ expect(printed).toMatch(/\$80\.00\/month/);
219
+ });
220
+ it("POSTs /outpost/provision with the refresh token when --yes", async () => {
221
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true }));
222
+ await run(["outposts", "provision", "--runtime", "codex", "--yes"]);
223
+ const [url, init] = fetchSpy.mock.calls[0];
224
+ expect(String(url)).toContain("/outpost/provision");
225
+ expect(init?.method).toBe("POST");
226
+ const sent = JSON.parse(init?.body);
227
+ expect(sent.refreshToken).toBe("rt_test");
228
+ expect(sent.agentRuntime).toBe("codex");
229
+ });
230
+ it("exits without provisioning when there is no cached session", async () => {
231
+ await expect(run(["outposts", "provision", "--yes"], {
232
+ loadCachedTokens: () => undefined,
233
+ })).rejects.toThrow("process.exit(1)");
234
+ expect(fetchSpy).not.toHaveBeenCalled();
235
+ });
236
+ it("rejects an unknown --runtime before the charge gate and makes NO API call", async () => {
237
+ const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
238
+ await expect(run(["outposts", "provision", "--runtime", "codx", "--yes"])).rejects.toThrow("process.exit(1)");
239
+ expect(fetchSpy).not.toHaveBeenCalled();
240
+ const printed = errSpy.mock.calls
241
+ .map((c) => c.map(String).join(" "))
242
+ .join("\n");
243
+ // A typo'd runtime must not silently resolve to claude — codex is the whole
244
+ // point of the flag, so a near-miss has to name itself.
245
+ expect(printed).toContain("codx");
246
+ expect(printed).toMatch(/claude/);
247
+ expect(printed).toMatch(/codex/);
248
+ });
249
+ it("accepts an explicit --runtime claude", async () => {
250
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { ok: true }));
251
+ await run(["outposts", "provision", "--runtime", "claude", "--yes"]);
252
+ const sent = JSON.parse(fetchSpy.mock.calls[0][1]?.body);
253
+ expect(sent.agentRuntime).toBe("claude");
254
+ });
255
+ it("explains the per-person cap on a 409 rather than printing a bare 'Conflict'", async () => {
256
+ const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
257
+ // hq-pro's cap body carries `capped`/`limit`/`outposts` and NO
258
+ // `message`/`error` field, so the generic decoder falls through to
259
+ // res.statusText — the operator sees only "Conflict".
260
+ fetchSpy.mockResolvedValueOnce(jsonResponse(409, {
261
+ capped: true,
262
+ userId: "user_test_123",
263
+ limit: 1,
264
+ outposts: [
265
+ {
266
+ outpostId: "primary",
267
+ state: "ready",
268
+ instanceName: "outpost-user_test_123",
269
+ region: "us-east-1",
270
+ agentRuntime: "claude",
271
+ platform: "ec2",
272
+ createdAt: "2026-07-01T00:00:00.000Z",
273
+ },
274
+ ],
275
+ }));
276
+ await expect(run(["outposts", "provision", "--yes"])).rejects.toThrow("process.exit(1)");
277
+ const printed = errSpy.mock.calls
278
+ .map((c) => c.map(String).join(" "))
279
+ .join("\n");
280
+ expect(printed).not.toMatch(/^Conflict$/m);
281
+ expect(printed).toMatch(/limit/i);
282
+ // Name the box they already own, and reassure on the charge they were just
283
+ // warned about — the cap is checked BEFORE activation billing.
284
+ expect(printed).toContain("primary");
285
+ expect(printed).toMatch(/not been charged/i);
286
+ });
287
+ it("mints a card-capture link on 402 billing_required and exits 1", async () => {
288
+ fetchSpy
289
+ .mockResolvedValueOnce(jsonResponse(402, {
290
+ error: "payment required",
291
+ billing: {
292
+ status: "billing_required",
293
+ setup: {
294
+ payerType: "person",
295
+ path: "/v1/billing/checkout/person",
296
+ method: "POST",
297
+ },
298
+ },
299
+ }))
300
+ .mockResolvedValueOnce(jsonResponse(200, { url: "https://checkout.stripe.com/outpost" }));
301
+ await expect(run(["outposts", "provision", "--yes"])).rejects.toThrow("process.exit(1)");
302
+ expect(String(fetchSpy.mock.calls[1][0])).toContain("/v1/billing/checkout/person");
303
+ const printed = logSpy.mock.calls.map((c) => String(c[0])).join("\n");
304
+ expect(printed).toContain("https://checkout.stripe.com/outpost");
305
+ });
306
+ it("surfaces the DECLINE reason on 402 payment_failed — never the 'No card on file' copy", async () => {
307
+ const errSpy = vi.spyOn(console, "error").mockImplementation(() => { });
308
+ // hq-pro's payment_failed envelope: a card EXISTS and was declined. The
309
+ // server's `message` carries the friendly decline copy; telling this user
310
+ // "No card on file" sends them down the wrong remediation path entirely.
311
+ fetchSpy
312
+ .mockResolvedValueOnce(jsonResponse(402, {
313
+ error: "payment required",
314
+ message: "Your card was declined. Try a different card or contact your bank.",
315
+ billing: {
316
+ status: "payment_failed",
317
+ setup: {
318
+ payerType: "person",
319
+ path: "/v1/billing/checkout/person",
320
+ method: "POST",
321
+ },
322
+ },
323
+ }))
324
+ .mockResolvedValueOnce(jsonResponse(200, { url: "https://checkout.stripe.com/update-card" }));
325
+ await expect(run(["outposts", "provision", "--yes"])).rejects.toThrow("process.exit(1)");
326
+ const printed = [...errSpy.mock.calls, ...logSpy.mock.calls]
327
+ .map((c) => c.map(String).join(" "))
328
+ .join("\n");
329
+ expect(printed).toContain("declined");
330
+ expect(printed).not.toContain("No card on file");
331
+ // The card-capture link still surfaces — as the way to UPDATE the card.
332
+ expect(printed).toContain("https://checkout.stripe.com/update-card");
333
+ });
334
+ });
335
+ describe("outposts exec", () => {
336
+ afterEach(() => {
337
+ process.exitCode = undefined;
338
+ });
339
+ it("wraps the command to run from the box's HQ folder, then runs it", () => {
340
+ const wrapped = withRemoteHqDir("pwd");
341
+ // SSM may invoke the command as root with HOME unset. Seed a real home so
342
+ // tools such as gh do not write machine state into the HQ checkout.
343
+ expect(wrapped).toContain('export HOME="${HOME:-/root}"');
344
+ // cd into $HOME/hq (SSH/login user) …
345
+ expect(wrapped).toContain('cd "$HOME/hq"');
346
+ // … falling back to ec2-user's home for the SSM/root path (no $HOME) …
347
+ expect(wrapped).toContain("cd ~ec2-user/hq");
348
+ // … never failing merely because the box has no HQ folder …
349
+ expect(wrapped).toContain("|| true");
350
+ // … and the caller's command still runs after the cd.
351
+ expect(wrapped.endsWith("; pwd")).toBe(true);
352
+ });
353
+ it("POSTs /outpost/exec with the joined command and streams stdout", async () => {
354
+ const stdoutSpy = vi
355
+ .spyOn(process.stdout, "write")
356
+ .mockImplementation(() => true);
357
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
358
+ ok: true,
359
+ outpostId: "primary",
360
+ instanceId: "i-abc",
361
+ commandId: "cmd-1",
362
+ status: "Success",
363
+ exitCode: 0,
364
+ stdout: "hello world\n",
365
+ stderr: "",
366
+ truncated: false,
367
+ }));
368
+ await run(["outposts", "exec", "echo", "hello", "world"]);
369
+ const [url, init] = fetchSpy.mock.calls[0];
370
+ expect(String(url)).toContain("/outpost/exec");
371
+ expect(init?.method).toBe("POST");
372
+ // The command is wrapped so it runs from the box's HQ folder.
373
+ expect(JSON.parse(init?.body)).toEqual({
374
+ command: withRemoteHqDir("'echo' 'hello' 'world'"),
375
+ });
376
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("");
377
+ expect(printed).toContain("hello world\n");
378
+ expect(process.exitCode).toBe(0);
379
+ });
380
+ it("propagates a non-zero remote exit code", async () => {
381
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
382
+ vi.spyOn(process.stderr, "write").mockImplementation(() => true);
383
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
384
+ ok: true,
385
+ outpostId: "primary",
386
+ instanceId: "i-abc",
387
+ commandId: "cmd-2",
388
+ status: "Failed",
389
+ exitCode: 2,
390
+ stdout: "",
391
+ stderr: "nope\n",
392
+ truncated: false,
393
+ }));
394
+ await run(["outposts", "exec", "exit", "2"]);
395
+ expect(process.exitCode).toBe(2);
396
+ });
397
+ it("exits nonzero when SSM reports a Failed status with no numeric exit code", async () => {
398
+ // A remote failure that SSM can't attach a code to (Failed/Cancelled with
399
+ // exitCode null) must NOT read as success, or `hq outposts exec` in a script
400
+ // silently swallows the failure.
401
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
402
+ vi.spyOn(process.stderr, "write").mockImplementation(() => true);
403
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
404
+ ok: true,
405
+ outpostId: "primary",
406
+ instanceId: "i-abc",
407
+ commandId: "cmd-x",
408
+ status: "Failed",
409
+ exitCode: null,
410
+ stdout: "",
411
+ stderr: "",
412
+ truncated: false,
413
+ }));
414
+ await run(["outposts", "exec", "boom"]);
415
+ expect(process.exitCode).toBe(1);
416
+ });
417
+ it("still exits 0 on a Success status that carries no numeric code", async () => {
418
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
419
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
420
+ ok: true,
421
+ outpostId: "primary",
422
+ instanceId: "i-abc",
423
+ commandId: "cmd-y",
424
+ status: "Success",
425
+ exitCode: null,
426
+ stdout: "",
427
+ stderr: "",
428
+ truncated: false,
429
+ }));
430
+ await run(["outposts", "exec", "true"]);
431
+ expect(process.exitCode).toBe(0);
432
+ });
433
+ it("passes --id through as the outpostId query param", async () => {
434
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
435
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
436
+ ok: true,
437
+ outpostId: "2",
438
+ instanceId: "i-2",
439
+ commandId: "c",
440
+ status: "Success",
441
+ exitCode: 0,
442
+ stdout: "",
443
+ stderr: "",
444
+ truncated: false,
445
+ }));
446
+ await run(["outposts", "exec", "--id", "2", "uptime"]);
447
+ expect(String(fetchSpy.mock.calls[0][0])).toContain("outpostId=2");
448
+ });
449
+ it("exits 1 and surfaces the server message on a non-2xx (e.g. not-ready)", async () => {
450
+ fetchSpy.mockResolvedValueOnce(jsonResponse(409, {
451
+ error: true,
452
+ step: "not-ready",
453
+ message: 'outpost is "provisioning", not ready — it must be running to exec',
454
+ }));
455
+ await expect(run(["outposts", "exec", "echo", "hi"])).rejects.toThrow("process.exit(1)");
456
+ });
457
+ it("emits raw JSON with --json", async () => {
458
+ const stdoutSpy = vi
459
+ .spyOn(process.stdout, "write")
460
+ .mockImplementation(() => true);
461
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
462
+ ok: true,
463
+ outpostId: "primary",
464
+ instanceId: "i-abc",
465
+ commandId: "cmd-3",
466
+ status: "Success",
467
+ exitCode: 0,
468
+ stdout: "x\n",
469
+ stderr: "",
470
+ truncated: false,
471
+ }));
472
+ await run(["outposts", "exec", "--json", "echo", "x"]);
473
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("");
474
+ expect(printed).toContain('"commandId": "cmd-3"');
475
+ });
476
+ });
477
+ describe("outposts exec — Lightsail SSH fallback", () => {
478
+ afterEach(() => {
479
+ process.exitCode = undefined;
480
+ });
481
+ function platformUnsupported() {
482
+ return jsonResponse(409, {
483
+ error: true,
484
+ step: "platform-unsupported",
485
+ message: "remote exec requires the EC2 platform",
486
+ });
487
+ }
488
+ function sshAccess() {
489
+ return jsonResponse(200, {
490
+ ok: true,
491
+ outpostId: "primary",
492
+ platform: "lightsail",
493
+ host: "52.2.2.2",
494
+ port: 22,
495
+ username: "ec2-user",
496
+ privateKey: "-----BEGIN KEY-----\nx\n-----END KEY-----\n",
497
+ });
498
+ }
499
+ it("falls back to SSH when the box is Lightsail, streams stdout, propagates exit", async () => {
500
+ const stdoutSpy = vi
501
+ .spyOn(process.stdout, "write")
502
+ .mockImplementation(() => true);
503
+ fetchSpy
504
+ .mockResolvedValueOnce(platformUnsupported()) // /outpost/exec (SSM) → 409
505
+ .mockResolvedValueOnce(sshAccess()); // /outpost/ssh-access → 200
506
+ mockSpawnSync.mockReturnValue({
507
+ status: 0,
508
+ stdout: "lightsail-out\n",
509
+ stderr: "",
510
+ signal: null,
511
+ output: [],
512
+ pid: 1,
513
+ });
514
+ // Flags meant for the remote command go after `--` (same as the SSM path).
515
+ await run(["outposts", "exec", "--", "uname", "-a"]);
516
+ // Second HTTP call is the ssh-access mint.
517
+ expect(String(fetchSpy.mock.calls[1][0])).toContain("/outpost/ssh-access");
518
+ // ssh was invoked with the box coordinates and the command as the last arg.
519
+ const args = mockSpawnSync.mock.calls[0][1];
520
+ expect(mockSpawnSync.mock.calls[0][0]).toBe("ssh");
521
+ expect(args).toContain("ec2-user@52.2.2.2");
522
+ expect(args[args.length - 1]).toBe(withRemoteHqDir("'uname' '-a'"));
523
+ expect(args).toContain("BatchMode=yes");
524
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("");
525
+ expect(printed).toContain("lightsail-out\n");
526
+ expect(process.exitCode).toBe(0);
527
+ });
528
+ it("propagates a non-zero SSH exit code", async () => {
529
+ vi.spyOn(process.stdout, "write").mockImplementation(() => true);
530
+ vi.spyOn(process.stderr, "write").mockImplementation(() => true);
531
+ fetchSpy
532
+ .mockResolvedValueOnce(platformUnsupported())
533
+ .mockResolvedValueOnce(sshAccess());
534
+ mockSpawnSync.mockReturnValue({
535
+ status: 7,
536
+ stdout: "",
537
+ stderr: "boom\n",
538
+ signal: null,
539
+ output: [],
540
+ pid: 1,
541
+ });
542
+ await run(["outposts", "exec", "false"]);
543
+ expect(process.exitCode).toBe(7);
544
+ });
545
+ it("exits 1 with a clear message when the ssh client is missing", async () => {
546
+ fetchSpy
547
+ .mockResolvedValueOnce(platformUnsupported())
548
+ .mockResolvedValueOnce(sshAccess());
549
+ const enoent = Object.assign(new Error("spawnSync ssh ENOENT"), {
550
+ code: "ENOENT",
551
+ });
552
+ mockSpawnSync.mockReturnValue({
553
+ error: enoent,
554
+ status: null,
555
+ stdout: "",
556
+ stderr: "",
557
+ signal: null,
558
+ output: [],
559
+ pid: 0,
560
+ });
561
+ await expect(run(["outposts", "exec", "echo", "hi"])).rejects.toThrow("process.exit(1)");
562
+ });
563
+ it("does NOT fall back for a non-platform error (e.g. not-ready)", async () => {
564
+ fetchSpy.mockResolvedValueOnce(jsonResponse(409, {
565
+ error: true,
566
+ step: "not-ready",
567
+ message: "not ready",
568
+ }));
569
+ await expect(run(["outposts", "exec", "echo", "hi"])).rejects.toThrow("process.exit(1)");
570
+ // Only the SSM call happened; no ssh-access mint, no ssh.
571
+ expect(fetchSpy).toHaveBeenCalledTimes(1);
572
+ expect(mockSpawnSync).not.toHaveBeenCalled();
573
+ });
574
+ it("refuses --async on Lightsail instead of silently holding an SSH session", async () => {
575
+ // --async exists to escape the ~20s sync cap. Falling back to a live SSH hold
576
+ // would reintroduce exactly the timeout it was meant to avoid.
577
+ fetchSpy.mockResolvedValueOnce(platformUnsupported());
578
+ await expect(run(["outposts", "exec", "--async", "sleep", "60"])).rejects.toThrow("process.exit(1)");
579
+ expect(mockSpawnSync).not.toHaveBeenCalled();
580
+ });
581
+ });
582
+ describe("outposts exec --async / --detach", () => {
583
+ afterEach(() => {
584
+ process.exitCode = undefined;
585
+ });
586
+ it("--detach submits with HQ-dir wrapper and prints commandId without waiting", async () => {
587
+ const stdoutSpy = vi
588
+ .spyOn(process.stdout, "write")
589
+ .mockImplementation(() => true);
590
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
591
+ ok: true,
592
+ userId: "u",
593
+ outpostId: "3",
594
+ instanceId: "i-3",
595
+ commandId: "cmd-detach",
596
+ outputPrefix: "outpost-exec/u/3/n/out",
597
+ executionTimeoutSeconds: 172800,
598
+ }));
599
+ await run([
600
+ "outposts",
601
+ "exec",
602
+ "--detach",
603
+ "--id",
604
+ "3",
605
+ "--json",
606
+ "sleep",
607
+ "999",
608
+ ]);
609
+ expect(fetchSpy).toHaveBeenCalledTimes(1);
610
+ const [url, init] = fetchSpy.mock.calls[0];
611
+ expect(String(url)).toContain("/outpost/exec");
612
+ expect(String(url)).toContain("outpostId=3");
613
+ expect(JSON.parse(init?.body)).toEqual({
614
+ mode: "submit",
615
+ command: withRemoteHqDir("'sleep' '999'"),
616
+ });
617
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("");
618
+ expect(printed).toContain('"commandId":"cmd-detach"');
619
+ // No second poll.
620
+ expect(fetchSpy).toHaveBeenCalledTimes(1);
621
+ });
622
+ it("--async submits then polls until done and streams stdout", async () => {
623
+ const stdoutSpy = vi
624
+ .spyOn(process.stdout, "write")
625
+ .mockImplementation(() => true);
626
+ fetchSpy
627
+ .mockResolvedValueOnce(jsonResponse(200, {
628
+ ok: true,
629
+ userId: "u",
630
+ outpostId: "primary",
631
+ instanceId: "i",
632
+ commandId: "cmd-async",
633
+ outputPrefix: "p",
634
+ executionTimeoutSeconds: 7200,
635
+ }))
636
+ .mockResolvedValueOnce(jsonResponse(200, {
637
+ ok: true,
638
+ userId: "u",
639
+ outpostId: "primary",
640
+ status: "Success",
641
+ done: true,
642
+ exitCode: 0,
643
+ stdout: "finished\n",
644
+ stderr: "",
645
+ }));
646
+ await run([
647
+ "outposts",
648
+ "exec",
649
+ "--async",
650
+ "--timeout-seconds",
651
+ "7200",
652
+ "echo",
653
+ "finished",
654
+ ]);
655
+ // submit + one result poll (terminal on first poll)
656
+ expect(fetchSpy).toHaveBeenCalledTimes(2);
657
+ expect(JSON.parse(fetchSpy.mock.calls[0][1]?.body)).toEqual({
658
+ mode: "submit",
659
+ command: withRemoteHqDir("'echo' 'finished'"),
660
+ timeoutSeconds: 7200,
661
+ });
662
+ expect(JSON.parse(fetchSpy.mock.calls[1][1]?.body)).toEqual({
663
+ mode: "result",
664
+ commandId: "cmd-async",
665
+ });
666
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("");
667
+ expect(printed).toContain("finished\n");
668
+ expect(process.exitCode).toBe(0);
669
+ });
670
+ it("refuses --async and --detach together", async () => {
671
+ await expect(run(["outposts", "exec", "--async", "--detach", "true"])).rejects.toThrow("process.exit(1)");
672
+ expect(fetchSpy).not.toHaveBeenCalled();
673
+ });
674
+ it("rejects a --timeout-seconds beyond the AWS-RunShellScript 48h ceiling", async () => {
675
+ await expect(run(["outposts", "exec", "--timeout-seconds", "172801", "true"])).rejects.toThrow("process.exit(1)");
676
+ expect(fetchSpy).not.toHaveBeenCalled();
677
+ });
678
+ it("exec-submit forwards --timeout-seconds", async () => {
679
+ const stdoutSpy = vi
680
+ .spyOn(process.stdout, "write")
681
+ .mockImplementation(() => true);
682
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
683
+ ok: true,
684
+ commandId: "cmd-sub",
685
+ executionTimeoutSeconds: 3600,
686
+ userId: "u",
687
+ outpostId: "primary",
688
+ instanceId: "i",
689
+ outputPrefix: "p",
690
+ }));
691
+ await run([
692
+ "outposts",
693
+ "exec-submit",
694
+ "--timeout-seconds",
695
+ "3600",
696
+ "--json",
697
+ "sleep",
698
+ "10",
699
+ ]);
700
+ expect(JSON.parse(fetchSpy.mock.calls[0][1]?.body)).toEqual({
701
+ mode: "submit",
702
+ command: "'sleep' '10'",
703
+ timeoutSeconds: 3600,
704
+ });
705
+ const printed = stdoutSpy.mock.calls.map((c) => String(c[0])).join("");
706
+ expect(printed).toContain("cmd-sub");
707
+ });
708
+ });
709
+ describe("outposts asynchronous exec", () => {
710
+ it("sends the stage, submit, and result mode request bodies", async () => {
711
+ fetchSpy
712
+ .mockResolvedValueOnce(jsonResponse(200, {
713
+ ok: true,
714
+ userId: "u1",
715
+ outpostId: "2",
716
+ key: "input-key",
717
+ putUrl: "https://upload.invalid/put",
718
+ getUrl: "https://download.invalid/get",
719
+ expiresInSeconds: 300,
720
+ }))
721
+ .mockResolvedValueOnce(jsonResponse(200, {
722
+ ok: true,
723
+ userId: "u1",
724
+ outpostId: "2",
725
+ instanceId: "i-2",
726
+ commandId: "cmd-1",
727
+ outputPrefix: "output-prefix",
728
+ }))
729
+ .mockResolvedValueOnce(jsonResponse(200, {
730
+ ok: true,
731
+ userId: "u1",
732
+ outpostId: "2",
733
+ status: "InProgress",
734
+ done: false,
735
+ }));
736
+ const client = new OutpostsClient({
737
+ transport: testTransport(),
738
+ token: "test-token",
739
+ });
740
+ await client.stageExecInput("2");
741
+ await client.submitExec("cd /tmp && run-worker", "2");
742
+ await client.fetchExecResult("cmd-1", "2");
743
+ expect(fetchSpy.mock.calls.map(([url]) => String(url))).toEqual([
744
+ expect.stringContaining("/outpost/exec?outpostId=2"),
745
+ expect.stringContaining("/outpost/exec?outpostId=2"),
746
+ expect.stringContaining("/outpost/exec?outpostId=2"),
747
+ ]);
748
+ expect(fetchSpy.mock.calls.map(([, init]) => JSON.parse(init?.body))).toEqual([
749
+ { mode: "stage" },
750
+ { mode: "submit", command: "cd /tmp && run-worker" },
751
+ { mode: "result", commandId: "cmd-1" },
752
+ ]);
753
+ });
754
+ it("exec-stage PUTs the exact file bytes and prints only key + getUrl JSON", async () => {
755
+ const stdoutSpy = vi
756
+ .spyOn(process.stdout, "write")
757
+ .mockImplementation(() => true);
758
+ const file = path.join(process.cwd(), "package.json");
759
+ const expectedBytes = fs.readFileSync(file);
760
+ fetchSpy
761
+ .mockResolvedValueOnce(jsonResponse(200, {
762
+ ok: true,
763
+ userId: "u1",
764
+ outpostId: "2",
765
+ key: "input-key",
766
+ putUrl: "https://upload.invalid/put",
767
+ getUrl: "https://download.invalid/get",
768
+ expiresInSeconds: 300,
769
+ }))
770
+ .mockResolvedValueOnce(new Response(null, { status: 200 }));
771
+ await run([
772
+ "outposts",
773
+ "exec-stage",
774
+ "--id",
775
+ "2",
776
+ "--file",
777
+ file,
778
+ "--json",
779
+ ]);
780
+ expect(fetchSpy).toHaveBeenCalledTimes(2);
781
+ const [uploadUrl, uploadInit] = fetchSpy.mock.calls[1];
782
+ expect(String(uploadUrl)).toBe("https://upload.invalid/put");
783
+ expect(uploadInit?.method).toBe("PUT");
784
+ expect(uploadInit?.headers).toEqual({
785
+ "Content-Length": String(expectedBytes.byteLength),
786
+ });
787
+ expect(Buffer.from(uploadInit?.body)).toEqual(expectedBytes);
788
+ const printed = stdoutSpy.mock.calls
789
+ .map((call) => String(call[0]))
790
+ .join("");
791
+ expect(JSON.parse(printed)).toEqual({
792
+ key: "input-key",
793
+ getUrl: "https://download.invalid/get",
794
+ });
795
+ });
796
+ it("exec-stage exits non-zero when the presigned upload fails", async () => {
797
+ fetchSpy
798
+ .mockResolvedValueOnce(jsonResponse(200, {
799
+ ok: true,
800
+ userId: "u1",
801
+ outpostId: "primary",
802
+ key: "input-key",
803
+ putUrl: "https://upload.invalid/put",
804
+ getUrl: "https://download.invalid/get",
805
+ expiresInSeconds: 300,
806
+ }))
807
+ .mockResolvedValueOnce(new Response(null, { status: 503 }));
808
+ await expect(run([
809
+ "outposts",
810
+ "exec-stage",
811
+ "--file",
812
+ path.join(process.cwd(), "package.json"),
813
+ "--json",
814
+ ])).rejects.toThrow("process.exit(1)");
815
+ });
816
+ it("exec-submit shell-quotes multiple argv parts without adding the HQ-directory wrapper", async () => {
817
+ const stdoutSpy = vi
818
+ .spyOn(process.stdout, "write")
819
+ .mockImplementation(() => true);
820
+ const script = 'printf "%s\\n" "$0" "$1" "$2"';
821
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, {
822
+ ok: true,
823
+ userId: "u1",
824
+ outpostId: "primary",
825
+ instanceId: "i-1",
826
+ commandId: "cmd-submit",
827
+ outputPrefix: "output-prefix",
828
+ }));
829
+ await run([
830
+ "outposts",
831
+ "exec-submit",
832
+ "--json",
833
+ "--",
834
+ "bash",
835
+ "-c",
836
+ script,
837
+ "marker",
838
+ "a b",
839
+ "quote's",
840
+ ]);
841
+ const body = JSON.parse(fetchSpy.mock.calls[0][1]?.body);
842
+ expect(body).toEqual({
843
+ mode: "submit",
844
+ command: joinCommandParts([
845
+ "bash",
846
+ "-c",
847
+ script,
848
+ "marker",
849
+ "a b",
850
+ "quote's",
851
+ ]),
852
+ });
853
+ expect(body.command).not.toContain("cd ~ec2-user/hq");
854
+ expect(JSON.parse(String(stdoutSpy.mock.calls[0][0]))).toEqual({
855
+ commandId: "cmd-submit",
856
+ });
857
+ });
858
+ // Spawns a real `bash` (execFileSync) to prove the round-trip end-to-end. Under
859
+ // the saturated full-suite parallel pool that spawn can exceed vitest's default
860
+ // per-test budget purely on scheduling contention; the extra budget covers that,
861
+ // not slow logic (isolated, this runs in milliseconds).
862
+ it("preserves one command part verbatim and round-trips quoted bash argv", () => {
863
+ const single = " printf 'already formed' ";
864
+ expect(joinCommandParts([single])).toBe(single);
865
+ const script = 'printf "%s\\n" "$0" "$1" "$2"';
866
+ const command = joinCommandParts([
867
+ "bash",
868
+ "-c",
869
+ script,
870
+ "marker",
871
+ "a b",
872
+ "quote's",
873
+ ]);
874
+ expect(execFileSync("bash", ["-c", command], { encoding: "utf8" })).toBe("marker\na b\nquote's\n");
875
+ }, 30_000);
876
+ it("exec-result --wait retries a 429, polls until done, and prints the result contract", async () => {
877
+ vi.useFakeTimers();
878
+ try {
879
+ const stdoutSpy = vi
880
+ .spyOn(process.stdout, "write")
881
+ .mockImplementation(() => true);
882
+ fetchSpy
883
+ .mockResolvedValueOnce(jsonResponse(429, {
884
+ error: true,
885
+ step: "rate",
886
+ message: "slow down",
887
+ }))
888
+ .mockResolvedValueOnce(jsonResponse(200, {
889
+ ok: true,
890
+ userId: "u1",
891
+ outpostId: "2",
892
+ status: "InProgress",
893
+ done: false,
894
+ }))
895
+ .mockResolvedValueOnce(jsonResponse(200, {
896
+ ok: true,
897
+ userId: "u1",
898
+ outpostId: "2",
899
+ status: "Success",
900
+ done: true,
901
+ exitCode: 0,
902
+ stdout: "finished\n",
903
+ stderr: "",
904
+ truncated: false,
905
+ }));
906
+ const pending = run([
907
+ "outposts",
908
+ "exec-result",
909
+ "--id",
910
+ "2",
911
+ "--command-id",
912
+ "cmd-1",
913
+ "--wait",
914
+ "--json",
915
+ ]);
916
+ await vi.advanceTimersByTimeAsync(500);
917
+ await vi.advanceTimersByTimeAsync(1_000);
918
+ await pending;
919
+ expect(fetchSpy).toHaveBeenCalledTimes(3);
920
+ expect(JSON.parse(String(stdoutSpy.mock.calls[0][0]))).toEqual({
921
+ done: true,
922
+ status: "Success",
923
+ exitCode: 0,
924
+ stdout: "finished\n",
925
+ stderr: "",
926
+ });
927
+ }
928
+ finally {
929
+ vi.useRealTimers();
930
+ }
931
+ });
932
+ });
933
+ //# sourceMappingURL=command.test.js.map