@fuzdev/fuz_app 0.175.0 → 0.176.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 (84) hide show
  1. package/README.md +3 -2
  2. package/dist/actions/CLAUDE.md +10 -8
  3. package/dist/actions/ws_outbound_writer.d.ts +8 -8
  4. package/dist/actions/ws_outbound_writer.d.ts.map +1 -1
  5. package/dist/actions/ws_outbound_writer.js +8 -11
  6. package/dist/auth/keyring.d.ts +1 -1
  7. package/dist/auth/keyring.js +1 -1
  8. package/dist/db/CLAUDE.md +9 -0
  9. package/dist/db/fact_disk_storage.d.ts +3 -2
  10. package/dist/db/fact_disk_storage.d.ts.map +1 -1
  11. package/dist/db/fact_disk_storage.js +2 -1
  12. package/dist/db/postgres_url.d.ts +95 -0
  13. package/dist/db/postgres_url.d.ts.map +1 -0
  14. package/dist/db/postgres_url.js +167 -0
  15. package/dist/dev/setup.d.ts +101 -33
  16. package/dist/dev/setup.d.ts.map +1 -1
  17. package/dist/dev/setup.js +174 -71
  18. package/dist/env/dotenv.d.ts +1 -1
  19. package/dist/env/dotenv.d.ts.map +1 -1
  20. package/dist/env/dotenv.js +2 -3
  21. package/dist/http/CLAUDE.md +1 -1
  22. package/dist/http/body_limit.d.ts +10 -16
  23. package/dist/http/body_limit.d.ts.map +1 -1
  24. package/dist/http/body_limit.js +10 -16
  25. package/dist/runtime/deps.d.ts +81 -45
  26. package/dist/runtime/deps.d.ts.map +1 -1
  27. package/dist/runtime/deps.js +7 -2
  28. package/dist/runtime/mock.d.ts +63 -16
  29. package/dist/runtime/mock.d.ts.map +1 -1
  30. package/dist/runtime/mock.js +75 -35
  31. package/dist/runtime/node.d.ts +3 -2
  32. package/dist/runtime/node.d.ts.map +1 -1
  33. package/dist/runtime/node.js +20 -72
  34. package/dist/runtime/process_id.d.ts +24 -0
  35. package/dist/runtime/process_id.d.ts.map +1 -0
  36. package/dist/runtime/process_id.js +27 -0
  37. package/dist/runtime/secure_file.d.ts +8 -30
  38. package/dist/runtime/secure_file.d.ts.map +1 -1
  39. package/dist/runtime/secure_file.js +23 -51
  40. package/dist/server/app_server.d.ts +2 -2
  41. package/dist/server/static.d.ts +1 -1
  42. package/dist/testing/CLAUDE.md +28 -27
  43. package/dist/testing/cross_backend/backend_config.d.ts +7 -7
  44. package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
  45. package/dist/testing/cross_backend/bench/bench_report.d.ts +2 -2
  46. package/dist/testing/cross_backend/bench/bench_report.js +2 -2
  47. package/dist/testing/cross_backend/body_size_smuggling.d.ts.map +1 -1
  48. package/dist/testing/cross_backend/body_size_smuggling.js +1 -4
  49. package/dist/testing/cross_backend/bootstrap_backend.d.ts +1 -1
  50. package/dist/testing/cross_backend/capabilities.d.ts +2 -2
  51. package/dist/testing/cross_backend/create_cross_backend_global_setup.d.ts +2 -2
  52. package/dist/testing/cross_backend/create_cross_backend_global_setup.js +1 -1
  53. package/dist/testing/cross_backend/create_dual_spawn_global_setup.d.ts +2 -2
  54. package/dist/testing/cross_backend/default_backend_configs.d.ts +1 -1
  55. package/dist/testing/cross_backend/default_backend_configs.js +4 -4
  56. package/dist/testing/cross_backend/differential.d.ts +2 -2
  57. package/dist/testing/cross_backend/differential.js +6 -6
  58. package/dist/testing/cross_backend/fact_serving.js +1 -1
  59. package/dist/testing/cross_backend/make_cross_backend_project.d.ts +2 -2
  60. package/dist/testing/cross_backend/make_cross_backend_project.js +1 -1
  61. package/dist/testing/cross_backend/origin_conformance.json +1 -1
  62. package/dist/testing/cross_backend/postgres_database.d.ts +7 -21
  63. package/dist/testing/cross_backend/postgres_database.d.ts.map +1 -1
  64. package/dist/testing/cross_backend/postgres_database.js +24 -35
  65. package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
  66. package/dist/testing/cross_backend/testing_server_bun.js +10 -12
  67. package/dist/testing/cross_backend/testing_server_core.d.ts +13 -17
  68. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  69. package/dist/testing/cross_backend/testing_server_core.js +1 -1
  70. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts +7 -17
  71. package/dist/testing/cross_backend/ts_spine_backend_config.d.ts.map +1 -1
  72. package/dist/testing/cross_backend/ts_spine_backend_config.js +0 -51
  73. package/dist/testing/cross_backend/ws_outbound_overflow.js +2 -2
  74. package/dist/testing/daemon_info.d.ts +11 -6
  75. package/dist/testing/daemon_info.d.ts.map +1 -1
  76. package/dist/testing/daemon_info.js +11 -8
  77. package/dist/testing/middleware_gate_probes.js +2 -2
  78. package/package.json +4 -9
  79. package/dist/runtime/deno.d.ts +0 -21
  80. package/dist/runtime/deno.d.ts.map +0 -1
  81. package/dist/runtime/deno.js +0 -191
  82. package/dist/testing/cross_backend/testing_server_deno.d.ts +0 -5
  83. package/dist/testing/cross_backend/testing_server_deno.d.ts.map +0 -1
  84. package/dist/testing/cross_backend/testing_server_deno.js +0 -38
