@cnc-tools/storm 0.14.0 → 0.14.2

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 (54) hide show
  1. package/dist/bin/storm.js +10 -2
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-27P2QSIM.js → chunk-3HBPNQ4Y.js} +1 -1
  4. package/dist/chunks/{chunk-HOKDKP5A.js → chunk-E3QU74NX.js} +1 -1
  5. package/dist/chunks/{chunk-RKONDLPS.js → chunk-GJOEPJJL.js} +2 -2
  6. package/dist/chunks/{chunk-XPCUINWS.js → chunk-HDL4WKIB.js} +1 -1
  7. package/dist/chunks/{chunk-IVRRGGCD.js → chunk-HP54VHGY.js} +4 -4
  8. package/dist/chunks/{chunk-5ED3IDUJ.js → chunk-I7AN3DIJ.js} +25 -4
  9. package/dist/chunks/{chunk-YBPTMJUM.js → chunk-LUOHJ3LB.js} +9 -9
  10. package/dist/chunks/{chunk-ZH5R7W4A.js → chunk-RUPD4TLT.js} +1 -1
  11. package/dist/chunks/{chunk-BFLYGMG3.js → chunk-TVMEKVOW.js} +4 -4
  12. package/dist/chunks/{chunk-Z5OXOZD3.js → chunk-UUBZTGLV.js} +1 -1
  13. package/dist/chunks/{chunk-5TMHYH7G.js → chunk-VH2POPW5.js} +4 -2
  14. package/dist/chunks/{chunk-QBR5VHJ7.js → chunk-XZCDA5PE.js} +1 -1
  15. package/dist/chunks/{live-app-FBVWUUMT.js → live-app-SZGEILCQ.js} +13 -7
  16. package/dist/commands/exec/command.js +10 -10
  17. package/dist/commands/exec/exec-words.js +1 -1
  18. package/dist/commands/exec/metadata.js +1 -1
  19. package/dist/commands/playwright/command.js +11 -11
  20. package/dist/commands/runs/list/command.js +5 -5
  21. package/dist/commands/runs/logs/command.js +5 -5
  22. package/dist/commands/runs/show/command.js +8 -8
  23. package/dist/commands/snapshots/build/command.js +9 -9
  24. package/dist/commands/snapshots/list/command.js +6 -6
  25. package/dist/commands/vitest/command.js +11 -11
  26. package/dist/context.d.ts +1 -0
  27. package/dist/context.js +4 -1
  28. package/dist/core/payload.d.ts +5 -3
  29. package/dist/core/payload.js +8 -3
  30. package/dist/extensions/testserver/commands/pool/create/command.js +1 -1
  31. package/dist/extensions/testserver/vercel-cli/arguments.d.ts +10 -4
  32. package/dist/extensions/testserver/vercel-cli/arguments.js +17 -6
  33. package/dist/extensions/testserver/vercel-cli/environment.d.ts +12 -1
  34. package/dist/extensions/testserver/vercel-cli/environment.js +35 -5
  35. package/dist/extensions/testserver/vercel-cli/invoker.d.ts +28 -13
  36. package/dist/extensions/testserver/vercel-cli/invoker.js +81 -67
  37. package/dist/extensions/testserver/vercel-cli/live/process-gateway.js +4 -10
  38. package/dist/extensions/testserver/vercel-cli/session-id.js +5 -4
  39. package/dist/extensions/testserver/vitest/diagnostics.d.ts +10 -9
  40. package/dist/extensions/testserver/vitest/diagnostics.js +17 -16
  41. package/dist/extensions/testserver/vitest/fixtures.d.ts +6 -2
  42. package/dist/extensions/testserver/vitest/fixtures.js +13 -10
  43. package/dist/extensions/testserver/vitest/types.d.ts +9 -2
  44. package/dist/live-app.d.ts +3 -1
  45. package/dist/live-app.js +5 -2
  46. package/dist/runner/gateways.d.ts +10 -2
  47. package/dist/runner/index.d.ts +1 -1
  48. package/dist/runner/live/sandbox-gateway.js +16 -2
  49. package/dist/runner/live/terminal.d.ts +15 -3
  50. package/dist/runner/live/terminal.js +25 -3
  51. package/dist/runner/recipe.d.ts +3 -2
  52. package/dist/runner/sandboxed-command.d.ts +5 -5
  53. package/dist/runner/sandboxed-command.js +7 -5
  54. package/package.json +1 -1
@@ -10,14 +10,15 @@ export type Redact = (text: string) => string;
10
10
  type RequestLine = ProxyRequestRecord | ApiRequestRecord | ExternalCallRecord;
