diff --git a/WIP.Screenshots.md b/WIP.Screenshots.md index 5ad94df16..258f1e44a 100644 --- a/WIP.Screenshots.md +++ b/WIP.Screenshots.md @@ -273,9 +273,7 @@ Exit codes: 0 every picture written or unchanged, 1 a picture failed, 2 the tool Added and deleted PNGs, one beyond noise, and one whose SVG alone changed are left alone. `--dry-run` lists; the IDE options (`--ide`, `--jobs`, `--svg`, `--bundles`, `--diffs`, `--against-disk`) are refused with it. One noise rule: the capture's `nearly`, `--cleanup` - and `sheet.mjs --against`'s within-noise section all call `withinNoise` - (`scripts/lib/shot-change.mjs`), and the sheet shows the `--cleanup` command beside its - `git checkout` one. On the BETA 1033 retake its dry run puts back none of the 329 modified + and the review tool all call `withinNoise` (`scripts/lib/shot-change.mjs`). On the BETA 1033 retake its dry run puts back none of the 329 modified pictures. - **Setups**: one IDE each --- `no-project` (menus, dialogs, panels), `help` (the add-in's nine, `test/addin/helpdemo`), `project`, `sample`, the `settings` setups, `glyphs`, `global-search` @@ -1147,33 +1145,6 @@ the PNG was just captured from, and the build shows it in place of the PNG which is what the filter's own merge paints. One SVG serves screen and book, since the bake is exact. Blurred shadows stay bitmaps in the PDF, which loses nothing. -- **The sheet of the pictures with no SVG** (owner): `scripts/svgshot/sheet.mjs --out ` - writes `index.html` and a `pictures/` folder, openable from `file://`: each PNG with no SVG - beside it (`--all`: every PNG) that has a bundle is drawn again and judged as replay does, - worst first, PNG, render and difference map side by side; then the ones with no bundle as - thumbnails. A bundle whose PNG has changed is drawn anyway, with a note (`redraw`'s `stale`). - The sheet is for the owner alone, so it is drawn with `checkUserName: false` and may show the - user name (owner); `outputRefusal` keeps it out of `docs/` and out of any path git does not - ignore, and an existing folder must hold an earlier sheet. What it shares with replay is - `scripts/svgshot/redraw.mjs` (`redraw`, `writeJudged`, `runShards`/`inBrowser`, the - `judgedFiles` names: `.svg-diff.png` and `.svg` as `--diffs` names them); its pages are - `scripts/svgshot/sheets.mjs`, made of the pieces in `scripts/lib/shot-views.mjs`. - `shoot_docs.mjs --diffs` is to call `sheetHtml` over its diffs folder in a later commit. - A sheet of the pictures with no SVG takes seconds; `--all`, over some 550 pictures, about a - minute. -- **The sheet of changes against a revision** (owner): `sheet.mjs --out --against ` - reviews what a screenshot run rewrote: each PNG under `--docs` that git (run in that folder, - so its repository answers) reports changed against the revision, working tree against commit, - untracked PNGs added, as old / new / difference map (`scripts/lib/shot-change.mjs`; sizes that - differ are compared aligned at the top left, the map shows the larger). Order: changed, most - changed first (share of pixels more than 16 levels off); then the pictures within the noise - rule (`withinNoise`, the rule `shoot_docs.mjs` moved there: 16 levels, 0.5% of the pixels), - which shoot_docs never writes over a file, so they are most likely rewritten in error (owner), - with one `git checkout -- ` and the `shoot_docs.mjs --cleanup` command, which the - page only shows; then added, then deleted. The revision's pictures are read in one `git - cat-file --batch` (`readRevisionFiles`, `scripts/lib/shot-revision.mjs`). PNG - against PNG, no browser: 337 pictures in about 30 s. On the BETA 1033 retake none was within - noise. - **The bar** (`SVG_FAITHFUL` in `scripts/lib/shot-policy.mjs`): an SVG with more than 0.25% of its pixels 96 grey levels or more off is not written, and an older one is removed. Anything not drawn falls to it. A picture's entry in `test/shots/manifest.json` can move it, to any level and share, diff --git a/WIP.ShotReview.md b/WIP.ShotReview.md index bb95b11de..4ab2d580e 100644 --- a/WIP.ShotReview.md +++ b/WIP.ShotReview.md @@ -5,14 +5,14 @@ picture, overriding it, starting retakes and replays, and committing the result. agreed with the owner on 2026-10-31; all nine steps of [the order of work](#order-of-work) are done: the tool runs as `node scripts/shot_review.mjs`, applies each verdict under `docs/` as it arrives, takes a review's decisions and allowances, starts and stops its runs from its runs -page, and commits the session's own files from its commit page; `sheet.mjs` judges and shows -each picture's allowances; the tool is documented in `Tools-IDE.md` and its tests are a gate of -`test.bat`.** The mockups it was agreed +page, and commits the session's own files from its commit page; the tool is documented in +`Tools-IDE.md` and its tests are a gate of `test.bat`.** The mockups it was agreed on were inline in that session and are not kept: the pages are described below instead. The tool covers everything the command-line screenshot tools do, interactively, with a person -deciding where a threshold cannot (owner). The command-line tools stay, and both reach the -same result for the same inputs: see [Factoring](#factoring). +deciding where a threshold cannot (owner). The tools that take and draw the pictures stay, and +both reach the same result for the same inputs: see [Factoring](#factoring). The tool's pages are +the one place to look at the pictures: there is no static page of them (owner, 2026-11-06). ## Why @@ -55,8 +55,7 @@ Two decisions are made by fixed thresholds, and neither threshold holds for ever - **A capture that differs from one already decided goes back to the queue**, showing the last decision, instead of having that decision applied to it. - **The queue is persistent**, with backward and forward navigation; an overview page shows - every picture at once, as the `sheet.mjs --against` page does, and opens a detail page for - any of them; the detail page moves backward and forward through the queue. + every picture at once, and opens a detail page for any of them; the detail page moves backward and forward through the queue. - **The tool starts and stops its own retakes and replays**, and their results show as they arrive. A picture can be decided as soon as it arrives, while the run goes on. - **Which build a picture was taken on is recorded**, in a committed manifest. @@ -72,10 +71,7 @@ Two decisions are made by fixed thresholds, and neither threshold holds for ever 2026-10-31), so that a page's and a picture's address can be kept; not a port from `tbbroker`. - **The overview also lists the pictures under `docs/` that differ from the baseline but that no run of the session reported** (a retake from a terminal, an edit), as a group of their own - (owner, 2026-10-31): HEAD's picture against the file, with no verdict to override. The - overview then covers what `sheet.mjs --against` covers. -- **The static sheets show a picture's allowances** (owner, 2026-10-31), as the overview does: - `sheet.mjs` reads the manifest, as the command-line tools already do. + (owner, 2026-10-31): HEAD's picture against the file, with no verdict to override. - **When HEAD moves under an open session** (a commit made outside the tool), the session keeps its baseline and the overview warns, as step 5 does; and the overview offers to **move the session to the new HEAD on demand** (owner, 2026-10-31). Moving makes the new HEAD the @@ -114,8 +110,7 @@ has it). Grouped, in this order: 9. **Failed**. A row of counts at the top, filters (all, needs a look, overridden, no SVG), and **Resume at -*n* of *m*** to go back to where the queue was left. The two pages of `sheet.mjs` become views -of this one: `--against` is the overview itself, the pictures with no SVG a filter. +*n* of *m*** to go back to where the queue was left. ### All pictures @@ -134,6 +129,15 @@ bundles**, a replay with `--recheck` of those with a bundle: option 2 on demand. picture's page of verdicts when the session has one, else a plain page: the baseline's picture, the file, its SVG, why it has none, and Retake and Replay, previous and next in this page's order. +**The images no shot takes** (owner, 2026-11-06) are on the page too, in a group *No automated +capture*, before the collapsed *With an SVG*: every image under docs (`imagesUnder`) that is not a +shot's PNG, SVG or light picture. They are there to look at: a card has no selection, and the plain +page has no run, no chip of a build, no size, and shows the file at its own size (a shot is 2x and +is shown at half), the baseline's copy only when it differs. Left out (`NOT_LISTED`, owner): what a +script makes, a diagram's SVG beside its DOT, the build's Gantt chart and a video's poster frame, +and the favicon. The file routes and the plain page take any image type; a review's actions still +take only a PNG or an SVG (`isDocsPath`). + ### Detail One picture: previous and next (in the order of the overview, within the filter it was opened @@ -375,7 +379,6 @@ and the writes are inline in `shoot_docs.mjs` (`keep`, `keepSvg`, `restoreSvg`, | Writing a verdict | `keep`, `keepSvg`, `restoreSvg`, `dropLight` in `shoot_docs.mjs`; `replay` in `replay.mjs` | `applyPicture` / `applySvg` in a new `scripts/lib/shot-apply.mjs` (PNG, SVG, bundle, the SVG going back with its PNG through `svgFate`), called by `shoot_docs.mjs`, `replay.mjs`, `--cleanup` and the tool | | How far an SVG is off | `diff.mjs` counts pixels at 8, 32 and 96 levels in the page | also returns the strength map (a byte per pixel, the one-pixel shift allowed), from which any level's share, rectangles left out and regions are worked out in Node, without drawing again; `pct8`/`pct32`/`pct96` derived from it | | Regions | none | `changeRegions(strength, {level, close, erode, rects})` in `shot-change.mjs`, for PNG and SVG alike | -| The sheets' HTML | `sheetHtml`, `changeSheetHtml` and their pieces in `redraw.mjs` | the pieces (card, figure, meter, page) in a views module shared by `sheet.mjs` and the tool; a static sheet is the overview without its actions | | `redraw.mjs`'s other contents | git change listing (`changedPictures`, `parseNameStatus`, ...) beside drawing | the git listing to `shot-revision.mjs`; `redraw.mjs` keeps drawing and the shards | | A child's report | `reportShard` / `runShards`, the `@@svgshot-result` line | one module for the prefixed-line protocol, used by the shards and by `--events` | | Server-sent events | `sseHandler` inside `builder/serve.mjs` | lifted to `lib/`, used by `serve.mjs` and the tool | @@ -392,7 +395,7 @@ uses it. `shoot_docs.mjs` cannot run in a gate, so a move is checked by its test Each step ends tested and usable on its own. 1. **The moves**, no behaviour changed: the table's *After* column, with `shoot_docs.mjs`, - `replay.mjs` and `sheet.mjs` calling the shared modules. Done (the commit helper with step + `replay.mjs` calling the shared modules. Done (the commit helper with step 8): see [Where the work stands](#where-the-work-stands). 2. **The manifest**: read and written by one module; `shoot_docs.mjs` and `replay.mjs` judge with its allowances, honour its decisions and record `build`. Done. @@ -405,7 +408,7 @@ Each step ends tested and usable on its own. the session to a new HEAD ([Decisions](#decisions-owner)). Done. 7. **The runs page**: retake, replay, clean up, stop. Done. 8. **The commit panel**. Done. -9. **`sheet.mjs` on the shared views**, showing each picture's allowances; the tool's entry in `Tools-IDE.md`, its node in +9. **The documentation**: the tool's entry in `Tools-IDE.md`, its node in `Tools-Groups.dot` (its command-line cases are in `scripts/lib/cli-cases.mjs` since step 5), its tests in `test.bat` (and so in Tools.md's list and the `run-gates` action), and the row in WIP.md's *Which file to open*. Done. @@ -428,7 +431,7 @@ On `staging` since 2026-10-31, steps 1 to 9. Each move kept the command-line too | Writing a verdict | `scripts/lib/shot-apply.mjs`: `applyPicture(outRoot, out, decision, revision, {svg, bundlesRoot})` (for "dark", with `svg`, and for "once", the light file's SVG and bundle go too, through `dropPicture`: the "dark" verdict's two calls of step 5 made one), `applySvg(outRoot, svgOut, svg or null)`, `restorePictures(outRoot, revision, outs, {dryRun})` (the PNGs and their SVGs, the SVGs by one `git restore`; `--cleanup` and a `restored` picture both use it), `dropPicture(outRoot, out, bundlesRoot)`, `writeSvg`, `svgOf`. What stays in `shoot_docs.mjs`'s `keep` and `keepSvg`: the counts, the lines it prints, the `--diffs` pictures, the bundle written, the user-name check, and the rule that an SVG stays as it is when its PNG was not written | | The git listing | `changedPictures`, `parseNameStatus`, `parseUntracked` in `scripts/lib/shot-revision.mjs` | | A child's report | `scripts/lib/record-lines.mjs`: `recordLine`, `writeRecord`, `parseRecord`, `readRecords(stream, kinds, {onRecord, onLine})`; `runShards` reads `svgshot-result` records with it, and `--events` writes `shot-event` records the same way (a shard's pass through its parent as lines) | -| The sheets' HTML | the pieces in `scripts/lib/shot-views.mjs`: `pageHtml({generator, title, intro, summary, contents, body})`, `cardHtml({out, meta, meter, figures})`, `figuresIn(folder)` (`href`, `figure`, `thumb`), `meterHtml`, `tocItem`, `esc`, `anchor`, `sizeText`, `pctText`. The two pages, their rows, their order, their commands and the output-folder rules (`mayWriteSheet`, `SHEET_GENERATOR`) are in `scripts/svgshot/sheets.mjs`, and `outputRefusal`, which the stage shares, in `shot-revision.mjs`; `redraw.mjs` keeps drawing and the shards | +| The pages' HTML | the pieces in `scripts/lib/shot-views.mjs`: `pageHtml({generator, title, intro, summary, contents, body, head})`, `chipHtml`, `allowancesOf`, `esc`, `anchor`, `sizeText`; `outputRefusal`, which the stage uses, in `shot-revision.mjs`; `redraw.mjs` keeps drawing and the shards | | Server-sent events | `createSseChannel()` in `lib/sse.mjs`: `handle(req, res)`, `send(event, data)`, `close()`; `builder/serve.mjs` uses one | | The installs | `listIdes()` in `scripts/lib/tb-install.mjs`, newest first, `[{build, exe}]` | | Commit | `workingChanges(root)` (`{top, changes}`, `parseStatus` of `git status --porcelain=v1 -z --no-renames --untracked-files=all`) and `commitPaths(root, {paths, added, message})` in `shot-revision.mjs`: `git add` of the paths git does not track, then `git commit --only` of every path named, literal pathspecs on stdin, hooks run; git's own words in the Error when it refuses | @@ -450,7 +453,7 @@ What step 6 added: |---|---| | Applying the verdicts | `createApplier({session, docsRoot, bundlesRoot, revision(), manifest()})` in `scripts/lib/shot-verdicts.mjs`: `arrive(n, out, part)` applies a part of a run's verdict as its event arrives, as the run decided it (the server queues each arrival and applies one per turn of its event loop, so that it answers between them: applied as their events were read, a replay's, each 0.1 s or more for its bundle copied into the cache, held every request up for as long as the replay ran, owner, 2026-11-01; a run that has exited stays live until its arrivals are applied, and `close()` applies what is left); `pending()` applies what was reported and not applied (the tool opened again); `rejudge(out, from)` applies every layer of a picture again from the run `from` on, judged anew with the manifest as it is and against the baseline; `reviewed(n, out)`, `heldPng(n, out)`, `errors`. Its header has the rules. What it applied is the stage's `review/` (`readReviewed`, `writeReviewed`, `reviewedFiles` in `shot-stage.mjs`), which the server shows in place of the run's own verdicts; a verdict judged again whose reference changed has its strength map measured again into `review/maps/` | | What a picture held | before a run's verdict on a picture is applied, `holdPicture(dir, outRoot, out, bundlesRoot, build)` keeps its PNG, SVG, bundle and manifest build in `runs//held/`; `unholdPicture` puts them back (each removed that was not there) and returns the build; `heldOf`. Putting a picture back as its first layer found it undoes that layer and every later one, which is how a decision is applied and a run removed (`heldPictures(dir)` lists what a run held) | -| A bundle into the cache | `copyBundle(fromRoot, toRoot, out, png)` in `svgshot/bundle.mjs`, naming the PNG the file holds once a review has decided (the run named the one it expected); `BUNDLE_CACHE` there, the one default for `shoot_docs.mjs`, `replay.mjs`, `sheet.mjs` and the tool | +| A bundle into the cache | `copyBundle(fromRoot, toRoot, out, png)` in `svgshot/bundle.mjs`, naming the PNG the file holds once a review has decided (the run named the one it expected); `BUNDLE_CACHE` there, the one default for `shoot_docs.mjs`, `replay.mjs` and the tool | | The SVG with its PNG | `svgFollowsPng({written, svgOnDisk})` in `shot-policy.mjs`, which `shoot_docs.mjs`'s `keepSvg` and the applier both ask. With `--stage`, `keepSvg` judges and stages the SVG of a picture whose PNG is not written too ("unchanged", `why` its reason, no look), and of one restored or the dark one's, so that a review that takes the capture can write the SVG as judged; the lines printed are the same, and without `--stage` nothing changed | | The noise rule over files | `pngsNear(a, b, rule)` in `shot-change.mjs`, `shoot_docs.mjs`'s `nearly` | | The manifest's setter | `setPart(out, part, key, value)` on `openManifest`'s object: a decision or an allowance set, or removed with `undefined`, checked as `parseManifest` checks an entry | @@ -520,24 +523,9 @@ What step 9 added: | Part | Where it is | |---|---| | A picture's allowances as text | `allowancesOf(entry)` in `shot-views.mjs`, `{png, svg}`: the rule each allowance makes, with the defaults filled in from `pngRule` and `svgRule`, or null. The overview's cards and a picture's page show each as a chip, `PNG: allowance` and `SVG: allowance`, the rule as its tooltip (`chipsOf(p, entry)`; `overviewHtml` takes `entry(out)` from the server) | -| The sheet of pictures with no SVG | `sheet.mjs` reads the manifest when `--docs` is `docs` (as `shoot_docs.mjs` and `replay.mjs` do for their `--out`) and passes each picture's entry to `judgeSvg`, so an SVG is judged by its own bar and a review's decision. A row has `by`, `allowance` and `own` ({share, bar}: the share off at its bar's levels with its rectangles left out, and its bar); its card shows the allowance with that share, or "accepted/refused by a review's decision", and its meter is drawn against its own bar | -| The sheet of changes | `compareRevisionPicture(item, before, after, entry)` compares by `pngRule(entry)` (`compareImages(A, B, rule)` takes the rule: its `levels` split beyond from faint, and `noiseOnly` is `withinNoise` with the whole rule) and files a picture as noise by `cleanupResets`, so the group is exactly what the `--cleanup` command it shows puts back. A row has `by`, `share` and `allowance`; the card says "kept old" or "taken new by a review's decision", and the meter's mark is the rule's share. `meterHtml` clamps a mark past the meter's full width to its end (an allowance of 100% is past the 10% the bar shows) | | The commit's status | the commit form has `data-busy="committing..."`, and the page script's `post` says the `data-busy` text of the form or control that sent an action, else "applying..." | | The tests | the review tool's four suites moved from `test/svgshot.test.mjs` into `test/shot-review.test.mjs` (session, pages, writes under docs, server), each file keeping the imports it uses; the modules the tool shares with the command-line tools stay tested in `svgshot.test.mjs`. The new file is a step of `test.bat`, of the `run-gates` action, of Tools.md's list (31 steps; `check_gate_lists.mjs` now reads number words up to forty) and of Building.md's command, with an entry of its own in `Tools-Toolchain-Tests.md` and a row in WIP.md's roster | -| The documentation | `shot_review.mjs` in `Tools-IDE.md` (after `sheet.mjs`, which now says how it reads the manifest), node `i10` in `Tools-Groups.dot` and `t29` for its tests (the next row's edge to the samples moved to it), the landing page's line, and WIP.md's *Which file to open* row naming the tool | - -Step 9 was checked with the tests (121 in `svgshot.test.mjs`, 22 in `shot-review.test.mjs`: -the allowances as text and as chips, the overview's chips after an allowance through the server, -the change sheet with an allowance, a rectangle left out and a decision each way, the no-SVG -sheet's card with its own bar and a decision, the clamped mark, and the commit form's -`data-busy` and the script that reads it), with `build.bat`, `check.bat` and `test.bat`, and by -running both sheets with an entry put in the manifest for the run and taken out after (`git -checkout` of it): `--against 16765345^ --only IDE/Menu/` filed `Menu_View.light.png`, with a PNG -allowance of 255 levels and 100%, under noise (0 changed beyond noise, its card naming the rule) -and `Menu_Edit.png`, with a "keep old" decision on its file, as kept old by a review although its -size changed; `--all --only Menu_Add-Ins` judged `Menu_Add-Ins.png` by an SVG bar of 32 levels -and 5% (0.081% off by it, the same as its `pct32`), and its light picture, with no entry, by the -default bar. +| The documentation | `shot_review.mjs` in `Tools-IDE.md`, node `i10` in `Tools-Groups.dot` and `t29` for its tests (the next row's edge to the samples moved to it), the landing page's line, and WIP.md's *Which file to open* row naming the tool | **The commit runs without blocking** (owner, 2026-11-01, after step 9): @@ -679,5 +667,5 @@ MutationObserver (`tabCloseIcon`). ## Open Nothing: the questions open after step 5 (the port, pictures changed outside the session, -allowances in the static sheets, HEAD moving under a session) were answered by the owner on +HEAD moving under a session) were answered by the owner on 2026-10-31 and are under [Decisions](#decisions-owner). diff --git a/WIP.md b/WIP.md index 08cb92889..9a8110251 100644 --- a/WIP.md +++ b/WIP.md @@ -81,7 +81,7 @@ The rest of this file is the maintenance guide for updating existing pages or ad > **Two rules come from this package.** First, **never widen an `exclude:` entry in > `_config.yml` to a bare underscore prefix.** The twinBASIC interface is named `_App` > (the COM hidden-interface convention), so a blanket `**/_*/**` would drop all 37 - > pages under `_App/`. The exclude is scoped to `**/_Images/**` (plus `**/*.af`). + > pages under `_App/`. The underscore entries match at the source root only. > Second, a UTF-8 BOM in front of a page's `---` hides its frontmatter: `discover` > would file the page as a *static file* and serve the raw markdown. Editors on > Windows add a BOM unasked. `lib/frontmatter.mjs` strips a leading BOM before parsing. @@ -592,7 +592,7 @@ Why the report separates the wedged task from the merely blocked ones, and why - `addin-test.bat` — tests IDE add-ins by operating an IDE: every lane in `test/addin/lanes.mjs` builds the add-ins it tests into a private copy of the install, opens a project and checks what the add-in does. Outside every gate and outside CI for the same reasons as `examples.bat`; the eighteen lanes: Samples 10 and 15, the fourteen probe lanes behind the answers in [WIP.HelpAddin.md](WIP.HelpAddin.md) (`keys-help` is `keys` with the help add-in loaded), and the help add-in in `add-in/` twice, built with its committed copy of the symbol index, `add-in/Resources/SYMBOLS/symbols.json`, which a local build rewrites whenever the index changes. The `help` lane serves the built `docs/_site` on localhost to the add-in's pane; `help-offline` builds the add-in with a help archive of `docs/_site-offline` and the pane's pages come from the add-in's own server. So run `build.bat` first. Exit 0 every lane passed and the registry is as it was found, 1 a lane failed, 2 the harness failed, 3 the registry or a work folder was not put back. See [Driving the twinBASIC compiler](#driving-the-twinbasic-compiler) for its rules. - `ide-test.bat` --- the same runner for scenarios that operate the IDE itself rather than an add-in: every lane in `test/ide/lanes.mjs`. Same exit codes, same standing outside every gate and outside CI, same rules. - `try-help-addin.bat` --- opens one IDE on the user's desktop with the help add-in built and loaded, to try it by hand, and puts the registry back once it is closed (see [Driving the twinBASIC compiler](#driving-the-twinbasic-compiler)). Needs `build.bat` first. Exit 0 closed and put back, 1 the add-in or the project did not compile, 2 the tool could not run, 3 not put back. -- `node scripts/shoot_docs.mjs` --- writes the documentation's IDE screenshots (plan and owner's decisions: [WIP.Screenshots.md](WIP.Screenshots.md)). Each picture is a shot in a table, `out` its path under `docs/` (`--only` matches it), in a setup (the main three below; the full list is in WIP.Screenshots.md), each one IDE on a **private** desktop started only when a shot in it is selected: `help` (builds the add-in as `try-help-addin.bat` does, opens `test/addin/helpdemo`, `TB_DOCS_HELP_REAL_TITLEBAR=0`: the nine `docs/IDE/AddIns/Images/Help_.png`), `no-project` (`Lane.openNoProject` with `includeProjects`: the menus, cut out with alpha, the dialogs that need no project, and the empty panels, each floated on its own, after the dialogs) and `project` (the demo without the add-in: About, which needs the compiler's licence answer, and IDE Options, whose font lists need a project). One setup is not an IDE: `web` starts puppeteer's Chrome through `launchOnDesktop` on a private desktop of its own (never headless, never on the user's desktop; native-window occlusion and occluded-window backgrounding switched off, or a capture waits forever or comes back blank) for the two public pages the FAQ shows, taken once; it needs the network, as do `webpage` (the Webpage pane on `https://docs.twinbasic.com/`, its page frozen from the pane's own DevTools target and shown in a frame of the IDE's page at the pane's place, as Help_Window's docs frame is shown by srcdoc, so that the SVG can draw both: `scripts/lib/shot-freeze.mjs`) and the package-server setups, which never publish. Every IDE gets `--force-device-scale-factor=1` (`Lane`'s `browserArgs`), else the page follows the display's scaling; the page is overridden to 1280x880 at 2x, and `PAGE_DEFAULTS` puts the IDE's options, panel layouts and keyboard groups to their defaults and the recent lists to the tool's own **in the page only**, nothing written because the IDE has `IDE_FLAGS` (the one recent-list call they do not guard, `RemoveRecentsList`, is replaced first). Each picture is a `Page.captureScreenshot` with a `clip`; a page showing it gives it `{:width height}` of half its pixel size. **Every picture is taken in two themes by one IDE**: dark as `X.png`, then, after `backToPrepared` and `tbTheme_SwitchToLightMode`, Light (not Classic) as `X.light.png` beside it, which the build pairs by name ([WIP.Build.md](WIP.Build.md#pictures-in-two-themes)); a light picture with the dark one's pixels is not kept, and one more than 32 device pixels off the dark one's size fails (a wrong state, not the theme). So does a picture whose two themes say different things (`themeTextDifference`, `scripts/lib/shot-policy.mjs`): the page's text inside the clip is read at each pass's capture, white space ignored, and text one theme shows whole and the other shows none of fails it, naming the words on each side, with or without `--svg`, so that a line cut by the clip's edge is no difference; a shot whose text must differ names the words in `themeWords`. A label's pill follows the theme unless the shot names a `tone`. A shot's `annotate` list (arrows, rings, badges...) is drawn by `scripts/svgshot/annotate.mjs` as one SVG layer over the page before the capture and removed after it, the clip growing to hold it. A picture is rewritten only when its bytes differ, and a second run reports every one `unchanged`; a capture is not byte-stable, so `capture` captures back to back, with no rest, until one equals the file on disk or two agree, and, when the two that agree are not the file, goes on capturing further apart, for 5.5 s at most, until one is, keeping the last two that agreed, and a picture that differs from the file only by a capture's noise (16 grey levels, 0.5% of its pixels) is left as it is. **The reference is the picture at git `HEAD` first, then the file** (owner): compared with the file alone, a picture drifted from `HEAD` over the runs of one retake, each step within noise of the file before it. A capture equal to or within noise of `HEAD`'s picture leaves the file as `HEAD` has it, its SVG too (`HEAD`'s, or none), reported `restored` when it held anything else; one that is not, but is within noise of the file, leaves the file (an earlier run's real change); a picture `HEAD` lacks is compared with the file only (`pictureFate`, `scripts/lib/shot-revision.mjs`; the run's pictures at `HEAD` read in one `git cat-file --batch`). `--against ` takes another revision, `--against-disk` the file only. **`--cleanup`** (`--dry-run` to list) starts no IDE: it resets every PNG git reports modified that is within noise of `HEAD`'s, with its SVG, so that only real changes stay; one noise rule, `withinNoise` in `scripts/lib/shot-change.mjs`, for the capture, `--cleanup` and `sheet.mjs --against`. **The manifest, `test/shots/manifest.json`** (`scripts/lib/shot-manifest.mjs`; [WIP.ShotReview.md](WIP.ShotReview.md#remembered-overrides)), records the build of each picture a run writes, and holds each picture's allowances (its noise rule's limits and rectangles left out, its SVG's bar) and a review's decisions, each tied to the bytes it was made on; `decidePicture` and `decideSvg` (`scripts/lib/shot-policy.mjs`) judge with them, in a run, in `--cleanup` and in `replay.mjs`, so a run from a terminal and one from the review tool come out the same. It is read and written only for the default `--out`. **`--stage `** (a new or empty folder git ignores) writes nothing under `docs/`, to the bundle cache or to the manifest, and puts each capture, its SVG, bundle, difference pictures, strength maps and verdict there (`scripts/lib/shot-stage.mjs`), for the review tool to apply; **`--events`** prints a `@@shot-event` line per event, and then a line `stop` on stdin ends the run as at its normal end; `replay.mjs` takes both ([WIP.ShotReview.md](WIP.ShotReview.md#runs)). `--jobs N` (default 6) runs the setups at once, each in a slot of its own from `tbbroker`, a full run with `--svg` in about 12 minutes on BETA 1010 (`--jobs 1`: one at a time); `--diffs ` writes the old picture, the new one and an amplified difference map for each that changed, named with its theme. Settle by a condition, never a fixed sleep, and a picture that shows some state sets it itself rather than relying on the shots before it. The page's animations and carets are switched off through a style sheet put into the document and every shadow root; a picture that holds DEBUG CONSOLE lines has their times (and a CodeLens run's time taken) set in the page once the real ones show. **A running program's window** (setup `programs`, fixture `test/shots/programs`) is taken **once** (`once: true`, the dark pass only) with `captureWindow`, cropped to its visible frame, at the display's DPI, shown at its size at 96 DPI; its shot says `window: true` in the table, and a shot whose take and table disagree fails. **`--list`** starts no IDE: it prints the table as one line of JSON (`[{out, setup, once, window}]`), which the review tool's page of every picture reads. **The Windows user name must never be in a published picture**: the visible text of the page, text boxes included, is searched for it before the first capture and again when a capture is chosen, with the picture's SVG under `--svg` (a page can draw again in between: Project Settings puts a real path back over the one the shot set), and for a program's window the texts of the window and its children, and the run fails when it is there. **A path a picture shows on the tool's own folder is virtual** (owner): the real folder is `.claude\tbshots` (`PACKAGE_ROOT`, gitignored, removed at the end of a run), every picture shows it as `C:\tbshots`, which is never created, and `scripts/lib/shot-root.mjs` rewrites it in the page from the moment the lane attaches, with the same kind of guard as the user name's. The tool finds each name it presses F1 on by searching the demo's source, not by line. The add-in's detached window has a port from the broker (the help setup's slot carries one), since the add-in is told it before it binds it. **`--svg`** also draws each picture as SVG from the page as it stands at the capture (`scripts/svgshot/`: a DOM snapshot converted, its text set in per-picture subsets of the fonts the IDE drew it with, cut by `scripts/subset_font.py`, which needs Python with fontTools), compares it with the PNG, and writes `X.svg` or `X.light.svg` beside it only when no more than 0.25% of its pixels are far off; otherwise an older SVG is removed and the page shows the PNG; the SVG of a picture whose PNG is not rewritten stays as it is, with its bundle, unless a review accepts the new one (owner), but its bundle goes to the cache when the SVG drawn is the file's to the byte (owner, `bundleFollowsSvg`), and the SVG is written with it when the cached bundle cannot draw the picture again (owner, `staleBundle`) ([WIP.Build.md](WIP.Build.md#pictures-as-svg)). With `--svg` each picture's *bundle*, what its SVG is drawn from, is saved in the gitignored `.svgshot-bundles/` (`--bundles`; never under `docs/`, a bundle holds the user name), and **after a change to the converter, `node scripts/svgshot/replay.mjs` draws every SVG again from the bundles, with no IDE**, in about 20 s for the 370 (an SVG the same as its file is not compared again, `--recheck` compares all; the fonts' cuts are kept in `.svgshot-bundles/subsets/`; one browser per process, GPU off); it lists the pictures whose bundle cannot answer what the converter now asks, with the `--only` command that retakes them ([WIP.Screenshots.md](WIP.Screenshots.md#pictures-as-svg)). `node scripts/svgshot/sheet.mjs --out ` writes a page of the pictures with no SVG (`--all`: every picture), each drawn again from its bundle beside its PNG and difference map, worst first; it is drawn without the user-name check (owner: the sheet is the owner's alone), so `--out` is refused under `docs/` and anywhere git does not ignore; what it and replay share is `scripts/svgshot/redraw.mjs`, and its pages are `scripts/svgshot/sheets.mjs`, made of the pieces in `scripts/lib/shot-views.mjs`. `node scripts/svgshot/bench.mjs` tests the converter's replicas of what Chromium draws outside the DOM (scrollbars, drop-down lists) in Edge, with no IDE ([WIP.Screenshots.md](WIP.Screenshots.md#pictures-as-svg)). No wrapper; outside every gate and outside CI, as `try-help-addin.bat` is. Exit 0 every picture written or unchanged, 1 a picture failed, 2 the tool could not run, 3 not put back. Run `build.bat` first. +- `node scripts/shoot_docs.mjs` --- writes the documentation's IDE screenshots (plan and owner's decisions: [WIP.Screenshots.md](WIP.Screenshots.md)). Each picture is a shot in a table, `out` its path under `docs/` (`--only` matches it), in a setup (the main three below; the full list is in WIP.Screenshots.md), each one IDE on a **private** desktop started only when a shot in it is selected: `help` (builds the add-in as `try-help-addin.bat` does, opens `test/addin/helpdemo`, `TB_DOCS_HELP_REAL_TITLEBAR=0`: the nine `docs/IDE/AddIns/Images/Help_.png`), `no-project` (`Lane.openNoProject` with `includeProjects`: the menus, cut out with alpha, the dialogs that need no project, and the empty panels, each floated on its own, after the dialogs) and `project` (the demo without the add-in: About, which needs the compiler's licence answer, and IDE Options, whose font lists need a project). One setup is not an IDE: `web` starts puppeteer's Chrome through `launchOnDesktop` on a private desktop of its own (never headless, never on the user's desktop; native-window occlusion and occluded-window backgrounding switched off, or a capture waits forever or comes back blank) for the two public pages the FAQ shows, taken once; it needs the network, as do `webpage` (the Webpage pane on `https://docs.twinbasic.com/`, its page frozen from the pane's own DevTools target and shown in a frame of the IDE's page at the pane's place, as Help_Window's docs frame is shown by srcdoc, so that the SVG can draw both: `scripts/lib/shot-freeze.mjs`) and the package-server setups, which never publish. Every IDE gets `--force-device-scale-factor=1` (`Lane`'s `browserArgs`), else the page follows the display's scaling; the page is overridden to 1280x880 at 2x, and `PAGE_DEFAULTS` puts the IDE's options, panel layouts and keyboard groups to their defaults and the recent lists to the tool's own **in the page only**, nothing written because the IDE has `IDE_FLAGS` (the one recent-list call they do not guard, `RemoveRecentsList`, is replaced first). Each picture is a `Page.captureScreenshot` with a `clip`; a page showing it gives it `{:width height}` of half its pixel size. **Every picture is taken in two themes by one IDE**: dark as `X.png`, then, after `backToPrepared` and `tbTheme_SwitchToLightMode`, Light (not Classic) as `X.light.png` beside it, which the build pairs by name ([WIP.Build.md](WIP.Build.md#pictures-in-two-themes)); a light picture with the dark one's pixels is not kept, and one more than 32 device pixels off the dark one's size fails (a wrong state, not the theme). So does a picture whose two themes say different things (`themeTextDifference`, `scripts/lib/shot-policy.mjs`): the page's text inside the clip is read at each pass's capture, white space ignored, and text one theme shows whole and the other shows none of fails it, naming the words on each side, with or without `--svg`, so that a line cut by the clip's edge is no difference; a shot whose text must differ names the words in `themeWords`. A label's pill follows the theme unless the shot names a `tone`. A shot's `annotate` list (arrows, rings, badges...) is drawn by `scripts/svgshot/annotate.mjs` as one SVG layer over the page before the capture and removed after it, the clip growing to hold it. A picture is rewritten only when its bytes differ, and a second run reports every one `unchanged`; a capture is not byte-stable, so `capture` captures back to back, with no rest, until one equals the file on disk or two agree, and, when the two that agree are not the file, goes on capturing further apart, for 5.5 s at most, until one is, keeping the last two that agreed, and a picture that differs from the file only by a capture's noise (16 grey levels, 0.5% of its pixels) is left as it is. **The reference is the picture at git `HEAD` first, then the file** (owner): compared with the file alone, a picture drifted from `HEAD` over the runs of one retake, each step within noise of the file before it. A capture equal to or within noise of `HEAD`'s picture leaves the file as `HEAD` has it, its SVG too (`HEAD`'s, or none), reported `restored` when it held anything else; one that is not, but is within noise of the file, leaves the file (an earlier run's real change); a picture `HEAD` lacks is compared with the file only (`pictureFate`, `scripts/lib/shot-revision.mjs`; the run's pictures at `HEAD` read in one `git cat-file --batch`). `--against ` takes another revision, `--against-disk` the file only. **`--cleanup`** (`--dry-run` to list) starts no IDE: it resets every PNG git reports modified that is within noise of `HEAD`'s, with its SVG, so that only real changes stay; one noise rule, `withinNoise` in `scripts/lib/shot-change.mjs`, for the capture, `--cleanup` and the review tool. **The manifest, `test/shots/manifest.json`** (`scripts/lib/shot-manifest.mjs`; [WIP.ShotReview.md](WIP.ShotReview.md#remembered-overrides)), records the build of each picture a run writes, and holds each picture's allowances (its noise rule's limits and rectangles left out, its SVG's bar) and a review's decisions, each tied to the bytes it was made on; `decidePicture` and `decideSvg` (`scripts/lib/shot-policy.mjs`) judge with them, in a run, in `--cleanup` and in `replay.mjs`, so a run from a terminal and one from the review tool come out the same. It is read and written only for the default `--out`. **`--stage `** (a new or empty folder git ignores) writes nothing under `docs/`, to the bundle cache or to the manifest, and puts each capture, its SVG, bundle, difference pictures, strength maps and verdict there (`scripts/lib/shot-stage.mjs`), for the review tool to apply; **`--events`** prints a `@@shot-event` line per event, and then a line `stop` on stdin ends the run as at its normal end; `replay.mjs` takes both ([WIP.ShotReview.md](WIP.ShotReview.md#runs)). `--jobs N` (default 6) runs the setups at once, each in a slot of its own from `tbbroker`, a full run with `--svg` in about 12 minutes on BETA 1010 (`--jobs 1`: one at a time); `--diffs ` writes the old picture, the new one and an amplified difference map for each that changed, named with its theme. Settle by a condition, never a fixed sleep, and a picture that shows some state sets it itself rather than relying on the shots before it. The page's animations and carets are switched off through a style sheet put into the document and every shadow root; a picture that holds DEBUG CONSOLE lines has their times (and a CodeLens run's time taken) set in the page once the real ones show. **A running program's window** (setup `programs`, fixture `test/shots/programs`) is taken **once** (`once: true`, the dark pass only) with `captureWindow`, cropped to its visible frame, at the display's DPI, shown at its size at 96 DPI; its shot says `window: true` in the table, and a shot whose take and table disagree fails. **`--list`** starts no IDE: it prints the table as one line of JSON (`[{out, setup, once, window}]`), which the review tool's page of every picture reads. **The Windows user name must never be in a published picture**: the visible text of the page, text boxes included, is searched for it before the first capture and again when a capture is chosen, with the picture's SVG under `--svg` (a page can draw again in between: Project Settings puts a real path back over the one the shot set), and for a program's window the texts of the window and its children, and the run fails when it is there. **A path a picture shows on the tool's own folder is virtual** (owner): the real folder is `.claude\tbshots` (`PACKAGE_ROOT`, gitignored, removed at the end of a run), every picture shows it as `C:\tbshots`, which is never created, and `scripts/lib/shot-root.mjs` rewrites it in the page from the moment the lane attaches, with the same kind of guard as the user name's. The tool finds each name it presses F1 on by searching the demo's source, not by line. The add-in's detached window has a port from the broker (the help setup's slot carries one), since the add-in is told it before it binds it. **`--svg`** also draws each picture as SVG from the page as it stands at the capture (`scripts/svgshot/`: a DOM snapshot converted, its text set in per-picture subsets of the fonts the IDE drew it with, cut by `scripts/subset_font.py`, which needs Python with fontTools), compares it with the PNG, and writes `X.svg` or `X.light.svg` beside it only when no more than 0.25% of its pixels are far off; otherwise an older SVG is removed and the page shows the PNG; the SVG of a picture whose PNG is not rewritten stays as it is, with its bundle, unless a review accepts the new one (owner), but its bundle goes to the cache when the SVG drawn is the file's to the byte (owner, `bundleFollowsSvg`), and the SVG is written with it when the cached bundle cannot draw the picture again (owner, `staleBundle`) ([WIP.Build.md](WIP.Build.md#pictures-as-svg)). With `--svg` each picture's *bundle*, what its SVG is drawn from, is saved in the gitignored `.svgshot-bundles/` (`--bundles`; never under `docs/`, a bundle holds the user name), and **after a change to the converter, `node scripts/svgshot/replay.mjs` draws every SVG again from the bundles, with no IDE**, in about 20 s for the 370 (an SVG the same as its file is not compared again, `--recheck` compares all; the fonts' cuts are kept in `.svgshot-bundles/subsets/`; one browser per process, GPU off); it lists the pictures whose bundle cannot answer what the converter now asks, with the `--only` command that retakes them ([WIP.Screenshots.md](WIP.Screenshots.md#pictures-as-svg)). `node scripts/svgshot/bench.mjs` tests the converter's replicas of what Chromium draws outside the DOM (scrollbars, drop-down lists) in Edge, with no IDE ([WIP.Screenshots.md](WIP.Screenshots.md#pictures-as-svg)). No wrapper; outside every gate and outside CI, as `try-help-addin.bat` is. Exit 0 every picture written or unchanged, 1 a picture failed, 2 the tool could not run, 3 not put back. Run `build.bat` first. - **The six GitHub pictures of `Documentation/Building.md` are taken by the Chrome extension in `scripts/svgshot/` and by no session** (owner: only the owner signs in to GitHub; no session opens a pull request, posts anything on GitHub or uses the owner's account); `node scripts/svgshot/chromeshot.mjs ` turns what it saves into `X.png`, `X.light.png`, their SVGs and their bundles, a capture of the whole window trimmed first to the area `chrome/shots.mjs` names (`trim.mjs`), and `chrome_try.mjs` tries the extension on a public page in a Chrome of its own ([WIP.Screenshots.md](WIP.Screenshots.md#pictures-from-a-signed-in-chrome)). **The folder `scripts/svgshot/` is the extension's root, and Chrome loads nothing from outside it and no Node module**: `capture.mjs`, `annotate.mjs`, `private-words.mjs`, `snapshot-svg.mjs`, `snapshot-trim.mjs`, `font-rules.mjs`, `colour-filter.mjs`, `gradient.mjs`, `util.mjs` and `chrome/` import nothing else, which `test/svgshot.test.mjs` checks by following the imports. **A capture or a bundle never goes under `docs/`**, and what is published is checked for the Windows user name, git's `user.name` and `user.email` and each `find` of `scripts/svgshot/private.json`, which git ignores: by `chromeshot.mjs` before it writes anything, and by `replay.mjs`. - **The help add-in's project file is written by every build, CI's included.** The `addinProject` task (`builder/addin-project.mjs`) packs `add-in/` into `tB/IDE/AddIns/downloads/tbDocsHelp.twinproj` in the **online tree only**, which the Help Add-In page offers as a download; `_config.yml`'s `addin_project` declares both ends, so a fixture config gets none. It waits for the `helpArchive` task. It packs the files `git ls-files` lists there, read from the working folder, never a `Resources/HELP/` file from the disk, with CRLF made LF outside `Resources/` (so a Windows and a Linux build write the same bytes), the `tB/symbols.json` the same build wrote in place of the committed copy, and **the zip that build's archive task wrote** as `Resources/HELP/site.zip`, passed in memory (a build that wrote none --- `--no-help-archive`, `--serve`, another `--dest`, a fixture --- packs without it, and the summary line says `without the offline archive`). The download is about 61 MB with the archive, 1 MB without. The offline tree holds no copy (the project carries that tree's archive, so a copy there would be circular), and its links to the file are rewritten to the website by the general rule in `offline-rewrite.mjs`: a URL the offline tree lacks but the online tree has becomes `site.url` + path, and is no miss (`computeWebsiteUrl`; the offline link check's `forbidExempt` excuses exactly those links, `isWebsiteOnlyLink`). The pack is `packFiles` from `scripts/impexp.mjs`, in memory (never staged through `%TEMP%`), the one module under `scripts/` that `builder/` may import (`biome.jsonc`); `check_tree_fresh.mjs` watches it and `add-in/` for that reason. The publish allowlist exempts the one path in the trees only (`publishPolicyFor`'s `generated`); a `.twinproj` anywhere else, or in `docs/`, is refused. `--serve` writes it into its one tree; `--dry-run` writes nothing. A failure (no git) fails the build with exit 1 and the index audit names the missing file. **Don't build the DLLs in CI from it**: that needs a twinBASIC install; the download is the project, and the reader builds it. Why each of these: [WIP.Build.md](WIP.Build.md#the-help-add-ins-project-file); `test/addin-project.test.mjs` is the gate. - **The help archive is the `helpArchive` task of the build's graph.** `builder/help-archive-step.mjs` writes `add-in/Resources/HELP/site.zip` from `docs/_site-offline` through `lib/help-archive.mjs`, once every task that writes into the offline tree has finished (`flushJoin`, `scss`, `searchIndex`, `writeOffline`; the archive task lists exactly those) and **before** the Gantt injection. **The archive leaves out `HELP_ARCHIVE_SKIP`** (`builder/help-archive-step.mjs`): the Documentation Development section (`BuildInfo.html` and `assets/images/gantt.svg` with it, so the chart never reaches the zip), Videos and their poster frames, Challenges, and **every download, which stays online** (owner): a file readers download goes in a `downloads` folder beside its page, and the step fails the build when the Downloads page offers a file the archive would hold. The add-in's server redirects any file the archive lacks to the website, because pages link to all of these; a new entry needs nothing else. It reads the file back to verify it. A mismatch fails the build (exit 1). After the Gantt injection `recheckHelpArchive` checks that the offline tree on disk lists the same files as the archive and differs from it only in `BuildInfo.html` and `gantt.svg`; a task that wrote into the offline tree late fails the build there. The help add-in embeds the zip as a resource and serves the pages from it with its own server; a build of the add-in without it uses the live site. The file is gitignored (about 60 MB, 10 MB of it the search index's `search-index.js`, deflated), so a build of the add-in from a clean clone is the online one until `build.bat` has run. The download carries the same zip (previous bullet). **`--no-help-archive` turns the step off, and neither CI workflow may pass it** (`check_ci_workflows.mjs` refuses it, in `ALLOWED.forbiddenBuildFlags`), because CI's published download would then hold no archive. It runs only for the guarded source tree (`docs`) built into the default `docs/_site-offline` (not another `--dest`, so `compare_trees` and `check_links_diff` leave it alone), never under `--serve` or `--dry-run`, never without an offline tree, and not keyed on `$CI`. There is no command-line tool for the archive: the `help-offline` lane makes its own with `writeHelpArchive`. The zip's format is fixed by the add-in's reader, which does no inflating ([WIP.HelpAddin.md](WIP.HelpAddin.md), Stage 4, increment 5). @@ -673,7 +673,7 @@ wrapper: | `test.bat` | `test/render.test.mjs` | `builder/render.mjs`'s markdown-it plugins, one at a time, on inputs no page holds --- today the ellipsis plugin's dot counting. Run by `node --test` | | `test.bat` | `test/strftime.test.mjs` | `builder/strftime.mjs`'s `formatDate`, which no build calls because no page sets `last_modified_date`. Run by `node --test` | | `test.bat` | `test/compact-image.test.mjs` | what an embedded image keeps (`compactImage` and `stripFile` in `scripts/lib/compact-image.mjs`): an editor's metadata goes, a notice of whose the picture is and on what terms stays (the IDE's lock icon carries a CC BY-NC-SA attribution), an sRGB profile goes and any other stays, a JPEG or a GIF is labelled by its bytes, and an image inside an SVG inside a CSS file is reached and keeps its encoding. Its second half runs `scripts/imagestrip/` over a CSS file and SVG files of every image the test builds and over the IDE's own stylesheets, and compares output, summary and reports with `stripFile` byte for byte; it is skipped unless `IMAGESTRIP_EXE` names the built exe. Run by `node --test` | -| `test.bat` | `test/svgshot.test.mjs` | an SVG screenshot is written on one line (`oneLine` in `scripts/svgshot/snapshot-svg.mjs`), a break in a tag as a space and one in text as a character reference, so that a CRLF checkout changes only its last line ending; an underline is placed and sized by the figures fitted in Edge (`underlineBand`) under the boxes that set one (`decoratingBoxes`); a background image is sized by its bytes, a JPEG the IDE calls `image/png` included (`naturalSize`); an iframe's document is decoded and placed at the iframe's content box, less its scroll, scaled when zoomed, over its canvas colour (`frameGeometry`, `frameView`, `unzoom`, `viewportScroller`, `canvasColor`); a run's web font is the `@font-face` rule CSS matching picks (`webFontFiles`), and a variable WOFF2 is read and cut per weight; a family split by `unicode-range` gives each character to the rule whose range holds it (`parseUnicodeRange`, `webRulesFor`); an inline `` is found and its ids scoped (`inlineSvgsIn`, `scopeIds`); a filter of colour functions is baked into the colours under it, in order and clamped, its pictures wrapped in a real filter and its opacity kept apart (`colour-filter.mjs`); a transformed element's boxes and text are put back from the snapshot's after-transform boxes (`elementTransform`, `untransformBox`); a closed select shows its option's whole text (`selectLabel`); a bundle draws the same SVG from its file as in memory, and counts each question it cannot answer (`renderBundle`); its web font rules and files draw each character from the file whose range holds it, at the weight its rule allows, and its inline `` markup is drawn in its box, from the file and when trimmed (`drawBundle`); a bundle of version 1 is refused; one trimmed to its view draws the same (`trimSnapshot`); a font's cut comes from the subset cache with no Python run (`subsetKey`, `useSubsetCache`); `redraw` draws a picture again from its bundle or names its retake, and fails on the user name unless `checkUserName: false`; `listPictures` leaves the output trees out; `outputRefusal` refuses a sheet under docs or where git would take it (`scripts/lib/shot-revision.mjs`), and `sheetHtml` puts the worst picture first (`scripts/svgshot/sheets.mjs`); both sheets judge and show a picture's allowance and a review's decision (`compareRevisionPicture`, `allowancesOf` in `scripts/lib/shot-views.mjs`); a strength map's share at a level and its regions of change, a word's strokes closed into one block and a line up to 4 pixels thick eroded away, and which pictures need a look, and a capture's regions against the picture it was compared with (`shareOff`, `changeRegions`, `scripts/lib/shot-change.mjs`; `pngLook`, `svgLook`, `reviewPicture`, `scripts/lib/shot-queue.mjs`); a run's stage, its files, verdicts and strength maps, refused under docs, where git would take it or when not empty, and the stop line (`stagedFiles`, `writeVerdict`, `writeStrength`, `stageRefusal`, `scripts/lib/shot-stage.mjs`; `onStop`, `scripts/lib/record-lines.mjs`); a capture's verdict with a picture's allowances and a review's decisions, and the manifest written, read back and refused when malformed (`decidePicture`, `decideSvg`, `cleanupResets`, `scripts/lib/shot-policy.mjs`; `parseManifest`, `manifestText`, `openManifest`, `scripts/lib/shot-manifest.mjs`); a capture's fate against the picture at a git revision and the file, the SVG of one put back, what `--cleanup` resets, and a revision's files read in one git process and a text file put back as a checkout writes it, in a scratch repository (`pictureFate`, `svgFate`, `planCleanup`, `readRevisionFiles`, `restoreFromRevision`, `scripts/lib/shot-revision.mjs`); what a picture held kept and put back, and a bundle copied (`holdPicture`, `unholdPicture`, `copyBundle`); and a commit of the paths named and nothing else, in a scratch repository (`parseStatus`, `commitPaths`, `shot-revision.mjs`). What it keeps of an image it embeds is `compactImage`'s, which the row above tests. Run by `node --test` | +| `test.bat` | `test/svgshot.test.mjs` | an SVG screenshot is written on one line (`oneLine` in `scripts/svgshot/snapshot-svg.mjs`), a break in a tag as a space and one in text as a character reference, so that a CRLF checkout changes only its last line ending; an underline is placed and sized by the figures fitted in Edge (`underlineBand`) under the boxes that set one (`decoratingBoxes`); a background image is sized by its bytes, a JPEG the IDE calls `image/png` included (`naturalSize`); an iframe's document is decoded and placed at the iframe's content box, less its scroll, scaled when zoomed, over its canvas colour (`frameGeometry`, `frameView`, `unzoom`, `viewportScroller`, `canvasColor`); a run's web font is the `@font-face` rule CSS matching picks (`webFontFiles`), and a variable WOFF2 is read and cut per weight; a family split by `unicode-range` gives each character to the rule whose range holds it (`parseUnicodeRange`, `webRulesFor`); an inline `` is found and its ids scoped (`inlineSvgsIn`, `scopeIds`); a filter of colour functions is baked into the colours under it, in order and clamped, its pictures wrapped in a real filter and its opacity kept apart (`colour-filter.mjs`); a transformed element's boxes and text are put back from the snapshot's after-transform boxes (`elementTransform`, `untransformBox`); a closed select shows its option's whole text (`selectLabel`); a bundle draws the same SVG from its file as in memory, and counts each question it cannot answer (`renderBundle`); its web font rules and files draw each character from the file whose range holds it, at the weight its rule allows, and its inline `` markup is drawn in its box, from the file and when trimmed (`drawBundle`); a bundle of version 1 is refused; one trimmed to its view draws the same (`trimSnapshot`); a font's cut comes from the subset cache with no Python run (`subsetKey`, `useSubsetCache`); `redraw` draws a picture again from its bundle or names its retake, and fails on the user name; `outputRefusal` refuses a stage under docs or where git would take it (`scripts/lib/shot-revision.mjs`); a picture's allowances read as text (`allowancesOf` in `scripts/lib/shot-views.mjs`); a strength map's share at a level and its regions of change, a word's strokes closed into one block and a line up to 4 pixels thick eroded away, and which pictures need a look, and a capture's regions against the picture it was compared with (`shareOff`, `changeRegions`, `scripts/lib/shot-change.mjs`; `pngLook`, `svgLook`, `reviewPicture`, `scripts/lib/shot-queue.mjs`); a run's stage, its files, verdicts and strength maps, refused under docs, where git would take it or when not empty, and the stop line (`stagedFiles`, `writeVerdict`, `writeStrength`, `stageRefusal`, `scripts/lib/shot-stage.mjs`; `onStop`, `scripts/lib/record-lines.mjs`); a capture's verdict with a picture's allowances and a review's decisions, and the manifest written, read back and refused when malformed (`decidePicture`, `decideSvg`, `cleanupResets`, `scripts/lib/shot-policy.mjs`; `parseManifest`, `manifestText`, `openManifest`, `scripts/lib/shot-manifest.mjs`); a capture's fate against the picture at a git revision and the file, the SVG of one put back, what `--cleanup` resets, and a revision's files read in one git process and a text file put back as a checkout writes it, in a scratch repository (`pictureFate`, `svgFate`, `planCleanup`, `readRevisionFiles`, `restoreFromRevision`, `scripts/lib/shot-revision.mjs`); what a picture held kept and put back, and a bundle copied (`holdPicture`, `unholdPicture`, `copyBundle`); and a commit of the paths named and nothing else, in a scratch repository (`parseStatus`, `commitPaths`, `shot-revision.mjs`). What it keeps of an image it embeds is `compactImage`'s, which the row above tests. Run by `node --test` | | `test.bat` | `test/shot-review.test.mjs` | the screenshot review tool (`scripts/shot_review.mjs`): its session, its lock and its runs read back, archived and listed; which verdict a picture shows, its group, its chips and allowances, and a loupe; its writes under docs as a run's verdicts arrive and after a review; and the server following a stand-in run, answering the loopback host only and stopping the run, and starting runs from its runs page one at a time, a clean-up holding a review's actions, and its commit, of the session's own files and nothing else, in a scratch repository, held open by a `pre-commit` hook while every page says it is under way and refuses a change, the session archived and opened again read-only and the next one served (`openSession`, `acquireLock`, `reviewPictures`, `chipsOf`, `createApplier`, `createReviewServer`, `runOf`, `commitPlan`, `commitMessage`, `listArchived`, `scripts/lib/shot-session.mjs`, `shot-review.mjs`, `shot-pages.mjs`, `shot-verdicts.mjs`, `shot-server.mjs`, `shot-runs.mjs`). Needs git. Run by `node --test` | | `test.bat` | `test/example-batches.test.mjs` | `check_examples.mjs`'s probes, from `scripts/lib/example-batches.mjs`: batching, crash isolation through a fake lane, the canaries, the fence classifier and `check_run`'s refusals, expected output, dispatcher and marker reading, with no IDE. Run by `node --test` | | `test.bat` | `test/ide-folders.test.mjs` | `shutdownIde` and `shutdownIdeAsync` remove the IDE's temp folder and profile once it is gone, and no other folder. Run by `node --test` | diff --git a/docs/Documentation/Authoring.md b/docs/Documentation/Authoring.md index 39d7feb7b..b59f28f3a 100644 --- a/docs/Documentation/Authoring.md +++ b/docs/Documentation/Authoring.md @@ -52,9 +52,8 @@ An animation is an animated `.webp`, a fraction of the size of the same `.gif`. **A file you do not want published does not belong under `docs/`,** unless a pattern in `_config.yml`'s `exclude:` covers it. These are excluded at any depth: -`.scss` stylesheets, `.dot` diagram sources, and the Affinity `.af` screenshot -sources under `_Images/`. So is everything underscore-prefixed at the root of -`docs/` --- `_config.yml` and `_book.yml`, the `_sass/` tree, and the build's +`.scss` stylesheets and `.dot` diagram sources. So is everything underscore-prefixed +at the root of `docs/` --- `_config.yml` and `_book.yml`, the `_sass/` tree, and the build's output trees (`_site/`, `_site-offline/`, `_serve/`, `_pdf/` and their variants). Keep scratch notes, editor backups and working documents outside the tree. diff --git a/docs/Documentation/Building.md b/docs/Documentation/Building.md index 8f40a0c79..0b1aed79d 100644 --- a/docs/Documentation/Building.md +++ b/docs/Documentation/Building.md @@ -533,7 +533,7 @@ Each picture is a *shot* in the tool's table: the file it writes, the IDE it is A new picture of the IDE is a new shot. `node scripts/shoot_docs.mjs --help` lists the options, and [shoot_docs.mjs](Tools-IDE#shoot-docs) describes how the tool keeps pictures the same from one run to the next and keeps your own settings and name out of them. -A picture the tool does not take, such as the GitHub pages under [Deploying to docs.twinbasic.com](#deploying-to-docstwinbasiccom), is a PNG file in the `Images` folder beside its page. The file an image editor saved it from, if you keep one, goes in the `_Images` folder beside that, which is not published. +A picture the tool does not take, such as the GitHub pages under [Deploying to docs.twinbasic.com](#deploying-to-docstwinbasiccom), is a PNG file in the `Images` folder beside its page. [docs-pr]: https://github.com/twinbasic/documentation/compare [docs-repo]: https://github.com/twinbasic/documentation diff --git a/docs/Documentation/Images/Tools-Groups.dot b/docs/Documentation/Images/Tools-Groups.dot index 46654b793..a757b6535 100644 --- a/docs/Documentation/Images/Tools-Groups.dot +++ b/docs/Documentation/Images/Tools-Groups.dot @@ -166,15 +166,15 @@ digraph tools_groups { i1 [label="addin_test"] i2 [label="ide_test"] i3 [label="try_help_addin"] i4 [label="shoot_docs"] i5 [label="imagestrip"] i8 [label="probe_theme_semicolon"] - i7 [label="svgshot/replay"] i9 [label="svgshot/sheet"] - i10 [label="shot_review"] i11 [label="svgshot/chromeshot"] + i7 [label="svgshot/replay"] i10 [label="shot_review"] + i11 [label="svgshot/chromeshot"] i12 [label="svgshot/chrome_try"] - i1 -> i3 -> i5 -> i7 -> i10 -> i12 - i2 -> i4 -> i8 -> i9 -> i11 + i1 -> i3 -> i5 -> i7 -> i12 + i2 -> i4 -> i8 -> i10 -> i11 { rank=same; i3 i4 } { rank=same; i5 i8 } - { rank=same; i7 i9 } - { rank=same; i10 i11 } + { rank=same; i7 i10 } + { rank=same; i12 i11 } } subgraph cluster_defects { margin=12 @@ -390,8 +390,6 @@ digraph tools_groups { tooltip="Draws the SVG of each picture again from its saved bundle, with the converter as it is now. Starts no IDE and takes no picture."] i8 [URL="Tools-IDE#probe-theme-semicolon" tooltip="Lists the properties that the IDE silently drops when it loads the theme files it ships, because a property lacks its semicolon."] - i9 [URL="Tools-IDE#svg-sheet" - tooltip="Writes a page that shows, for each picture with no SVG, the PNG, the SVG drawn again from its bundle and a map of their differences, the worst first."] i10 [URL="Tools-IDE#shot-review" tooltip="Serves a page in the browser for reviewing what the screenshot tools decided about each picture, deciding otherwise, starting runs and committing the result."] i11 [URL="Tools-IDE#chromeshot" diff --git a/docs/Documentation/Images/Tools-Groups.svg b/docs/Documentation/Images/Tools-Groups.svg index b76e21415..877998ffa 100644 --- a/docs/Documentation/Images/Tools-Groups.svg +++ b/docs/Documentation/Images/Tools-Groups.svg @@ -1,71 +1,71 @@ - - + + tools_groups cluster_wrappers - -Batch wrappers + +Batch wrappers cluster_build - -Build and Generation + +Build and Generation cluster_site - -Site Checks + +Site Checks cluster_compiler - -Compiler Harness + +Compiler Harness cluster_tests - -Toolchain Tests + +Toolchain Tests cluster_samples - -Code Samples and Attributes + +Code Samples and Attributes cluster_ide - -IDE Automation + +IDE Automation cluster_defects - -Defect Reproducers + +Defect Reproducers @@ -73,8 +73,8 @@ w1 - -build.bat + +build.bat @@ -82,8 +82,8 @@ w2 - -serve.bat + +serve.bat @@ -91,8 +91,8 @@ w3 - -check.bat + +check.bat @@ -100,8 +100,8 @@ w4 - -test.bat + +test.bat @@ -109,8 +109,8 @@ w5 - -book.bat + +book.bat @@ -118,8 +118,8 @@ w6 - -examples.bat + +examples.bat @@ -127,8 +127,8 @@ w7 - -addin-test.bat + +addin-test.bat @@ -136,8 +136,8 @@ w8 - -ide-test.bat + +ide-test.bat @@ -145,8 +145,8 @@ w9 - -try-help-addin.bat + +try-help-addin.bat @@ -154,8 +154,8 @@ w10 - -package-tests.bat + +package-tests.bat @@ -163,8 +163,8 @@ b1 - -tbdocs + +tbdocs @@ -172,8 +172,8 @@ b2 - -render-book + +render-book @@ -181,8 +181,8 @@ b3 - -compare_trees + +compare_trees @@ -190,8 +190,8 @@ b4 - -survey_tooling + +survey_tooling @@ -199,8 +199,8 @@ b5 - -convert_em_dash_separators + +convert_em_dash_separators @@ -208,8 +208,8 @@ b6 - -build_fonts.py + +build_fonts.py @@ -217,8 +217,8 @@ b7 - -build_dot_metrics + +build_dot_metrics @@ -226,8 +226,8 @@ b8 - -twin-index + +twin-index @@ -235,8 +235,8 @@ s1 - -check_links + +check_links @@ -244,8 +244,8 @@ s2 - -crawl_check + +crawl_check @@ -253,8 +253,8 @@ s3 - -check_links_diff + +check_links_diff @@ -262,8 +262,8 @@ s4 - -check_tree_fresh + +check_tree_fresh @@ -271,8 +271,8 @@ s5 - -check_dot_fit + +check_dot_fit @@ -280,8 +280,8 @@ s6 - -check_a11y + +check_a11y @@ -289,8 +289,8 @@ s7 - -pick_a11y_sample + +pick_a11y_sample @@ -298,8 +298,8 @@ s8 - -axe-scan + +axe-scan @@ -307,8 +307,8 @@ s9 - -check_a11y_fingerprint + +check_a11y_fingerprint @@ -316,8 +316,8 @@ s10 - -sweep_a11y + +sweep_a11y @@ -325,8 +325,8 @@ c1 - -tbbuild + +tbbuild @@ -334,8 +334,8 @@ c2 - -tbrun + +tbrun @@ -343,8 +343,8 @@ c3 - -impexp + +impexp @@ -352,8 +352,8 @@ c4 - -check_tb_registry + +check_tb_registry @@ -361,8 +361,8 @@ c7 - -tbbroker + +tbbroker @@ -370,8 +370,8 @@ c6 - -probe_build_twice + +probe_build_twice @@ -380,8 +380,8 @@ t1 - -check_publish_policy + +check_publish_policy @@ -389,8 +389,8 @@ t2 - -check_regex_safety + +check_regex_safety @@ -398,8 +398,8 @@ t3 - -check_code_regions + +check_code_regions @@ -407,8 +407,8 @@ t4 - -check_gate_lists + +check_gate_lists @@ -416,8 +416,8 @@ t5 - -check_ci_workflows + +check_ci_workflows @@ -425,8 +425,8 @@ t6 - -check_lint + +check_lint @@ -434,8 +434,8 @@ t7 - -search.test + +search.test @@ -443,8 +443,8 @@ t8 - -render.test + +render.test @@ -452,8 +452,8 @@ t9 - -strftime.test + +strftime.test @@ -461,8 +461,8 @@ t10 - -png.test + +png.test @@ -470,8 +470,8 @@ t11 - -compact-image.test + +compact-image.test @@ -479,8 +479,8 @@ t12 - -svgshot.test + +svgshot.test @@ -488,8 +488,8 @@ t13 - -example-batches.test + +example-batches.test @@ -497,8 +497,8 @@ t14 - -ide-folders.test + +ide-folders.test @@ -506,8 +506,8 @@ t15 - -addin-project.test + +addin-project.test @@ -515,8 +515,8 @@ t16 - -check_page_baseline + +check_page_baseline @@ -524,8 +524,8 @@ t17 - -check_book_coverage + +check_book_coverage @@ -533,8 +533,8 @@ t18 - -check_symbol_index + +check_symbol_index @@ -542,8 +542,8 @@ t19 - -check_twin_parsers + +check_twin_parsers @@ -551,8 +551,8 @@ t20 - -check_attribute_sweep + +check_attribute_sweep @@ -560,8 +560,8 @@ t21 - -check_cli + +check_cli @@ -569,8 +569,8 @@ t22 - -check_pdf_shims_equiv + +check_pdf_shims_equiv @@ -578,8 +578,8 @@ t23 - -check_impexp_parity + +check_impexp_parity @@ -587,8 +587,8 @@ t24 - -check_axe_patch_equiv + +check_axe_patch_equiv @@ -596,8 +596,8 @@ t25 - -indexer.test + +indexer.test @@ -605,8 +605,8 @@ t26 - -check_package_tests + +check_package_tests @@ -614,8 +614,8 @@ t27 - -broker.test + +broker.test @@ -623,8 +623,8 @@ t28 - -ide-js.test + +ide-js.test @@ -632,8 +632,8 @@ t29 - -shot-review.test + +shot-review.test @@ -641,8 +641,8 @@ t30 - -check_callout_evidence + +check_callout_evidence @@ -650,8 +650,8 @@ e1 - -check_examples + +check_examples @@ -659,8 +659,8 @@ e2 - -gen_attribute_probes + +gen_attribute_probes @@ -668,8 +668,8 @@ e3 - -census_attributes + +census_attributes @@ -677,8 +677,8 @@ e4 - -sweep_attributes + +sweep_attributes @@ -686,8 +686,8 @@ e5 - -package_tests + +package_tests @@ -695,8 +695,8 @@ i1 - -addin_test + +addin_test @@ -704,8 +704,8 @@ i2 - -ide_test + +ide_test @@ -713,8 +713,8 @@ i3 - -try_help_addin + +try_help_addin @@ -722,8 +722,8 @@ i4 - -shoot_docs + +shoot_docs @@ -731,8 +731,8 @@ i5 - -imagestrip + +imagestrip @@ -740,8 +740,8 @@ i8 - -probe_theme_semicolon + +probe_theme_semicolon @@ -749,80 +749,71 @@ i7 - -svgshot/replay - - - - - -i9 - - -svgshot/sheet + +svgshot/replay - + i10 - - -shot_review + + +shot_review - + i11 - - -svgshot/chromeshot + + +svgshot/chromeshot - + i12 - - -svgshot/chrome_try + + +svgshot/chrome_try - + d1 - - -bug_repro + + +bug_repro - + d2 - - -vb6run + + +vb6run - + d3 - - -recheck_callouts + + +recheck_callouts - + d4 - - -ide_js + + +ide_js @@ -895,10 +886,9 @@ - - - - + + + diff --git a/docs/Documentation/Tools-IDE.md b/docs/Documentation/Tools-IDE.md index afa4829be..f1a8cb0f2 100644 --- a/docs/Documentation/Tools-IDE.md +++ b/docs/Documentation/Tools-IDE.md @@ -144,7 +144,7 @@ Flags: - `--only` takes the pictures whose path under the output folder matches a regular expression, such as `Menu_File` or `IDE/Menu/`, each in both themes. `--out` is the folder those paths are under, `docs` by default. - `--diffs` names a folder, outside `docs`, for a difference picture of each updated picture: the file on disk, the new picture and their difference side by side, with the region that differs magnified underneath. A matching pixel is dark grey; a differing one is yellow for one grey level, shading to red for large differences. File names end in `.dark` or `.light`. A `.capture-` file is written for each two captures of one state that disagree, a `.noise` file for a picture left as it is because it differs from the file only by that variation, and a `.restored` file, the file and the picture at `HEAD`, for a picture put back. - `--against` names the git revision a capture is compared with first, `HEAD` by default; git runs in the `--out` folder, and reads the run's pictures in one process. With the default, an output folder outside git is compared with its files only; a revision given that cannot be read is refused. `--against-disk` compares with the file on disk only. -- `--cleanup` starts no IDE and no browser. Every PNG under the output folder that git reports modified against the revision (`--against`, `HEAD` by default) and that is within the noise of the revision's is put back as the revision has it, with its SVG as a restored picture's is, so that only real changes stay in the working folder. An added or a deleted picture, one that differs by more than the noise, and one whose SVG alone changed are real changes and are left alone. It prints each path it puts back and a count of those, the real changes and the added and deleted pictures it skipped. `--dry-run` lists them and changes nothing. `--only` chooses a PNG when the expression matches its dark path or its `.light.png`; `--out` and `--against` apply, and the flags that need an IDE are refused. The noise is the same test, in `scripts/lib/shot-change.mjs`, that the capture and the change sheet of [`sheet.mjs --against`](#svg-sheet) apply. +- `--cleanup` starts no IDE and no browser. Every PNG under the output folder that git reports modified against the revision (`--against`, `HEAD` by default) and that is within the noise of the revision's is put back as the revision has it, with its SVG as a restored picture's is, so that only real changes stay in the working folder. An added or a deleted picture, one that differs by more than the noise, and one whose SVG alone changed are real changes and are left alone. It prints each path it puts back and a count of those, the real changes and the added and deleted pictures it skipped. `--dry-run` lists them and changes nothing. `--only` chooses a PNG when the expression matches its dark path or its `.light.png`; `--out` and `--against` apply, and the flags that need an IDE are refused. The noise is the same test, in `scripts/lib/shot-change.mjs`, that the capture applies. - `--jobs` is how many IDEs run at once, 6 by default and at most 16. Each runs on a private desktop (a slot from [`tbbroker`](Tools-Compiler#tbbroker)) with a work folder and an install copy of its own, and a DevTools port Windows picks. The setups wait in a queue, the longest first, and the three long ones (no-project, sample and customcontrols) are cut into three parts, each in an IDE of its own. Every line of output starts with the setup or part it is from. `--jobs 1` runs each setup whole, one after another. - The help setup's slot also carries a port from the broker for the add-in's detached window, which the add-in has to be told before it binds it. The add-in's saved settings (`tbDocsHelp`) are emptied for the run and, with the IDE's project state, put back at the end. - `--svg` also draws each picture as SVG, from the page as it stands at the capture, and writes it beside the PNG as `X.svg` when it is close enough to the PNG (see [A picture as SVG](Authoring#a-picture-as-svg)). An SVG already there is rewritten only when its PNG is. It needs Python with fontTools. What the SVG is drawn from --- the page's layout, styles and measurements --- is saved for each picture as a *bundle* in the folder `--bundles` names, `.svgshot-bundles` in the repository by default, so that [`replay.mjs`](#replay) can draw the SVG again without the IDE. Git ignores that folder, and it must stay outside `docs`: a bundle holds the Windows user name. @@ -244,32 +244,6 @@ Takes a public page through the [Chrome extension](#svgshot-extension) with no p Exit codes: **0** the capture was saved and the page is as it was found; **1** the panel reported a failure, or the page was not put back; **2** the tool could not run. -## sheet.mjs -{: #svg-sheet } - - node scripts/svgshot/sheet.mjs --out [--docs ] [--bundles ] [--only ] [--all] [--jobs N] - node scripts/svgshot/sheet.mjs --out --against [--docs ] [--only ] - -Writes a page that shows how far each picture's SVG is from its PNG, to look at in a browser. By default it shows every picture under `docs` that has no SVG beside it, which is the list of pictures the SVG converter still draws wrongly. The page is `index.html` in the folder `--out` names, with the pictures it shows in its `pictures` folder, so it opens from the disk with no server. - -Each picture that has a bundle is drawn again from it, with the converter as it is now, as [`replay.mjs`](#replay) draws it, and compared with its PNG in the same way: the share of its pixels more than 96 grey levels off the PNG's, with a shift of one pixel allowed. Those pictures come first, the worst first, each with its path, theme, size, how far off it is, and the PNG, the SVG's render and a map of the differences side by side. Selecting a picture opens it at full size. A picture whose PNG has changed since its bundle was saved is drawn all the same, with a note. The pictures with no bundle follow, as small pictures. - -`--all` shows every picture, also those that have an SVG: a picture with a bundle is drawn again from it, and one without a bundle has its SVG file compared as it is. `--only` takes the pictures whose path under `docs` matches a regular expression, a light picture's path ending in `.light.png`. `--docs` is the folder the pictures are in, `docs` by default, and `--bundles` the bundle folder, `.svgshot-bundles` by default, where new font cuts are kept as `replay.mjs` keeps them. `--jobs` is how many processes draw at once, by default half the logical processors and at most 8. The tool starts no IDE and writes nothing under `docs`. - -**`--against `** writes a page of another kind: it compares each PNG under `docs` with the same file at a git revision (a commit, a branch, a tag, `HEAD`), to review what a screenshot run rewrote. Git runs in the `--docs` folder, so that folder's own repository answers, and the folder as it is on disk is compared with the revision, tracked and untracked files alike. Each picture that differs is shown as the revision has it, as it is now and as a map of the differences, each opening at full size, with its path, theme, both sizes and the share of its pixels that changed by more than 16 grey levels. The map is dark grey where the pictures agree, yellow for a difference of one grey level and red for 128 or more. Pictures of two sizes are compared aligned at the top left over the area they share, and the row says so; the map shows the whole of the larger picture, a pixel only the old picture has cyan and one only the new picture has magenta. The page opens with a heading that names the revision and its commit, then lists: - -1. the changed pictures, most changed first; -1. the pictures that differ from the revision only within the noise rule of [`shoot_docs.mjs`](#shoot-docs) (no pixel more than 16 grey levels off, and at most 0.5% of the pixels off at all). That tool never writes a capture within that rule of a file, so such a picture was most likely rewritten in error. This section shows one `git checkout -- ` command that would restore them all, with paths from the repository's root, and the [`shoot_docs.mjs --cleanup`](#shoot-docs) command that would restore them with their SVGs. The tool only shows them and never runs them; -1. the added pictures, which are new in the working folder, and then the deleted ones, each with a single picture. - -A picture with an entry in `test/shots/manifest.json` is judged by it on either page, as [`shoot_docs.mjs`](#shoot-docs) and its `--cleanup` judge it: an SVG by its own bar, a PNG by its own noise rule, and either by a review's decision about the same bytes. A picture listed within noise is then exactly one that `--cleanup` puts back. Its card says what its entry changes, and its bar marks its own limit. The file is read only when `--docs` is `docs`. - -It compares PNG with PNG: no SVG is drawn, no bundle is read and no browser starts, so a run over several hundred pictures takes about half a minute. `--against` is not combined with `--all`, `--bundles` or `--jobs`; `--only` and `--docs` apply as before. A revision the repository does not have, or a `--docs` folder outside a git working folder, is refused before anything is written. - -The pictures on the page are drawn without the check for the Windows user name, so the page and its pictures can show it. So the folder may not be under `docs`, nor inside a git working folder at a path git does not ignore; a folder that already holds files must hold an earlier page of this tool, which is replaced. - -Exit codes: **0** the page was written; **1** the page was written, but a picture could not be drawn or compared, and is listed with the reason; **2** the tool could not run: a refused command line, a refused folder, no bundle folder, no browser, no such revision, a `test/shots/manifest.json` it cannot read, or a crash. - ## shot_review.mjs {: #shot-review } @@ -284,7 +258,7 @@ The tool works in a *session*: a folder in `.shot-review` at the repository's ro **The overview** (`/`) shows every picture the session's runs took or drew, as cards in groups: in progress, needs a look, changed (most changed first), only noise, changed outside the runs, unchanged, and added, deleted or failed. *Needs a look* holds the pictures whose decision a person should check, chosen from the regions of the picture that changed: a capture taken although only a fringe or a caret changed, or only a word or two; a capture kept as noise although a block of it changed; an SVG accepted although a part of it is missing, or refused for a fringe alone. *Changed outside the runs* holds the pictures under `docs` that differ from the baseline although no run of the session reported them, such as a retake from a terminal. Each card shows a chip for each decision, why the picture needs a look, and its allowances. Filters show only the pictures that need a look, those with an allowance or a decision (*Overridden*), or those with no SVG. **Resume at** goes back to where the review of *Needs a look* was left. -**All pictures** (`/all`) shows every picture `shoot_docs.mjs` takes (the table that [`shoot_docs.mjs --list`](#shoot-docs) prints) and the six of the [Chrome extension](#svgshot-extension), as the working folder has it, whatever any session did. So it is the page to open after a commit, when the overview of the new session is empty. Each card shows the picture's PNG and whether it has an SVG, the build `test/shots/manifest.json` records for it, and its allowances. Its groups are the pictures with no SVG that are of a program's window, the other pictures with no SVG, those the table names that are not under `docs`, those with an allowance or a decision, and those with an SVG. A picture with no SVG says why: a program's window, or what the newest verdict of this session or of an archived one said, such as an SVG refused for how far it was off its PNG, with the run and session it is from. When no verdict says, the card says so. **Judge their SVGs again from their bundles** replays the SVGs of the pictures with no SVG that have a bundle, with `--recheck`. A card opens the picture's page of verdicts when the session has one, and otherwise a page that shows the picture at the baseline, the file and its SVG, with **Retake this picture** and **Replay its SVG**. +**All pictures** (`/all`) shows every picture `shoot_docs.mjs` takes (the table that [`shoot_docs.mjs --list`](#shoot-docs) prints) and the six of the [Chrome extension](#svgshot-extension), as the working folder has it, whatever any session did. So it is the page to open after a commit, when the overview of the new session is empty. Each card shows the picture's PNG and whether it has an SVG, the build `test/shots/manifest.json` records for it, and its allowances. Its groups are the pictures with no SVG that are of a program's window, the other pictures with no SVG, those the table names that are not under `docs`, those with an allowance or a decision, those with no automated capture, and those with an SVG. A picture with no SVG says why: a program's window, or what the newest verdict of this session or of an archived one said, such as an SVG refused for how far it was off its PNG, with the run and session it is from. When no verdict says, the card says so. **Judge their SVGs again from their bundles** replays the SVGs of the pictures with no SVG that have a bundle, with `--recheck`. A card opens the picture's page of verdicts when the session has one, and otherwise a page that shows the picture at the baseline, the file and its SVG, with **Retake this picture** and **Replay its SVG**. *No automated capture* holds every other image under `docs`, such as a picture replaced by hand, to look at: no run can retake or judge one, so its page shows the file, and the picture at the baseline when that differs. What a script makes (a diagram's SVG, the build's chart, a video's poster frame) and the favicon are not listed. **A picture's page** compares the picture at the baseline with the new capture: side by side, by a swipe, by blinking between them, and as a difference map, with the SVG against its PNG and its own map. Below them, each region that changed is cropped and enlarged. The page's choices: diff --git a/docs/Documentation/Tools-Toolchain-Tests.md b/docs/Documentation/Tools-Toolchain-Tests.md index b954aa711..50ce048f4 100644 --- a/docs/Documentation/Tools-Toolchain-Tests.md +++ b/docs/Documentation/Tools-Toolchain-Tests.md @@ -277,7 +277,7 @@ Unit tests for the SVG screenshot converter. They cover: - The [Chrome extension](Tools-IDE#svgshot-extension), without a Chrome: that every module it loads imports no Node module and stays inside its folder, the files its manifest names, how `scripts/svgshot/chrome/take.mjs` lays a page out at 1x on a display of any scale, its connection through `chrome.debugger`, its capture file, and the six pictures it names. - The private words: masking them in any case and longest first, what counts as shown, and what [`chromeshot.mjs`](Tools-IDE#chromeshot) refuses before it writes anything. - `scripts/svgshot/trim.mjs`, which trims a capture of the whole window to its picture: finding an element by the part of CSS the table uses, the area, what it refuses, and the PNG and the bundle cut to it. -- `scripts/svgshot/redraw.mjs`, shared by [`replay.mjs`](Tools-IDE#replay) and [`sheet.mjs`](Tools-IDE#svg-sheet): a picture drawn again from its bundle, or listed as needing a retake, and failed when its SVG holds the Windows user name unless the caller turns that check off; and the list of pictures, with the build's output trees left out. `scripts/svgshot/sheets.mjs`, built from the pieces in `scripts/lib/shot-views.mjs`: the folders a sheet may not be written to, and the sheet's page, worst picture first. The sheet of changes against a git revision (`sheet.mjs --against`) is tested the same way, with no git and no browser: the change list read from git's output (the PNGs only, untracked ones added), the calls made to git, the noise rule of `scripts/lib/shot-change.mjs` and its comparison of pictures of one size and of two, the difference map's colours, the order of the rows, the commands that restore the pictures within noise, and the page. Both sheets judge a picture with its allowance and a review's decision from the manifest, as `--cleanup` does, and show them on its card. +- `scripts/svgshot/redraw.mjs`, which [`replay.mjs`](Tools-IDE#replay) draws with: a picture drawn again from its bundle, or listed as needing a retake, and failed when its SVG holds the Windows user name. What differs from a git revision is tested the same way, with no git and no browser: the change list read from git's output (the PNGs only, untracked ones added), the calls made to git, the noise rule of `scripts/lib/shot-change.mjs`, a picture's allowance applied to it as `--cleanup` applies it, and the colours of the difference map, for pictures of one size and of two. - `scripts/lib/shot-revision.mjs`, which [`shoot_docs.mjs`](Tools-IDE#shoot-docs) compares a new capture with: what becomes of a capture with the picture at a git revision or without one, within the noise of it, of the file on disk or of neither; the SVG that goes with a picture put back as the revision has it; which modified pictures `--cleanup` puts back; git's batch output, a name with spaces and a missing one included; and, in a scratch git repository, a revision's files read in one process and a text file put back as a checkout writes it, with the index left alone. - `scripts/lib/shot-policy.mjs`, which decides what becomes of a capture and of its SVG, and `scripts/lib/shot-manifest.mjs`, which reads and writes `test/shots/manifest.json`: a light picture compared with the dark one first; a picture's own noise rule and SVG bar passed to the comparison; a review's decision used for the bytes it was made on and for no others, in a run and in `--cleanup`; the manifest written in a fixed order and read back the same, from an LF or a CRLF checkout; every malformed entry refused with its key named; a build recorded and the file saved only when it changes; and the repository's own manifest read. - The strength map, a byte per pixel saying how far one picture is from another, which `scripts/lib/shot-change.mjs` makes of two captures and `scripts/svgshot/diff.mjs` of an SVG against its PNG: the share of its pixels at a level, with rectangles left out, and its regions of change. The tests draw small maps by hand: a line up to 4 pixels thick leaves no core after the erosion and a block keeps its middle, the strokes of a word are joined into one block, every changed pixel is kept along the picture's edge, and regions that touch at a corner are one. `scripts/lib/shot-queue.mjs` then says which pictures the review tool shows first: a capture taken with nothing surviving or only a word or two, a capture kept as within noise with something 2 grey levels off or more surviving, an SVG accepted with a part surviving or refused with nothing; and the regions of a capture measured against the picture it was compared with, when that is of its size. diff --git a/docs/Documentation/Tools.md b/docs/Documentation/Tools.md index 4269074c6..1dc21bf5b 100644 --- a/docs/Documentation/Tools.md +++ b/docs/Documentation/Tools.md @@ -17,7 +17,7 @@ Reference for every executable in the documentation repository. This page covers ## Tool groups -![Eight rounded boxes, one per group of tools, each holding a smaller rounded box for every tool in the group. Batch wrappers holds the nine .bat files at the repository root. Build and Generation holds tbdocs, render-book, compare_trees and the generators of committed files. Site Checks holds the link, freshness, diagram and accessibility checks. Toolchain Tests, the largest group, holds the gates test.bat runs. Compiler Harness holds tbbuild, tbrun, impexp, tbbroker and the probes of the harness itself. Code Samples and Attributes holds check_examples and the three attribute tools. IDE Automation holds the add-in and IDE test runners, try_help_addin, shoot_docs, imagestrip, probe_theme_semicolon, the SVG replay and sheet, and the Chrome extension's chromeshot and chrome_try. Defect Reproducers holds bug_repro and vb6run. Each group's name links to its page, and each tool's box to its entry.](Images/Tools-Groups.svg) +![Eight rounded boxes, one per group of tools, each holding a smaller rounded box for every tool in the group. Batch wrappers holds the nine .bat files at the repository root. Build and Generation holds tbdocs, render-book, compare_trees and the generators of committed files. Site Checks holds the link, freshness, diagram and accessibility checks. Toolchain Tests, the largest group, holds the gates test.bat runs. Compiler Harness holds tbbuild, tbrun, impexp, tbbroker and the probes of the harness itself. Code Samples and Attributes holds check_examples and the three attribute tools. IDE Automation holds the add-in and IDE test runners, try_help_addin, shoot_docs, imagestrip, probe_theme_semicolon, the SVG replay, and the Chrome extension's chromeshot and chrome_try. Defect Reproducers holds bug_repro and vb6run. Each group's name links to its page, and each tool's box to its entry.](Images/Tools-Groups.svg) - [Build and Generation Tools](Tools-Build) -- `tbdocs`, the PDF render driver, the build comparison, and the generators of committed files. - [Site Checks](Tools-Site-Checks) -- the link, freshness, diagram and accessibility checks over a built site. @@ -125,7 +125,7 @@ The tests the toolchain has to pass. Thirty-two steps, each stopping the run if 8. [`test/strftime.test.mjs`](Tools-Toolchain-Tests#strftime-test) --- unit tests for the footer's date formatter, which no build calls. 9. [`test/png.test.mjs`](Tools-Toolchain-Tests#png-test) --- unit tests for the pictures of a bug reproducer: PNG decoding, comparing and the side-by-side image, the files behind `images` and `expect.imagesDiffer`, and the refusals of `bug_repro.mjs`. 10. [`test/compact-image.test.mjs`](Tools-Toolchain-Tests#compact-image-test) --- unit tests for what an embedded image keeps: an editor's metadata goes, a notice of ownership and terms stays. The half that runs [`imagestrip`](Tools-IDE#imagestrip) is skipped unless its exe is named. -11. [`test/svgshot.test.mjs`](Tools-Toolchain-Tests#svgshot-test) --- unit tests that an SVG screenshot is written on one line, that its underlines are placed as Chromium places them, that a background image is sized by its bytes, that a frame's page is placed inside its frame, that a web font is found and cut as the page uses it, that the page's own `` icons are found and kept apart, that a colour filter is baked into the colours it paints, and that a picture is drawn again from its bundle and put on the sheet of pictures as the SVG tools need. +11. [`test/svgshot.test.mjs`](Tools-Toolchain-Tests#svgshot-test) --- unit tests that an SVG screenshot is written on one line, that its underlines are placed as Chromium places them, that a background image is sized by its bytes, that a frame's page is placed inside its frame, that a web font is found and cut as the page uses it, that the page's own `` icons are found and kept apart, that a colour filter is baked into the colours it paints, and that a picture is drawn again from its bundle as the SVG tools need. 12. [`test/shot-review.test.mjs`](Tools-Toolchain-Tests#shot-review-test) --- unit tests for the [screenshot review tool](Tools-IDE#shot-review): its session, what its pages show, its writes under `docs`, and its server, with a stand-in run in place of the screenshot tools and the commit in a scratch repository. 13. [`test/example-batches.test.mjs`](Tools-Toolchain-Tests#example-batches-test) --- runs `check_examples.mjs`'s probes, which test how samples are batched and how a crashed batch is cut down, without an IDE. 14. [`test/ide-folders.test.mjs`](Tools-Toolchain-Tests#ide-folders-test) --- unit tests for the temp folder and profile an IDE leaves behind, and that ending it removes them and no other folder, without an IDE. diff --git a/docs/Documentation/_Images/choose-workflow.af b/docs/Documentation/_Images/choose-workflow.af deleted file mode 100644 index 93dd1597d..000000000 Binary files a/docs/Documentation/_Images/choose-workflow.af and /dev/null differ diff --git a/docs/Documentation/_Images/compare-changes.af b/docs/Documentation/_Images/compare-changes.af deleted file mode 100644 index ca3d7488b..000000000 Binary files a/docs/Documentation/_Images/compare-changes.af and /dev/null differ diff --git a/docs/Documentation/_Images/confirm-merge.af b/docs/Documentation/_Images/confirm-merge.af deleted file mode 100644 index b94a24225..000000000 Binary files a/docs/Documentation/_Images/confirm-merge.af and /dev/null differ diff --git a/docs/Documentation/_Images/create-pull-request.af b/docs/Documentation/_Images/create-pull-request.af deleted file mode 100644 index ef964f721..000000000 Binary files a/docs/Documentation/_Images/create-pull-request.af and /dev/null differ diff --git a/docs/Documentation/_Images/merge-pull-request.af b/docs/Documentation/_Images/merge-pull-request.af deleted file mode 100644 index 8ca452603..000000000 Binary files a/docs/Documentation/_Images/merge-pull-request.af and /dev/null differ diff --git a/docs/Documentation/_Images/run-workflow.af b/docs/Documentation/_Images/run-workflow.af deleted file mode 100644 index 76a197e67..000000000 Binary files a/docs/Documentation/_Images/run-workflow.af and /dev/null differ diff --git a/docs/_config.yml b/docs/_config.yml index 1e083899d..cf88b91f1 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -93,8 +93,8 @@ offline_exclude: # what may reach a published tree, enforced unconditionally inside the # build; see WIP.Build.md's "The publish allowlist". What belongs here is the # noise a contributor should not have to see refused: source files that -# sit beside the pages they produce (.scss, .dot, .af) and the build's -# own output trees. +# sit beside the pages they produce (.scss, .dot) and the build's own +# output trees. # # Patterns that start with * must be quoted so YAML does not interpret them # as alias references. @@ -145,27 +145,16 @@ search: exclude: # Underscore-prefixed entries AT THE SOURCE ROOT -- _config.yml, # _book.yml, _sass, and every build-output tree (_site*, _serve*, _pdf). + # + # At the root only, never a blanket `**/_*/**`. That rule silently swallows + # every page under Reference/Built-In/AppGlobalClassObject/_App/ -- 37 of + # them -- because the twinBASIC interface really is named `_App`, after the + # COM hidden-interface convention, and the folder is named for it, and + # underscore-prefixed pages such as + # Reference/Built-In/CustomControls/Framework/_CustomControlContext.md. + # Nothing reports the loss: excluded files are not missing files. - _* - _*/** - # Affinity sources, kept beside the pages they illustrate. Only the - # exported .png under the sibling Images/ folder is published. - # - # Scoped to _Images rather than the `**/_*/**` this used to be. That - # blanket rule silently swallowed every page under - # Reference/Built-In/AppGlobalClassObject/_App/ -- 37 of them -- because - # the twinBASIC interface really is named `_App`, after the COM - # hidden-interface convention, and the folder is named for it. Nothing - # reported the loss: excluded files are not missing files. - # - # Note the rule matches a _Images *directory*, so it does not touch - # underscore-prefixed *pages* such as - # Reference/Built-In/CustomControls/Framework/_CustomControlContext.md, - # which are published and always have been. - - "**/_Images/**" - # Defensive, now that the underscore rule no longer covers them: the - # Affinity sources are the only thing _Images holds, and a stray one - # filed anywhere else must not ship either. - - "**/*.af" # Defensive: caches and unrelated trees that should never be in docs/. - "**/.git/**" - "**/node_modules/**" diff --git a/scripts/lib/cli-cases.mjs b/scripts/lib/cli-cases.mjs index 6652b6ce2..90fca80aa 100644 --- a/scripts/lib/cli-cases.mjs +++ b/scripts/lib/cli-cases.mjs @@ -11,7 +11,6 @@ // A new tool goes into HELP_TOOLS and REFUSALS; building the list throws if // the two disagree. -import { tmpdir } from "node:os"; import path from "node:path"; import { REPO_ROOT } from "../../lib/repo-paths.mjs"; @@ -459,7 +458,6 @@ const HELP_TOOLS = { "scripts/svgshot/chromeshot.mjs": null, "scripts/svgshot/pixels.mjs": null, "scripts/svgshot/replay.mjs": null, - "scripts/svgshot/sheet.mjs": null, "scripts/tbbuild.mjs": null, "scripts/tbrun.mjs": null, "scripts/vb6run.mjs": null, @@ -549,7 +547,6 @@ const REFUSALS = { "scripts/svgshot/chromeshot.mjs": ["out"], "scripts/svgshot/pixels.mjs": ["beside"], "scripts/svgshot/replay.mjs": ["bundles"], - "scripts/svgshot/sheet.mjs": ["out"], "scripts/tbbuild.mjs": ["ide"], "scripts/tbrun.mjs": ["ide"], "scripts/vb6run.mjs": ["vb6"], @@ -1186,33 +1183,6 @@ bad( bad(tool, ["analyze", "--check"], "--check does not apply to analyze\n"); bad(tool, ["analyze", "--out", "x.json"], "--out does not apply to analyze\n"); } -// sheet.mjs needs --out, reads its values, then refuses a folder under docs or one git -// would take: the sheet can hold the Windows user name. Each is refused before it -// lists a picture or starts a browser. -{ - const tool = "scripts/svgshot/sheet.mjs"; - bad(tool, [], "sheet: --out is required: the folder for the sheet\n"); - bad(tool, ["--only", "x"], "sheet: --out is required: the folder for the sheet\n"); - bad(tool, ["--out", "x", "--jobs", "0"], "--jobs expects a whole number from 1 to 32, got: 0\n"); - bad(tool, ["--out", "x", "--only", "("], REGEX_REASON("--only", "(")); - const refused = (why) => - new RegExp(`^${literal("sheet: --out must not be under docs nor where git would take it: ")}.+${why}\\n$`); - bad(tool, [`--out=${path.join(REPO_ROOT, "docs", "sheet")}`], refused("is under .+")); - bad(tool, [`--out=${path.join(REPO_ROOT, "scripts", "sheet")}`], refused("at a path git does not ignore")); - // --against is a sheet of its own: it excludes the options of the other, and a revision the - // repository of the docs folder does not have is refused before anything is written. - const into = `--out=${path.join(tmpdir(), "sheet-cli-case")}`; - bad(tool, [into, "--against", "HEAD", "--all"], "--against and --all cannot be given together\n"); - bad(tool, [into, "--against", "HEAD", "--jobs", "2"], "--against and --jobs cannot be given together\n"); - bad(tool, [into, "--against", "HEAD", "--bundles", "x"], "--against and --bundles cannot be given together\n"); - bad(tool, [into, "--against"], "--against needs a value\n"); - bad( - tool, - [into, "--against", "no-such-revision-x"], - new RegExp(`^${literal("sheet: no revision no-such-revision-x in the git repository of ")}.+\\n$`), - ); - bad(tool, [into, "--against=--output=x"], `sheet: not a revision: "--output=x"\n`); -} for (const made of BAD_VALUES) { CASES.push(made); LEAVES_EMPTY.add(made); diff --git a/scripts/lib/shot-change.mjs b/scripts/lib/shot-change.mjs index 631fdc4b5..9f124721d 100644 --- a/scripts/lib/shot-change.mjs +++ b/scripts/lib/shot-change.mjs @@ -1,7 +1,7 @@ // How two versions of a screenshot differ, as numbers and as a picture: the rule that // shoot_docs.mjs uses to tell a new capture from the file on disk only by a capture's -// noise (withinNoise), and the comparison that svgshot/sheet.mjs --against shows for a -// picture and the same file at a git revision (compareImages, changeMap). +// noise (withinNoise), and the map the screenshot review tool shows for a picture and the +// same file at the session's baseline (changeMap). // // Images are what png.mjs's decodePng returns: {width, height, rgba}. @@ -189,58 +189,6 @@ export function changeRegions(strength, options) { return regions.sort((a, b) => b.core - a.core || b.pixels - a.pixels || a.y0 - b.y0 || a.x0 - b.x0); } -/** - * Compares two images aligned at the top left, over the area they share; a pixel only - * one of them has counts as changed beyond noise. Returns - * {sameSize, old: [w, h], new: [w, h], canvas: [w, h], common: [w, h], total, differing, - * beyond, faint, pctBeyond, pctDiffering, levels, noiseOnly}: `total` the pixels of the larger - * canvas, `differing` those that differ at all, `beyond` those that differ by more - * than `levels` or exist in one picture only, `faint` those that differ by 1 to - * `levels`, the two percentages of `total` (not rounded), and `noiseOnly` whether - * the pictures are of one size and within the noise rule `rule` (withinNoise's, a picture's - * pngRule; `levels` is its levels, NOISE_LEVELS by default), identical ones included. The - * rule's rectangles are left out of `noiseOnly` only. - */ -export function compareImages(A, B, rule = {}) { - const levels = rule.levels ?? NOISE_LEVELS; - const cw = Math.min(A.width, B.width); - const ch = Math.min(A.height, B.height); - const w = Math.max(A.width, B.width); - const h = Math.max(A.height, B.height); - const total = w * h; - let differing = 0; - let beyond = 0; - let faint = 0; - for (let y = 0; y < ch; y++) { - for (let x = 0; x < cw; x++) { - const d = pixelDiff(A, (y * A.width + x) * 4, B, (y * B.width + x) * 4); - if (!d) continue; - differing++; - if (d > levels) beyond++; - else faint++; - } - } - const only = total - cw * ch; - differing += only; - beyond += only; - const sameSize = A.width === B.width && A.height === B.height; - return { - sameSize, - old: [A.width, A.height], - new: [B.width, B.height], - canvas: [w, h], - common: [cw, ch], - total, - differing, - beyond, - faint, - pctBeyond: (beyond / total) * 100, - pctDiffering: (differing / total) * 100, - levels, - noiseOnly: sameSize && withinNoise(A, B, rule), - }; -} - // A pixel over white, as [r, g, b]. const overWhite = (img, i) => { const a = img.rgba[i + 3]; diff --git a/scripts/lib/shot-pages.mjs b/scripts/lib/shot-pages.mjs index 1b43511fb..5fee0eaf2 100644 --- a/scripts/lib/shot-pages.mjs +++ b/scripts/lib/shot-pages.mjs @@ -44,7 +44,7 @@ export const hrefs = { log: (n) => `/log/${n}`, /** The session's runs, and the forms that start one. */ runs: "/runs", - /** Every picture shoot_docs.mjs takes, as the working tree has it, whatever any session did. */ + /** Every picture under docs, as the working tree has it, whatever any session did. */ all: "/all", /** What a commit of the session takes, and its message. */ commitPage: "/commit", @@ -970,9 +970,13 @@ ${p.outside === "deleted" ? "" : actionsHtml(runButtons(p.out, busy, { replay: f const whereText = (where) => where ? `run ${where.run} of ${where.session ? `session ${esc(where.session)}` : "this session"}` : ""; +// What the page of every picture says of an image no shot takes. +const NOT_TAKEN = "No tool takes this image: it is replaced by hand, so no run can retake or judge it."; + // The chips of a picture of the page of every picture (shot-review.mjs's allPictures), `entry` // its entry in the manifest, `bundled` whether the bundle cache has a bundle of it (null: no cache). function everyChips(p, entry, bundled) { + if (p.uncaptured) return chipHtml("no automated capture", "", NOT_TAKEN); const chips = []; if (!p.png) chips.push(chipHtml("no PNG under docs", "fail", "the table names it, and docs has no such file")); else if (p.window) chips.push(chipHtml("PNG only: a program's window", "", p.reason?.text ?? "")); @@ -999,7 +1003,7 @@ const reasonHtml = (p) => : `

${esc(p.reason.text)}${p.reason.where ? ` (${whereText(p.reason.where)})` : ""}

`; /** - * The page of every picture shoot_docs.mjs takes (shot-review.mjs's allPictures): `groups` its + * The page of every picture under docs (shot-review.mjs's allPictures): `groups` its * groups, `error` why the table could not be read, or null; `baseline` the session's; * `bundled(out)` whether the bundle cache has a bundle of a picture (null: no cache); `entry(out)` * a picture's entry in the manifest, or null; `busy` what keeps a run from starting, or null; @@ -1019,15 +1023,17 @@ export function allHtml({ // (a bundle file is decompressed): asked once each, for those only const asked = new Map(); const bundledIf = (p) => { - if (!p.png || p.svg || p.window) return null; + if (!p.png || p.svg || p.window || p.uncaptured) return null; if (!asked.has(p.out)) asked.set(p.out, bundledAt(p.out)); return asked.get(p.out); }; const card = (p) => { const link = hrefs.picture(p.out); + const pick = p.uncaptured + ? "" + : `\n`; return `
- -${p.png ? `${esc(p.out)}` : ""}

${esc(p.out)}

+${pick}${p.png ? `${esc(p.out)}` : ""}

${esc(p.out)}

${everyChips(p, entry(p.out), bundledIf(p))}

${reasonHtml(p)}
`; @@ -1036,8 +1042,11 @@ ${reasonHtml(p)} const cards = `
${g.pictures.map(card).join("\n")}
`; - const pickAll = ``; - const heading = `${esc(g.title)} (${g.pictures.length}) ${pickAll}`; + const pickAll = + g.key === "uncaptured" + ? "" + : ` `; + const heading = `${esc(g.title)} (${g.pictures.length})${pickAll}`; // the SVGs of the pictures with no SVG judged again from their bundles: a replay with --recheck const replayable = g.key === "nosvg" ? g.pictures.filter((p) => bundledIf(p) !== false).map((p) => p.out) : []; const replay = replayable.length @@ -1068,7 +1077,7 @@ ${replay}${cards}`; generator: REVIEW_GENERATOR, title: "Every picture", head: HEAD, - intro: `Every picture shoot_docs.mjs takes, as the working tree has it now, whatever any session did: its PNG and SVG under docs, the build the manifest records and its allowances, and, for one with no SVG, why, from the newest verdict of this session or an archived one that says. The session's baseline is ${esc(baseline.short)}.`, + intro: `Every picture under docs, as the working tree has it now, whatever any session did. For each one shoot_docs.mjs or a browser retake takes: its PNG and SVG, the build the manifest records and its allowances, and, for one with no SVG, why, from the newest verdict of this session or an archived one that says. The images no tool takes are listed too, to look at. The session's baseline is ${esc(baseline.short)}.`, summary: shown.map((g) => [g.title, g.pictures.length]), contents: shown.map((g) => `
  • ${esc(g.title)} (${g.pictures.length})
  • `).join("\n"), body: `${topNav("all")} @@ -1095,7 +1104,12 @@ export function plainHtml({ p, place, prev, next, files, entry = null, baseline, }${place.index + 1} of ${place.total} · All pictures${ next ? `` : "" }`; - const body = `${pager} + const body = p.uncaptured + ? `${pager} +

    ${everyChips(p)}

    +

    ${esc(NOT_TAKEN)}

    +
    ${figs.join("\n")}
    ` + : `${pager}

    ${esc(sizeText(files.docs?.size ?? files.head?.size ?? null))}; ${everyChips(p, entry, bundled)}

    ${reasonHtml(p)}

    No run of this session reported this picture: it is shown as the working tree has it, with no verdict to override. A retake of it, or a replay of its SVG, through this tool judges it.

    @@ -1105,7 +1119,7 @@ ${actionsHtml(runButtons(p.out, busy, { replay: p.png && !p.window, bundled }))} generator: REVIEW_GENERATOR, title: p.out, head: HEAD, - intro: "A picture of the table of shots, as the working tree has it.", + intro: `${p.uncaptured ? "An image no tool takes" : "A picture of the table of shots"}, as the working tree has it.`, body, }).replace("", ``); } diff --git a/scripts/lib/shot-review.mjs b/scripts/lib/shot-review.mjs index f487d1609..3feb997bb 100644 --- a/scripts/lib/shot-review.mjs +++ b/scripts/lib/shot-review.mjs @@ -5,6 +5,7 @@ // and verdicts (shot-stage.mjs), and git's status (shot-revision.mjs), and passes in what else // the model needs to know, such as whether a file is under docs/. +import { THUMB_DIR_REL } from "../../builder/vendor-assets.mjs"; import { svgOf } from "./shot-apply.mjs"; import { SVG_FAITHFUL } from "./shot-policy.mjs"; import { WINDOW_WHY } from "./shot-stage.mjs"; @@ -301,7 +302,8 @@ export function appliedVerdict(v, done) { // The page of every picture (WIP.ShotReview.md, All pictures) shows the pictures as the working // tree has them, whatever any session did: every picture shoot_docs.mjs's table names // (shoot_docs.mjs --list), each with its PNG and SVG as they are under docs/, its build and -// allowances from the manifest, and for one with no SVG, why, from the newest verdict that says. +// allowances from the manifest, and for one with no SVG, why, from the newest verdict that says; +// and every other image under docs/, which no run can take. /** The groups of the page of every picture, in its order: [key, heading]. */ export const ALL_GROUPS = [ @@ -309,9 +311,19 @@ export const ALL_GROUPS = [ ["nosvg", "No SVG"], ["missing", "Not under docs"], ["overridden", "With an allowance or a review's decision"], + ["uncaptured", "No automated capture"], ["svg", "With an SVG"], ]; +// The images that are no pictures of the documentation to look at: what a script makes (a +// diagram's SVG, beside its DOT source; the build's Gantt chart; a video's poster frame) and the +// favicon, which never changes. +const NOT_LISTED = new Set(["assets/images/gantt.svg", "favicon.png"]); +const notListed = (out, exists) => + NOT_LISTED.has(out) || + out.startsWith(`${THUMB_DIR_REL}/`) || + (/\.svg$/i.test(out) && exists(out.replace(/\.svg$/i, ".dot"))); + /** The light picture of a dark one's path. */ const lightOf = (out) => out.replace(/\.png$/i, ".light.png"); @@ -346,16 +358,18 @@ export function noSvgReason(svg) { * pixels, and the page shows the dark one in both themes). `exists(path)` says whether a file is * under docs/, `entry(out)` a picture's entry in the manifest, or null, and `verdicts(out)` the * SVG verdicts any session gave it, newest first, [{svg, where}], `where` {session, run} (the - * session's id, null for the one being served). + * session's id, null for the one being served). `images` is every image file under docs/: each + * that no shot takes is listed too, as `uncaptured`, unless a script makes it (NOT_LISTED). * * Returns {pictures, groups}: each picture {out, setup, window, once, png, svg, bothThemes, - * build, reason, group}, `png` and `svg` whether each file is under docs/, `bothThemes` that the - * dark picture is shown in both themes, `build` the manifest's, and `reason` for a picture with - * no SVG {why, text, where}: the table's for a program's window, else the newest verdict's that - * says (noSvgReason), with where it is from, else {why: "unknown"}. `groups` is ALL_GROUPS with - * each one's pictures, [{key, title, pictures}]; the No SVG group is ordered by reason, then path. + * build, reason, group, uncaptured}, `png` and `svg` whether each file is under docs/, + * `bothThemes` that the dark picture is shown in both themes, `build` the manifest's, and `reason` + * for a picture of the table with no SVG {why, text, where}: the table's for a program's window, + * else the newest verdict's that says (noSvgReason), with where it is from, else {why: "unknown"}. + * `groups` is ALL_GROUPS with each one's pictures, [{key, title, pictures}]; the No SVG group is + * ordered by reason, then path. */ -export function allPictures({ shots, exists, entry = () => null, verdicts = () => [] }) { +export function allPictures({ shots, exists, entry = () => null, verdicts = () => [], images = [] }) { const pictures = []; for (const shot of shots) { const light = lightOf(shot.out); @@ -373,6 +387,7 @@ export function allPictures({ shots, exists, entry = () => null, verdicts = () = build: e?.build ?? null, reason: null, group: null, + uncaptured: false, }; if (!p.svg) { if (p.window) p.reason = { ...noSvgReason({ window: true }), where: null }; @@ -387,6 +402,23 @@ export function allPictures({ shots, exists, entry = () => null, verdicts = () = pictures.push(p); } } + const taken = new Set(shots.flatMap((shot) => [shot.out, lightOf(shot.out)]).flatMap((out) => [out, svgOf(out)])); + for (const out of images) { + if (taken.has(out) || notListed(out, exists)) continue; + pictures.push({ + out, + setup: null, + window: false, + once: false, + png: true, + svg: false, + bothThemes: false, + build: null, + reason: null, + group: "uncaptured", + uncaptured: true, + }); + } pictures.sort((a, b) => (a.out < b.out ? -1 : a.out > b.out ? 1 : 0)); const groups = ALL_GROUPS.map(([key, title]) => ({ key, title, pictures: pictures.filter((p) => p.group === key) })); groups diff --git a/scripts/lib/shot-revision.mjs b/scripts/lib/shot-revision.mjs index 130cc80d4..fd46be85a 100644 --- a/scripts/lib/shot-revision.mjs +++ b/scripts/lib/shot-revision.mjs @@ -3,10 +3,10 @@ // (or another revision) before the file on disk, so that a picture does not drift from the // repository's over several runs, each step within a capture's noise of the file before it; // and its --cleanup puts back every picture git reports modified that is within that noise of -// the revision's. svgshot/sheet.mjs --against lists the pictures that differ from a revision +// the revision's. The screenshot review tool lists the pictures that differ from a revision // and reads the revision's pictures here too. The noise rule itself is withinNoise, in // shot-change.mjs: every caller passes it in. And where a folder of pictures that may hold the -// Windows user name may be written (outputRefusal): a sheet, or a run's stage. And what the +// Windows user name may be written (outputRefusal): a run's stage. And what the // working tree changed, and a commit of some of it, for the screenshot review tool's commit. // // Git is run in the docs folder, so that the repository that holds it answers, whichever @@ -362,8 +362,8 @@ const inside = (dir, root) => { /** * Why `dir` may not take a folder of pictures that may hold the Windows user name, or * null: it is under one of `docsRoots`, or inside a git working tree at a path git does - * not ignore. A sheet (sheet.mjs draws its pictures without the check) and a run's stage - * (shot-stage.mjs: its bundles hold the page's text) must never be committed or published. `git` stands in for running git in the probes: + * not ignore. A run's stage (shot-stage.mjs: its bundles hold the page's text) must never be + * committed or published. `git` stands in for running git in the probes: * git(args, cwd) returns its exit code and output, {status, stdout}. */ export function outputRefusal(dir, docsRoots, git = runGit) { diff --git a/scripts/lib/shot-server.mjs b/scripts/lib/shot-server.mjs index 0bb8aa008..0e7138e36 100644 --- a/scripts/lib/shot-server.mjs +++ b/scripts/lib/shot-server.mjs @@ -21,9 +21,10 @@ // git's status), while no run runs and the baseline is HEAD; it closes the session, and the // server then serves the next one, whose baseline is the new commit. -import { existsSync, readFileSync, realpathSync, statSync } from "node:fs"; +import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from "node:fs"; import { createServer } from "node:http"; import path from "node:path"; +import { isOutputTree } from "../../lib/markdown-files.mjs"; import { DOCS_DIR, REPO_ROOT } from "../../lib/repo-paths.mjs"; import { createSseChannel } from "../../lib/sse.mjs"; import { readBundle } from "../svgshot/bundle.mjs"; @@ -61,7 +62,17 @@ import { kindOf, runOf, startRun } from "./shot-runs.mjs"; import { commandOf, optionOf, parseSession, readEvents, runPaths, sessionPaths } from "./shot-session.mjs"; import { readReviewed, readStrength, readVerdicts } from "./shot-stage.mjs"; -const TYPES = { ".png": "image/png", ".svg": "image/svg+xml" }; +const TYPES = { + ".png": "image/png", + ".svg": "image/svg+xml", + ".jpg": "image/jpeg", + ".jpeg": "image/jpeg", + ".gif": "image/gif", + ".webp": "image/webp", + ".bmp": "image/bmp", + ".ico": "image/x-icon", +}; +const isImage = (name) => Object.hasOwn(TYPES, path.extname(name).toLowerCase()); // How long the table of shots (shoot_docs.mjs --list) is used before it is read again: it changes // only with the tool's code. @@ -89,10 +100,26 @@ function closedSessionPictures(root) { return reviewPictures(runs).pictures; } -// A picture's or an SVG's path under docs/, as a URL gives it: forward slashes, no empty or -// parent segment. -const isDocsPath = (p) => - /^[^\\]+\.(png|svg)$/i.test(p) && !p.startsWith("/") && !p.split("/").some((s) => s === "" || s === ".."); +// A path under docs/ as a URL gives it: forward slashes, no empty or parent segment. +const isDocsFile = (p) => !p.includes("\\") && !p.startsWith("/") && !p.split("/").some((s) => s === "" || s === ".."); +// A picture's or an SVG's path, which a review can act on, and any image's, which it can only show. +const isDocsPath = (p) => /\.(png|svg)$/i.test(p) && isDocsFile(p); +const isDocsImage = (p) => isImage(p) && isDocsFile(p); + +// Every image under `root`, the build's output trees left out, as its path under it. +function imagesUnder(root) { + const found = []; + const walk = (dir, rel) => { + for (const e of readdirSync(dir, { withFileTypes: true })) { + if (!rel && isOutputTree(e.name)) continue; + const r = rel ? `${rel}/${e.name}` : e.name; + if (e.isDirectory()) walk(path.join(dir, e.name), r); + else if (e.isFile() && isImage(e.name)) found.push(r); + } + }; + walk(root, ""); + return found; +} const readIf = (file) => (existsSync(file) && statSync(file).isFile() ? readFileSync(file) : null); @@ -309,7 +336,7 @@ export function createReviewServer({ }); } async function everyPicture() { - return allPictures({ shots: await table(), exists, entry, verdicts: verdictsOf() }); + return allPictures({ shots: await table(), exists, entry, verdicts: verdictsOf(), images: imagesUnder(docsRoot) }); } async function allPage() { let all = null; @@ -330,8 +357,9 @@ export function createReviewServer({ }); } // The page of a picture no run of this session reported, from the page of every picture: the - // baseline's picture against the file, its SVG, why it has none, and its runs. Null when the - // table does not name it. + // baseline's picture against the file, its SVG, why it has none, and its runs. An image no shot + // takes is shown at its own size, not at half as a 2x shot is, and the baseline's copy only when + // it differs. Null when the page of every picture does not list it. async function plainPage(out) { let all; try { @@ -342,15 +370,17 @@ export function createReviewServer({ const place = neighbours(all.pictures, out); if (place.index < 0) return null; const p = all.pictures[place.index]; - const file = (src, bytes) => (bytes ? { src, size: pngSize(bytes) } : null); + const file = (src, bytes) => (bytes ? { src, size: p.uncaptured ? null : pngSize(bytes) } : null); + const atBaseline = revision.bytes(out); + const now = readIf(path.join(docsRoot, out)); return plainHtml({ p, place: { index: place.index, total: all.pictures.length }, prev: place.prev, next: place.next, files: { - head: file(hrefs.head(out), revision.bytes(out)), - docs: file(hrefs.docs(out), readIf(path.join(docsRoot, out))), + head: p.uncaptured && atBaseline?.equals(now) ? null : file(hrefs.head(out), atBaseline), + docs: file(hrefs.docs(out), now), svg: p.svg ? { src: hrefs.docs(svgOf(out)), size: null } : null, }, entry: entry(out), @@ -1089,12 +1119,12 @@ export function createReviewServer({ if (url.pathname === hrefs.events) return sse.handle(req, res); if (first === "picture") { const out = rest.join("/"); - if (!isDocsPath(out)) return notFound(res, `${out} is not a picture`); - // a picture of the session has its page of verdicts; any other the table names, a plain one + if (!isDocsImage(out)) return notFound(res, `${out} is not a picture`); + // a picture of the session has its page of verdicts; any other image under docs, a plain one const html = detail(out, filter); if (html) return page(req, res, html); return plainPage(out).then((plain) => - plain ? page(req, res, plain) : notFound(res, `${out} is not a picture of this session or of the table`), + plain ? page(req, res, plain) : notFound(res, `${out} is not a picture of this session or under docs`), ); } if (first === "log") { @@ -1120,7 +1150,7 @@ export function createReviewServer({ const [kind, ...more] = rest; if (kind === "head" || kind === "docs") { const out = more.join("/"); - if (!isDocsPath(out)) return notFound(res); + if (!isDocsImage(out)) return notFound(res); return sendFile(req, res, out, kind === "head" ? revision.bytes(out) : readIf(path.join(docsRoot, out))); } const n = Number(more[0]); diff --git a/scripts/lib/shot-views.mjs b/scripts/lib/shot-views.mjs index c94962ffb..5d6ad69e0 100644 --- a/scripts/lib/shot-views.mjs +++ b/scripts/lib/shot-views.mjs @@ -1,7 +1,5 @@ -// The HTML pieces the pages about screenshots are made of: the page itself, a picture's -// card, a figure, a thumbnail, a line of the contents, a meter, a chip and a picture's -// allowances. scripts/svgshot/sheets.mjs builds the two static sheets from them, and the -// screenshot review tool its pages, with its actions added (shot-pages.mjs, WIP.ShotReview.md). +// The HTML pieces the screenshot review tool's pages are made of (shot-pages.mjs, +// WIP.ShotReview.md): the page itself, a chip and a picture's allowances. // // Each takes text where it says text, and escapes it, and HTML where it says HTML, which // it puts in as it is. Nothing here reads or writes a file. @@ -18,15 +16,11 @@ export const anchor = (out) => `p-${out.replace(/[^A-Za-z0-9]+/g, "-")}`; /** A picture's size ([w, h] in device pixels, or null) as text. */ export const sizeText = (size) => (size ? `${size[0]} x ${size[1]} px` : "size unknown"); -/** A share of the pixels, as text: two decimals, and "under 0.01" for what would round to none. */ -export const pctText = (pct) => (pct === 0 ? "0" : pct < 0.01 ? "under 0.01" : pct.toFixed(2)); - const rectsNote = (rects) => (rects.length ? `, ${rects.length} rectangle${rects.length > 1 ? "s" : ""} left out` : ""); /** * The allowances of a picture's entry in the manifest (or null), as text: {png, svg}, each the - * rule it is judged by when an allowance changes it, else null. The review tool's overview and - * the static sheets show them alike. + * rule it is judged by when an allowance changes it, else null. */ export function allowancesOf(entry) { let png = null; @@ -42,8 +36,8 @@ export function allowancesOf(entry) { return { png, svg }; } -const PAGE_STYLE = `:root{color-scheme:light dark;--bg:#fff;--fg:#1b1b1b;--mut:#666;--line:#ccc;--card:#f6f6f6;--bar:#d33;--lim:#080;--link:#2a6ed8} -@media (prefers-color-scheme:dark){:root{--bg:#1b1b1b;--fg:#e6e6e6;--mut:#a0a0a0;--line:#444;--card:#262626;--bar:#e55;--lim:#4c4;--link:#7aaaff}} +const PAGE_STYLE = `:root{color-scheme:light dark;--bg:#fff;--fg:#1b1b1b;--mut:#666;--line:#ccc;--card:#f6f6f6;--bar:#d33;--link:#2a6ed8} +@media (prefers-color-scheme:dark){:root{--bg:#1b1b1b;--fg:#e6e6e6;--mut:#a0a0a0;--line:#444;--card:#262626;--bar:#e55;--link:#7aaaff}} body{margin:0 auto;max-width:1500px;padding:16px;background:var(--bg);color:var(--fg);font:15px/1.45 system-ui,Segoe UI,sans-serif} h1{margin-top:0}h3{margin:0 0 4px;word-break:break-all}a{color:var(--link)} section{border:1px solid var(--line);background:var(--card);border-radius:6px;padding:12px;margin:16px 0} @@ -52,21 +46,14 @@ section{border:1px solid var(--line);background:var(--card);border-radius:6px;pa .trio figure{margin:0;flex:1 1 30%;min-width:260px} .trio img{max-width:100%;max-height:520px;border:1px solid var(--line);background:repeating-conic-gradient(#8884 0 25%,#0000 0 50%) 0 0/16px 16px;display:block} figcaption{font-size:12px;color:var(--mut);margin-top:2px;word-break:break-all} -.bar{position:relative;display:block;height:10px;max-width:500px;border:1px solid var(--line);margin:2px 0 8px} -.bar i{position:absolute;left:0;top:0;bottom:0;background:var(--bar)} -.bar b{position:absolute;top:-2px;bottom:-2px;width:2px;background:var(--lim)} -.pct{color:var(--mut)} -.thumbs{display:flex;flex-wrap:wrap;gap:12px} -.thumb{margin:0;width:230px}.thumb img{max-width:230px;max-height:150px;border:1px solid var(--line);background:repeating-conic-gradient(#8884 0 25%,#0000 0 50%) 0 0/16px 16px} table{border-collapse:collapse}td,th{border:1px solid var(--line);padding:3px 10px;text-align:left} `; /** - * A page: the head with `generator` in its (by which a folder is - * known to hold a page of that tool), and `head` (HTML) after its style, the `title` (text) - * and `intro` (HTML), the `summary` table ([[label, value]], text), the `contents` (the - *
  • s of the list, HTML), and `body` (HTML). A page with no `summary` has no table, and one - * with no `contents` no list. + * A page: the head with `generator` in its and `head` (HTML) after its + * style, the `title` (text) and `intro` (HTML), the `summary` table ([[label, value]], text), the + * `contents` (the
  • s of the list, HTML), and `body` (HTML). A page with no `summary` has no + * table, and one with no `contents` no list. */ export function pageHtml({ generator, title, intro, summary, contents, body, head = "" }) { const table = summary @@ -99,39 +86,3 @@ ${table}${list}${body} /** A chip: a short `text` (text) with the classes `classes` and the tooltip `title` (text). */ export const chipHtml = (text, classes = "", title = "") => `${esc(text)}`; - -/** - * For files in `folder`, relative to the page: `href`, a file's link; `figure`, a linked - * picture with its caption (text), for a card; `thumb`, a linked thumbnail with its alt - * text and caption (text). - */ -export function figuresIn(folder) { - const href = (name) => `${folder}/${encodeURIComponent(name)}`; - const figure = (name, caption) => - `
    ${esc(caption)}
    ${esc(caption)}
    `; - const thumb = (name, alt, caption) => - `
    ${esc(alt)}
    ${esc(caption)}
    `; - return { href, figure, thumb }; -} - -/** - * A bar `pct` of the way to `full` percent, with a mark at `mark` percent (at its end when - * `mark` is past `full`: a picture's own limit can be); `title` is its tooltip (text). - */ -export const meterHtml = (pct, full, mark, title) => - ``; - -/** - * A picture's card, with the id `anchor(out)`: its path `out` (text) as the heading, the - * line of facts `meta` (HTML), a `meter` (HTML, or "") and the `figures` (HTML, one each). - */ -export const cardHtml = ({ out, meta, meter = "", figures }) => `
    -

    ${esc(out)}

    -

    ${meta}

    -${meter} -
    ${figures.join("\n")}
    -
    `; - -/** A line of the contents: a link to the card of `out`, and `note` (text) after it. */ -export const tocItem = (out, note) => - `
  • ${esc(out)} ${esc(note)}
  • `; diff --git a/scripts/svgshot/redraw.mjs b/scripts/svgshot/redraw.mjs index 111b74296..e85fa2b75 100644 --- a/scripts/svgshot/redraw.mjs +++ b/scripts/svgshot/redraw.mjs @@ -1,17 +1,13 @@ -// What the tools that draw a picture's SVG again from its bundle have in common: -// replay.mjs, which writes the SVGs beside their PNGs, and sheet.mjs, which writes a -// sheet of them to look at. Finding the pictures and their bundles, drawing one again -// and judging it (keep.mjs, against lib/shot-policy.mjs's bar), writing what the judge made -// into a folder, and running the pictures in processes of their own. The sheets' pages are -// in sheets.mjs. +// What the tools that draw a picture's SVG again from its bundle use, replay.mjs above all: +// drawing one again and judging it (keep.mjs, against lib/shot-policy.mjs's bar), writing what +// the judge made into a folder, and running the pictures in processes of their own. // // Nothing here writes under docs/: each writer is given its folder. import { spawn } from "node:child_process"; -import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { availableParallelism } from "node:os"; import path from "node:path"; -import { isOutputTree } from "../../lib/markdown-files.mjs"; import { LAUNCH_ARGS, launchBrowser } from "../lib/browser.mjs"; import { readRecords, sendStop, writeRecord } from "../lib/record-lines.mjs"; import { BUNDLE_VERSION, drawBundle, pngHash, readBundle, renderBundle } from "./bundle.mjs"; @@ -32,42 +28,19 @@ export const judgedFiles = (out) => { return { png: `${s}.png`, svg: `${s}.svg`, render: `${s}.svg-render.png`, diff: `${s}.svg-diff.png` }; }; -/** - * Every PNG under `docsRoot`, the build's output trees left out, as its path under - * it with forward slashes, sorted, each with whether an SVG of the same name is - * beside it: [{out, svg}]. - */ -export function listPictures(docsRoot) { - const found = []; - const walk = (dir, rel) => { - for (const e of readdirSync(dir, { withFileTypes: true })) { - if (!rel && isOutputTree(e.name)) continue; - const r = rel ? `${rel}/${e.name}` : e.name; - if (e.isDirectory()) walk(path.join(dir, e.name), r); - else if (e.isFile() && /\.png$/i.test(e.name)) found.push(r); - } - }; - walk(docsRoot, ""); - return found - .sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)) - .map((out) => ({ out, svg: existsSync(path.join(docsRoot, out.replace(/\.png$/i, ".svg"))) })); -} - /** * Draws the SVG of the picture `out` (its path under `docsRoot`) again from its * bundle under `bundlesRoot`, with the converter as it is now. Returns * {retake, detail} when it cannot be drawn faithfully to its PNG -- `retake` the - * reason in the tool's own words, `detail` text from the bundle that a console - * may show and a sheet must not -- else {png, svg, stats, notes}. + * reason in the tool's own words, `detail` text from the bundle for a console alone + * -- else {png, svg, stats, notes}. * * A PNG that is not the one the bundle was taken with, or a question the bundle has * no answer for, is a retake; with `stale`, the SVG is drawn all the same and the * reason is one of its `notes`. An SVG that holds `user` (the Windows user name, or a - * list of the words no published picture may show: private-list.mjs) throws, unless - * `checkUserName` is false: only sheet.mjs passes that, whose sheet is for its owner - * alone and is never written where git would take it (outputRefusal). + * list of the words no published picture may show: private-list.mjs) throws. */ -export async function redraw({ bundlesRoot, docsRoot, out, user, stale = false, checkUserName = true }) { +export async function redraw({ bundlesRoot, docsRoot, out, user, stale = false }) { const bundle = readBundle(bundlesRoot, out); const ready = readyToDraw(bundle, docsRoot, out, stale); if (ready.retake) return ready; @@ -78,7 +51,7 @@ export async function redraw({ bundlesRoot, docsRoot, out, user, stale = false, if (!stale) return missed; notes.push(missed.retake); } - if (checkUserName && heldWords(svg, [user].flat()).length) throw new Error("the SVG holds the Windows user name"); + if (heldWords(svg, [user].flat()).length) throw new Error("the SVG holds the Windows user name"); return { png, svg, stats, notes }; } diff --git a/scripts/svgshot/sheet.mjs b/scripts/svgshot/sheet.mjs deleted file mode 100644 index 4e718011d..000000000 --- a/scripts/svgshot/sheet.mjs +++ /dev/null @@ -1,354 +0,0 @@ -// Writes a sheet to look at: an HTML page of the pictures under docs/ that have no SVG -// beside them, each drawn again from its bundle with the converter as it is now and -// judged against its PNG as replay.mjs and shoot_docs.mjs --svg judge it (lib/shot-policy.mjs's -// bar), worst first, with the PNG, the SVG's render and the difference map side by -// side; then the pictures with no bundle, as thumbnails. With --all, every picture. -// -// With --against , a sheet of another kind: every PNG that differs from the same -// file at a git revision, each as the revision has it, as it is and the difference map, -// to review what a screenshot run rewrote. PNG against PNG: no SVG is drawn, no bundle is -// read and no browser starts. -// -// Both judge each picture under docs/ with its allowances and a review's decisions from the -// manifest (test/shots/manifest.json), as the tools that write the pictures do, and show them. -// -// It writes only into the folder it is given, which may not be under docs/ or anywhere -// git does not ignore: the SVGs are drawn without the user-name check (the sheet is -// for its owner alone; owner), so the sheet and its pictures can hold the Windows user -// name. It starts no IDE and writes nothing under docs/; the fonts' cuts go to the -// bundle folder's cache, as replay.mjs's do. - -import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; -import { userInfo } from "node:os"; -import path from "node:path"; -import { - exitOnCrash, - numberOption, - parseCli, - printHelpAndExit, - refuseTogether, - regexOption, - withUsageError, -} from "../../lib/cli.mjs"; -import { DOCS_DIR } from "../../lib/repo-paths.mjs"; -import { changedPictures, outputRefusal, readRevisionFiles } from "../lib/shot-revision.mjs"; -import { BUNDLE_CACHE, listBundles } from "./bundle.mjs"; -import { useSubsetCache } from "./fonts.mjs"; -import { pngSize } from "../lib/png.mjs"; -import { MANIFEST, openManifest } from "../lib/shot-manifest.mjs"; -import { SVG_FAITHFUL, svgRule } from "../lib/shot-policy.mjs"; -import { allowancesOf } from "../lib/shot-views.mjs"; -import { judgeSvg } from "./keep.mjs"; -import { - defaultJobs, - inBrowser, - judgedFiles, - listPictures, - redraw, - reportShard, - retakeText, - runShards, - shardOf, - shareOf, - themeOf, - writeJudged, -} from "./redraw.mjs"; -import { changeFiles, changeSheetHtml, compareRevisionPicture, mayWriteSheet, notDrawn, sheetHtml } from "./sheets.mjs"; - -exitOnCrash(); - -const USAGE = `usage: node scripts/svgshot/sheet.mjs --out [--docs ] [--bundles ] [--only ] [--all] [--jobs N] [-h, --help] - node scripts/svgshot/sheet.mjs --out --against [--docs ] [--only ] - -Writes /index.html, a page of the pictures under docs that have no SVG -beside them, with their files in /pictures. Each picture with a bundle is -drawn again from it with the converter as it is now and judged as replay.mjs -judges it (an SVG is kept below ${SVG_FAITHFUL}% of its pixels far off the PNG's), -worst first, with its PNG, the SVG's render and the difference map; then the -pictures with no bundle, as thumbnails. Starts no IDE and writes nothing under -docs; needs Python with fontTools for a font cut not in the cache, as replay does. -A picture under docs is judged, by either kind of sheet, with its allowances -and a review's decisions in test/shots/manifest.json, which the sheet shows. - -The pictures are drawn without the check for the Windows user name, so the sheet -can hold it: must not be under docs, nor inside a git working tree at a -path git does not ignore. - - --out the folder for the sheet (required): new, empty, or holding a - sheet, which is replaced - --docs the folder the pictures are in (default docs) - --bundles the bundle cache (default .svgshot-bundles in the repository); - new font cuts are kept in its subsets folder - --only only the pictures whose path under docs (with .light for a - light one) matches - --all every picture, also one with an SVG beside it: drawn again from - its bundle, else its SVG file judged as it is - --jobs N processes drawing at once, each with a browser of its own - (default: half the logical processors, at most 8) - --against a sheet of another kind: every PNG under docs that differs from - the same file at the git revision (a commit, a branch, a - tag, HEAD), as the revision has it, as it is now and the - difference map, read with git run in the --docs folder, so that - folder's own repository answers. Most changed first; then the - pictures that differ only within the screenshotter's noise rule, - or that a review kept old (which it never writes: most - likely rewritten in error), with a - git command that would restore them and the shoot_docs.mjs - --cleanup one that would with their SVGs, shown and never run; then the - added; then the deleted. No SVG is drawn, no bundle is read and - no browser starts. Not combined with --all, --bundles or --jobs - -h, --help print this text and exit - -Exit codes: - 0 the sheet was written, every picture in it drawn or shown - 1 the sheet was written, but a picture could not be drawn or compared (it is listed so) - 2 the tool could not run: a refused command line, a refused output folder, no - bundle cache, no browser, no such revision, a manifest it cannot read, or a - crash`; - -const { values } = withUsageError(() => - parseCli(process.argv.slice(2), { - options: { - out: { type: "string" }, - docs: { type: "string" }, - bundles: { type: "string" }, - only: { type: "string" }, - all: { type: "boolean", default: false }, - jobs: { type: "string" }, - against: { type: "string" }, - help: { type: "boolean", short: "h", default: false }, - }, - stopAt: ["help"], - }), -); -if (values.help) printHelpAndExit(USAGE); -const refuse = (message) => { - console.error(`sheet: ${message}`); - process.exit(2); -}; -if (values.out === undefined) refuse("--out is required: the folder for the sheet"); -if (values.against !== undefined) - withUsageError(() => { - for (const other of ["all", "bundles", "jobs"]) refuseTogether(values, ["against", other]); - }); -const only = values.only === undefined ? null : withUsageError(() => regexOption(values.only, { option: "--only" })); -const jobs = withUsageError(() => - numberOption(values.jobs ?? String(defaultJobs()), { option: "--jobs", integer: true, min: 1, max: 32 }), -); -const outRoot = path.resolve(values.out); -const docsRoot = path.resolve(values.docs ?? DOCS_DIR); -const bundlesRoot = path.resolve(values.bundles ?? BUNDLE_CACHE); -const picturesDir = path.join(outRoot, "pictures"); -const SHARD_ENV = "SVGSHOT_SHEET_SHARD"; -const SHARD = shardOf(SHARD_ENV); - -// The manifest (lib/shot-manifest.mjs): its entries are for the pictures under docs/, so a -// sheet of another folder judges without them, as shoot_docs.mjs and replay.mjs do. -let manifest = null; -if (docsRoot === path.resolve(DOCS_DIR)) { - try { - manifest = openManifest(MANIFEST); - } catch (e) { - refuse(e.message); - } -} -const entryOf = (out) => manifest?.entry(out) ?? null; - -const refusal = outputRefusal(outRoot, [docsRoot, DOCS_DIR]); -if (refusal) refuse(`--out must not be under docs nor where git would take it: ${refusal}`); -// A child finds the folder as its parent left it, emptied for it. -if (!SHARD && !mayWriteSheet(outRoot)) refuse(`--out holds files that are not a sheet: ${outRoot}`); -if (!existsSync(docsRoot)) refuse(`no folder of pictures at ${docsRoot}`); - -// The old sheet goes: its page, and the files in its pictures folder. -function clearSheet() { - rmSync(path.join(outRoot, "index.html"), { force: true }); - if (existsSync(picturesDir)) - for (const e of readdirSync(picturesDir, { withFileTypes: true })) - if (e.isFile()) rmSync(path.join(picturesDir, e.name)); - mkdirSync(picturesDir, { recursive: true }); -} - -// A sheet of changes against a git revision: PNG against PNG, in this process, with no browser. -if (values.against !== undefined) { - let found; - try { - found = changedPictures(docsRoot, values.against); - } catch (e) { - refuse(e.message); - } - const listed = found.pictures.filter((p) => !only || only.test(p.out)); - // The revision's pictures, in one git process. - let atRevision; - try { - atRevision = readRevisionFiles( - docsRoot, - found.hash, - found.prefix, - listed.filter((p) => p.status !== "added").map((p) => p.out), - ); - } catch (e) { - refuse(`git could not read the pictures of ${values.against}: ${e.message}`); - } - clearSheet(); - const rows = []; - for (const item of listed) { - const names = changeFiles(item.out); - let before = null; - let after = null; - let result; - try { - if (item.status !== "added") { - before = atRevision.get(item.out); - if (!before) throw new Error(`${found.short} has no file ${item.out}`); - } - if (item.status !== "deleted") after = readFileSync(path.join(docsRoot, item.out)); - result = compareRevisionPicture(item, before, after, entryOf(item.out)); - } catch (e) { - result = { - row: { - out: item.out, - theme: themeOf(item.out), - status: item.status, - kind: "error", - error: e.message, - files: {}, - }, - map: null, - }; - } - if (before && result.row.files.old) writeFileSync(path.join(picturesDir, names.old), before); - if (after && result.row.files.new) writeFileSync(path.join(picturesDir, names.new), after); - if (result.map) writeFileSync(path.join(picturesDir, names.map), result.map); - rows.push(result.row); - } - writeFileSync( - path.join(outRoot, "index.html"), - changeSheetHtml({ - rows, - rev: values.against, - hash: found.hash, - short: found.short, - prefix: found.prefix, - only: values.only, - docs: values.docs, - }), - ); - const count = (kind) => rows.filter((r) => r.kind === kind).length; - console.log( - `${values.against} (${found.short}): ${rows.length} picture${rows.length === 1 ? "" : "s"}: ${count("changed")} changed, ${count("noise")} only by capture noise, ${count("added")} added, ${count("deleted")} deleted, ${count("error")} not compared`, - ); - console.log(`the sheet: ${path.join(outRoot, "index.html")}`); - process.exit(count("error") ? 1 : 0); -} - -if (!existsSync(bundlesRoot)) refuse(`no bundle cache at ${bundlesRoot}; shoot_docs.mjs --svg writes it`); -useSubsetCache(path.join(bundlesRoot, "subsets")); -const USER = userInfo().username; - -// The pictures, and what each is drawn from: its bundle, the SVG beside it (--all), or nothing. -const bundled = new Set(listBundles(bundlesRoot)); -const chosen = listPictures(docsRoot).filter((p) => (values.all || !p.svg) && (!only || only.test(p.out))); -const drawn = chosen - .filter((p) => bundled.has(p.out) || p.svg) - .map((p) => ({ out: p.out, source: bundled.has(p.out) ? "bundle" : "file" })); -const plain = chosen.filter((p) => !bundled.has(p.out) && !p.svg).map((p) => p.out); - -// One picture drawn and judged, its files written to the pictures folder: its row of the sheet. -async function draw({ out, source }, browser) { - const row = { out, theme: themeOf(out), source, files: { png: judgedFiles(out).png } }; - let svg; - let png; - let stats; - if (source === "bundle") { - const got = await redraw({ bundlesRoot, docsRoot, out, user: USER, stale: true, checkUserName: false }); - if (got.retake) return { ...row, error: retakeText(got) }; - ({ svg, png, stats } = got); - row.notes = got.notes; - } else { - svg = readFileSync(path.join(docsRoot, out.replace(/\.png$/i, ".svg")), "utf8").replace(/\r\n/g, "\n"); - png = readFileSync(path.join(docsRoot, out)); - stats = { unsupported: {} }; - } - const entry = entryOf(out); - const { diff, faithful, by, verdict } = await judgeSvg(browser, svg, png, stats, entry); - Object.assign(row.files, writeJudged(picturesDir, out, diff, { render: true, svg })); - const allowance = allowancesOf(entry).svg; - return { - ...row, - pct96: diff.stats.pct96, - pct32: diff.stats.pct32, - pct8: diff.stats.pct8, - faithful, - by, - allowance, - own: allowance ? { share: +verdict.share.toFixed(3), bar: svgRule(entry).share } : null, - notDrawn: notDrawn(stats.unsupported), - }; -} - -if (SHARD) { - const rows = []; - await inBrowser(shareOf(drawn, SHARD), async (p, browser) => { - let row; - try { - row = await draw(p, browser); - } catch (e) { - row = { - out: p.out, - theme: themeOf(p.out), - source: p.source, - files: { png: judgedFiles(p.out).png }, - error: e.message, - }; - } - rows.push(row); - console.log(`${p.out}: ${row.error === undefined ? `${row.pct96}% strongly off` : `not drawn (${row.error})`}`); - }); - reportShard({ rows }); - process.exit(0); -} - -// The parent: the old sheet goes, the pictures are drawn in `jobs` children, then the page. -clearSheet(); - -const rows = []; -const shards = drawn.length ? await runShards(SHARD_ENV, Math.min(jobs, drawn.length)) : []; -for (const { result } of shards) rows.push(...(result?.rows ?? [])); -// A child that ended without its report leaves its pictures undrawn: each is listed so. -const done = new Set(rows.map((r) => r.out)); -for (const p of drawn) - if (!done.has(p.out)) - rows.push({ - out: p.out, - theme: themeOf(p.out), - source: p.source, - files: {}, - error: "its process ended without a report", - }); - -// The PNGs are copied beside what was drawn, so the folder stands alone. -const sizes = new Map(); -for (const out of [...drawn.map((p) => p.out), ...plain]) { - const png = readFileSync(path.join(docsRoot, out)); - sizes.set(out, pngSize(png)); - copyFileSync(path.join(docsRoot, out), path.join(picturesDir, judgedFiles(out).png)); -} -for (const r of rows) { - r.size = sizes.get(r.out); - r.files.png = judgedFiles(r.out).png; -} -const html = sheetHtml({ - rows, - plain: plain.map((out) => ({ out, size: sizes.get(out), files: { png: judgedFiles(out).png } })), - bar: SVG_FAITHFUL, - all: values.all, -}); -writeFileSync(path.join(outRoot, "index.html"), html); - -const failed = rows.filter((r) => r.error !== undefined).length; -console.log( - `\n${chosen.length} picture${chosen.length === 1 ? "" : "s"}: ${rows.length - failed} drawn, ${failed} not drawn, ${plain.length} with nothing to draw from`, -); -console.log(`the sheet: ${path.join(outRoot, "index.html")}`); -process.exit(failed ? 1 : 0); diff --git a/scripts/svgshot/sheets.mjs b/scripts/svgshot/sheets.mjs deleted file mode 100644 index e71e86ed6..000000000 --- a/scripts/svgshot/sheets.mjs +++ /dev/null @@ -1,328 +0,0 @@ -// The two sheets sheet.mjs writes, and where it may write them. The sheet of the pictures -// with no SVG (sheetHtml): each drawn again from its bundle (redraw.mjs) and judged, worst -// first. The sheet of changes against a git revision (changeSheetHtml, sheet.mjs --against): -// the comparison of each picture (compareRevisionPicture, scripts/lib/shot-change.mjs), their -// order and the commands that put the ones within noise back; the list of them is -// changedPictures, in scripts/lib/shot-revision.mjs. Both pages are made of the pieces in -// scripts/lib/shot-views.mjs. -// -// Nothing here writes a file: sheet.mjs writes the page and its pictures. - -import { existsSync, readdirSync, readFileSync, statSync } from "node:fs"; -import path from "node:path"; -import { decodePng, pngSize } from "../lib/png.mjs"; -import { changeMap, compareImages, NOISE_LEVELS, NOISE_SHARE } from "../lib/shot-change.mjs"; -import { - allowancesOf, - cardHtml, - esc, - figuresIn, - meterHtml, - pageHtml, - pctText, - sizeText, - tocItem, -} from "../lib/shot-views.mjs"; -import { slugOf } from "../lib/shot-apply.mjs"; -import { pngDecision } from "../lib/shot-manifest.mjs"; -import { cleanupResets, pngRule } from "../lib/shot-policy.mjs"; -import { themeOf } from "./redraw.mjs"; - -/** The generator a sheet names in its , by which a folder is known to hold one. */ -export const SHEET_GENERATOR = "scripts/svgshot/sheet.mjs"; - -/** - * Whether the folder `dir` may be written over: it does not exist, is empty, or - * holds a sheet (its index.html names SHEET_GENERATOR). - */ -export function mayWriteSheet(dir) { - if (!existsSync(dir)) return true; - if (!statSync(dir).isDirectory()) return false; - if (readdirSync(dir).length === 0) return true; - const index = path.join(dir, "index.html"); - return ( - existsSync(index) && readFileSync(index, "utf8").includes(``) - ); -} - -// ---- the sheet of the pictures with no SVG ---------------------------------------------- - -/** What the converter reports it did not draw (stats.unsupported), as [[kind, count]] sorted by kind. */ -export const notDrawn = (unsupported) => - Object.entries(unsupported ?? {}).sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0)); - -/** The judged rows worst first; a row that could not be judged after them; ties by path. */ -export const sortRows = (rows) => - [...rows].sort((a, b) => (b.pct96 ?? -1) - (a.pct96 ?? -1) || (a.out < b.out ? -1 : a.out > b.out ? 1 : 0)); - -/** - * The sheet, a page that needs no other file but the pictures it links: `rows` the - * judged pictures, each {out, theme, size, pct96, pct32, pct8, faithful, by, allowance, - * own, source ("bundle" or "file"), notes, notDrawn, files: {png, render, diff, svg}} or - * {out, theme, size, error, files: {png}}, `by` "decision" or "rule" (decideSvg's), - * `allowance` the SVG's allowance as text or null, and `own` {share, bar} when it has one: - * the share off by its own bar's levels and rectangles, and its bar's share (percent); - * `plain` the pictures with no drawing, each - * {out, size, files: {png}}; `bar` SVG_FAITHFUL; `all` whether pictures with an SVG - * are included; `folder` the folder the files are in, relative to the page. - */ -export function sheetHtml({ rows, plain, bar, all, folder = "pictures" }) { - const { href, figure, thumb } = figuresIn(folder); - const sorted = sortRows(rows); - const judged = sorted.filter((r) => r.error === undefined); - const title = all ? "Every picture against its SVG" : "Pictures with no SVG"; - const meter = (r) => - r.own - ? meterHtml(r.own.share, 10, r.own.bar, `${r.own.share}% off by its own bar; the bar is ${r.own.bar}%`) - : meterHtml(r.pct96, 10, bar, `${r.pct96}% strongly off; the bar is ${bar}%`); - const card = (r) => { - // Each fact is HTML: text from elsewhere is escaped as it is put in. - const facts = [`${r.theme} theme`, sizeText(r.size)]; - if (r.error === undefined) { - facts.push( - `${r.pct96}% strongly off (the bar is ${bar}%), ${r.pct32}% off by 32 levels or more, ${r.pct8}% by 8 or more`, - ); - if (r.allowance) facts.push(`${esc(r.allowance)}: ${r.own.share}% off by it`); - if (r.by === "decision") facts.push(`${r.faithful ? "accepted" : "refused"} by a review's decision`); - facts.push(r.source === "file" ? "the SVG file beside the PNG" : "drawn again from its bundle"); - if (r.notDrawn?.length) - facts.push( - `the converter did not draw: ${esc(r.notDrawn.map(([k, n]) => (n > 1 ? `${k} x${n}` : k)).join(", "))}`, - ); - } else facts.push(`not drawn: ${esc(r.error)}`); - if (r.notes?.length) facts.push(`note: ${esc(r.notes.join("; "))}`); - const figures = [figure(r.files.png, "PNG")]; - if (r.files.render) figures.push(figure(r.files.render, "SVG render")); - if (r.files.diff) - figures.push(figure(r.files.diff, "Difference (red: 96 levels or more, orange: 32 or more, yellow: 8 or more)")); - return cardHtml({ - out: r.out, - meta: `${facts.join(", ")}${r.files.svg ? ` (the SVG)` : ""}`, - meter: r.error === undefined ? meter(r) : "", - figures, - }); - }; - const thumbs = plain.map((p) => thumb(p.files.png, p.out, `${p.out}, ${sizeText(p.size)}`)).join("\n"); - const toc = sorted - .map((r) => tocItem(r.out, `${r.pct96 ?? "not drawn"}${r.pct96 === undefined ? "" : "%"}`)) - .join("\n"); - return pageHtml({ - generator: SHEET_GENERATOR, - title, - intro: `${all ? "Every PNG under docs" : "Every PNG under docs with no SVG of the same name beside it"}, the build's output trees left out. A picture with a bundle is drawn again from it with the converter as it is now, and judged as the tools judge an SVG: the share of its pixels more than 96 grey levels off the PNG's, a shift of one pixel allowed. An SVG is kept only below ${bar}% (the green mark on each bar, whose full width is 10%), or below the bar of its own allowance in the manifest, which its bar then shows, unless a review decided otherwise. Select a picture to open it full size.`, - summary: [ - [all ? "PNGs" : "PNGs with no SVG", rows.length + plain.length], - ["drawn and judged", judged.length], - ["could not be drawn", rows.length - judged.length], - ["with nothing to draw from", plain.length], - ], - contents: `${toc} -
  • Pictures with nothing to draw from
  • `, - body: `

    Drawn, worst first

    -${sorted.map(card).join("\n")} -

    With nothing to draw from (no bundle${all ? " and no SVG" : ""})

    -
    -${thumbs} -
    `, - }); -} - -// ---- the sheet of changes against a git revision ---------------------------------------- -// The change list itself is changedPictures, in shot-revision.mjs. - -/** The files a picture of the change sheet can have in a flat folder: the old PNG, the new one and the map. */ -export const changeFiles = (out) => { - const s = slugOf(out); - return { old: `${s}.old.png`, new: `${s}.new.png`, map: `${s}.change.png` }; -}; - -/** - * Compares the picture `item` ({out, status}) as the revision has it (`before`, bytes, or - * null) and as it is now (`after`), with `entry` its entry in the manifest (or null). Returns - * {row, map}: the row of the change sheet -- {out, theme, status, kind, by, share, allowance, - * sizeOld, sizeNew, stats, error, files} -- and the difference map as PNG bytes, null for an - * added or deleted picture or one that could not be read. `kind` is "changed", "noise" (what - * shoot_docs.mjs --cleanup puts back as the revision has it: within the picture's noise rule - * of it, or kept old by a review's decision; cleanupResets), "added", "deleted" or "error" (a - * file this tool cannot read as a PNG, with `error` the reason); `by` "decision" or "rule"; - * `share` the noise rule's share (percent) and `allowance` the PNG's allowance as text, or null. - */ -export function compareRevisionPicture(item, before, after, entry = null) { - const { out, status } = item; - const names = changeFiles(out); - const rule = pngRule(entry); - const row = { - out, - theme: themeOf(out), - status, - share: rule.share * 100, - allowance: allowancesOf(entry).png, - files: {}, - }; - if (before) { - row.sizeOld = pngSize(before); - row.files.old = names.old; - } - if (after) { - row.sizeNew = pngSize(after); - row.files.new = names.new; - } - if (status === "added") return { row: { ...row, kind: "added" }, map: null }; - if (status === "deleted") return { row: { ...row, kind: "deleted" }, map: null }; - try { - const A = decodePng(before); - const B = decodePng(after); - const stats = compareImages(A, B, rule); - const resets = cleanupResets({ before, after, entry, near: () => stats.noiseOnly }); - const by = pngDecision(entry, after) ? "decision" : "rule"; - row.files.map = names.map; - return { row: { ...row, stats, by, kind: resets ? "noise" : "changed" }, map: changeMap(A, B) }; - } catch (e) { - return { row: { ...row, kind: "error", error: e.message }, map: null }; - } -} - -const KIND_RANK = { error: 0, changed: 0, noise: 1, added: 2, deleted: 3 }; - -/** - * The change sheet's rows in the order it shows them: the changed pictures, most changed - * first (the share changed beyond noise, then the share that differs at all, then the - * path), those that could not be read after them; then the pictures that differ only by - * a capture's noise, in the same order; then the added; then the deleted, by path. - */ -export const sortChangeRows = (rows) => - [...rows].sort((a, b) => { - const k = KIND_RANK[a.kind] - KIND_RANK[b.kind]; - if (k) return k; - const share = (r) => (r.stats ? [r.stats.pctBeyond, r.stats.pctDiffering] : [-1, -1]); - const [ab, ad] = share(a); - const [bb, bd] = share(b); - return bb - ab || bd - ad || (a.out < b.out ? -1 : a.out > b.out ? 1 : 0); - }); - -const shellQuote = (p) => (/[^A-Za-z0-9_./:@%+=,~^{}-]/.test(p) ? `"${p}"` : p); - -/** - * The command that puts the pictures `outs` (paths under the docs folder, which is - * `prefix` from the repository's root) back as the revision `rev` has them, to be run - * in the repository's root. The tool only shows it. - */ -export const restoreCommand = (rev, prefix, outs) => - `git checkout ${shellQuote(rev)} -- ${outs.map((o) => shellQuote(prefix + o)).join(" ")}`; - -/** - * The command that puts back, with no IDE, every picture that differs from the revision - * `rev` only within the noise rule, its SVG with it (shoot_docs.mjs --cleanup), to be run in - * the repository's root: `only` the sheet's --only, `docs` its --docs, each as given, or - * undefined. The tool only shows it. - */ -export const cleanupCommand = (rev, { only, docs } = {}) => - [ - "node scripts/shoot_docs.mjs --cleanup", - rev === "HEAD" ? "" : ` --against ${shellQuote(rev)}`, - only === undefined ? "" : ` --only ${shellQuote(only)}`, - docs === undefined ? "" : ` --out ${shellQuote(docs)}`, - ].join(""); - -/** - * The change sheet, a page that needs no other file but the pictures it links: `rows` - * from compareRevisionPicture; `rev` the revision as the command line gave it, `hash` - * and `short` the commit it names, `prefix` the docs folder's path from the repository's - * root; `folder` the folder the files are in, relative to the page. - */ -export function changeSheetHtml({ rows, rev, hash, short, prefix, folder = "pictures", only, docs }) { - const { figure } = figuresIn(folder); - const sorted = sortChangeRows(rows); - const kinds = (...wanted) => sorted.filter((r) => wanted.includes(r.kind)); - const changed = kinds("changed", "error"); - const noise = kinds("noise"); - const added = kinds("added"); - const deleted = kinds("deleted"); - const title = `Pictures changed since ${rev} (${short})`; - const sizes = (r) => - r.sizeOld && r.sizeNew && (r.sizeOld[0] !== r.sizeNew[0] || r.sizeOld[1] !== r.sizeNew[1]) - ? `size changed from ${sizeText(r.sizeOld)} to ${sizeText(r.sizeNew)}` - : sizeText(r.sizeNew ?? r.sizeOld); - const card = (r) => { - // Each fact is HTML: text from elsewhere is escaped as it is put in. - const facts = [`${r.theme} theme`, esc(sizes(r))]; - if (r.error !== undefined) facts.push(`not compared: ${esc(r.error)}`); - const st = r.stats; - if (st) { - if (!st.sameSize) - facts.push( - `compared aligned at the top left over the common ${st.common[0]} x ${st.common[1]} px; the map shows the whole ${st.canvas[0]} x ${st.canvas[1]} px, a pixel only the old picture has cyan, one only the new picture has magenta`, - ); - facts.push( - st.differing === 0 - ? "the same pixels in a different file" - : `${pctText(st.pctBeyond)}% changed beyond noise (by more than ${st.levels} grey levels${st.sameSize ? "" : ", or in one picture only"}), ${pctText((st.faint / st.total) * 100)}% by ${st.levels} or fewer`, - ); - } - if (r.allowance) facts.push(esc(r.allowance)); - if (r.by === "decision") - facts.push(`${r.kind === "noise" ? "kept old" : "taken new"} by a review's decision`); - const figures = []; - if (r.files.old) figures.push(figure(r.files.old, `As ${short} has it`)); - if (r.files.new) figures.push(figure(r.files.new, "As it is now")); - if (r.files.map) - figures.push( - figure(r.files.map, "Difference (yellow: 1 grey level, shading to red at 128 or more; dark grey: the same)"), - ); - const mark = r.share ?? NOISE_SHARE * 100; - const tip = st - ? `${pctText(st.pctBeyond)}% changed beyond noise; the mark is ${mark}%, the share of the pixels the noise rule lets differ` - : ""; - return cardHtml({ - out: r.out, - meta: facts.join(", "), - meter: st ? meterHtml(st.pctBeyond, 10, mark, tip) : "", - figures, - }); - }; - const toc = (list) => list.map((r) => tocItem(r.out, r.stats ? `${pctText(r.stats.pctBeyond)}%` : r.kind)).join("\n"); - const group = (id, heading, list, note = "") => - `

    ${esc(heading)} (${list.length})

    -${note}${list.length ? list.map(card).join("\n") : "

    None.

    "}`; - const noiseNote = `

    These differ from ${esc(short)} within the noise rule the screenshotter applies (no pixel more than ${NOISE_LEVELS} grey levels off, and at most ${NOISE_SHARE * 100}% of the pixels off at all, unless the picture has an allowance of its own in the manifest), or a review decided to keep the old picture, and it never writes a capture that does: a run that kept the other version of the noise, or drift over several runs, left them.

    -${ - noise.length - ? `

    To put them all back as ${esc(short)} has them, run this in the repository's root (this page only shows it; nothing has been run):

    -
    ${esc(
    -        restoreCommand(
    -          rev,
    -          prefix,
    -          noise.map((r) => r.out),
    -        ),
    -      )}
    -

    Or this, which also puts back each one's SVG as ${esc(short)} has it (removed where it has none) and starts no IDE; with --dry-run it only lists them:

    -
    ${esc(cleanupCommand(rev, { only, docs }))}
    -` - : "" -}`; - const section = (id, heading, list) => - `
  • ${esc(heading)} (${list.length})\n
      \n${toc(list)}\n
  • `; - return pageHtml({ - generator: SHEET_GENERATOR, - title, - intro: `Every PNG under docs that differs from the commit ${esc(hash)} (${esc(rev)}): the picture as the commit has it, as it is now, and the difference between them, aligned at the top left. The change is the share of pixels that differ by more than ${NOISE_LEVELS} grey levels (or exist in one picture only). Select a picture to open it full size.`, - summary: [ - ["changed", changed.length], - ["differ only by capture noise", noise.length], - ["added", added.length], - ["deleted", deleted.length], - ], - contents: [ - section("changed", "Changed, most changed first", changed), - section("noise", "Differ only by capture noise", noise), - section("added", "Added", added), - section("deleted", "Deleted", deleted), - ].join("\n"), - body: [ - group("changed", "Changed, most changed first", changed), - group("noise", "Differ only by capture noise, most likely rewritten in error", noise, noiseNote), - group("added", "Added", added), - group("deleted", "Deleted", deleted), - ].join("\n"), - }); -} diff --git a/test/shot-review.test.mjs b/test/shot-review.test.mjs index d4dfb9ff0..928a57531 100644 --- a/test/shot-review.test.mjs +++ b/test/shot-review.test.mjs @@ -876,6 +876,7 @@ describe("what the screenshot review shows (shot-review.mjs, shot-pages.mjs)", ( ["nosvg", ["IDE/Images/B.png", "IDE/Images/A.light.png", "IDE/Images/B.light.png", C]], ["missing", ["IDE/Images/Gone.png"]], ["overridden", [E]], + ["uncaptured", []], ["svg", [A]], ], ); @@ -903,6 +904,89 @@ describe("what the screenshot review shows (shot-review.mjs, shot-pages.mjs)", ( }); }); + test("an image no shot takes is listed, unless a script makes it or it is the favicon", () => { + const hand = ["Features/Hand.png", "Tutorials/Hand.webp"]; + const images = [ + A, + "IDE/Images/A.light.png", + "IDE/Images/A.svg", + "IDE/Images/A.light.svg", + ...hand, + "Tutorials/Diagram.svg", + "assets/images/gantt.svg", + "assets/thumbnails/yt-x.jpg", + "favicon.png", + ]; + const files = new Set([...images, "Tutorials/Diagram.dot"]); + const { pictures, groups } = allPictures({ + shots: [{ out: A, setup: "s", once: false, window: false }], + exists: (p) => files.has(p), + images, + }); + assert.deepEqual( + groups.find((g) => g.key === "uncaptured").pictures.map((p) => p.out), + hand, + ); + assert.deepEqual( + pictures.filter((p) => p.uncaptured).map((p) => p.out), + hand, + ); + assert.deepEqual( + pictures.find((p) => p.out === hand[1]), + { + out: hand[1], + setup: null, + window: false, + once: false, + png: true, + svg: false, + bothThemes: false, + build: null, + reason: null, + group: "uncaptured", + uncaptured: true, + }, + ); + // one with an SVG of its own that no shot takes is listed as well, and neither is a diagram + assert.deepEqual( + allPictures({ shots: [], exists: () => false, images: ["Hand.svg"] }).pictures.map((p) => p.out), + ["Hand.svg"], + ); + }); + + test("an image no shot takes can be looked at, and offers nothing a run would do", () => { + const p = { + out: "Features/Hand.webp", + setup: null, + window: false, + once: false, + png: true, + svg: false, + bothThemes: false, + build: null, + reason: null, + group: "uncaptured", + uncaptured: true, + }; + const all = allHtml({ + groups: [{ key: "uncaptured", title: "No automated capture", pictures: [p] }], + baseline: { short: "abc" }, + }); + assert.match(all, /No automated capture \(1\)/); + assert.match(all, /no automated capture<\/span>/); + assert.ok(all.includes(`src="${hrefs.docs(p.out)}"`)); + assert.doesNotMatch(all, /]*data-pick/); + const plain = plainHtml({ + p, + place: { index: 0, total: 1 }, + files: { head: null, docs: { src: hrefs.docs(p.out), size: null }, svg: null }, + baseline: { short: "abc" }, + }); + assert.match(plain, /No tool takes this image/); + assert.doesNotMatch(plain, /Retake|Replay|size unknown|HEAD \(abc\)/); + assert.ok(plain.includes(`The file`)); + }); + test("the page of every picture says why each has no SVG, offers their replay, and a picture's plain page its runs", () => { const p = { out: C, @@ -1700,7 +1784,14 @@ onStop(process.stdin, () => { fs.writeFileSync(path.join(docs, C), flat(false)); fs.writeFileSync(path.join(docs, A), flat(false)); fs.writeFileSync(path.join(docs, "IDE/Images/A.svg"), ""); - const revision = stubRevision("a", { [C]: flat(false) }); + // images no shot takes: one to look at, a poster frame and the favicon + const HAND = "Features/Hand.webp"; + fs.mkdirSync(path.join(docs, "Features"), { recursive: true }); + fs.mkdirSync(path.join(docs, "assets/thumbnails"), { recursive: true }); + fs.writeFileSync(path.join(docs, HAND), "RIFF"); + fs.writeFileSync(path.join(docs, "assets/thumbnails/yt-x.jpg"), "jpeg"); + fs.writeFileSync(path.join(docs, "favicon.png"), flat(false)); + const revision = stubRevision("a", { [C]: flat(false), [HAND]: Buffer.from("RIFF") }); const base = () => ({ hash: revision.hash, short: revision.short, build: 1500 }); // a closed session whose replay refused C's SVG const closed = openSession(archiveRoot(root, "abc1234"), base); @@ -1744,6 +1835,22 @@ onStop(process.stdin, () => { assert.match(text, //); assert.match(text, /No run of this session reported this picture/); assert.equal((await fetch(at + hrefs.picture("IDE/Images/Nope.png"))).status, 404); + // an image no shot takes is listed and shown, alone when the baseline has the same bytes; a + // poster frame and the favicon are not listed; and no action reaches it + assert.match(all, /No automated capture \(1\)/); + assert.doesNotMatch(all, /yt-x\.jpg|favicon/); + const hand = await (await fetch(at + hrefs.picture(HAND))).text(); + assert.match(hand, /No tool takes this image/); + assert.doesNotMatch(hand, /HEAD \(/); + const file = await fetch(at + hrefs.docs(HAND)); + assert.equal(file.headers.get("content-type").split(";")[0], "image/webp"); + assert.equal((await fetch(at + hrefs.picture("assets/thumbnails/yt-x.jpg"))).status, 404); + const acted = await fetch(at + hrefs.act(HAND), { + method: "POST", + headers: { origin: at, "content-type": "application/json" }, + body: "{}", + }); + assert.equal(acted.status, 404); // the overview links to the page assert.match(await (await fetch(`${at}/`)).text(), /All pictures<\/a>/); // a table that cannot be read is said so, on a server that has none yet diff --git a/test/svgshot.test.mjs b/test/svgshot.test.mjs index 6df75111e..e1e7f03a5 100644 --- a/test/svgshot.test.mjs +++ b/test/svgshot.test.mjs @@ -14,13 +14,10 @@ // inlineSvgsIn, which lists the ones to read in the page, and scopeIds, which keeps the ids of // two icons apart in one picture; the reading of an itself is in the page and is // measured by the bench pages. And colour-filter.mjs, which bakes a filter of colour functions -// into the colours its group paints. And redraw.mjs, which replay.mjs and sheet.mjs share: -// redraw, which draws a picture again from its bundle or names its retake, and fails on the -// user name unless its caller turns the check off; and the pictures listed. And sheets.mjs: -// the folders a sheet is refused, and the sheet's page, made of lib/shot-views.mjs's pieces. -// And the sheet of changes against a git revision -// (sheet.mjs --against): git's change list, the comparison of two pictures over two sizes, -// the noise rule, the order and the page. And the url()s of a frozen page's style sheets +// into the colours its group paints. And redraw.mjs: redraw, which draws a picture again from +// its bundle or names its retake, and fails on the user name; and the folders a stage is refused. +// And what differs from a git revision: git's change list, the noise rule and the difference +// map over two sizes. And the url()s of a frozen page's style sheets // (lib/shot-freeze.mjs; the freezing itself is in the page). And lib/record-lines.mjs, the records a child // process writes among its lines, which runShards reads. And what becomes of a picture and // its SVG: lib/shot-policy.mjs's decisions, with a picture's allowances and a review's @@ -138,7 +135,6 @@ import { import { changeMap, changeRegions, - compareImages, NOISE_LEVELS, NOISE_SHARE, pixelDiff, @@ -148,7 +144,7 @@ import { strengthOf, withinNoise, } from "../scripts/lib/shot-change.mjs"; -import { allowancesOf, meterHtml } from "../scripts/lib/shot-views.mjs"; +import { allowancesOf } from "../scripts/lib/shot-views.mjs"; import { FAINT_LEVEL, pngLook, @@ -178,28 +174,7 @@ import { svgFate, workingChanges, } from "../scripts/lib/shot-revision.mjs"; -import { - judgedFiles, - listPictures, - redraw, - retakeText, - shareOf, - staleBundle, - themeOf, -} from "../scripts/svgshot/redraw.mjs"; -import { - cleanupCommand, - changeFiles, - changeSheetHtml, - compareRevisionPicture, - restoreCommand, - sortChangeRows, - mayWriteSheet, - notDrawn, - SHEET_GENERATOR, - sheetHtml, - sortRows, -} from "../scripts/svgshot/sheets.mjs"; +import { judgedFiles, redraw, retakeText, shareOf, staleBundle, themeOf } from "../scripts/svgshot/redraw.mjs"; import { bakeable, bakeColour, @@ -1547,11 +1522,9 @@ describe("bundles", () => { const drawn = await redraw({ ...args, user: "nobody" }); assert.deepEqual(drawn.notes, []); assert.match(drawn.svg, />Shown<\/text>/); - // The page's text holds "Shown": as a user name, it fails the picture, unless the - // caller (sheet.mjs alone) turns the check off. + // The page's text holds "Shown": as a user name, it fails the picture. await assert.rejects(redraw({ ...args, user: "SHOWN" }), /holds the Windows user name/); await assert.rejects(redraw({ ...args, user: ["nobody", "SHOWN"] }), /holds the Windows user name/); - assert.equal((await redraw({ ...args, user: "SHOWN", checkUserName: false })).svg, drawn.svg); // A PNG that is not the bundle's is a retake, or with `stale` a note on a drawing. fs.writeFileSync(path.join(docsRoot, "Images/x.png"), Buffer.from("another picture")); const why = "the PNG is not the one the bundle was taken with"; @@ -2785,8 +2758,8 @@ describe("web fonts as WOFF2", () => { }); }); -// redraw.mjs's parts that need no browser, what sheet.mjs lists, and sheets.mjs: where it may write, and the page. -describe("the sheet", () => { +// redraw.mjs's parts that need no browser, where a folder of pictures may be written, and a picture's allowances. +describe("a picture's files, folders and allowances", () => { const PNG = (w, h) => { const b = Buffer.alloc(33); Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]).copy(b); @@ -2816,22 +2789,6 @@ describe("the sheet", () => { assert.deepEqual(shareOf(["a", "b", "c", "d", "e"], { k: 1, of: 2 }), ["b", "d"]); }); - test("lists every PNG with whether an SVG is beside it, the output trees left out", () => { - const root = fs.mkdtempSync(path.join(os.tmpdir(), "sheet-list-")); - try { - for (const f of ["b/Y.png", "b/Y.svg", "a/X.light.png", "_site/Z.png", "_site-offline/Z.png", "c/d.txt"]) { - fs.mkdirSync(path.dirname(path.join(root, f)), { recursive: true }); - fs.writeFileSync(path.join(root, f), "x"); - } - assert.deepEqual(listPictures(root), [ - { out: "a/X.light.png", svg: false }, - { out: "b/Y.png", svg: true }, - ]); - } finally { - fs.rmSync(root, { recursive: true, force: true }); - } - }); - test("is never written under docs or where git would take it", () => { const docs = path.join(REPO_ROOT, "docs"); assert.match(outputRefusal(path.join(docs, "sheet"), [docs]), /is under/); @@ -2851,95 +2808,6 @@ describe("the sheet", () => { assert.match(outputRefusal(path.join(os.tmpdir(), "sheet"), [docs], unsure), /could not say/); }); - test("replaces only a folder that is new, empty or a sheet", () => { - const root = fs.mkdtempSync(path.join(os.tmpdir(), "sheet-out-")); - try { - assert.equal(mayWriteSheet(path.join(root, "new")), true); - assert.equal(mayWriteSheet(root), true); - fs.writeFileSync(path.join(root, "index.html"), "

    someone's page

    "); - assert.equal(mayWriteSheet(root), false); - fs.writeFileSync(path.join(root, "index.html"), sheetHtml({ rows: [], plain: [], bar: 0.25, all: false })); - assert.equal(mayWriteSheet(root), true); - assert.equal(mayWriteSheet(path.join(root, "index.html")), false); - } finally { - fs.rmSync(root, { recursive: true, force: true }); - } - }); - - test("puts the judged pictures worst first, those not drawn after them", () => { - const rows = [ - { out: "b.png", pct96: 0.3 }, - { out: "c.png", error: "x" }, - { out: "a.png", pct96: 5 }, - { out: "d.png", pct96: 0.3 }, - ]; - assert.deepEqual( - sortRows(rows).map((r) => r.out), - ["a.png", "b.png", "d.png", "c.png"], - ); - assert.deepEqual(notDrawn({ resizer: 1, "a frame of another process": 2 }), [ - ["a frame of another process", 2], - ["resizer", 1], - ]); - }); - - test("writes a page that links each picture's files and escapes what it shows", () => { - const files = (out) => ({ ...judgedFiles(out) }); - const html = sheetHtml({ - rows: [ - { - out: "IDE/A&B.png", - theme: "dark", - size: [800, 600], - pct96: 0.4, - pct32: 1, - pct8: 2, - faithful: false, - source: "bundle", - notes: [], - notDrawn: [["filter ", 2]], - files: files("IDE/A&B.png"), - }, - { - out: "IDE/Z.light.png", - theme: "light", - size: [10, 10], - pct96: 9, - pct32: 9, - pct8: 9, - source: "file", - files: files("IDE/Z.light.png"), - }, - { - out: "IDE/Gone.png", - theme: "dark", - size: null, - error: "the bundle is of format 1", - files: { png: "IDE__Gone.png" }, - }, - ], - plain: [{ out: "Other/P.png", size: [5, 6], files: { png: "Other__P.png" } }], - bar: 0.25, - all: false, - }); - assert.ok(html.includes(``)); - assert.ok(html.includes("Pictures with no SVG")); - // Worst first, and the one not drawn after the drawn ones. - const order = ["IDE/Z.light.png", "IDE/A&B.png", "IDE/Gone.png"].map((t) => html.indexOf(`

    ${t}

    `)); - assert.ok( - order.every((i, k) => i > 0 && (k === 0 || i > order[k - 1])), - String(order), - ); - assert.ok(html.includes('href="pictures/IDE__A%26B.svg-diff.png"')); - assert.ok(html.includes('src="pictures/IDE__A%26B.svg-render.png"')); - assert.ok(html.includes("the converter did not draw: filter <x> x2")); - assert.ok(html.includes("not drawn: the bundle is of format 1")); - assert.ok(html.includes("the SVG file beside the PNG")); - assert.ok(html.includes("Other/P.png, 5 x 6 px")); - assert.ok(!html.includes("IDE__Gone.svg")); - assert.ok(sheetHtml({ rows: [], plain: [], bar: 0.25, all: true }).includes("Every picture against its SVG")); - }); - test("describes a picture's allowances, and nothing for an entry with none", () => { assert.deepEqual(allowancesOf(null), { png: null, svg: null }); assert.deepEqual(allowancesOf({ build: 1501, png: { decision: { keep: "old", capture: "x" } } }), { @@ -2962,49 +2830,12 @@ describe("the sheet", () => { ); assert.equal(both.svg, `SVG allowance: written below ${SVG_FAITHFUL}% of the pixels 200 levels or more off`); assert.match(allowancesOf({ svg: { ignore: [[0, 0, 1, 1]] } }).svg, /96 levels or more off, 1 rectangle left out$/); - // A limit of its own past the meter's full width is marked at its end. - assert.ok(meterHtml(0, 10, 100, "").includes('')); - }); - - test("shows a picture's own bar and a review's decision on its card", () => { - const row = { - out: "IDE/A.png", - theme: "dark", - size: [10, 10], - pct96: 0.4, - pct32: 1, - pct8: 2, - source: "bundle", - files: judgedFiles("IDE/A.png"), - }; - const html = sheetHtml({ - rows: [ - { - ...row, - faithful: true, - by: "rule", - allowance: "SVG allowance: written below 0.5% of the pixels 96 levels or more off", - own: { share: 0.4, bar: 0.5 }, - }, - { ...row, out: "IDE/B.png", faithful: true, by: "decision", allowance: null, own: null }, - ], - plain: [], - bar: 0.25, - all: false, - }); - assert.ok( - html.includes("SVG allowance: written below 0.5% of the pixels 96 levels or more off: 0.4% off by it"), - ); - assert.ok(html.includes('title="0.4% off by its own bar; the bar is 0.5%"')); - assert.ok(html.includes('')); - assert.ok(html.includes("accepted by a review's decision")); - assert.ok(html.includes('title="0.4% strongly off; the bar is 0.25%"')); }); }); -// The sheet of changes against a git revision (sheet.mjs --against): the change list from git's -// output, the comparison of two pictures over two sizes, the noise rule, the order and the page. -describe("the change sheet", () => { +// What differs from a git revision: the change list from git's output, the noise rule and the +// difference map over two sizes. +describe("changes against a git revision", () => { // An image of one colour, `w` by `h`, and a PNG file of it; `paint` changes pixels. const image = (w, h, grey = 100, paint = () => {}) => { const rgba = new Uint8Array(w * h * 4); @@ -3084,6 +2915,16 @@ describe("the change sheet", () => { ); }); + test("a picture's allowance widens the noise rule, as --cleanup judges two PNGs", () => { + const before = encodePng(image(10, 10)); + // One pixel 30 levels off: a change by the default rule. + const after = encodePng(image(10, 10, 100, setGrey(0, 0, 1, 1, 130))); + const resets = (entry) => cleanupResets({ before, after, entry, near: pngsNear }); + assert.equal(resets(null), false); + assert.equal(resets({ png: { noise: { levels: 32, share: 1 } } }), true); + assert.equal(resets({ png: { ignore: [[0, 0, 1, 1]] } }), true); + }); + test("applies the noise rule the screenshotter applies", () => { const a = image(100, 100); assert.equal(withinNoise(a, image(100, 100)), true); @@ -3122,39 +2963,9 @@ describe("the change sheet", () => { assert.equal(withinNoise(edge(255, 1), edge(0, 1), { share: 1 }), true); }); - test("compares two pictures of one size over their pixels", () => { - const a = image(10, 10); - const b = image(10, 10, 100, setGrey(0, 0, 2, 5, 220)); // 10 pixels, 120 levels - const c = image(10, 10, 100, setGrey(0, 0, 1, 1, 105)); // 1 pixel, 5 levels - const st = compareImages(a, b); - assert.deepEqual([st.sameSize, st.total, st.differing, st.beyond, st.faint], [true, 100, 10, 10, 0]); - assert.equal(st.pctBeyond, 10); - assert.equal(st.noiseOnly, false); - const faint = compareImages(a, c); - assert.deepEqual([faint.differing, faint.beyond, faint.faint, faint.pctBeyond], [1, 0, 1, 0]); - assert.equal(faint.noiseOnly, true); - assert.equal(compareImages(a, image(10, 10)).noiseOnly, true); - }); - - test("compares two pictures of two sizes aligned at the top left, and the map shows the larger", () => { + test("the map of two pictures of two sizes aligns them at the top left and shows the larger", () => { const small = image(4, 2); const large = image(6, 5, 100, setGrey(0, 0, 1, 1, 250)); - const st = compareImages(small, large); - assert.equal(st.sameSize, false); - assert.deepEqual( - [st.old, st.new, st.canvas, st.common], - [ - [4, 2], - [6, 5], - [6, 5], - [4, 2], - ], - ); - // The one pixel of the shared area that differs, and the 22 that only the larger has. - assert.deepEqual([st.total, st.differing, st.beyond], [30, 23, 23]); - assert.equal(st.noiseOnly, false); - // The same the other way round: the shared area is the same, the others are only the old picture's. - assert.equal(compareImages(large, small).differing, 23); const map = decodePng(changeMap(small, large)); assert.deepEqual([map.width, map.height], [6, 5]); const at = (x, y) => [...map.rgba.subarray((y * 6 + x) * 4, (y * 6 + x) * 4 + 3)]; @@ -3170,191 +2981,6 @@ describe("the change sheet", () => { const one = decodePng(changeMap(image(2, 2), image(2, 2, 100, setGrey(0, 0, 1, 1, 101)))); assert.deepEqual([...one.rgba.subarray(0, 3)], [255, 255, 0]); }); - - test("makes a row for each kind of picture, the map only for one in both", () => { - const png = (img) => encodePng(img); - const same = compareRevisionPicture({ out: "a/X.png", status: "modified" }, png(image(8, 8)), png(image(8, 8))); - assert.equal(same.row.kind, "noise"); - assert.equal(same.row.stats.differing, 0); - assert.deepEqual(same.row.files, { old: "a__X.old.png", new: "a__X.new.png", map: "a__X.change.png" }); - assert.ok(Buffer.isBuffer(same.map)); - const moved = compareRevisionPicture( - { out: "a/Y.light.png", status: "modified" }, - png(image(8, 8)), - png(image(8, 8, 100, setGrey(0, 0, 8, 8, 200))), - ); - assert.equal(moved.row.kind, "changed"); - assert.equal(moved.row.theme, "light"); - const added = compareRevisionPicture({ out: "n.png", status: "added" }, null, png(image(3, 3))); - assert.deepEqual( - [added.row.kind, added.map, added.row.sizeNew, added.row.files], - ["added", null, [3, 3], { new: "n.new.png" }], - ); - const gone = compareRevisionPicture({ out: "g.png", status: "deleted" }, png(image(3, 4)), null); - assert.deepEqual([gone.row.kind, gone.row.sizeOld, gone.row.files], ["deleted", [3, 4], { old: "g.old.png" }]); - const bad = compareRevisionPicture( - { out: "b.png", status: "modified" }, - Buffer.from("not a png"), - png(image(2, 2)), - ); - assert.equal(bad.row.kind, "error"); - assert.match(bad.row.error, /not a PNG/); - assert.equal(bad.map, null); - assert.deepEqual(changeFiles("a/X.light.png"), { - old: "a__X.light.old.png", - new: "a__X.light.new.png", - map: "a__X.light.change.png", - }); - }); - - test("judges a picture with its allowance and a review's decision, as --cleanup does", () => { - const png = (img) => encodePng(img); - const before = png(image(10, 10)); - // One pixel 30 levels off: a change by the default rule. - const after = png(image(10, 10, 100, setGrey(0, 0, 1, 1, 130))); - const item = { out: "a/X.png", status: "modified" }; - const plain = compareRevisionPicture(item, before, after); - assert.deepEqual( - [plain.row.kind, plain.row.by, plain.row.share, plain.row.allowance], - ["changed", "rule", NOISE_SHARE * 100, null], - ); - // Within noise at 32 levels, as --cleanup judges it with the same entry. - const loose = { png: { noise: { levels: 32, share: 1 } } }; - const allowed = compareRevisionPicture(item, before, after, loose); - assert.deepEqual([allowed.row.kind, allowed.row.by, allowed.row.share], ["noise", "rule", 1]); - assert.equal(allowed.row.stats.levels, 32); - assert.equal(allowed.row.stats.beyond, 0); - assert.equal(cleanupResets({ before, after, entry: loose, near: pngsNear }), true); - assert.match(allowed.row.allowance, /^PNG allowance: within noise when no pixel is more than 32 levels off/); - // The pixel left out by a rectangle. - const left = compareRevisionPicture(item, before, after, { png: { ignore: [[0, 0, 1, 1]] } }); - assert.equal(left.row.kind, "noise"); - assert.match(left.row.allowance, /1 rectangle left out$/); - // A review's decision about these bytes takes the rule's place, both ways. - const kept = compareRevisionPicture(item, before, after, { - png: { decision: { keep: "old", capture: hashOf(after) } }, - }); - assert.deepEqual([kept.row.kind, kept.row.by, kept.row.allowance], ["noise", "decision", null]); - const taken = compareRevisionPicture(item, before, after, { - png: { noise: { levels: 32 }, decision: { keep: "new", capture: hashOf(after) } }, - }); - assert.deepEqual([taken.row.kind, taken.row.by], ["changed", "decision"]); - // The page says so on the card, and the meter's mark is the picture's own share. - const html = changeSheetHtml({ - rows: [allowed.row, { ...kept.row, out: "a/K.png" }, { ...taken.row, out: "a/T.png" }], - rev: "HEAD", - hash: "h", - short: "s", - prefix: "docs/", - }); - assert.ok(html.includes("by more than 32 grey levels")); - assert.ok(html.includes("kept old by a review's decision")); - assert.ok(html.includes("taken new by a review's decision")); - assert.ok(html.includes('')); - }); - - test("puts the most changed first, then the noise, the added and the deleted", () => { - const row = (out, kind, pctBeyond, pctDiffering = pctBeyond) => ({ - out, - kind, - stats: pctBeyond === undefined ? undefined : { pctBeyond, pctDiffering }, - }); - const rows = [ - row("d.png", "deleted"), - row("n2.png", "noise", 0, 0.2), - row("a.png", "added"), - row("c1.png", "changed", 5), - row("e.png", "error"), - row("n1.png", "noise", 0, 0.4), - row("c3.png", "changed", 40), - row("c2.png", "changed", 5, 9), - row("b.png", "added"), - ]; - assert.deepEqual( - sortChangeRows(rows).map((r) => r.out), - ["c3.png", "c2.png", "c1.png", "e.png", "n1.png", "n2.png", "a.png", "b.png", "d.png"], - ); - }); - - test("quotes a path with a space in the command that restores pictures", () => { - assert.equal( - restoreCommand("HEAD", "docs/", ["IDE/A.png", "Two Words/B.light.png"]), - 'git checkout HEAD -- docs/IDE/A.png "docs/Two Words/B.light.png"', - ); - assert.equal(restoreCommand("HEAD~1", "", ["a.png"]), "git checkout HEAD~1 -- a.png"); - }); - - test("writes a page that names the revision, orders its sections and shows the restore command", () => { - const rows = [ - { out: "IDE/Gone.png", kind: "deleted", theme: "dark", sizeOld: [5, 6], files: { old: "IDE__Gone.old.png" } }, - { out: "IDE/New&.png", kind: "added", theme: "dark", sizeNew: [7, 8], files: { new: "IDE__New&.new.png" } }, - { - out: "IDE/Noisy one.png", - kind: "noise", - theme: "dark", - sizeOld: [10, 10], - sizeNew: [10, 10], - stats: compareImages(image(10, 10), image(10, 10, 100, setGrey(0, 0, 1, 1, 104))), - files: { old: "o.png", new: "n.png", map: "m.png" }, - }, - { - out: "IDE/Big.png", - kind: "changed", - theme: "dark", - sizeOld: [4, 2], - sizeNew: [6, 5], - stats: compareImages(image(4, 2), image(6, 5, 100, setGrey(0, 0, 1, 1, 250))), - files: { old: "big.old.png", new: "big.new.png", map: "big.change.png" }, - }, - ]; - const html = changeSheetHtml({ rows, rev: "HEAD", hash: "abcdef0123456789", short: "abcdef01", prefix: "docs/" }); - assert.ok(html.includes(``)); - assert.ok(html.includes("Pictures changed since HEAD (abcdef01)")); - assert.ok(html.includes("abcdef0123456789")); - const at = (t) => html.indexOf(t); - const order = [ - '

    ', - "

    IDE/Big.png

    ", - '

    ', - "

    IDE/Noisy one.png

    ", - '

    ', - "

    IDE/New&.png

    ", - '

    ', - "

    IDE/Gone.png

    ", - ].map(at); - assert.ok( - order.every((i, k) => i > 0 && (k === 0 || i > order[k - 1])), - String(order), - ); - assert.ok(html.includes("most likely rewritten in error")); - assert.ok(html.includes("
    git checkout HEAD -- "docs/IDE/Noisy one.png"
    ")); - assert.ok(html.includes("
    node scripts/shoot_docs.mjs --cleanup
    ")); - assert.ok(html.includes("size changed from 4 x 2 px to 6 x 5 px")); - assert.ok(html.includes("compared aligned at the top left over the common 4 x 2 px")); - assert.ok(html.includes('href="pictures/big.change.png"')); - assert.ok(html.includes('href="pictures/IDE__New%26.new.png"')); - // One figure for an added or a deleted picture. - assert.ok(!html.includes("IDE__Gone.new.png")); - // With nothing within noise there is no command. - const none = changeSheetHtml({ - rows: rows.filter((r) => r.kind !== "noise"), - rev: "v1", - hash: "h", - short: "s", - prefix: "", - }); - assert.ok(!none.includes("git checkout")); - assert.ok(!none.includes("--cleanup")); - assert.ok(none.includes("Pictures changed since v1 (s)")); - }); - - test("names the cleanup command with the sheet's revision, --only and --docs", () => { - assert.equal(cleanupCommand("HEAD"), "node scripts/shoot_docs.mjs --cleanup"); - assert.equal( - cleanupCommand("HEAD~1", { only: "^IDE/(A|B)", docs: "D:/two words/docs" }), - 'node scripts/shoot_docs.mjs --cleanup --against HEAD~1 --only "^IDE/(A|B)" --out "D:/two words/docs"', - ); - }); }); describe("the picture at a git revision", () => {