@@ -143,7 +143,7 @@ const unescape_double_quoted = (s) => {
143
143
  * @param runtime - runtime with `read_text_file` capability
144
144
  * @param path - path to env file
145
145
  * @returns parsed env record, or `null` if file doesn't exist
146
- * @throws Error if reading fails for any reason other than `ENOENT` / `NotFound`
146
+ * @throws Error if reading fails for any reason other than `ENOENT`
147
147
  */
148
148
  export const load_env_file = async (runtime, path) => {
149
149
  try {
@@ -151,8 +151,7 @@ export const load_env_file = async (runtime, path) => {
151
151
  return parse_dotenv(content);
152
152
  }
153
153
  catch (error) {
154
- // Node (`ENOENT`) and Deno (`Deno.errors.NotFound`) — handle both.
155
- if (error?.code === 'ENOENT' || error?.name === 'NotFound')
154
+ if (error?.code === 'ENOENT')
156
155
  return null;
157
156
  throw error;
158
157
  }
@@ -24,7 +24,7 @@ effects, see ../../../docs/architecture.md.
24
24
  - `http/schema_helpers.ts` — shared schema introspection (null/void/strict/surface/middleware-applies), and `to_void_params` / `to_input_params` / `scan_json_value` / `safe_parse_dropping_unknown_keys`.
25
25
  - `http/json_text.ts` — `parse_json_text`: JSON text read as the Rust spine's `serde_json` reads it, refusing what `JSON.parse` accepts and serde refuses (an escaped lone surrogate in a string or key, a number out of `f64` range, nesting `JSON_DEPTH_LIMIT` (128) deep); one linear scan of the text after `JSON.parse` accepts it (`is_serde_json_text`), so a refused value under a duplicated key is seen and the cost stays a few milliseconds a MiB. `read_json_body(c.req)` reads a request body through it once per request (the authorization phase's `acting` read and input validation share it), as text, never `c.req.json()`. Every body and frame parse runs it: route input, the RPC POST body and `GET` `params`, WS frames. Hono-free, imports nothing.
26
26
  - `http/middleware_spec.ts` — `MiddlewareSpec` interface.
27
- - `http/body_limit.ts` — `create_body_limit_middleware(max_size)`: the `413` body cap `create_app_server` mounts, as `create_body_limit_middleware_spec(max_size)`, a `MiddlewareSpec` at `'*'` ahead of the other middleware, absent with `max_body_size: null`. Its hono-free shape, `body_limit_middleware_shape` (`http/body_limit_schema.ts`), declares its `413` `payload_too_large` and `400` `invalid_content_length`, so every route's error map carries both; `create_test_app_surface_spec` lists the same shape with a stub handler. Refuses on `Content-Length` without reading `c.req.raw.body` and answers `Connection: close` — `413` past the cap, `400` `ERROR_INVALID_CONTENT_LENGTH` when the value is not a plain run of ASCII digits (a length the cap cannot read, which Hono's `bodyLimit` would pass uncounted) — else falls through to Hono's `bodyLimit` (no `Content-Length`, or one beside `Transfer-Encoding`), which reads the body into memory up to the cap before the next middleware runs, so its `413` — no `Connection: close` — also precedes origin and auth. After the header `413` Node and Bun close at once (the header is what makes them — Bun 1.4.3 is the tested floor, an older Bun kept the connection and served the next request) and Deno closes once the declared body has arrived (../../../docs/security.md §Body Size Limiting).
27
+ - `http/body_limit.ts` — `create_body_limit_middleware(max_size)`: the `413` body cap `create_app_server` mounts, as `create_body_limit_middleware_spec(max_size)`, a `MiddlewareSpec` at `'*'` ahead of the other middleware, absent with `max_body_size: null`. Its hono-free shape, `body_limit_middleware_shape` (`http/body_limit_schema.ts`), declares its `413` `payload_too_large` and `400` `invalid_content_length`, so every route's error map carries both; `create_test_app_surface_spec` lists the same shape with a stub handler. Refuses on `Content-Length` without reading `c.req.raw.body` and answers `Connection: close` — `413` past the cap, `400` `ERROR_INVALID_CONTENT_LENGTH` when the value is not a plain run of ASCII digits (a length the cap cannot read, which Hono's `bodyLimit` would pass uncounted) — else falls through to Hono's `bodyLimit` (no `Content-Length`, or one beside `Transfer-Encoding`), which reads the body into memory up to the cap before the next middleware runs, so its `413` — no `Connection: close` — also precedes origin and auth. After the header `413` Node and Bun close at once (the header is what makes them — Bun 1.4.3 is the tested floor, an older Bun kept the connection and served the next request) (../../../docs/security.md §Body Size Limiting).
28
28
  - `http/surface.ts` — `AppSurface`, `AppSurfaceSpec`, `generate_app_surface`, diagnostics.