11
11
  /**
12
12
  * One request record as a line: its method, URL as sent, result, whether it carried an `authorization` header,
13
- * duration and any `vercel` CLI session id (both read from its `requestHeaders`), such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts
14
- * with its external service, such as `external github POST /scenarios → 204, …`. A proxy record whose
15
- * exchange was still open reads `open`, its duration counted to the read. A proxy record of a request a fault rule
16
- * matched tags its result with the action and what Testserver answered, such as `500 (fault: replace, Testserver
17
- * 200)`. A status that fails the call (a record's `failure`) reads with why, such as `503 (the container stopped: …)`,
18
- * and an answer that broke off after its status with `then failed`, such as `200, then failed (aborted)`.
13
+ * duration, and any session id from `sessionHeader` (both read from its `requestHeaders`, ignoring `<redacted>`),
14
+ * such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts with its external
15
+ * service, such as `external github POST /scenarios → 204, …`. A proxy record whose exchange was still open reads
16
+ * `open`, its duration counted to the read. A proxy record of a request a fault rule matched tags its result with the
17
+ * action and what Testserver answered, such as `500 (fault: replace, Testserver 200)`. A status that fails the call
18
+ * (a record's `failure`) reads with why, such as `503 (the container stopped: …)`, and an answer that broke off after
19
+ * its status with `then failed`, such as `200, then failed (aborted)`.
19
20
  */
20
- export declare function describeRequest(request: RequestLine): string;
21
+ export declare function describeRequest(request: RequestLine, sessionHeader?: string): string;
21
22
  /**
22
23
  * A recorded body on one line, cut at `BODY_REPORT_CHARS`: JSON compact, a form as its encoded fields, text
23
24
  * quoted, and an omitted body as its note, such as `[binary, 5 bytes, image/png]`.
@@ -142,7 +143,7 @@ export declare function sharedContainerFailureReport(container: Omit<ContainerRe
142
143
  * What a verbose run prints as the proxy records a request: the request line with its bodies, as a failure report
143
144
  * would show it, naming the test id.
144
145
  */
145
- export declare function proxyRequestReport(testId: string, request: ProxyRequestRecord, redact: Redact): string;
146
+ export declare function proxyRequestReport(testId: string, request: ProxyRequestRecord, redact: Redact, sessionHeader?: string): string;
146
147
  /**
147
148
  * One warmup as a failure report's line: how many services, how long, and each that failed with why, such as
148
149
  * `warmup: 3 services in 2140ms, 1 failed (api-projects: HTTP 500: …)`.
@@ -173,7 +174,7 @@ export declare function containerStartReport(start: {
173
174
  * container's, so a secret the proxy's own redaction can't know of, such as another seeded token, reads `<token>`
174
175
  * too).
175
176
  */
176
- export declare function proxyFailureReport(testId: string, requests: readonly ProxyRequestRecord[], redact: Redact, faults?: readonly FaultHandle[]): string;
177
+ export declare function proxyFailureReport(testId: string, requests: readonly ProxyRequestRecord[], redact: Redact, faults?: readonly FaultHandle[], sessionHeader?: string): string;
177
178
  /**
178
179
  * Why a test fails when Testserver failed a request its proxy forwarded, naming each such request, through
179
180
  * `redact`; `undefined` when none did. Testserver failed a request a fault rule forwarded when it gave no answer, one
@@ -1,19 +1,19 @@
1
- import { describeFailure, FEATURE_FLAG_CLIENTS, REDACTED, redactTokenFields, TestserverCallError, } from "../../../vendor/testserver-sdk/index.js";
2
- import { vercelCliSessionId } from "../vercel-cli/session-id.js";
1
+ import { describeFailure, FEATURE_FLAG_CLIENTS, REDACTED, REDACTED_HEADER, redactTokenFields, TestserverCallError, } from "../../../vendor/testserver-sdk/index.js";
3
2
  /** The most characters of one body, input, response or container log line a failure report prints. */
4
3
  export const BODY_REPORT_CHARS = 1000;
5
4
  /** The most container log records a failure report prints, the last ones. */
6
5
  export const LOG_REPORT_RECORDS = 50;
7
6
  /**
8
7
  * One request record as a line: its method, URL as sent, result, whether it carried an `authorization` header,
9
- * duration and any `vercel` CLI session id (both read from its `requestHeaders`), such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts
10
- * with its external service, such as `external github POST /scenarios → 204, …`. A proxy record whose
11
- * exchange was still open reads `open`, its duration counted to the read. A proxy record of a request a fault rule
12
- * matched tags its result with the action and what Testserver answered, such as `500 (fault: replace, Testserver
13
- * 200)`. A status that fails the call (a record's `failure`) reads with why, such as `503 (the container stopped: …)`,
14
- * and an answer that broke off after its status with `then failed`, such as `200, then failed (aborted)`.
8
+ * duration, and any session id from `sessionHeader` (both read from its `requestHeaders`, ignoring `<redacted>`),
9
+ * such as `GET /v2/user → 200, authorization sent, 412ms, session 7f3a`; an external call's starts with its external
10
+ * service, such as `external github POST /scenarios → 204, …`. A proxy record whose exchange was still open reads
11
+ * `open`, its duration counted to the read. A proxy record of a request a fault rule matched tags its result with the
12
+ * action and what Testserver answered, such as `500 (fault: replace, Testserver 200)`. A status that fails the call
13
+ * (a record's `failure`) reads with why, such as `503 (the container stopped: …)`, and an answer that broke off after
14
+ * its status with `then failed`, such as `200, then failed (aborted)`.
15
15
  */
