@unotest/viewer 0.31.0 → 0.33.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,291 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.33.0] - 2026-09-06
4
+
5
+ ### Minor Changes
6
+
7
+ - 5d1bde3: Run isolation, stage 1: a box no longer executes a test bundle inside its
8
+ own daemon.
9
+
10
+ box-runner (new, private): the run sidecar — the only service on a box
11
+ holding the docker socket, and the only one that starts a container. Three
12
+ authenticated routes on the `box` network (`POST /runs`, `GET
13
+ /runs/:id/stream` NDJSON, `DELETE /runs/:id`), a shared secret compared in
14
+ constant time, and an API that cannot be told anything about how a
15
+ container is built: no path, image, network, user, mount or flag. A request
16
+ names a project, an environment, a bundle, a scenario and the environment's
17
+ values; the bind sources are derived from the first three, resolved with
18
+ `realpath` and re-checked against the projects root, and must already
19
+ exist. The container is created over the Docker Engine API (pinned
20
+ `v1.43`) straight over the socket — no `docker` binary in the image and no
21
+ client dependency, and a container that is a JSON document has no place
22
+ for a value to become a flag. A daemon that refuses or is not there comes
23
+ back as `502 {reason}` before the run is accepted, or as an `error` event
24
+ on the stream after — never as a run that "exited with code null". An
25
+ environment variable the box does not forward is named in the sidecar's
26
+ log rather than dropped silently. A run gets the bundle tree read-only as its working directory, the
27
+ environment's `unotest/.runs.<env>` read-write, a `noexec` tmpfs `/tmp`,
28
+ a read-only rootfs, all capabilities dropped, `no-new-privileges`, its own
29
+ uid in boxd's group, memory/pids/cpu limits clamped to both the operator's ceilings and the
30
+ host's own size (docker refuses a container bigger than the machine
31
+ instead of clamping it), a 512 MB `/dev/shm`
32
+ (docker's default 64 MB kills Chromium mid-page; the host's IPC namespace
33
+ is deliberately not borrowed), and the `runs` network only. The container engine is an interface, so every rule is asserted on
34
+ the container that would have reached docker — including the cases where
35
+ the answer is no container at all.
36
+
37
+ boxd: running the SUITE is its own contract (`IScenarioRunner`), separate
38
+ from running a command (`ICommandRunner`, still the daemon's own `npm ci`
39
+ and viewers). `ContainerScenarioRunner` talks to the sidecar,
40
+ `ProcessScenarioRunner` keeps the old child-process shape for a box without
41
+ docker; `BOXD_RUNNER_KIND=container|process` chooses, and half a container
42
+ configuration refuses to start. Reading a bundle's schedules
43
+ (`unotest-web schedules --json`) executes the project's config module, so it
44
+ goes the same way. A run's environment is built from named parts
45
+ (`run-environment.ts`) instead of inheriting `process.env`, and its debug
46
+ tree is pointed at the run's own directory rather than the read-only
47
+ sources. New metrics
48
+ `boxd_run_container_total{outcome}` and `boxd_run_container_start_seconds`.
49
+ An environment's runs directory is created by the daemon with `2775`, so
50
+ the run's uid may write into it and the daemon's group may read it back.
51
+
52
+ box-kit: `secretsMatch` (constant-time secret comparison, moved out of
53
+ dist-service), `splitLines`, and `envNumber` / `envPositiveNumber` — the
54
+ env-reading rule the box-side services share.
55
+
56
+ `npm ci` of a bundle is a container of its own (`kind: "install"`): the
57
+ bundle tree is its only mount and it is writable, there is no environment
58
+ and no artifacts directory in reach, and a dependency's install scripts
59
+ RUN — a native module builds or fetches its binary as usual. That is what
60
+ running them inside the daemon could never allow. The container's last
61
+ steps, only on success, check the tree against the box's size cap, set
62
+ the final modes on what the install created and write the install marker
63
+ — each with an exit code of its own, so the daemon's log names the step
64
+ that failed — so a killed or oversized
65
+ install leaves a tree the box will not mount; a failed install takes the
66
+ tree with it. The daemon no longer passes `--ignore-scripts` and no
67
+ longer walks the tree afterwards.
68
+
69
+ The daemon runs with `umask 002` and clears `node_modules` before each
70
+ install, so a tree it created is one the install container (another uid
71
+ in its group) can actually write.
72
+
73
+ An install that fails KEEPS the tree, unmarked: nothing mounts it and the
74
+ next attempt reinstalls in place (`npm ci` wipes `node_modules` itself).
75
+ And a bundle directory holding a manifest with neither an archive nor a
76
+ tree behind it no longer counts as "this box has it" — a push of the same
77
+ content brings it back instead of being answered `already had this exact
78
+ bundle`.
79
+
80
+ web: `bundle push` and the docs say that a dependency's install scripts
81
+ run on a box, in isolation — the earlier advice to vendor them is gone.
82
+
83
+ A run ordered in the viewer now goes through the daemon's queue instead
84
+ of being spawned by the viewer.
85
+
86
+ `POST/GET/DELETE /api/box/envs/<project>/<env>/runs[/<runId>]` (paths and
87
+ wire types in `@unotest/protocol`) takes a `manual` ticket like every
88
+ other producer. Two callers may use it, and neither is taken on its word:
89
+ the guard, proving it is the guard with a shared secret from `box-init`
90
+ (the actor header is read only next to it — a viewer container could
91
+ otherwise claim to be any admin), and a viewer, with a per-environment
92
+ token the daemon minted when it started that viewer plus a short-lived
93
+ single-use ticket the guard signed over WHO clicked. The guard gates the
94
+ route under `admin` and requires an `Origin` on a mutation; the daemon
95
+ checks the token's environment, the ticket's environment and its `jti`
96
+ against the path.
97
+
98
+ `@unotest/viewer` gets `BoxdRunner`: on a box the Run button orders and
99
+ the Stop button asks the daemon, and the progress still comes from the
100
+ run's journal on disk. A local viewer spawns as it always did — the
101
+ composition root picks by whether a box handed it credentials.
102
+
103
+ - 348aba7: Run isolation, stage 2b and 3: an environment's viewer runs in a
104
+ container of its own, and a box ships the sidecar in its compose stack.
105
+
106
+ The viewer was the last thing on a box that executed a bundle's code next
107
+ to the daemon's state: it runs the UI, the language service and the
108
+ linter out of the bundle's own `node_modules`. It is now a container the
109
+ run sidecar starts and the daemon asks for — `POST /viewers`, one per
110
+ environment, addressed by a name both services derive
111
+ (`unotest-viewer-<project>-<env>-<8 hex>`, port 7788).
112
+
113
+ Each viewer gets a NETWORK of its own with exactly two other containers
114
+ attached: the guard, which proxies people at it, and the daemon, which it
115
+ orders runs from. Not the sidecar's network, not the runs network, and
116
+ above all not another viewer's — a viewer has no authentication of its
117
+ own, and two on one network would be two containers of untrusted code
118
+ with a route to each other. That network is INTERNAL: a viewer's server
119
+ makes no outbound call, so it gets none, while the network a run joins
120
+ stays open because a test drives an application. The name of a viewer and
121
+ its network is a function of the project/environment PAIR rather than of
122
+ the string they join to, so two environments whose names concatenate the
123
+ same way cannot end up sharing one. Its mounts are the bundle tree read-only and
124
+ the environment's `unotest/` read-write (the run history it renders and
125
+ the queue it withdraws tickets from); the environment's secrets and its
126
+ `current` link sit in the directory above and are mounted by nobody. Its
127
+ environment is assembled by the daemon — the target, the environment's
128
+ variables and secrets, its own credential — and the daemon's own
129
+ `process.env` no longer travels.
130
+
131
+ **Editing a suite's files from the viewer on a box no longer works**: the
132
+ sources are read-only there. Such edits never survived the next `bundle
133
+ push` anyway, which replaced the tree. Everything else in the UI is
134
+ unchanged.
135
+
136
+ Readiness is the docker daemon's own healthcheck, probed inside the
137
+ container and read through the sidecar — the daemon no longer waits on a
138
+ lock file, and nothing dials a viewer from the process holding the docker
139
+ socket. A viewer's output is streamed into the daemon's log and
140
+ reattached when the stream drops. A container whose bundle and values
141
+ still match is ADOPTED across a restart of either service, keeping the
142
+ credential it was born with; one whose environment is gone is stopped,
143
+ with its network and its token. The sidecar recognises its own containers
144
+ by label, never by name alone, and enforces its own ceiling on how many
145
+ viewers may exist (`BOX_RUNNER_MAX_VIEWERS`) — boxd knows how many
146
+ environments there are right up until boxd is the thing that was
147
+ compromised.
148
+
149
+ A run somebody stopped now ENDS in the viewer instead of hanging.
150
+ Stopping a run stops its container gracefully (SIGTERM, then SIGKILL
151
+ after `BOX_RUNNER_STOP_GRACE_SECONDS`, default 10) so the suite writes
152
+ the terminal event of its own journal; if it could not — the grace ran
153
+ out, the machine died — the daemon appends it. The same grace applies to
154
+ a run killed on its timeout, so a run's budget is the timeout plus the
155
+ grace.
156
+
157
+ A viewer that dies is noticed in about a second and replaced: the log
158
+ stream the daemon holds open ends with the container, and the 404 that
159
+ answers its immediate reattach is the signal. The route comes out of the
160
+ table at once — the guard then says the environment has no viewer instead
161
+ of proxying at a dead address — and a fresh container is started, on the
162
+ same backoff the daemon uses for everything else it cannot reach.
163
+
164
+ A restart of the sidecar is no longer an outage. While it cannot be
165
+ reached the daemon keeps the routes it published (the viewer containers
166
+ are up, and the guard reaches them directly) and tries again with a short
167
+ backoff instead of waiting for its next five-minute sweep. Editing a file
168
+ in the viewer on a box now answers 403 with the reason — the sources are
169
+ read-only there — rather than a blank 500.
170
+
171
+ The viewer no longer collapses the daemon's refusals into a blank 500:
172
+ the box's own status and reason reach the browser, so "that click has
173
+ already been used" (409), "the box cannot verify the caller" (503) and
174
+ "the box daemon is not answering" (503) are told apart by the person who
175
+ clicked.
176
+
177
+ Deployment: `compose.yaml` gains the `runner` service (the only holder of
178
+ the docker socket, the release ships its bundled `box-runner.mjs` beside
179
+ `boxd.mjs`), fixed container names for the guard and the daemon, a
180
+ `box_secrets` volume whose secrets `box-init` generates, and a one-off
181
+ migration of the projects tree to the group layout an install container
182
+ needs. Two values an operator fills in: `BOX_PROJECTS_HOST_DIR` (a bind
183
+ source is resolved by the docker daemon on the host) and `BOX_DOCKER_GID`.
184
+ Step by step in `docs/manuals/box-run-isolation-cutover.md`.
185
+
186
+ ### Patch Changes
187
+
188
+ - 9158968: Viewer: a run that started before the page was reloaded is shown again.
189
+
190
+ The live sidebar was rebuilt from WebSocket events only, and those speak
191
+ from the moment the page connects — a collection already in progress
192
+ never re-sent its `started` event, so after a reload it was missing from
193
+ ACTIVE, then reappeared nameless with no scenario list once its next
194
+ scenario began, while its children showed up one by one. On load, and on
195
+ an environment or target switch, the viewer now asks the server which
196
+ runs are live and replays each one's journal into the same state the
197
+ live stream feeds, so a reload mid-run shows the collection with its
198
+ name, scenarios and progress.
199
+
200
+ - b3e1220: Viewer: a session that may not edit variables does not see credential-shaped
201
+ values, nor the project's absolute path.
202
+
203
+ Behind the guard, a readonly session could read `GET /api/variables` and
204
+ get every box variable's value — `PASSWORD=…` included when the operator
205
+ had pushed it as a variable rather than a secret. The viewer now reads the
206
+ capabilities the guard stamps on each request: when the caller cannot edit
207
+ variables, a value whose name matches `PASSWORD | PASSWD | SECRET | TOKEN |
208
+ KEY | CREDENTIAL` is sent empty and flagged `secret`, and `GET /api/targets`
209
+ leaves out `projectRoot`. Display-masking by capability, not authorization —
210
+ a viewer without a proxy in front is unchanged, and the guard still refuses
211
+ every write.
212
+
213
+ - bd6b7ba: Viewer: a collection run no longer shows up nameless and without scenarios.
214
+
215
+ The journal tailer moved its cursor to the end of the file even when the
216
+ last line was still being written, so the half already on disk was lost
217
+ and the other half was later read as garbage. The longest line in a
218
+ journal is `collection-run:started` with the scenario list, so that was
219
+ the one it usually caught: the run appeared under its id instead of its
220
+ collection name, with "collection has no scenarios" and a `2/0 done`
221
+ counter. The cursor now stops at the last complete line and the rest is
222
+ read on the next change.
223
+
224
+ - 8846a06: Viewer: a run started the moment the viewer came up is shown, not lost
225
+ until the next change.
226
+
227
+ Watching a directory becomes live a moment after the watcher reports it
228
+ is ready, and a run directory created inside that gap was not merely
229
+ late — it was invisible until something else changed in the same day,
230
+ which in a quiet environment is the next run. Measured at 1-3% on macOS
231
+ with a busy machine, and the window is exactly "open the viewer, start a
232
+ run". The viewer now proves the watch delivers before it declares itself
233
+ up: it creates a directory of its own and waits to hear about it, so
234
+ boot completes on evidence rather than on a promise. A tree it cannot
235
+ write to, or a probe that never comes back, costs a warning in the log
236
+ and boots as before.
237
+
238
+ A directory whose name starts with a dot is never reported as a run — an
239
+ editor's leftovers, or the watcher's own probe, can no longer appear in
240
+ the run list as a phantom.
241
+
242
+ Run queue: a waiter whose process paused is no longer mistaken for dead
243
+ — the queue stamps its own files with its own clock.
244
+
245
+ A run waiting for a slot proves it is alive by touching its ticket, and
246
+ what it is judged against was the modification time the filesystem
247
+ wrote: on a network share that is the server's clock, and against a
248
+ machine busy enough to keep a process off the CPU, a ticket written a
249
+ moment ago could look like it belonged to a process that died. The queue
250
+ now stamps every file it creates with the same clock it judges them by.
251
+
252
+ - Updated dependencies [2abfd4d]
253
+ - Updated dependencies [b3e1220]
254
+ - Updated dependencies [b3e1220]
255
+ - Updated dependencies [5d1bde3]
256
+ - Updated dependencies [8846a06]
257
+ - @unotest/protocol@0.33.0
258
+ - @unotest/core@0.33.0
259
+ - @unotest/dsl@0.33.0
260
+
261
+ ## [0.32.0] - 2026-09-05
262
+
263
+ ### Minor Changes
264
+
265
+ - 442fadf: `npx @unotest/web box …` reads a box's results from a terminal: `box envs` lists the environments a read token may look at, `box runs` their history (`--latest` collapses it to one line per scenario with its failing streak), `box run <id>` explains one run — the failure, the soft steps, the judge's verdicts — `box queue` shows who is waiting, and `box screenshot` saves a frame the run captured.
266
+
267
+ `box run --download` fetches the run's `*.unotest.zip` into `.unotest/box/` and unpacks its failure bundle into `.unotest/failures/`, where `list_failures`, `get_failure_*` and `agent_fix` already look — so a run that failed on a box is debugged with the commands a local failure is. `--no-screenshots` asks the box itself to leave the step frames out (`GET /api/runs/:id/export?screenshots=0`), which is what makes the download smaller rather than only the disk.
268
+
269
+ Reading needs a personal read token in `UNOTEST_BOX_READ_TOKEN`; the project's `UNOTEST_BOX_TOKEN` still pushes bundles and values and cannot read runs.
270
+
271
+ The viewer publishes its archive reader as `@unotest/viewer/snapshot`, so the three places that open a `*.unotest.zip` — its server, its browser bundle and now the CLI — share one implementation and one message for a file that is not an archive.
272
+
273
+ - 442fadf: `BoxReadClient` reads a box's runs — environments, run history, one run's whole journal, a collection's children, the queue, a run's export zip and its individual artifacts — over the same HTTP routes a browser uses, authenticated with the personal read token in `UNOTEST_BOX_READ_TOKEN`. Every refusal arrives as a typed `BoxReadError` whose `kind` says what to do next, so throttling is never mistaken for a rejected token and a live run's export says "wait" rather than looking like a broken box. Configuration mistakes surface when a read is attempted rather than at startup, so a stale token in a project's `.env` cannot stop a local run that never touches a box.
274
+
275
+ The viewer gains a `@unotest/viewer/wire` entry point exporting its HTTP contract types (the runs page, a run's full snapshot, the queue payload and the snapshot manifest), so a client can name the shapes it parses instead of keeping a second copy of them.
276
+
277
+ ### Patch Changes
278
+
279
+ - 8aa0f30: Protocol contract for reading a box's run results with a personal read token: `UNOTEST_BOX_READ_TOKEN` (distinct from the project's `UNOTEST_BOX_TOKEN`, which stays a write credential for bundles and environment values), the `X-Unotest-Environment: <project>/<environment>` header every bearer request names its own environment with, the `/_guard/api/envs` listing and its `BoxReadEnvironment` entry, and typed refusals (`unauthorized`, `forbidden`, `unknown-environment`, `not-found`, `rate-limited`, `run-in-progress`, `unavailable`, `malformed`) with parsers that reject anything that is not a box answering. Throttling gets a code of its own rather than an `unauthorized` carrying `Retry-After`: a rejected token means mint a new one, a throttled one means wait and resend the same one. The viewer's `ViewerEnvOption` is now that same protocol type rather than a second copy of it. An environment whose viewer is still starting — the common state right after a bundle push — answers `unavailable` rather than looking like an unreachable box, so the advice is to wait rather than to check the address.
280
+ - 8aa0f30: A run exported as `*.unotest.zip` now carries everything needed to diagnose it away from the machine that produced it: `stdout.log` and `stderr.log` (previously dropped, which left the one artifact that explains a runner crash outside the bundle), the failing page's `page.html` reachable through the manifest, and the run's step screenshots — declared in a new `manifest.screenshots` list, because an importer keeps only what the manifest names and a frame absent from it did not survive the round trip.
281
+ - Updated dependencies [8aa0f30]
282
+ - Updated dependencies [047ca68]
283
+ - Updated dependencies [047ca68]
284
+ - Updated dependencies [047ca68]
285
+ - @unotest/protocol@0.32.0
286
+ - @unotest/dsl@0.32.0
287
+ - @unotest/core@0.32.0
288
+
3
289
  ## [0.31.0] - 2026-09-04