29
29
  - `http/surface_query.ts` — pure filters/groupings over `AppSurface`.
30
30
  - `http/proxy.ts` — trusted-proxy middleware, CIDR parsing, rightmost-first XFF resolution. Pulls `hono/utils/ipaddr` for CIDR matching.
@@ -11,20 +11,18 @@
11
11
  * The runtimes' HTTP parsers answer their own bodiless `400` to most of
12
12
  * these before the application sees them, so this branch is defense in
13
13
  * depth where they do and the refusal where they do not: Node's refuses
14
- * them all; Deno and Bun hand over a repeated equal header as one combined
15
- * value (`50, 50`) and refuse the rest (observed on Node 24.14.1, Deno
16
- * 2.8.3, Bun 1.4.3). The Rust spine's parser (hyper) refuses a malformed
17
- * value and differing repeats, and accepts an equal repeat as the one
18
- * value.
14
+ * them all; Bun hands over a repeated equal header as one combined value
15
+ * (`50, 50`) and refuses the rest (observed on Node 24.14.1, Bun 1.4.3).
16
+ * The Rust spine's parser (hyper) refuses a malformed value and differing
17
+ * repeats, and accepts an equal repeat as the one value.
19
18
  * - A request whose `Content-Length` exceeds the cap is refused with `413`
20
19
  * `{error: 'payload_too_large'}`, whatever its method. A digit run of any
21
20
  * length compares as a number, so one too long to represent exactly is over
22
- * the cap, never unreadable. Over a socket that branch is reached on Node
23
- * and Deno, whose parsers hand over any length below 2^64 and refuse a
24
- * longer one with their own `400`. `Bun.serve` hands none over: with its
25
- * default options it answers a length past 128 MiB with its own `413`, and
26
- * one of 2^63 - 1 or more with its own `400` (observed on Node 24.14.1,
27
- * Deno 2.8.3, Bun 1.4.3).
21
+ * the cap, never unreadable. Over a socket that branch is reached on Node,
22
+ * whose parser hands over any length below 2^64 and refuses a longer one
23
+ * with its own `400`. `Bun.serve` hands none over: with its default options
24
+ * it answers a length past 128 MiB with its own `413`, and one of 2^63 - 1
25
+ * or more with its own `400` (observed on Node 24.14.1, Bun 1.4.3).
28
26
  * - Both refusals answer on the header alone — without touching
29
27
  * `c.req.raw.body` — and carry `Connection: close`.
30
28
  * - A request with a well-formed `Content-Length` beside `Transfer-Encoding`,
@@ -38,7 +36,7 @@
38
36
  * the headers answers first; which status an over-cap body with no declared
39
37
  * length gets when another refusal also applies is implementation-defined
40
38
  * across the two (`docs/security.md` §"Body Size Limiting").
41
- * The Node, Deno and Bun parsers refuse a request carrying both headers
39
+ * The Node and Bun parsers refuse a request carrying both headers
42
40
  * with their own `400`; hyper accepts one, drops its `Content-Length`,
43
41
  * frames the body as chunked, and closes the connection after the response.
44
42
  * - A well-formed `Content-Length` within the cap is trusted to frame the
@@ -52,10 +50,6 @@
52
50
  * holds the connection for a drain window and then closes or, the body
53
51
  * untouched and arriving within the window, reads it off and serves the
54
52
  * next request.
55
- * - **Deno** closes once the whole declared body has arrived and holds the
56
- * connection open while a client withholds it; a request pipelined behind
57
- * the body is not served. Neither the header nor what the handler does with
58
- * the body changes that (observed on Deno 2.8.3).
59
53
  * - **Bun** closes at once, the body unread, honouring the header. Bun 1.4.3
60
54
  * is the tested floor: an older Bun kept the connection after the `413` and
61
55
  * served the next request (correctly framed), so run Bun at the floor or
@@ -1 +1 @@
1
- {"version":3,"file":"body_limit.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/body_limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAI9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,MAAM,KAAG,iBA6B/D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,KAAG,cAGnE,CAAC"}
1
+ {"version":3,"file":"body_limit.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/body_limit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAI9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,GAAI,UAAU,MAAM,KAAG,iBA6B/D,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,KAAG,cAGnE,CAAC"}
@@ -11,20 +11,18 @@
11
11
  * The runtimes' HTTP parsers answer their own bodiless `400` to most of
12
12
  * these before the application sees them, so this branch is defense in
13
13
  * depth where they do and the refusal where they do not: Node's refuses
14
- * them all; Deno and Bun hand over a repeated equal header as one combined
15
- * value (`50, 50`) and refuse the rest (observed on Node 24.14.1, Deno
16
- * 2.8.3, Bun 1.4.3). The Rust spine's parser (hyper) refuses a malformed
17
- * value and differing repeats, and accepts an equal repeat as the one
18
- * value.
14
+ * them all; Bun hands over a repeated equal header as one combined value
15
+ * (`50, 50`) and refuses the rest (observed on Node 24.14.1, Bun 1.4.3).
16
+ * The Rust spine's parser (hyper) refuses a malformed value and differing
17
+ * repeats, and accepts an equal repeat as the one value.
19
18
  * - A request whose `Content-Length` exceeds the cap is refused with `413`