16
- export function describeRequest(request) {
16
+ export function describeRequest(request, sessionHeader) {
17
17
  const result = "open" in request
18
18
  ? "open"
19
19
  : !("status" in request)
@@ -24,7 +24,8 @@ export function describeRequest(request) {
24
24
  ? `${request.status}, then failed (${request.error})`
25
25
  : `${request.status} (${request.error})`;
26
26
  const authorization = "authorization" in request.requestHeaders ? "authorization sent" : "no authorization";
27
- const sessionId = vercelCliSessionId(request.requestHeaders);
27
+ const rawSessionId = sessionHeader === undefined ? undefined : request.requestHeaders[sessionHeader.toLowerCase()];
28
+ const sessionId = rawSessionId === REDACTED_HEADER ? undefined : rawSessionId;
28
29
  const session = sessionId === undefined ? "" : `, session ${sessionId}`;
29
30
  const fault = "fault" in request && request.fault !== undefined ? ` ${faultTag(request.fault)}` : "";
30
31
  const external = "externalId" in request ? `external ${request.externalId} ` : "";
@@ -80,10 +81,10 @@ function cut(text, max) {
80
81
  * One request record as its line, then a line for each body it has: what the client sent and got, and what
81
82
  * Testserver answered under a forwarding fault.
82
83
  */
83
- function describeExchange(request, redact) {
84
+ function describeExchange(request, redact, sessionHeader) {
84
85
  const upstreamBody = "fault" in request ? request.fault?.upstream?.responseBody : undefined;
85
86
  return [
86
- redact(describeRequest(request)),
87
+ redact(describeRequest(request, sessionHeader)),
87
88
  ...(request.requestBody === undefined ? [] : [` request body: ${describeBody(request.requestBody, redact)}`]),
88
89
  ...(request.responseBody === undefined ? [] : [` response body: ${describeBody(request.responseBody, redact)}`]),
89
90
  ...(upstreamBody === undefined ? [] : [` Testserver response body: ${describeBody(upstreamBody, redact)}`]),
@@ -305,8 +306,8 @@ function listed(items) {
305
306
  * What a verbose run prints as the proxy records a request: the request line with its bodies, as a failure report
306
307
  * would show it, naming the test id.
307
308
  */
308
- export function proxyRequestReport(testId, request, redact) {
309
- return [`storm: the proxy for test id ${testId} received:`, ...describeExchange(request, redact)].join("\n ");
309
+ export function proxyRequestReport(testId, request, redact, sessionHeader) {
310
+ return [`storm: the proxy for test id ${testId} received:`, ...describeExchange(request, redact, sessionHeader)].join("\n ");
310
311
  }
311
312
  /**
312
313
  * One warmup as a failure report's line: how many services, how long, and each that failed with why, such as
@@ -353,12 +354,12 @@ function services(count) {
353
354
  * container's, so a secret the proxy's own redaction can't know of, such as another seeded token, reads `<token>`
354
355
  * too).
355
356
  */
356
- export function proxyFailureReport(testId, requests, redact, faults = []) {
357
+ export function proxyFailureReport(testId, requests, redact, faults = [], sessionHeader) {
357
358
  const received = requests.length === 0
358
359
  ? [`storm: the proxy for test id ${testId} received no requests`]
359
360
  : [
360
361
  `storm: requests the proxy received for test id ${testId}:`,
361
- ...requests.flatMap((request) => describeExchange(request, redact)).map((line) => ` ${line}`),
362
+ ...requests.flatMap((request) => describeExchange(request, redact, sessionHeader)).map((line) => ` ${line}`),
362
363
  ];
363
364
  const unused = faults.filter((handle) => handle.remaining > 0);
364
365
  const rules = unused.length === 0
@@ -44,12 +44,16 @@ declare module "vitest" {
44
44
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
45
45
  * - `recordHeaders`: the headers whose values the container's and the proxy's records show as sent besides the
46
46
  * SDK's defaults (`DEFAULT_RECORD_HEADERS`, such as `content-type`), such as `["dpop"]`, by default none. Every other header's value reads `<redacted>`, but `authorization`,
47
- * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). The proxy's
48
- * records also show `x-vercel-cli-session-id`, the Vercel CLI invoker's session id. A suite sets it on its own
47
+ * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). A suite sets it on its own
49
48
  * `test` with `.override("recordHeaders", [...])`, a file or `describe` with `test.override({ recordHeaders })`.
50
49
  * In `'file'` scope, a test whose list shows other headers than that of the file's container ends it and starts a
51
50
  * new one, as for `featureFlags`; the proxy is the test's own. A bad list fails the test with a `TypeError` before
52
51
  * any container is acquired.
52
+ * - `proxySessionHeader`: an optional request header name that `proxy` records in addition to `recordHeaders` and
53
+ * prints as `, session <value>` on proxied request lines (such as `VERCEL_CLI_SESSION_ID_HEADER`), by default
54
+ * `undefined`. A suite sets it on its own `test` with `.override("proxySessionHeader", ...)`, a file or `describe`
55
+ * with `test.override({ proxySessionHeader })`. Unlike `recordHeaders`, it applies only to `proxy`, survives
56
+ * per-test `recordHeaders` overrides, and never replaces a file-scoped container.
53
57
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
54
58
  * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
55
59
  * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
@@ -6,7 +6,6 @@ import { containerStartReport, proxyFailureReport, proxyRequestReport, proxyTest
6
6
  import { workerTestserverUrl } from "./worker-sandbox.js";
7
7
  import { acquireOwned, Acquisitions, countTests, testEventReporter, testEventState } from "../../../vitest/index.js";
8
8
  import { reportedStart } from "./container-start.js";
9
- import { VERCEL_CLI_SESSION_ID_HEADER } from "../vercel-cli/session-id.js";
10
9
  /** The default `warmServices`: no service is warmed. */
11
10
  const NO_SERVICES = [];
12
11
  /** The default `featureFlags`: none. */
@@ -75,6 +74,7 @@ const fixtures = vitestTest
75
74
  .extend("warmServices", NO_SERVICES)
76
75
  .extend("featureFlags", NO_FEATURE_FLAGS)
77
76
  .extend("recordHeaders", NO_RECORD_HEADERS)
77
+ .extend("proxySessionHeader", undefined)
78
78
  // How the test's container is set up, for the fixture that hands it `onCleanup` (`stormContainer`, or `container`
79
79
  // in its place). Setting this up starts nothing and never throws.
80
80
  .extend("stormContainerSetup", ({ containerScope, warmServices, featureFlags, recordHeaders, stormFile, stormTestserverFailure, stormEvents, testserverUrl, verbose, task, signal, onTestFailed, }) => async (onCleanup) => {
@@ -134,11 +134,11 @@ const fixtures = vitestTest
134
134
  const provided = stormContainer;
135
135
  return provided ?? stormContainerSetup(onCleanup);
136
136
  })
137
- .extend("proxy", async ({ container, recordHeaders, stormFile, stormTestserverFailure, verbose, signal, onTestFailed, onTestFinished }, { onCleanup }) => {
137
+ .extend("proxy", async ({ container, recordHeaders, proxySessionHeader, stormFile, stormTestserverFailure, verbose, signal, onTestFailed, onTestFinished, }, { onCleanup }) => {
138
138
  startedContainer(container);
139
139
  // Under a verbose run, each request prints as the proxy records it, for passing tests too.
140
140
  const onRequest = verbose
141
- ? (record) => console.error(proxyRequestReport(container.testId, record, (text) => container.redact(text)))
141
+ ? (record) => console.error(proxyRequestReport(container.testId, record, (text) => container.redact(text), proxySessionHeader))
142
142
  : undefined;
143
143
  // Why Testserver failed the test through the proxy, once it has closed. The cleanup only notes it, and this
144
144
  // handler, which Vitest runs after every cleanup and before the failure handlers, fails the test with it: a
@@ -149,11 +149,10 @@ const fixtures = vitestTest
149
149
  if (failure.message !== undefined)
150
150
  throw new Error(failure.message);
151
151
  });
152
- const proxy = await stormFile.acquisitions.track(signal, acquireOwned(signal, onCleanup,
153
- // The proxy's records also show the Vercel CLI invoker's session id header, which its report counts by.
154
- () => startProxy({
152
+ const proxyRecordHeaders = proxySessionHeader === undefined ? recordHeaders : [proxySessionHeader, ...recordHeaders];
153
+ const proxy = await stormFile.acquisitions.track(signal, acquireOwned(signal, onCleanup, () => startProxy({
155
154
  container,
156
- recordHeaders: [VERCEL_CLI_SESSION_ID_HEADER, ...recordHeaders],
155
+ recordHeaders: proxyRecordHeaders,
157
156
  ...(onRequest === undefined ? {} : { onRequest }),
158
157
  }),
159
158
  // Checked once closed, when every record has ended: a test whose fault rule forwarded a request Testserver
@@ -169,7 +168,7 @@ const fixtures = vitestTest
169
168
  failure.message = message;
170
169
  }));
171
170
  onTestFailed(() => {
172
- console.error(proxyFailureReport(container.testId, proxy.requests, (text) => proxy.redact(text), proxy.faults));
171
+ console.error(proxyFailureReport(container.testId, proxy.requests, (text) => proxy.redact(text), proxy.faults, proxySessionHeader));
173
172
  });
174
173
  return proxy;
175
174
  });
@@ -206,12 +205,16 @@ const fixtures = vitestTest
206
205
  * test whose feature flags differ from those of the file's container ends it and starts a new one.
207
206
  * - `recordHeaders`: the headers whose values the container's and the proxy's records show as sent besides the
208
207
  * SDK's defaults (`DEFAULT_RECORD_HEADERS`, such as `content-type`), such as `["dpop"]`, by default none. Every other header's value reads `<redacted>`, but `authorization`,
209
- * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). The proxy's
210
- * records also show `x-vercel-cli-session-id`, the Vercel CLI invoker's session id. A suite sets it on its own
208
+ * which shows its scheme, and cookies, which show their names (`ContainerOptions.recordHeaders`). A suite sets it on its own
211
209
  * `test` with `.override("recordHeaders", [...])`, a file or `describe` with `test.override({ recordHeaders })`.
212
210
  * In `'file'` scope, a test whose list shows other headers than that of the file's container ends it and starts a
213
211
  * new one, as for `featureFlags`; the proxy is the test's own. A bad list fails the test with a `TypeError` before
214
212
  * any container is acquired.
213
+ * - `proxySessionHeader`: an optional request header name that `proxy` records in addition to `recordHeaders` and
214
+ * prints as `, session <value>` on proxied request lines (such as `VERCEL_CLI_SESSION_ID_HEADER`), by default
215
+ * `undefined`. A suite sets it on its own `test` with `.override("proxySessionHeader", ...)`, a file or `describe`
216
+ * with `test.override({ proxySessionHeader })`. Unlike `recordHeaders`, it applies only to `proxy`, survives
217
+ * per-test `recordHeaders` overrides, and never replaces a file-scoped container.
215
218
  * - `container`: in `'file'` scope, the file's container, labeled with the file's path, started by the file's first
216
219
  * test that asks for it. A failed test that used it ends it when its failure may come from the container, such as
217
220
  * a failed factory call or API request, a fault rule's forwarded request Testserver failed, or a timeout, so the
@@ -28,12 +28,19 @@ export interface TestserverTestFixtureSet {
28
28
  /**
29
29
  * The headers whose values the container's and the proxy's records show as sent besides the SDK's defaults
30
30
  * (`DEFAULT_RECORD_HEADERS`, such as `content-type`), such as `["dpop"]`; by default none, so every other header's
31
- * value reads `<redacted>`. The proxy's records also show the `vercel` CLI's
32
- * `x-vercel-cli-session-id`. Set it with `.override("recordHeaders", [...])` on a suite's `test`, or
31
+ * value reads `<redacted>`. Set it with `.override("recordHeaders", [...])` on a suite's `test`, or
33
32
  * `test.override({ recordHeaders })`. In `'file'` scope, a test whose list shows other headers than that of the
34
33
  * file's container ends it and gets a new one, as for `featureFlags`.
35
34
  */
36
35
  recordHeaders: readonly string[];
36
+ /**
37
+ * An optional request header name that `proxy` records in addition to `recordHeaders` and prints as
38
+ * `, session <value>` on proxied request lines (such as `VERCEL_CLI_SESSION_ID_HEADER`); by default `undefined`.
39
+ * Set it with `.override("proxySessionHeader", ...)` on a suite's `test`, or
40
+ * `test.override({ proxySessionHeader })`. Unlike `recordHeaders`, it applies only to `proxy`, survives per-test
41
+ * `recordHeaders` overrides, and never replaces a file-scoped container.
42
+ */
43
+ proxySessionHeader: string | undefined;
37
44
  /** The file's container in `'file'` scope, or the test's own in `'test'` scope. */
38
45
  container: Container;
39
46
  /** A proxy adding `container`'s test id, closed after the test. */
@@ -6,4 +6,6 @@ export interface StormBuild {
6
6
  readonly commit: string | null;
7
7
  }
8
8
  /** The live app over the resolved host, whose commands record their status in `exit`, which the executable reads. */
9
- export declare function liveStormApp(host: NodeHost, build: StormBuild, exit: StormExit): StormApp;
9
+ export declare function liveStormApp(host: NodeHost, build: StormBuild, exit: StormExit, options?: {
10
+ readonly noColor?: boolean;
11
+ }): StormApp;
package/dist/live-app.js CHANGED
@@ -7,8 +7,11 @@ import { resolvePresentation } from "./presentation.js";
7
7
  import { liveDriverContexts, liveResourceContexts, RESOURCES } from "./extensions.js";
8
8
  import { localUserName } from "./runner/index.js";
9
9
  /** The live app over the resolved host, whose commands record their status in `exit`, which the executable reads. */
10
- export function liveStormApp(host, build, exit) {
11
- const context = liveContext({ env: host.env });
10
+ export function liveStormApp(host, build, exit, options = {}) {
11
+ const context = liveContext({
12
+ env: host.env,
13
+ ...(options.noColor === undefined ? {} : { noColor: options.noColor }),
14
+ });
12
15
  return {
13
16
  context,
14
17
  resourceContexts: liveResourceContexts(host.env),
@@ -353,12 +353,20 @@ export interface RunnerSandboxGateway {
353
353
  /** Deletes a sandbox, keeping every snapshot it was started from or saved as. */
354
354
  delete(sandbox: RunnerSandbox): Promise<RunnerSandboxOperation>;
355
355
  }
356
+ /**
357
+ * What color environment variable the launcher terminal asks the command to receive when the command's own
358
+ * environment sets neither `FORCE_COLOR` nor `NO_COLOR`:
359
+ * - `"on"`: set `FORCE_COLOR=1` (stdout is a TTY, or launcher `FORCE_COLOR` turns color on).
360
+ * - `"off"`: set `NO_COLOR=1` (`--no-color` was passed, or launcher `NO_COLOR` is set and non-empty).
361
+ * - `"auto"`: set neither (non-TTY launcher with no explicit color setting, or `FORCE_COLOR` set to `0` or `false`).
362
+ */
363
+ export type RunnerTerminalColor = "on" | "off" | "auto";
356
364
  /**
357
365
  * The terminal the command's output reaches, wherever the command runs, a DI seam: stdout and stderr, and whether the
358
- * terminal shows color. Writes never throw.
366
+ * launcher terminal asks the command for color. Writes never throw.
359
367
  */
360
368
  export interface RunnerTerminal {
361
- readonly color: boolean;
369
+ readonly color: RunnerTerminalColor;
362
370
  writeStdout(text: string): void;
363
371
  writeStderr(text: string): void;
364
372
  }
@@ -1,7 +1,7 @@
1
1
  export type { RunnerContext } from "./context.ts";
2
2
  export { buildSnapshots, prepareSnapshotBuild, type PrepareSnapshotBuildOutcome, type SnapshotBuildOutcome, } from "./build-snapshots.ts";
3
3
  export { type KeptSandbox, type RunnerEvent, type RunnerFailure, type RunnerProgress, type RunnerStepPhase, type SnapshotBuildReason, } from "./events.ts";
4
- export type { CheckoutFailure, CheckoutGateway, RunnerSandboxGateway, RunnerSnapshotCacheFailure, RunnerSnapshotCacheGateway, RunnerSnapshotEntry, RunnerTerminal, } from "./gateways.ts";
4
+ export type { CheckoutFailure, CheckoutGateway, RunnerSandboxGateway, RunnerSnapshotCacheFailure, RunnerSnapshotCacheGateway, RunnerSnapshotEntry, RunnerTerminal, RunnerTerminalColor, } from "./gateways.ts";
5
5
  export { liveCheckoutGateway } from "./live/checkout-gateway.ts";
6
6
  export { liveRunnerSandboxGateway } from "./live/sandbox-gateway.ts";
7
7
  export { liveRunnerTerminal } from "./live/terminal.ts";
@@ -15,6 +15,20 @@ export const KILL_GRACE_MS = 5_000;
15
15
  const STDERR_MESSAGE_CHARS = 1000;
16
16
  /** The Sandbox API's answer when a snapshot to start from has expired or been deleted. */
17
17
  const SNAPSHOT_GONE_STATUS = 410;
18
+ /**
19
+ * `setpriv` flags used to drop every Linux capability and block privilege escalation before `execve` of the user
20
+ * command. Vercel Sandbox's default `vercel-sandbox` user (uid 1000) holds full capabilities (`CAP_DAC_OVERRIDE`,
21
+ * `CAP_DAC_READ_SEARCH`, etc.), which causes filesystem permission tests (`chmod 0500` / `0444`) to pass writes
22
+ * instead of failing with `EACCES`. Only `runCommand` uses this; `runScript` keeps capabilities so toolchain steps
23
+ * can run `sudo dnf install`.
24
+ */
25
+ const DROP_CAPABILITIES_ARGS = [
26
+ "--inh-caps=-all",
27
+ "--ambient-caps=-all",
28
+ "--bounding-set=-all",
29
+ "--no-new-privs",
30
+ "--",
31
+ ];
18
32
  /** Vercel Sandbox through `@vercel/sandbox`. */
19
33
  export function liveRunnerSandboxGateway() {
20
34
  let loading;
@@ -125,8 +139,8 @@ export function liveRunnerSandboxGateway() {
125
139
  if (kill.aborted)
126
140
  return { ok: false, failure: { kind: "aborted" } };
127
141
  const command = await startDetached(holder, {
128
- cmd,
129
- args: [...request.args],
142
+ cmd: "setpriv",
143
+ args: [...DROP_CAPABILITIES_ARGS, cmd, ...request.args],
130
144
  cwd: request.cwd,
131
145
  env: { ...request.env },
132
146
  });
@@ -1,4 +1,4 @@
1
- import type { RunnerTerminal } from "../gateways.ts";
1
+ import type { RunnerTerminal, RunnerTerminalColor } from "../gateways.ts";
2
2
  /** The part of a writable stream the terminal uses: `process.stdout` and `process.stderr` have it. */
3
3
  export interface TerminalStream {
4
4
  readonly isTTY?: boolean;
@@ -6,11 +6,23 @@ export interface TerminalStream {
6
6
  on(event: "error", listener: (error: Error) => void): unknown;
7
7
  }
8
8
  /**
9
- * A terminal over `stdout` and `stderr`, by default this process's. It shows color when stdout is a TTY and the
10
- * launcher environment doesn't set `NO_COLOR`.
9
+ * Resolves the color policy for a command launched from this terminal:
10
+ * - `"off"` when `--no-color` was passed or launcher `NO_COLOR` is set and non-empty.
11
+ * - `"on"` when launcher `FORCE_COLOR` is set to a non-empty value other than `"0"` or `"false"`, or `stdout` is a TTY and `TERM` isn't `"dumb"`.
12
+ * - `"auto"` otherwise, so a non-TTY or `TERM=dumb` launcher with no explicit color opt-out sets neither `FORCE_COLOR` nor `NO_COLOR`.
13
+ */
14
+ export declare function resolveRunnerTerminalColor(options: {
15
+ readonly isTTY: boolean;
16
+ readonly env: Readonly<Record<string, string | undefined>>;
17
+ readonly noColor?: boolean;
18
+ }): RunnerTerminalColor;
19
+ /**
20
+ * A terminal over `stdout` and `stderr`, by default this process's. Its `color` reflects explicit `--no-color` /
21
+ * `NO_COLOR`, explicit `FORCE_COLOR`, or an interactive TTY stdout, and stays `"auto"` on a plain non-TTY launcher.
11
22
  */
12
23
  export declare function liveRunnerTerminal(options: {
13
24
  readonly env: Readonly<Record<string, string | undefined>>;
25
+ readonly noColor?: boolean;
14
26
  readonly stdout?: TerminalStream;
15
27
  readonly stderr?: TerminalStream;
16
28
  }): RunnerTerminal;
@@ -2,8 +2,26 @@
2
2
  // EPIPE after SIGHUP closes the terminal, it stops writing, so a closed terminal can't crash storm before it
3
3
  // cleans up its sandboxes.
4
4
  /**
5
- * A terminal over `stdout` and `stderr`, by default this process's. It shows color when stdout is a TTY and the
6
- * launcher environment doesn't set `NO_COLOR`.
5
+ * Resolves the color policy for a command launched from this terminal:
6
+ * - `"off"` when `--no-color` was passed or launcher `NO_COLOR` is set and non-empty.
7
+ * - `"on"` when launcher `FORCE_COLOR` is set to a non-empty value other than `"0"` or `"false"`, or `stdout` is a TTY and `TERM` isn't `"dumb"`.
8
+ * - `"auto"` otherwise, so a non-TTY or `TERM=dumb` launcher with no explicit color opt-out sets neither `FORCE_COLOR` nor `NO_COLOR`.
9
+ */
10
+ export function resolveRunnerTerminalColor(options) {
11
+ if (options.noColor === true)
12
+ return "off";
13
+ const noColor = options.env["NO_COLOR"];
14
+ if (noColor !== undefined && noColor !== "")
15
+ return "off";
16
+ const forced = options.env["FORCE_COLOR"];
17
+ if (forced !== undefined && forced !== "") {
18
+ return forced === "0" || forced === "false" ? "auto" : "on";
19
+ }
20
+ return options.isTTY && options.env["TERM"] !== "dumb" ? "on" : "auto";
21
+ }
22
+ /**
23
+ * A terminal over `stdout` and `stderr`, by default this process's. Its `color` reflects explicit `--no-color` /
24
+ * `NO_COLOR`, explicit `FORCE_COLOR`, or an interactive TTY stdout, and stays `"auto"` on a plain non-TTY launcher.
7
25
  */
8
26
  export function liveRunnerTerminal(options) {
9
27
  const stdout = options.stdout ?? process.stdout;
@@ -30,7 +48,11 @@ export function liveRunnerTerminal(options) {
30
48
  }
31
49
  };
32
50
  return {
33
- color: stdout.isTTY === true && options.env["NO_COLOR"] === undefined,
51
+ color: resolveRunnerTerminalColor({
52
+ isTTY: stdout.isTTY === true,
53
+ env: options.env,
54
+ ...(options.noColor === undefined ? {} : { noColor: options.noColor }),
55
+ }),
34
56
  writeStdout: (text) => write(stdout, text),
35
57
  writeStderr: (text) => write(stderr, text),
36
58
  };
@@ -54,8 +54,9 @@ export interface RunnerRecipe<Run = never> {
54
54
  readonly vcpus: number | ((run: Run) => number);
55
55
  /**
56
56
  * Extra environment variables for the command. It can't set `STORM_RUN`. When it sets neither `FORCE_COLOR` nor
57
- * `NO_COLOR`, storm sets `FORCE_COLOR=1` when the local terminal shows color, else `NO_COLOR=1`; when it sets
58
- * either, storm sets neither, so `{ FORCE_COLOR: "1" }` gets color and no `NO_COLOR`.
57
+ * `NO_COLOR`, storm sets `FORCE_COLOR=1` when the local terminal asks for color (a TTY or `FORCE_COLOR`),
58
+ * `NO_COLOR=1` when the launcher explicitly opted out (`--no-color` or a non-empty `NO_COLOR`), and neither on a
59
+ * plain non-TTY launcher; when the recipe sets either, storm sets neither.
59
60
  */
60
61
  readonly env?: Readonly<Record<string, string>>;
61
62
  /**
@@ -1,6 +1,6 @@
1
1
  import type { Clock } from "../time/index.ts";
2
2
  import type { RunnerFailure, RunnerProgress } from "./events.ts";
3
- import type { RunnerSandboxGateway, RunnerTerminal } from "./gateways.ts";
3
+ import type { RunnerSandboxGateway, RunnerTerminal, RunnerTerminalColor } from "./gateways.ts";
4
4
  import type { ReadyRunner } from "./ready.ts";
5
5
  /**
6
6
  * The command as the runner sandbox runs it: each `<repoRoot>/` in its arguments, the executable's included, points
@@ -18,14 +18,14 @@ export declare function sandboxedCommand(request: {
18
18
  * What the command's environment adds to the runner sandbox's own: `PATH` with the sandbox `cwd`'s and the
19
19
  * repository's `node_modules/.bin` before the login shell's, no update checks, the recipe's `env`, and `STORM_RUN`
20
20
  * last, so nothing overrides it. When the recipe's `env` sets neither `FORCE_COLOR` nor `NO_COLOR`, it also gets
21
- * `FORCE_COLOR=1` when the local terminal shows color, else `NO_COLOR=1`, as a run with no runner does
22
- * (`colorEnvironment` in `core/payload.ts`); a recipe that sets either gets neither from storm. Nothing comes from
23
- * the local environment.
21
+ * `FORCE_COLOR=1` when the local terminal asks for color (`"on"`), `NO_COLOR=1` when the launcher explicitly opted out
22
+ * (`"off"`), and neither on a plain non-TTY launcher (`"auto"`), as a run with no runner does (`colorEnvironment` in
23
+ * `core/payload.ts`); a recipe that sets either gets neither from storm. Nothing else comes from the local environment.
24
24
  */
25
25
  export declare function sandboxEnvironment(request: {
26
26
  readonly cwd: string;
27
27
  readonly loginPath: string;
28
- readonly color: boolean;
28
+ readonly color: RunnerTerminalColor;
29
29
  readonly env: Readonly<Record<string, string>>;
30
30
  readonly runPayload: string;
31
31
  }): Record<string, string>;
@@ -18,9 +18,9 @@ export function sandboxedCommand(request) {
18
18
  * What the command's environment adds to the runner sandbox's own: `PATH` with the sandbox `cwd`'s and the
19
19
  * repository's `node_modules/.bin` before the login shell's, no update checks, the recipe's `env`, and `STORM_RUN`
20
20
  * last, so nothing overrides it. When the recipe's `env` sets neither `FORCE_COLOR` nor `NO_COLOR`, it also gets
21
- * `FORCE_COLOR=1` when the local terminal shows color, else `NO_COLOR=1`, as a run with no runner does
22
- * (`colorEnvironment` in `core/payload.ts`); a recipe that sets either gets neither from storm. Nothing comes from
23
- * the local environment.
21
+ * `FORCE_COLOR=1` when the local terminal asks for color (`"on"`), `NO_COLOR=1` when the launcher explicitly opted out
22
+ * (`"off"`), and neither on a plain non-TTY launcher (`"auto"`), as a run with no runner does (`colorEnvironment` in
23
+ * `core/payload.ts`); a recipe that sets either gets neither from storm. Nothing else comes from the local environment.
24
24
  */
25
25
  export function sandboxEnvironment(request) {
26
26
  const bins = [
@@ -31,9 +31,11 @@ export function sandboxEnvironment(request) {
31
31
  NO_UPDATE_NOTIFIER: "1",
32
32
  ...(request.env["FORCE_COLOR"] !== undefined || request.env["NO_COLOR"] !== undefined
33
33
  ? {}
34
- : request.color
34
+ : request.color === "on"
35
35
  ? { FORCE_COLOR: "1" }
36
- : { NO_COLOR: "1" }),
36
+ : request.color === "off"
37
+ ? { NO_COLOR: "1" }
38
+ : {}),
37
39
  ...request.env,
38
40
  [RUN_PAYLOAD_VARIABLE]: request.runPayload,
39
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnc-tools/storm",
3
- "version": "0.14.0",
3
+ "version": "0.14.2",
4
4
  "description": "A test orchestrator: run your tests in the inner loop of development, in the cloud, in a test environment that you define",
5
5
  "repository": {
6
6
  "type": "git",