@fusion.dev/helix-cli 0.200.0 → 0.201.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 (2) hide show
  1. package/package.json +6 -6
  2. package/visual/README.md +56 -15
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fusion.dev/helix-cli",
3
3
  "description": "The Helix command line, for a workspace that reaches it through npm, and the visual tests it runs.",
4
- "version": "0.200.0",
4
+ "version": "0.201.0",
5
5
  "license": "MIT",
6
6
  "author": "Ross Sheppard <ross.sheppard@fusion.dev>",
7
7
  "repository": {
@@ -41,11 +41,11 @@
41
41
  "visual-regression"
42
42
  ],
43
43
  "optionalDependencies": {
44
- "@fusion.dev/helix-cli-darwin-arm64": "0.200.0",
45
- "@fusion.dev/helix-cli-darwin-x64": "0.200.0",
46
- "@fusion.dev/helix-cli-linux-arm64": "0.200.0",
47
- "@fusion.dev/helix-cli-linux-x64": "0.200.0",
48
- "@fusion.dev/helix-cli-win32-x64": "0.200.0"
44
+ "@fusion.dev/helix-cli-darwin-arm64": "0.201.0",
45
+ "@fusion.dev/helix-cli-darwin-x64": "0.201.0",
46
+ "@fusion.dev/helix-cli-linux-arm64": "0.201.0",
47
+ "@fusion.dev/helix-cli-linux-x64": "0.201.0",
48
+ "@fusion.dev/helix-cli-win32-x64": "0.201.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@anthropic-ai/sdk": ">=0.132",
package/visual/README.md CHANGED
@@ -25,6 +25,8 @@ helix visual test compare every shot, and fail on a differenc
25
25
  helix visual test button only the entries named button
26
26
  helix visual update write only the baselines the comparison rejects
27
27
  helix visual update --boxes also write element boxes into baselines that have none
28
+ helix visual accept write the last test's captures into the baselines
29
+ helix visual accept --run 123 the same from a GitHub Actions run, downloaded with gh
28
30
  helix visual test --shard 0 --of 4 the first of four shards, for CI
29
31
  helix visual report open the report of the last run
30
32
  helix visual report --merge a b the groups of several shards' reports as one
@@ -41,6 +43,19 @@ helix visual compare a.png b.png compare two PNG files, with no browser
41
43
  `--boxes` also writes the element boxes into each matching baseline that has
42
44
  none, inside its own PNG, leaving its pixels as they are, so the run can say
43
45
  how far a changed element moved.
46
+ - **`helix visual accept`** writes the capture of each shot a `test` failed into
47
+ the baseline it failed against, and the accessibility snapshot of each entry
48
+ whose snapshot changed. It reads the report the run left, `.helix/visual`
49
+ unless you name report directories, so nothing is pictured again and each
50
+ baseline is the picture the report showed. `--run` takes a GitHub Actions
51
+ run by its ID or the address of its page, downloads its `visual-*`
52
+ artifacts with the [GitHub CLI](https://cli.github.com), and accepts every
53
+ report in them. Use it when your machine cannot take baselines, such as a
54
+ Mac when the baselines are taken on Linux: push, let CI fail, and accept the
55
+ run. It refuses a run of a commit other than the one checked out, because
56
+ those captures show other code, unless you pass `--any-commit`. A shot that
57
+ could not be taken has no capture, and is named. Review the files it writes
58
+ before you commit them.
44
59
  - **`helix visual report`** opens the report the last run wrote. `--markdown` prints
45
60
  its summary as Markdown instead, for a CI job's summary page. `--merge`
46
61
  takes the reports of a run's shards, each a report directory or its
@@ -62,8 +77,9 @@ once, and `--shard` with `--of` takes one shard of a run split across jobs.
62
77
 
63
78
  `helix --json visual …` prints one JSON document on stdout and moves the
64
79
  sentences to stderr: `test` and `update` print the run's record, the same as
65
- the report's `run.json`, `report` prints the last one, and `compare` prints
66
- whether the two pictures match and how many pixels differ.
80
+ the report's `run.json`, `report` prints the last one, `accept` prints what it
81
+ wrote and what it left, and `compare` prints whether the two pictures match and
82
+ how many pixels differ.
67
83
 
68
84
  ## The config
69
85
 
@@ -275,6 +291,11 @@ It lists the shots that needed a second take, the exceptions with their
275
291
  measurements, and what was skipped. The directory is emptied at the start of
276
292
  each run.
277
293
 
294
+ For each failed shot, `run.json` names the capture in the report and the file
295
+ its baseline is kept in, relative to the top of the git repository. It also
296
+ names the commit the run pictured, and on GitHub Actions the run's page. That
297
+ is what `helix visual accept` reads, in this checkout or in another one.
298
+
278
299
  ## The GitHub Action
279
300
 
280
301
  The Action lives in the Fusion repository, in `helix/visual/action`.
@@ -293,6 +314,17 @@ The Action lives in the Fusion repository, in `helix/visual/action`.
293
314
  App or a person: a pull request opened with `GITHUB_TOKEN` starts no checks.
294
315
  Run it on `workflow_dispatch` only, with `concurrency` set to queue and never
295
316
  cancel, so a retake is asked for and never cut in half.
317
+ - **`mode: accept`** runs `helix visual accept --run` on the check run named by
318
+ `run`, and delivers what it wrote the way a retake does. It installs no
319
+ browser. The job needs `permissions: actions: read` to download the run's
320
+ artifacts.
321
+ - **`push: true`** commits a retake or an accept onto the branch the workflow
322
+ ran on, with `token`, and comments on the branch's open pull request with the
323
+ files it changed. Your pull request then shows each changed picture, and its
324
+ checks run again on the push. The default branch always gets a pull request.
325
+ A branch that moved after the workflow started is refused, because the
326
+ pictures show the commit before it. Check out `ref: ${{ github.ref }}` so a
327
+ queued run starts from the branch as it is.
296
328
 
297
329
  `args` passes arguments to `helix visual`, such as `--config` or `--shard`.
298
330
  `helix` and `playwright` name the commands that run each,
@@ -308,13 +340,14 @@ The Action lives in the Fusion repository, in `helix/visual/action`.
308
340
 
309
341
  ## Review on the pull request
310
342
 
311
- A workflow can let a reviewer retake the entries they have looked at with a
312
- comment, using only the retake workflow you already run. This one takes
343
+ A workflow can let a reviewer accept or retake baselines with a comment, using
344
+ only the baselines workflow you already run. This one takes `/accept` and
313
345
  `/retake styled/badge site/home` from anyone who can push, on a branch of the
314
- repository, and dispatches the retake there:
346
+ repository. `/accept` finds the last finished check run of the pull request's
347
+ head commit and accepts its captures. `/retake` takes the entries named again.
315
348
 
316
349
  ```yaml
317
- name: Retake on request
350
+ name: Baselines on request
318
351
  on:
319
352
  issue_comment:
320
353
  types: [created]
@@ -323,8 +356,8 @@ permissions:
323
356
  contents: read
324
357
  pull-requests: write
325
358
  jobs:
326
- retake:
327
- if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/retake') && contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) }}
359
+ baselines:
360
+ if: ${{ github.event.issue.pull_request && (startsWith(github.event.comment.body, '/retake') || startsWith(github.event.comment.body, '/accept')) && contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) }}
328
361
  runs-on: ubuntu-latest
329
362
  steps:
330
363
  - env:
@@ -333,23 +366,31 @@ jobs:
333
366
  GH_TOKEN: ${{ github.token }}
334
367
  NUMBER: ${{ github.event.issue.number }}
335
368
  run: |
336
- head=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER" --jq .head.ref)
369
+ pr=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$NUMBER")
370
+ head=$(jq -r .head.ref <<<"$pr")
371
+ if [ "$(head -n 1 <<<"$BODY" | awk '{ print $1 }')" = /accept ]; then
372
+ run=$(gh run list --workflow visual.yml --commit "$(jq -r .head.sha <<<"$pr")" --status completed --limit 1 --json databaseId --jq '.[0].databaseId // empty')
373
+ [ -n "$run" ] && gh workflow run visual-baselines.yml --ref "$head" -f run="$run"
374
+ exit 0
375
+ fi
337
376
  entries=$(head -n 1 <<<"$BODY" | sed 's#^/retake##' | tr -s ' ' '\n' | grep -E '^[a-z0-9-]+(/[a-z0-9-]+)?$' | tr '\n' ' ')
338
377
  gh workflow run visual-baselines.yml --ref "$head" -f entries="$entries"
339
378
  ```
340
379
 
341
- It dispatches a `visual-baselines.yml` that runs the Action with
342
- `mode: retake` and passes an `entries` input in `args`. Read the comment from
343
- the environment, as this does, and never paste it into a command. The retake opens its own pull request into the branch, which is
344
- where the pictures are looked at before they land.
380
+ It dispatches a `visual-baselines.yml` that runs the Action with `push: true`,
381
+ in `mode: accept` when it is given a `run` input and in `mode: retake` with an
382
+ `entries` input in `args` otherwise. `visual.yml` is the workflow that runs
383
+ your checks. Read the comment from the environment, as this does, and never
384
+ paste it into a command. The baselines land on the pull request's branch, and
385
+ the pull request is where the pictures are looked at before they merge.
345
386
 
346
387
  ## How it works
347
388
 
348
389
  - **Local-first.** `helix visual` runs on your machine and in your CI. It needs no
349
390
  hosted service, and no picture leaves your machine unless you turn that on.
350
391
  - **Baselines in git.** Each baseline is a file in your repository. A retake
351
- writes only the pictures the comparison rejects, and the pull request that
352
- carries them is where you review the change.
392
+ or an accept writes only the pictures the comparison rejects, and the pull
393
+ request that carries them is where you review the change.
353
394
  - **Three shots by default.** A wide width, a phone width, and the dark color
354
395
  scheme, each compared to its own baseline.
355
396
  - **The environment is part of the baseline.** The browser version, the