20
19
  * `{error: 'payload_too_large'}`, whatever its method. A digit run of any
21
20
  * length compares as a number, so one too long to represent exactly is over
22
- * the cap, never unreadable. Over a socket that branch is reached on Node
23
- * and Deno, whose parsers hand over any length below 2^64 and refuse a
24
- * longer one with their own `400`. `Bun.serve` hands none over: with its
25
- * default options it answers a length past 128 MiB with its own `413`, and
26
- * one of 2^63 - 1 or more with its own `400` (observed on Node 24.14.1,
27
- * Deno 2.8.3, Bun 1.4.3).
21
+ * the cap, never unreadable. Over a socket that branch is reached on Node,
22
+ * whose parser hands over any length below 2^64 and refuses a longer one
23
+ * with its own `400`. `Bun.serve` hands none over: with its default options
24
+ * it answers a length past 128 MiB with its own `413`, and one of 2^63 - 1
25
+ * or more with its own `400` (observed on Node 24.14.1, Bun 1.4.3).
28
26
  * - Both refusals answer on the header alone — without touching
29
27
  * `c.req.raw.body` — and carry `Connection: close`.
30
28
  * - A request with a well-formed `Content-Length` beside `Transfer-Encoding`,
@@ -38,7 +36,7 @@
38
36
  * the headers answers first; which status an over-cap body with no declared
39
37
  * length gets when another refusal also applies is implementation-defined
40
38
  * across the two (`docs/security.md` §"Body Size Limiting").
41
- * The Node, Deno and Bun parsers refuse a request carrying both headers
39
+ * The Node and Bun parsers refuse a request carrying both headers
42
40
  * with their own `400`; hyper accepts one, drops its `Content-Length`,
43
41
  * frames the body as chunked, and closes the connection after the response.
44
42
  * - A well-formed `Content-Length` within the cap is trusted to frame the
@@ -52,10 +50,6 @@
52
50
  * holds the connection for a drain window and then closes or, the body
53
51
  * untouched and arriving within the window, reads it off and serves the
54
52
  * next request.
55
- * - **Deno** closes once the whole declared body has arrived and holds the
56
- * connection open while a client withholds it; a request pipelined behind
57
- * the body is not served. Neither the header nor what the handler does with
58
- * the body changes that (observed on Deno 2.8.3).
59
53
  * - **Bun** closes at once, the body unread, honouring the header. Bun 1.4.3
60
54
  * is the tested floor: an older Bun kept the connection after the `413` and
61
55
  * served the next request (correctly framed), so run Bun at the floor or
@@ -2,8 +2,13 @@
2
2
  * Shared dependency interfaces for runtime operations.
3
3
  *
4
4
  * Small composable interfaces that functions accept for only the capabilities
5
- * they need. Both Deno and Node implementations satisfy all these interfaces
6
- * via `RuntimeDeps`.
5
+ * they need. `create_node_runtime` (Node and Bun) and `create_mock_runtime`
6
+ * satisfy all these interfaces via `RuntimeDeps`.
7
+ *
8
+ * Running a program is not a `RuntimeDeps` member: a helper that spawns takes
9
+ * each program it runs as its own `Program` handle, or a `ProgramFactory`
10
+ * that makes one, from the composition root, so no helper resolves a command
11
+ * name against the ambient `PATH` and environment.
7
12
  *
8
13
  * @module
9
14
  */
@@ -18,7 +23,7 @@ export interface StatResult {
18
23
  * directories it is runtime-defined (real OS `stat` reports the directory
19
24
  * entry's on-disk size, not 0 — only `create_mock_runtime` reports 0).
20
25
  * Populated by every runtime factory (`create_node_runtime` /
21
- * `create_deno_runtime` / `create_mock_runtime`); optional so loose test
26
+ * `create_mock_runtime`); optional so loose test
22
27
  * stubs that only assert `is_file` / `is_directory` don't have to supply it.
23
28
  * Callers that need an exact size (e.g. a streaming upload's
24
29
  * `Content-Length`) read it from a real runtime, where it is always present.
@@ -26,39 +31,14 @@ export interface StatResult {
26
31
  size?: number;
27
32
  /**
28
33
  * Last-modification time in epoch milliseconds, when the runtime reports it.
29
- * Populated by `create_node_runtime` / `create_deno_runtime`;
30
- * `create_mock_runtime` omits it (so a mock-backed sweep treats every temp as
31
- * unknown-age and never reaps). Optional so loose test stubs that only assert
32
- * `is_file` / `is_directory` don't have to supply it. The orphan-temp sweep
34
+ * Populated by `create_node_runtime`; `create_mock_runtime` omits it (so a
35
+ * mock-backed sweep treats every temp as unknown-age and never reaps).
36
+ * Optional so loose test stubs that only assert `is_file` / `is_directory`
37
+ * don't have to supply it. The orphan-temp sweep
33
38
  * (`db/fact_disk_storage.ts`) reads it to age out stale `.tmp` spill files.
34
39
  */
35
40
  mtime_ms?: number;
36
41
  }
37
- /**
38
- * Result of executing a command.
39
- *
40
- * `timed_out` is present only when `timeout_ms` was passed in `RunCommandOptions`
41
- * and the process was killed after exceeding the timeout. Callers that pass
42
- * `timeout_ms` should check this flag to distinguish timeout from exit-code failure.
43
- */
44
- export interface CommandResult {
45
- success: boolean;
46
- code: number;
47
- stdout: string;
48
- stderr: string;
49
- timed_out?: boolean;
50
- }
51
- /**
52
- * Options for `run_command`.
53
- */
54
- export interface RunCommandOptions {
55
- /** Working directory for the child process. */
56
- cwd?: string;
57
- /** AbortSignal to terminate the child process. */
58
- signal?: AbortSignal;
59
- /** Kill the process and return `timed_out: true` after this many milliseconds. */
60
- timeout_ms?: number;
61
- }
62
42
  /**
63
43
  * Environment variable access.
64
44
  */
@@ -198,19 +178,58 @@ export interface FsRemoveDeps {
198
178
  }) => Promise<void>;