4
290
 
5
291
  ### Minor Changes
@@ -1,5 +1,17 @@
1
1
  import { IRunnerAdapter, IDslLanguageService, IProcessLauncher } from '@unotest/protocol';
2
2
 
3
+ /** What a BOX handed this viewer so it can order runs from the daemon
4
+ * instead of spawning them itself. Present only there: a local viewer
5
+ * owns its runs, and a box's viewer owns none. */
6
+ interface ViewerBoxConfig {
7
+ /** The daemon, on the box's own network — never a public address. */
8
+ readonly daemonUrl: string;
9
+ /** This viewer's own credential, minted when it started. It says WHICH
10
+ * environment is asking; who clicked is a separate, signed claim. */
11
+ readonly token: string;
12
+ readonly project: string;
13
+ readonly environment: string;
14
+ }
3
15
  interface BoxInjectedNames {
4
16
  /** Non-secret: the viewer has their values in its own environment. */
5
17
  readonly variables: readonly string[];
@@ -82,6 +94,14 @@ declare function startViewerServer(opts: StartViewerOptions): Promise<ViewerHand
82
94
  /** The box's injected-variable names, when a box supervisor set them.
83
95
  * Both lists come together or not at all; an environment with no secrets
84
96
  * still has a target URL, so "set" means the variables list is present. */
97
+ /** The credentials a BOX hands its viewer so it can order runs from the
98
+ * daemon: where the daemon is, this viewer's own token, and which
99
+ * project and environment it speaks for. All four or nothing — a token
100
+ * with no address is a viewer that cannot ask, and an address with no
101
+ * token is one that will be refused, and neither is a shape a box ever
102
+ * produces. A local viewer has none of them and spawns its own runs, as
103
+ * it always did. */
104
+ declare function boxRunnerFrom(env: NodeJS.ProcessEnv): ViewerBoxConfig | undefined;
85
105
  declare function boxInjectedFrom(env: NodeJS.ProcessEnv): BoxInjectedNames | undefined;
86
106
  /** Everything the standalone launcher reads from its environment, in one
87
107
  * pure place so the plumbing is testable without starting a server.
@@ -93,4 +113,4 @@ declare function boxInjectedFrom(env: NodeJS.ProcessEnv): BoxInjectedNames | und
93
113
  declare function viewerCliOptions(env: NodeJS.ProcessEnv, cwd: string): Omit<StartViewerOptions, "runners">;
94
114
  declare function runViewerCli(): Promise<void>;
95
115
 
96
- export { type RunnerEntry, type StartViewerOptions, type ViewerHandle, boxInjectedFrom, runViewerCli, startViewerServer, viewerCliOptions };
116
+ export { type RunnerEntry, type StartViewerOptions, type ViewerHandle, boxInjectedFrom, boxRunnerFrom, runViewerCli, startViewerServer, viewerCliOptions };