199
179
  }
200
180
  /**
201
- * Command execution.
181
+ * How a program run ended: exited with a code, ended by a signal, or stopped
182
+ * after a timeout or an abort (with the code or signal it then ended by, the
183
+ * other `null`).
184
+ *
185
+ * The shape of `SpawnResult` in `@fuzdev/gro/spawn.ts`, declared here so a
186
+ * gro program handle satisfies `Program` without fuz_app depending on gro.
187
+ */
188
+ export type ProgramResult = {
189
+ readonly kind: 'exited';
190
+ readonly code: number;
191
+ } | {
192
+ readonly kind: 'signaled';
193
+ readonly signal: string;
194
+ } | {
195
+ readonly kind: 'timed_out' | 'aborted';
196
+ readonly code: number | null;
197
+ readonly signal: string | null;
198
+ };
199
+ /** A program run's result with its captured output, as UTF-8 text. */
200
+ export type ProgramOutput = ProgramResult & {
201
+ readonly stdout: string;
202
+ readonly stderr: string;
203
+ };
204
+ /**
205
+ * The capability to run one program, resolved and given its environment by
206
+ * whoever made it: the helper that holds it can run that program with
207
+ * arguments it chooses, and nothing else.
208
+ *
209
+ * A gro `SpawnProgram` (`spawn.program(name, options)` or `spawn.find`, from
210
+ * `@fuzdev/gro/spawn.ts`) satisfies it, built at a composition root that
211
+ * decides which binary runs and which environment it gets. A program is
212
+ * missing when `spawn.find` returns `null`, so a helper takes `Program | null`,
213
+ * or a `ProgramFactory`, where a missing tool is something to report rather
214
+ * than a bug.
202
215
  */
203
- export interface CommandDeps {
216
+ export interface Program {
204
217
  /**
205
- * Run a command and return the result. Never throws — failures surface as
206
- * `success: false`.
207
- *
208
- * `options.cwd` sets the child's working directory. `options.signal` aborts
209
- * the child when the signal fires. `options.timeout_ms` kills the child
210
- * after the given duration and returns `timed_out: true` on the result.
218
+ * Run the program with `args` (argv only, never a shell string), stdin
219
+ * closed, and capture its output. A non-zero exit is a result, not a throw;
220
+ * a program that can't start throws.
211
221
  */
212
- run_command: (cmd: string, args: Array<string>, options?: RunCommandOptions) => Promise<CommandResult>;
222
+ out: (args: ReadonlyArray<string>) => Promise<ProgramOutput>;
213
223
  }
224
+ /**
225
+ * Make a `Program` whose environment gains `env`, or `null` when the program
226
+ * isn't installed — for a helper that learns at run time what the program's
227
+ * environment must carry (a password read from a URL), where a gro handle's
228
+ * environment is fixed when it's made. At a gro task root:
229
+ * `(env) => spawn.find('createdb', {pass_env: ['PG*'], env})`, where `env`'s
230
+ * values win over the ones `pass_env` forwards.
231
+ */
232
+ export type ProgramFactory = (env: Readonly<Record<string, string>>) => Program | null;
214
233
  /**
215
234
  * HTTP fetch capability.
216
235
  */
@@ -242,20 +261,37 @@ export interface ProcessDeps {
242
261
  exit: (code: number) => never;
243
262
  }
244
263
  /**
245
- * Full runtime capabilities returned by `create_deno_runtime` or `create_node_runtime`.
264
+ * Whether a process exists, as signal 0 reports it: `'running'`, `'not_permitted'`
265
+ * (it exists, but this process may not signal it — another user's, `EPERM`),
266
+ * or `'not_found'` (`ESRCH`).
267
+ */
268
+ export type ProcessProbe = 'running' | 'not_permitted' | 'not_found';
269
+ /**
270
+ * Process liveness, with no program spawned.
271
+ */
272
+ export interface ProcessProbeDeps {
273
+ /**
274
+ * Probe the process `pid` names by sending it signal 0, which checks that
275
+ * it exists and may be signaled and delivers nothing.
276
+ *
277
+ * @throws RangeError when `pid` is not a positive integer within `pid_t`
278
+ * range — 0 and negative numbers name process groups, never one process
279
+ */
280
+ probe_process: (pid: number) => ProcessProbe;
281
+ }
282
+ /**
283
+ * Full runtime capabilities returned by `create_node_runtime` or `create_mock_runtime`.
246
284
  *
247
285
  * Extends all `*Deps` interfaces with additional app-level capabilities.
248
286
  * Functions should accept narrow `*Deps` interfaces, not this full type —
249
287
  * this type is for the wiring layer that creates and passes the runtime.
250
288
  */
251
- export interface RuntimeDeps extends EnvDeps, FsReadDeps, FsSecureReadDeps, FsWriteDeps, FsStreamDeps, FsRemoveDeps, CommandDeps, FetchDeps, TerminalDeps, ProcessDeps, LogDeps {
289
+ export interface RuntimeDeps extends EnvDeps, FsReadDeps, FsSecureReadDeps, FsWriteDeps, FsStreamDeps, FsRemoveDeps, FetchDeps, TerminalDeps, ProcessDeps, ProcessProbeDeps, LogDeps {
252
290
  /** Get all environment variables. */
253
291
  env_all: () => Record<string, string>;
254
292
  /** CLI arguments passed to the program. */
255
293
  readonly args: ReadonlyArray<string>;
256
294
  /** Get current working directory. */
257
295
  cwd: () => string;
258
- /** Run a command with inherited stdout/stderr (output goes directly to terminal). */
259
- run_command_inherit: (cmd: string, args: Array<string>) => Promise<number>;
260
296
  }
261
297
  //# sourceMappingURL=deps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deps.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/runtime/deps.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CA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AAW,WAChB,SACC,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,OAAO;IACR,qCAAqC;IACrC,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,2CAA2C;IAC3C,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACrC,qCAAqC;IACrC,GAAG,EAAE,MAAM,MAAM,CAAC;CAClB"}
@@ -2,8 +2,13 @@
2
2
  * Shared dependency interfaces for runtime operations.
3
3
  *
4
4
  * Small composable interfaces that functions accept for only the capabilities
5
- * they need. Both Deno and Node implementations satisfy all these interfaces
6
- * via `RuntimeDeps`.
5
+ * they need. `create_node_runtime` (Node and Bun) and `create_mock_runtime`
6
+ * satisfy all these interfaces via `RuntimeDeps`.
7
+ *
8
+ * Running a program is not a `RuntimeDeps` member: a helper that spawns takes
9
+ * each program it runs as its own `Program` handle, or a `ProgramFactory`
10
+ * that makes one, from the composition root, so no helper resolves a command
11
+ * name against the ambient `PATH` and environment.
7
12
  *
8
13
  * @module
9
14
  */
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @module
9
9
  */
10
- import type { RuntimeDeps, CommandResult, RunCommandOptions } from './deps.js';
10
+ import type { ProcessProbe, Program, ProgramFactory, ProgramOutput, RuntimeDeps } from './deps.js';
11
11
  /**
12
12
  * Mock `RuntimeDeps` with observable state for assertions.
13
13
  */
@@ -29,21 +29,13 @@ export interface MockRuntime extends RuntimeDeps {
29
29
  mock_dirs: Set<string>;
30
30
  /** Exit calls recorded (exit codes). */
31
31
  exit_calls: Array<number>;
32
- /** Commands executed. Captures `options` when passed so tests can assert cwd/timeout/signal. */
33
- command_calls: Array<{
34
- cmd: string;
35
- args: Array<string>;
36
- options?: RunCommandOptions;
37
- }>;
38
- /** Commands executed with inherit. */
39
- command_inherit_calls: Array<{
40
- cmd: string;
41
- args: Array<string>;
42
- }>;
32
+ /**
33
+ * Processes `probe_process` finds (pid -> probe). A pid with no entry is
34
+ * `'not_found'`.
35
+ */
36
+ mock_processes: Map<number, Exclude<ProcessProbe, 'not_found'>>;
43
37
  /** Stdout writes recorded. */
44
38
  stdout_writes: Array<string>;
45
- /** Mock command results (cmd -> result). */
46
- mock_command_results: Map<string, CommandResult>;
47
39
  /** Stdin buffer for input simulation. */
48
40
  stdin_buffer: Uint8Array | null;
49
41
  /** Fetch calls recorded. */
@@ -71,7 +63,6 @@ export interface MockRuntime extends RuntimeDeps {
71
63
  *
72
64
  * await some_function(runtime);
73
65
  *
74
- * assert.strictEqual(runtime.command_calls.length, 1);
75
66
  * assert.deepStrictEqual(runtime.exit_calls, [0]);
76
67
  * ```
77
68
  */
@@ -79,9 +70,65 @@ export declare const create_mock_runtime: (args?: Array<string>) => MockRuntime;
79
70
  /**
80
71
  * Reset a mock runtime to initial state.
81
72
  *
82
- * @mutates runtime - clears all mock state (env, fs, dirs, exit/command/stdout/fetch call records, mock results, stdin buffer)
73
+ * @mutates runtime - clears all mock state (env, fs, modes, dirs, processes, exit/stdout/fetch call records, fetch responses, stdin buffer)
83
74
  */
84
75
  export declare const reset_mock_runtime: (runtime: MockRuntime) => void;
76
+ /** A `Program` fake with its calls recorded for assertions. */
77
+ export interface MockProgram extends Program {
78
+ /** The arguments of each call, in order. */
79
+ readonly calls: Array<ReadonlyArray<string>>;
80
+ }
81
+ /**
82
+ * Create a fake `Program` for testing a helper that runs one.
83
+ *
84
+ * Each call is recorded on `calls`, then answered by `respond`; with no
85
+ * `respond`, every call exits 0 with empty output. `respond` may throw, as a
86
+ * program that can't start does.
87
+ *
88
+ * @param respond - the output for a call's arguments
89
+ * @returns the fake program
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const git = create_mock_program((args) =>
94
+ * args[0] === 'status' ? mock_program_exit(0, '', 'clean') : mock_program_exit(1, 'unknown')
95
+ * );
96
+ * assert.strictEqual((await git.out(['status'])).stdout, 'clean');
97
+ * assert.deepStrictEqual(git.calls, [['status']]);
98
+ * ```
99
+ */
100
+ export declare const create_mock_program: (respond?: (args: ReadonlyArray<string>) => ProgramOutput | Promise<ProgramOutput>) => MockProgram;
101
+ /** A `ProgramFactory` fake that hands out one program and records each environment asked for. */
102
+ export interface MockProgramFactory extends ProgramFactory {
103
+ /** The `env` of each call, in order. */
104
+ readonly envs: Array<Readonly<Record<string, string>>>;
105
+ /** The program every call returns — `null` for one that isn't installed. */
106
+ readonly program: MockProgram | null;
107
+ }
108
+ /**
109
+ * Create a fake `ProgramFactory` for testing a helper that makes its program
110
+ * with extra environment: every call records its `env` and returns `program`.
111
+ *
112
+ * @param program - the program to hand out, `null` for one that isn't installed
113
+ * @returns the fake factory
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const createdb = create_mock_program_factory();
118
+ * await create_database({createdb}, 'postgres://app:pw@localhost/app');
119
+ * assert.deepStrictEqual(createdb.envs, [{PGPASSWORD: 'pw'}]);
120
+ * assert.strictEqual(createdb.program?.calls.length, 1);
121
+ * ```
122
+ */
123
+ export declare const create_mock_program_factory: (program?: MockProgram | null) => MockProgramFactory;
124
+ /**
125
+ * A program output that exited with `code`.
126
+ *
127
+ * @param code - the exit code
128
+ * @param stderr - what the program wrote to stderr
129
+ * @param stdout - what the program wrote to stdout
130
+ */
131
+ export declare const mock_program_exit: (code: number, stderr?: string, stdout?: string) => ProgramOutput;
85
132
  /**
86
133
  * Set stdin buffer for simulating user input.
87
134
  *
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/runtime/mock.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAc,aAAa,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAK3F;;GAEG;AACH,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC/C,kCAAkC;IAClC,QAAQ,EAAE,GAAG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AKzE,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,WAAW,EAAE,OAAO,MAAM,KAAG,IAEpE,CAAC;AAEF;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM;CAKxB"}
@@ -8,6 +8,7 @@
8
8
  * @module
9
9
  */
10
10
  import { assert_secure_mode, assert_secure_size } from './secure_file.js';
11
+ import { assert_process_id } from './process_id.js';
11
12
  /**
12
13
  * Create a mock `RuntimeDeps` for testing.
13
14
  *
@@ -25,7 +26,6 @@ import { assert_secure_mode, assert_secure_size } from './secure_file.js';
25
26
  *
26
27
  * await some_function(runtime);
27
28
  *
28
- * assert.strictEqual(runtime.command_calls.length, 1);
29
29
  * assert.deepStrictEqual(runtime.exit_calls, [0]);
30
30
  * ```
31
31
  */
@@ -36,10 +36,8 @@ export const create_mock_runtime = (args = []) => {
36
36
  const mock_fs_modes = new Map();
37
37
  const mock_dirs = new Set();
38
38
  const exit_calls = [];
39
- const command_calls = [];
40
- const command_inherit_calls = [];
39
+ const mock_processes = new Map();
41
40
  const stdout_writes = [];
42
- const mock_command_results = new Map();
43
41
  const fetch_calls = [];
44
42
  const mock_fetch_responses = new Map();
45
43
  let stdin_buffer = null;
@@ -51,10 +49,8 @@ export const create_mock_runtime = (args = []) => {
51
49
  mock_fs_modes,
52
50
  mock_dirs,
53
51
  exit_calls,
54
- command_calls,
55
- command_inherit_calls,
52
+ mock_processes,
56
53
  stdout_writes,
57
- mock_command_results,
58
54
  fetch_calls,
59
55
  mock_fetch_responses,
60
56
  get stdin_buffer() {
@@ -75,6 +71,10 @@ export const create_mock_runtime = (args = []) => {
75
71
  exit_calls.push(code);
76
72
  throw new MockExitError(code);
77
73
  },
74
+ probe_process: (pid) => {
75
+ assert_process_id(pid);
76
+ return mock_processes.get(pid) ?? 'not_found';
77
+ },
78
78
  // === Local File System ===
79
79
  stat: async (path) => {
80
80
  const bytes = mock_fs_bytes.get(path);
@@ -307,30 +307,6 @@ export const create_mock_runtime = (args = []) => {
307
307
  }
308
308
  throw new TypeError(`fetch failed (no mock for ${url})`);
309
309
  },
310
- // === Local Commands ===
311
- run_command: async (cmd, args, options) => {
312
- command_calls.push(options ? { cmd, args, options } : { cmd, args });
313
- const key = `${cmd} ${args.join(' ')}`;
314
- const mocked = mock_command_results.get(key);
315
- if (mocked) {
316
- if (options?.timeout_ms !== undefined && mocked.timed_out === undefined) {
317
- return { ...mocked, timed_out: false };
318
- }
319
- return mocked;
320
- }
321
- const result = { success: true, code: 0, stdout: '', stderr: '' };
322
- if (options?.timeout_ms !== undefined)
323
- result.timed_out = false;
324
- return result;
325
- },
326
- run_command_inherit: async (cmd, args) => {
327
- command_inherit_calls.push({ cmd, args });
328
- const key = `${cmd} ${args.join(' ')}`;
329
- const mocked = mock_command_results.get(key);
330
- if (mocked)
331
- return mocked.code;
332
- return 0;
333
- },
334
310
  // === Terminal I/O ===
335
311
  stdout_write: async (data) => {
336
312
  stdout_writes.push(new TextDecoder().decode(data));
@@ -352,7 +328,7 @@ export const create_mock_runtime = (args = []) => {
352
328
  /**
353
329
  * Reset a mock runtime to initial state.
354
330
  *
355
- * @mutates runtime - clears all mock state (env, fs, dirs, exit/command/stdout/fetch call records, mock results, stdin buffer)
331
+ * @mutates runtime - clears all mock state (env, fs, modes, dirs, processes, exit/stdout/fetch call records, fetch responses, stdin buffer)
356
332
  */
357
333
  export const reset_mock_runtime = (runtime) => {
358
334
  runtime.mock_env.clear();
@@ -360,14 +336,78 @@ export const reset_mock_runtime = (runtime) => {
360
336
  runtime.mock_fs_bytes.clear();
361
337
  runtime.mock_dirs.clear();
362
338
  runtime.exit_calls.length = 0;
363
- runtime.command_calls.length = 0;
364
- runtime.command_inherit_calls.length = 0;
339
+ runtime.mock_fs_modes.clear();
340
+ runtime.mock_processes.clear();
365
341
  runtime.stdout_writes.length = 0;
366
- runtime.mock_command_results.clear();
367
342
  runtime.fetch_calls.length = 0;
368
343
  runtime.mock_fetch_responses.clear();
369
344
  runtime.stdin_buffer = null;
370
345
  };
346
+ /**
347
+ * Create a fake `Program` for testing a helper that runs one.
348
+ *
349
+ * Each call is recorded on `calls`, then answered by `respond`; with no
350
+ * `respond`, every call exits 0 with empty output. `respond` may throw, as a
351
+ * program that can't start does.
352
+ *
353
+ * @param respond - the output for a call's arguments
354
+ * @returns the fake program
355
+ *
356
+ * @example
357
+ * ```ts
358
+ * const git = create_mock_program((args) =>
359
+ * args[0] === 'status' ? mock_program_exit(0, '', 'clean') : mock_program_exit(1, 'unknown')
360
+ * );
361
+ * assert.strictEqual((await git.out(['status'])).stdout, 'clean');
362
+ * assert.deepStrictEqual(git.calls, [['status']]);
363
+ * ```
364
+ */
365
+ export const create_mock_program = (respond = () => mock_program_exit(0)) => {
366
+ const calls = [];
367
+ return {
368
+ calls,
369
+ out: async (args) => {
370
+ calls.push([...args]);
371
+ return respond(args);
372
+ }
373
+ };
374
+ };
375
+ /**
376
+ * Create a fake `ProgramFactory` for testing a helper that makes its program
377
+ * with extra environment: every call records its `env` and returns `program`.
378
+ *
379
+ * @param program - the program to hand out, `null` for one that isn't installed
380
+ * @returns the fake factory
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * const createdb = create_mock_program_factory();
385
+ * await create_database({createdb}, 'postgres://app:pw@localhost/app');
386
+ * assert.deepStrictEqual(createdb.envs, [{PGPASSWORD: 'pw'}]);
387
+ * assert.strictEqual(createdb.program?.calls.length, 1);
388
+ * ```
389
+ */
390
+ export const create_mock_program_factory = (program = create_mock_program()) => {
391
+ const envs = [];
392
+ const factory = (env) => {
393
+ envs.push({ ...env });
394
+ return program;
395
+ };
396
+ return Object.assign(factory, { envs, program });
397
+ };
398
+ /**
399
+ * A program output that exited with `code`.
400
+ *
401
+ * @param code - the exit code
402
+ * @param stderr - what the program wrote to stderr
403
+ * @param stdout - what the program wrote to stdout
404
+ */
405
+ export const mock_program_exit = (code, stderr = '', stdout = '') => ({
406
+ kind: 'exited',
407
+ code,
408
+ stdout,
409
+ stderr
410
+ });
371
411
  /**
372
412
  * Set stdin buffer for simulating user input.
373
413
  *