diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84b35715..d494d89a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,9 +29,8 @@ permissions: contents: read env: - NODE_VERSION: "24.16.0" - NPM_VERSION: "12.0.2" - RUST_VERSION: "1.98.1" + NODE_VERSION: "26.13.0" + NPM_VERSION: "12.2.1" CARGO_AUDIT_VERSION: "0.22.2" jobs: @@ -74,9 +73,17 @@ jobs: cache: npm - name: Install latest npm 12 run: npm install --global npm@${{ env.NPM_VERSION }} --ignore-scripts --min-release-age=3 + - name: Read pinned Rust toolchain + id: rust-toolchain + shell: bash + run: | + set -euo pipefail + channel="$(node scripts/rust-toolchain.mjs)" + test -n "$channel" + echo "channel=$channel" >> "$GITHUB_OUTPUT" - uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable with: - toolchain: ${{ env.RUST_VERSION }} + toolchain: ${{ steps.rust-toolchain.outputs.channel }} components: rustfmt, clippy - name: Install Linux dependencies run: | @@ -127,9 +134,17 @@ jobs: cache: npm - name: Install latest npm 12 run: npm install --global npm@${{ env.NPM_VERSION }} --ignore-scripts --min-release-age=3 + - name: Read pinned Rust toolchain + id: rust-toolchain + shell: bash + run: | + set -euo pipefail + channel="$(node scripts/rust-toolchain.mjs)" + test -n "$channel" + echo "channel=$channel" >> "$GITHUB_OUTPUT" - uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable with: - toolchain: ${{ env.RUST_VERSION }} + toolchain: ${{ steps.rust-toolchain.outputs.channel }} components: clippy - run: npm ci --ignore-scripts # On windows-latest gpg ships only in Git for Windows (usr\bin), which is @@ -222,9 +237,17 @@ jobs: cache: npm - name: Install latest npm 12 run: npm install --global npm@${{ env.NPM_VERSION }} --ignore-scripts --min-release-age=3 + - name: Read pinned Rust toolchain + id: rust-toolchain + shell: bash + run: | + set -euo pipefail + channel="$(node scripts/rust-toolchain.mjs)" + test -n "$channel" + echo "channel=$channel" >> "$GITHUB_OUTPUT" - uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable with: - toolchain: ${{ env.RUST_VERSION }} + toolchain: ${{ steps.rust-toolchain.outputs.channel }} - name: Install Linux dependencies if: runner.os == 'Linux' run: | @@ -269,9 +292,17 @@ jobs: cache: npm - name: Install latest npm 12 run: npm install --global npm@${{ env.NPM_VERSION }} --ignore-scripts --min-release-age=3 + - name: Read pinned Rust toolchain + id: rust-toolchain + shell: bash + run: | + set -euo pipefail + channel="$(node scripts/rust-toolchain.mjs)" + test -n "$channel" + echo "channel=$channel" >> "$GITHUB_OUTPUT" - uses: dtolnay/rust-toolchain@4be7066ada62dd38de10e7b70166bc74ed198c30 # stable with: - toolchain: ${{ env.RUST_VERSION }} + toolchain: ${{ steps.rust-toolchain.outputs.channel }} - run: npm ci --ignore-scripts - run: node scripts/npm-audit-signatures.cjs - name: npm audit - production diff --git a/.github/workflows/ytdlp-watch.yml b/.github/workflows/ytdlp-watch.yml index 8935e607..8fdc5ca4 100644 --- a/.github/workflows/ytdlp-watch.yml +++ b/.github/workflows/ytdlp-watch.yml @@ -23,7 +23,8 @@ permissions: contents: read env: - NODE_VERSION: "24.16.0" + NODE_VERSION: "26.13.0" + NPM_VERSION: "12.2.1" jobs: watch: diff --git a/.gitignore b/.gitignore index f389f6c4..04d867c9 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,7 @@ assets/.ytdlp-download-*.tmp # E2E run artifacts (kept locally as verification evidence) e2e/artifacts/ + +# Windows VM PowerShell module analysis caches (accidentally committed; never tracked) +Microsoft/ +**/Microsoft/Windows/PowerShell/ diff --git a/AGENTS.md b/AGENTS.md index 3a64969a..a143d489 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,5 +1,8 @@ -# Critical Information - Do not modify +# Critical Information - Do not modify this section, other sections below may be modified - NEVER write unit tests after you write code. - Highly prefer E2E tests as the sole testing mechanism. Use them to verify complex features work. At the end of E2E tests, produce a verifiable and repeatable artifact. - If you must test a system in isolation, FIRST write all the ways it could fail, THEN write the code. +- Do not add agents as co-authors to commits. + +# ROSI \ No newline at end of file diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index dd28bb1c..6fcd242a 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -19,8 +19,9 @@ split into focused modules: | `validation.rs` | Security boundary: URL safety (no private/loopback hosts), path allow-lists, IPC payloads | | `settings.rs` | Settings model, lenient migration/sanitization, import/export | | `legacy.rs` | First-launch import of ROSI 4 data from `/rosi` | -| `downloader.rs` | Single active download session: yt-dlp, optional FFmpeg conversion, cancellation | -| `queue.rs` | Persistent queue (`download-queue.json` + backup) and its sequential runner | +| `downloader.rs` | Single active download session: yt-dlp, optional FFmpeg conversion, cancellation. The session is owned by one thread (`downloader/session_owner.rs`) that runs its tasks in order; callers wait on replies, and the owner never waits on processes or the coordinator. Child modules `downloader/conversion.rs` (FFmpeg runs) and `downloader/publication.rs` (output installs, captions) | +| `queue.rs` | Persistent queue (`download-queue.json` + backup), its writer, and its sequential runner. The queue state is owned by the coordinator thread, not held in a global lock | +| `coordinator.rs` | Single owner of queue state, queue transitions, and session results: one thread applies each change in arrival order, publishes revisioned queue snapshots, and answers reads over reply channels | | `command_builders.rs` | yt-dlp / FFmpeg argument builders and codec probing | | `progress.rs` | yt-dlp JSON / FFmpeg `-progress` parsing, phase and queue weighting, throttling | | `media_info.rs` | Format listing (`-F`) and metadata previews | @@ -28,11 +29,13 @@ split into focused modules: | `sidecars.rs` | Sidecar location and effective FFmpeg resolution | | `process_util.rs` | Scrubbed environment, process groups, tree termination, bounded output capture | | `platform.rs` | Platform queries, beta updater target, OS handoffs (open URL, reveal, notify) | +| `updater.rs` | Update engine: one state thread owns channel and target selection (per-arch zstd feeds with a universal fallback, Rosetta to native `aarch64`), check/download/install generations, single-flight download and install, and the Flatpak feed-only rule; emits `updater-status` and `updater-progress` | | `window.rs` | Splash, deferred main-window reveal, close flow (confirm, settings flush), restart | | `app_menu.rs` | Native macOS menu | | `app_state.rs` | Process-wide handles: app handle, resolved user directories, background event sink | | `constants.rs` | Limits and allow-lists shared by validation, settings, and the downloader | | `deno.rs` | Deno runtime detection and optional install for yt-dlp's JavaScript extractors | +| `download_options.rs` | Shared option precedence, validation, and snapshots for manual and queued downloads and the effective-options preview | | `ffmpeg_guard.rs` | Per-operation FFmpeg/ffprobe launchers that restrict yt-dlp to local inputs | | `fs_util.rs` | Atomic, private file writes and bounded reads for persisted JSON state | | `gpu.rs` | Hardware encoder detection by probing FFmpeg (cached for five minutes) | @@ -40,6 +43,7 @@ split into focused modules: | `ipc.rs` | `{ ok, data } \| { ok: false, error }` envelopes shared with the frontend | | `logging.rs` | Rolling local diagnostics log (`logs/rosi.log`) | | `network_security.rs` | Per-operation outbound proxy that pins each destination to a vetted IP, optionally reached through the user's upstream HTTP proxy | +| `network_security_async.rs` | Tokio implementation of the proxy's listener and client tasks (256 active, 128 pending); DNS stays in `network_security.rs`'s resolver pool | | `staging.rs` | Startup sweep of stale ROSI scratch entries in the download folder (no symlink following) | | `types.rs` | Shared data model, serialized as camelCase to match the v4 bridge shapes | @@ -64,19 +68,20 @@ normal loaders validate everything, and the result is recorded in argument and result types from `generated/ipc-types.ts`. It is the only place that calls `invoke()`; `src/tests/commands.contract.test.ts` checks its names against `src-tauri/build.rs` and the main window capability. -- `tauri-bridge.ts` implements the renderer API (`window.api`) on top of - `commands.ts` and Tauri events. `window.api` stays the seam that the vitest - DOM tests and the E2E specs drive. -- `updater.ts` wraps `@tauri-apps/plugin-updater`. Stable checks use the default - `latest-{target}-{arch}.json` endpoints; beta checks pass the - `{os}-beta-{arch}-{installer}` target from `get_beta_updater_target`. -- `main.ts` is the entry point. It imports the bridge first, then the renderer +- `api.ts` exports the renderer API object `api` on top of `commands.ts` and + Tauri events. Callers import it and call `api.method(...)` at call time. The + vitest DOM tests mock this module. The E2E hook exposes the same object as + `window.__ROSI_E2E__.api` in E2E builds only. +- `engine/updater-ui.ts` draws update state. It calls the updater commands in + `commands.ts` and renders the `updater-status` and `updater-progress` events; + it makes no update decisions. The webview has no updater plugin permissions. +- `main.ts` is the entry point. It imports `api.ts` first, then the renderer modules, then `rosiEngine.ts`. After the renderer reports startup readiness it calls `mark_main_window_ready`, which lets the backend close the splash. - `rosiEngine.ts` is the renderer controller's startup: it loads settings, looks up the DOM, and calls the `engine/bind/*` functions in order, which bind - each feature's controls and the backend events. It calls the same `window.api` contract the v4 Electron preload - exposed, which `tauri-bridge.ts` implements. + each feature's controls and the backend events. It uses the same API contract + the v4 Electron preload exposed, which `api.ts` implements. - `engine/*` are ES modules split out of the controller by feature: `settings-store.ts` (settings state and serialized saves), `settings-view.ts`, `queue-controller.ts`, `manual-download.ts`, `preview-controller.ts`, @@ -111,6 +116,32 @@ builds. The release pipeline (`scripts/run-release.js`, `release-session.js`, The vendored `src-tauri/vendor/tauri-plugin-updater` carries install-safety patches, documented in `src-tauri/vendor/tauri-plugin-updater/PATCHES.md`. +### Compact macOS updates + +Fresh installs use the universal DMG/ZIP. In-app updates on macOS download a +per-arch `ROSI-{aarch64,x86_64}.app.tar.zst` instead of the universal +`ROSI.app.tar.gz` (141.5 MB to about 60 MB): + +- `release:mac:continue` also runs `tauri build --target {aarch64,x86_64}-apple-darwin --bundles app`. + `scripts/pack-macos-updater-zst.js` then repacks each per-arch `.app.tar.gz` with + `zstd --long=27` and signs the result (`tauri signer sign --app-version`). The long + window dedupes `rosi-ffmpeg` against `rosi-ffprobe`. The tar bytes are unchanged, so + the bundle signature and staple survive. +- `scripts/gpg-sign.js` publishes them under `latest-darwin[-beta]-{arch}-app-zst.json` + and never collects the per-arch builds' arch-less `.app.tar.gz`. +- Packaged macOS apps ask for that target (`get_compact_updater_target`). If the + compact feed is missing they fall back to the universal feed, which stays published + for clients older than 5.1.0. An x86_64 process running under Rosetta 2 requests + `darwin[-beta]-aarch64-app-zst` so it updates directly to native Apple Silicon execution. +- Staged updates are verified prior to installation: the vendored updater validates that + the extracted executable and sidecars match the host architecture before live bundle + replacement or backup retirement. +- `rosi-yt-dlp` is upstream's universal2 binary and already compressed, so about + 36 MB of every update is yt-dlp. + +Failure modes: `e2e/updater-zst.failure-modes.md`. Check: `npm run test:e2e:updater-zst` +(report in `e2e/artifacts/updater-zst-report.json`). + ### macOS entitlements for sidecars (planned, not implemented) Today `src-tauri/entitlements.plist` grants `disable-library-validation` and @@ -150,6 +181,7 @@ Ordered plan (confirm each Tauri step with a dry run before changing the pipelin insert steps 2 to 5 into `scripts/release-session.js` or `run-release.js` between `tauri build` and checksum/GPG signing in `scripts/gpg-sign.js`. 7. Regenerated artifacts to re-check before publish: the `.app`, `.app.tar.gz`, + the per-arch bundles and their `.app.tar.zst` (repack after re-signing), `.sig`, the `latest-*.json` manifests, the DMG, the ZIP, checksums, and GPG signatures. `verify-release-draft.js` must pass on the final set. diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ec647cf..c1b369dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # ⬇️ Downloads -| Windows | macOS | Linux | -| :-- | :-- | :-- | -| **EXE: [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.0.2/ROSI-Windows-x64.exe) / [arm64](https://github.com/BurntToasters/ROSI/releases/download/v5.0.2/ROSI-Windows-arm64.exe)** | **[Universal DMG](https://github.com/BurntToasters/ROSI/releases/download/v5.0.2/ROSI-MacOS-universal.dmg)** | **AppImage:** [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.0.2/ROSI-Linux-x64.AppImage) | -|
| **[Universal ZIP](https://github.com/BurntToasters/ROSI/releases/download/v5.0.2/ROSI-MacOS-universal.zip)** | **Flatpak:** [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.0.2/ROSI-Linux-x64.flatpak) | +| Windows | macOS | Linux | +| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------- | +| **EXE: [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-Windows-x64.exe) / [arm64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-Windows-arm64.exe)** | **DMG: [arm64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-MacOS-arm64.dmg) / [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-MacOS-x64.dmg) / [universal](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-MacOS-universal.dmg)** | **AppImage:** [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-Linux-x64.AppImage) | +|
| **ZIP: [arm64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-MacOS-arm64.zip) / [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-MacOS-x64.zip) / [universal](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-MacOS-universal.zip)** | **Flatpak:** [x64](https://github.com/BurntToasters/ROSI/releases/download/v5.1.0-beta.1/ROSI-Linux-x64.flatpak) | > macOS downloads require macOS 15 or later. +> Native arm64 builds run on Apple silicon; native x64 builds run on Intel and +> under Rosetta on Apple silicon. Universal builds run on both architectures. > [!IMPORTANT] > The `.sig` files in this repo are NOT normal GPG signatures. They are for Tauri V2's updater to verify the integrity of updates before downloading and installing. @@ -16,6 +18,42 @@ ROSI! A cross platform yt-dlp GUI built on Tauri V2! +## Changes in `v5.1.0-beta.1:` + +- **Updater:** macOS in-app updates now download compact per-architecture archives (`.app.tar.zst`), reducing update sizes from ~141 MB to ~60 MB using zstd compression. +- **Updater:** Added seamless fallback to universal updates if per-architecture manifests are missing. +- **Updater:** Architecture verification ensures downloaded macOS updates match the host machine before installation. +- **Updater:** Rosetta-translated processes on Apple Silicon automatically request the native arm64 target to migrate away from emulation. +- **Packaging:** Per-architecture updater archives are verified for codesigning and notarization stapling prior to packaging. +- **Packaging:** Native arm64 and x64 DMG/ZIP downloads are available alongside the universal macOS packages. +- **Updater:** Update checks use only the `latest` release feed URLs. The version-pinned fallback URLs were removed, and update signatures must name the version they were signed for (`requireSignedVersion`). +- **Queue:** All queue changes now go through one coordinator, so queue updates reach the window in the order they happen. Each update carries a revision, and an older update never replaces a newer one. +- **Downloads:** Manual downloads, queued downloads, and the effective-options preview share one option-resolution path in the backend, so the options shown before a download match the options it uses. +- **Downloads:** A summary under the output settings shows the effective options for the current URL, profile, formats, and playlist selection. It explains what is missing (a valid URL, a save location, a format, or a valid playlist selection) and waits while settings are saving. +- **Formats:** The video and audio format lists are built from structured data returned by the backend, not from parsing yt-dlp's text output. Each entry shows its resolution, frame rate, codecs, and size when yt-dlp reports them. +- **Network:** The outbound proxy relay runs on the Tokio runtime and serves up to 256 connections at once. Up to 128 more connections wait for a free slot for up to 5 seconds. Connections beyond that, or still waiting after 5 seconds, receive HTTP 503. +- **Settings:** Settings show whether they are saving, saved, or not saved. A failed save keeps your choices on screen and offers a "Retry save" button. If the backend refuses one setting, the other settings still save, and the refused one returns to its saved value. +- **Settings:** Each section's reset button asks for confirmation first, and reports whether the restored defaults were saved. +- **Settings:** Saving settings no longer overwrites changes made elsewhere, such as presets, with stale values. +- **Setup:** The setup wizard shows an inline message when choosing a download folder is cancelled or fails. If the Deno check or install fails, it offers the install instructions. +- **Deno:** If the Deno check fails, ROSI shows a dialog with the install instructions instead of only writing to the log. +- **Build:** Building from source now requires Node.js `^24.22.1` or `>=26.13.0` and npm 12.2.1 or later. CI builds with Node.js 26.13.0 LTS. +- **Build:** The pinned Rust toolchain is 1.99.1, read from `rust-toolchain.toml`. The Flatpak build installs that exact compiler with rustup. +- **Tests:** End-to-end scenarios are grouped by feature in `e2e/suites.json`. `npm run test:e2e -- --group ` runs only the named groups, and reports list each scenario's groups. +- **Downloads:** With "Ask where to save" off and no folder chosen, downloads and the effective-options summary use the system Downloads folder instead of blocking or opening a folder picker. +- **Downloads:** Presets are resolved only by the backend. Applying a preset shows the backend's values, a later change to the stored preset takes effect, and the format lists always download exactly what they show. +- **Downloads:** The reason a download cannot start, and what to do next, now appears beside the Download button. +- **Downloads:** Choosing a folder from the destination strip, or turning off "Ask where to save" without a folder, reports a cancelled or failed folder pick inline. +- **Formats:** Format option labels are built by the backend. +- **Settings:** If settings cannot be loaded at startup, the defaults come from the backend instead of a copy kept in the window. +- **Queue:** When retry, remove, reorder, or open location fails, the message appears on that queue row and the row's other actions stay available. +- **Queue:** Pasted links are checked by the backend with the same rules as adding links to the queue. +- **Activity:** Keyboard focus stays on the same activity action when the list updates, and each new entry is announced once to screen readers. +- **Accessibility:** Dialogs move focus inside as soon as they open. Long URLs, paths, titles, and errors wrap or truncate instead of widening the window. +- **Network:** A proxy client turned away with HTTP 503 now receives the full response on macOS instead of a connection reset. +- **Security:** Every backend command now checks its input against a typed structure. Error messages are unchanged. +- **Updater:** Update checks, downloads, and installs run in the backend, and the window only shows their status. The window no longer has permission to use the updater plugin directly. + ## Changes in `v5.0.2:` - **YT-DLP:** Updated `yt-dlp` to `2026.10.21`. diff --git a/README.md b/README.md index eccd4186..a8263cb5 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,9 @@ webview, so installers and memory use are much smaller. ## System requirements -- macOS 15 or later (universal build for Intel and Apple silicon). The bundled - FFmpeg is built for macOS 15. +- macOS 15 or later. Choose the arm64 package for Apple silicon, the x64 + package for Intel or Rosetta, or the universal package for either processor. + The bundled FFmpeg is built for macOS 15. - Windows 10 version 2004 (build 19041) or later, on x64 or ARM64, with the Microsoft Edge WebView2 runtime (installed automatically when missing). - Linux x64 with WebKitGTK 4.1 (Ubuntu 24.04+, Debian 13+, Fedora 43+, or a @@ -83,7 +84,8 @@ See the Microsoft Store section of [build-setup.md](build-setup.md). convert). 5. Packaged builds: - Windows: `npm run build:win` - - macOS: `npm run build:mac:universal`, then `npm run build:mac:zip` + - macOS: `npm run build:mac:universal`, then `npm run build:mac:zip` for + universal packages; `npm run build:mac:native` for arm64 and x64 packages - Linux x64: `npm run build:linux` (or `npm run build:linux:x64`) - Linux ARM64 (native ARM64 hardware only): `npm run build:linux:arm64` - Flatpak: `npm run flatpak:bundle` diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.md index 04c23c0b..38dccdb1 100644 --- a/THIRD-PARTY-NOTICES.md +++ b/THIRD-PARTY-NOTICES.md @@ -1060,6 +1060,45 @@ The complete, version-specific license notices for every Rust crate compiled into ROSI (including Tauri and its plugins) are generated at build time and shown in the app under **Licenses > Rust Crate Dependencies**. +## zstd (libzstd) + +License: BSD-3-Clause +Link: https://github.com/facebook/zstd + +The macOS updater statically compiles the libzstd reference implementation +via the `zstd-sys` crate for per-architecture archive extraction. + +BSD License + +For Zstandard software + +Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name Facebook, nor Meta, nor the names of its contributors may + be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + --- # Bundled yt-dlp binary diff --git a/build-setup.md b/build-setup.md index 0f470669..a4f2c3ed 100644 --- a/build-setup.md +++ b/build-setup.md @@ -11,7 +11,7 @@ Build from a VS developer shell (`npm run win-compiler:arm64` or `win-compiler:x64`), which puts that clang on `PATH`; a plain PowerShell window does not. -- Node.js `^24.15.0 || >=26` (`engines.node` in package.json) +- Node.js `^24.22.1 || >=26.13.0` (`engines.node` in package.json) - Rust (rustup) - Azure Artifact Signing: once per release VM, as Administrator, run `npm run setup:win:artifact-signing` @@ -19,19 +19,32 @@ ## macOS - macOS 15 or later. `minimumSystemVersion` in `tauri.conf.json` is - 15.0 because the bundled FFmpeg is built for macOS 15; `build:mac:zip` rejects - any bundled Mach-O whose minimum OS is above that floor. + 15.0 because the bundled FFmpeg is built for macOS 15; `build:mac:zip` checks + the minimum OS of each required architecture slice against that floor. - Xcode Command Line Tools (`lipo`, `codesign`, `notarytool`) -- Node.js `^24.15.0 || >=26` +- zstd CLI (`brew install zstd`) for the updater archives; checked by `npm run prerelease:prepare` +- Node.js `^24.22.1 || >=26.13.0` - Rust (rustup) +macOS builds can produce the universal package or native arm64 and x64 +packages. `npm run build:mac:universal` builds the universal DMG/app, then +`npm run build:mac:zip` verifies the signed app and creates its ZIP. +`npm run build:mac:native` builds each native app once with its DMG and +updater archive, then creates architecture-matched ZIPs. Individual prepared +targets are `build:mac:arm64:prepared` and `build:mac:x64:prepared`; run the +matching `build:mac:zip:arm64` or `build:mac:zip:x64` after those builds. +Native app and FFmpeg/ffprobe binaries must be thin for their target. The +upstream universal2 yt-dlp binary may remain universal when it contains the +requested slice. Every public installer is named +`ROSI-MacOS-{arm64,x64,universal}.{dmg,zip}`. + ## Linux - Build the public AppImage on Ubuntu 24.04, the oldest supported glibc baseline. - `npm run setup:deb` installs the Ubuntu build, E2E (xvfb), 7-Zip (for `get:ffmpeg`), and Flatpak prerequisites. -- Node.js `^24.15.0 || >=26` +- Node.js `^24.22.1 || >=26.13.0` - Rust (rustup) - Linux v5 releases ship x64 only (`npm run release:linux:x64`). ARM64 wiring (`release:linux:arm64`, `build:linux:arm64`) remains for future development @@ -39,7 +52,7 @@ ## Rust toolchain policy -ROSI builds with Rust `1.98.1`, pinned in `rust-toolchain.toml` and used by CI, +ROSI builds with the Rust version pinned in `rust-toolchain.toml`, used by CI, Flatpak, and release builds. Install that exact toolchain before building: ```sh @@ -221,9 +234,9 @@ The `b`, `r`, and `release:*` scripts intentionally reset and clean their Git worktrees. Run them only on disposable, isolated build VMs. `b` and `r` run directly without confirmation. `release:finalize` also runs without a guard, so run it only from a checkout with nothing uncommitted. Before publishing, -verify that the draft contains the Windows x64/ARM64 NSIS installers, the -universal macOS DMG/ZIP, Linux x64 AppImage/Flatpak, updater -manifests/signatures, SHA-256 lists, and GPG detached signatures +verify that the draft contains the Windows x64/ARM64 NSIS installers, native +arm64/x64 and universal macOS DMG/ZIP packages, Linux x64 AppImage/Flatpak, +updater manifests/signatures, SHA-256 lists, and GPG detached signatures (`npm run release:verify:draft`). ## Microsoft Store diff --git a/docs/DEPENDENCY_UPDATES.md b/docs/DEPENDENCY_UPDATES.md new file mode 100644 index 00000000..4fe96596 --- /dev/null +++ b/docs/DEPENDENCY_UPDATES.md @@ -0,0 +1,42 @@ +# Dependency updates + +## Rust toolchain + +`rust-toolchain.toml` is the single source of the Rust version. The `channel` +value in its `[toolchain]` table is the only place the version is written. +`scripts/rust-toolchain.mjs` reads that file for the npm scripts, CI reads its +output for the `dtolnay/rust-toolchain` steps, and the Flatpak manifest extracts +the same value with `sed`. + +Do not copy the version into `package.json`, `.github/workflows/ci.yml`, or +`run.rosie.rosi.yml`. + +To bump Rust: + +1. Change `channel` in `rust-toolchain.toml`. Keep `profile` and `components` + in that file as needed. +2. Run `npm run rust:update` to install the pinned toolchain. +3. Run `npm run rust:targets:win`, `npm run rust:targets:mac`, or + `npm run rust:targets:linux` as appropriate. +4. Run `npm run validate:flatpak` and the normal test suite. + +The helper is also usable directly: + +```sh +node scripts/rust-toolchain.mjs # print the pinned version +node scripts/rust-toolchain.mjs --install # install profile and components +node scripts/rust-toolchain.mjs --target aarch64-apple-darwin +``` + +## npm and Cargo + +Run the guarded updaters from a clean worktree: + +```sh +node scripts/npm-safe-update.mjs +node scripts/cargo-safe-update.mjs --manifest-path src-tauri/Cargo.toml +``` + +`npm run u` runs both updaters plus version synchronization. Neither updater +changes the Rust pin; update `rust-toolchain.toml` separately when the toolchain +itself should move. diff --git a/docs/FFMPEG-SIZE-5.1.md b/docs/FFMPEG-SIZE-5.1.md new file mode 100644 index 00000000..50241e46 --- /dev/null +++ b/docs/FFMPEG-SIZE-5.1.md @@ -0,0 +1,88 @@ +# FFmpeg and package size for 5.1 (plan workstream C) + +## Decision (C0) + +Pre-compressing ffmpeg and ffprobe on the release machines and unpacking them +at first launch (plan items C1 to C5) is not done. Every package format ROSI +ships already compresses its payload, so a compressed sidecar archive leaves +the DMG, AppImage, and Flatpak about the same size and makes the Windows NSIS +installer and the macOS `.app.tar.zst` update larger. ROSI does the plan's +alternative levers (C6) instead. + +Measured 2026-11-06 with FFmpeg 9.0.2: Windows x64 `ffmpeg.exe` is 143.9 MB +raw, 55 MB with gzip -6, and 43.8 MB with zstd -19, while the whole 5.0.2 NSIS +installer is 63.7 MB because NSIS already compresses its full payload (about +320 MB) as one solid LZMA stream. Published 5.0.2 sizes: universal DMG +146.9 MB, AppImage 175.9 MB, Flatpak 99.3 MB. + +## C6.1 AppImage zstd SquashFS + +The Linux builds pass `LDAI_COMP=zstd` to linuxdeploy's AppImage plugin, and +`scripts/check-appimage-compression.js` fails the release unless the payload is +zstd and the AppImage runtime can extract it. Failure modes: +[`e2e/appimage-zstd.failure-modes.md`](../e2e/appimage-zstd.failure-modes.md). +Size effect: not measured yet; the Linux release machine must build it once and +record the before and after sizes in IMPLEMENTATION-5.1.md. + +## C6.2 DMG as ULMO + +`build:mac:dmg:ulmo` converts each release DMG from UDZO to ULMO, proves the +`ROSI.app` tree is identical, then signs, notarizes, and staples it. Failure +modes: [`e2e/dmg-ulmo.failure-modes.md`](../e2e/dmg-ulmo.failure-modes.md). + +| Image | UDZO (Tauri) | ULMO | Saved | +| --------------------------- | ------------ | ----------- | ---------------- | +| Universal DMG, 5.0.0-beta.1 | 139,316,852 | 114,260,300 | 25,056,552 (18%) | + +Measured on macOS 27.2 arm64 with `scripts/convert-dmg-ulmo.mjs --no-notarize` +on a local build (report `e2e/artifacts/dmg-ulmo-report.json`). ULFO (LZFSE) +saved under 1 MB, so ULMO is used. Signed and notarized release DMGs are proven +by `release:mac:continue`. + +## C6.3 Dropping ffprobe: not viable + +ffprobe is as large as ffmpeg on every platform (both are static builds of the +same libraries), so removing it would halve the FFmpeg payload: + +| Platform | ffmpeg (bytes) | ffprobe (bytes) | +| ------------- | -------------- | --------------- | +| Windows x64 | 143,919,616 | 143,712,768 | +| Windows arm64 | 77,086,208 | 76,920,320 | +| macOS arm64 | 50,232,552 | 50,041,096 | +| macOS x64 | 75,667,112 | 75,481,112 | +| Linux x64 | 144,906,888 | 144,689,672 | +| Linux arm64 | 106,962,112 | 106,765,504 | + +Study method: E2E builds accept `ROSI_E2E_FFPROBE=log:` (record every +ffprobe call yt-dlp makes through ROSI's media-tool launcher) and +`ROSI_E2E_FFPROBE=absent` (give yt-dlp no ffprobe). Production builds ignore +both (`src-tauri/src/ffmpeg_guard.rs`). Both modes ran the `downloads` and +`conversion` groups on macOS arm64 on 2026-11-08. + +Findings: + +- With ffprobe present, yt-dlp called it 6 times: `-bsfs` (its capability + check) and `-show_streams` on the file for audio extraction, three downloads. +- With ffprobe absent, every download, merge, conversion, and caption scenario + still passed. Only the two checks that test the ffprobe launcher itself + failed (`ffprobe-local-playlist-network-guard`, `ffprobe-only-path-without-ffmpeg`), + as expected. yt-dlp falls back to `ffmpeg -i` for audio codec detection. +- The suites do not exercise features that need network sources, and yt-dlp's + own code (2026.10.21, `yt_dlp/postprocessor/ffmpeg.py` + `get_metadata_object`) raises "ffprobe not found" without ffprobe. ROSI turns + on three of the features that call it: `--sponsorblock-remove` + (`ModifyChaptersPP` needs the real duration), `--embed-thumbnail` + (`EmbedThumbnailPP.get_stream_number` for MP4 and MKV), and + `--embed-metadata` (chapter end-time fixup and info JSON attachment). + +Conclusion: dropping ffprobe would break SponsorBlock removal, thumbnail +embedding, and parts of metadata embedding. Replacing it with a launcher that +turns `ffmpeg -i` output into ffprobe's JSON would have to reproduce +`-show_format -show_streams -print_format json` for every container and codec +yt-dlp reads, which is fragile. ROSI keeps ffprobe. + +A lever that would shrink both tools without changing behavior is a shared +library FFmpeg build (ffmpeg and ffprobe linking one copy of the libav +libraries). It changes how the sidecars are built, signed, notarized, and +located at runtime on all three platforms, so it is a separate decision and is +not part of 5.1.0 unless chosen. diff --git a/docs/IMPLEMENTATION-5.1.md b/docs/IMPLEMENTATION-5.1.md new file mode 100644 index 00000000..e2a628fa --- /dev/null +++ b/docs/IMPLEMENTATION-5.1.md @@ -0,0 +1,94 @@ +# ROSI 5.1 implementation and evidence ledger + +## Accepted delivery + +The following six milestones are accepted for ROSI 5.1. Acceptance is scope, +not a completion claim. This ledger records evidence produced by the verification +foundation at the current worktree snapshot; other workstreams must update their +own status when they produce implementation and platform evidence. + +| # | Milestone | Evidence status | +| --- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | Baseline evidence and E2E organization | The E2E manifest and feature-group selector are implemented. A current inventory capture is retained on Windows x64. It records discovered scenarios separately from execution. The initial full baseline report was overwritten while the shared artifact tree was changing; that report is unavailable and has not been reconstructed. Runtime measurements remain missing. A macOS arm64 full-suite E2E report at `9e60f970d2a62d636a019d7b15975c9814364dde` passed 120 expected scenarios (see the proof matrix). | +| 2 | Native macOS distribution and artifact verification | The native macOS artifact verifier is in progress in a separate workstream. No native macOS package build or size comparison is recorded here. On macOS arm64, `npm run test:e2e:updater-zst` (without `--require-real-builds`) passed 12/12 on 2026-11-07 using derived per-architecture archives; the commit for that run is not recorded here. The signed per-architecture `--require-real-builds` run, signing, notarization, and package size comparison have not run. | +| 3 | Typed formats, shared option resolution, structured lifecycle consumption | Typed formats, shared option resolution, and preset preview are implemented: format lists are built from structured backend data, and preset Apply resolves through the backend (`resolve_preset_options`). The macOS arm64 full gate passed at `9e60f970d2a62d636a019d7b15975c9814364dde`. Lifecycle acceptance, integration, and cross-platform proof remain outstanding. | +| 4 | Queue/session coordinator migration | Implemented with residue: `coordinator.rs` owns queue transitions and session results. Residue: the global `QUEUE` mutex and the `ACTIVE`, `STARTUP`, and `EVENT_PUBLISH` mutexes remain. The full gate passed on macOS arm64 at `9e60f970d2a62d636a019d7b15975c9814364dde`; full-gate proof on the other required platforms is still outstanding. See [ROADMAP-5.1.md](ROADMAP-5.1.md) (B7). | +| 5 | Async proxy migration | Implemented with residue: the Tokio relay in `network_security_async.rs` serves 256 active and 128 pending clients. The relay wakes on a cancellation watch channel and DNS replies arrive over oneshot channels, so it has no polling sleeps. Residue: the DNS pool still uses blocking threads with a condvar, the blocking caller outside the relay keeps a 25 ms reply check, and required-platform full-gate proof is still outstanding. | +| 6 | Full-app polish and integrated release candidate | Accepted; the integrated candidate and full required-platform E2E proof remain outstanding. The macOS arm64 full gate passed at `9e60f970d2a62d636a019d7b15975c9814364dde`. No other platform has a build or app E2E run. | + +Milestone 6 keeps ROSI's visual identity and layout while improving downloads, +queue management, settings, onboarding, and accessibility. It does not add the +major features listed as deferred below. + +## Required support and proof matrix + +ROSI 5.1 must retain the current supported platforms: macOS 15 and newer, Linux +x64, and Windows x64 and arm64. A Windows x64 inventory capture does not prove +the app or release artifacts on any platform. + +| Platform | Evidence from this foundation | +| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| macOS 15+ | Apple silicon (arm64), macOS 27.2. Full gate `npm run test:all -- --require-clean-proof` passed at commit `9e60f970d2a62d636a019d7b15975c9814364dde`, completed 2026-11-08T00:01:02Z. Every check passed. The full-suite E2E report passed with 120 expected scenarios and 26 screenshots, and a release quality-gate proof was recorded. Window mode was background (`ROSI_E2E_BACKGROUND=1`). Report: `e2e/artifacts/e2e-report-darwin-arm64.json`, SHA-256 prefix `687e91abd3249ec8`. `npm run test:e2e:updater-zst` passed 12/12 on 2026-11-07 using derived per-architecture archives, without `--require-real-builds`. Not run: the `--require-real-builds` updater run with signed per-architecture builds, signing, notarization, and native package size comparison. No macOS x64 result is recorded. | +| Linux x64 | No build or app E2E performed. | +| Windows x64 | Benchmark inventory captured on this host; no build, app E2E, or release artifact verification performed. | +| Windows arm64 | No build or app E2E performed. | + +Existing archived reports are recorded as references only. This work does not +claim that historical baseline runs passed or that their results correspond to +the saved clean snapshot. + +## Baseline artifact + +The retained current-only inventory is +`e2e/artifacts/benchmark-51-current-final-win32-x64.json`, with its adjacent +`.sha256` file. It records the source revision and dirty-file hashes, the saved +clean-snapshot identity, host and tool versions, evidence artifact and sidecar +sizes, the static and dynamic suite inventory, and references to existing +reports. Native release packages are `not-measured` when no packages are +present; frontend `dist/` is recorded separately. The benchmark records that no +scenarios were executed by that command. + +The older schema 1 file named `benchmark-51-baseline-win32-x64.json` is a +current-only capture made after the initial report was overwritten. It is not +the retained baseline and is not a valid comparison input for the current +schema. + +The current inventory has 103 static scenarios and 8 dynamic `v5-fixes` areas. +These are discovered counts, not passed scenario counts. The first full +baseline report produced during this work was overwritten while the shared +E2E artifact tree was changing. It is unavailable as a verifiable report; no +historical count or report content is reconstructed. The saved clean snapshot +still identifies `010d9faf5fd0ff1284b5a26be20f8c05c14fc690` and contains 522 +tracked-file hashes with empty staged and unstaged patches. It does not contain +runtime observations. + +Runtime data for startup, idle CPU, peak memory, queue latency, and proxy +throughput is **missing, not measured**. The initial runtime baseline cannot be +reconstructed from the saved source snapshot. + +To provide real measurements later, pass a versioned runtime metrics JSON file +to `scripts/benchmark-51.mjs --runtime-metrics `. The tool records the +input hash, method, host, units, and sample counts, and compares a metric only +when both reports contain compatible measured values. Missing inputs remain +explicit; the tool does not derive runtime values from artifact sizes or old +report references. + +## Performance and artifact acceptance + +There is no numeric performance target. Before and after evidence must show +smaller native macOS package artifacts. Startup, CPU and memory use, queue +latency, proxy throughput, and other agreed runtime measures must show no +regression. The retained current capture has no runtime values and no native +package measurements, so this acceptance is still open. An absent package +inventory is not a zero-byte package or evidence of a saving. + +Each comparison must identify its source revision, platform, architecture, tool +versions, measurement method, and report hash. Do not compare measurements from +different hosts as if they were like-for-like. + +## Deferred beyond 5.1 + +These items remain outside the accepted delivery: an independent yt-dlp update +channel, updater key rotation, macOS entitlement redesign, new Flatpak hosting, +Linux arm64 support, and major product features. Existing Flatpak packaging and +current supported platforms remain in the required release-verification scope. diff --git a/docs/RELEASE-STABLE.md b/docs/RELEASE-STABLE.md index 5b2e2491..186b4a22 100644 --- a/docs/RELEASE-STABLE.md +++ b/docs/RELEASE-STABLE.md @@ -113,6 +113,12 @@ finds a runtime change, stop: that runtime must be beta-tested before stable promotion. Download the `e2e-*` evidence artifacts from that CI run and confirm each report lists every scenario as passed. +On a Mac, the local E2E gate runs ROSI in background mode by default +(`ROSI_E2E_BACKGROUND=1`, see `e2e/README.md`). CI runs in the foreground. The +gate report does not record the window mode, so the release record for any +macOS evidence must state the mode that produced it: background (the default) +or foreground (`ROSI_E2E_FOREGROUND=1`). + If the accepted beta still needs to be published, use the normal beta release flow first and complete beta smoke testing before the stable version change. @@ -175,6 +181,21 @@ Also confirm: - `cargo audit` reports no unignored vulnerability. - The stable version is `X.Y.Z` everywhere and contains no `-beta.N` suffix. +On the macOS release machine, also run the E2E stability run on the exact +stable commit, after the gate above has passed: + +```sh +npm run test:e2e:stability +``` + +It repeats the full E2E gate five times (`scripts/test-e2e.js --repeat 5`), so +expect several hours. It writes `e2e/artifacts/e2e-stability-darwin-arm64.json`, +and the release record must cite that file. Known flake: the macOS +`download-process-repairs` scenario (spec `e2e/download-process.spec.js`, runner +`e2e/run-download-process.mjs`) can fail on execute or async timeouts. Re-run +the failing pass once before debugging, and record both the first result and +the re-run result in the release record. + ## 5. Build and sign on isolated platform VMs Use clean, isolated release VMs. Load their signing secrets for the session diff --git a/docs/ROADMAP-5.1.md b/docs/ROADMAP-5.1.md index 76dc1843..4e83c034 100644 --- a/docs/ROADMAP-5.1.md +++ b/docs/ROADMAP-5.1.md @@ -1,20 +1,26 @@ # ROSI 5.1 roadmap -These are deferred, long-term items. None of them blocks 5.0.0 stable. Each -entry gives the problem with file and line evidence, a concrete plan, and +This status ledger separates work already present in the repository, scope +accepted for ROSI 5.1, and work deferred beyond 5.1. “Accepted” is a planning +status, not evidence that implementation or platform verification is complete. +The accepted delivery plan and proof gaps are in +[IMPLEMENTATION-5.1.md](IMPLEMENTATION-5.1.md). The required stable matrix is +macOS 15 and newer, Linux x64, and Windows x64 and arm64. Linux arm64 remains +deferred. Each entry gives the problem with file evidence, a concrete plan, and acceptance criteria. Line numbers were read on 2026-10-19 and will drift; search for the named symbol when they do. -Items already covered by the current stable-readiness fixes are not listed -here. Keep each item's acceptance criteria as the definition of done, and check -them against the E2E evidence the change produces. Where a plan adds a -dependency, the change must be approved on its own; this roadmap does not add -one. +Check acceptance criteria against evidence from the change that produces it. +Where a plan adds a dependency, the change must be approved on its own; this +roadmap does not add one. ## 1. Split the renderer engine into feature modules -**Status (2026-10-20): done in 5.0.0-beta.4.** Feature logic lives in `src/engine/`, and per-feature event binding in `src/engine/bind/`. `src/rosiEngine.ts` (about 570 lines) loads settings, looks up the DOM, and calls the bind functions in their original order. - +**Status (2026-11-06): partial implementation present.** Feature logic lives in +`src/engine/`, and per-feature event binding in `src/engine/bind/`. +`src/rosiEngine.ts` is about 440 lines and still defines `initializeRenderer`; +`window.rosiModules` remains in use. The extraction is useful existing work, but +the acceptance criteria below are not all met. No completion is claimed here. **Problem.** `src/rosiEngine.ts` is 5,943 lines. `initializeRenderer` starts at `src/rosiEngine.ts:2370` and runs to about line 5927. It holds 66 nested @@ -47,11 +53,14 @@ taking explicit inputs. ## 2. Typed command layer and generated IPC types -**Status (2026-10-20): done in 5.0.0-beta.4.** `src/generated/ipc-types.ts` is generated from the Rust types (test-only `ts-rs`), `src/commands.ts` types every command call, and a contract test checks the command names against `build.rs` and the capability. `window.api` stays as the seam for vitest and E2E; removing it would mean rewriting those harnesses, which is not planned. - +**Status (2026-11-06): partial implementation present.** +`src/generated/ipc-types.ts`, `src/commands.ts`, and the command contract check +exist. The renderer API is now the `api` module in `src/api.ts` (B6 part B), +not `window.api`. Only the E2E hook exposes it, as `window.__ROSI_E2E__.api` +in E2E builds. The method list is still hand-written, so this item is not done. -**Problem.** `src/tauri-bridge.ts:132` assigns `window.api`, a shim that copies -the v4 Electron contract onto Tauri. The renderer also depends on IIFE modules +**Problem.** The API object (formerly `src/tauri-bridge.ts`, now `src/api.ts`) +copies the v4 Electron contract onto Tauri. The renderer also depends on IIFE modules exposed as window globals. The settings shape is written twice by hand: `src-tauri/src/types.rs:59` (`struct Settings`) and the TypeScript copy in `src/rosiEngine.ts:39` (`theme: 'system' | 'light' | 'dark' | 'purple'`). They @@ -64,14 +73,15 @@ can drift without a compile error. Neither `tauri-specta` nor `ts-rs` is in Compare their Tauri 2 support and how they fit the build. Choose one. 2. Generate a TypeScript file from the Rust command and type definitions during the build. Commit the generated file and have CI fail if it is stale. -3. Replace `window.api` with typed wrappers around `invoke` and event listeners. - Migrate one command group at a time, and delete each `window.api` member once - no caller uses it. +3. Replace the hand-written API methods with typed wrappers around `invoke` and + event listeners. Migrate one command group at a time. The `api` module exists; + the wrappers inside it are still per-method. 4. Replace the IIFE globals with ES module imports, as item 1 does. **Acceptance criteria.** -- `window.api` and `window.rosiModules` no longer exist in `src/`. +- `window.api` and `window.rosiModules` no longer exist in `src/` (met: the API + is the `api` module, and the E2E seam is `window.__ROSI_E2E__.api`). - No hand-written copy of `Settings` or any other IPC type remains in `src/`. - A stale generated file fails CI, and a Rust type change without a matching TypeScript change fails the type check. @@ -81,6 +91,10 @@ can drift without a compile error. Neither `tauri-specta` nor `ts-rs` is in **Status (2026-10-20): settings enums done in 5.0.0-beta.4** (`Theme`, `DockTab`, `DownloadProfile`, `GpuType`, `UpdateChannel`). Remaining: typed IPC structs in place of `serde_json::Value` plus hand validation. +**Status (2026-11-06): partially implemented; typed IPC structs remain open.** +The settings enums are present in `src-tauri/src/types.rs`. `serde_json::Value` +still appears in backend helpers and command/probe code; no claim is made that +the old acceptance criteria are complete. **Problem.** Several settings are free-form strings: `theme` (`src-tauri/src/types.rs:61`), `dock_tab` (`:63`), `download_mode` (`:65`), @@ -117,6 +131,14 @@ back to defaults rather than failing the import. ## 4. Replace the downloader and queue locks with a state thread +**Status (2026-11-06): implemented with residue, see [IMPLEMENTATION-5.1.md](IMPLEMENTATION-5.1.md).** +`coordinator.rs` runs one command thread with reply channels and revisioned +`queue-update`, and the condition variables are gone. Residue: + +- `queue.rs:40` still has the global `QUEUE: OnceLock>`; + `downloader.rs:79-85` still has `ACTIVE`, `STARTUP`, `EVENT_PUBLISH` mutexes. + Acceptance said "no global Mutex or Condvar". + **Problem.** The download and queue state uses global locks and condition variables. `src-tauri/src/downloader.rs:78` holds `ACTIVE: Mutex>` with `SESSION_CHANGED` (`:82`), `FINALIZING` (`:83`), and @@ -146,6 +168,16 @@ rather than enforced by types. ## 5. Async proxy relay on the Tauri runtime +**Status (2026-11-06): implemented with residue, see [IMPLEMENTATION-5.1.md](IMPLEMENTATION-5.1.md).** +The Tokio relay in `network_security_async.rs` serves 256 active and 128 +pending clients, and answers 503 on overload. The E2E probe is in place. Residue: + +- Polling remains: `network_security_async.rs:37,174-185` + (`EXTERNAL_CANCELLATION_POLL` 25 ms per client task), `:686-702` (DNS reply + polled with `try_recv` + 25 ms sleep); the DNS pool is still blocking threads + with a condvar (`network_security.rs:56,398-440`). Acceptance said "no polling + sleep" and "no measurable idle CPU". + **Problem.** `src-tauri/src/network_security.rs` is 1,917 lines. It starts `PROXY_WORKERS: usize = 32` blocking workers (`:35`). Each `proxy_worker` (`:604`) takes one client at a time, so the worker count caps concurrent @@ -178,6 +210,13 @@ idle relay still wakes up on its sleep. ## 6. Regroup E2E suites by feature +**Status (2026-11-06): implemented with residue, see [IMPLEMENTATION-5.1.md](IMPLEMENTATION-5.1.md).** +`e2e/suites.json`, `--group` selection, and `scenarioGroups` in reports are in +place. Residue: + +- 23 files in `e2e/` still named `round*`/`audit*`/`*repair*`; + `scripts/test-e2e.js` is 2,430 lines (target < 800). + **Problem.** `e2e/` holds about 95 files and roughly 25,000 lines. 35 of the file names refer to audit rounds or repair passes (for example `round2-native.spec.js`, `audit4-repairs.spec.js`, and @@ -205,6 +244,8 @@ names say nothing about what they cover. `scripts/test-e2e.js` is 2,165 lines. ## 7. Centralize user-facing strings +**Status (2026-11-06): deferred beyond ROSI 5.1.** + **Problem.** User-facing text is written inline in the renderer and the Rust backend. `src/rosiEngine.ts` has about 56 lines that call a toast helper, and the Rust backend has about 225 `format!` string literals, not all of them user-facing. Wording differs between the two sides, and no one @@ -231,6 +272,10 @@ can translate or review the full set in one place. ## 8. macOS sidecar entitlements +**Status (2026-11-06): entitlement redesign deferred beyond ROSI 5.1.** The +current signing model remains part of platform verification; this roadmap item +does not authorize a pipeline or entitlement change. + **Problem.** Today `src-tauri/entitlements.plist` grants the whole app, including every sidecar, `disable-library-validation` and `allow-unsigned-executable-memory`. Only the PyInstaller `rosi-yt-dlp` needs them. The fix is already planned in @@ -251,6 +296,9 @@ with a dry run before changing the pipeline. ## 9. Signed yt-dlp-only update channel +**Status (2026-11-06): deferred beyond ROSI 5.1.** This is the independent +yt-dlp update channel explicitly excluded from the accepted 5.1 milestones. + **Problem.** yt-dlp is bundled. `assets/ytdlp-checksums.json` is the committed manifest (`scripts/fetch-ytdlp.cjs:37`), and `.github/workflows/ytdlp-watch.yml` updates it from the GPG-verified upstream `SHA2-256SUMS`. A YouTube break @@ -283,6 +331,8 @@ work, even though only one binary changed. ## 10. Dual-key updater support +**Status (2026-11-06): deferred beyond ROSI 5.1.** + **Problem.** The vendored updater trusts one Minisign public key, set in `src-tauri/tauri.conf.json:115` as `plugins.updater.pubkey`. A rotation needs a release signed with the old key, and a compromised old key can publish such a @@ -309,6 +359,8 @@ release too. [KEY-COMPROMISE.md](KEY-COMPROMISE.md) describes this limit. ## 11. Deno end of life (about October 2027) +**Status (2026-11-06): deferred beyond ROSI 5.1.** + **Problem.** yt-dlp uses Deno as its default JavaScript runtime for YouTube. Deno is expected to shut down around October 2027, and yt-dlp has not picked a replacement. ROSI finds Deno by path in `src-tauri/src/deno.rs:19` to `:48`, and @@ -333,6 +385,10 @@ wizard in `src/rosiEngine.ts`. See also the "Deno end of life" section of ## 12. Flathub or a hosted Flatpak repository +**Status (2026-11-06): new Flatpak hosting and Linux arm64 deferred beyond +ROSI 5.1.** Existing Flatpak packaging remains in the required Linux x64 +verification scope. + **Problem.** The Flatpak is a single-file bundle, `ROSI-Linux-x64.flatpak`, on the GitHub release. The in-app updater does not apply to Flatpak, so Flatpak users update only by downloading the new file by hand. The stable runbook's @@ -355,3 +411,69 @@ updater gate requires a manual reinstall for the same reason. - The release pipeline fails if the repository is not updated for a stable release. - The runbook's Flatpak updater step is replaced by a `flatpak update` check. + +## Deferred to 5.1.x + +These items are not required for 5.1.0. They are planned for 5.1.x and have not +started. The proof gaps for the accepted milestones are in +[IMPLEMENTATION-5.1.md](IMPLEMENTATION-5.1.md). + +### B7: Finish coordinator ownership (roadmap item 4) + +**Precondition.** The full gate, `npm run test:all -- --require-clean-proof`, +must be green on every required platform (macOS 15 and newer, Linux x64, +Windows x64, and Windows arm64) before this change starts. Today it is green +only on macOS arm64. Before the port, write failure-mode rows for +`cancel_session`, `complete_session`, `start_download`, and `on_ytdlp_exit` +(`src-tauri/src/downloader.rs`). Part B's rows are in +`e2e/session-ownership.failure-modes.md`. + +**Remaining globals** in `src-tauri/src` at this snapshot: + +| Symbol | File and line | Role | +| --------------------------------------------------------- | ----------------------------- | ------------------------------------------------------------------------------------- | +| `QUEUE`: `OnceLock>`, read by `state()` | `queue.rs:42`, `queue.rs:197` | **Done (B7 part A).** Removed. `QueueState` is a local in `coordinator::run`; reads are `Snapshot` and `IsRunning` requests. | +| `PERSISTENCE` (inside `persistence()`) | `queue.rs:180` | **Kept.** Configuration only: file paths and the save function. Its `revisions` mutex serializes the writer's `persist` and `flush`, and the writer tests depend on that, so it stays. | +| `WRITER` (inside `writer()`) | `queue.rs:328` | **Kept.** A `OnceLock` holding the writer's channel sender, not shared state. | +| `ACTIVE`: `Mutex>`, read by `lock()` | `downloader.rs` (was `:82`) | **Done (B7 part B).** Removed. The session lives on the session owner thread (`downloader/session_owner.rs`). Reads and changes are tasks run in arrival order. | +| `ACTIVE_PRESENT`: `AtomicBool` | `downloader.rs` (was `:85`) | **Done (B7 part B).** Replaced by the owner's read-only `SLOT_OWNER` hint, which `is_busy` and `can_start` read. The install task decides. | +| `STARTUP`: `Mutex<()>` | `downloader.rs` (was `:87`) | **Done (B7 part B).** Removed. `install` makes the one authoritative check. A same-owner start cancels the occupant by id, awaits it, and retries. | +| `EVENT_PUBLISH`: `Mutex<()>` | `downloader.rs` (was `:88`) | **Done (B7 part B).** Removed. The owner runs every event emit in arrival order, so a replaced session's events are dropped. | +| `COUNTER`: `AtomicU64` | `downloader.rs:94` | **Kept with reason.** Mints session ids before install, so no owner round trip is needed. It is an atomic counter, not shared state. | + +The `downloader/conversion.rs` and `downloader/publication.rs` modules declare no +statics. Test-only statics (`SERIAL` at `downloader.rs:1631`) are excluded. +Outside this list: `coordinator.rs` `COORDINATOR` holds a channel sender, not +state, and `activity.rs` `state()` is outside the queue and downloader scope. + +**Acceptance.** Item 4's criteria apply: no global `Mutex` or `Condvar` in +`downloader.rs` or `queue.rs`, queue updates keep their order, and the cancel, +start, and restart E2E scenarios pass repeatedly. The `OnceLock` and atomic +statics above are listed so the port accounts for them too. + +### B6: Renderer seams (roadmap items 1 and 2) + +**Status: done (part A and part B).** Not a 5.1.0 blocker, as the +implementation plan states. + +- Part A: `window.rosiModules` is removed. The modules are ES module imports + (commit 17d0dea). +- Part B: `window.api` is removed. The API object is `api` in `src/api.ts`. + Renderer callers import it and call `api.method(...)` at call time. The + E2E hook sets `window.__ROSI_E2E__.api` to the same object, inside the + `VITE_ROSI_E2E` branch only. `src/tauri-bridge.ts` is deleted. The vitest + DOM suite mocks `../api`, and the renderer DOM checks pass the module to + their loader. Failure modes: `src/api.failure-modes.md`. + +**Remaining.** The method signatures in `RosiRendererApi` (`src/api.ts`) are +still written by hand. They use the generated payload types, but the method +list is not generated from `commands.ts`. That is outside this item and can be +done later. + +**Removal order (done).** Part A converted the modules to ES imports. Part B +moved the API into `src/api.ts`, switched every caller to `api.method(...)` +at call time, and removed the old global. + +**Acceptance (met, except the hand-written method list under Remaining).** +`window.api` and `window.rosiModules` no longer exist in `src/`, and the E2E +specs read `window.__ROSI_E2E__.api`. diff --git a/e2e/README.md b/e2e/README.md index 76967686..68823a75 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -9,31 +9,96 @@ E2E binary once, runs every suite below against that binary, writes evidence to from that spec alone, and its report sets `fullSuite: false` and `onlySpec`, so release evidence rejects it. A blank value counts as unset. +`e2e/suites.json` is the canonical static scenario inventory and feature index. +It maps the existing files to their current runner owners. Files are named by +feature; the owner ids and scenario names are unchanged from the earlier round +and audit names. To run selected feature groups, use `npm run test:e2e -- --group +settings,queue` or set `ROSI_E2E_GROUPS=settings,queue`. The selector expands to +the whole current runner owner, so a group that uses `main.spec.js` can report +scenarios from other features owned by that same pass. Reports include both the +requested groups and the expanded scenario list. Group runs set +`fullSuite: false`, use a fresh E2E binary, and are not release proof. A group +selection cannot be combined with `ROSI_E2E_ONLY`. + On a local Mac the gate runs ROSI in background mode (`ROSI_E2E_BACKGROUND=1`): the E2E app has no Dock icon, never takes focus, and its window stays below -other apps. Native alert dialogs that specs open on purpose still appear. CI +other apps. Native alert dialogs that specs open on purpose still appear. The +page keeps rendering in background mode: WebKit would otherwise report a window +behind other apps as occluded and mark the page hidden, which stops animation +frames and CSS transitions. The E2E build turns WebKit's occlusion detection +off for the main webview (`src-tauri/src/window.rs`, `e2e_occlusion`), and the +window's level, focus, and activation policy stay as described above. CI runs in the foreground; set `ROSI_E2E_FOREGROUND=1` to do the same locally. +The gate report does not record the window mode. Release evidence from a Mac +uses the default background mode unless `ROSI_E2E_FOREGROUND=1` is set, and +the release record must state which mode produced the report. The +`settings-reset-all` and `close-flow` scenarios wait for their observable +effects (the reset bridge call, the "Main window closed." log line), not fixed +delays, so both modes use the same waits. + +| Suite | Area | How the gate runs it | +| ------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | +| `specs/legacy-import.spec.js` | Legacy import | WebdriverIO pass, twice: import and corrupt settings | +| `specs/main.spec.js` | Persistence, settings, UI, downloads, close flow | WebdriverIO main pass | +| `specs/security-release-offline-queue.spec.js` | Security and network (offline queue) | WebdriverIO pass | +| `specs/security-release-checks.spec.js` | Security and network | WebdriverIO pass | +| `state-updater.spec.js` | Updater and state | WebdriverIO pass | +| `renderer-updates.spec.js` | Renderer | WebdriverIO pass | +| `native-downloads.spec.js` via `native-downloads-run.mjs` | Download and process (native) | Runner, verified report | +| `long-term-persistence.spec.js` via `long-term-persistence-run.mjs` | Persistence | Runner, verified report | +| `download-process.spec.js` via `run-download-process.mjs` | Download and process | Runner, verified report (macOS and Linux) | +| `download-process-targeted.spec.js` via `run-download-process.mjs` | Download and process (captions, sidecars, GPU, playlists) | Same runner with `ROSI_REPAIRS_SPEC`, verified report (macOS and Linux) | +| `download-session.spec.js` via `download-session-run.mjs` | Download and process (artwork, queue drain) | Runner, `result.json` verified under `e2e/artifacts/audit4-repairs/` | +| `platform-probes/probes.spec.js` via `run-probes.mjs` | Security (`--security`), renderer (`--ui`), process termination (`--termination`) | Four launches, one per mode, macOS only. Every `invariantPassed` must be true | +| `renderer-dom-checks/run.cjs` | Renderer and updater (jsdom, no app) | Node runner, all 15 checks must pass | +| `e2e/v5-fixes//*.spec.js` (no `run.mjs` in the area) | Whatever the area covers | WebdriverIO pass per area, one fresh profile each | +| `e2e/v5-fixes//run.mjs` and the specs it drives | Whatever the area covers | Runner only, after the build; verified report (see below) | +| `e2e/v5-fixes/network/run.mjs` | Security and network policy | Runner, `report.json` under `e2e/artifacts/v5-fixes-network/` | +| `e2e/v5-fixes/persistence/run.mjs` | Persistence acceptance | Runner, `report.json` under `e2e/artifacts/v5-fixes-persistence/` | +| `e2e/v5-fixes/downloader/run.mjs` | Downloader (install fallback, orphan sweep, panic log) | Runner, `report.json` under `e2e/artifacts/v5-fixes-downloader/` | + +The report keeps the original flat `expectedScenarios` inventory for release +checks and adds `scenarioGroups` so outcomes can be read by feature. Existing +runner ownership, platform-specific skip allowances, fresh-report checks, and +the E2E binary hash checks are described in the manifest and runner. + +## ROSI 5.1 baseline capture + +`node scripts/benchmark-51.mjs --label current --snapshot ` +records the current source revision and dirty-file hashes, platform, tool +versions, evidence artifact and sidecar sizes, static and dynamic scenario +inventory, and references to reports already under `e2e/artifacts/`. Native +package sizes are recorded separately; when packages are absent, their size is +`not-measured` rather than zero. Frontend `dist/` size is also separate from +native packages. The command writes a timestamped JSON report and `.sha256` +sidecar; it does not execute scenarios. The inventory counts discovered cases, +while execution evidence remains `not-run` for the benchmark capture. + +The first full baseline report created during ROSI 5.1 foundation work was +overwritten while the shared artifact tree was changing. That report is not +retained or verifiable, and its contents are not reconstructed. A later +current-only capture does not stand in for that lost baseline. + +To compare a later capture, run: + +```sh +node scripts/benchmark-51.mjs --label candidate \ + --compare path/to/baseline.json \ + --runtime-metrics path/to/runtime-metrics.json +``` -| Suite | Area | How the gate runs it | -| ------------------------------------------------------------------------- | --------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | -| `specs/legacy-import.spec.js` | Legacy import | WebdriverIO pass, twice: import and corrupt settings | -| `specs/main.spec.js` | Persistence, settings, UI, downloads, close flow | WebdriverIO main pass | -| `specs/security-release-offline-queue.spec.js` | Security and network (offline queue) | WebdriverIO pass | -| `specs/security-release-repairs.spec.js` | Security and network | WebdriverIO pass | -| `state-updater-repairs.spec.js` | Updater and state | WebdriverIO pass | -| `round2-renderer-repairs.spec.js` | Renderer | WebdriverIO pass | -| `round2-native.spec.js` via `round2-native-run.mjs` | Download and process (native) | Runner, verified report | -| `long-term-v5-audit.spec.js` via `long-term-v5-audit-run.mjs` | Persistence | Runner, verified report | -| `download-process-repairs.spec.js` via `run-download-process-repairs.mjs` | Download and process | Runner, verified report (macOS and Linux) | -| `audit3-native-targeted.spec.js` via `run-download-process-repairs.mjs` | Download and process (captions, sidecars, GPU, playlists) | Same runner with `ROSI_REPAIRS_SPEC`, verified report (macOS and Linux) | -| `audit4-repairs.spec.js` via `audit4-repairs-run.mjs` | Download and process (artwork, queue drain) | Runner, `result.json` verified under `e2e/artifacts/audit4-repairs/` | -| `audit-v5-beta2/audit.spec.js` via `run-probes.mjs` | Security (`--security`), renderer (`--ui`), process termination (`--termination`) | Four launches, one per mode, macOS only. Every `invariantPassed` must be true | -| `round3-renderer-repairs/run.cjs` | Renderer and updater (jsdom, no app) | Node runner, all 15 checks must pass | -| `e2e/v5-fixes//*.spec.js` (no `run.mjs` in the area) | Whatever the area covers | WebdriverIO pass per area, one fresh profile each | -| `e2e/v5-fixes//run.mjs` and the specs it drives | Whatever the area covers | Runner only, after the build; verified report (see below) | -| `e2e/v5-fixes/network/run.mjs` | Security and network policy | Runner, `report.json` under `e2e/artifacts/v5-fixes-network/` | -| `e2e/v5-fixes/persistence/run.mjs` | Persistence acceptance | Runner, `report.json` under `e2e/artifacts/v5-fixes-persistence/` | -| `e2e/v5-fixes/downloader/run.mjs` | Downloader (install fallback, orphan sweep, panic log) | Runner, `report.json` under `e2e/artifacts/v5-fixes-downloader/` | +The default output includes a timestamp and refuses to replace an existing +file. An explicit `--out ` also refuses to overwrite; pass `--force` only +when replacement is intentional. The runtime metrics input uses +`schemaVersion: 1`, the measured `platform` and +`arch`, a `method` description, and a `measurements` object. Supported fields +are `startupMs` (`ms`), `idleCpuPercent` (`percent`), `peakMemoryBytes` +(`bytes`), `queueLatencyMs` (`ms`), and `proxyThroughputBytesPerSecond` +(`bytes_per_second`). Each value is an object with a numeric `value` and exact +`unit`; optional `samples`, `method`, and `evidence` fields preserve measurement +context. Missing values stay `not-measured`; comparisons produce a delta only +when both reports contain a compatible measurement. No historical runtime +result is inferred from existing E2E report files. ### v5-fixes areas and `run.mjs` @@ -80,10 +145,15 @@ hand or from CI. They need network access and do not start the app. closes. Specs run inside the gate's pass, so they can use `ROSI_E2E_MEDIA_URL`. - Do not run cargo between the E2E build and the gate, since that replaces the E2E binary. The gate checks the binary hash in each report. +- E2E builds never open informational native alerts (profile recovery, refused + settings save, newer data, missing FFmpeg, quit failures), since WebDriver + cannot dismiss them. `src-tauri/src/notices.rs` logs and records them instead; + assert one with the `e2e_native_notices` command. New alerts with only an OK + button go through `notices::show`. See `e2e/native-notices.failure-modes.md`. ## Suites not wired into the gate None. Every suite in `e2e/` is wired, and none was judged obsolete. The audit-round documents remain as failure-mode records. The `audit3-native-targeted` -caption enumeration and identity-race cases are not in `download-process-repairs.spec.js`, +caption enumeration and identity-race cases are not in `download-process.spec.js`, so that suite is not a duplicate. diff --git a/e2e/appimage-zstd.failure-modes.md b/e2e/appimage-zstd.failure-modes.md new file mode 100644 index 00000000..aadb7b9a --- /dev/null +++ b/e2e/appimage-zstd.failure-modes.md @@ -0,0 +1,31 @@ +# AppImage zstd compression: failure modes + +Scope: the Linux AppImage build (`build:linux:*:prepared`) and +`scripts/check-appimage-compression.js`. Plan item C6.1. Tauri builds the +AppImage with linuxdeploy's AppImage plugin, which compresses the SquashFS +payload with gzip unless `LDAI_COMP` names another algorithm. ROSI sets +`LDAI_COMP=zstd`, so the payload is smaller and the updater signature is still +computed by `tauri build` over the final file. + +Status: the macOS host cannot build or run an AppImage. Every row below is +proven only when `release:linux:x64:continue` runs on the Linux release +machine, and the launch check on Ubuntu 24.04 is manual (row 6). + +| # | Failure mode | Required behavior | +| --- | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | The linuxdeploy plugin ignores `LDAI_COMP`, so the AppImage stays gzip and nobody notices | `check-appimage-compression.js` reads the SquashFS superblock after the ELF runtime and fails the release unless the compression id is zstd (6). | +| 2 | The AppImage runtime cannot read a zstd payload, so the app never starts | The check runs the AppImage with `--appimage-extract` into a temporary directory, which uses the runtime's own SquashFS reader, and requires `AppRun` and the `rosi` binary in it. | +| 3 | The updater signature covers a different file than the one published | Compression happens inside `tauri build`, before Tauri signs the AppImage. No step rewrites the AppImage after the build. | +| 4 | The check reads the wrong offset (a runtime with a different ELF layout) and passes or fails by luck | The SquashFS offset is the end of the ELF section header table, and the magic `hsqs` must be at that offset, or the check fails. | +| 5 | The check runs on a stale AppImage from an earlier build | The check takes the AppImage path from the target's bundle directory and requires it to be newer than the release session start. | +| 6 | The AppImage starts on the build machine but not on the documented floor (Ubuntu 24.04) | Manual: launch the built AppImage on Ubuntu 24.04 before publishing, and record it in docs/IMPLEMENTATION-5.1.md with the AppImage SHA-256. | +| 7 | The vendored updater rejects the new AppImage | The updater installs the AppImage file itself (createUpdaterArtifacts: true, no archive). Its structure check, `validate_squashfs_at` in `src-tauri/vendor/tauri-plugin-updater/src/appimage_install.rs`, accepts compression ids 1 to 6, which includes zstd. A Linux update from the previous beta proves it end to end. | + +Proof: + +- `node scripts/check-appimage-compression.js --self-test` builds a synthetic + ELF plus SquashFS header for each compression id and checks rows 1 and 4. It + runs on any OS. +- Release: `node scripts/check-appimage-compression.js --target +x86_64-unknown-linux-gnu` in `release:linux:x64:continue`, after the build + and the glibc check. It writes `e2e/artifacts/appimage-compression-report.json`. diff --git a/e2e/audit-v5-beta2-deep/README.md b/e2e/deep-probes/README.md similarity index 90% rename from e2e/audit-v5-beta2-deep/README.md rename to e2e/deep-probes/README.md index c8ee7378..d9b7d0a0 100644 --- a/e2e/audit-v5-beta2-deep/README.md +++ b/e2e/deep-probes/README.md @@ -1,4 +1,4 @@ -# V5 beta 2 deep audit probes +# V5 beta 2 deep probes These observational E2E probes drive the real unpackaged Tauri app with the bundled yt-dlp and an isolated profile per mode. The failure modes in @@ -10,8 +10,8 @@ a real `ffmpeg` on PATH: ```sh npm run test:e2e # or any command that rebuilds the E2E binary -node e2e/audit-v5-beta2-deep/run.mjs -node e2e/audit-v5-beta2-deep/run.mjs --only close-newer-queue,queue-owner-race +node e2e/deep-probes/run.mjs +node e2e/deep-probes/run.mjs --only close-newer-queue,queue-owner-race ``` Do not run `cargo build`, `cargo test` or `cargo clippy` between the E2E build @@ -31,7 +31,7 @@ feature, and the runner refuses a stale binary. the test CA in `e2e/fixtures`, with a 10-minute keep-alive timeout. It observes for 120 seconds and then cancels the download. -`close-invalid-folder` replaces only `window.api.selectDownloadLocation`, so it +`close-invalid-folder` replaces only `window.__ROSI_E2E__.api.selectDownloadLocation`, so it returns a real folder outside the profile's HOME. That is what the native folder picker returns when a user picks such a folder. Every backend path is unchanged. diff --git a/e2e/audit-v5-beta2-deep/failure-modes.md b/e2e/deep-probes/failure-modes.md similarity index 98% rename from e2e/audit-v5-beta2-deep/failure-modes.md rename to e2e/deep-probes/failure-modes.md index f90366e9..2fc7f825 100644 --- a/e2e/audit-v5-beta2-deep/failure-modes.md +++ b/e2e/deep-probes/failure-modes.md @@ -1,4 +1,4 @@ -# V5 beta 2 deep audit probes: failure modes +# V5 beta 2 deep probes: failure modes Written before any probe code. Each probe drives the real unpackaged E2E build. A probe records observations; `invariantPassed: false` is a reproduced @@ -51,7 +51,7 @@ validation. When the backend rejects that folder (outside home and the allowed volumes), the whole settings snapshot is rejected. Every later save, and the close flush, fails until the user picks another folder. -The probe replaces only `window.api.selectDownloadLocation` so it returns a +The probe replaces only `window.__ROSI_E2E__.api.selectDownloadLocation` so it returns a real folder outside the profile's HOME. This is what the native picker returns when a user chooses such a folder (for example `/Users/Shared` on macOS or `/srv/media` on Linux). The backend path is unchanged. diff --git a/e2e/audit-v5-beta2-deep/deep-audit.spec.js b/e2e/deep-probes/probes.spec.js similarity index 98% rename from e2e/audit-v5-beta2-deep/deep-audit.spec.js rename to e2e/deep-probes/probes.spec.js index 11a0dca8..ac867fc7 100644 --- a/e2e/audit-v5-beta2-deep/deep-audit.spec.js +++ b/e2e/deep-probes/probes.spec.js @@ -101,7 +101,7 @@ async function closeInvalidFolder(observation) { observation.folderBefore = settingsBefore.downloadFolder; // Simulate the native picker returning a folder outside the allowed bases. await browser.execute((folder) => { - window.api.selectDownloadLocation = async () => folder; + window.__ROSI_E2E__.api.selectDownloadLocation = async () => folder; document.getElementById("changeDownloadFolderBtn").click(); }, outside); await sleep(1500); @@ -181,9 +181,9 @@ async function queueOwnerRace(observation) { const manualFirst = round % 2 === 0; const results = await browser.executeAsync( (manual, outputPath, manualFirstOrder, done) => { - const queue = () => window.api.startQueue(); + const queue = () => window.__ROSI_E2E__.api.startQueue(); const download = () => - window.api.downloadVideo({ url: manual, outputPath }); + window.__ROSI_E2E__.api.downloadVideo({ url: manual, outputPath }); const started = manualFirstOrder ? [download(), queue()] : [queue(), download()]; diff --git a/e2e/audit-v5-beta2-deep/run.mjs b/e2e/deep-probes/run.mjs similarity index 96% rename from e2e/audit-v5-beta2-deep/run.mjs rename to e2e/deep-probes/run.mjs index 4b1e05d2..1b024a2d 100644 --- a/e2e/audit-v5-beta2-deep/run.mjs +++ b/e2e/deep-probes/run.mjs @@ -1,6 +1,6 @@ // Runner for the V5 beta 2 deep audit probes. See failure-modes.md (written // first) and README.md. Usage, after a fresh E2E build: -// node e2e/audit-v5-beta2-deep/run.mjs [--only [,...]] +// node e2e/deep-probes/run.mjs [--only [,...]] // Exit zero means every observation completed. Inspect each mode's // `invariantPassed`; false is a reproduced product defect. import crypto from "node:crypto"; @@ -366,7 +366,7 @@ for (const mode of modes) { ...profile.env, ...seeded.env, ROSI_E2E_BINARY: binary, - ROSI_E2E_SPECS: "./audit-v5-beta2-deep/deep-audit.spec.js", + ROSI_E2E_SPECS: "./deep-probes/probes.spec.js", ROSI_DEEP_MODE: mode, ROSI_DEEP_ARTIFACTS: directory, ROSI_DEEP_DOWNLOADS: profile.downloads, @@ -428,14 +428,12 @@ const report = { binarySha256: sha256(fs.readFileSync(binary)), ffmpeg, probeSourceSha256: { - "deep-audit.spec.js": fileHash( - path.join(REPO_ROOT, "e2e/audit-v5-beta2-deep/deep-audit.spec.js"), - ), - "run.mjs": fileHash( - path.join(REPO_ROOT, "e2e/audit-v5-beta2-deep/run.mjs"), + "probes.spec.js": fileHash( + path.join(REPO_ROOT, "e2e/deep-probes/probes.spec.js"), ), + "run.mjs": fileHash(path.join(REPO_ROOT, "e2e/deep-probes/run.mjs")), "failure-modes.md": fileHash( - path.join(REPO_ROOT, "e2e/audit-v5-beta2-deep/failure-modes.md"), + path.join(REPO_ROOT, "e2e/deep-probes/failure-modes.md"), ), }, platform: `${process.platform}-${process.arch}`, diff --git a/e2e/dmg-ulmo.failure-modes.md b/e2e/dmg-ulmo.failure-modes.md new file mode 100644 index 00000000..c94ea9f5 --- /dev/null +++ b/e2e/dmg-ulmo.failure-modes.md @@ -0,0 +1,33 @@ +# DMG compression (ULMO): failure modes + +Scope: `scripts/convert-dmg-ulmo.mjs`, which converts the release DMGs that +Tauri builds as UDZO (zlib) to ULMO (LZMA) before they are verified, GPG +signed, and uploaded. Plan item C6.2. Measured on a universal 5.0.0-beta.1 +DMG: 139.3 MB as UDZO, 114.3 MB as ULMO (ULFO saved under 1 MB). macOS 15, +ROSI's minimum, opens ULMO images (supported since macOS 10.15). + +Required behavior: every published DMG is ULMO, holds exactly the same +`ROSI.app` tree as the image Tauri produced, and is signed, notarized, and +stapled like before. The conversion never changes what is installed. + +| # | Failure mode | Required behavior | +| --- | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | The converted image holds a different `ROSI.app` (a file, mode, or symlink target changed or missing) | Both images are mounted read-only and their full trees (relative path, type, mode, size, SHA-256, symlink target) must be identical, or the step fails. | +| 2 | The conversion leaves the image unreadable or damaged | `hdiutil verify` must pass on the converted image before it replaces the original. | +| 3 | The original is replaced before the new image is proven, so a failure loses the only DMG | The new image is written beside the original under a temporary name and renamed over it only after every check passes. | +| 4 | The converted DMG is published unsigned or without a notarization ticket (Gatekeeper warns on open) | In release mode the image is code-signed with `APPLE_SIGNING_IDENTITY`, submitted with `notarytool --wait`, stapled, and `stapler validate` must pass. | +| 5 | Release mode runs without signing or notarization credentials and silently publishes an unsigned image | Release mode refuses to start when `APPLE_SIGNING_IDENTITY` or the notarization credentials are missing. | +| 6 | The step runs on a stale DMG from an earlier build | Release mode requires each DMG to be newer than the release session start, like `e2e-macos-native-packages.mjs --require-real-builds`. | +| 7 | A DMG that is already ULMO is converted again, or a non-UDZO input is treated as Tauri output | An input already in ULMO is left alone and reported as such; any other format than UDZO or ULMO fails the step. | +| 8 | A mounted image stays attached after a failure | Every attach is detached in a `finally` block, forced if a normal detach fails. | +| 9 | The images grow instead of shrink (a future Tauri or payload change) | The step fails when the ULMO image is not smaller than the input, so a regression is noticed instead of published. | +| 10 | The release chain verifies or signs the DMG before the conversion | `release:mac:continue` runs the conversion right after the DMGs are built and before `test:e2e:macos-native-packages`, GPG signing, and upload. | + +Proof: + +- Local, without credentials: `node scripts/convert-dmg-ulmo.mjs --dmg +--no-notarize --out ` converts a copy, runs rows 1, 2, 3, 7, 8, and 9, + and writes `e2e/artifacts/dmg-ulmo-report.json`. +- Release: `npm run build:mac:dmg:ulmo` inside `release:mac:continue`, followed + by `test:e2e:macos-native-packages -- --require-real-builds`, which already + mounts each DMG, checks the app signature, and validates the staple. diff --git a/e2e/audit3-native-failure-modes.md b/e2e/download-process-targeted-failure-modes.md similarity index 98% rename from e2e/audit3-native-failure-modes.md rename to e2e/download-process-targeted-failure-modes.md index 92dfe67c..09d7d142 100644 --- a/e2e/audit3-native-failure-modes.md +++ b/e2e/download-process-targeted-failure-modes.md @@ -1,4 +1,4 @@ -# Audit 3 native repair failure modes +# Download process targeted failure modes Findings 1–5 were recorded before the original repair harness and native production edits. Follow-up findings 6–14 were recorded before their matching @@ -108,7 +108,7 @@ and its invariant. verify the published original remains in `failedPaths` and also appears in `outputPaths` with accurate bytes and its actual format. -Gate wiring: `scripts/test-e2e.js` runs `audit3-native-targeted.spec.js` through +Gate wiring: `scripts/test-e2e.js` runs `download-process-targeted.spec.js` through the isolated process-repair wrapper (`ROSI_REPAIRS_SPEC`) as the `audit3-native-targeted` scenario. Its result is verified by the same report identity checks as `download-process-repairs`. diff --git a/e2e/audit3-native-targeted.spec.js b/e2e/download-process-targeted.spec.js similarity index 99% rename from e2e/audit3-native-targeted.spec.js rename to e2e/download-process-targeted.spec.js index cb18277a..3dadafc9 100644 --- a/e2e/audit3-native-targeted.spec.js +++ b/e2e/download-process-targeted.spec.js @@ -738,7 +738,7 @@ describe("ROSI audit 3 native targeted repairs", () => { assert.equal(savedA.ok, true, JSON.stringify(savedA)); await browser.execute(() => { window.audit3GpuProbeA = { settled: false, result: null }; - window.api.detectGpu().then( + window.__ROSI_E2E__.api.detectGpu().then( (result) => { window.audit3GpuProbeA = { settled: true, result }; }, diff --git a/e2e/download-process-repairs.README.md b/e2e/download-process.README.md similarity index 91% rename from e2e/download-process-repairs.README.md rename to e2e/download-process.README.md index e94790c5..7a42ed04 100644 --- a/e2e/download-process-repairs.README.md +++ b/e2e/download-process.README.md @@ -1,6 +1,6 @@ -# Downloader and process repair E2E +# Downloader and process E2E -The failure inventory is in `download-process-repairs.failures.md`. The probe +The failure inventory is in `download-process.failures.md`. The probe drives the real unpackaged Tauri application and bundled yt-dlp with deterministic local media, real FFmpeg, an isolated Firefox cookie database, and test-owned FFmpeg behaviors for tree escalation, bounded output, GPU failure fallback, and @@ -11,7 +11,7 @@ Build a fresh E2E binary with the repository's `npm run test:e2e` gate, then run the focused probe without rebuilding it: ```sh -node e2e/run-download-process-repairs.mjs +node e2e/run-download-process.mjs ``` The probe currently requires macOS or Linux, Python 3, a real FFmpeg, and the diff --git a/e2e/download-process-repairs.failures.md b/e2e/download-process.failures.md similarity index 99% rename from e2e/download-process-repairs.failures.md rename to e2e/download-process.failures.md index dc827e2a..95c71cd5 100644 --- a/e2e/download-process-repairs.failures.md +++ b/e2e/download-process.failures.md @@ -1,4 +1,4 @@ -# Downloader and process repair failure inventory +# Downloader and process failure inventory The original cases were written before the repair probe and production edits. Follow-up cases below were recorded before the corresponding integration fixes. @@ -97,7 +97,7 @@ partial playlist failure, cancellation between playlist entries, and the stale-event injection described above. Each timing and output-path invariant is saved in the hashed repair report. -The existing `e2e/audit-v5-beta2` probes establish the native baseline for +The existing `e2e/platform-probes` probes establish the native baseline for conversion collision, concurrent starts, playlist conversion, VP8 conversion, metadata requests, and process-tree escalation. The new probe adds explicit repair assertions and records a repeatable JSON artifact. Browser-profile diff --git a/e2e/download-process-repairs.spec.js b/e2e/download-process.spec.js similarity index 99% rename from e2e/download-process-repairs.spec.js rename to e2e/download-process.spec.js index 690ea4f9..e5d0c8e8 100644 --- a/e2e/download-process-repairs.spec.js +++ b/e2e/download-process.spec.js @@ -259,7 +259,7 @@ async function metadataCancellation(method, marker) { window.repairMetadataResults = []; for (let index = 0; index < 10; index += 1) { const url = `${baseUrl}/slow.html?${queryMarker}=1&n=${index}`; - window.api[methodName](url).then( + window.__ROSI_E2E__.api[methodName](url).then( (result) => window.repairMetadataResults.push({ ok: result?.ok ?? null, @@ -760,12 +760,12 @@ describe("ROSI downloader and process repairs", () => { const starts = await browser.executeAsync( (url, output, done) => { Promise.all([ - window.api.downloadVideo({ + window.__ROSI_E2E__.api.downloadVideo({ url, outputPath: output, convertEnabled: false, }), - window.api.startQueue(), + window.__ROSI_E2E__.api.startQueue(), ]).then( (results) => done(JSON.stringify(results)), (error) => done(JSON.stringify({ error: String(error) })), @@ -800,7 +800,7 @@ describe("ROSI downloader and process repairs", () => { (baseUrl, output, done) => { Promise.all( Array.from({ length: 10 }, (_, index) => - window.api.downloadVideo({ + window.__ROSI_E2E__.api.downloadVideo({ url: `${baseUrl}/slow.mp4?repair-manual-fanout=1&n=${index}`, outputPath: output, convertEnabled: false, @@ -838,8 +838,8 @@ describe("ROSI downloader and process repairs", () => { try { await browser.execute((baseUrl) => { window.repairStartedSessions = []; - const original = window.api.downloadVideo; - window.api.downloadVideo = async (...args) => { + const original = window.__ROSI_E2E__.api.downloadVideo; + window.__ROSI_E2E__.api.downloadVideo = async (...args) => { const result = await original(...args); if (result?.ok === true && result.data?.sessionId) { window.repairStartedSessions.push(result.data.sessionId); @@ -963,7 +963,7 @@ describe("ROSI downloader and process repairs", () => { : []; await browser.execute((target) => { window.repairDelayedFormats = { settled: false, response: null }; - window.api.getFormats(target).then( + window.__ROSI_E2E__.api.getFormats(target).then( (response) => { window.repairDelayedFormats = { settled: true, response }; }, @@ -1768,7 +1768,7 @@ describe("ROSI downloader and process repairs", () => { assert.equal(savedA.ok, true, JSON.stringify(savedA)); await browser.execute(() => { window.audit3GpuProbeA = { settled: false, result: null }; - window.api.detectGpu().then( + window.__ROSI_E2E__.api.detectGpu().then( (result) => { window.audit3GpuProbeA = { settled: true, result }; }, diff --git a/e2e/audit4-repair-failure-modes.md b/e2e/download-session-failure-modes.md similarity index 96% rename from e2e/audit4-repair-failure-modes.md rename to e2e/download-session-failure-modes.md index eea5b7a8..38bbec23 100644 --- a/e2e/audit4-repair-failure-modes.md +++ b/e2e/download-session-failure-modes.md @@ -1,4 +1,4 @@ -# Audit 4 repair failure inventory +# Download session failure inventory Write verification before production repairs. Preserve unrelated behavior and retain repeatable JSON/TAP artifacts. @@ -14,7 +14,7 @@ Write verification before production repairs. Preserve unrelated behavior and re Native GUI E2E is preferred. Controlled renderer/native isolation is supplemental when native execution is unavailable; it does not certify signed installers or hosted CI. -Gate wiring: `audit4-repairs-run.mjs` writes `result.json` under +Gate wiring: `download-session-run.mjs` writes `result.json` under `e2e/artifacts/audit4-repairs/`. `scripts/test-e2e.js` runs it as the `audit4-repairs` scenario and checks the exit code, the binary hash, the spec hash, and the native observations file. diff --git a/e2e/audit4-repairs-run.mjs b/e2e/download-session-run.mjs similarity index 97% rename from e2e/audit4-repairs-run.mjs rename to e2e/download-session-run.mjs index f4bfdf66..60e1f3e4 100644 --- a/e2e/audit4-repairs-run.mjs +++ b/e2e/download-session-run.mjs @@ -103,12 +103,12 @@ await new Promise((resolve, reject) => { server.once("error", reject); server.listen(0, "127.0.0.1", resolve); }); -const specPath = path.join(REPO_ROOT, "e2e", "audit4-repairs.spec.js"); +const specPath = path.join(REPO_ROOT, "e2e", "download-session.spec.js"); const env = { ...process.env, ...profile.env, ROSI_E2E_BINARY: binary, - ROSI_E2E_SPECS: "./audit4-repairs.spec.js", + ROSI_E2E_SPECS: "./download-session.spec.js", ROSI_AUDIT4_ARTIFACTS: directory, ROSI_AUDIT4_FFPROBE: ffprobe, ROSI_AUDIT4_MEDIA: "http://127.0.0.1:" + server.address().port, diff --git a/e2e/audit4-repairs.spec.js b/e2e/download-session.spec.js similarity index 100% rename from e2e/audit4-repairs.spec.js rename to e2e/download-session.spec.js diff --git a/e2e/helpers/app-bridge.js b/e2e/helpers/app-bridge.js index 614ac126..7de3136a 100644 --- a/e2e/helpers/app-bridge.js +++ b/e2e/helpers/app-bridge.js @@ -1,6 +1,6 @@ import { browser } from "@wdio/globals"; -/** Call a `window.api` method in the app and return its resolved value. */ +/** Call a `window.__ROSI_E2E__.api` method in the app and return its resolved value. */ export async function api(method, ...args) { // The WebDriver bridge fails on script results containing non-ASCII text, // so the page returns ASCII-escaped JSON and Node parses it. @@ -12,7 +12,7 @@ export async function api(method, ...args) { (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`, ); Promise.resolve() - .then(() => window.api[name](...params)) + .then(() => window.__ROSI_E2E__.api[name](...params)) .then( (value) => done(ascii({ ok: true, value: value ?? null })), (error) => @@ -29,7 +29,9 @@ export async function api(method, ...args) { ); const outcome = JSON.parse(encoded); if (!outcome.ok) - throw new Error(`window.api.${method} failed: ${outcome.error}`); + throw new Error( + `window.__ROSI_E2E__.api.${method} failed: ${outcome.error}`, + ); return outcome.value; } @@ -40,9 +42,12 @@ export async function waitForAppReady() { browser.execute( () => Boolean(window.__ROSI_E2E__?.ready) && - Boolean(window.api) && + Boolean(window.__ROSI_E2E__?.api) && Boolean(document.getElementById("url")), ), - { timeout: 60_000, timeoutMsg: "E2E hook / window.api not installed" }, + { + timeout: 60_000, + timeoutMsg: "E2E hook / window.__ROSI_E2E__.api not installed", + }, ); } diff --git a/e2e/helpers/updater-engine-fixture.js b/e2e/helpers/updater-engine-fixture.js new file mode 100644 index 00000000..c5df03ed --- /dev/null +++ b/e2e/helpers/updater-engine-fixture.js @@ -0,0 +1,93 @@ +// Starts a local signed update server and points the Rust updater at it. +// Used by the updater scenarios; the key is generated into the scenario's own +// temporary directory, so nothing signed is committed. +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { browser } from "@wdio/globals"; +import { startUpdaterServer } from "./updater-server.js"; +import { generateUpdaterSigningKey } from "./updater-signing.js"; + +/** + * Configures the engine. Overrides mirror the E2E binary's platform answers: + * it is never packaged, has no bundle type, and runs under no Flatpak. + */ +export async function startUpdaterFixture({ + isPackaged = true, + isFlatpak = false, + betaTarget = "darwin-beta-aarch64-app", + compactTarget = null, + disableCompact = true, + restartRefusals = 0, + checkTimeoutMs, + downloadTimeoutMs, + installConfirmHoldMs, + installWriteHoldMs, +} = {}) { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rosi-updater-e2e-")); + const key = generateUpdaterSigningKey(dir); + const server = await startUpdaterServer({ key }); + const config = { + endpoint: server.endpoint, + pubkey: key.pubkey, + isPackaged, + isFlatpak, + betaTarget, + compactTarget, + disableCompact, + installProbe: true, + restartRefusals, + checkTimeoutMs, + downloadTimeoutMs, + installConfirmHoldMs, + installWriteHoldMs, + }; + const outcome = await browser.executeAsync((payload, done) => { + window.__TAURI__.core + .invoke("e2e_configure_updater", { config: payload }) + .then( + () => done({ ok: true }), + (error) => done({ error: String(error) }), + ); + }, config); + if (!outcome?.ok) { + await server.close(); + throw new Error(`e2e_configure_updater failed: ${JSON.stringify(outcome)}`); + } + return { + server, + key, + dir, + async close() { + await server.close(); + fs.rmSync(dir, { recursive: true, force: true }); + }, + }; +} + +/** Sets the persisted update channel through the engine's command. */ +export async function setUpdateChannel(channel) { + await browser.executeAsync((next, done) => { + window.__TAURI__.core.invoke("set_update_channel", { channel: next }).then( + () => done({ ok: true }), + (error) => done({ error: String(error) }), + ); + }, channel); +} + +/** Starts a manual check the way the Check for updates button does. */ +export async function clickManualCheck() { + await browser.execute(() => + document.getElementById("checkUpdateBtn")?.click(), + ); +} + +/** Captures updater-status events in the page, in arrival order. */ +export async function captureUpdaterStatuses(storeName) { + await browser.execute((name) => { + window[name] = []; + window.__TAURI__.event.listen("updater-status", (event) => + window[name].push(event.payload), + ); + }, storeName); +} diff --git a/e2e/helpers/updater-server.js b/e2e/helpers/updater-server.js new file mode 100644 index 00000000..ad6ccbe2 --- /dev/null +++ b/e2e/helpers/updater-server.js @@ -0,0 +1,185 @@ +// Local update server for the updater E2E. It serves static-format manifests +// (`latest-{target}.json`) and signed payloads, signed with a key the scenario +// generated at test time. Routes are set per scenario, and every request is +// logged so specs can assert which feed records the engine asked for. +import http from "node:http"; +import { manifestSignature, signUpdateArtifact } from "./updater-signing.js"; + +/** Writes the body in slices with a pause between them, for progress tests. */ +function dripBody(response, route) { + const { chunkBytes, intervalMs } = route.drip; + response.writeHead(route.status ?? 200, { + "Content-Type": route.contentType, + "Content-Length": Buffer.byteLength(route.body), + }); + let offset = 0; + let timer = null; + response.on("close", () => clearTimeout(timer)); + const next = () => { + if (response.destroyed) return; + if (offset >= route.body.length) { + response.end(); + return; + } + response.write(route.body.subarray(offset, offset + chunkBytes)); + offset += chunkBytes; + timer = setTimeout(next, intervalMs); + }; + next(); +} + +/** + * Starts the server on 127.0.0.1 with an ephemeral port. + * `key` comes from generateUpdaterSigningKey(). + */ +export async function startUpdaterServer({ key }) { + const routes = new Map(); + const queues = new Map(); + const requests = []; + const server = http.createServer((request, response) => { + const pathname = new URL(request.url, "http://127.0.0.1").pathname; + requests.push({ path: pathname, at: Date.now() }); + const queued = queues.get(pathname); + const route = queued?.length ? queued.shift() : routes.get(pathname); + if (!route) { + response.writeHead(404, { "Content-Type": "text/plain" }); + response.end("not found"); + return; + } + const send = () => { + if (response.destroyed || response.writableEnded) return; + if (route.drip) { + dripBody(response, route); + return; + } + if (route.truncate) { + // Promise the whole body, deliver half, then drop the connection. + response.writeHead(200, { + "Content-Type": route.contentType, + "Content-Length": Buffer.byteLength(route.body) * 2, + }); + response.write( + route.body.subarray(0, Math.floor(route.body.length / 2)), + ); + setTimeout(() => response.destroy(), 50); + return; + } + response.writeHead(route.status ?? 200, { + "Content-Type": route.contentType, + "Content-Length": Buffer.byteLength(route.body), + }); + response.end(route.body); + }; + if (route.gate) { + // The response is held until the scenario releases it. + route.gate.then(send); + } else { + send(); + } + }); + await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); + const base = `http://127.0.0.1:${server.address().port}`; + + /** + * Serves a signed manifest that points at `payload`. `target` is the platform + * key inside the manifest; `route` is the name in `latest-{route}.json` + * (defaults to `target`). With no explicit target the engine requests the + * OS name only, e.g. `latest-darwin.json`, and then looks up `{os}-{arch}`. + * `gate` holds the artifact response and `manifestGate` holds the manifest + * response until the scenario resolves the promise. + */ + function publish({ + target, + route = target, + version, + payload, + fileName, + gate = null, + manifestGate = null, + drip = null, + }) { + const artifactPath = `/artifacts/${fileName}`; + routes.set(artifactPath, { + contentType: "application/octet-stream", + body: payload, + gate, + drip, + }); + const signature = manifestSignature( + signUpdateArtifact(key, payload, { fileName, version }), + ); + const manifest = { + version, + notes: `Controlled ${version}`, + pub_date: new Date().toISOString(), + platforms: { + [target]: { url: `${base}${artifactPath}`, signature }, + }, + }; + routes.set(`/latest-${route}.json`, { + contentType: "application/json", + body: JSON.stringify(manifest), + gate: manifestGate, + }); + return manifest; + } + + /** + * Answers the target's manifest with a status code (404 for a missing feed). + * `gate` holds the response until the scenario resolves it. + */ + function respond(target, status, body = "", { gate = null } = {}) { + routes.set(`/latest-${target}.json`, { + status, + contentType: "text/plain", + body, + gate, + }); + } + + /** + * Answers the next requests for the target from `steps` (each a status and + * optional body), then falls back to the published route. + */ + function queueFeed(target, steps) { + queues.set( + `/latest-${target}.json`, + steps.map((step) => ({ + contentType: "text/plain", + body: "", + ...step, + })), + ); + } + + /** Serves `bytes` for an artifact that was signed as something else. */ + function tamper(fileName, bytes) { + const artifact = routes.get(`/artifacts/${fileName}`); + routes.set(`/artifacts/${fileName}`, { ...artifact, body: bytes }); + } + + /** Makes the artifact drop after half its body. */ + function truncate(fileName) { + const artifact = routes.get(`/artifacts/${fileName}`); + routes.set(`/artifacts/${fileName}`, { ...artifact, truncate: true }); + } + + /** Removes a route so the feed answers 404 again. */ + function unpublish(target) { + routes.delete(`/latest-${target}.json`); + } + + return { + base, + /** The endpoint template handed to e2e_configure_updater. */ + endpoint: `${base}/latest-{{target}}.json`, + requests, + publish, + respond, + queueFeed, + unpublish, + tamper, + truncate, + close: () => new Promise((resolve) => server.close(() => resolve())), + }; +} diff --git a/e2e/helpers/updater-signing.js b/e2e/helpers/updater-signing.js new file mode 100644 index 00000000..673bb356 --- /dev/null +++ b/e2e/helpers/updater-signing.js @@ -0,0 +1,68 @@ +// Test-only minisign signer for the updater E2E. The key is generated at test +// time into the scenario's own directory; no private key is committed. Output +// matches what the vendored tauri-plugin-updater verifies: a prehashed ("ED") +// signature over blake2b-512(data), and a global signature over the signature +// bytes plus the trusted comment, with `version:` in the trusted comment. +import crypto from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; + +const ED25519_SPKI_PREFIX_BYTES = 12; + +function rawPublicKey(publicKey) { + const der = publicKey.export({ format: "der", type: "spki" }); + return Buffer.from(der.subarray(ED25519_SPKI_PREFIX_BYTES)); +} + +/** + * Generates a minisign key pair. Writes the secret key and public key files + * into `directory` (the caller's temp profile) and returns the pubkey value + * that `e2e_configure_updater` expects: base64 of the whole `.pub` file. + */ +export function generateUpdaterSigningKey(directory) { + fs.mkdirSync(directory, { recursive: true }); + const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519"); + const keyId = crypto.randomBytes(8); + const publicText = [ + "untrusted comment: minisign public key (ROSI E2E)", + Buffer.concat([Buffer.from("Ed"), keyId, rawPublicKey(publicKey)]).toString( + "base64", + ), + "", + ].join("\n"); + const pubPath = path.join(directory, "updater-e2e.pub"); + fs.writeFileSync(pubPath, publicText, { mode: 0o600 }); + return { + privateKey, + keyId, + publicKeyFile: pubPath, + pubkey: Buffer.from(publicText, "utf8").toString("base64"), + }; +} + +/** + * Signs `data` and returns the `.sig` file text. `version` goes into the + * trusted comment, which requireSignedVersion checks against the manifest. + */ +export function signUpdateArtifact(key, data, { fileName, version }) { + const digest = crypto.createHash("blake2b512").update(data).digest(); + const signature = crypto.sign(null, digest, key.privateKey); + const trustedComment = `timestamp:${Math.floor(Date.now() / 1000)}\tfile:${fileName}\tversion:${version}`; + const globalSignature = crypto.sign( + null, + Buffer.concat([signature, Buffer.from(trustedComment, "utf8")]), + key.privateKey, + ); + return [ + "untrusted comment: signature from minisign secret key", + Buffer.concat([Buffer.from("ED"), key.keyId, signature]).toString("base64"), + `trusted comment: ${trustedComment}`, + globalSignature.toString("base64"), + "", + ].join("\n"); +} + +/** The manifest `signature` field: base64 of the `.sig` file text. */ +export function manifestSignature(sigText) { + return Buffer.from(sigText, "utf8").toString("base64"); +} diff --git a/e2e/long-term-v5-audit-run.mjs b/e2e/long-term-persistence-run.mjs similarity index 96% rename from e2e/long-term-v5-audit-run.mjs rename to e2e/long-term-persistence-run.mjs index 04c64fc8..bb6b1cdf 100644 --- a/e2e/long-term-v5-audit-run.mjs +++ b/e2e/long-term-persistence-run.mjs @@ -13,7 +13,7 @@ import { const artifactRoot = path.resolve( REPO_ROOT, process.env.ROSI_LONG_TERM_ARTIFACT_ROOT || - `e2e/artifacts/long-term-v5-repairs/${new Date().toISOString().replaceAll(":", "-")}-${process.pid}`, + `e2e/artifacts/long-term-persistence/${new Date().toISOString().replaceAll(":", "-")}-${process.pid}`, ); const binary = e2eBinaryPath(); const stamp = e2eStampPath(); @@ -33,18 +33,18 @@ const ownedRoot = path.join( REPO_ROOT, "e2e", "artifacts", - "long-term-v5-repairs", + "long-term-persistence", ); if (!artifactRoot.startsWith(`${ownedRoot}${path.sep}`)) { throw new Error( - "Repair artifacts must use a new child directory under e2e/artifacts/long-term-v5-repairs.", + "Repair artifacts must use a new child directory under e2e/artifacts/long-term-persistence.", ); } fs.mkdirSync(path.dirname(artifactRoot), { recursive: true }); fs.mkdirSync(artifactRoot); const sourceFiles = [ - "e2e/long-term-v5-audit-run.mjs", - "e2e/long-term-v5-audit.spec.js", + "e2e/long-term-persistence-run.mjs", + "e2e/long-term-persistence.spec.js", "e2e/long-term-v5-failure-modes.md", "src-tauri/src/settings.rs", "src-tauri/src/legacy.rs", @@ -103,7 +103,7 @@ function run(mode, profile, expectedQueueCount) { ...process.env, ...profile.env, ROSI_E2E_BINARY: binary, - ROSI_E2E_SPECS: "./long-term-v5-audit.spec.js", + ROSI_E2E_SPECS: "./long-term-persistence.spec.js", ROSI_LONG_TERM_MODE: mode, ROSI_LONG_TERM_EXPECTED_QUEUE_COUNT: String(expectedQueueCount ?? ""), ROSI_LONG_TERM_ARTIFACTS: directory, diff --git a/e2e/long-term-v5-audit.README.md b/e2e/long-term-persistence.README.md similarity index 80% rename from e2e/long-term-v5-audit.README.md rename to e2e/long-term-persistence.README.md index 0c798c18..8292a792 100644 --- a/e2e/long-term-v5-audit.README.md +++ b/e2e/long-term-persistence.README.md @@ -1,4 +1,4 @@ -# Long-term ROSI V5 audit and repair probes +# Long-term ROSI V5 persistence probes These probes run the real unpackaged Tauri application through WebDriver using generated profiles. The failure inventory predates implementation; repair acceptance extensions precede the relevant production edits. No unit tests are added. @@ -12,21 +12,21 @@ The canonical E2E gate requires the `long-term-persistence` aggregate. To rerun ```sh node --input-type=module -e "import { buildE2eBinary } from './scripts/test-e2e.js'; buildE2eBinary();" -node e2e/long-term-v5-audit-run.mjs +node e2e/long-term-persistence-run.mjs ``` Do not run Cargo commands between building the E2E application and running the standalone probes: another Cargo command can replace the binary. Do not run another GUI suite concurrently. The standalone runner currently targets the available macOS environment; Windows/Linux execution and timeout cleanup require validation before claiming release acceptance there. The runner covers normal settings, failed and successful statistics reset, unreadable settings, a future schema, damaged settings, a blocked migration journal, a temporarily blocked V4 queue import, old-marker compatibility, temporary legacy settings corruption during retry, repaired destination restart, oversized queue rejection with an existing item followed by restart, and 500 short URLs followed by restart. Generated URLs use `audit.invalid`; the queue probes never start downloads or contact that host. All mutations affect generated test profiles. -Each run creates a fresh directory beneath `e2e/artifacts/long-term-v5-repairs/` and prints its report path. Existing directories cannot be reused or overwritten. Each case retains before/after state, native logs and an observation. Source snapshots and `working-tree.patch` identify uncommitted changes. The report binds the Git base, binary hash, copied sources, retained files and acceptance outcomes. Evidence is kept locally under `e2e/artifacts/`, which is gitignored. `.github/workflows/ci.yml` uploads that directory after `npm run test:all` as the `e2e-*` CI artifact (30-day retention). The original audit evidence in `e2e/artifacts/long-term-v5-audit-2026-10-07/` is local only and is not in the repository. +Each run creates a fresh directory beneath `e2e/artifacts/long-term-persistence/` and prints its report path. Existing directories cannot be reused or overwritten. Each case retains before/after state, native logs and an observation. Source snapshots and `working-tree.patch` identify uncommitted changes. The report binds the Git base, binary hash, copied sources, retained files and acceptance outcomes. Evidence is kept locally under `e2e/artifacts/`, which is gitignored. `.github/workflows/ci.yml` uploads that directory after `npm run test:all` as the `e2e-*` CI artifact (30-day retention). The original audit evidence in `e2e/artifacts/long-term-v5-audit-2026-10-07/` is local only and is not in the repository. Exit zero requires all fifteen observations to pass. Exit one with `runnerExitCode: 0` and `invariantPassed: false` means a case completed but failed acceptance. Missing observations or nonzero native runner exits are execution failures. The initial repair trial's short-URL false result was a harness assertion error; see the repair report for final results. Verify a selected run, substituting its actual directory: ```sh -ROSI_REPAIR_REPORT=e2e/artifacts/long-term-v5-repairs//report.json node --input-type=module <<'JS' +ROSI_REPAIR_REPORT=e2e/artifacts/long-term-persistence//report.json node --input-type=module <<'JS' import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; diff --git a/e2e/long-term-v5-audit.spec.js b/e2e/long-term-persistence.spec.js similarity index 97% rename from e2e/long-term-v5-audit.spec.js rename to e2e/long-term-persistence.spec.js index 23e76e4a..a1cf9651 100644 --- a/e2e/long-term-v5-audit.spec.js +++ b/e2e/long-term-persistence.spec.js @@ -133,14 +133,14 @@ describe("long-term V5 observational audit", () => { (_, index) => `https://audit.invalid/video.mp4?item=${index}&padding=${"x".repeat(35000)}`, ); - window.api.addToQueue(urls).then( + window.__ROSI_E2E__.api.addToQueue(urls).then( (value) => done(JSON.stringify(value)), (error) => done(JSON.stringify({ error: String(error) })), ); }), ); observation.queueCount = await browser.executeAsync((done) => { - window.api.getQueue().then((queue) => done(queue.length)); + window.__ROSI_E2E__.api.getQueue().then((queue) => done(queue.length)); }); await browser.waitUntil( () => @@ -211,7 +211,7 @@ describe("long-term V5 observational audit", () => { observation.toast.includes("Could not reset statistics"); } else if (mode === "queue-reload") { observation.queueCount = await browser.executeAsync((done) => { - window.api.getQueue().then((queue) => done(queue.length)); + window.__ROSI_E2E__.api.getQueue().then((queue) => done(queue.length)); }); observation.invariantPassed = observation.queueCount === diff --git a/e2e/macos-native-packages.failure-modes.md b/e2e/macos-native-packages.failure-modes.md new file mode 100644 index 00000000..19709175 --- /dev/null +++ b/e2e/macos-native-packages.failure-modes.md @@ -0,0 +1,36 @@ +# macOS native package failure modes + +This inventory was written before implementation. `scripts/e2e-macos-native-packages.mjs` +will exercise the packaging and release-asset rules with isolated fixtures and +write repeatable JSON evidence. macOS signing, notarization, DMG mounting, and +native Mach-O inspection remain platform acceptance checks for a macOS release +machine. + +| ID | Failure mode | Required result | +| ----- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| MNP01 | An arm64 package is built from a universal or x86_64 app, or vice versa. | Reject the bundle because the ROSI host executable and native FFmpeg/ffprobe sidecars do not contain exactly the requested architecture. | +| MNP02 | A valid native bundle contains upstream universal2 yt-dlp. | Accept it when it includes the requested architecture; do not require yt-dlp to be thin. | +| MNP03 | Any app or sidecar requires a macOS version above the configured minimum. | Reject the package and identify the offending executable and slice. | +| MNP04 | The app or sidecar is ad-hoc signed, signed by another team, has mismatched entitlements, or is not notarized/stapled. | Reject before writing the ZIP; preserve Developer ID, team, entitlement, and staple checks for the requested slice. Fixture evidence checks these gates remain wired; signed acceptance requires macOS. | +| MNP05 | The plist marketing version or bundle version does not match the release config. | Reject the package. | +| MNP06 | The native DMG/ZIP receives a generic or colliding filename. | Emit the unique `ROSI-MacOS-arm64`, `ROSI-MacOS-x64`, or `ROSI-MacOS-universal` basename and keep each architecture distinct through collection, sidecars, and checksums. | +| MNP07 | A stale or duplicate architecture package is present alongside the new one. | Require current-session outputs, preserve architecture names, and fail on ambiguous same-name DMGs/ZIPs instead of silently choosing one. | +| MNP08 | A ZIP is missing, empty, or misnamed after packaging. | Fail E2E/release verification; require both native DMGs and ZIPs in the draft. | +| MNP09 | GPG signing sees native package names. | Sign each DMG and ZIP once; do not normalize native names back to universal or collide with the universal signatures. | +| MNP10 | SHA256SUMS files omit a native package, duplicate it, or use an architecture-inaccurate target key. | Generate deterministic checksum target lists covering each package and verify the uploaded checksum/signature assets against those names. | +| MNP11 | An updater manifest resolves a compact archive to the wrong architecture, or a native installer is mistaken for an updater archive. | Keep legacy universal app feeds intact; preserve per-architecture zstd feeds and validate the updater archive against the host architecture. | +| MNP12 | The macOS release rebuilds the same native app separately for installer and compact updater packaging. | Build each per-architecture app once with its DMG and updater archive, then feed that app/archive to both packagers. | +| MNP13 | A build or release command runs on Windows and pretends native macOS acceptance succeeded. | The fixture E2E reports static pipeline evidence only and clearly records native platform checks as blocked. | +| MNP14 | The updater's universal fallback, Rosetta native-arm64 selection, or missing-architecture fallback changes while adding native downloads. | Retain existing updater routing behavior and the universal release/update artifacts. | +| MNP15 | `--require-real-builds` runs off macOS or any of the six current package files is missing. | Fail the command; fixture helpers must never satisfy a real release gate. | +| MNP16 | A native DMG or ZIP is as large as or larger than its universal counterpart, or a payload hash cannot be recorded. | Fail for that package and report file size plus SHA-256 for every package and source bundle. | +| MNP17 | A ZIP is truncated, changes the app tree, loses its Developer ID signature, or loses its staple. | Extract it with macOS `ditto`, compare the complete bundle tree and executable hashes to the source app, then validate code signature and notarization staple. | +| MNP18 | A DMG cannot mount, contains no single `ROSI.app`, has the wrong target architecture, or fails signature/staple validation. | Attach read-only, require exactly one app, reuse target-aware bundle verification, and detach every mounted image in `finally`, including on failure. | +| MNP19 | A package or source bundle predates the current release build, or its version differs from `package.json`/`tauri.conf.json`. | Fail real acceptance rather than using stale or mismatched local artifacts. | +| MNP20 | A mounted volume remains after verification fails. | Detach every image attached by this E2E run in `finally` and report cleanup failures without hiding the original verification error. | + +Fixture mode is cross-platform pipeline evidence and does not prove that a +package was built, signed, stapled, mounted, or smaller. `--require-real-builds` +must run after the three real builds on macOS, verify every package and mounted +DMG, and write actual hashes, sizes, and native acceptance results. The release +chain uses this strict mode. diff --git a/e2e/round2-native-failure-modes.md b/e2e/native-downloads-failure-modes.md similarity index 99% rename from e2e/round2-native-failure-modes.md rename to e2e/native-downloads-failure-modes.md index 8341d536..d3de5bda 100644 --- a/e2e/round2-native-failure-modes.md +++ b/e2e/native-downloads-failure-modes.md @@ -1,4 +1,4 @@ -# Round 2 native repair failure inventory +# Native downloads failure inventory These scenarios were enumerated before the native production edits. The corresponding E2E probe must launch the real ROSI E2E binary with an isolated diff --git a/e2e/round2-native-run.mjs b/e2e/native-downloads-run.mjs similarity index 98% rename from e2e/round2-native-run.mjs rename to e2e/native-downloads-run.mjs index 3cf7a458..66ca0d07 100644 --- a/e2e/round2-native-run.mjs +++ b/e2e/native-downloads-run.mjs @@ -196,7 +196,7 @@ const wdio = spawnSync(npx, ["wdio", "run", "e2e/wdio.conf.js"], { ...process.env, ...profile.env, ROSI_E2E_BINARY: binary, - ROSI_E2E_SPECS: "./round2-native.spec.js", + ROSI_E2E_SPECS: "./native-downloads.spec.js", ROSI_E2E_DOWNLOADS: profile.downloads, ROSI_E2E_DATA_DIR: profile.dataDir, ROSI_ROUND2_NATIVE_ARTIFACTS: artifactDirectory, @@ -237,12 +237,13 @@ const reportBody = { ffmpegExecutablePath: realFfmpegPath, ffmpegExecutableSha256: sha256(fs.readFileSync(realFfmpegPath)), probeSources: Object.fromEntries( - ["e2e/round2-native.spec.js", "e2e/round2-native-failure-modes.md"].map( - (relativePath) => [ - relativePath, - sha256(fs.readFileSync(path.join(REPO_ROOT, relativePath))), - ], - ), + [ + "e2e/native-downloads.spec.js", + "e2e/native-downloads-failure-modes.md", + ].map((relativePath) => [ + relativePath, + sha256(fs.readFileSync(path.join(REPO_ROOT, relativePath))), + ]), ), isolatedProfile: profile.profileDir, toneFixtureSha256: sha256(fs.readFileSync(tone)), diff --git a/e2e/round2-native.spec.js b/e2e/native-downloads.spec.js similarity index 100% rename from e2e/round2-native.spec.js rename to e2e/native-downloads.spec.js diff --git a/e2e/native-notices.failure-modes.md b/e2e/native-notices.failure-modes.md new file mode 100644 index 00000000..7b78a36b --- /dev/null +++ b/e2e/native-notices.failure-modes.md @@ -0,0 +1,29 @@ +# Native notices in E2E builds: failure modes + +Scope: the informational native alerts the backend raises (title, message, one +OK button), routed through `src-tauri/src/notices.rs`. WebDriver drives only the +webview, so it cannot see or dismiss a native alert. Fault scenarios (a corrupt +or newer `settings.json`, a refused save, a missing FFmpeg) raised one alert per +launch, and on macOS these piled up over the developer's screen during every +local run. + +Required behavior: production builds show every notice exactly as before. E2E +builds (`--features e2e`) never open the alert; they log it and record it in a +bounded in-memory list that `e2e_native_notices` returns, so a scenario can assert +the notice instead of a person dismissing it. + +| # | Failure mode | Required behavior | +| --- | --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | The suppression leaks into a production build | The E2E branch is compiled only with `feature = "e2e"`. The release build has no `e2e_native_notices` command and always shows the alert. | +| 2 | A suppressed notice disappears without a trace, so a regression that stops raising it passes | Every suppressed notice is logged (`logs/rosi.log`) and recorded; a scenario asserts the recorded title and message. | +| 3 | A notice with a callback (for example the missing yt-dlp alert that exits the app) is skipped | Only notices without a callback go through `notices.rs`. Alerts whose dismissal does something keep their own dialog code. | +| 4 | Confirmation dialogs (close with a running download, close without saving) are suppressed | Out of scope: they choose between actions and stay native. E2E scenarios already avoid them. | +| 5 | File and folder pickers are suppressed | Out of scope: pickers are not notices. | +| 6 | A fault scenario raises notices without end and the record grows without bound | The record keeps the newest 64 notices. | +| 7 | The record is read by a window other than the main window | `e2e_native_notices` refuses any window but the main window, like the other E2E commands. | +| 8 | A notice raised before the app handle exists is lost | Same as before: a production build with no app handle shows nothing. An E2E build still logs and records it. | +| 9 | Notices from an earlier scenario are mistaken for the current one | Scenarios read the record length first and assert only on entries added after it. A once-per-process notice (profile recovery) is matched anywhere in the record. | + +Proof: `e2e/state-updater.spec.js` scenario "renders the Rust defaults when +settings.json is corrupt at startup" asserts that the "ROSI Profile Recovery" +notice was recorded, and a full local E2E run on macOS opens no native alert. diff --git a/e2e/audit-v5-beta2/README.md b/e2e/platform-probes/README.md similarity index 93% rename from e2e/audit-v5-beta2/README.md rename to e2e/platform-probes/README.md index 8732c871..85a6cc13 100644 --- a/e2e/audit-v5-beta2/README.md +++ b/e2e/platform-probes/README.md @@ -1,4 +1,4 @@ -# V5 beta 2 audit probes +# V5 beta 2 platform probes These observational E2E probes drive the real unpackaged Tauri app, bundled yt-dlp, real FFmpeg, and an isolated local media server. Failure modes were written before probe implementation. They do not modify production code or the user's application profile. @@ -6,10 +6,10 @@ Run from the repository root on macOS with Node dependencies installed and a rea ```sh npm run test:e2e -node e2e/audit-v5-beta2/run-probes.mjs -node e2e/audit-v5-beta2/run-probes.mjs --security -node e2e/audit-v5-beta2/run-probes.mjs --ui -node e2e/audit-v5-beta2/run-probes.mjs --termination +node e2e/platform-probes/run-probes.mjs +node e2e/platform-probes/run-probes.mjs --security +node e2e/platform-probes/run-probes.mjs --ui +node e2e/platform-probes/run-probes.mjs --termination ``` The first command builds the E2E binary. Its existing suite may fail while the candidate's audit findings remain unresolved. The custom probes can still run if the build completed. Do not run Cargo build, test, or clippy between building the E2E binary and these probes; those commands can replace it without the E2E feature. Rebuild after production source changes. diff --git a/e2e/audit-v5-beta2/failure-modes.md b/e2e/platform-probes/failure-modes.md similarity index 98% rename from e2e/audit-v5-beta2/failure-modes.md rename to e2e/platform-probes/failure-modes.md index 615dbc3a..2686696e 100644 --- a/e2e/audit-v5-beta2/failure-modes.md +++ b/e2e/platform-probes/failure-modes.md @@ -1,4 +1,4 @@ -# V5 beta 2 adversarial audit probes +# V5 beta 2 platform probes: failure modes The audit probes exercise the actual Tauri app, Rust IPC, bundled yt-dlp, local media server, and real FFmpeg. No production code changes precede these probes. diff --git a/e2e/audit-v5-beta2/audit.spec.js b/e2e/platform-probes/probes.spec.js similarity index 97% rename from e2e/audit-v5-beta2/audit.spec.js rename to e2e/platform-probes/probes.spec.js index 6d81609a..89bf4624 100644 --- a/e2e/audit-v5-beta2/audit.spec.js +++ b/e2e/platform-probes/probes.spec.js @@ -84,11 +84,11 @@ function processes(marker) { it("records a stale settings response erasing a later UI choice", async () => { const initial = await api("getSettings"); await browser.execute(() => { - const original = window.api.saveSettings; + const original = window.__ROSI_E2E__.api.saveSettings; window.auditOriginalSave = original; window.auditSaveCalls = []; let held = false; - window.api.saveSettings = async (settings) => { + window.__ROSI_E2E__.api.saveSettings = async (settings) => { window.auditSaveCalls.push(JSON.parse(JSON.stringify(settings))); const response = await original(settings); if (!held) { @@ -135,7 +135,7 @@ function processes(marker) { invariantPassed: saved.theme === desired, }); await browser.execute(() => { - window.api.saveSettings = window.auditOriginalSave; + window.__ROSI_E2E__.api.saveSettings = window.auditOriginalSave; }); }); @@ -266,7 +266,7 @@ function processes(marker) { } await browser.execute(() => { document.documentElement.dataset.flatUi = "false"; - window.rosiModules.dock.selectTab("activity"); + window.__ROSI_E2E__.modules.dock.selectTab("activity"); document .querySelector("#history-list .history-item-actions button") .focus(); @@ -310,7 +310,7 @@ function processes(marker) { (baseUrl, output, done) => { Promise.all( Array.from({ length: 10 }, (_, index) => - window.api.downloadVideo({ + window.__ROSI_E2E__.api.downloadVideo({ url: `${baseUrl}/slow.mp4?audit-race=1&n=${index}`, outputPath: output, convertEnabled: false, @@ -351,7 +351,7 @@ function processes(marker) { await browser.execute((baseUrl) => { window.auditPreviewResults = []; for (let index = 0; index < 10; index += 1) { - window.api + window.__ROSI_E2E__.api .getVideoInfo(`${baseUrl}/slow.html?audit-preview=1&n=${index}`) .then( (result) => window.auditPreviewResults.push(result), @@ -522,7 +522,7 @@ function processes(marker) { } } await browser.execute(() => { - window.rosiModules.dock.selectTab("activity"); + window.__ROSI_E2E__.modules.dock.selectTab("activity"); document .querySelector("#history-list .history-item-actions button") .focus(); diff --git a/e2e/audit-v5-beta2/run-probes.mjs b/e2e/platform-probes/run-probes.mjs similarity index 98% rename from e2e/audit-v5-beta2/run-probes.mjs rename to e2e/platform-probes/run-probes.mjs index eec3348e..a6450443 100644 --- a/e2e/audit-v5-beta2/run-probes.mjs +++ b/e2e/platform-probes/run-probes.mjs @@ -200,7 +200,7 @@ try { ...profile.env, ROSI_E2E_ALLOW_LOOPBACK: securityOnly ? "0" : "1", ROSI_E2E_BINARY: e2eBinaryPath(), - ROSI_E2E_SPECS: "./audit-v5-beta2/audit.spec.js", + ROSI_E2E_SPECS: "./platform-probes/probes.spec.js", ROSI_AUDIT_SECURITY_ONLY: securityOnly ? "1" : "0", ROSI_AUDIT_UI_ONLY: uiOnly ? "1" : "0", ROSI_AUDIT_TERMINATION_ONLY: terminationOnly ? "1" : "0", @@ -254,7 +254,7 @@ try { binarySha256: hash(fs.readFileSync(e2eBinaryPath())), probeSourceSha256: { runner: hash(fs.readFileSync(fileURLToPath(import.meta.url))), - spec: hash(fs.readFileSync(path.join(scriptDirectory, "audit.spec.js"))), + spec: hash(fs.readFileSync(path.join(scriptDirectory, "probes.spec.js"))), }, fixtureSha256: { tone: hash(fs.readFileSync(tone)), diff --git a/e2e/queue-ownership.failure-modes.md b/e2e/queue-ownership.failure-modes.md new file mode 100644 index 00000000..650039f3 --- /dev/null +++ b/e2e/queue-ownership.failure-modes.md @@ -0,0 +1,81 @@ +# Queue ownership: failure modes + +Written before the Rust change. This is roadmap B7 part A: `QueueState` moves +from the global `QUEUE` mutex (`src-tauri/src/queue.rs`) into a local value +owned by the coordinator thread (`src-tauri/src/coordinator.rs`). Every read +from another thread becomes a coordinator request answered over a reply +channel. `QUEUE` and `queue::state()` are removed. + +Scenario names are the ones in `e2e/suites.json`. Where a scenario's spec +file is named, the test is the `it(...)` or `record(...)` call that proves it. +`queue-coordinator` is the v5-fixes area in `e2e/v5-fixes/queue-coordinator/`, +run by the `queue` and `lifecycle` groups. + +## Deadlock + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 1 | An in-thread handler asks the coordinator for a read (`items()`, `is_running()`, a Snapshot request) and waits. The coordinator sends to itself and hangs. | A helper called from a handler reaches a request function. | Code that runs on the coordinator thread takes `&mut QueueState` directly. Only code outside that thread calls `coordinator::request`. The handler set is reviewed for this. | The `queue`, `cancel`, `queue-management`, `queue-cancel`, and `queue-controls` scenarios each run start, cancel, remove, retry, reorder, and clear through their handlers. A self-request would hang them. | +| 2 | The coordinator waits on a child process, disk, settings, or another thread's reply. Every reader and writer then stalls. | Loading persisted items or reading settings on the coordinator thread. | Persisted items load on the first caller of `coordinator::init()` (the setup path in `queue::init`), not on the coordinator thread. The coordinator thread only changes state, sends replies, and submits to the writer or to helper threads. | `queue-coordinator` "runs queued items one at a time with exactly one outcome each" (every transition runs through the coordinator). `persisted-offline-queue` (offline-queue owner) reloads the queue at startup. | +| 3 | The main thread asks `is_running()` (window close) and waits while the coordinator publishes `queue-update`, and the publish waits on the main thread. | Blocking emit from the coordinator. | `app_state::emit` uses Tauri `emit_to` and does not wait for the webview. The main thread waits only on a reply that the coordinator sends without waiting on anything. | `close-flow` (dock-ui, main) covers the close path. No scenario forces a close while a run is publishing, so this rests on the emit contract. | +| 4 | Writer thread and coordinator wait on each other. The writer asks for a snapshot, and the coordinator waits for the writer. | Blocking send to the writer. | `schedule_persist` and `flush` only send on channels. The coordinator never waits on the writer. The writer waits on the coordinator. | `queue-latest-snapshot` (state-repairs) and `queue-flush-backup-failure` (state-repairs) run debounced writes and flushes during transitions. | + +## Torn and stale snapshots + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 5 | A reader gets items from one state and a revision from another. | Two separate reads. | Items and revision come back in one reply: `revisioned_snapshot` runs inside the coordinator, and `Snapshot` returns the pair. `items()` returns only the items from one Snapshot. | `queue-coordinator` "publishes strictly increasing revisions and never renders a stale snapshot". | +| 6 | A caller reads the queue after its own transition and does not see it. | Read answered before the commit. | A transition commits, then replies. A read sent after the reply sees the committed state, because the coordinator handles commands in arrival order. | `queue-coordinator` "keeps the persisted queue equal to the live queue after a run" (`getQueue` after the run, compared with the file). | +| 7 | `get_queue` returns an empty list while the queue exists. | The coordinator is not running (thread died), so the request returns `None`. | Readers return the empty value (`Vec::new()`, `false`). Writers keep returning `Queue coordinator is not running.` or `INTERNAL_ERROR`. This is a documented change: before, a poisoned mutex was recovered and reads still worked after a panic. | No scenario. Only reached after a coordinator panic (row 15). | + +## Order of published revisions + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 8 | The renderer gets `queue-update` revisions out of order. | Two threads publish. | Only the coordinator publishes, and each commit is published before the next command. Revisions still increase by one per commit. | `queue-coordinator` "publishes strictly increasing revisions and never renders a stale snapshot". | +| 9 | Commit order changes when the queue is read through a request. | A read bumps the revision. | Only commits bump the revision. Reads use `bump: false`. The writer's flush uses `bump: true` as before. | `queue-coordinator` revision test above. | + +## Writer snapshot racing a transition + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 10 | The writer persists an older snapshot after a newer one is durable. | A delayed debounced write. | `QueuePersistence::persist` keeps the `highest_attempted` and `last_persisted` rules. The snapshot and its revision come from one Snapshot reply. | `queue-latest-snapshot` (state-repairs) and the Rust test `flush_waits_for_the_serial_writer_and_leaves_primary_and_backup_at_latest_revision`, kept as is. | +| 11 | A flush (close or restart) acknowledges a revision that is not durable. | Flush skips a write that was superseded. | A flush acknowledges only when an equal or newer revision is durably committed. | `queue-flush-backup-failure` (state-repairs, lifecycle close path). | +| 12 | A debounced write sees a stale queue because the transition has not committed yet. | Debounce fires between the mutation and the commit. | Mutation and commit happen in one coordinator command, so the writer's snapshot always includes the full transition. | `queue-coordinator` "keeps the persisted queue equal to the live queue after a run". | + +## Shutdown and flush while the coordinator is busy + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 13 | Close or restart flushes while a stop is in progress, and the flush returns before the interrupted item is requeued. | Flush races `finish_stop_if_ready`. | The stop reply is sent only after the requeue and commit. The flush reads the state after that. | `close-pending-timeout` (state-repairs, lifecycle) and `close-flow` (dock-ui). | +| 14 | Stop or cancel leaves a child process running while the coordinator thinks the run ended. | Helper thread skipped or the state flips early. | Stop and cancel keep the existing order: flags set, helper cancels and kills, `StopCancelSettled` finishes the stop. Process waits stay off the coordinator. | `cancel` (main) waits for `yt-dlp` to exit. `queue-coordinator` "cancels a running item, retries it, and records one outcome per attempt". | + +## Runner exit and coordinator panic + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 15 | The coordinator panics in a handler. The thread unwinds and drops `QueueState` and every pending reply sender. Waiting callers get `None` and return. | Any panic in a handler. | No hang: a dropped reply makes `recv` fail, and a dropped receiver makes `send` fail. Command callers get `INTERNAL_ERROR`. Readers get an empty value (row 7). This matches today's coordinator-thread behavior. | No scenario forces a panic. Review rule. | +| 16 | The runner exits without telling the coordinator, so a later start waits on it. | Runner panic or early return. | `RunnerFinished` drops and submits `RunnerExited`, unchanged. | `queue-coordinator` "refuses manual downloads and queue starts while the other owner runs" and `download-again-quickly` (main) start the queue right after a run. | +| 17 | A start arrives while a stop waits for the runner, and replaces that runner. | Start evaluated during `stopping`. | `evaluate_start` keeps the `stopping` check and the "Queue is stopping." error. | `queue-coordinator` "cancels a running item, retries it, and records one outcome per attempt" (stop and restart). | +| 18 | A deferred start (waiting for an exiting runner) is answered only on the next command. | Deferred starts need a timer. | `run` uses `recv_timeout` to settle deferred starts. The loop keeps its timers. | `queue` (main) starts a queue right after a previous run ends. | + +## Persistence objects + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 19 | `PERSISTENCE` or `WRITER` stop being initialized after the move, so writes fail. | Lazy init order changes. | `PERSISTENCE` and `WRITER` stay as `OnceLock` holders. They are initialized on first use, as today. | `queue-flush-backup-failure` and `long-term-persistence` (persistence owner). | +| 20 | A newer-schema queue file is overwritten by an older build. | Flush path changed. | `queue::flush` keeps the `is_newer_schema_file` branch, which returns `Ok` with a warning. | `long-term-persistence` (persistence owner). | +| 21 | Corrupt primary file reads as empty, not as the backup. | Load moved to another thread. | `load_persisted` keeps the primary, then backup, order. Corrupt primary falls back to backup. | `persisted-offline-queue` (offline-queue owner) and the Rust test `corrupt_primary_reads_as_unreadable_so_backup_fallback_can_run`, kept as is. | + +## Admission + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 22 | Duplicate URL admitted because the duplicate check reads an older copy of the queue. | Check outside the coordinator. | `admit` checks against the coordinator's own state. `nonterminal_urls` only pre-filters before settings reads. | `queue-coordinator` "skips a duplicate of a URL that is already downloading" and `queue-paste-extraction` (main). | +| 23 | Queue start accepted while a manual session holds the slot. | `can_start` read at the wrong time. | `evaluate_start` calls `downloader::can_start` unchanged. The ACTIVE slot stays under its own lock (part B). | `queue-coordinator` "refuses manual downloads and queue starts while the other owner runs". | + +## Test strategy + +- The E2E gate for this change is `npm run test:e2e -- --group queue,persistence,downloads`, run twice in a row, with `ROSI_E2E_BACKGROUND=1`. +- The Rust tests in `queue.rs` (`run_drain_tests`, `persistence_tests`) and the `start_waits_for_exit` test are adapted to the new API and not weakened. No new unit tests are added. +- Rows 7, 15, and 18 have no direct scenario. They rest on review and on the existing scenarios that exercise the same paths. diff --git a/e2e/queue-url-extraction.failure-modes.md b/e2e/queue-url-extraction.failure-modes.md new file mode 100644 index 00000000..a0b74aa5 --- /dev/null +++ b/e2e/queue-url-extraction.failure-modes.md @@ -0,0 +1,26 @@ +# Queue URL extraction failure modes + +Pasted and dropped text becomes queue links through the backend command +`extract_queue_urls`. It splits the text into candidate tokens and runs each +one through `normalize_queue_url`, so the same URL safety rules that guard +`add_to_queue` decide what is accepted. The renderer keeps a per-keystroke +`isValidUrl` check only for instant feedback. It never decides what is queued. + +| # | Failure mode | Required behavior | +| --- | ------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | Private, loopback, or local host (`http://192.168.1.10/a.mp4`, `http://localhost/a.mp4`) | Refused. The token is listed in `rejected` and counted in `rejectedCount`. Nothing from it reaches the queue. | +| 2 | Non-http scheme (`ftp://`, `file://`, `mailto:`) | Refused. Tokens with `://` are listed in `rejected`. Other schemes are refused and not listed. | +| 3 | Same link twice, once with a fragment (`a.mp4?x=1` and `a.mp4?x=1#t=5`) | One URL, the fragment removed, kept at the first-seen position. | +| 4 | Same link pasted twice | One URL. A repeat is not a rejection and is not counted. | +| 5 | Trailing punctuation (`https://example.com/a.mp4,`) | Kept as part of the URL, the same as `add_to_queue` treats it. The backend does not guess and strip it. | +| 6 | Oversized paste (more than 256 KiB of text) | The command returns a `VALIDATION_ERROR` envelope. Nothing is queued, and the queue and its input stay as they were. | +| 7 | One oversized token (more than 64 KiB, the per-URL limit) inside an otherwise good paste | The token is refused and listed in `rejected`. The other links are extracted, so `add_to_queue` does not refuse the whole batch. | +| 8 | Empty, whitespace-only, or comment-only text (`# note`) | An ok envelope with empty `urls`, `rejected`, and a count of 0. The UI shows the existing "No valid http or https links were found." message. | +| 9 | Prose with no link (`please grab these`) | Not link-looking, so not listed and not counted. Only tokens with `://` count as rejected. | +| 10 | Renderer and backend disagree (the renderer's `isValidUrl` accepts a private host the backend refuses) | The per-keystroke count may show it. The add path sends only backend `urls` to the queue, and the "ignored as invalid" count comes from the backend `rejectedCount`. | +| 11 | More than 20 refused tokens in one paste | `rejected` holds the first 20 tokens. `rejectedCount` still reports the full number of refusals. | + +The E2E scenario `queue-paste-extraction` pastes a mixed block that covers rows +1 to 4, 8 and 9 through the real queue input. It asserts the queue receives +exactly the normalized safe links in first-seen order, and it records the +`extract_queue_urls` result as the repeatable proof. diff --git a/e2e/round3-renderer-repairs/README.md b/e2e/renderer-dom-checks/README.md similarity index 83% rename from e2e/round3-renderer-repairs/README.md rename to e2e/renderer-dom-checks/README.md index 61591b47..733e6ea5 100644 --- a/e2e/round3-renderer-repairs/README.md +++ b/e2e/renderer-dom-checks/README.md @@ -1,14 +1,14 @@ -# Renderer round-three repair diagnostics +# Renderer DOM checks These repeatable DOM diagnostics load the shipping `src/index.html`, transpile the shipping renderer modules, and exercise the updater module with a controlled adapter. They cover audit findings 6, 7, 8, 9, and 12 without adding unit tests. Run from the repository root: ```sh -node e2e/round3-renderer-repairs/run.cjs +node e2e/renderer-dom-checks/run.cjs ``` -The runner prints a JSON verification record and writes the same record to `e2e/artifacts/round3-renderer/renderer-repairs.json`. The artifact directory is ignored by Git. +The runner prints a JSON verification record and writes the same record to `e2e/artifacts/round3-renderer/renderer-dom-checks.json`. The artifact directory is ignored by Git. The 15 checks cover sidebar/license/modal focus ownership and inert state, modal stacking and stale-hide retirement, candidate-bound updater actions and prompt retirement, URL-bound formats across stale replies and asynchronous submissions, explicit preset survival against a pending lookup, previous-channel forwarding, and latest-preview supersession. The controlled DOM harness does not replace manual assistive-technology review or a packaged Tauri E2E run. diff --git a/e2e/round3-renderer-repairs/failure-modes.md b/e2e/renderer-dom-checks/failure-modes.md similarity index 100% rename from e2e/round3-renderer-repairs/failure-modes.md rename to e2e/renderer-dom-checks/failure-modes.md diff --git a/e2e/renderer-dom-checks/format-fixtures.cjs b/e2e/renderer-dom-checks/format-fixtures.cjs new file mode 100644 index 00000000..870ccf18 --- /dev/null +++ b/e2e/renderer-dom-checks/format-fixtures.cjs @@ -0,0 +1,14 @@ +// Typed get_formats payloads (FormatList in src-tauri media_info.rs). +function videoFormat(formatId, resolution) { + return { formatId, streamKind: "video", resolution }; +} + +function audioFormat(formatId) { + return { formatId, streamKind: "audio" }; +} + +function formatList(formats) { + return { formats }; +} + +module.exports = { audioFormat, formatList, videoFormat }; diff --git a/e2e/renderer-dom-checks/load-renderer.cjs b/e2e/renderer-dom-checks/load-renderer.cjs new file mode 100644 index 00000000..d5bcde9a --- /dev/null +++ b/e2e/renderer-dom-checks/load-renderer.cjs @@ -0,0 +1,56 @@ +const fs = require("fs"); +const path = require("node:path"); + +/** + * Loads renderer ES modules into a jsdom window. Each file runs as CommonJS + * in the window, with a resolver for its relative imports. Bare specifiers + * (the Tauri API packages) resolve to the `externals` map. + */ +// `provided` maps src paths to ready exports, so those files are never +// transpiled (the API module imports Tauri packages the loader does not know). +function createRendererLoader(w, root, ts, externals = {}, provided = {}) { + const loaded = new Map(); + const srcDir = path.join(root, "src"); + for (const [rel, exports] of Object.entries(provided)) { + loaded.set(path.resolve(srcDir, rel), { exports }); + } + function load(p) { + const file = path.resolve(srcDir, p.endsWith(".ts") ? p : `${p}.ts`); + if (loaded.has(file)) return loaded.get(file).exports; + const module = { exports: {} }; + loaded.set(file, module); + const code = ts.transpileModule(fs.readFileSync(file, "utf8"), { + compilerOptions: { + target: ts.ScriptTarget.ES2020, + module: ts.ModuleKind.CommonJS, + }, + }).outputText; + const run = w.eval(`(function (exports, require, module) {${code}\n})`); + run( + module.exports, + (spec) => { + if (!spec.startsWith(".")) { + // Packages the renderer reaches through Tauri: supplied by the caller. + if (Object.hasOwn(externals, spec)) return externals[spec]; + // Icon SVGs imported as text (Vite `?raw`), read from node_modules. + if (spec.endsWith("?raw")) { + const text = fs.readFileSync( + path.join(root, "node_modules", spec.slice(0, -"?raw".length)), + "utf8", + ); + return { default: text }; + } + throw new Error(`renderer loader has no module for ${spec}`); + } + return load( + path.relative(srcDir, path.resolve(path.dirname(file), spec)), + ); + }, + module, + ); + return module.exports; + } + return load; +} + +module.exports = { createRendererLoader }; diff --git a/e2e/round3-renderer-repairs/preview.cjs b/e2e/renderer-dom-checks/preview.cjs similarity index 91% rename from e2e/round3-renderer-repairs/preview.cjs rename to e2e/renderer-dom-checks/preview.cjs index ec790717..4d64fdee 100644 --- a/e2e/round3-renderer-repairs/preview.cjs +++ b/e2e/renderer-dom-checks/preview.cjs @@ -1,3 +1,8 @@ +const { + audioFormat, + formatList, + videoFormat, +} = require("./format-fixtures.cjs"); const fs = require("fs"); const path = require("node:path"); const root = path.resolve(__dirname, "../.."); @@ -45,7 +50,7 @@ const previewCalls = []; let resolvePreview; const ok = (data) => Promise.resolve({ ok: true, data }); const previewResolutions = new Map(); -w.api = new Proxy( +const api = new Proxy( { getChannel: () => "github", getSettings: () => Promise.resolve(s), @@ -54,7 +59,8 @@ w.api = new Proxy( getAppPlatform: () => Promise.resolve("darwin"), checkDenoInstalled: () => Promise.resolve(true), getQueue: () => Promise.resolve([]), - getFormats: () => ok("137 mp4 1920x1080 video only\n140 m4a audio only"), + getFormats: () => + ok(formatList([videoFormat("137", "1920x1080"), audioFormat("140")])), getVideoInfo: (url) => { previewCalls.push(url); return new Promise((r) => { @@ -77,7 +83,14 @@ w.api = new Proxy( : () => ok({}), }, ); -const load = require("./load-renderer.cjs").createRendererLoader(w, root, ts); +const { createTauriShim } = require("./tauri-shim.cjs"); +const load = require("./load-renderer.cjs").createRendererLoader( + w, + root, + ts, + createTauriShim().externals, + { "api.ts": { api } }, +); for (const m of ["ui", "downloads", "queue", "settings", "updates", "dock"]) load("modules/" + m + ".ts"); load("rosiEngine.ts"); diff --git a/e2e/round3-renderer-repairs/renderer.cjs b/e2e/renderer-dom-checks/renderer.cjs similarity index 78% rename from e2e/round3-renderer-repairs/renderer.cjs rename to e2e/renderer-dom-checks/renderer.cjs index 57d47bf0..efb43181 100644 --- a/e2e/round3-renderer-repairs/renderer.cjs +++ b/e2e/renderer-dom-checks/renderer.cjs @@ -1,3 +1,8 @@ +const { + audioFormat, + formatList, + videoFormat, +} = require("./format-fixtures.cjs"); const fs = require("fs"); const path = require("node:path"); const root = path.resolve(__dirname, "../.."); @@ -77,20 +82,84 @@ let queueArgs; let getFormatsImpl; let formatRequests = []; let cancelFormatsCount = 0; -let updaterStatusHandler; const settingsSaveResolvers = []; let deferNextSettingsSave = false; const ok = (data) => Promise.resolve({ ok: true, data }); -getFormatsImpl = () => ok("137 mp4 1920x1080 video only\n140 m4a audio only"); -w.api = new Proxy( +getFormatsImpl = () => + ok(formatList([videoFormat("137", "1920x1080"), audioFormat("140")])); +// Rust's preset-to-request mapping (settings::preset_to_request_options) for the +// fields this harness uses, so resolveDownloadOptions answers like the backend. +function presetRequestFields(preset) { + return { + profile: preset.profile, + bestQuality: preset.bestQuality, + audioOnly: preset.audioOnly, + advancedOptions: preset.profile === "custom", + audioOutputFormat: preset.audioFormat, + audioFormat: preset.audioFormatId, + videoFormat: preset.videoFormat, + convertEnabled: preset.convertEnabled, + convertFormat: preset.convertFormat, + keepOriginal: preset.keepOriginalAfterConvert, + gpuAcceleration: preset.gpuAcceleration, + gpuType: preset.gpuType, + writeSubtitles: preset.writeSubtitles, + subtitleLangs: preset.subtitleLangs, + embedThumbnail: preset.embedThumbnail, + embedMetadata: preset.embedMetadata, + sponsorblockRemove: preset.sponsorblockRemove, + }; +} +const api = new Proxy( { getChannel: () => "github", getSettings: () => Promise.resolve(s), + resolveDownloadOptions: (request) => { + const preset = s.downloadPresets.find((p) => p.id === request?.presetId); + const explicit = Object.fromEntries( + Object.entries(request ?? {}).filter( + ([, v]) => v !== null && v !== undefined, + ), + ); + return ok({ + url: "https://example.com/", + outputPath: "/tmp/rosi", + profile: s.downloadMode, + ...(preset ? presetRequestFields(preset) : {}), + ...explicit, + ...(preset ? { presetId: preset.id, presetName: preset.name } : {}), + }); + }, + // Apply's URL-less preset resolution, answered like resolve_preset_options. + resolvePresetOptions: (presetId) => { + const preset = s.downloadPresets.find((p) => p.id === presetId); + if (!preset) { + return Promise.resolve({ + ok: false, + error: { + code: "VALIDATION_ERROR", + message: "presetId does not match a saved preset.", + }, + }); + } + return ok({ + url: "", + outputPath: "/tmp/rosi", + profile: preset.profile, + ...presetRequestFields(preset), + presetId: preset.id, + presetName: preset.name, + }); + }, + // Saves may send only changed keys, so store the patch and answer with the + // full stored settings, as the backend does. saveSettings: (v) => { - if (!deferNextSettingsSave) return ok(v); + Object.assign(s, v); + const stored = JSON.parse(JSON.stringify(s)); + if (!deferNextSettingsSave) return ok(stored); deferNextSettingsSave = false; return new Promise((resolve) => - settingsSaveResolvers.push(() => resolve({ ok: true, data: v })), + settingsSaveResolvers.push(() => resolve({ ok: true, data: stored })), ); }, getAppVersion: () => Promise.resolve("5.0.0-beta.2"), @@ -109,16 +178,21 @@ w.api = new Proxy( downloadArgs = a; return ok({ started: true, sessionId: 1 }); }, + // Same split as extract_queue_urls for plain http(s) tokens. + extractQueueUrls: (text) => { + const urls = []; + for (const token of String(text).split(/\s+/)) { + if (/^https?:\/\//.test(token) && !urls.includes(token)) + urls.push(token); + } + return ok({ urls, rejected: [], rejectedCount: 0 }); + }, addToQueue: (urls, options) => { queueArgs = { urls, options }; return ok({ added: urls.length, skipped: 0 }); }, isPackaged: () => Promise.resolve(false), getDownloadActivity: () => ok([]), - onUpdaterStatus: (callback) => { - updaterStatusHandler = callback; - return () => {}; - }, }, { get: (o, k) => @@ -129,8 +203,18 @@ w.api = new Proxy( : () => ok({}), }, ); -const load = require("./load-renderer.cjs").createRendererLoader(w, root, ts); -for (const m of ["ui", "downloads", "queue", "settings", "updates", "dock"]) +const { createTauriShim } = require("./tauri-shim.cjs"); +const tauriShim = createTauriShim(); +const emitUpdaterStatus = (event) => tauriShim.emit("updater-status", event); +const load = require("./load-renderer.cjs").createRendererLoader( + w, + root, + ts, + tauriShim.externals, + { "api.ts": { api } }, +); +const ui = load("modules/ui.ts"); +for (const m of ["downloads", "queue", "settings", "updates", "dock"]) load("modules/" + m + ".ts"); load("rosiEngine.ts"); const wait = (ms) => new Promise((r) => setTimeout(r, ms)); @@ -168,11 +252,11 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); .getAttribute("aria-hidden"), mainInert: w.document.getElementById("main-content").inert, }; - w.rosiModules.ui.closeSidebar(); + ui.closeSidebar(); w.document.getElementById("licensesLink").click(); await wait(30); - updaterStatusHandler?.({ + emitUpdaterStatus({ status: "available", candidateId: 11, version: "6.0.0", @@ -213,7 +297,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); .getAttribute("aria-hidden"), mainInert: w.document.getElementById("main-content").inert, }; - updaterStatusHandler?.({ + emitUpdaterStatus({ status: "available", candidateId: 12, version: "6.0.1", @@ -248,14 +332,14 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); .getAttribute("aria-hidden"), }; - updaterStatusHandler?.({ + emitUpdaterStatus({ status: "available", candidateId: 13, version: "6.0.2", }); await wait(30); w.document.querySelector("#modal-buttons button:last-child").click(); - updaterStatusHandler?.({ + emitUpdaterStatus({ status: "downloaded", candidateId: 14, version: "7.0.0", @@ -310,12 +394,12 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); await wait(20); resolveSecond?.({ ok: true, - data: "88 mp4 1280x720 video only\n89 m4a audio only", + data: formatList([videoFormat("88", "1280x720"), audioFormat("89")]), }); await wait(20); resolveFirst?.({ ok: true, - data: "177 mp4 3840x2160 video only\n178 m4a audio only", + data: formatList([videoFormat("177", "3840x2160"), audioFormat("178")]), }); await wait(40); const staleReplyFormats = { @@ -357,7 +441,8 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); await wait(30); input.value = "https://example.com/e"; input.dispatchEvent(new w.Event("input", { bubbles: true })); - getFormatsImpl = () => ok("277 mp4 1920x1080 video only\n278 m4a audio only"); + getFormatsImpl = () => + ok(formatList([videoFormat("277", "1920x1080"), audioFormat("278")])); w.document.getElementById("fetchFormatsBtn").click(); await wait(40); w.document.getElementById("videoFormat").value = "277"; @@ -383,7 +468,8 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); await wait(30); input.value = "https://example.com/f"; input.dispatchEvent(new w.Event("input", { bubbles: true })); - getFormatsImpl = () => ok("377 mp4 1920x1080 video only\n378 m4a audio only"); + getFormatsImpl = () => + ok(formatList([videoFormat("377", "1920x1080"), audioFormat("378")])); w.document.getElementById("fetchFormatsBtn").click(); await wait(40); w.document.getElementById("videoFormat").value = "377"; @@ -405,7 +491,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)); await wait(30); resolvePresetLookup?.({ ok: true, - data: "477 mp4 1920x1080 video only\n478 m4a audio only", + data: formatList([videoFormat("477", "1920x1080"), audioFormat("478")]), }); await wait(50); const presetSurvivesStaleLookup = { diff --git a/e2e/round3-renderer-repairs/run.cjs b/e2e/renderer-dom-checks/run.cjs similarity index 87% rename from e2e/round3-renderer-repairs/run.cjs rename to e2e/renderer-dom-checks/run.cjs index 61c210af..ec71789b 100644 --- a/e2e/round3-renderer-repairs/run.cjs +++ b/e2e/renderer-dom-checks/run.cjs @@ -5,7 +5,7 @@ const { spawnSync } = require("node:child_process"); const root = path.resolve(__dirname, "../.."); const artifactPath = path.join( root, - "e2e/artifacts/round3-renderer/renderer-repairs.json", + "e2e/artifacts/round3-renderer/renderer-dom-checks.json", ); function runDiagnostic(name) { @@ -139,30 +139,20 @@ verify( ); verify( "previous-channel-reaches-updater", - updater.bridgeForwardsPreviousChannel && - updater.checksAfterChange.includes("darwin-beta-aarch64-app"), + updater.channelForwarded === true, { - bridgeForwardsPreviousChannel: updater.bridgeForwardsPreviousChannel, - checks: updater.checksAfterChange, + channelForwarded: updater.channelForwarded, }, ); verify( "updater-prompt-retires-and-binds-candidate", updater.activePromptAfterSecondCheck.includes("7.0.0-beta.1") && updater.readyPromptTitle === "Update Ready!" && - updater.firstCandidateId !== undefined && - updater.currentCandidateId !== undefined && updater.firstCandidateId !== updater.currentCandidateId && updater.oldPromptStillConnected === false && - updater.staleCandidateResult?.cancelled === true && - updater.staleInstallResult === undefined && - updater.installedAfterStaleAction.length === 0 && - updater.downloadCalls.at(-1) === updater.currentCandidateId && - updater.installCalls.at(-1) === updater.currentCandidateId && - updater.downloadedAfterStaleAction.length === 0 && - updater.downloaded.filter((version) => version === "7.0.0-beta.1") - .length === 1 && - !updater.downloaded.includes("6.0.0"), + updater.downloadCallsAfterStale.length === 0 && + updater.installCalls.length === 1 && + updater.installCalls[0] === updater.currentCandidateId, updater, ); verify( diff --git a/e2e/renderer-dom-checks/tauri-shim.cjs b/e2e/renderer-dom-checks/tauri-shim.cjs new file mode 100644 index 00000000..3ffd7d57 --- /dev/null +++ b/e2e/renderer-dom-checks/tauri-shim.cjs @@ -0,0 +1,36 @@ +// Fake Tauri IPC for the jsdom renderer diagnostics. Commands are recorded; +// events are emitted by the caller. The updater engine is not run here: its +// behaviour is covered by the real-app scenarios in e2e/v5-fixes/updater-engine. + +/** The modules the renderer imports from Tauri, plus the recording hooks. */ +function createTauriShim() { + const invocations = []; + const listeners = new Map(); + function invoke(command, args) { + invocations.push({ command, args: args ?? null }); + if (command === "download_update") { + return Promise.resolve({ success: true, cancelled: false, error: null }); + } + if (command === "check_for_updates") return Promise.resolve(null); + return Promise.resolve(undefined); + } + function emit(event, payload) { + for (const handler of listeners.get(event) ?? []) { + handler({ event, payload }); + } + } + const externals = { + "@tauri-apps/api/core": { invoke }, + "@tauri-apps/api/event": { + listen: (event, handler) => { + const set = listeners.get(event) ?? new Set(); + set.add(handler); + listeners.set(event, set); + return Promise.resolve(() => set.delete(handler)); + }, + }, + }; + return { externals, invocations, emit }; +} + +module.exports = { createTauriShim }; diff --git a/e2e/renderer-dom-checks/updater.cjs b/e2e/renderer-dom-checks/updater.cjs new file mode 100644 index 00000000..4ef9aa81 --- /dev/null +++ b/e2e/renderer-dom-checks/updater.cjs @@ -0,0 +1,189 @@ +const { + audioFormat, + formatList, + videoFormat, +} = require("./format-fixtures.cjs"); +const fs = require("fs"); +const path = require("node:path"); +const ts = require( + path.join(path.resolve(__dirname, "../.."), "node_modules/typescript"), +); +const { JSDOM, VirtualConsole } = require( + path.join(path.resolve(__dirname, "../.."), "node_modules/jsdom"), +); +const root = path.resolve(__dirname, "../.."); +const errors = []; +const vc = new VirtualConsole(); +vc.on("jsdomError", (e) => errors.push(e.message)); +const html = fs + .readFileSync(root + "/src/index.html", "utf8") + .replace(//gi, ""); +const dom = new JSDOM(html, { + url: "http://localhost", + runScripts: "outside-only", + pretendToBeVisual: true, + virtualConsole: vc, +}); +const w = dom.window; +Object.defineProperty(w.HTMLElement.prototype, "offsetParent", { + get() { + return this.parentElement; + }, +}); +w.matchMedia = () => ({ + matches: false, + addEventListener() {}, + removeEventListener() {}, +}); +const testSource = fs.readFileSync( + root + "/src/tests/rosiEngine.dom.test.ts", + "utf8", +); +const defaults = testSource.slice( + testSource.indexOf("function defaultSettings()"), + testSource.indexOf("function buildMockApi"), +); +w.eval(defaults); +const s = w.defaultSettings(); +s.downloadFolder = "/tmp/downloads"; +s.advancedOptions = true; +let downloadArgs; +const ok = (data) => Promise.resolve({ ok: true, data }); +const api = new Proxy( + { + getChannel: () => "github", + getSettings: () => Promise.resolve(s), + saveSettings: (v) => ok(v), + getAppVersion: () => Promise.resolve("5.0.0-beta.2"), + getAppPlatform: () => Promise.resolve("darwin"), + checkDenoInstalled: () => Promise.resolve(true), + getQueue: () => Promise.resolve([]), + getFormats: () => + ok(formatList([videoFormat("137", "1920x1080"), audioFormat("140")])), + getVideoInfo: () => ok({}), + downloadVideo: (a) => { + downloadArgs = a; + return ok({ started: true, sessionId: 1 }); + }, + isPackaged: () => Promise.resolve(false), + getDownloadActivity: () => ok([]), + }, + { + get: (o, k) => + k in o + ? o[k] + : String(k).startsWith("on") + ? () => () => {} + : () => ok({}), + }, +); + +// Renderer-side updater checks. The updater engine lives in Rust +// (src-tauri/src/updater.rs) and is covered by the real-app scenarios in +// e2e/v5-fixes/updater-engine. Here the Tauri IPC layer is a fake: commands +// are recorded, and updater-status events are emitted by the test, so only +// what the renderer does with each answer and event is checked. +const { createTauriShim } = require("./tauri-shim.cjs"); +const { invocations, emit, externals } = createTauriShim(); +const load = require("./load-renderer.cjs").createRendererLoader( + w, + root, + ts, + externals, + { "api.ts": { api } }, +); +for (const m of ["ui", "downloads", "queue", "settings", "updates", "dock"]) + load("modules/" + m + ".ts"); +const updater = load("engine/updater-ui.ts"); +const wait = (ms) => new Promise((r) => setTimeout(r, ms)); +const commandsNamed = (name) => + invocations.filter((entry) => entry.command === name); +const modalTitle = () => w.document.getElementById("modal-title").textContent; +const modalMessage = () => + w.document.getElementById("modal-message").textContent; +const clickModalButton = (label) => { + const button = [...w.document.querySelectorAll("#modal-buttons button")].find( + (entry) => entry.textContent.trim() === label, + ); + button?.click(); + return button; +}; + +(async () => { + await wait(60); + updater.setupAutoUpdater(async () => true); + + // Channel change: the renderer forwards the channel; Rust saves and revalidates it. + updater.notifyUpdateChannelChanged("auto"); + await wait(20); + const channelForwarded = commandsNamed("set_update_channel").some( + (entry) => entry.args?.channel === "auto", + ); + + // Two candidates in a row: the first prompt is retired by the second. + emit("updater-status", { + status: "available", + candidateId: 1, + version: "6.0.0", + releaseNotes: null, + isBeta: false, + manualInstall: false, + }); + await wait(30); + const firstPrompt = modalMessage(); + const oldPromptButton = [...w.document.querySelectorAll("#modal-buttons button")].find( + (entry) => entry.textContent.trim() === "Download & Install", + ); + emit("updater-status", { + status: "available", + candidateId: 2, + version: "7.0.0-beta.1", + releaseNotes: null, + isBeta: true, + manualInstall: false, + }); + await wait(30); + const activePromptAfterSecondCheck = modalMessage(); + const oldPromptStillConnected = oldPromptButton?.isConnected ?? false; + + // The superseded prompt must not start a download for candidate 1. + oldPromptButton?.click(); + await wait(30); + const downloadCallsAfterStale = commandsNamed("download_update").map( + (entry) => entry.args?.candidateId, + ); + + // Downloaded candidate 2 is the only one offered for install. + clickModalButton("Later"); + emit("updater-status", { + status: "downloaded", + candidateId: 2, + version: "7.0.0-beta.1", + }); + await wait(30); + const readyPromptTitle = modalTitle(); + clickModalButton("Restart Now"); + await wait(400); + const installCalls = commandsNamed("install_update").map( + (entry) => entry.args?.candidateId, + ); + + console.log( + JSON.stringify( + { + channelForwarded, + firstPrompt, + activePromptAfterSecondCheck, + readyPromptTitle, + firstCandidateId: 1, + currentCandidateId: 2, + oldPromptStillConnected, + downloadCallsAfterStale, + installCalls, + }, + null, + 2, + ), + ); + dom.window.close(); +})(); diff --git a/e2e/round2-renderer-failures.md b/e2e/renderer-updates-failures.md similarity index 98% rename from e2e/round2-renderer-failures.md rename to e2e/renderer-updates-failures.md index 5c59b9eb..84e26f07 100644 --- a/e2e/round2-renderer-failures.md +++ b/e2e/renderer-updates-failures.md @@ -1,4 +1,4 @@ -# Renderer round-two failure modes +# Renderer updates failure modes These cases describe the failure paths to cover before changing production code. diff --git a/e2e/renderer-updates.spec.js b/e2e/renderer-updates.spec.js new file mode 100644 index 00000000..b47dc0ad --- /dev/null +++ b/e2e/renderer-updates.spec.js @@ -0,0 +1,461 @@ +import fs from "node:fs"; +import path from "node:path"; +import assert from "node:assert/strict"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "./helpers/app-bridge.js"; +import { startUpdaterFixture } from "./helpers/updater-engine-fixture.js"; + +const RESULT_PATH = + process.env.ROSI_ROUND2_RENDERER_RESULTS || process.env.ROSI_E2E_RESULTS; +const observations = []; + +function record(name, details) { + observations.push({ name, status: "passed", ...details }); + if (RESULT_PATH) { + fs.mkdirSync(path.dirname(RESULT_PATH), { recursive: true }); + fs.writeFileSync(RESULT_PATH, `${JSON.stringify(observations, null, 2)}\n`); + } +} + +async function waitForModal(titleText) { + try { + await browser.waitUntil( + () => + browser.execute((expectedTitle) => { + const modal = document.getElementById("app-modal"); + return ( + modal?.classList.contains("active") && + document + .getElementById("modal-title") + ?.textContent?.includes(expectedTitle) + ); + }, titleText), + { + timeout: 10_000, + timeoutMsg: `modal ${titleText} did not appear`, + }, + ); + } catch (error) { + const currentModal = await browser.execute(() => { + const modal = document.getElementById("app-modal"); + return { + active: modal?.classList.contains("active") ?? false, + showing: modal?.classList.contains("showing") ?? false, + hiding: modal?.classList.contains("hiding") ?? false, + title: document.getElementById("modal-title")?.textContent ?? "", + message: document.getElementById("modal-message")?.textContent ?? "", + }; + }); + const reason = error instanceof Error ? error.message : String(error); + throw new Error(`${reason}; current modal=${JSON.stringify(currentModal)}`); + } + return browser.execute(() => ({ + title: document.getElementById("modal-title")?.textContent ?? "", + message: document.getElementById("modal-message")?.textContent ?? "", + })); +} + +async function clickModalButton(label) { + await browser.execute((expectedLabel) => { + const button = [...document.querySelectorAll("#modal-buttons button")].find( + (candidate) => candidate.textContent.trim() === expectedLabel, + ); + if (!button) throw new Error(`modal button ${expectedLabel} was not found`); + button.click(); + }, label); +} + +async function dismissModal(titleText, label) { + await waitForModal(titleText); + await clickModalButton(label); + await browser.waitUntil( + () => + browser.execute( + () => + !document.getElementById("app-modal")?.classList.contains("active"), + ), + { + timeout: 5_000, + interval: 50, + timeoutMsg: `modal ${titleText} did not finish dismissing`, + }, + ); +} + +describe("renderer round-two repairs", () => { + before(waitForAppReady); + + it("waits for startup settings before reporting the window ready", async () => { + const saved = await api("getSettings"); + const rendered = await browser.execute(() => ({ + theme: document.getElementById("themeSelect")?.value, + updateChannel: document.getElementById("updateChannelSelect")?.value, + selectedProfiles: Object.fromEntries( + ["compatible", "best-video", "audio", "custom"].map((mode) => [ + mode, + document + .getElementById( + `profile${mode === "best-video" ? "BestVideo" : mode[0].toUpperCase() + mode.slice(1)}Btn`, + ) + ?.classList.contains("selected"), + ]), + ), + })); + assert.equal(rendered.theme, saved.theme); + assert.equal(rendered.updateChannel, saved.updateChannel ?? "auto"); + const downloadMode = saved.downloadMode ?? "compatible"; + assert.equal(rendered.selectedProfiles[downloadMode], true); + record("renderer-startup-settings-ready", { + theme: rendered.theme, + updateChannel: rendered.updateChannel, + downloadMode, + closeListenerReadyBeforeReveal: true, + }); + }); + + it("keeps updater downloads single-flight and revalidates the target through install", async () => { + const platformOs = + process.platform === "darwin" + ? "darwin" + : process.platform === "linux" + ? "linux" + : "windows"; + const stableTarget = `${platformOs}-aarch64`; + const betaTarget = "darwin-beta-round2-app"; + const engine = async (command, args) => + browser.executeAsync( + (name, payload, done) => { + window.__TAURI__.core.invoke(name, payload).then( + (data) => done({ ok: true, data: data ?? null }), + (error) => done({ error: String(error) }), + ); + }, + command, + args, + ); + const probe = async () => { + const result = await engine("e2e_updater_probe"); + assert.ok(result.ok, JSON.stringify(result)); + return result.data; + }; + const statuses = () => browser.execute(() => window.round2Statuses.slice()); + const latestAvailable = async (version) => + (await statuses()) + .filter( + (event) => event.status === "available" && event.version === version, + ) + .at(-1); + const waitForAvailable = (version, after = 0) => + browser.waitUntil( + async () => + (await statuses()).filter( + (event) => + event.status === "available" && event.version === version, + ).length > after, + { + timeout: 20_000, + interval: 100, + timeoutMsg: `update ${version} was not offered`, + }, + ); + + // The beta channel is set before the feed; its background recheck settles first. + await engine("set_update_channel", { channel: "beta" }); + await browser.pause(1_500); + const fixture = await startUpdaterFixture({ + betaTarget, + disableCompact: true, + restartRefusals: 1, + }); + await browser.execute(() => { + window.round2Statuses = []; + window.__TAURI__.event.listen("updater-status", (event) => + window.round2Statuses.push(event.payload), + ); + }); + const artifactRequests = () => + fixture.server.requests.filter((request) => + request.path.startsWith("/artifacts/"), + ).length; + const probeBefore = await probe(); + const checkManually = () => + browser.execute(() => document.getElementById("checkUpdateBtn").click()); + + try { + // One transfer at a time: a second download is refused while the first runs. + let releaseFirst; + fixture.server.publish({ + target: betaTarget, + version: "9.0.0-beta.1", + payload: Buffer.from("single-flight first payload"), + fileName: "ROSI-round2-1.bin", + gate: new Promise((resolve) => { + releaseFirst = resolve; + }), + }); + await checkManually(); + await waitForAvailable("9.0.0-beta.1"); + const first = await latestAvailable("9.0.0-beta.1"); + await dismissModal("Update Available", "Later"); + await browser.execute((id) => { + window.round2FirstDownload = undefined; + window.__TAURI__.core + .invoke("download_update", { candidateId: id }) + .then((data) => { + window.round2FirstDownload = data; + }); + }, first.candidateId); + await browser.waitUntil(() => artifactRequests() === 1, { + timeout: 20_000, + interval: 100, + timeoutMsg: "first transfer did not start", + }); + const second = await engine("download_update", { + candidateId: first.candidateId, + }); + assert.equal(second.data?.error, "A download is already in progress."); + + // Cancel, then let the held response finish: its bytes are discarded. + await engine("cancel_update_download"); + await dismissModal("Download Cancelled", "OK"); + releaseFirst(); + await browser.waitUntil( + () => browser.execute(() => window.round2FirstDownload !== undefined), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "cancelled transfer did not settle", + }, + ); + assert.deepEqual( + await browser.execute(() => window.round2FirstDownload), + { + success: false, + cancelled: true, + error: null, + }, + ); + assert.ok( + !(await statuses()).some( + (event) => + event.status === "downloaded" && + event.candidateId === first.candidateId, + ), + "a cancelled late transfer was reported as downloaded", + ); + + // A downloaded candidate is released when the channel changes before Restart Now. + fixture.server.publish({ + target: betaTarget, + version: "9.0.0-beta.2", + payload: Buffer.from("target revalidation payload"), + fileName: "ROSI-round2-2.bin", + }); + await checkManually(); + await waitForAvailable("9.0.0-beta.2"); + const second2 = await latestAvailable("9.0.0-beta.2"); + await dismissModal("Update Available", "Later"); + await browser.execute((id) => { + window.__TAURI__.core.invoke("download_update", { candidateId: id }); + }, second2.candidateId); + await dismissModal("Update Ready", "Later"); + const installsBeforeStale = (await probe()).installs; + const checkingBefore = (await statuses()).filter( + (event) => event.status === "checking", + ).length; + await engine("set_update_channel", { channel: "stable" }); + await browser.waitUntil( + async () => + (await statuses()).filter((event) => event.status === "checking") + .length > checkingBefore, + { + timeout: 20_000, + interval: 100, + timeoutMsg: "channel change did not recheck", + }, + ); + await engine("install_update", { candidateId: second2.candidateId }); + await browser.pause(800); + assert.equal( + (await probe()).installs, + installsBeforeStale, + "a candidate from the former channel was installed", + ); + assert.equal( + await browser.execute(() => + document.getElementById("app-modal")?.classList.contains("active"), + ), + false, + ); + record("updater-channel-and-singleflight", { + singleflightRefused: second.data.error, + lateCancelledTransferDiscarded: true, + staleChannelInstallCalls: + (await probe()).installs - installsBeforeStale, + stableTargetChecked: stableTarget, + }); + + // Background feed errors stay quiet; a manual feed error is shown. + fixture.server.respond(betaTarget, 500, "boom"); + await engine("set_update_channel", { channel: "beta" }); + await browser.waitUntil( + async () => + (await statuses()).some( + (event) => event.status === "error" && event.kind === "feed", + ), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "background feed error was not reported", + }, + ); + await browser.pause(400); + assert.equal( + await browser.execute(() => + document.getElementById("app-modal")?.classList.contains("active"), + ), + false, + "a background feed error opened a dialog", + ); + await checkManually(); + const manualError = await waitForModal("Update Error"); + assert.ok( + manualError.message.length > 0, + "manual feed error showed no message", + ); + await dismissModal("Update Error", "OK"); + + // Installation errors stay visible with no manual check active. + fixture.server.publish({ + target: betaTarget, + version: "9.0.0-beta.3", + payload: Buffer.from("install error payload"), + fileName: "ROSI-round2-3.bin", + }); + await checkManually(); + await waitForAvailable("9.0.0-beta.3"); + const third = await latestAvailable("9.0.0-beta.3"); + await dismissModal("Update Available", "Later"); + await engine("download_update", { candidateId: third.candidateId }); + await engine("install_update", { candidateId: third.candidateId }); + const installError = await waitForModal("Update Error"); + assert.match(installError.message, /refused/); + await dismissModal("Update Error", "OK"); + const probeAfter = await probe(); + assert.equal(probeAfter.refusedRestarts - probeBefore.refusedRestarts, 1); + record("updater-channel-and-singleflight-install-error", { + installErrorVisible: installError.message.includes("refused"), + manualFeedErrorVisible: manualError.title, + }); + } finally { + await fixture.close(); + await browser.execute(() => { + if ( + document.getElementById("app-modal")?.classList.contains("active") + ) { + const dismiss = [ + ...document.querySelectorAll("#modal-buttons button"), + ].find((button) => + ["Later", "OK"].includes(button.textContent.trim()), + ); + dismiss?.click(); + } + }); + } + }); + + it("keeps legacy activity until the backend confirms a clear", async () => { + const initialClear = await api("clearDownloadActivity"); + assert.equal(initialClear.ok, true); + const legacy = [ + { + filename: "round-two-legacy.mp4", + path: "/tmp/round-two-legacy.mp4", + timestamp: Date.now(), + status: "success", + }, + ]; + await browser.execute(() => { + window.round2OriginalClearActivity = + window.__ROSI_E2E__.api.clearDownloadActivity; + }); + + try { + await browser.execute((entries) => { + window.localStorage.setItem( + "rosi-download-history", + JSON.stringify(entries), + ); + window.__ROSI_E2E__.api.clearDownloadActivity = async () => ({ + ok: false, + error: { + code: "controlled-failure", + message: "controlled history clear failure", + }, + }); + document.getElementById("clearHistory").click(); + }, legacy); + await dismissModal("Clear Activity", "Clear"); + await browser.waitUntil( + () => + browser.execute(() => + [...document.querySelectorAll(".toast-message")].some((node) => + node.textContent.includes("controlled history clear failure"), + ), + ), + { + timeout: 10_000, + timeoutMsg: "activity clear failure was not visible", + }, + ); + const afterFailure = await browser.execute(() => ({ + stored: window.localStorage.getItem("rosi-download-history"), + visible: document.querySelector(".toast-message")?.textContent ?? "", + })); + assert.ok(afterFailure.stored); + const normalizeEntries = (entries) => + entries.map((entry) => + Object.fromEntries( + Object.entries(entry).sort(([left], [right]) => + left.localeCompare(right), + ), + ), + ); + assert.deepEqual( + normalizeEntries(JSON.parse(afterFailure.stored)), + normalizeEntries(legacy), + ); + + await browser.execute(() => { + window.__ROSI_E2E__.api.clearDownloadActivity = + window.round2OriginalClearActivity; + document.getElementById("clearHistory").click(); + }); + await dismissModal("Clear Activity", "Clear"); + await browser.waitUntil( + () => + browser.execute( + () => window.localStorage.getItem("rosi-download-history") === null, + ), + { + timeout: 10_000, + timeoutMsg: "legacy activity remained after a successful clear", + }, + ); + assert.deepEqual((await api("getDownloadActivity")).data, []); + record("activity-clear-commits-after-backend", { + legacyRetainedOnFailure: true, + failureToast: afterFailure.visible, + legacyRemovedAfterSuccess: true, + }); + } finally { + await browser.execute(() => { + if (window.round2OriginalClearActivity) { + window.__ROSI_E2E__.api.clearDownloadActivity = + window.round2OriginalClearActivity; + } + window.localStorage.removeItem("rosi-download-history"); + }); + } + }); +}); diff --git a/e2e/rosi-51-foundation.failure-modes.md b/e2e/rosi-51-foundation.failure-modes.md new file mode 100644 index 00000000..c00f12a5 --- /dev/null +++ b/e2e/rosi-51-foundation.failure-modes.md @@ -0,0 +1,43 @@ +# ROSI 5.1 verification foundation failure modes + +This note is written before changes to the E2E runner and benchmark utility. + +1. **A scenario disappears from full proof.** A manifest omission, duplicate, + or typo can make the suite appear complete while coverage is missing. Keep + one canonical manifest entry per existing scenario, validate the inventory + for duplicates and missing/extra names, and keep full-gate evidence bound to + the whole canonical list. +2. **A selected feature runs the wrong underlying suite.** A group can point + at the wrong runner owner or miss a required pass. Make selection expand to + the existing runnable owner boundary and include that boundary's complete + expected scenario set; report the requested groups and expanded selection. +3. **A platform allowance masks a real failure.** A skip allowed on Windows, + macOS, or Linux can silently spread to the wrong host. Preserve the current + scenario-to-platform map verbatim and continue rejecting skipped outcomes + everywhere else. +4. **A runner-owned suite runs twice or not at all.** Treating a runner-owned + spec like a generic WebdriverIO spec can duplicate side effects; omitting its + owner can create a false pass. Preserve runner ownership and require each + runner's fresh, passing report as the full gate currently does. +5. **A targeted run is accepted as release proof.** Suite/group selection or + `ROSI_E2E_ONLY` can accidentally set `fullSuite: true` or claim the complete + expected list. Keep any targeted run partial and retain release-session's + checks for `fullSuite: true`, the canonical complete list, and the exact + E2E binary hash. +6. **A size or timing result looks more certain than its source.** Missing + files, absent reports, and unmeasured runtime metrics must not become zero + or inferred values. Record only observed sizes and report references, label + unavailable metrics explicitly, and compare only supplied, schema-valid + baseline reports. +7. **An artifact comparison mixes unrelated runs.** Different revisions, + platforms, or tool versions can make a delta misleading. Record those + identities in every benchmark report and mark comparisons incompatible when + the identity fields differ. + +## Acceptance boundary + +The full gate retains every existing scenario, its platform allowances, +execution owner, report checks, and binary hash. Manifest-selected runs are +useful for focused verification but never constitute full release proof. The +benchmark captures reproducible file-size and inventory data; runtime +performance remains unavailable until it is measured on the required hosts. diff --git a/e2e/round2-renderer-repairs.spec.js b/e2e/round2-renderer-repairs.spec.js deleted file mode 100644 index 1d0ded98..00000000 --- a/e2e/round2-renderer-repairs.spec.js +++ /dev/null @@ -1,693 +0,0 @@ -import fs from "node:fs"; -import path from "node:path"; -import assert from "node:assert/strict"; -import { browser } from "@wdio/globals"; -import { api, waitForAppReady } from "./helpers/app-bridge.js"; - -const RESULT_PATH = - process.env.ROSI_ROUND2_RENDERER_RESULTS || process.env.ROSI_E2E_RESULTS; -const observations = []; - -function record(name, details) { - observations.push({ name, status: "passed", ...details }); - if (RESULT_PATH) { - fs.mkdirSync(path.dirname(RESULT_PATH), { recursive: true }); - fs.writeFileSync(RESULT_PATH, `${JSON.stringify(observations, null, 2)}\n`); - } -} - -async function waitForModal(titleText) { - try { - await browser.waitUntil( - () => - browser.execute((expectedTitle) => { - const modal = document.getElementById("app-modal"); - return ( - modal?.classList.contains("active") && - document - .getElementById("modal-title") - ?.textContent?.includes(expectedTitle) - ); - }, titleText), - { - timeout: 10_000, - timeoutMsg: `modal ${titleText} did not appear`, - }, - ); - } catch (error) { - const currentModal = await browser.execute(() => { - const modal = document.getElementById("app-modal"); - return { - active: modal?.classList.contains("active") ?? false, - showing: modal?.classList.contains("showing") ?? false, - hiding: modal?.classList.contains("hiding") ?? false, - title: document.getElementById("modal-title")?.textContent ?? "", - message: document.getElementById("modal-message")?.textContent ?? "", - }; - }); - const reason = error instanceof Error ? error.message : String(error); - throw new Error(`${reason}; current modal=${JSON.stringify(currentModal)}`); - } - return browser.execute(() => ({ - title: document.getElementById("modal-title")?.textContent ?? "", - message: document.getElementById("modal-message")?.textContent ?? "", - })); -} - -async function clickModalButton(label) { - await browser.execute((expectedLabel) => { - const button = [...document.querySelectorAll("#modal-buttons button")].find( - (candidate) => candidate.textContent.trim() === expectedLabel, - ); - if (!button) throw new Error(`modal button ${expectedLabel} was not found`); - button.click(); - }, label); -} - -async function dismissModal(titleText, label) { - await waitForModal(titleText); - await clickModalButton(label); - await browser.waitUntil( - () => - browser.execute( - () => - !document.getElementById("app-modal")?.classList.contains("active"), - ), - { - timeout: 5_000, - interval: 50, - timeoutMsg: `modal ${titleText} did not finish dismissing`, - }, - ); -} - -async function waitForStoredPromise(name) { - return browser.executeAsync((promiseName, done) => { - window[promiseName].then( - (result) => done({ result }), - (error) => - done({ error: error instanceof Error ? error.message : String(error) }), - ); - }, name); -} - -describe("renderer round-two repairs", () => { - before(waitForAppReady); - - it("waits for startup settings before reporting the window ready", async () => { - const saved = await api("getSettings"); - const rendered = await browser.execute(() => ({ - theme: document.getElementById("themeSelect")?.value, - updateChannel: document.getElementById("updateChannelSelect")?.value, - selectedProfiles: Object.fromEntries( - ["compatible", "best-video", "audio", "custom"].map((mode) => [ - mode, - document - .getElementById( - `profile${mode === "best-video" ? "BestVideo" : mode[0].toUpperCase() + mode.slice(1)}Btn`, - ) - ?.classList.contains("selected"), - ]), - ), - })); - assert.equal(rendered.theme, saved.theme); - assert.equal(rendered.updateChannel, saved.updateChannel ?? "auto"); - const downloadMode = saved.downloadMode ?? "compatible"; - assert.equal(rendered.selectedProfiles[downloadMode], true); - record("renderer-startup-settings-ready", { - theme: rendered.theme, - updateChannel: rendered.updateChannel, - downloadMode, - closeListenerReadyBeforeReveal: true, - }); - }); - - it("keeps updater downloads single-flight and revalidates the target through install", async () => { - await browser.execute(() => { - const state = { - channel: "beta", - plans: [ - { gated: true }, - { gated: true }, - {}, - { noUpdate: true }, - { noUpdate: true }, - { error: "background feed failed" }, - { error: "manual feed failed" }, - { installError: "controlled installer failure" }, - { gated: true }, - { noUpdate: true }, - ], - feeds: [], - downloadCalls: [], - activeTransfers: 0, - maxActiveTransfers: 0, - releaseDownload: {}, - closedResources: [], - installCalls: [], - statuses: [], - nextRid: 9100, - }; - const makeUpdate = (rid, target, plan) => ({ - rid, - version: target ? `5.0.0-beta.${rid - 9100}` : `5.0.${rid - 9100}`, - body: "Renderer round-two controlled update", - target, - downloadedBytes: undefined, - async close() { - state.closedResources.push(rid); - if (this.downloadedBytes) { - await this.downloadedBytes.close(); - this.downloadedBytes = undefined; - } - }, - async download(onEvent) { - state.activeTransfers += 1; - state.maxActiveTransfers = Math.max( - state.maxActiveTransfers, - state.activeTransfers, - ); - state.downloadCalls.push(rid); - try { - if (plan.gated) { - await new Promise((resolve) => { - state.releaseDownload[rid] = resolve; - }); - } - const bytesRid = 12000 + (rid - 9100); - this.downloadedBytes = { - rid: bytesRid, - async close() { - state.closedResources.push(bytesRid); - }, - }; - onEvent({ event: "Started", data: { contentLength: 1024 } }); - onEvent({ event: "Progress", data: { chunkLength: 1024 } }); - } finally { - state.activeTransfers -= 1; - } - }, - async install() { - state.installCalls.push(rid); - if (plan.installError) throw new Error(plan.installError); - }, - }); - - state.originalAdapter = window.__ROSI_E2E__?.updaterAdapter; - state.originalSaveSettings = window.api.saveSettings; - state.delayNextSettingsSave = false; - state.settingsSaveStarted = false; - state.settingsSaveCompleted = false; - window.api.saveSettings = async (settings) => { - if (!state.delayNextSettingsSave) - return state.originalSaveSettings(settings); - state.delayNextSettingsSave = false; - state.settingsSaveStarted = true; - await new Promise((resolve) => setTimeout(resolve, 800)); - const result = await state.originalSaveSettings(settings); - state.settingsSaveCompleted = true; - return result; - }; - state.unsubscribe = window.api.onUpdaterStatus((event) => - state.statuses.push(event), - ); - window.round2Updater = state; - window.__ROSI_E2E__.updaterAdapter = { - invoke: async (command, args = {}) => { - if (command === "get_settings") - return { updateChannel: state.channel }; - if (command === "is_packaged") return true; - if (command === "is_flatpak") return false; - if (command === "get_beta_updater_target") { - return "darwin-beta-round2-app"; - } - if (command === "restart_app") return undefined; - return window.__TAURI__.core.invoke(command, args); - }, - check: async (target) => { - const plan = state.plans.shift() ?? { noUpdate: true }; - state.feeds.push({ target: target ?? null, plan }); - if (plan.error) throw new Error(plan.error); - if (plan.noUpdate) return null; - const rid = ++state.nextRid; - return makeUpdate(rid, target, plan); - }, - }; - }); - - try { - const checkForAvailableUpdate = async () => { - const before = await browser.execute( - () => - window.round2Updater.statuses.filter( - (event) => event.status === "available", - ).length, - ); - await api("checkForUpdates"); - await browser.waitUntil( - () => - browser.execute( - (count) => - window.round2Updater.statuses.filter( - (event) => event.status === "available", - ).length > count, - before, - ), - { - timeout: 10_000, - timeoutMsg: "controlled update was not available", - }, - ); - const feed = await browser.execute(() => - window.round2Updater.feeds.at(-1), - ); - await dismissModal("Update Available", "Later"); - return feed; - }; - - const betaFeed = await checkForAvailableUpdate(); - assert.equal(betaFeed.target, "darwin-beta-round2-app"); - await browser.execute(() => { - window.round2FirstDownload = window.api.downloadUpdate(); - }); - await browser.waitUntil( - () => - browser.execute( - () => window.round2Updater.downloadCalls.length === 1, - ), - { - timeout: 10_000, - timeoutMsg: "first controlled transfer did not start", - }, - ); - await api("cancelUpdateDownload"); - await dismissModal("Download Cancelled", "OK"); - await browser.execute(() => { - window.round2Updater.channel = "stable"; - }); - await api("checkForUpdates"); - const blockedRetry = await api("downloadUpdate"); - const whileFirstTransferRuns = await browser.execute(() => ({ - feeds: window.round2Updater.feeds.length, - downloads: window.round2Updater.downloadCalls.length, - active: window.round2Updater.activeTransfers, - })); - assert.equal(blockedRetry.success, undefined); - assert.equal(whileFirstTransferRuns.feeds, 1); - assert.equal(whileFirstTransferRuns.downloads, 1); - assert.equal(whileFirstTransferRuns.active, 1); - - await browser.execute( - (rid) => window.round2Updater.releaseDownload[rid](), - 9101, - ); - const cancelledResult = await waitForStoredPromise("round2FirstDownload"); - assert.deepEqual(cancelledResult, { result: { cancelled: true } }); - const firstBytesRid = 12001; - await browser.waitUntil( - () => - browser.execute( - (rid) => window.round2Updater.closedResources.includes(rid), - firstBytesRid, - ), - { - timeout: 10_000, - timeoutMsg: "late bytes from the cancelled transfer remained open", - }, - ); - - const stableFeed = await checkForAvailableUpdate(); - assert.equal(stableFeed.target, null); - await browser.execute(() => { - window.round2StableDownload = window.api.downloadUpdate(); - }); - await browser.waitUntil( - () => - browser.execute( - () => window.round2Updater.downloadCalls.length === 2, - ), - { timeout: 10_000, timeoutMsg: "stable transfer did not start" }, - ); - const statusCountBeforeTargetChange = await browser.execute( - () => window.round2Updater.statuses.length, - ); - await browser.execute(() => { - window.round2Updater.channel = "beta"; - window.round2Updater.releaseDownload[9102](); - }); - const staleTargetResult = await waitForStoredPromise( - "round2StableDownload", - ); - assert.deepEqual(staleTargetResult, { result: { cancelled: true } }); - const stableBytesRid = 12002; - await browser.waitUntil( - () => - browser.execute( - (rid) => window.round2Updater.closedResources.includes(rid), - stableBytesRid, - ), - { - timeout: 10_000, - timeoutMsg: "channel-changed update bytes remained open", - }, - ); - - await browser.waitUntil( - () => - browser.execute( - (previousCount) => - window.round2Updater.statuses - .slice(previousCount) - .some((event) => event.status === "available" && event.isBeta), - statusCountBeforeTargetChange, - ), - { - timeout: 10_000, - timeoutMsg: "effective beta target was not checked after transfer", - }, - ); - await dismissModal("Update Available", "Later"); - const betaReplacement = await browser.execute(() => - window.round2Updater.feeds.at(-1), - ); - assert.equal(betaReplacement.target, "darwin-beta-round2-app"); - await api("downloadUpdate"); - await dismissModal("Update Ready", "Later"); - - // A same-target no-update response must keep the already downloaded identity. - await api("checkForUpdates"); - await waitForModal("Update Ready"); - const retained = await browser.execute(() => ({ - hasDownloadedStatus: window.round2Updater.statuses.some( - (event) => event.status === "downloaded", - ), - lastStatus: window.round2Updater.statuses.at(-1)?.status, - })); - assert.equal(retained.lastStatus, "downloaded"); - assert.equal(retained.hasDownloadedStatus, true); - - // The channel may change after download and before the user presses Restart Now. - await browser.execute(() => { - window.round2Updater.channel = "stable"; - }); - await clickModalButton("Restart Now"); - await browser.waitUntil( - () => - browser.execute(() => - window.round2Updater.closedResources.some((rid) => rid >= 12003), - ), - { - timeout: 10_000, - timeoutMsg: - "pre-install channel check did not retire downloaded bytes", - }, - ); - const staleTargetInstallCalls = await browser.execute(() => - window.round2Updater.installCalls.slice(), - ); - assert.deepEqual( - staleTargetInstallCalls, - [], - "an update from the former channel was installed", - ); - - // Background feed failures stay quiet; manual feed failures stay visible. - const beforeBackgroundError = await browser.execute( - () => window.round2Updater.statuses.length, - ); - await api("checkForUpdates"); - await browser.waitUntil( - () => - browser.execute( - (count) => - window.round2Updater.statuses - .slice(count) - .some( - (event) => event.status === "error" && event.kind === "feed", - ), - beforeBackgroundError, - ), - { - timeout: 10_000, - timeoutMsg: "background feed error was not reported", - }, - ); - await new Promise((resolve) => setTimeout(resolve, 250)); - const backgroundModalVisible = await browser.execute(() => - document.getElementById("app-modal")?.classList.contains("active"), - ); - if (backgroundModalVisible) await clickModalButton("OK"); - assert.equal(backgroundModalVisible, false); - - await browser.execute(() => - document.getElementById("checkUpdateBtn").click(), - ); - const manualError = await waitForModal("Update Error"); - assert.match(manualError.message, /manual feed failed/); - await clickModalButton("OK"); - - // Installation errors remain visible even when no manual feed check is active. - await browser.execute(() => { - window.round2Updater.channel = "beta"; - }); - await checkForAvailableUpdate(); - await api("downloadUpdate"); - await dismissModal("Update Ready", "Later"); - await api("installUpdate"); - const installError = await waitForModal("Update Error"); - assert.match(installError.message, /controlled installer failure/); - await clickModalButton("OK"); - - // The renderer's selected channel changes before the backend save - // commits. A completing beta transfer must retire immediately, remain - // single-flight until its late bytes close, and then check Stable. - const delayedBetaFeed = await checkForAvailableUpdate(); - assert.equal(delayedBetaFeed.target, "darwin-beta-round2-app"); - await browser.execute(() => { - window.round2Updater.delayNextSettingsSave = true; - window.round2DelayedSaveDownload = window.api.downloadUpdate(); - }); - await browser.waitUntil( - () => - browser.execute( - () => window.round2Updater.downloadCalls.length === 5, - ), - { - timeout: 10_000, - timeoutMsg: "delayed-save beta transfer did not start", - }, - ); - const delayedSaveFeedCount = await browser.execute( - () => window.round2Updater.feeds.length, - ); - const delayedSaveStatusCount = await browser.execute( - () => window.round2Updater.statuses.length, - ); - await browser.execute(() => { - const channel = document.getElementById("updateChannelSelect"); - channel.value = "stable"; - channel.dispatchEvent(new Event("change", { bubbles: true })); - }); - await browser.waitUntil( - () => browser.execute(() => window.round2Updater.settingsSaveStarted), - { - timeout: 10_000, - timeoutMsg: "controlled delayed settings save did not start", - }, - ); - await dismissModal("Download Cancelled", "OK"); - await browser.execute( - (rid) => window.round2Updater.releaseDownload[rid](), - 9105, - ); - const delayedDownloadResult = await waitForStoredPromise( - "round2DelayedSaveDownload", - ); - assert.deepEqual(delayedDownloadResult, { - result: { cancelled: true }, - }); - await new Promise((resolve) => setTimeout(resolve, 100)); - const targetWhileSettingsSavePending = await browser.execute(() => ({ - backendChannel: window.round2Updater.channel, - settingsSaveCompleted: window.round2Updater.settingsSaveCompleted, - feedCount: window.round2Updater.feeds.length, - })); - assert.equal(targetWhileSettingsSavePending.backendChannel, "beta"); - assert.equal(targetWhileSettingsSavePending.settingsSaveCompleted, false); - assert.equal( - targetWhileSettingsSavePending.feedCount, - delayedSaveFeedCount, - "the target check must wait for the pending channel save", - ); - await browser.waitUntil( - () => - browser.execute( - (feedCount, statusCount) => - window.round2Updater.settingsSaveCompleted && - window.round2Updater.feeds.length > feedCount && - window.round2Updater.statuses - .slice(statusCount) - .some((event) => event.status === "not-available"), - delayedSaveFeedCount, - delayedSaveStatusCount, - ), - { - timeout: 10_000, - timeoutMsg: "Stable was not rechecked after the delayed save", - }, - ); - const delayedSaveResult = await browser.execute(() => ({ - selectedChannel: document.getElementById("updateChannelSelect").value, - staleBackendChannel: window.round2Updater.channel, - checkedTarget: window.round2Updater.feeds.at(-1).target, - lateBytesClosed: window.round2Updater.closedResources.includes(12005), - })); - assert.equal(delayedSaveResult.selectedChannel, "stable"); - assert.equal(delayedSaveResult.staleBackendChannel, "beta"); - assert.equal(delayedSaveResult.checkedTarget, null); - assert.equal(delayedSaveResult.lateBytesClosed, true); - - record("updater-channel-and-singleflight", { - maxConcurrentTransfers: await browser.execute( - () => window.round2Updater.maxActiveTransfers, - ), - lateCancelledBytesReleased: firstBytesRid, - staleChannelBytesReleased: stableBytesRid, - stableAndBetaTargetsChecked: true, - sameTargetNoUpdateKeptDownloadedPrompt: - retained.lastStatus === "downloaded", - staleTargetInstallCalls, - backgroundFeedErrorModalVisible: backgroundModalVisible, - manualFeedErrorVisible: - manualError.message.includes("manual feed failed"), - installErrorVisible: installError.message.includes( - "controlled installer failure", - ), - delayedSettingsSaveKeptStaleBackend: true, - stableTargetAfterDelayedSave: delayedSaveResult.checkedTarget, - }); - } finally { - await browser.execute(() => { - for (const release of Object.values( - window.round2Updater?.releaseDownload ?? {}, - )) { - release(); - } - }); - await browser.execute(() => { - window.round2Updater?.unsubscribe?.(); - if (window.round2Updater?.originalSaveSettings) { - window.api.saveSettings = window.round2Updater.originalSaveSettings; - } - if (window.round2Updater?.originalAdapter) { - window.__ROSI_E2E__.updaterAdapter = - window.round2Updater.originalAdapter; - } else if (window.__ROSI_E2E__) { - delete window.__ROSI_E2E__.updaterAdapter; - } - if ( - document.getElementById("app-modal")?.classList.contains("active") - ) { - const dismiss = [ - ...document.querySelectorAll("#modal-buttons button"), - ].find((button) => - ["Later", "OK"].includes(button.textContent.trim()), - ); - dismiss?.click(); - } - }); - } - }); - - it("keeps legacy activity until the backend confirms a clear", async () => { - const initialClear = await api("clearDownloadActivity"); - assert.equal(initialClear.ok, true); - const legacy = [ - { - filename: "round-two-legacy.mp4", - path: "/tmp/round-two-legacy.mp4", - timestamp: Date.now(), - status: "success", - }, - ]; - await browser.execute(() => { - window.round2OriginalClearActivity = window.api.clearDownloadActivity; - }); - - try { - await browser.execute((entries) => { - window.localStorage.setItem( - "rosi-download-history", - JSON.stringify(entries), - ); - window.api.clearDownloadActivity = async () => ({ - ok: false, - error: { - code: "controlled-failure", - message: "controlled history clear failure", - }, - }); - document.getElementById("clearHistory").click(); - }, legacy); - await dismissModal("Clear Activity", "Clear"); - await browser.waitUntil( - () => - browser.execute(() => - [...document.querySelectorAll(".toast-message")].some((node) => - node.textContent.includes("controlled history clear failure"), - ), - ), - { - timeout: 10_000, - timeoutMsg: "activity clear failure was not visible", - }, - ); - const afterFailure = await browser.execute(() => ({ - stored: window.localStorage.getItem("rosi-download-history"), - visible: document.querySelector(".toast-message")?.textContent ?? "", - })); - assert.ok(afterFailure.stored); - const normalizeEntries = (entries) => - entries.map((entry) => - Object.fromEntries( - Object.entries(entry).sort(([left], [right]) => - left.localeCompare(right), - ), - ), - ); - assert.deepEqual( - normalizeEntries(JSON.parse(afterFailure.stored)), - normalizeEntries(legacy), - ); - - await browser.execute(() => { - window.api.clearDownloadActivity = window.round2OriginalClearActivity; - document.getElementById("clearHistory").click(); - }); - await dismissModal("Clear Activity", "Clear"); - await browser.waitUntil( - () => - browser.execute( - () => window.localStorage.getItem("rosi-download-history") === null, - ), - { - timeout: 10_000, - timeoutMsg: "legacy activity remained after a successful clear", - }, - ); - assert.deepEqual((await api("getDownloadActivity")).data, []); - record("activity-clear-commits-after-backend", { - legacyRetainedOnFailure: true, - failureToast: afterFailure.visible, - legacyRemovedAfterSuccess: true, - }); - } finally { - await browser.execute(() => { - if (window.round2OriginalClearActivity) { - window.api.clearDownloadActivity = window.round2OriginalClearActivity; - } - window.localStorage.removeItem("rosi-download-history"); - }); - } - }); -}); diff --git a/e2e/round3-renderer-repairs/load-renderer.cjs b/e2e/round3-renderer-repairs/load-renderer.cjs deleted file mode 100644 index 20297f85..00000000 --- a/e2e/round3-renderer-repairs/load-renderer.cjs +++ /dev/null @@ -1,34 +0,0 @@ -const fs = require("fs"); -const path = require("node:path"); - -/** - * Loads renderer ES modules into a jsdom window. Each file runs as CommonJS - * in the window, with a resolver for its relative imports. - */ -function createRendererLoader(w, root, ts) { - const loaded = new Map(); - const srcDir = path.join(root, "src"); - function load(p) { - const file = path.resolve(srcDir, p.endsWith(".ts") ? p : `${p}.ts`); - if (loaded.has(file)) return loaded.get(file).exports; - const module = { exports: {} }; - loaded.set(file, module); - const code = ts.transpileModule(fs.readFileSync(file, "utf8"), { - compilerOptions: { - target: ts.ScriptTarget.ES2020, - module: ts.ModuleKind.CommonJS, - }, - }).outputText; - const run = w.eval(`(function (exports, require, module) {${code}\n})`); - run( - module.exports, - (spec) => - load(path.relative(srcDir, path.resolve(path.dirname(file), spec))), - module, - ); - return module.exports; - } - return load; -} - -module.exports = { createRendererLoader }; diff --git a/e2e/round3-renderer-repairs/updater.cjs b/e2e/round3-renderer-repairs/updater.cjs deleted file mode 100644 index 497cb74e..00000000 --- a/e2e/round3-renderer-repairs/updater.cjs +++ /dev/null @@ -1,225 +0,0 @@ -const fs = require("fs"); -const path = require("node:path"); -const ts = require( - path.join(path.resolve(__dirname, "../.."), "node_modules/typescript"), -); -const { JSDOM, VirtualConsole } = require( - path.join(path.resolve(__dirname, "../.."), "node_modules/jsdom"), -); -const root = path.resolve(__dirname, "../.."); -const errors = []; -const vc = new VirtualConsole(); -vc.on("jsdomError", (e) => errors.push(e.message)); -const html = fs - .readFileSync(root + "/src/index.html", "utf8") - .replace(//gi, ""); -const dom = new JSDOM(html, { - url: "http://localhost", - runScripts: "outside-only", - pretendToBeVisual: true, - virtualConsole: vc, -}); -const w = dom.window; -Object.defineProperty(w.HTMLElement.prototype, "offsetParent", { - get() { - return this.parentElement; - }, -}); -w.matchMedia = () => ({ - matches: false, - addEventListener() {}, - removeEventListener() {}, -}); -const testSource = fs.readFileSync( - root + "/src/tests/rosiEngine.dom.test.ts", - "utf8", -); -const defaults = testSource.slice( - testSource.indexOf("function defaultSettings()"), - testSource.indexOf("function buildMockApi"), -); -w.eval(defaults); -const s = w.defaultSettings(); -s.downloadFolder = "/tmp/downloads"; -s.advancedOptions = true; -let downloadArgs; -const ok = (data) => Promise.resolve({ ok: true, data }); -w.api = new Proxy( - { - getChannel: () => "github", - getSettings: () => Promise.resolve(s), - saveSettings: (v) => ok(v), - getAppVersion: () => Promise.resolve("5.0.0-beta.2"), - getAppPlatform: () => Promise.resolve("darwin"), - checkDenoInstalled: () => Promise.resolve(true), - getQueue: () => Promise.resolve([]), - getFormats: () => ok("137 mp4 1920x1080 video only\n140 m4a audio only"), - getVideoInfo: () => ok({}), - downloadVideo: (a) => { - downloadArgs = a; - return ok({ started: true, sessionId: 1 }); - }, - isPackaged: () => Promise.resolve(false), - getDownloadActivity: () => ok([]), - }, - { - get: (o, k) => - k in o - ? o[k] - : String(k).startsWith("on") - ? () => () => {} - : () => ok({}), - }, -); - -const vm = require("vm"); -const downloaded = []; -const installed = []; -const downloadCalls = []; -const installCalls = []; -const downloadPromises = []; -const availableEvents = []; -let channel = "stable"; -let feedVersion = "6.0.0"; -let checks = []; -const updaterExports = {}; -const updaterJs = ts.transpileModule( - fs - .readFileSync(root + "/src/updater.ts", "utf8") - .replaceAll("import.meta.env.VITE_ROSI_E2E", "'1'"), - { - compilerOptions: { - target: ts.ScriptTarget.ES2020, - module: ts.ModuleKind.CommonJS, - }, - }, -).outputText; -w.__ROSI_E2E__ = { - updaterAdapter: { - invoke: (command) => - ({ - is_packaged: true, - is_flatpak: false, - get_settings: { updateChannel: channel }, - get_beta_updater_target: "darwin-beta-aarch64-app", - })[command], - check: (target) => { - checks.push(target ?? "stable"); - const version = feedVersion; - return { - version, - body: "notes", - download: async () => { - downloaded.push(version); - }, - close: async () => {}, - install: async () => { - installed.push(version); - }, - }; - }, - }, -}; -vm.runInNewContext(updaterJs, { - exports: updaterExports, - require: (id) => - id.includes("/app") - ? { getVersion: async () => "5.0.0-beta.2" } - : { invoke: () => {}, check: () => {} }, - window: w, - console, - Date, - Set, - Object, - Error, -}); -w.api.checkForUpdates = updaterExports.checkForUpdates; -w.api.onUpdaterStatus = updaterExports.onUpdaterStatus; -w.api.onUpdaterProgress = updaterExports.onUpdaterProgress; -w.api.onUpdaterStatus((event) => { - if (event.status === "available") availableEvents.push(event); -}); -w.api.downloadUpdate = (candidateId) => { - downloadCalls.push(candidateId); - const promise = updaterExports.downloadUpdate(candidateId); - downloadPromises.push(promise); - return promise; -}; -w.api.installUpdate = (candidateId) => { - installCalls.push(candidateId); - return updaterExports.installUpdate(candidateId); -}; -const load = require("./load-renderer.cjs").createRendererLoader(w, root, ts); -for (const m of ["ui", "downloads", "queue", "settings", "updates", "dock"]) - load("modules/" + m + ".ts"); -load("rosiEngine.ts"); -const wait = (ms) => new Promise((r) => setTimeout(r, ms)); -(async () => { - await wait(120); - await w.__ROSI_RENDERER_STARTUP_READY__; - - await updaterExports.checkForUpdates(); - await wait(30); - const firstPrompt = w.document.getElementById("modal-message").textContent; - const oldPromptButton = w.document.querySelector("#modal-buttons button"); - const bridgeSource = fs.readFileSync(root + "/src/tauri-bridge.ts", "utf8"); - const bridgeForwardsPreviousChannel = - /notifyUpdaterChannelChanged:\s*\(channel,\s*save,\s*previousChannel\)\s*=>\s*notifyUpdaterChannelChanged\(channel,\s*save,\s*previousChannel\)/s.test( - bridgeSource, - ); - const bridgeNotify = (next, save, previousChannel) => - updaterExports.notifyUpdaterChannelChanged(next, save, previousChannel); - channel = "auto"; - feedVersion = "7.0.0-beta.1"; - bridgeNotify("auto", Promise.resolve(true), "stable"); - await wait(100); - const checksAfterChange = checks.slice(); - await updaterExports.checkForUpdates(); - await wait(50); - const activePromptAfterSecondCheck = - w.document.getElementById("modal-message").textContent; - oldPromptButton?.click(); - await wait(80); - if (downloadPromises[0]) await downloadPromises[0]; - await wait(30); - const downloadedAfterStaleAction = downloaded.slice(); - const oldPromptStillConnected = oldPromptButton?.isConnected ?? false; - const staleCandidateResult = await updaterExports.downloadUpdate( - availableEvents[0]?.candidateId, - ); - w.document.querySelector("#modal-buttons button")?.click(); - await wait(350); - const readyPromptTitle = w.document.getElementById("modal-title").textContent; - const staleInstallResult = await updaterExports.installUpdate( - availableEvents[0]?.candidateId, - ); - const installedAfterStaleAction = installed.slice(); - w.document.querySelector("#modal-buttons button")?.click(); - await wait(350); - console.log( - JSON.stringify( - { - firstPrompt, - bridgeForwardsPreviousChannel, - checksAfterChange, - checks, - activePromptAfterSecondCheck, - readyPromptTitle, - firstCandidateId: availableEvents[0]?.candidateId, - currentCandidateId: availableEvents.at(-1)?.candidateId, - oldPromptStillConnected, - staleCandidateResult, - staleInstallResult, - downloadCalls, - installCalls, - downloadedAfterStaleAction, - installedAfterStaleAction, - downloaded, - installed, - }, - null, - 2, - ), - ); - dom.window.close(); -})(); diff --git a/e2e/run-download-process-repairs.mjs b/e2e/run-download-process.mjs similarity index 98% rename from e2e/run-download-process-repairs.mjs rename to e2e/run-download-process.mjs index ed5c5610..9ee791df 100644 --- a/e2e/run-download-process-repairs.mjs +++ b/e2e/run-download-process.mjs @@ -23,12 +23,16 @@ if (process.platform === "win32") { } const scriptPath = fileURLToPath(import.meta.url); -const e2eSpec = - process.env.ROSI_REPAIRS_SPEC || "./download-process-repairs.spec.js"; +const e2eSpec = process.env.ROSI_REPAIRS_SPEC || "./download-process.spec.js"; const artifactToken = `${new Date().toISOString().replace(/[:.]/g, "-")}-${process.pid}`; const artifactDir = path.resolve( process.env.ROSI_AUDIT3_ARTIFACT_DIR || - path.join(REPO_ROOT, "e2e", "artifacts", `audit3-native-${artifactToken}`), + path.join( + REPO_ROOT, + "e2e", + "artifacts", + `download-process-${artifactToken}`, + ), ); const proxyTracePath = path.join(artifactDir, "proxy-decisions.jsonl"); const binary = e2eBinaryPath(); @@ -929,7 +933,7 @@ try { ROSI_AUDIT3_FAILURE_MODES: path.join( REPO_ROOT, "e2e", - "audit3-native-failure-modes.md", + "download-process-targeted-failure-modes.md", ), ROSI_AUDIT3_REAL_FFPROBE: ffprobeBinary, ROSI_AUDIT3_SIDECAR_FIXTURE: sidecarSrt, @@ -1078,12 +1082,16 @@ try { ), failureModes: sha256( fs.readFileSync( - path.join(REPO_ROOT, "e2e", "download-process-repairs.failures.md"), + path.join(REPO_ROOT, "e2e", "download-process.failures.md"), ), ), audit3FailureModes: sha256( fs.readFileSync( - path.join(REPO_ROOT, "e2e", "audit3-native-failure-modes.md"), + path.join( + REPO_ROOT, + "e2e", + "download-process-targeted-failure-modes.md", + ), ), ), }, diff --git a/e2e/security-release-repairs-failure-modes.md b/e2e/security-release-checks-failure-modes.md similarity index 84% rename from e2e/security-release-repairs-failure-modes.md rename to e2e/security-release-checks-failure-modes.md index 1b08a881..da5fea46 100644 --- a/e2e/security-release-repairs-failure-modes.md +++ b/e2e/security-release-checks-failure-modes.md @@ -1,4 +1,4 @@ -# Security and release repair failure modes +# Security and release checks failure modes This inventory is written before the new regression coverage and production changes. It covers the F06/F07/F08 audit findings and the two development @@ -230,3 +230,43 @@ advisories that beta 2 reported without review. 5. A warning/allowlist update masks an advisory without a documented review, or labels a package dev-only without verifying every affected lock node. 6. `package.json` and `package-lock.json` disagree after a targeted update. + +## B4 typed IPC for the remaining `Value` commands + +Commands converted: `get_formats`, `get_video_info`, `open_external`, +`open_file_location`, `show_notification`, `save_settings`, `log_error`, +`remove_from_queue`, `retry_queue_item`, `reorder_queue_item`. Each takes +`FalliblePayload` (or `FalliblePayload>` for objects). A +`FalliblePayload::Invalid` value carries the malformed JSON, and the command maps +it to the same envelope and message the `Value` path returned. The rules: + +1. Wrong JSON type for a URL, path or ID field (number, array, object, `null` + where a string is required): same code and message as before, for example + `INVALID_URL "Invalid URL provided."`, `INVALID_PATH "File path must be a + non-empty string."`, `VALIDATION_ERROR "Queue item ID must be a string."`. +2. Missing field: `get_formats`, `open_external`, `open_file_location`, + `remove_from_queue` and `retry_queue_item` treat it as wrong type and return + the same message. A missing `options` or `request` argument is still a Tauri + argument error, as before. +3. Extra unknown field: ignored. No `deny_unknown_fields` is added, so + `show_notification` and `reorder_queue_item` keep today's behavior. +4. `log_error` with a non-string message is still dropped silently, and long + messages are still truncated at `MAX_RENDERER_MESSAGE_CHARS`. +5. `get_video_info` checks the URL before `playlistMode`, and `reserve()` still + runs first. A `playlistMode` that is not `current`, `all` or `null` (including + a wrong type) gets `VALIDATION_ERROR "Playlist preview mode must be current or all."`. +6. `show_notification` with a non-object payload returns `"Notification payload + must be an object."`. With an object whose title, body or filePath has the + wrong type, it returns `"Notification title, body, and filePath must be + strings when provided."`. `JsonObject` keeps arrays out of the struct path. +7. Validator skipped by a typed path: the typed value still goes through the + policy checks. URLs go through `is_safe_http_url` or `validate_external_url`, + paths through `validate_file_location`, queue IDs through + `validate_queue_item_id` (length and safe identifier), reorder direction + through the up/down check, and notifications through the length caps and the + `filePath` allow-list. Those checks are kept in `validation.rs`. Only the + shape checks that the types enforce were removed. +8. Message drift: each message string is copied verbatim from the old code. + `validate_external_url` and `validate_file_location` keep their existing + policy text. `validate_file_location` still accepts `&Value` for stored + activity and queue data. diff --git a/e2e/session-ownership.failure-modes.md b/e2e/session-ownership.failure-modes.md new file mode 100644 index 00000000..e3df6b99 --- /dev/null +++ b/e2e/session-ownership.failure-modes.md @@ -0,0 +1,67 @@ +# Session ownership: failure modes + +Written before the Rust change. This is roadmap B7 part B: the download session +slot moves out of the globals in `src-tauri/src/downloader.rs` (`ACTIVE`, +`ACTIVE_PRESENT`, `STARTUP`, `EVENT_PUBLISH`) into a session owner thread +(`src-tauri/src/downloader/session_owner.rs`). The owner holds the one +`Session` and runs its tasks in arrival order. Callers ask it over reply +channels. Process waits, process termination, stats, and coordinator waits stay +on caller threads. + +Scenario names are the ones in `e2e/suites.json` groups `downloads`, +`conversion`, `queue`, and `persistence`, and the spec titles in +`e2e/queue-coordinator`, `e2e/download-process*.spec.js`, +`e2e/native-downloads.spec.js`, and `e2e/download-session.spec.js`. + +## Deadlock + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 1 | An owner task asks the owner for something and waits. The owner waits on itself. | A helper called inside a task calls `with_session`, `cancel_session`, or `complete_session`. | Tasks take `&mut Session` directly. Only caller threads send requests. `run` checks a thread-local flag and refuses a request from the owner with a logged error and `None`, so it cannot hang. | `queue-coordinator` "cancels a running item, retries it, and records one outcome per attempt" and "clears a running queue without recording an outcome for removed items" run cancel, stop, and clear through the owner. A self-request would hang them. | +| 2 | The owner waits on a child process, a reader thread, or the coordinator. Every session event stalls. | `terminate_tree` (up to 5 s), `await_finalized`, stats file IO, or a join on a reader inside a handler. | `Cancel` only marks the session and returns the children. The caller terminates them, then awaits the coordinator or calls `Finish`. `Finish` takes the session and emits. Stats and the terminal send happen on the caller after `Finish` returns. | `download-process` "process-tree-escalation-after-parent-exit" (kill escalation without a stalled owner). `download-process` "codec-probe-cancellation" (probe waits run off the owner). | +| 3 | The owner emits a taskbar update, the main thread is waiting on a request to the owner, and both wait on each other. | `apply_taskbar` blocks on the main thread. | The main thread never sends a request to the owner. It reads `is_busy()` from the atomic hint. Queue commands run on `spawn_blocking` threads (`clear_queue_blocking`, `cancel_queue_blocking`, `cancel_download`). | `close-flow` (dock-ui) and `queue-controls` (queue) run close, clear, and cancel while a download is active. | +| 4 | The owner waits on the coordinator, and the coordinator waits on the owner. | `await_finalized` inside a handler. Coordinator's `can_start` asks the owner. | The owner only calls `coordinator::register` and `coordinator::terminal`, which are non-blocking submits. The coordinator reads `can_start` from the atomic hint. It never sends a request to the owner. The stop helper runs `cancel_active_session` on its own thread. | `queue-coordinator` "refuses manual downloads and queue starts while the other owner runs" (coordinator checks ownership while a download runs). | +| 5 | A start waits for the previous session's finalization while the previous session waits for the start. | Same-owner `start_download` cancels the current session and awaits it. | The start caller awaits the coordinator with no owner state held. The previous session's exit path finalizes it through `Finish`, which does not depend on the start caller. | `queue-coordinator` "runs queued items one at a time with exactly one outcome each" (queue hands off session to session). `download-process` "concurrent-manual-start-cancellation". | + +## Stale and racing sessions + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 6 | Events from an old session are emitted after a new session started. | An old reader or conversion thread emits after `Install` of the next session. | `install` is accepted only into an empty slot, and `with_session` matches the current id. Once the old session is finished, its events find no match and are dropped. Events the owner emitted earlier were ordered before the next install. | `download-process` "stale-session-events-do-not-clear-active-operation". | +| 7 | Two starts race, and both install a session. | Two `start_download` calls run at once. | `Install` is one owner command. The first install wins. The second gets `Occupied` (same owner) or `Conflict` (other owner). `Occupied` cancels that exact session id and awaits it, then retries. | `download-process` "manual-queue-start-ownership" and "concurrent-manual-start-cancellation". | +| 8 | A cancel lands while a session is starting, before its child is registered. | `cancel_session` between `Install` and spawn. | Cancel sets `cancelled`. Registration checks `cancelled` under the owner (`with_session`) and terminates the new child. `active_not_cancelled` checks run before spawn. | `native-downloads` "download-cancel-cleans-staging". `queue-coordinator` "cancels a running item, retries it, and records one outcome per attempt". | +| 9 | A cancel targets a session that was already replaced. | Stop helper reads a session id, then another session installs. | `cancel_session` takes an optional target id. A target mismatch returns no plan, and the caller awaits that id. It never cancels the newer session. | `queue-coordinator` "runs queued items one at a time with exactly one outcome each". | +| 10 | Cancel and exit both finalize the same session. | `on_ytdlp_exit` and `cancel_session` race. | Cancel sets `ytdlp_exit_pending` when a child, a conversion, or an exit is pending, and the caller then awaits. Only `Finish` takes the session, so the first `Finish` wins. | `download-process-targeted` "playlist-ytdlp-cancel-preserves-complete-entry". | + +## Completion, terminal results, and ordering + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 11 | A completion is delivered twice. | Two `complete_session` calls for one session. | `Finish` takes the session out of the slot. Only the first call with a matching id gets `Some`. Later calls return with nothing sent. | `queue-coordinator` "runs queued items one at a time with exactly one outcome each". | +| 12 | A completion is never delivered. | Caller panics after `Finish`, before the terminal send. Or an await waits on a session whose exit path never runs. | Caller code after `Finish` is only stats and the terminal send, with no panicking calls. Exit paths for every wait case are listed in row 14. | `queue-coordinator` "keeps the persisted queue equal to the live queue after a run" (every queued item gets a terminal). | +| 13 | Terminal order changes: the coordinator sees the terminal before stats or before the completion events. | Terminal sent by the owner before the caller records stats. | `Finish` emits `complete`, `download-complete`, and idle `job-progress` on the owner. The caller records stats, then sends the terminal, which keeps the old order. | `native-downloads` "download-only-final-placement" (completion and activity records). `queue-coordinator` "publishes strictly increasing revisions and never renders a stale snapshot". | +| 14 | Exit or cancel path leaves the session without a finalizer. | Child exits before its wait thread starts, or cancel marks a conversion without a worker. | The wait thread starts after registration, so `on_ytdlp_exit` always sees the session. Conversion handoff sets `conversion_pending`, and cancel waits for it. | `download-process` "process-tree-escalation-after-parent-exit" and "conversion-attempt-ownership". | +| 15 | Setup failures finish without a terminal. | Early returns in `start_download` (invalid URL, folder, dependency, spawn) skip `complete_session`. | Each early return calls `complete_session` with its existing message. Messages stay the same. | `native-downloads` "download-failure-cleans-staging" and "download-retry-cleans-staging". | + +## Owner thread failure + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 16 | The owner thread panics and every later download fails. | A panic in a task. | The owner catches the panic per task and keeps running, like the old recovered mutex. The panicking caller gets no reply, and callers treat a missing reply as "session gone". `install` has no panicking step, so a missing reply there returns "Download session is unavailable." and is not expected in practice. | No scenario. Documented change: before, a poisoned lock was recovered and later downloads still ran. The same recovery now happens per command on the owner. | +| 17 | `can_start` or `is_busy` reads a stale hint. | Atomic hint set after the owner moved. | The hint is read-only. `Install` is the only authoritative check and returns `Conflict` or `Occupied` on the owner. The queue retries after `Conflict`. | `queue-coordinator` "refuses manual downloads and queue starts while the other owner runs". | + +## Conversion and publication steps + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 18 | FFmpeg registers after a cancel and keeps running. | `execute_ffmpeg` registers the child late. | Registration checks `cancelled`. A cancelled registration terminates the child and returns `Cancelled`. | `download-process` "codec-probe-cancellation" and `conversion` "conversion-attempt-ownership". | +| 19 | A codec probe leaves an owned child behind after cancel. | Probe clears `ffmpeg` after a cancel. | The probe clears its own child only if the slot still holds that child (`Arc::ptr_eq`). | `download-process` "codec-probe-cancellation". | +| 20 | Output is published after cancel and dropped from the batch result. | `install_conversion_output_for_session` and `publish_same_extension_for_session` record after a cancel. | Same as before: the record goes through the owner. A cancelled session still records what was installed, and the batch reports it. | `download-process-targeted` "same-extension-cancel-records-final-path" and `download-process` "playlist-cancel-retains-completed-entry". | +| 21 | A conversion failure is recorded after cancel and changes the batch status. | `record_conversion_failure` after cancel. | The `!session.cancelled` check stays inside the owner closure. | `download-process` "playlist-conversion-accounting". | +| 22 | Shutdown drops a claimed queue item. | `kill_all_processes` runs while a claimed item starts. | Shutdown uses the same cancel path with `ytdlp_first`. The coordinator's stop helper runs it off the coordinator thread. | `download-session` "shutdown drains a newly claimed queue item before final flush". | + +## Ids + +| # | Failure mode | Mechanism | Required behavior | Proof | +| --- | --- | --- | --- | --- | +| 23 | Two sessions get one id. | Id minted under contention. | `COUNTER` stays an `AtomicU64`. It mints ids before `Install` without a round trip, so an id is unique without owner state. | `queue-coordinator` "runs queued items one at a time with exactly one outcome each" (ids route terminals). | diff --git a/e2e/settings-patch.failure-modes.md b/e2e/settings-patch.failure-modes.md new file mode 100644 index 00000000..1205092c --- /dev/null +++ b/e2e/settings-patch.failure-modes.md @@ -0,0 +1,25 @@ +# Settings patch save failure modes + +The renderer keeps a baseline of the settings the backend last confirmed +(`backendSettings` in `src/engine/settings-store.ts`). Each save sends only the +top-level keys that differ from that baseline, and `save_settings` merges the +patch into the stored file. Values the renderer did not change are never sent, +so a value written to disk by another path survives an unrelated save. + +| # | Failure mode | Required behavior | +| --- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | `downloadPresets` (or another key) changes on disk after load, then an unrelated setting is saved | The disk value survives. The stale renderer copy is not sent. | +| 2 | The renderer changes one key and the others match the baseline | The patch holds only the changed key. | +| 3 | The snapshot equals the last confirmed state (edit reverted or no real change) | An empty patch is still sent, so the backend keeps every value. Waiters settle as saved, feedback shows saved for the latest revision, and `settingsSavedRevision` advances. | +| 4 | A save succeeds | The returned settings become the new baseline. Reconcile runs as before, only when the snapshot is still the newest revision. | +| 5 | A save fails by error, exception, or `NEWER_VERSION` | The baseline does not move, so the changed keys are sent again on the next save. | +| 6 | `VALIDATION_ERROR` refuses some keys | The baseline becomes the disk state from `getSettings`. Refused keys are restored as before. A newer edit to a refused key stays and is sent on the next save. | +| 7 | A structured value is copied to a new object with equal contents | It is not sent. Equality is deep through `settingsValuesMatch`. | +| 8 | A key is missing from the renderer snapshot | It is not sent and not deleted. The backend keeps the stored value. | +| 9 | Imported settings are reconciled in place | The imported values become the baseline, so they are not sent again as changes. | +| 10 | No baseline was recorded | The full snapshot is sent, as before. | + +The E2E scenario `settings-patch-preserves-backend-values` changes +`downloadPresets` in `settings.json` behind the renderer, saves an unrelated +toggle through the UI, and checks the file on disk and the keys the renderer +sent. Its recorded observation is the repeatable proof artifact. diff --git a/e2e/settings-rejection-failure-modes.md b/e2e/settings-rejection-failure-modes.md index 34e089ee..6f75539f 100644 --- a/e2e/settings-rejection-failure-modes.md +++ b/e2e/settings-rejection-failure-modes.md @@ -26,3 +26,39 @@ The rejection path must handle these cases: The renderer E2E case holds an actual backend rejection, edits the same field during the save and settings-read waits, then checks both the visible control and `settings.json`. Its recorded observation is the repeatable proof artifact. + +## Typed `save_settings` payload (B4) + +`save_settings` takes `FalliblePayload>`. Every +known key is an `Option>`, so one bad field never fails the +whole struct. These cases must keep the behavior of the old `Value` validator: + +1. Wrong JSON type for a field (a string for a boolean, a number for an enum, + an array for `ffmpegPath`): the field is refused with its existing message + (`" must be a boolean."`, `"theme must be one of: ..."`, and so on), the + other fields are saved, and `details` lists the refused key. +2. `null` for a boolean, enum or path field is a wrong type, not an absent field, + so it is refused with the field's message. `present_payload` keeps `null` as + `Invalid`. Notification options and queue reorder fields still treat `null` + as absent, as before. +3. Missing field: not a rejection. The stored value is kept. +4. Extra unknown key: ignored and not saved, as before. No `deny_unknown_fields` + is added, so this stays a deliberate decision. +5. Non-object payload (array, string, number, `null`): `VALIDATION_ERROR` with + `"Settings payload must be an object."`. `JsonObject` rejects arrays, because + serde would otherwise build a struct with all defaults from `[]`. +6. Message drift: every refused field keeps the literal message from the old + `validate_setting_value`. The rejection list is sorted by key, matching the + old `serde_json::Map` (no `preserve_order`), so the joined message order is + unchanged. +7. Validator skipped by the typed path: each typed value still goes through its + policy closure (allow-lists, length limits, `validate_download_path`, + `validate_ffmpeg_path_value`, `parse_upstream_proxy`, subtitle language + syntax). A typed `theme: "neon"` is refused the same way the `Value` path + refused it. +8. Unchanged value: a field equal to the stored JSON is skipped before + validation, as before, so a stored FFmpeg path that is missing on disk is not + reported on every save. Equality uses the field's JSON (`as_json`), which is + the re-serialized typed value or the raw invalid value. +9. `downloadPresets` keeps its nested grammar in `validate_preset_list`. Both the + typed and the invalid path run that validator, so its messages are unchanged. diff --git a/e2e/specs/main.spec.js b/e2e/specs/main.spec.js index 33bea332..6940bacf 100644 --- a/e2e/specs/main.spec.js +++ b/e2e/specs/main.spec.js @@ -32,7 +32,7 @@ function sha256File(filePath) { .digest("hex"); } -/** Call a `window.api` method in the app and return its resolved value. */ +/** Call a `window.__ROSI_E2E__.api` method in the app and return its resolved value. */ async function api(method, ...args) { // The WebDriver bridge fails on script results containing non-ASCII text, // so the page returns ASCII-escaped JSON and Node parses it. @@ -44,7 +44,7 @@ async function api(method, ...args) { (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`, ); Promise.resolve() - .then(() => window.api[name](...params)) + .then(() => window.__ROSI_E2E__.api[name](...params)) .then( (value) => done(ascii({ ok: true, value: value ?? null })), (error) => @@ -61,7 +61,9 @@ async function api(method, ...args) { ); const outcome = JSON.parse(encoded); if (!outcome.ok) - throw new Error(`window.api.${method} failed: ${outcome.error}`); + throw new Error( + `window.__ROSI_E2E__.api.${method} failed: ${outcome.error}`, + ); return outcome.value; } @@ -303,7 +305,9 @@ async function reloadRenderer() { await browser.waitUntil( async () => browser.execute( - () => Boolean(window.__ROSI_E2E__?.ready) && Boolean(window.api), + () => + Boolean(window.__ROSI_E2E__?.ready) && + Boolean(window.__ROSI_E2E__?.api), ), { timeout: 60_000, timeoutMsg: "renderer did not come back after reload" }, ); @@ -611,7 +615,7 @@ async function restoreWizardSettings(original) { } /** - * Replace window.api methods with recorders for bridge calls that would + * Replace window.__ROSI_E2E__.api methods with recorders for bridge calls that would * leave the app (browser, Finder, OS dialogs, notifications). Each stub * records its arguments and resolves to the given value. */ @@ -620,9 +624,9 @@ async function stubApi(stubs) { window.__rosiStubs ??= { original: {}, calls: [] }; for (const [name, value] of Object.entries(map)) { if (!(name in window.__rosiStubs.original)) { - window.__rosiStubs.original[name] = window.api[name]; + window.__rosiStubs.original[name] = window.__ROSI_E2E__.api[name]; } - window.api[name] = (...args) => { + window.__ROSI_E2E__.api[name] = (...args) => { window.__rosiStubs.calls.push({ name, args: JSON.parse(JSON.stringify(args)), @@ -649,7 +653,7 @@ function restoreApi() { return browser.execute(() => { const stubs = window.__rosiStubs; if (!stubs) return []; - Object.assign(window.api, stubs.original); + Object.assign(window.__ROSI_E2E__.api, stubs.original); window.__rosiStubs = undefined; return stubs.calls; }); @@ -779,9 +783,14 @@ describe("ROSI main window", () => { await browser.waitUntil( async () => browser.execute( - () => Boolean(window.__ROSI_E2E__?.ready) && Boolean(window.api), + () => + Boolean(window.__ROSI_E2E__?.ready) && + Boolean(window.__ROSI_E2E__?.api), ), - { timeout: 60_000, timeoutMsg: "E2E hook / window.api not installed" }, + { + timeout: 60_000, + timeoutMsg: "E2E hook / window.__ROSI_E2E__.api not installed", + }, ); }); @@ -798,7 +807,7 @@ describe("ROSI main window", () => { try { await browser.execute(() => { const stubs = window.__rosiStubs; - if (stubs) Object.assign(window.api, stubs.original); + if (stubs) Object.assign(window.__ROSI_E2E__.api, stubs.original); window.__rosiStubs = undefined; }); const patch = Object.fromEntries( @@ -1666,6 +1675,58 @@ describe("ROSI main window", () => { expectedComponentText, "the rendered yt-dlp component license differs from the packaged source", ); + // Licence links in the frame must reach api.openExternal through the main + // window's postMessage listener. Forged or unsafe messages must not. + const linkUrl = "https://www.gnu.org/licenses/old-licenses/gpl-2.0.html"; + await browser.execute(() => { + const api = window.__ROSI_E2E__.api; + window.__rosiLicenseOriginalOpen = api.openExternal; + window.__rosiLicenseOpened = []; + api.openExternal = async (url) => { + window.__rosiLicenseOpened.push(url); + return { ok: true, data: { opened: true } }; + }; + }); + try { + // The frame's CSP blocks WebDriver script injection, so the click is a + // DOM click on the frame's own link. It runs the frame's click handler, + // which posts the message to this window. + const clicked = await browser.execute((url) => { + const frameDoc = + document.getElementById("licenses-frame")?.contentDocument; + const link = [ + ...(frameDoc?.querySelectorAll("a[data-external]") ?? []), + ].find((candidate) => candidate.getAttribute("data-external") === url); + if (!link) return false; + link.click(); + return true; + }, linkUrl); + assert.ok(clicked, "licence link is missing from the frame"); + await browser.waitUntil( + () => browser.execute(() => window.__rosiLicenseOpened.length === 1), + { timeout: 10_000, timeoutMsg: "licence link did not open" }, + ); + const afterLink = await browser.execute(() => window.__rosiLicenseOpened); + assert.deepEqual(afterLink, [linkUrl]); + + // The main window posting the same shape must not open anything. + await browser.execute((url) => { + window.postMessage( + { type: "rosi-open-external", url }, + window.location.origin, + ); + }, linkUrl); + await browser.pause(300); + const afterForged = await browser.execute( + () => window.__rosiLicenseOpened, + ); + assert.deepEqual(afterForged, [linkUrl]); + } finally { + await browser.switchToParentFrame(); + await browser.execute(() => { + window.__ROSI_E2E__.api.openExternal = window.__rosiLicenseOriginalOpen; + }); + } await browser.execute(() => document.getElementById("close-licenses")?.click(), ); @@ -1684,7 +1745,7 @@ describe("ROSI main window", () => { await browser.pause(1500); const after = await browser.execute(() => ({ href: window.location.href, - api: typeof window.api?.getAppVersion, + api: typeof window.__ROSI_E2E__?.api?.getAppVersion, })); assert.equal(after.href, before); assert.equal(after.api, "function"); @@ -1757,12 +1818,27 @@ describe("ROSI main window", () => { : `${MEDIA}/clip-one.mp4`; const formats = await api("getFormats", url); assert.equal(formats.ok, true, formats.error?.message); + assert.ok(Array.isArray(formats.data.formats)); + assert.ok( + formats.data.formats.every( + (format) => + typeof format.formatId === "string" && + ["audio", "video", "audioVideo"].includes(format.streamKind), + ), + ); if (HAS_FFMPEG) { - assert.match(formats.data, /audio only/); - assert.match(formats.data, /video only/); + assert.ok( + formats.data.formats.some((format) => format.streamKind === "audio"), + ); + assert.ok( + formats.data.formats.some((format) => format.streamKind === "video"), + ); } record("formats", { - lines: formats.data.split(/\r?\n/).filter(Boolean).length, + formats: formats.data.formats.length, + streamKinds: [ + ...new Set(formats.data.formats.map((format) => format.streamKind)), + ], }); }); @@ -1927,7 +2003,9 @@ describe("ROSI main window", () => { }); it("switches Queue, Activity, and Console in one dock and remembers the tab", async () => { - await browser.execute(() => window.rosiModules.dock.selectTab("queue")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("queue"), + ); let state = await dockState(); assert.deepEqual(state.selected, ["queue"]); assert.deepEqual(state.visiblePanels, ["queueSection"]); @@ -1990,7 +2068,9 @@ describe("ROSI main window", () => { "2", ); await api("clearQueue"); - await browser.execute(() => window.rosiModules.dock.selectTab("activity")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("activity"), + ); await waitForSavedSetting("dockTab", "activity", "dock tab was not saved"); await reloadRenderer(); @@ -2000,7 +2080,9 @@ describe("ROSI main window", () => { ); state = await dockState(); assert.deepEqual(state.visiblePanels, ["download-history"]); - await browser.execute(() => window.rosiModules.dock.selectTab("queue")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("queue"), + ); await waitForSavedSetting( "dockTab", "queue", @@ -2062,7 +2144,8 @@ describe("ROSI main window", () => { it("accepts links dropped onto the download card", async () => { const link = `${MEDIA}/clip-two.mp4`; - const dropped = await browser.execute((value) => { + // The drop reads the backend's link split, so wait for the value to land. + const dropped = await browser.executeAsync((value, done) => { const card = document.querySelector(".download-card"); const input = document.getElementById("url"); input.value = ""; @@ -2082,12 +2165,21 @@ describe("ROSI main window", () => { dataTransfer: data, }), ); - return { - value: input.value, - highlighted, - overPrevented: over.defaultPrevented, - cleared: !card.classList.contains("drag-over"), + const cleared = !card.classList.contains("drag-over"); + const started = Date.now(); + const settle = () => { + if (input.value === value || Date.now() - started > 5000) { + done({ + value: input.value, + highlighted, + overPrevented: over.defaultPrevented, + cleared, + }); + return; + } + setTimeout(settle, 50); }; + settle(); }, link); await typeUrl(""); assert.equal(dropped.value, link); @@ -2160,7 +2252,7 @@ describe("ROSI main window", () => { it("shrinks the dock to its empty message and grows it for content", async () => { const originalTab = await browser.execute( - () => window.rosiModules.dock.getState().tab, + () => window.__ROSI_E2E__.modules.dock.getState().tab, ); const measure = () => browser.execute(() => { @@ -2184,7 +2276,9 @@ describe("ROSI main window", () => { }; await api("clearQueue"); - await browser.execute(() => window.rosiModules.dock.selectTab("queue")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("queue"), + ); const empty = await waitForEmpty( true, "empty queue did not shrink the dock", @@ -2205,10 +2299,12 @@ describe("ROSI main window", () => { await api("clearQueue"); await waitForEmpty(true, "cleared queue did not shrink the dock again"); - await browser.execute(() => window.rosiModules.dock.selectTab("activity")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("activity"), + ); const activity = await waitForEmpty(false, "activity with rows is empty"); await browser.execute( - (tab) => window.rosiModules.dock.selectTab(tab), + (tab) => window.__ROSI_E2E__.modules.dock.selectTab(tab), originalTab, ); record("dock-empty", { @@ -2290,7 +2386,9 @@ describe("ROSI main window", () => { it("draws every icon from the bundled Lucide set", async () => { const icons = await browser.execute(() => { - window.rosiModules.ui.showToast("Lucide check", { type: "success" }); + window.__ROSI_E2E__.modules.ui.showToast("Lucide check", { + type: "success", + }); const svgs = [...document.querySelectorAll("svg")]; return { placeholders: document.querySelectorAll("span[data-icon]").length, @@ -2387,7 +2485,10 @@ describe("ROSI main window", () => { const result = await browser.execute(() => { const pictographic = /\p{Extended_Pictographic}/u; const probe = document.createElement("span"); - window.rosiModules.icons.renderStatus(probe, "\u274C Download failed."); + window.__ROSI_E2E__.modules.icons.renderStatus( + probe, + "\u274C Download failed.", + ); const output = document.getElementById("output"); return { probeIcon: probe.querySelector("svg")?.dataset.icon ?? null, @@ -2422,9 +2523,11 @@ describe("ROSI main window", () => { it("keeps console lines copyable, capped, and clearable", async () => { const originalTab = await browser.execute( - () => window.rosiModules.dock.getState().tab, + () => window.__ROSI_E2E__.modules.dock.getState().tab, + ); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("console"), ); - await browser.execute(() => window.rosiModules.dock.selectTab("console")); const result = await browser.execute(() => { const output = document.getElementById("output"); const lines = () => @@ -2435,7 +2538,10 @@ describe("ROSI main window", () => { const copied = output.textContent.split("\n").slice(0, -1); const before = { lines: lines(), copied }; const bulk = Array.from({ length: 4100 }, (_, i) => `bulk line ${i}`); - window.rosiModules.ui.appendConsoleOutput(output, bulk.join("\n")); + window.__ROSI_E2E__.modules.ui.appendConsoleOutput( + output, + bulk.join("\n"), + ); const after = lines(); return { before, @@ -2476,7 +2582,7 @@ describe("ROSI main window", () => { "cleared console did not shrink the dock", ); await browser.execute( - (tab) => window.rosiModules.dock.selectTab(tab), + (tab) => window.__ROSI_E2E__.modules.dock.selectTab(tab), originalTab, ); record("console-log", { capped: result.count, firstKept: result.first }); @@ -2484,7 +2590,7 @@ describe("ROSI main window", () => { it("keeps Activity row actions as quiet icon buttons", async () => { await browser.execute(() => { - window.rosiModules.dock.selectTab("activity"); + window.__ROSI_E2E__.modules.dock.selectTab("activity"); document.activeElement?.blur(); }); await settle(); @@ -2557,7 +2663,9 @@ describe("ROSI main window", () => { }); it("runs each Activity row action", async () => { - await browser.execute(() => window.rosiModules.dock.selectTab("activity")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("activity"), + ); await settle(); const activity = (await api("getDownloadActivity")).data; const target = activity.find( @@ -2591,8 +2699,8 @@ describe("ROSI main window", () => { // Open folder: stub the bridge so the test does not open Finder. await browser.execute(() => { window.__rosiOpened = []; - window.__rosiOpenFileLocation = window.api.openFileLocation; - window.api.openFileLocation = async (filePath) => { + window.__rosiOpenFileLocation = window.__ROSI_E2E__.api.openFileLocation; + window.__ROSI_E2E__.api.openFileLocation = async (filePath) => { window.__rosiOpened.push(filePath); return { ok: true }; }; @@ -2603,7 +2711,7 @@ describe("ROSI main window", () => { ); await settle(300); const opened = await browser.execute(() => { - window.api.openFileLocation = window.__rosiOpenFileLocation; + window.__ROSI_E2E__.api.openFileLocation = window.__rosiOpenFileLocation; return window.__rosiOpened; }); assert.deepEqual( @@ -3074,17 +3182,17 @@ describe("ROSI main window", () => { ? "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", }); - window.api.checkDenoInstalled = async () => { + window.__ROSI_E2E__.api.checkDenoInstalled = async () => { if (how.check === "throw") throw new Error("lookup failed"); return false; }; - window.api.installDeno = async () => { + window.__ROSI_E2E__.api.installDeno = async () => { window.__rosiDeno.installs += 1; const next = how.installs.shift(); if (next === "fail") throw new Error("winget exploded"); return next === "cancel" ? { cancelled: true } : { success: true }; }; - window.api.openExternal = async (url) => { + window.__ROSI_E2E__.api.openExternal = async (url) => { window.__rosiDeno.external.push(url); }; }, mode); @@ -3291,7 +3399,10 @@ describe("ROSI main window", () => { }); }; const selectDock = (tab) => - browser.execute((name) => window.rosiModules.dock.selectTab(name), tab); + browser.execute( + (name) => window.__ROSI_E2E__.modules.dock.selectTab(name), + tab, + ); await resizeWindow(1200, 900); await typeUrl(""); @@ -3458,13 +3569,28 @@ describe("ROSI main window", () => { !defaults.sponsorblockRemove, "SponsorBlock change was not saved", ); - await browser.execute(() => - document - .querySelector( - '.settings-section-reset[data-reset-section="enhancements"]', - ) - .click(), - ); + const resetEnhancements = () => + browser.execute(() => + document + .querySelector( + '.settings-section-reset[data-reset-section="enhancements"]', + ) + .click(), + ); + // Reset asks first: Cancel must leave the changed values alone. + await resetEnhancements(); + await waitForModal(true, "section reset did not ask for confirmation"); + await clickModalButton("Cancel"); + await waitForModal(false, "Cancel did not close the reset prompt"); + assert.equal( + settingsOnDisk().embedMetadata, + !defaults.embedMetadata, + "Cancel changed the metadata setting", + ); + await resetEnhancements(); + await waitForModal(true, "section reset did not reopen the prompt"); + await clickModalButton("Reset section"); + await waitForModal(false, "confirmed reset did not close the prompt"); await waitForSavedSetting( "embedMetadata", defaults.embedMetadata, @@ -3655,12 +3781,19 @@ describe("ROSI main window", () => { ); await clickById("resetSettings"); modal = await waitForModal(true, "Reset All asked nothing the second time"); + const confirmedAt = Date.now(); await clickModalButton(modal.buttons.find((label) => /reset/i.test(label))); - await settle(300); + // The confirm runs after the modal's hide timer and the settings flush + // round trip, so wait for the bridge call itself instead of a fixed delay. + await browser.waitUntil( + async () => (await stubCalls("resetSettings")).length > 0, + { timeout: 10_000, interval: 50, timeoutMsg: "confirming did not reset" }, + ); + const resetMs = Date.now() - confirmedAt; const calls = await stubCalls("resetSettings"); await restoreApi(); assert.equal(calls.length, 1, "confirming did not reset"); - record("settings-reset-all", { prompt: modal.title }); + record("settings-reset-all", { prompt: modal.title, resetMs }); }); it("opens every help and support link at the right address", async () => { @@ -4095,7 +4228,9 @@ describe("ROSI main window", () => { it("runs the queue entirely from its controls", async () => { await api("clearQueue"); - await browser.execute(() => window.rosiModules.dock.selectTab("queue")); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("queue"), + ); const urls = [`${MEDIA}/clip-two.mp4?ui=1`, `${MEDIA}/clip-three.mp4?ui=1`]; const fillQueueInput = (text) => browser.execute((value) => { @@ -4187,6 +4322,69 @@ describe("ROSI main window", () => { record("queue-controls", { completed: urls.length, cancelled: 1 }); }); + it("splits a mixed paste through the backend and queues only the safe links", async () => { + await api("clearQueue"); + await browser.execute(() => + window.__ROSI_E2E__.modules.dock.selectTab("queue"), + ); + const kept = [ + `${MEDIA}/clip-two.mp4?paste=1`, + `${MEDIA}/clip-three.mp4?paste=1`, + ]; + // Private and local hosts and a non-http scheme must be refused. + const refused = [ + "http://192.168.1.10/private.mp4", + "http://localhost:8080/local.mp4", + "ftp://files.example.com/clip.mp4", + ]; + const mixed = [ + "# pasted from chat, comment lines are skipped", + `${kept[0]} ${refused[0]} please`, + `${kept[1]}#t=5 ${kept[0]}`, + `${refused[1]}\n${refused[2]}`, + ].join("\n"); + + const direct = await api("extractQueueUrls", mixed); + assert.equal(direct.ok, true, "extract_queue_urls refused the paste"); + assert.deepEqual(direct.data.urls, kept, "backend urls differ"); + assert.deepEqual(direct.data.rejected, refused, "backend rejected differ"); + assert.equal(direct.data.rejectedCount, refused.length); + const blank = await api("extractQueueUrls", "# only a note\n "); + assert.deepEqual(blank.data.urls, []); + const oversized = await api("extractQueueUrls", "a".repeat(256 * 1024 + 1)); + assert.equal(oversized.ok, false, "oversized paste was not refused"); + + // Paste into the real queue box and press Add. + await browser.execute((value) => { + const input = document.getElementById("queueUrlInput"); + input.value = value; + input.dispatchEvent(new Event("input", { bubbles: true })); + }, mixed); + await clickById("addToQueueBtn"); + await browser.waitUntil( + async () => (await api("getQueue")).length === kept.length, + { timeout: 10_000, timeoutMsg: "Add did not queue the safe links" }, + ); + const queued = (await api("getQueue")).map((item) => item.url); + assert.deepEqual(queued, kept, "queue differs from the safe links"); + const status = await browser.execute( + () => document.getElementById("queueStatusMessage")?.textContent ?? "", + ); + assert.match(status, /3 ignored as invalid\./, `status was: ${status}`); + record("queue-paste-extraction", { + queued: queued.length, + rejectedCount: direct.data.rejectedCount, + rejected: direct.data.rejected, + command: { + ok: direct.ok, + urls: direct.data.urls, + blank: blank.data.urls, + }, + oversizedRefused: oversized.ok === false, + }); + await api("clearQueue"); + }); + it("changes the save folder and asks every time when told to", async () => { const original = settingsOnDisk(); const picked = path.join(DOWNLOADS, "picked folder"); @@ -4349,6 +4547,7 @@ describe("ROSI main window", () => { const target = !before.notifications; // Flip a toggle (saved after a 300 ms debounce) and close immediately: // the close flow must flush it before the window goes away. + const closeAt = Date.now(); await browser.execute((checked) => { const toggle = document.getElementById("notificationsToggle"); toggle.checked = checked; @@ -4370,6 +4569,7 @@ describe("ROSI main window", () => { timeoutMsg: "main window never closed", }, ); + const closeMs = Date.now() - closeAt; const log = fs.readFileSync(logFile, "utf8"); assert.match( log, @@ -4380,6 +4580,6 @@ describe("ROSI main window", () => { fs.readFileSync(path.join(DATA_DIR, "settings.json"), "utf8"), ); assert.equal(after.notifications, target); - record("close-flow", { flushedSetting: "notifications" }); + record("close-flow", { flushedSetting: "notifications", closeMs }); }); }); diff --git a/e2e/specs/security-release-repairs.spec.js b/e2e/specs/security-release-checks.spec.js similarity index 99% rename from e2e/specs/security-release-repairs.spec.js rename to e2e/specs/security-release-checks.spec.js index 2160b769..45b03aed 100644 --- a/e2e/specs/security-release-repairs.spec.js +++ b/e2e/specs/security-release-checks.spec.js @@ -1140,7 +1140,7 @@ describe("ROSI URL boundary and release proof repairs", () => { (methodName, target, resultName) => { window[resultName] = { done: false, value: null }; Promise.resolve() - .then(() => window.api[methodName](target)) + .then(() => window.__ROSI_E2E__.api[methodName](target)) .then( (value) => { window[resultName].value = value; @@ -1210,7 +1210,7 @@ describe("ROSI URL boundary and release proof repairs", () => { (target, name) => { window[name] = { settled: false, ok: null, error: null, data: null }; Promise.resolve() - .then(() => window.api.getVideoInfo(target)) + .then(() => window.__ROSI_E2E__.api.getVideoInfo(target)) .then( (value) => { window[name] = { @@ -1317,7 +1317,7 @@ describe("ROSI URL boundary and release proof repairs", () => { (methodName, parameters, name) => { window[name] = { settled: false, ok: null, error: null }; Promise.resolve() - .then(() => window.api[methodName](...parameters)) + .then(() => window.__ROSI_E2E__.api[methodName](...parameters)) .then( (value) => { window[name] = { diff --git a/e2e/state-updater-repairs.failure-modes.md b/e2e/state-updater.failure-modes.md similarity index 73% rename from e2e/state-updater-repairs.failure-modes.md rename to e2e/state-updater.failure-modes.md index dd724148..7dafce66 100644 --- a/e2e/state-updater-repairs.failure-modes.md +++ b/e2e/state-updater.failure-modes.md @@ -1,4 +1,4 @@ -# State and updater repair failure modes +# State and updater failure modes Enumerate these cases before changing production code. The E2E spec covers renderer-visible contracts; temporary-directory native tests cover filesystem @@ -149,6 +149,45 @@ replacement rules that cannot be exercised safely against an installed app. attached to the same update identity. After removing the disk fault, retry must reach the installer path and retire the resource. +## F15: compact updater target (5.1 packaged macOS feed) + +Enumerated before the spec changes. A packaged build asks +`get_compact_updater_target` before `get_beta_updater_target`. The compact +target is `darwin[-beta]-{arch}-app-zst` whenever Tauri reports bundle type +`App`, which includes an unbundled macOS E2E binary. The legacy target is the +compact target without `-zst` (`darwin-beta-aarch64-app`). A stable compact +target has no legacy target and falls back to the default target. + +1. A compact feed check throws (no per-arch zstd archive, network error, or + manifest miss). The renderer makes exactly one more feed request, for the + legacy target, with no in-place retry of the compact target, and emits + `available` from that feed. Covered by `updater-compact-target-fallback`. +2. Both feed records are audited in order: the compact target marked as + thrown, then the legacy target marked as returned. A skipped compact request + or an extra retry must fail the scenario. Covered by + `updater-compact-target-fallback`. +3. The fallback warning names the compact target, the legacy target, and the + error. Logging must never change the check result. Covered by + `updater-compact-target-fallback`. +4. A compact check that throws after the check generation has moved on (channel + change or newer check) returns `null` with no legacy feed request and no feed + error. Not covered by a scenario yet; the guard is `isCurrent()` in + `checkFeed`. +5. The legacy target also throws: the error surfaces once as a `feed` error and + there is no third request. Not covered by a scenario yet. +6. A stable compact target (`darwin-aarch64-app-zst`) has no legacy target, so + the fallback requests the default target (`undefined`). Not covered by a + scenario yet. +7. The compact target must not replace the beta target in the beta-generation + fencing scenario (`updater-generation-retry`) or in Flatpak feed-only mode + (`flatpak-update-notice`). Both adapters return `null` for + `get_compact_updater_target`, so their targets stay + `darwin-beta-e2e-app`, `darwin-beta-round2-app` and `linux-beta-x86_64`, and + their existing target assertions still prove what they were written for. +8. The compact path is never requested on a Flatpak build by these specs, so + Flatpak refusals (no download, no install) stay proven only with the compact + target stubbed to `null`. Compact-on-Flatpak is not covered. + ## E2E-only native command access 1. A native E2E command present in the invoke handler but absent from the @@ -192,3 +231,28 @@ that fault is removed. renderable; absent, malformed, or remote values clear the old thumbnail. 3. A late preview response must not restore a thumbnail after the preview target changes or is cleared. + +## B3 default settings come from Rust only + +1. `get_settings` rejects at renderer startup. The renderer takes its defaults + from `get_default_settings`, never from a copy in `src/rosiEngine.ts`, and + shows the "Settings Error" modal. The E2E gate cannot inject an IPC rejection + into the startup path without a test hook, so this row is verified by the + code path and typecheck, not by the gate. +2. `get_settings` rejects and `get_default_settings` also rejects or returns + `ok: false`. The renderer uses only `{ settingsVersion, theme: 'system' }`, + the modal names the defaults failure, and the app still starts. Same + limitation as row 1. +3. `settings.json` is corrupt. `get_settings` answers with Rust defaults and no + IPC error, so the sidebar controls must show exactly the values that + `get_default_settings` returns, field by field. The scenario corrupts the + file, reloads the renderer so startup reads it again, and compares every + sidebar control with the live Rust defaults. +4. Defaults drift between Rust and the renderer. A renderer copy of the defaults + can disagree with `default_settings()` and only shows up when a load fails. + Because the renderer no longer holds a copy, a changed Rust default reaches + the sidebar without a renderer edit, and the scenario reads the Rust values + at run time instead of comparing against a fixed table. +5. Section reset and Reset All keep their existing paths: section reset reads + `loadDefaultSettings()` (Rust, cached), and Reset All is handled by the Rust + `reset_settings` command. Neither reads the startup fallback. diff --git a/e2e/state-updater-repairs.spec.js b/e2e/state-updater.spec.js similarity index 64% rename from e2e/state-updater-repairs.spec.js rename to e2e/state-updater.spec.js index 8ab7d28c..96529ac4 100644 --- a/e2e/state-updater-repairs.spec.js +++ b/e2e/state-updater.spec.js @@ -4,6 +4,12 @@ import assert from "node:assert/strict"; import { browser } from "@wdio/globals"; import { api, waitForAppReady } from "./helpers/app-bridge.js"; import { readListFile } from "./helpers/persisted.js"; +import { + captureUpdaterStatuses, + clickManualCheck, + setUpdateChannel, + startUpdaterFixture, +} from "./helpers/updater-engine-fixture.js"; const DATA_DIR = process.env.ROSI_E2E_DATA_DIR; const RESULT_PATH = process.env.ROSI_STATE_REPAIR_RESULTS; @@ -76,6 +82,25 @@ async function dismissModal(titleText, buttonText) { }, buttonText); } +async function engineInvoke(command, args) { + return browser.executeAsync( + (name, payload, done) => { + window.__TAURI__.core.invoke(name, payload).then( + (data) => done({ ok: true, data: data ?? null }), + (error) => done({ error: String(error) }), + ); + }, + command, + args, + ); +} + +async function engineProbe() { + const result = await engineInvoke("e2e_updater_probe"); + assert.ok(result.ok, JSON.stringify(result)); + return result.data; +} + describe("state and updater repair E2E", () => { before(waitForAppReady); @@ -84,11 +109,11 @@ describe("state and updater repair E2E", () => { const desiredTheme = initial.theme === "dark" ? "light" : "dark"; await browser.execute(() => { - window.auditOriginalSave = window.api.saveSettings; + window.auditOriginalSave = window.__ROSI_E2E__.api.saveSettings; window.auditSaveCalls = []; window.auditSaveHeld = false; let heldFirstResponse = false; - window.api.saveSettings = async (snapshot) => { + window.__ROSI_E2E__.api.saveSettings = async (snapshot) => { const copy = JSON.parse(JSON.stringify(snapshot)); const response = await window.auditOriginalSave(copy); window.auditSaveCalls.push(copy); @@ -150,7 +175,7 @@ describe("state and updater repair E2E", () => { await browser.execute((settings) => { if (window.auditReleaseSave) window.auditReleaseSave(); if (window.auditOriginalSave) - window.api.saveSettings = window.auditOriginalSave; + window.__ROSI_E2E__.api.saveSettings = window.auditOriginalSave; const theme = document.getElementById("themeSelect"); theme.value = settings.theme; theme.dispatchEvent(new Event("change", { bubbles: true })); @@ -176,14 +201,14 @@ describe("state and updater repair E2E", () => { await browser.execute( (invalidFfmpegPath, theme) => { - window.auditOriginalSettingsSave = window.api.saveSettings; - window.auditOriginalSettingsRead = window.api.getSettings; + window.auditOriginalSettingsSave = window.__ROSI_E2E__.api.saveSettings; + window.auditOriginalSettingsRead = window.__ROSI_E2E__.api.getSettings; window.auditInvalidSettingsSaveHeld = false; window.auditSettingsReadHeld = false; window.auditHoldSettingsRead = false; window.auditSettingsSaveSnapshot = null; window.auditSettingsSaveResponse = null; - window.api.saveSettings = async (settings) => { + window.__ROSI_E2E__.api.saveSettings = async (settings) => { const snapshot = JSON.parse(JSON.stringify(settings)); const response = await window.auditOriginalSettingsSave(snapshot); if (snapshot.ffmpegPath === invalidFfmpegPath) { @@ -196,7 +221,7 @@ describe("state and updater repair E2E", () => { } return response; }; - window.api.getSettings = async (...args) => { + window.__ROSI_E2E__.api.getSettings = async (...args) => { const settings = await window.auditOriginalSettingsRead(...args); if (window.auditHoldSettingsRead) { window.auditSettingsReadHeld = true; @@ -303,10 +328,12 @@ describe("state and updater repair E2E", () => { window.auditReleaseInvalidSettingsSave?.(); window.auditReleaseSettingsRead?.(); if (window.auditOriginalSettingsSave) { - window.api.saveSettings = window.auditOriginalSettingsSave; + window.__ROSI_E2E__.api.saveSettings = + window.auditOriginalSettingsSave; } if (window.auditOriginalSettingsRead) { - window.api.getSettings = window.auditOriginalSettingsRead; + window.__ROSI_E2E__.api.getSettings = + window.auditOriginalSettingsRead; } }); const restored = await api("saveSettings", original); @@ -322,14 +349,14 @@ describe("state and updater repair E2E", () => { const settingsFile = path.join(DATA_DIR, "settings.json"); await browser.execute(() => { - window.auditOriginalSaveSettings = window.api.saveSettings; + window.auditOriginalSaveSettings = window.__ROSI_E2E__.api.saveSettings; window.auditOriginalNotifySettingsFlushed = - window.api.notifySettingsFlushed; + window.__ROSI_E2E__.api.notifySettingsFlushed; window.auditLifecycleSaveCalls = []; window.auditLifecycleAckGenerations = []; window.auditSaveAStarted = false; window.auditSaveBStarted = false; - window.api.saveSettings = async (settings) => { + window.__ROSI_E2E__.api.saveSettings = async (settings) => { const snapshot = JSON.parse(JSON.stringify(settings)); window.auditLifecycleSaveCalls.push(snapshot); if (window.auditLifecycleSaveCalls.length === 1) { @@ -348,7 +375,7 @@ describe("state and updater repair E2E", () => { } return window.auditOriginalSaveSettings(snapshot); }; - window.api.notifySettingsFlushed = async (generation) => { + window.__ROSI_E2E__.api.notifySettingsFlushed = async (generation) => { window.auditLifecycleAckGenerations.push(generation); return window.__TAURI__.core.invoke("e2e_cancel_close_request", { generation, @@ -422,8 +449,8 @@ describe("state and updater repair E2E", () => { await browser.execute(() => { window.auditReleaseSaveA?.(); window.auditReleaseSaveB?.(); - window.api.saveSettings = window.auditOriginalSaveSettings; - window.api.notifySettingsFlushed = + window.__ROSI_E2E__.api.saveSettings = window.auditOriginalSaveSettings; + window.__ROSI_E2E__.api.notifySettingsFlushed = window.auditOriginalNotifySettingsFlushed; }); const restored = await api("saveSettings", original); @@ -454,7 +481,7 @@ describe("state and updater repair E2E", () => { { timeout: 10_000, timeoutMsg: "setup wizard did not open" }, ); await browser.execute(() => { - window.api.checkDenoInstalled = async () => false; + window.__ROSI_E2E__.api.checkDenoInstalled = async () => false; document.getElementById("wizard-skip").click(); }); await browser.waitUntil( @@ -557,9 +584,9 @@ describe("state and updater repair E2E", () => { await browser.execute( (responses) => { - window.auditOriginalGetVideoInfo = window.api.getVideoInfo; + window.auditOriginalGetVideoInfo = window.__ROSI_E2E__.api.getVideoInfo; window.auditPreviewCalls = []; - window.api.getVideoInfo = async (url) => { + window.__ROSI_E2E__.api.getVideoInfo = async (url) => { window.auditPreviewCalls.push(url); const data = url.endsWith("remote-thumb") ? responses.remote @@ -654,7 +681,8 @@ describe("state and updater repair E2E", () => { } finally { await browser.execute(() => { if (window.auditOriginalGetVideoInfo) { - window.api.getVideoInfo = window.auditOriginalGetVideoInfo; + window.__ROSI_E2E__.api.getVideoInfo = + window.auditOriginalGetVideoInfo; } document.getElementById("url").value = ""; document @@ -704,11 +732,12 @@ describe("state and updater repair E2E", () => { const slowUrl = `${MEDIA_URL}/slow.mp4?state-session=second`; await browser.execute(() => { - window.auditOriginalDownloadVideo = window.api.downloadVideo; - window.auditOriginalOpenFileLocation = window.api.openFileLocation; + window.auditOriginalDownloadVideo = window.__ROSI_E2E__.api.downloadVideo; + window.auditOriginalOpenFileLocation = + window.__ROSI_E2E__.api.openFileLocation; window.auditStartedSessionIds = []; window.auditStaleEventsDuringPendingStart = false; - window.api.downloadVideo = async (options) => { + window.__ROSI_E2E__.api.downloadVideo = async (options) => { const result = await window.auditOriginalDownloadVideo(options); if (result?.ok === true) { window.auditStartedSessionIds.push(result.data.sessionId ?? null); @@ -773,7 +802,7 @@ describe("state and updater repair E2E", () => { ); await browser.execute(() => { window.auditOpenedFilePath = null; - window.api.openFileLocation = async (filePath) => { + window.__ROSI_E2E__.api.openFileLocation = async (filePath) => { window.auditOpenedFilePath = filePath; return { ok: true, data: { opened: true } }; }; @@ -890,10 +919,12 @@ describe("state and updater repair E2E", () => { await api("cancelDownload"); await browser.execute(() => { if (window.auditOriginalDownloadVideo) { - window.api.downloadVideo = window.auditOriginalDownloadVideo; + window.__ROSI_E2E__.api.downloadVideo = + window.auditOriginalDownloadVideo; } if (window.auditOriginalOpenFileLocation) { - window.api.openFileLocation = window.auditOriginalOpenFileLocation; + window.__ROSI_E2E__.api.openFileLocation = + window.auditOriginalOpenFileLocation; } }); } @@ -903,336 +934,209 @@ describe("state and updater repair E2E", () => { assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); const queueFile = path.join(DATA_DIR, "download-queue.json"); const backupPath = path.join(DATA_DIR, "download-queue.backup.json"); + const platformOs = + process.platform === "darwin" + ? "darwin" + : process.platform === "linux" + ? "linux" + : "windows"; + const betaTarget = "darwin-beta-aarch64-app"; + const stableTarget = `${platformOs}-aarch64`; let priorBackup = null; - - await browser.execute(() => { - window.auditOriginalE2eUpdaterAdapter = - window.__ROSI_E2E__?.updaterAdapter; - window.auditUpdateChannel = "beta"; - window.auditFeedRecords = []; - window.auditDownloadCalls = []; - window.auditActiveTransfers = 0; - window.auditAttachedBytes = []; - window.auditDownloadReleases = {}; - window.auditClosedResources = []; - window.auditInstallCalls = []; - window.auditRestartCalls = 0; - window.auditUpdaterStatuses = []; - window.auditCheckResults = []; - window.auditInvokeCommands = []; - const makeUpdate = (rid, version, target) => ({ - rid, - currentVersion: "5.0.0-beta.2", - version, - date: null, - body: `Controlled ${version}`, - rawJson: {}, - target, - available: true, - downloadedBytes: undefined, - async close() { - window.auditClosedResources.push(this.rid); - if (this.downloadedBytes) { - await this.downloadedBytes.close(); - this.downloadedBytes = undefined; - } - }, - async download(onEvent) { - window.auditDownloadCalls.push(this.rid); - window.auditActiveTransfers += 1; - try { - const bytesRid = 8000 + (this.rid - 7000); - const attachBytes = () => { - window.auditAttachedBytes.push(bytesRid); - this.downloadedBytes = { - rid: bytesRid, - async close() { - window.auditClosedResources.push(bytesRid); - }, - }; - onEvent({ event: "Started", data: { contentLength: 1024 } }); - onEvent({ event: "Progress", data: { chunkLength: 1024 } }); - }; - if (this.rid === 7001 || this.rid === 7002) { - await new Promise((resolve) => { - window.auditDownloadReleases[this.rid] = () => { - attachBytes(); - resolve(); - }; - }); - } else { - attachBytes(); - } - } finally { - window.auditActiveTransfers -= 1; - } - }, - async install() { - const bytesRid = this.downloadedBytes?.rid; - window.auditInstallCalls.push({ - updateRid: this.rid, - bytesRid, - }); - await window.__TAURI__.core.invoke("e2e_updater_install_probe"); - this.downloadedBytes = undefined; - }, - }); - window.auditOriginalCheckForUpdates = window.api.checkForUpdates; - window.api.checkForUpdates = async (...args) => { - const result = await window.auditOriginalCheckForUpdates(...args); - window.auditCheckResults.push(result); - return result; - }; - window.auditUpdaterStatusCleanup = window.api.onUpdaterStatus((event) => - window.auditUpdaterStatuses.push(event), - ); - window.__ROSI_E2E__.updaterAdapter = { - invoke: async (command, args = {}) => { - window.auditInvokeCommands.push(command); - if (command === "get_settings") { - return { updateChannel: window.auditUpdateChannel }; - } - if (command === "is_packaged") return true; - if (command === "is_flatpak") return false; - if (command === "get_beta_updater_target") { - return "darwin-beta-e2e-app"; - } - if (command === "restart_app") { - window.auditRestartCalls += 1; - return undefined; - } - return window.__TAURI__.core.invoke(command, args); - }, - check: async (target) => { - const rid = 7000 + window.auditFeedRecords.length + 1; - const version = `5.0.0-beta.${window.auditFeedRecords.length + 3}`; - window.auditFeedRecords.push({ - rid, - version, - target: target ?? null, - }); - return makeUpdate(rid, version, target); - }, - }; - window.auditUpdaterAdapterInstalled = - typeof window.__ROSI_E2E__.updaterAdapter?.check === "function" && - typeof window.__ROSI_E2E__.updaterAdapter?.invoke === "function"; + // Released in finally too, so a failed step never leaves the held B + // response open (the server could not close and the engine stays busy). + let releaseB = () => {}; + await reloadRenderer(); + // The channel change rechecks in the background; set it before the feed. + await setUpdateChannel("beta"); + await browser.pause(1_500); + const fixture = await startUpdaterFixture({ + betaTarget, + disableCompact: true, }); - - const resolveDownload = async (rid, promiseName) => { - await browser.execute((updateRid) => { - window.auditDownloadReleases[updateRid]?.(); - }, rid); - return browser.executeAsync((name, done) => { - window[name].then( - (result) => done({ result }), - (error) => done({ error: String(error) }), - ); - }, promiseName); - }; - - const checkForAvailableUpdate = async () => { - const before = await browser.execute(() => ({ - checks: window.auditCheckResults.length, - feeds: window.auditFeedRecords.length, - statuses: window.auditUpdaterStatuses.length, - })); - await browser.execute(() => - document.getElementById("checkUpdateBtn").click(), - ); - await browser.waitUntil( - () => - browser.execute( - (count) => window.auditCheckResults.length > count, - before.checks, - ), + await captureUpdaterStatuses("auditGenerationStatuses"); + const feedRequests = () => + fixture.server.requests.filter((request) => + request.path.startsWith("/latest-"), + ).length; + const artifactRequests = () => + fixture.server.requests.filter((request) => + request.path.startsWith("/artifacts/"), + ).length; + const statusesNow = () => + browser.execute(() => window.auditGenerationStatuses.slice()); + const latestAvailable = async (version) => + (await statusesNow()) + .filter( + (event) => event.status === "available" && event.version === version, + ) + .at(-1); + const waitForAvailable = (version, after = 0) => + browser.waitUntil( + async () => + (await statusesNow()).filter( + (event) => + event.status === "available" && event.version === version, + ).length > after, { - timeout: 10_000, - timeoutMsg: "manual updater check did not settle", + timeout: 20_000, + interval: 100, + timeoutMsg: `update ${version} was not offered`, }, ); - const outcome = await browser.execute( - (counts) => ({ - result: window.auditCheckResults.at(-1), - feed: window.auditFeedRecords.slice(counts.feeds), - statuses: window.auditUpdaterStatuses.slice(counts.statuses), - updaterAdapterInstalled: window.auditUpdaterAdapterInstalled, - invokeCommands: window.auditInvokeCommands.slice(), - }), - before, - ); - assert.equal( - outcome.result, - null, - `controlled updater check returned ${JSON.stringify(outcome)}`, - ); - assert.ok( - outcome.feed.length > 0, - `controlled feed was not called: ${JSON.stringify(outcome)}`, - ); - assert.equal( - outcome.statuses.at(-1)?.status, - "available", - `controlled updater check did not emit available: ${JSON.stringify(outcome)}`, - ); - await dismissModal("Update Available", "Later"); - return outcome.feed.at(-1); - }; try { - const prior = fs.existsSync(backupPath) + priorBackup = fs.existsSync(backupPath) ? fs.readFileSync(backupPath) : null; - priorBackup = prior; - - const firstIdentity = await checkForAvailableUpdate(); - assert.equal(firstIdentity.target, "darwin-beta-e2e-app"); - - await browser.execute(() => { - window.auditFirstDownload = window.api.downloadUpdate(); + const probeBefore = await engineProbe(); + + // Generation A is offered and downloaded, then superseded by B. + fixture.server.publish({ + target: betaTarget, + version: "9.0.0-beta.1", + payload: Buffer.from("generation A payload"), + fileName: "ROSI-A.bin", }); - await browser.waitUntil( - () => browser.execute(() => window.auditDownloadCalls.length === 1), - { timeout: 10_000, timeoutMsg: "first updater download did not start" }, - ); - await api("checkForUpdates"); - assert.equal( - await browser.execute(() => window.auditFeedRecords.length), - 1, - "a check started a second feed request during download", - ); - const firstDownloadResult = await resolveDownload( - firstIdentity.rid, - "auditFirstDownload", - ); - assert.deepEqual(firstDownloadResult, { result: { success: true } }); + await clickManualCheck(); + await waitForAvailable("9.0.0-beta.1"); + const candidateA = await latestAvailable("9.0.0-beta.1"); + await dismissModal("Update Available", "Later"); + const downloadA = await engineInvoke("download_update", { + candidateId: candidateA.candidateId, + }); + assert.equal(downloadA.data?.success, true, JSON.stringify(downloadA)); await dismissModal("Update Ready", "Later"); - const staleIdentity = await checkForAvailableUpdate(); - await browser.execute(() => { - window.auditStaleDownload = window.api.downloadUpdate(); + // Generation B downloads behind a held response. + const gateB = new Promise((resolve) => { + releaseB = resolve; }); - await browser.waitUntil( - () => browser.execute(() => window.auditDownloadCalls.length === 2), - { - timeout: 10_000, - timeoutMsg: "replacement updater download did not start", - }, - ); - await browser.execute(() => window.api.cancelUpdateDownload()); - await dismissModal("Download Cancelled", "OK"); - const feedCountBeforeSettlement = await browser.execute( - () => window.auditFeedRecords.length, - ); - await browser.execute(() => { - window.auditUpdateChannel = "stable"; + fixture.server.publish({ + target: betaTarget, + version: "9.0.0-beta.2", + payload: Buffer.from("generation B payload"), + fileName: "ROSI-B.bin", + gate: gateB, + }); + await clickManualCheck(); + await waitForAvailable("9.0.0-beta.2"); + const candidateB = await latestAvailable("9.0.0-beta.2"); + await dismissModal("Update Available", "Later"); + await browser.execute((id) => { + window.auditDownloadBResult = undefined; + window.__TAURI__.core + .invoke("download_update", { candidateId: id }) + .then((data) => { + window.auditDownloadBResult = data; + }); + }, candidateB.candidateId); + await browser.waitUntil(() => artifactRequests() >= 2, { + timeout: 20_000, + interval: 100, + timeoutMsg: "B download did not start", }); - const beforeSettlement = await browser.execute( - (rid) => ({ - activeTransfers: window.auditActiveTransfers, - downloadCalls: window.auditDownloadCalls.length, - updateClosed: window.auditClosedResources.includes(rid), - bytesAttached: window.auditAttachedBytes.includes( - 8000 + (rid - 7000), - ), - }), - staleIdentity.rid, - ); - assert.equal(beforeSettlement.activeTransfers, 1); - assert.equal(beforeSettlement.downloadCalls, 2); - assert.equal(beforeSettlement.updateClosed, false); - assert.equal(beforeSettlement.bytesAttached, false); - - const blockedFeedCheck = await api("checkForUpdates"); - const blockedDownloadRetry = await api("downloadUpdate"); - const afterBlockedRequests = await browser.execute( - (rid) => ({ - feedCount: window.auditFeedRecords.length, - downloadCalls: window.auditDownloadCalls.length, - updateClosed: window.auditClosedResources.includes(rid), - activeTransfers: window.auditActiveTransfers, - }), - staleIdentity.rid, - ); - assert.equal(blockedFeedCheck, null); + // While B downloads: a second download is single-flight, and a check is refused. + const feedBeforeBlocked = feedRequests(); + const second = await engineInvoke("download_update", { + candidateId: candidateB.candidateId, + }); assert.equal( - blockedDownloadRetry.error, + second.data?.error, "A download is already in progress.", + JSON.stringify(second), ); - assert.equal(afterBlockedRequests.feedCount, feedCountBeforeSettlement); - assert.equal(afterBlockedRequests.downloadCalls, 2); - assert.equal(afterBlockedRequests.updateClosed, false); - assert.equal(afterBlockedRequests.activeTransfers, 1); - - const staleDownloadResult = await resolveDownload( - staleIdentity.rid, - "auditStaleDownload", + const blockedCheck = await engineInvoke("check_for_updates"); + assert.equal(blockedCheck.data, null, JSON.stringify(blockedCheck)); + assert.equal( + feedRequests(), + feedBeforeBlocked, + "a check during download requested a feed", + ); + + // Channel change and cancel while B is in flight; B settles after the cancel. + fixture.server.publish({ + target: stableTarget, + route: platformOs, + version: "9.0.0", + payload: Buffer.from("generation C payload"), + fileName: "ROSI-C.bin", + }); + await setUpdateChannel("stable"); + await engineInvoke("cancel_update_download"); + await dismissModal("Download Cancelled", "OK"); + // Compared in the page: WebDriver returns an undefined value as null. + assert.equal( + await browser.execute(() => window.auditDownloadBResult === undefined), + true, + "cancelled download resolved before it settled", ); - assert.deepEqual(staleDownloadResult, { result: { cancelled: true } }); - const staleBytesRid = 8000 + (staleIdentity.rid - 7000); + releaseB(); await browser.waitUntil( - () => - browser.execute( - (resources) => - window.auditActiveTransfers === 0 && - window.auditClosedResources.includes(resources.updateRid) && - window.auditClosedResources.includes(resources.bytesRid), - { updateRid: staleIdentity.rid, bytesRid: staleBytesRid }, - ), - { - timeout: 10_000, - timeoutMsg: - "settled stale download did not release its update and byte resources", - }, + () => browser.execute(() => window.auditDownloadBResult !== undefined), + { timeout: 20_000, interval: 100, timeoutMsg: "B did not settle" }, ); - const afterSettlement = await browser.execute( - (resources) => ({ - activeTransfers: window.auditActiveTransfers, - updateClosed: window.auditClosedResources.includes( - resources.updateRid, - ), - bytesClosed: window.auditClosedResources.includes(resources.bytesRid), - }), - { - updateRid: staleIdentity.rid, - bytesRid: staleBytesRid, - }, + assert.deepEqual( + await browser.execute(() => window.auditDownloadBResult), + { success: false, cancelled: true, error: null }, + ); + assert.ok( + !(await statusesNow()).some( + (event) => + event.status === "downloaded" && + event.candidateId === candidateB.candidateId, + ), + "the cancelled candidate was reported as downloaded", ); - assert.deepEqual(afterSettlement, { - activeTransfers: 0, - updateClosed: true, - bytesClosed: true, - }); - - const currentIdentity = await checkForAvailableUpdate(); - assert.equal(currentIdentity.target, null); - await api("installUpdate"); + // Generation C (stable target) is offered; install before download is refused. + await waitForAvailable("9.0.0"); + await dismissModal("Update Available", "Later"); + const countBeforeC = (await statusesNow()).filter( + (event) => event.status === "available" && event.version === "9.0.0", + ).length; + await clickManualCheck(); + await waitForAvailable("9.0.0", countBeforeC); + const candidateC = await latestAvailable("9.0.0"); + assert.equal(candidateC.isBeta, false); + await dismissModal("Update Available", "Later"); + const installProbeBefore = await engineProbe(); + await engineInvoke("install_update", { + candidateId: candidateC.candidateId, + }); await dismissModal("Update Error", "OK"); assert.equal( - await browser.execute(() => window.auditInstallCalls.length), + (await engineProbe()).installs - installProbeBefore.installs, 0, - "replacement update was installable without its own downloaded bytes", + "candidate was installed without its downloaded bytes", ); - await api("downloadUpdate"); - const currentBytesRid = 8000 + (currentIdentity.rid - 7000); - await api("clearQueue"); + // Download C, then fault the queue backup so the install's restart is refused. + const downloadC = await engineInvoke("download_update", { + candidateId: candidateC.candidateId, + }); + assert.equal(downloadC.data?.success, true, JSON.stringify(downloadC)); + await dismissModal("Update Ready", "Later"); + + await engineInvoke("clear_queue"); fs.rmSync(backupPath, { recursive: true, force: true }); fs.mkdirSync(backupPath); - const queued = await api("addToQueue", [ - "https://93.184.216.34/updater-install-backup-fault", - ]); - assert.equal(queued.ok, true, JSON.stringify(queued)); - const queue = await api("getQueue"); - const latestQueueId = queue.at(-1)?.id; + const queued = await engineInvoke("add_to_queue", { + urls: ["https://93.184.216.34/updater-install-backup-fault"], + options: null, + }); + // add_to_queue answers with the IpcResult wrapper ({ ok, data }). + assert.equal(queued.data?.data?.added, 1, JSON.stringify(queued)); + const queue = await engineInvoke("get_queue"); + const latestQueueId = queue.data.at(-1)?.id; assert.ok(latestQueueId); await browser.waitUntil( () => { try { - const onDisk = readListFile(queueFile); - return onDisk.some((item) => item.id === latestQueueId); + return readListFile(queueFile).some( + (item) => item.id === latestQueueId, + ); } catch { return false; } @@ -1245,73 +1149,47 @@ describe("state and updater repair E2E", () => { }, ); - await browser.execute(() => { - const restart = [ - ...document.querySelectorAll("#modal-buttons button"), - ].find((button) => button.textContent.trim() === "Restart Now"); - if (!restart) - throw new Error("Update Ready modal has no Restart Now action"); - restart.click(); + const probeBeforeRefusal = await engineProbe(); + await engineInvoke("install_update", { + candidateId: candidateC.candidateId, }); await dismissModal("Update Error", "OK"); - const firstInstall = await browser.execute( - () => window.auditInstallCalls[0], - ); - assert.equal(firstInstall.updateRid, currentIdentity.rid); - assert.equal(firstInstall.bytesRid, currentBytesRid); - assert.equal(await browser.execute(() => window.auditRestartCalls), 0); - const stillRunning = await api("getQueue"); - assert.ok(stillRunning.some((item) => item.id === latestQueueId)); + const afterRefusal = await engineProbe(); + // The flush refuses before the install, so no install is recorded. + assert.equal(afterRefusal.installs - probeBeforeRefusal.installs, 0); + assert.equal(afterRefusal.restarts - probeBeforeRefusal.restarts, 0); assert.ok( readListFile(queueFile).some((item) => item.id === latestQueueId), + "refused restart dropped the queued item", ); + // The retry installs the kept bytes once, then restarts. fs.rmSync(backupPath, { recursive: true, force: true }); if (priorBackup) fs.writeFileSync(backupPath, priorBackup); - await api("installUpdate"); - const installCalls = await browser.execute(() => - window.auditInstallCalls.slice(), - ); - assert.equal(installCalls.length, 2); - assert.deepEqual(installCalls[1], installCalls[0]); - assert.equal(await browser.execute(() => window.auditRestartCalls), 1); + const retry = await engineInvoke("install_update", { + candidateId: candidateC.candidateId, + }); + assert.ok(retry.ok, JSON.stringify(retry)); + await browser.pause(800); + const afterRetry = await engineProbe(); + // Measured from the refusal: the refused flush recorded no install. + assert.equal(afterRetry.installs - afterRefusal.installs, 1); + assert.equal(afterRetry.restarts - afterRefusal.restarts, 1); record("updater-generation-retry", { - feedTargets: await browser.execute(() => - window.auditFeedRecords.map((item) => item.target), - ), - activeDownloadCheckSuppressed: true, - cancelledIdentityRetainedUntilSettlement: - !beforeSettlement.updateClosed, - singleflightRetainedUntilSettlement: - blockedDownloadRetry.error === "A download is already in progress.", - staleDownloadResult, - staleUpdateReleasedAfterSettlement: afterSettlement.updateClosed, - staleBytesReleased: staleBytesRid, - stableTargetCheckedAfterSettlement: currentIdentity.target === null, - refusedInstallBytesRid: firstInstall.bytesRid, - retryInstallBytesRid: installCalls[1].bytesRid, - restartCalls: 1, - controlledUpdaterBoundary: "VITE_ROSI_E2E adapter", - sdkByteResourcesExercised: false, - nativeInstallPreflightExercised: true, - signedInstallationExercised: false, + feedTargets: fixture.server.requests + .map((request) => request.path) + .filter((item) => item.startsWith("/latest-")), + staleDownloadResult: { cancelled: true }, + singleflightRefused: second.data.error, + refusedInstallBytesKept: true, + retryRestarts: afterRetry.restarts - afterRefusal.restarts, + installsAfterRefusal: afterRefusal.installs - probeBefore.installs, }); } finally { + releaseB(); fs.rmSync(backupPath, { recursive: true, force: true }); if (priorBackup) fs.writeFileSync(backupPath, priorBackup); await browser.execute(() => { - window.auditUpdaterStatusCleanup?.(); - if (window.auditOriginalCheckForUpdates) { - window.api.checkForUpdates = window.auditOriginalCheckForUpdates; - } - if (window.__ROSI_E2E__) { - if (window.auditOriginalE2eUpdaterAdapter) { - window.__ROSI_E2E__.updaterAdapter = - window.auditOriginalE2eUpdaterAdapter; - } else { - delete window.__ROSI_E2E__.updaterAdapter; - } - } if ( document.getElementById("app-modal")?.classList.contains("active") ) { @@ -1323,12 +1201,11 @@ describe("state and updater repair E2E", () => { close?.click(); } }); - await api("clearQueue"); + await fixture.close(); + await engineInvoke("clear_queue"); await browser.waitUntil( () => { try { - // The backup keeps the previous generation, so it may still hold the - // queue that was just cleared; it only has to be a readable list. return ( readListFile(queueFile).length === 0 && Array.isArray(readListFile(backupPath)) @@ -1346,6 +1223,102 @@ describe("state and updater repair E2E", () => { } }); + it("falls back from the 5.1 compact macOS target to the legacy feed", async () => { + // A fresh renderer drops updater state left by the previous scenario. + await reloadRenderer(); + // The channel change rechecks in the background. Set it before the feed is + // configured and let that recheck finish, so the manual check is the only + // feed attempt that is asserted. + await setUpdateChannel("beta"); + await browser.pause(1_500); + const fixture = await startUpdaterFixture({ + compactTarget: "darwin-beta-aarch64-app-zst", + betaTarget: "darwin-beta-aarch64-app", + disableCompact: false, + }); + try { + // The compact feed is missing; only the legacy feed publishes an update. + fixture.server.respond("darwin-beta-aarch64-app-zst", 404); + fixture.server.publish({ + target: "darwin-beta-aarch64-app", + version: "9.0.0-beta.9", + payload: Buffer.from("controlled legacy payload"), + fileName: "legacy-app.tar.gz", + }); + await captureUpdaterStatuses("auditCompactStatuses"); + await clickManualCheck(); + await browser.waitUntil( + () => + browser.execute(() => + window.auditCompactStatuses.some((event) => + ["available", "not-available", "error"].includes(event.status), + ), + ), + { + timeout: 15_000, + timeoutMsg: "compact fallback check did not settle", + }, + ); + const statuses = await browser.execute(() => + window.auditCompactStatuses.slice(), + ); + // A channel change rechecks in the background, so the manual check can + // overlap it, and each check makes its own feed attempts. Every attempt + // must be the compact feed (404) followed by the legacy feed. + const feeds = fixture.server.requests + .map((request) => request.path) + .filter((item) => item.startsWith("/latest-")); + const attempts = []; + for (let index = 0; index < feeds.length; index += 2) { + attempts.push(feeds.slice(index, index + 2)); + } + assert.ok(attempts.length >= 1, "no compact fallback attempt was made"); + for (const attempt of attempts) { + assert.deepEqual( + attempt, + [ + "/latest-darwin-beta-aarch64-app-zst.json", + "/latest-darwin-beta-aarch64-app.json", + ], + `compact fallback feed requests were ${JSON.stringify(feeds)}`, + ); + } + assert.equal(feeds.length, attempts.length * 2, "unpaired feed request"); + const available = statuses.find((event) => event.status === "available"); + assert.ok( + available, + `compact fallback did not emit available: ${JSON.stringify(statuses)}`, + ); + assert.equal(available.version, "9.0.0-beta.9"); + assert.equal(available.isBeta, true); + const log = fs.readFileSync( + path.join(DATA_DIR, "logs", "rosi.log"), + "utf8", + ); + assert.ok( + log.includes( + "updater: darwin-beta-aarch64-app-zst check failed, falling back to darwin-beta-aarch64-app target", + ), + "compact fallback was not logged", + ); + await dismissModal("Update Available", "Later"); + record("updater-compact-target-fallback", { + feedTargets: feeds.map((item) => + item.replace(/^\/latest-|\.json$/g, ""), + ), + compactAttemptThrew: true, + legacyAttemptReturned: true, + availableVersion: available.version, + controlledBoundary: + "local signed update server (e2e_configure_updater)", + nativeCompactFeedExercised: true, + }); + } finally { + await fixture.close(); + await reloadRenderer(); + } + }); + it("refuses close and restart when the actual queue backup path is blocked", async () => { assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); const queueFile = path.join(DATA_DIR, "download-queue.json"); @@ -1450,9 +1423,9 @@ describe("state and updater repair E2E", () => { assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); const logFile = path.join(DATA_DIR, "logs", "rosi.log"); await browser.execute(() => { - window.auditOriginalSaveSettings = window.api.saveSettings; + window.auditOriginalSaveSettings = window.__ROSI_E2E__.api.saveSettings; window.auditSaveRelease = null; - window.api.saveSettings = async (settings) => { + window.__ROSI_E2E__.api.saveSettings = async (settings) => { await new Promise((resolve) => { window.auditSaveRelease = resolve; }); @@ -1514,7 +1487,7 @@ describe("state and updater repair E2E", () => { }); } finally { await browser.execute(() => { - window.api.saveSettings = window.auditOriginalSaveSettings; + window.__ROSI_E2E__.api.saveSettings = window.auditOriginalSaveSettings; const ok = [...document.querySelectorAll("#modal-buttons button")].find( (button) => button.textContent.trim() === "OK", ); @@ -1522,4 +1495,186 @@ describe("state and updater repair E2E", () => { }); } }); + + it("renders the Rust defaults when settings.json is corrupt at startup", async () => { + const settingsFile = path.join(DATA_DIR, "settings.json"); + const original = fs.readFileSync(settingsFile); + try { + const seeded = JSON.parse(original.toString("utf8")); + fs.writeFileSync( + settingsFile, + '{"theme":"purple","B3_DAMAGED_SETTINGS":', + ); + // A renderer reload runs startup again: get_settings reads the damaged + // file from disk and answers with the Rust defaults. + await reloadRenderer(); + + const defaults = (await api("getDefaultSettings")).data; + const loaded = await api("getSettings"); + const rendered = await browser.execute((controls) => { + const read = (control) => { + const element = document.getElementById(control.id); + if ( + !(element instanceof HTMLInputElement) && + !(element instanceof HTMLSelectElement) + ) + return null; + return control.kind === "checked" ? element.checked : element.value; + }; + return Object.fromEntries( + controls.map((control) => [control.id, read(control)]), + ); + }, SIDEBAR_CONTROLS); + + const expectedFor = (control, source) => { + const value = source[control.key]; + return control.id === "browserChoice" + ? String(value).toLowerCase() + : value; + }; + const differsFromSeed = SIDEBAR_CONTROLS.filter( + (control) => seeded[control.key] !== defaults[control.key], + ).map((control) => control.key); + assert.ok( + differsFromSeed.length > 0, + "seeded settings must differ from the defaults for this check to prove anything", + ); + for (const control of SIDEBAR_CONTROLS) { + const expected = expectedFor(control, defaults); + assert.equal( + rendered[control.id], + expected, + `sidebar ${control.id} shows ${JSON.stringify(rendered[control.id])}; get_default_settings ${control.key}=${JSON.stringify(defaults[control.key])}`, + ); + assert.equal( + expectedFor(control, loaded), + expected, + `get_settings ${control.key} differs from get_default_settings`, + ); + } + + // The recovery notice is recorded, not shown: WebDriver cannot dismiss a + // native alert (e2e/native-notices.failure-modes.md). get_settings reports + // it once per process, so it is found anywhere in the record. + const notices = await engineInvoke("e2e_native_notices"); + assert.ok(notices.ok, JSON.stringify(notices)); + const recovery = notices.data.find( + (notice) => notice.title === "ROSI Profile Recovery", + ); + assert.ok(recovery, JSON.stringify(notices.data)); + assert.equal(recovery.kind, "warning"); + + record("settings-corrupt-defaults", { + settingsFile: "settings.json", + recoveryNotice: recovery.message, + defaultsSource: "get_default_settings", + controlsCompared: SIDEBAR_CONTROLS.map((control) => control.id), + seededKeysDiffering: differsFromSeed, + }); + } finally { + fs.writeFileSync(settingsFile, original); + await reloadRenderer(); + } + }); + + it("keeps backend values the renderer did not change across a save", async () => { + assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); + const settingsFile = path.join(DATA_DIR, "settings.json"); + const original = fs.readFileSync(settingsFile); + const before = await api("getSettings"); + const desiredNotifications = !before.notifications; + const addedPreset = { + id: "e2e-backend-preset", + name: "E2E Backend Preset", + profile: "best-video", + }; + + try { + // The renderer keeps its loaded copy. The new preset exists only on disk. + const stored = JSON.parse(original.toString("utf8")); + stored.downloadPresets = [...(stored.downloadPresets ?? []), addedPreset]; + fs.writeFileSync(settingsFile, JSON.stringify(stored, null, 2)); + + await browser.execute(() => { + window.auditPatchOriginalSave = window.__ROSI_E2E__.api.saveSettings; + window.auditPatchKeys = []; + window.__ROSI_E2E__.api.saveSettings = async (patch) => { + const copy = JSON.parse(JSON.stringify(patch)); + window.auditPatchKeys.push(Object.keys(copy)); + return window.auditPatchOriginalSave(copy); + }; + }); + await browser.execute((value) => { + const toggle = document.getElementById("notificationsToggle"); + toggle.checked = value; + toggle.dispatchEvent(new Event("change", { bubbles: true })); + }, desiredNotifications); + await waitForStoredSetting( + "notifications", + desiredNotifications, + "unrelated notifications change was not saved", + ); + + const sentKeys = await browser.execute(() => window.auditPatchKeys); + const persisted = JSON.parse(fs.readFileSync(settingsFile, "utf8")); + const presetIds = persisted.downloadPresets.map((preset) => preset.id); + const rendererPresetIds = (await api("getSettings")).downloadPresets.map( + (preset) => preset.id, + ); + assert.ok(sentKeys.length > 0, "no settings save reached the backend"); + for (const keys of sentKeys) { + assert.deepEqual(keys, ["notifications"], "save sent unchanged keys"); + } + assert.ok( + presetIds.includes(addedPreset.id), + "backend preset was overwritten by the renderer's stale copy", + ); + assert.ok(rendererPresetIds.includes(addedPreset.id)); + assert.equal(persisted.notifications, desiredNotifications); + record("settings-patch-preserves-backend-values", { + addedPresetId: addedPreset.id, + changedKey: "notifications", + sentKeysPerSave: sentKeys, + storedNotifications: persisted.notifications, + storedPresetIds: presetIds, + rendererPresetIds, + }); + } finally { + await browser.execute(() => { + if (window.auditPatchOriginalSave) { + window.__ROSI_E2E__.api.saveSettings = window.auditPatchOriginalSave; + } + }); + fs.writeFileSync(settingsFile, original); + await reloadRenderer(); + } + }); }); + +// Sidebar controls and the settings key each one renders. Every value is +// compared with `get_default_settings` at run time, not with a fixed table. +const SIDEBAR_CONTROLS = [ + ["consoleToggle", "showConsoleOutput", "checked"], + ["keepOriginalToggle", "keepOriginalAfterConvert", "checked"], + ["hookBrowserToggle", "hookBrowser", "checked"], + ["browserChoice", "browserChoice", "value"], + ["convertToggle", "convertEnabled", "checked"], + ["convertFormat", "convertFormat", "value"], + ["gpuAccelerationToggle", "gpuAcceleration", "checked"], + ["gpuType", "gpuType", "value"], + ["ffmpegPathInput", "ffmpegPath", "value"], + ["upstreamProxyInput", "upstreamProxy", "value"], + ["animateBackgroundToggle", "animateBackground", "checked"], + ["themeSelect", "theme", "value"], + ["flatUiToggle", "flatUi", "checked"], + ["askDownloadLocationToggle", "askDownloadLocation", "checked"], + ["notificationsToggle", "notifications", "checked"], + ["taskbarProgressToggle", "showTaskbarProgress", "checked"], + ["checkUpdatesOnStartupToggle", "checkUpdatesOnStartup", "checked"], + ["updateChannelSelect", "updateChannel", "value"], + ["embedMetadataToggle", "embedMetadata", "checked"], + ["embedThumbnailToggle", "embedThumbnail", "checked"], + ["sponsorblockToggle", "sponsorblockRemove", "checked"], + ["writeSubtitlesToggle", "writeSubtitles", "checked"], + ["subtitleLangsInput", "subtitleLangs", "value"], +].map(([id, key, kind]) => ({ id, key, kind })); diff --git a/e2e/suites.json b/e2e/suites.json new file mode 100644 index 00000000..ae0e769f --- /dev/null +++ b/e2e/suites.json @@ -0,0 +1,808 @@ +{ + "schemaVersion": 1, + "selectionBoundary": "existing runner owner; selected groups expand to every scenario owned by selected passes", + "groups": [ + { + "id": "conversion", + "owners": ["main", "v5-fixes"], + "v5FixAreas": ["download-options", "typed-formats"] + }, + { + "id": "dock-ui", + "owners": ["main", "round2-renderer", "round3-renderer"], + "v5FixAreas": [] + }, + { + "id": "downloads", + "owners": [ + "audit4-repairs", + "main", + "process-repairs", + "round2-native", + "state-repairs", + "v5-fixes" + ], + "v5FixAreas": ["downloader"] + }, + { + "id": "legacy-import", + "owners": ["legacy-import"], + "v5FixAreas": [] + }, + { + "id": "lifecycle", + "owners": ["state-repairs", "v5-fixes"], + "v5FixAreas": ["queue-coordinator"] + }, + { + "id": "network-policy", + "owners": ["main", "security", "v5-fixes"], + "v5FixAreas": ["async-proxy", "network", "upstream-proxy"] + }, + { + "id": "onboarding", + "owners": ["main"], + "v5FixAreas": [] + }, + { + "id": "packaging", + "owners": ["main", "v5-fixes"], + "v5FixAreas": ["flatpak-updates"] + }, + { + "id": "persistence", + "owners": ["persistence", "v5-fixes"], + "v5FixAreas": ["persistence"] + }, + { + "id": "platform-verification", + "owners": ["audit-v5-beta2", "v5-fixes"], + "v5FixAreas": ["platform"] + }, + { + "id": "queue", + "owners": ["main", "offline-queue", "state-repairs", "v5-fixes"], + "v5FixAreas": ["queue-coordinator"] + }, + { + "id": "settings", + "owners": ["main", "state-repairs"], + "v5FixAreas": [] + }, + { + "id": "updater", + "owners": ["main", "state-repairs", "v5-fixes"], + "v5FixAreas": ["deno-installer", "updater-engine"] + }, + { + "id": "ui-polish", + "owners": ["v5-fixes"], + "v5FixAreas": ["ui-polish"] + } + ], + "owners": { + "legacy-import": { + "id": "legacy-import", + "kind": "webdriverio", + "entrypoint": "e2e/specs/legacy-import.spec.js" + }, + "main": { + "id": "main", + "kind": "webdriverio", + "entrypoint": "e2e/specs/main.spec.js" + }, + "offline-queue": { + "id": "offline-queue", + "kind": "webdriverio", + "entrypoint": "e2e/specs/security-release-offline-queue.spec.js" + }, + "security": { + "id": "security", + "kind": "webdriverio", + "entrypoint": "e2e/specs/security-release-checks.spec.js" + }, + "state-repairs": { + "id": "state-repairs", + "kind": "webdriverio", + "entrypoint": "e2e/state-updater.spec.js" + }, + "round2-renderer": { + "id": "round2-renderer", + "kind": "webdriverio", + "entrypoint": "e2e/renderer-updates.spec.js" + }, + "process-repairs": { + "id": "process-repairs", + "kind": "runner", + "entrypoint": "e2e/run-download-process.mjs" + }, + "round2-native": { + "id": "round2-native", + "kind": "runner", + "entrypoint": "e2e/native-downloads-run.mjs" + }, + "persistence": { + "id": "persistence", + "kind": "runner", + "entrypoint": "e2e/long-term-persistence-run.mjs" + }, + "audit4-repairs": { + "id": "audit4-repairs", + "kind": "runner", + "entrypoint": "e2e/download-session-run.mjs" + }, + "audit-v5-beta2": { + "id": "audit-v5-beta2", + "kind": "runner", + "entrypoint": "e2e/platform-probes/run-probes.mjs" + }, + "round3-renderer": { + "id": "round3-renderer", + "kind": "node-runner", + "entrypoint": "e2e/renderer-dom-checks/run.cjs" + }, + "v5-fixes": { + "id": "v5-fixes", + "kind": "dynamic-runner", + "entrypoint": "e2e/v5-fixes//run.mjs or WebdriverIO" + } + }, + "scenarios": [ + { + "name": "legacy-v4-import", + "feature": "legacy-import", + "owner": "legacy-import", + "allowedSkips": [] + }, + { + "name": "legacy-v4-corrupt-settings", + "feature": "legacy-import", + "owner": "legacy-import", + "allowedSkips": [] + }, + { + "name": "launch", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "legacy-v4-preserve", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-sidebar", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-persistence", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "download-profiles", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-layout", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "flat-ui-tokens", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "window-theme", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "no-overscroll", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "sidebar-glass", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "url-safety", + "feature": "network-policy", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "loopback-exception-and-thumbnail-data", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "loopback-download", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "proxy-delayed-http-response", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "proxy-cancels-streamed-response", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "private-dns-alias", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "dns-rebinding-connection-time", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "redirect-and-extractor-handoffs", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "verified-https-connect-proxy", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "untrusted-https-certificate-rejected", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "credential-bearing-urls", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "guarded-hls-fragments", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "bracketed-ipv6-classification", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "proxy-cancellation-closes-active-sockets", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "thumbnail-fetch-cancellation", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "dns-cancellation-reserved-ipc", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "proxy-rejects-unreviewed-pipelined-destination", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "bounded-dns-cancellation", + "feature": "network-policy", + "owner": "security", + "allowedSkips": [] + }, + { + "name": "persisted-offline-queue", + "feature": "queue", + "owner": "offline-queue", + "allowedSkips": [] + }, + { + "name": "manual-download", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "unicode-download", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "queue", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "cancel", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "conversion", + "feature": "conversion", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "audio-extract", + "feature": "conversion", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "gpu-detect", + "feature": "conversion", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "licenses", + "feature": "packaging", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "navigation-guard", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "preview", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "formats", + "feature": "conversion", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "merge-download", + "feature": "conversion", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "queue-management", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "queue-cancel", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "dock-tabs", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "webview-guard", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "link-drop", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "small-window", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "dock-empty", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "save-path", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "lucide-icons", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "status-icons", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "console-log", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "activity-actions", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "activity-action-clicks", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "theme-contrast", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "setup-wizard", + "feature": "onboarding", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "setup-wizard-skip", + "feature": "onboarding", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "setup-wizard-escape", + "feature": "onboarding", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "setup-wizard-small", + "feature": "onboarding", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "setup-wizard-deno", + "feature": "onboarding", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "browser-choice", + "feature": "onboarding", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "xdg-download-dir", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": ["darwin", "win32"] + }, + { + "name": "ui-screenshots", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "stats", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-search-reset", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-controls", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-reset-all", + "feature": "settings", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "settings-response-revision", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "settings-rejection-preserves-newer-field", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "settings-lifecycle-latest-revision", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "settings-captured-wizard-deno", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "compatible-profile-wording", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "settings-corrupt-defaults", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "settings-patch-preserves-backend-values", + "feature": "settings", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "guarded-preview-thumbnail", + "feature": "downloads", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "queue-latest-snapshot", + "feature": "queue", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "updater-generation-retry", + "feature": "updater", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "updater-compact-target-fallback", + "feature": "updater", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "queue-flush-backup-failure", + "feature": "queue", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "close-pending-timeout", + "feature": "lifecycle", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "download-session-isolation", + "feature": "downloads", + "owner": "state-repairs", + "allowedSkips": [] + }, + { + "name": "external-links", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "menu-actions", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "update-check", + "feature": "updater", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "dialogs", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "download-card-input", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "presets", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "custom-formats", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "playlist-range", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "embed-extras", + "feature": "downloads", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "queue-controls", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "queue-paste-extraction", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "save-location", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "notifications", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "download-again-quickly", + "feature": "queue", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "download-process-repairs", + "feature": "downloads", + "owner": "process-repairs", + "allowedSkips": ["win32"] + }, + { + "name": "activity-clear", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "close-flow", + "feature": "dock-ui", + "owner": "main", + "allowedSkips": [] + }, + { + "name": "round2-renderer", + "feature": "dock-ui", + "owner": "round2-renderer", + "allowedSkips": [] + }, + { + "name": "round2-native", + "feature": "downloads", + "owner": "round2-native", + "allowedSkips": [] + }, + { + "name": "long-term-persistence", + "feature": "persistence", + "owner": "persistence", + "allowedSkips": [] + }, + { + "name": "audit3-native-targeted", + "feature": "downloads", + "owner": "process-repairs", + "allowedSkips": ["win32"] + }, + { + "name": "audit4-repairs", + "feature": "downloads", + "owner": "audit4-repairs", + "allowedSkips": [] + }, + { + "name": "audit-v5-beta2", + "feature": "platform-verification", + "owner": "audit-v5-beta2", + "allowedSkips": ["linux", "win32"] + }, + { + "name": "round3-renderer-repairs", + "feature": "dock-ui", + "owner": "round3-renderer", + "allowedSkips": [] + } + ], + "dynamicV5Fixes": { + "owner": "v5-fixes", + "groupAreas": { + "downloads": ["downloader"], + "queue": ["queue-coordinator"], + "conversion": ["download-options", "typed-formats"], + "network-policy": ["async-proxy", "network", "upstream-proxy"], + "persistence": ["persistence"], + "updater": ["deno-installer", "updater-engine"], + "packaging": ["flatpak-updates"], + "platform-verification": ["platform"], + "ui-polish": ["ui-polish"] + } + } +} diff --git a/e2e/updater-zst.failure-modes.md b/e2e/updater-zst.failure-modes.md new file mode 100644 index 00000000..6f66105c --- /dev/null +++ b/e2e/updater-zst.failure-modes.md @@ -0,0 +1,83 @@ +# Compact macOS updater (per-arch `.app.tar.zst`) failure modes + +Enumerated before implementation. Each case names the layer that must catch it. +`scripts/e2e-updater-zst.mjs` exercises the pipeline end to end and writes +`e2e/artifacts/updater-zst-report.json`. + +## Z01: archive decoding (vendored updater plugin) + +1. A truncated `.tar.zst` download must fail extraction. The live app must + stay untouched and the update must stay retryable. +2. A frame whose window exceeds 2^27 bytes (for example, compressed with + `--long=31`) must be rejected rather than allocating an unbounded window. +3. A decompression bomb (small archive, huge tar payload) must stop at the + decompressed-byte cap. +4. Garbage after the last zstd frame, or a tar stream without both end + blocks, must be rejected the same way the AppImage reader rejects it. +5. A gzip `.app.tar.gz` must still extract. Old and new feeds can both reach + a new client. +6. Unknown leading bytes (neither gzip nor zstd magic) must fail with an + invalid-format error, never be fed to a decoder. +7. Every existing tar member rule (confinement, hard links, symlink targets, + directory collisions) must apply to zstd archives unchanged. + +## Z02: staged bundle contents + +1. A zstd archive whose app lacks a sidecar, or whose identity differs, must + be refused by the existing completeness and identity checks. +2. A per-arch bundle for the wrong architecture must never be offered: the + feed key carries the arch, and the client asks for its host target. +3. An arm64-only app later moved to an Intel Mac will not launch. This is + accepted and documented; recovery is the universal DMG. +4. A bundle whose executable or sidecars do not support the host architecture + (for example, an arm64-only bundle on an Intel Mac, or an x86_64-only bundle + on native Apple Silicon) must be rejected before live app replacement or + backup retirement, while a translated x86_64 process under Rosetta 2 accepts + both `aarch64` and `x86_64` bundles. + +## Z03: client target selection and fallback + +1. A packaged macOS app asks for `darwin-{arch}-app-zst` (stable) or + `darwin-beta-{arch}-app-zst` (beta). +2. A translated process on Apple Silicon (Rosetta) requests the native `aarch64` + target so that updates automatically migrate to native arm64 execution. +3. If the compact feed is missing or lacks the key (a release published + without zst artifacts), the check must fall back to the legacy target and + still find the update. The endpoint configuration must not mask a missing + compact feed with an installed-version manifest. +4. A compact feed that exists and reports no newer version must not trigger + the fallback. +5. Clients on 5.0.x never request the compact key and keep receiving the + universal `.app.tar.gz`. +6. Windows, Linux, and Flatpak targets must not change. + +Scope: since 5.1.0-beta.1 the Rust engine (`src-tauri/src/updater.rs`) picks the +target, so Z03.1, Z03.3 (stable), Z03.4 and Z03.6 run against the real engine and a +local signed feed in `e2e/v5-fixes/updater-engine` (`updater-engine-compact-routing`, +row G34 of that area's failure modes). The beta half of Z03.3 is +`updater-compact-target-fallback` in `e2e/state-updater.spec.js`. This script keeps +the checks that need release archives or old clients: Z03.2 (the Rosetta +`sysctl.proc_translated` probe and the per-arch Mach-O matrix) and Z03.5 (the real +5.0.2 renderer from git). The Rust target selection itself (bundle-type gate, +Rosetta sysctl, arch) must still be confirmed on real macOS hardware. + +## Z04: release pipeline + +1. Per-arch builds also produce an arch-less `ROSI.app.tar.gz`. It must never + be collected as the universal updater archive, because then an Intel Mac + could receive an arm64 bundle. +2. The packer must refuse a missing or stale per-arch `.app.tar.gz`, a tar + whose top-level entry is not `ROSI.app`, and a bundle whose main executable + is not thin for the expected arch. +3. The repacked `.tar.zst` must hold the exact tar bytes from Tauri's archive + (round-trip check), so the code signature and staple inside survive. +4. A missing or mismatched `.sig` must stop manifest generation. +5. Stable and beta compact manifests must be generated, validated, listed in + the required beta-manifest set, and pass the live validator. +6. Compact entries must never become the generic `darwin-{arch}` or + `darwin-beta-{arch}[-app]` fallback for old clients. +7. Per-arch input bundles in release builds must have valid Developer ID code + signatures, stapled notarization tickets, and pass Gatekeeper assessment + (`spctl`) before being repacked. +8. The E2E test harness supports a strict `--require-real-builds` mode to prevent + synthetic bundles from being accepted as final release proof. diff --git a/e2e/v5-fixes/async-proxy/async-proxy.spec.js b/e2e/v5-fixes/async-proxy/async-proxy.spec.js new file mode 100644 index 00000000..1127216f --- /dev/null +++ b/e2e/v5-fixes/async-proxy/async-proxy.spec.js @@ -0,0 +1,174 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { browser } from "@wdio/globals"; +import { waitForAppReady } from "../../helpers/app-bridge.js"; + +const resultsDirectory = process.env.ROSI_V5_ASYNC_PROXY_RESULTS_DIR; +const observations = []; +let outcome; + +function record(name, details) { + observations.push({ name, ...details }); + if (!resultsDirectory) return; + fs.mkdirSync(resultsDirectory, { recursive: true }); + fs.writeFileSync( + path.join(resultsDirectory, "observations.json"), + `${JSON.stringify(observations, null, 2)}\n`, + ); +} + +async function invokeProbe() { + const encoded = await browser.executeAsync((done) => { + window.__TAURI__.core.invoke("e2e_network_pipelining_probe").then( + (value) => done(JSON.stringify({ ok: true, value })), + (error) => done(JSON.stringify({ ok: false, error: String(error) })), + ); + }); + return JSON.parse(encoded); +} + +function probeSection(name) { + assert.ok(outcome?.ok, JSON.stringify(outcome)); + const section = outcome.value?.asyncProxy?.[name]; + assert.ok(section, `probe omitted asyncProxy.${name}`); + return section; +} + +describe("V5 bounded asynchronous proxy", () => { + before(async () => { + await waitForAppReady(); + outcome = await invokeProbe(); + }); + + it("serves at least 256 simultaneous vetted CONNECT tunnels", async () => { + const capacity = outcome.value?.asyncProxy?.capacity; + const invariantPassed = + outcome.ok === true && + capacity?.requestedTunnels === 256 && + capacity?.activeLimit >= 256 && + capacity?.activeAtCapacity >= 256 && + capacity?.peakActiveTunnels >= 256 && + capacity?.peakActiveConnections >= 256; + record("active-tunnel-capacity", { + probeError: outcome.ok ? null : outcome.error, + capacity: capacity ?? null, + invariantPassed, + }); + assert.ok(outcome.ok, JSON.stringify(outcome)); + assert.equal(capacity?.requestedTunnels, 256); + assert.ok(capacity?.activeLimit >= 256); + assert.ok(capacity?.activeAtCapacity >= 256); + assert.ok(capacity?.peakActiveTunnels >= 256); + assert.ok(capacity?.peakActiveConnections >= 256); + }); + + it("caps pending admissions and rejects overload with HTTP 503", async () => { + const capacity = outcome.value?.asyncProxy?.capacity; + const invariantPassed = + outcome.ok === true && + capacity?.pendingLimit > 0 && + capacity?.pendingHighWater === capacity?.pendingLimit && + capacity?.overloadStatus === 503 && + capacity?.overloadRejections >= 1; + record("bounded-overload", { + probeError: outcome.ok ? null : outcome.error, + pendingLimit: capacity?.pendingLimit ?? null, + pendingHighWater: capacity?.pendingHighWater ?? null, + overloadStatus: capacity?.overloadStatus ?? null, + overloadRejections: capacity?.overloadRejections ?? null, + invariantPassed, + }); + assert.ok(outcome.ok, JSON.stringify(outcome)); + assert.ok(capacity?.pendingLimit > 0); + assert.equal(capacity?.pendingHighWater, capacity?.pendingLimit); + assert.equal(capacity?.overloadStatus, 503); + assert.ok(capacity?.overloadRejections >= 1); + }); + + it("cancels active and queued proxy sockets and upstream tunnels", async () => { + const cancellation = probeSection("cancellation"); + const invariantPassed = + cancellation.activeConnectionsAfterCancel === 0 && + cancellation.activeTunnelsAfterCancel === 0 && + cancellation.pendingAdmissionsAfterCancel === 0 && + cancellation.closedClientSockets === cancellation.expectedClientSockets && + cancellation.expectedClientSockets === 384 && + cancellation.closedOriginSockets === cancellation.expectedOriginSockets && + cancellation.expectedOriginSockets === 256 && + cancellation.elapsedMs <= 5000; + record("operation-cancellation-cleanup", { cancellation, invariantPassed }); + assert.equal(cancellation.activeConnectionsAfterCancel, 0); + assert.equal(cancellation.activeTunnelsAfterCancel, 0); + assert.equal(cancellation.pendingAdmissionsAfterCancel, 0); + assert.equal(cancellation.closedClientSockets, 384); + assert.equal(cancellation.closedOriginSockets, 256); + assert.ok(cancellation.elapsedMs <= 5000); + }); + + it("drops its listener and active client without blocking", async () => { + const drop = probeSection("drop"); + const invariantPassed = + drop.activeConnectionsAfterDrop === 0 && + drop.closedClientSocket === true && + drop.elapsedMs <= 5000; + record("guard-drop-cleanup", { drop, invariantPassed }); + assert.equal(drop.activeConnectionsAfterDrop, 0); + assert.equal(drop.closedClientSocket, true); + assert.ok(drop.elapsedMs <= 5000); + }); + + it("keeps an idle tunnel from waking the relay", async () => { + const idle = probeSection("idle"); + const invariantPassed = + idle.openTunnels === 1 && + idle.activeTunnelsAtWindowEnd === 1 && + idle.windowMs === 5000 && + idle.idleWakeups <= 2; + record("idle-tunnel-wakeups", { idle, invariantPassed }); + assert.equal(idle.openTunnels, 1); + assert.equal(idle.activeTunnelsAtWindowEnd, 1); + assert.equal(idle.windowMs, 5000); + assert.ok( + idle.idleWakeups <= 2, + `idle tunnel woke the relay ${idle.idleWakeups} times`, + ); + }); + + it("retains HTTP pipeline blocking and bounded DNS resolution", async () => { + const requests = outcome.value?.requests ?? []; + const dns = outcome.value?.dnsResolution; + const invariantPassed = + outcome.ok === true && + outcome.value?.responseStatus === 200 && + requests.length === 1 && + requests.every((request) => request.includes("/first")) && + outcome.value?.secondTargetForwarded === false && + dns?.maxActiveWorkers <= dns?.workerLimit && + dns?.workerLimit === 4 && + dns?.queueHighWater <= dns?.queueLimit && + dns?.queueLimit === 16 && + dns?.batchesAtQueueLimit === 3 && + dns?.pendingAfterDrain === 0 && + dns?.activeAfterDrain === 0; + record("framing-and-dns-regression", { + probeError: outcome.ok ? null : outcome.error, + requestCount: requests.length, + responseStatus: outcome.value?.responseStatus ?? null, + secondTargetForwarded: outcome.value?.secondTargetForwarded ?? null, + dns: dns ?? null, + invariantPassed, + }); + assert.ok(outcome.ok, JSON.stringify(outcome)); + assert.equal(outcome.value?.responseStatus, 200); + assert.equal(requests.length, 1); + assert.ok(requests.every((request) => request.includes("/first"))); + assert.equal(outcome.value?.secondTargetForwarded, false); + assert.equal(dns?.workerLimit, 4); + assert.ok(dns?.maxActiveWorkers <= dns?.workerLimit); + assert.ok(dns?.queueHighWater <= dns?.queueLimit); + assert.equal(dns?.batchesAtQueueLimit, 3); + assert.equal(dns?.pendingAfterDrain, 0); + assert.equal(dns?.activeAfterDrain, 0); + }); +}); diff --git a/e2e/v5-fixes/async-proxy/failure-modes.md b/e2e/v5-fixes/async-proxy/failure-modes.md new file mode 100644 index 00000000..94c1d03f --- /dev/null +++ b/e2e/v5-fixes/async-proxy/failure-modes.md @@ -0,0 +1,155 @@ +# Async proxy failure modes + +This inventory was written before the implementation change. The existing +`NetworkSecurityGuard` synchronous constructors and credential-bearing proxy +URL remain the caller contract. The listener and every client operation must +run on Tauri's Tokio runtime, with admission and DNS work bounded independently. + +1. **The caller has no ambient Tokio handle.** A synchronous downloader or + metadata caller must still start the guard through Tauri's shared runtime; + startup failures are returned and never cause an unproxied network fallback. +2. **Many long-lived CONNECT tunnels consume all service capacity.** At least + 256 active connections must be serviceable without a fixed 32-worker queue. +3. **A burst exceeds connection capacity.** Pending admission is capped; excess + clients receive an explicit bounded 503 response and do not create tasks or + retain sockets indefinitely. +4. **An owner cancels or drops its guard with idle or active connections.** The + listener, pending sockets, client tasks, and both tunnel endpoints are + cancelled and released promptly. +5. **Cancellation happens during DNS, connect, header parsing, body copying, + or upstream-proxy negotiation.** The caller wait returns without accumulating + unabortable DNS jobs or leaving connection tasks behind. +6. **A DNS storm outlives its callers.** Resolver workers and queued lookups + stay independently bounded; dropping a wait removes queued work and running + system lookups remain capped by the fixed resolver worker count. +7. **A peer sends a partial or oversized request header or an idle tunnel.** + Header limits and idle deadlines terminate it without busy polling or a + blocked runtime worker. +8. **Authentication is missing, duplicated, or incorrect.** Exactly one valid + proxy credential is required before resolving or connecting to a destination. +9. **A hostname resolves to a private, mixed public/private, or changing + address set.** Reject unsafe answer sets and connect directly only to the + exact addresses that were vetted; retain IPv4 and IPv6 classification. +10. **An upstream HTTP proxy is configured.** Preserve its existing CONNECT and + absolute-form behavior while still vetting the requested destination; do + not apply destination policy to the user's upstream itself. +11. **A CONNECT request arrives with tunnel payload already buffered after its + headers, or the upstream sends payload with its success headers.** Preserve + both byte sequences exactly and relay both directions with TCP half-close + behavior. +12. **A half-close is mistaken for full connection closure.** Forward the + remaining response in the opposite direction until both sides end or the + idle deadline expires. +13. **Plain HTTP uses ambiguous or excessive framing.** Enforce header and body + byte limits, reject conflicting or repeated framing headers, copy only the + framed body, and never forward a pipelined second request on the connection. +14. **Backpressure or slow peers stall a connection.** Async reads/writes and + per-operation deadlines must not block unrelated connections or grow + buffers without a limit. +15. **A task exits through I/O error, cancellation, or panic.** Admission slots + and active-socket ownership are released, and shutdown still drains or + aborts all tracked tasks. +16. **The new capacity probe is missing, synthetic, or only checks configuration + constants.** The existing `e2e_network_pipelining_probe` must exercise real + loopback traffic and report observed 256-tunnel service, overload rejection, + cancellation cleanup, and unchanged pipeline blocking in repeatable JSON. +17. **A rejected client still has unread input when the server closes.** Writing + the 503, calling `shutdown()`, and dropping the socket makes the BSD stack + send RST, which can discard the response before the client reads it (the + overload probe saw `os error 54`). After the write, read and discard client + bytes until EOF, 64 KiB, or 250 ms, whichever comes first, then drop. The + probe keeps its strict `read_to_end`. +18. **A slow or never-closing client holds the drain open.** The 250 ms deadline + is fixed when the drain starts and is not extended by arriving bytes. Loop + drains (`Proxy Busy`, `Proxy Admission Timeout`) run as tracked tasks, so a + stalled client never blocks accept or admission, and cancellation or guard + drop aborts them with the other handlers. +19. **A client sends more than the drain cap.** Reading stops at 64 KiB through a + fixed 4 KiB scratch buffer, so no buffer grows past the cap. Bytes beyond the + cap may still reset the connection; that is accepted because the 503 is + already written and the peer is misbehaving. +20. **Drains multiply under a flood of rejected clients.** Loop drains take a + permit from a fixed `MAX_DRAINING_REJECTS` semaphore without waiting. When no + permit is free the socket is dropped immediately, as before this change. + Handler drains run inside an existing active-connection permit and are + bounded by the same deadline. +21. **The "Proxy Admission Timeout" 503 keeps its pending admission during the + drain.** The expired entry's `PendingMetricGuard` is released before the 503 + is written, so `pending_admissions` never counts a client that is only being + drained. The 128-entry pending cap is unaffected because expired entries have + already left the queue. +22. **The DNS capacity probe reads a transient queue state.** The resolver + enforces its queue limit under the pool lock, but a worker pop can remove one + queued job between two probe samples. Under full-gate load worker wakeups are + late: the pool rejected five callers at the limit (`rejectedDelta=5`), yet the + sampled `maxQueueLen` stayed at 15, so the probe never saw 16 queued beside 4 + active workers and failed with `reachedCapacity=false`. The probe must hold its + own lookups at a gate until 4 workers are busy, the queue is observed at 16, + and the overflow callers are rejected, so each capacity state it checks is + stable. A missed sample must not be able to fail a correct pool. +23. **A held probe lookup outlives the probe.** The gate reopens on every exit + path from a batch, including a failed spawn or a failed capacity check, and a + held lookup returns after a fixed fail-safe timeout, so the process-wide + resolver cannot stay blocked. Ordinary `rosi-dns-delay-` lookups used by other + specs keep their existing synthetic delay and are not gated. +24. **A cancel is signalled before a relay task subscribes.** Download and metadata + cancellation are `watch` channels whose value stays `true`. A receiver + created or cloned after the signal reads `true` at once, so + `ProxyShared::cancelled()` checks the current value before it awaits a + change and returns without waiting. A guard started after cancel fails with + the existing cancelled error. +25. **The cancellation sender is dropped without signalling.** The session that + owns the sender ends without cancelling the operation. `changed()` returns an + error, which can never become a cancel, so the wait stays pending on the + shutdown signal alone. No busy loop starts, and guard drop still stops every + task. +26. **A blocking resolver caller needs the current value.** Blocking code reads + the cancellation synchronously with `borrow()` (guard start and `is_cancelled`), + never through a poll loop on the relay side. The blocking DNS probe keeps its + per-caller `AtomicBool`, which it sets itself, and the blocking + `is_public_http_destination` path is unchanged. The blocking DNS caller still + checks its oneshot reply every 25 ms (`try_recv` then sleep). That loop runs on + a plain thread, not in the relay, so the 25 ms bound is kept deliberately; the + relay itself never polls. +27. **A DNS oneshot sender is dropped without a reply.** A worker panic or pool + stop drops the job, and the waiting relay task receives a closed error. It + returns `None` (the existing "Destination Blocked" 403), never hangs, and + leaves no queue entry behind. +28. **The resolver queue is full.** `enqueue` still rejects under the pool lock + before any oneshot is created. The caller gets `None` at once, and the + rejected count the DNS probe checks still increments. +29. **Cancellation arrives during DNS.** Guard cancel or drop aborts the client + task that waits on the reply. Dropping `PendingDnsJob` removes a queued job, + while a running lookup finishes and its reply is discarded. The answer-count + cap (more than 32 answers) and `ip_policy` vetting run unchanged. +30. **An idle tunnel wakes the relay with nothing to do.** With one open idle + tunnel, the relay task and the listener wake only for I/O, cancellation, or + the idle deadline. A debug counter records any other wake, and the probe + requires at most 2 such wakes in a 5 s window (the old 25 ms poll would give + about 200 in that window). +31. **A metadata caller cancels through the process-utility sender.** `process_util` + holds the reservation cancellation as a `watch` sender, and metadata guards + subscribe to it like downloads. A cancelled stalled thumbnail therefore wakes + its relay at once and closes its fixture socket within the scenario's 5 s. + No `AtomicBool` cancel source feeds a relay any more. + +The native E2E probe is the acceptance mechanism for concurrency and cleanup. +Rust unit tests must not be added after implementation; existing network and +upstream-proxy E2E specs remain required regression coverage. + +## Repeatable probe evidence + +The new `asyncProxy` object is added to the existing +`e2e_network_pipelining_probe` result; it does not add a Tauri command. Its +`capacity` section reports `requestedTunnels`, `activeLimit`, +`activeAtCapacity`, `peakActiveTunnels`, `pendingLimit`, `pendingHighWater`, +`overloadStatus`, and `overloadRejections`. The `cancellation` section reports +`activeConnectionsAfterCancel`, `activeTunnelsAfterCancel`, +`pendingAdmissionsAfterCancel`, `closedClientSockets`, +`expectedClientSockets`, `closedOriginSockets`, `expectedOriginSockets`, and +`elapsedMs`. The `drop` section reports `activeConnectionsAfterDrop`, +`closedClientSocket`, and `elapsedMs`. Acceptance requires 256 simultaneously +open tunnels, a full bounded pending queue followed by HTTP 503, and zero +active/pending resources after both operation cancellation and guard drop. The +same result records the existing pipelining check so the new runner proves +that the second request was never forwarded. diff --git a/e2e/v5-fixes/async-proxy/run.mjs b/e2e/v5-fixes/async-proxy/run.mjs new file mode 100644 index 00000000..abb6009e --- /dev/null +++ b/e2e/v5-fixes/async-proxy/run.mjs @@ -0,0 +1,141 @@ +import crypto from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; +import { spawnSync } from "node:child_process"; +import { + createE2eProfile, + e2eBinaryPath, + e2eStampPath, + REPO_ROOT, +} from "../../helpers/profile.js"; + +const relativeArtifactRoot = path.join( + process.env.ROSI_E2E_ARTIFACT_DIR ?? + path.join(REPO_ROOT, "e2e", "artifacts", "v5-fixes-async-proxy"), + `${new Date().toISOString().replace(/[:.]/g, "-")}-${process.pid}`, +); +const artifactRoot = path.isAbsolute(relativeArtifactRoot) + ? relativeArtifactRoot + : path.join(REPO_ROOT, relativeArtifactRoot); +const binary = process.env.ROSI_E2E_BINARY ?? e2eBinaryPath(); +const stamp = e2eStampPath(); +if ( + !fs.existsSync(binary) || + !fs.existsSync(stamp) || + fs.statSync(stamp).mtimeMs < fs.statSync(binary).mtimeMs +) { + throw new Error( + "Build a fresh E2E binary with npm run test:e2e before running this suite.", + ); +} + +const hash = (bytes) => crypto.createHash("sha256").update(bytes).digest("hex"); +const sourceFiles = [ + "e2e/v5-fixes/async-proxy/run.mjs", + "e2e/v5-fixes/async-proxy/async-proxy.spec.js", + "e2e/v5-fixes/async-proxy/failure-modes.md", + "src-tauri/src/network_security.rs", + "src-tauri/src/network_security_async.rs", + "src-tauri/Cargo.toml", + "src-tauri/Cargo.lock", +]; +fs.mkdirSync(artifactRoot, { recursive: true }); +for (const source of sourceFiles) { + const from = path.join(REPO_ROOT, source); + if (!fs.existsSync(from)) continue; + const destination = path.join(artifactRoot, "sources", source); + fs.mkdirSync(path.dirname(destination), { recursive: true }); + fs.copyFileSync(from, destination); +} +const patch = spawnSync("git", ["diff", "--binary", "HEAD"], { + cwd: REPO_ROOT, + encoding: "buffer", +}); +if (patch.error || patch.status !== 0) { + throw new Error( + `Could not capture the working-tree diff: ${patch.error?.message ?? patch.stderr?.toString() ?? patch.status}`, + ); +} +fs.writeFileSync(path.join(artifactRoot, "working-tree.patch"), patch.stdout); + +const profile = createE2eProfile(); +const resultsDirectory = path.join(artifactRoot, "app"); +const result = spawnSync( + process.execPath, + [ + path.join(REPO_ROOT, "node_modules", "@wdio", "cli", "bin", "wdio.js"), + "run", + "e2e/wdio.conf.js", + ], + { + cwd: REPO_ROOT, + env: { + ...process.env, + ...profile.env, + ROSI_E2E_BINARY: binary, + ROSI_E2E_DOWNLOADS: profile.downloads, + ROSI_E2E_XDG_DOWNLOADS: profile.xdgDownloads, + ROSI_E2E_PROFILE: profile.profileDir, + ROSI_E2E_SPECS: "./v5-fixes/async-proxy/async-proxy.spec.js", + ROSI_V5_ASYNC_PROXY_RESULTS_DIR: resultsDirectory, + }, + encoding: "utf8", + windowsHide: true, + timeout: 300_000, + maxBuffer: 16 * 1024 * 1024, + }, +); +const launchError = result.error + ? { + message: result.error.message, + code: result.error.code ?? null, + } + : null; +fs.writeFileSync( + path.join(artifactRoot, "wdio.log"), + `${result.stdout ?? ""}${result.stderr ?? ""}${result.error ? `\n[WDIO launcher error]\n${result.error.stack ?? result.error.message}\n` : ""}`, +); + +let observations = []; +try { + observations = JSON.parse( + fs.readFileSync(path.join(resultsDirectory, "observations.json"), "utf8"), + ); +} catch {} +const body = { + suite: "v5-fixes-async-proxy", + startedAt: new Date().toISOString(), + exitStatus: result.status, + signal: result.signal ?? null, + launchError, + binarySha256: hash(fs.readFileSync(binary)), + workingTreeDiffSha256: hash( + fs.readFileSync(path.join(artifactRoot, "working-tree.patch")), + ), + sources: sourceFiles + .filter((source) => + fs.existsSync(path.join(artifactRoot, "sources", source)), + ) + .map((source) => ({ + path: source, + sha256: hash(fs.readFileSync(path.join(artifactRoot, "sources", source))), + })), + observations, +}; +const passed = + result.status === 0 && + observations.length === 6 && + observations.every((observation) => observation.invariantPassed === true); +const report = { + ...body, + passed, + reportSha256: hash(Buffer.from(JSON.stringify(body, null, 2))), +}; +fs.writeFileSync( + path.join(artifactRoot, "report.json"), + `${JSON.stringify(report, null, 2)}\n`, +); +console.log( + `V5 async proxy evidence: ${path.join(artifactRoot, "report.json")}`, +); +if (!passed) process.exitCode = 1; diff --git a/e2e/v5-fixes/deno-installer/deno-installer.spec.js b/e2e/v5-fixes/deno-installer/deno-installer.spec.js index 503a9eff..ee0b1cfd 100644 --- a/e2e/v5-fixes/deno-installer/deno-installer.spec.js +++ b/e2e/v5-fixes/deno-installer/deno-installer.spec.js @@ -72,7 +72,9 @@ async function reloadRenderer() { await browser.waitUntil( async () => browser.execute( - () => Boolean(window.__ROSI_E2E__?.ready) && Boolean(window.api), + () => + Boolean(window.__ROSI_E2E__?.ready) && + Boolean(window.__ROSI_E2E__?.api), ), { timeout: 60_000, timeoutMsg: "renderer did not come back after reload" }, ); @@ -82,7 +84,7 @@ async function reloadRenderer() { function stubOpenExternal() { return browser.execute(() => { window.__rosiDenoInstaller = { external: [] }; - window.api.openExternal = async (url) => { + window.__ROSI_E2E__.api.openExternal = async (url) => { window.__rosiDenoInstaller.external.push(url); }; }); diff --git a/e2e/v5-fixes/download-options/download-options.spec.js b/e2e/v5-fixes/download-options/download-options.spec.js new file mode 100644 index 00000000..ab0756a7 --- /dev/null +++ b/e2e/v5-fixes/download-options/download-options.spec.js @@ -0,0 +1,648 @@ +import assert from "node:assert/strict"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "../../helpers/app-bridge.js"; + +const MEDIA = process.env.ROSI_E2E_MEDIA_URL; +const DOWNLOADS = process.env.ROSI_E2E_DOWNLOADS; + +function withoutUrl(options) { + const copy = { ...options }; + delete copy.url; + return copy; +} + +/** Request snapshots differ only by the URL and output folder they were started with. */ +function omitUrlAndOutput(request) { + const copy = { ...request }; + delete copy.url; + delete copy.outputPath; + return copy; +} + +/** Reload the page and wait until its bridge and preset list are installed. */ +async function reloadApp() { + await browser.refresh(); + await browser.waitUntil( + () => + browser.execute( + () => + document.readyState === "complete" && + typeof window.__ROSI_E2E__?.api?.resolveDownloadOptions === + "function" && + typeof window.__ROSI_E2E__?.api?.addToQueue === "function", + ), + { + timeout: 60_000, + timeoutMsg: "reloaded page never installed window.__ROSI_E2E__.api", + }, + ); + await waitForAppReady(); +} + +/** Record the renderer's own resolve and queue calls, not the harness's `api()` calls. */ +async function armRendererRecorder() { + await browser.execute(() => { + window.__b2Calls = []; + window.__b2Armed = false; + for (const name of [ + "resolveDownloadOptions", + "resolvePresetOptions", + "addToQueue", + ]) { + const original = window.__ROSI_E2E__.api[name]; + window.__ROSI_E2E__.api[name] = (...args) => { + if (window.__b2Armed) { + window.__b2Calls.push({ + name, + args: JSON.parse(JSON.stringify(args)), + }); + } + return original(...args); + }; + } + }); +} + +async function recordRendererCalls(action) { + await browser.execute(() => { + window.__b2Calls = []; + window.__b2Armed = true; + }); + await action(); +} + +async function takeRendererCalls() { + return browser.execute(() => { + window.__b2Armed = false; + const calls = window.__b2Calls ?? []; + window.__b2Calls = []; + return calls; + }); +} + +async function selectAndApplyPreset(presetId, presetName) { + // After a reload the preset list is rebuilt during startup, so wait for the option. + await browser.waitUntil( + () => + browser.execute( + (id) => + [ + ...(document.getElementById("downloadPresetSelect")?.options ?? []), + ].some((option) => option.value === id), + presetId, + ), + { timeout: 20_000, timeoutMsg: "preset option never appeared" }, + ); + await browser.execute((id) => { + const select = document.getElementById("downloadPresetSelect"); + select.value = id; + select.dispatchEvent(new Event("change", { bubbles: true })); + document.getElementById("applyPresetBtn").click(); + }, presetId); + let lastStatus = ""; + try { + await browser.waitUntil( + async () => { + lastStatus = await presetStatus(); + return lastStatus.includes(`Applied ${presetName}.`); + }, + { timeout: 20_000, timeoutMsg: "preset was not applied" }, + ); + } catch (error) { + throw new Error( + `preset was not applied; last status: "${lastStatus}" (${error.message})`, + ); + } +} + +async function presetStatus() { + return browser.execute( + () => document.getElementById("presetStatus")?.textContent ?? "", + ); +} + +async function setUrlField(value) { + await browser.execute((text) => { + const input = document.getElementById("url"); + input.value = text; + input.dispatchEvent(new Event("input", { bubbles: true })); + }, value); +} + +async function summaryState() { + return browser.execute(() => { + const summary = document.getElementById("downloadOutputSummary"); + return { + state: summary?.dataset.state ?? "", + text: summary?.textContent ?? "", + }; + }); +} + +async function waitForSummary(fragment) { + await browser.waitUntil( + async () => { + const summary = await summaryState(); + return summary.state === "resolved" && summary.text.includes(fragment); + }, + { + timeout: 20_000, + timeoutMsg: `effective-options summary never showed ${fragment}`, + }, + ); + return summaryState(); +} + +async function waitForSettingOnDisk(key, value) { + await browser.waitUntil( + async () => (await api("getSettings"))[key] === value, + { timeout: 10_000, timeoutMsg: `${key} was not saved as ${value}` }, + ); +} + +describe("shared download option resolution", () => { + let originalSettings; + + before(async () => { + await waitForAppReady(); + originalSettings = await api("getSettings"); + assert.ok(MEDIA, "ROSI_E2E_MEDIA_URL is required"); + assert.ok(DOWNLOADS, "ROSI_E2E_DOWNLOADS is required"); + }); + + after(async () => { + await api("clearQueue"); + if (originalSettings) { + const restored = await api("saveSettings", originalSettings); + assert.equal(restored.ok, true, restored.error?.message); + } + }); + + it("shares preset and explicit-option precedence across manual and queue requests", async () => { + await api("clearQueue"); + const preset = { + id: "resolver-e2e", + name: "Resolver E2E", + profile: "audio", + bestQuality: true, + audioOnly: true, + audioFormat: "flac", + convertEnabled: true, + convertFormat: "m4a", + keepOriginalAfterConvert: false, + gpuAcceleration: true, + gpuType: "nvidia", + playlist: { mode: "all" }, + }; + const saved = await api("saveSettings", { + downloadMode: "custom", + advancedOptions: true, + bestQuality: false, + audioOnly: false, + convertEnabled: false, + gpuAcceleration: false, + downloadPresets: [preset], + }); + assert.equal(saved.ok, true, saved.error?.message); + + const url = `${MEDIA}/clip-one.mp4?resolver=manual-${Date.now()}`; + const explicit = { + url, + outputPath: DOWNLOADS, + presetId: preset.id, + profile: "compatible", + bestQuality: false, + audioOnly: false, + convertEnabled: false, + gpuAcceleration: false, + playlist: { mode: "current" }, + }; + const manual = await api("resolveDownloadOptions", explicit); + assert.equal(manual.ok, true, manual.error?.message); + assert.equal(manual.data.profile, "compatible"); + assert.equal(manual.data.bestQuality, false); + assert.equal(manual.data.audioOnly, false); + assert.equal(manual.data.convertEnabled, false); + assert.equal(manual.data.gpuAcceleration, false); + assert.equal(manual.data.convertFormat, "m4a"); + assert.equal(manual.data.keepOriginal, false); + assert.equal(manual.data.audioOutputFormat, "flac"); + assert.deepEqual(manual.data.playlist, { mode: "current" }); + + const nullsInherit = await api("resolveDownloadOptions", { + ...explicit, + profile: null, + bestQuality: null, + audioOnly: null, + convertEnabled: null, + gpuAcceleration: null, + playlist: null, + }); + assert.equal(nullsInherit.ok, true, nullsInherit.error?.message); + assert.equal(nullsInherit.data.profile, "audio"); + assert.equal(nullsInherit.data.bestQuality, true); + assert.equal(nullsInherit.data.audioOnly, true); + assert.equal(nullsInherit.data.convertEnabled, true); + assert.equal(nullsInherit.data.gpuAcceleration, true); + assert.deepEqual(nullsInherit.data.playlist, { mode: "all" }); + + const queuedUrl = `${MEDIA}/clip-one.mp4?resolver=queue-${Date.now()}`; + const queued = await api("addToQueue", [queuedUrl], { + ...withoutUrl(explicit), + outputPath: DOWNLOADS, + }); + assert.equal(queued.ok, true, queued.error?.message); + assert.equal(queued.data.added, 1); + const queue = await api("getQueue"); + const queuedItem = queue.find((item) => item.url === queuedUrl); + assert.ok( + queuedItem?.request, + "queue admission did not save a request snapshot", + ); + assert.deepEqual( + { ...manual.data, url: queuedUrl }, + queuedItem.request, + "queue and manual resolution produced different request options", + ); + + const profileUrl = `${MEDIA}/clip-one.mp4?resolver=profile-${Date.now()}`; + const profileOnly = { + url: profileUrl, + outputPath: DOWNLOADS, + profile: "audio", + }; + const profileManual = await api("resolveDownloadOptions", profileOnly); + assert.equal(profileManual.ok, true, profileManual.error?.message); + assert.equal(profileManual.data.audioOnly, true); + assert.equal(profileManual.data.bestQuality, false); + assert.equal(profileManual.data.advancedOptions, false); + const profileQueueUrl = `${MEDIA}/clip-one.mp4?resolver=profile-queue-${Date.now()}`; + const profileQueued = await api("addToQueue", [profileQueueUrl], { + outputPath: DOWNLOADS, + profile: "audio", + }); + assert.equal(profileQueued.ok, true, profileQueued.error?.message); + const afterProfileQueue = await api("getQueue"); + const profileItem = afterProfileQueue.find( + (item) => item.url === profileQueueUrl, + ); + assert.ok( + profileItem?.request, + "profile-only queue request was not captured", + ); + assert.deepEqual( + { ...profileManual.data, url: profileQueueUrl }, + profileItem.request, + "profile-only manual and queue resolution diverged", + ); + }); + + it("keeps an enqueue-time request on replay and returns validation envelopes", async () => { + await api("clearQueue"); + const preset = { + id: "resolver-replay", + name: "Resolver Replay", + profile: "best-video", + bestQuality: true, + audioOnly: false, + convertEnabled: false, + gpuAcceleration: false, + playlist: { mode: "current" }, + }; + const saved = await api("saveSettings", { + downloadMode: "compatible", + bestQuality: false, + audioOnly: false, + downloadPresets: [preset], + }); + assert.equal(saved.ok, true, saved.error?.message); + + const url = `${MEDIA}/missing-resolver-replay-${Date.now()}.mp4`; + const added = await api("addToQueue", [url], { + outputPath: DOWNLOADS, + presetId: preset.id, + convertEnabled: false, + }); + assert.equal(added.ok, true, added.error?.message); + const before = await api("getQueue"); + const queued = before.find((item) => item.url === url); + assert.ok(queued?.request, "queue item lacks its resolved options"); + const snapshot = queued.request; + + const changed = await api("saveSettings", { + downloadMode: "custom", + advancedOptions: true, + bestQuality: false, + audioOnly: true, + convertEnabled: true, + gpuAcceleration: true, + downloadPresets: [ + { ...preset, audioFormatId: "999", videoFormat: "888" }, + ], + }); + assert.equal(changed.ok, true, changed.error?.message); + const started = await api("startQueue"); + assert.equal(started.ok, true, started.error?.message); + await browser.waitUntil( + async () => { + const queue = await api("getQueue"); + const item = queue.find((candidate) => candidate.url === url); + return ( + item && ["completed", "failed", "cancelled"].includes(item.status) + ); + }, + { + timeout: 120_000, + interval: 500, + timeoutMsg: "queued replay did not finish", + }, + ); + const after = await api("getQueue"); + const replayed = after.find((item) => item.url === url); + assert.deepEqual( + replayed.request, + snapshot, + "queue request changed while replaying", + ); + + await browser.waitUntil( + async () => { + const activity = await api("getDownloadActivity"); + return activity.ok && activity.data.some((entry) => entry.url === url); + }, + { + timeout: 20_000, + interval: 250, + timeoutMsg: "queue replay was not recorded", + }, + ); + const activity = await api("getDownloadActivity"); + const completion = activity.data.find((entry) => entry.url === url); + assert.deepEqual( + completion.request, + snapshot, + "replayed completion used settings changed after queue admission", + ); + assert.equal( + completion.request.audioFormat ?? null, + snapshot.audioFormat ?? null, + "a later preset format ID was added to the stored snapshot", + ); + assert.equal( + completion.request.videoFormat ?? null, + snapshot.videoFormat ?? null, + "a later preset video format was added to the stored snapshot", + ); + + const wrongResolverShape = await api( + "resolveDownloadOptions", + "wrong-shape", + ); + assert.equal(wrongResolverShape.ok, false); + assert.equal(wrongResolverShape.error.code, "VALIDATION_ERROR"); + const wrongDownloadShape = await api("downloadVideo", "wrong-shape"); + assert.equal(wrongDownloadShape.ok, false); + assert.equal(wrongDownloadShape.error.code, "VALIDATION_ERROR"); + const wrongQueueShape = await api("addToQueue", "wrong-shape"); + assert.equal(wrongQueueShape.ok, false); + assert.equal(wrongQueueShape.error.code, "VALIDATION_ERROR"); + const rejectedPath = await api("resolveDownloadOptions", { + url: `${MEDIA}/clip-one.mp4`, + outputPath: "relative-output", + }); + assert.equal(rejectedPath.ok, false); + assert.equal(rejectedPath.error.code, "INVALID_PATH"); + }); + it("applied preset follows the stored value in Rust, not the renderer copy", async () => { + await api("clearQueue"); + const stored = { + id: "resolver-applied", + name: "Resolver Applied", + profile: "best-video", + bestQuality: true, + audioOnly: false, + convertEnabled: true, + convertFormat: "m4a", + keepOriginalAfterConvert: false, + gpuAcceleration: false, + }; + const saved = await api("saveSettings", { + downloadMode: "compatible", + bestQuality: false, + audioOnly: false, + advancedOptions: false, + convertEnabled: false, + convertFormat: "mp4", + keepOriginalAfterConvert: true, + gpuAcceleration: false, + // A folder prompt would block the queue add, so save to the E2E folder. + askDownloadLocation: false, + downloadFolder: DOWNLOADS, + downloadPresets: [stored], + }); + assert.equal(saved.ok, true, saved.error?.message); + + // Reload so the renderer's preset cache holds the stored preset before Apply. + await reloadApp(); + await armRendererRecorder(); + await selectAndApplyPreset(stored.id, stored.name); + await waitForSettingOnDisk("convertFormat", "m4a"); + // Apply saved the copied values, so the renderer's next save carries no preset edit. + + // The stored preset changes after Apply. The controls still show the copied m4a. + const edited = await api("saveSettings", { + downloadPresets: [{ ...stored, convertFormat: "mp3" }], + }); + assert.equal(edited.ok, true, edited.error?.message); + + const url = `${MEDIA}/clip-one.mp4?resolver=applied-${Date.now()}`; + await recordRendererCalls(async () => { + await setUrlField(url); + await waitForSummary("Convert to MP3"); + }); + const [summaryCall] = (await takeRendererCalls()) + .filter( + (call) => + call.name === "resolveDownloadOptions" && call.args[0]?.url === url, + ) + .slice(-1); + assert.ok(summaryCall, "summary did not resolve through the backend"); + const summaryKeys = Object.keys(summaryCall.args[0]).filter( + (key) => !["url", "outputPath"].includes(key), + ); + assert.deepEqual( + summaryKeys, + ["presetId"], + "summary sent copied preset values as explicit overrides", + ); + const summaryText = (await summaryState()).text; + assert.doesNotMatch( + summaryText, + /Convert to M4A/, + "summary showed the cached copy", + ); + const summaryRust = await api( + "resolveDownloadOptions", + summaryCall.args[0], + ); + assert.equal(summaryRust.ok, true, summaryRust.error?.message); + assert.equal(summaryRust.data.convertFormat, "mp3"); + assert.equal(summaryRust.data.presetName, stored.name); + + // Saving from the renderer would write its cached preset list back over the + // stored edit, so reload before starting, then apply the edited preset. + await reloadApp(); + await armRendererRecorder(); + await selectAndApplyPreset(stored.id, stored.name); + await waitForSettingOnDisk("convertFormat", "mp3"); + + // The queue add goes through the renderer's builder. The stored request is + // checked below against Rust's own resolution, so copied values would show. + await setUrlField(url); + await waitForSummary("Convert to MP3"); + await browser.execute((queueUrl) => { + document.getElementById("queueUrlInput").value = queueUrl; + document.getElementById("addToQueueBtn").click(); + }, url); + + await browser.waitUntil( + async () => { + const queue = await api("getQueue"); + return queue.some((item) => item.url === url && item.request); + }, + { + timeout: 20_000, + interval: 250, + timeoutMsg: "queue item was not stored", + }, + ); + const queue = await api("getQueue"); + const queued = queue.find((item) => item.url === url); + const queueRust = await api("resolveDownloadOptions", { + presetId: stored.id, + url, + }); + assert.equal(queueRust.ok, true, queueRust.error?.message); + assert.deepEqual( + queued.request, + queueRust.data, + "queued request differs from resolve_download_options for the same request", + ); + assert.equal(queued.request.convertFormat, "mp3"); + assert.equal(queued.request.presetName, stored.name); + assert.deepEqual( + omitUrlAndOutput(queued.request), + omitUrlAndOutput(summaryRust.data), + "summary and queued request disagree", + ); + }); + + it("preset preview takes no URL and shows backend values", async () => { + await api("clearQueue"); + const stored = { + id: "resolver-preview", + name: "Resolver Preview", + profile: "best-video", + bestQuality: true, + audioOnly: false, + convertEnabled: true, + convertFormat: "m4a", + keepOriginalAfterConvert: false, + gpuAcceleration: false, + }; + const saved = await api("saveSettings", { + downloadMode: "compatible", + bestQuality: false, + audioOnly: false, + advancedOptions: false, + convertEnabled: false, + convertFormat: "mp4", + keepOriginalAfterConvert: true, + gpuAcceleration: false, + askDownloadLocation: false, + downloadFolder: DOWNLOADS, + downloadPresets: [stored], + }); + assert.equal(saved.ok, true, saved.error?.message); + + await reloadApp(); + await armRendererRecorder(); + await recordRendererCalls(() => + selectAndApplyPreset(stored.id, stored.name), + ); + const calls = await takeRendererCalls(); + const previews = calls.filter( + (call) => call.name === "resolvePresetOptions", + ); + assert.equal( + previews.length, + 1, + "Apply did not call resolve_preset_options once", + ); + assert.deepEqual( + previews[0].args, + [stored.id], + "Apply sent more than the preset id", + ); + assert.equal( + calls.some((call) => JSON.stringify(call.args).includes("example.com")), + false, + "a request during Apply carried the example.com placeholder", + ); + assert.equal( + calls.some((call) => call.name === "resolveDownloadOptions"), + false, + "Apply still resolved through the URL-based command", + ); + + // The controls show the backend's preset values, not the saved settings. + const controls = await browser.execute(() => ({ + convertEnabled: document.getElementById("convertToggle")?.checked, + convertFormat: document.getElementById("convertFormat")?.value, + keepOriginal: document.getElementById("keepOriginalToggle")?.checked, + })); + assert.deepEqual( + controls, + { convertEnabled: true, convertFormat: "m4a", keepOriginal: false }, + "controls did not show the preset values Rust resolved", + ); + + // The URL-less preview matches the URL-validated preset layer for the same preset. + const preview = await api("resolvePresetOptions", stored.id); + assert.equal(preview.ok, true, preview.error?.message); + assert.equal(preview.data.convertFormat, "m4a"); + assert.equal(preview.data.presetName, stored.name); + const withUrl = await api("resolveDownloadOptions", { + url: `${MEDIA}/clip-one.mp4?resolver=preview-${Date.now()}`, + outputPath: DOWNLOADS, + presetId: stored.id, + }); + assert.equal(withUrl.ok, true, withUrl.error?.message); + assert.deepEqual( + omitUrlAndOutput(preview.data), + omitUrlAndOutput(withUrl.data), + "URL-less preview and URL-validated resolution disagree for the same preset", + ); + + const unknown = await api("resolvePresetOptions", "no-such-preset"); + assert.equal(unknown.ok, false); + assert.equal(unknown.error.code, "VALIDATION_ERROR"); + + // A malformed payload comes back as an envelope, not a rejected invoke. + const malformed = await browser.executeAsync((done) => { + window.__TAURI__.core + .invoke("resolve_preset_options", { options: "wrong-shape" }) + .then( + (result) => done({ rejected: false, result }), + (error) => done({ rejected: true, error: String(error) }), + ); + }); + assert.equal(malformed.rejected, false, malformed.error); + assert.equal(malformed.result.ok, false); + assert.equal(malformed.result.error.code, "VALIDATION_ERROR"); + + // Preview only resolves values: no queue item was added. + const queue = await api("getQueue"); + assert.equal(queue.length, 0, "preset preview added a queue item"); + }); +}); diff --git a/e2e/v5-fixes/download-options/failure-modes.md b/e2e/v5-fixes/download-options/failure-modes.md new file mode 100644 index 00000000..e166ef3a --- /dev/null +++ b/e2e/v5-fixes/download-options/failure-modes.md @@ -0,0 +1,88 @@ +# Shared download option resolver failure modes + +1. **Resolution order changes.** Settings defaults must be applied first, a + selected preset second, and explicit on-screen values last. An explicit + `false` must survive every merge. +2. **Null is mistaken for an override.** `null` and omitted optional fields + remain unset so a preset/default can supply them; explicit `false` remains + a value. Hidden playlist controls omit the playlist, while a visible + `current` selection overrides a saved `all` or `range` selection. +3. **Preview and start disagree.** `resolve_download_options` and + `download_video` must return/use the same validated resolved snapshot for + the same settings and request. +4. **Manual and queue disagree.** Both paths must call the shared resolver; + equivalent settings, preset and explicit overrides produce equivalent + resolved options. +5. **Queue replay drifts.** Queue admission stores all resolved settings and + options. Starting or reloading a queued item after settings or presets + change must keep its enqueue-time request. +6. **Invalid requests bypass envelopes.** Wrong-shaped URL/options payloads, + unsafe URLs, and disallowed paths return the existing structured IPC error + envelope rather than a Tauri deserialization rejection or a started job. +7. **Validation is weakened by consolidation.** URL and output path + allow-lists, preset value validation, and lenient persisted settings/queue + imports remain in force. +8. **Queue execution semantics change.** Queue ordering, duplicate handling, + cancellation, and one-at-a-time execution remain unchanged. +9. **Stale renderer copy of a preset.** The renderer caches `downloadPresets`, + and Rust can hold a newer stored value than that cache. Apply and every + request must take preset values from `resolve_download_options`, never from + the cached preset object. Apply writes Rust's resolved values into the + controls, so the cache is not read for values at all. +10. **A copied value is sent as explicit.** After Apply, a control still holding + the value Apply copied in must not be sent. Otherwise a later stored change + to the preset is hidden by a stale on-screen value. Only controls changed + after Apply are explicit. Exception: the video and audio format dropdowns + hold URL-specific choices, so whatever they show for the current URL is + always explicit, even when Apply put it there. The user must get exactly + what the dropdowns show, and a URL switch during a save must not change the + formats a request was built with (round-3 checks + `download-uses-current-url-formats` and + `manual-format-snapshot-survives-url-switch-during-save`). +11. **An on-screen change after selection loses to the preset.** A control the + user changed after Apply must win. Related controls move as one group: the + profile group (`profile`, `bestQuality`, `audioOnly`, `advancedOptions`) and + the convert group (`convertEnabled`, `convertFormat`, `keepOriginal`), so a + preset's derived flag cannot override a changed profile or convert choice. +12. **Preset deleted or edited after selection.** A deleted preset id is ignored + by Rust, so the summary shows no preset label, and the renderer drops its + selection and copied baseline once its cache loses the preset. An edited + preset resolves to its stored value at the next summary refresh and start. +13. **Summary, manual Download, and queue add disagree.** All three build the + request through one renderer builder, and the started request must equal + `resolve_download_options` for that same request. Applying a preset must not + change what the summary reports for the same settings. + +## E2E acceptance + +The native scenario resolves the same preset/overrides through manual and +queue admission, checks explicit `false`, inherited `null`, and the visible +playlist `current` override, rejects invalid payloads through the IPC +envelope, then changes settings before replaying a queued item and verifies +its completion still carries the enqueue-time snapshot. The existing E2E +runner report under `e2e/artifacts/` is the repeatable evidence. + +The WebdriverIO scenario `applied preset follows the stored value in Rust` +applies a preset, changes its stored value through the backend, and checks +that the effective-options summary and a queued request both match +`resolve_download_options` for the same request, with no copied values sent. + +## Preset preview without a URL + +| # | Failure mode | Required behavior | +| --- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | Apply sends a placeholder URL to `resolve_download_options`. | Apply calls `resolve_preset_options` with only a preset id. No request sent by Apply carries a URL, including `example.com`. | +| 2 | An unknown or deleted preset id resolves silently to plain settings. | `resolve_preset_options` returns a `VALIDATION_ERROR` envelope. Apply reports failure and leaves the controls unchanged. | +| 3 | A malformed payload (not an object, missing or non-string `presetId`) rejects inside Tauri. | The command returns the structured error envelope and starts nothing. | +| 4 | The URL-less preview computes precedence differently from a real request. | Both call `layer_candidate`, so for the same settings and preset the preview values equal the preset layer of `resolve_download_options`. | +| 5 | Apply reads the renderer's cached preset instead of the stored one. | The backend resolves the id from stored settings; the cached preset object is not read for values. | +| 6 | Skipping URL validation for the preview weakens `resolve_download_options`. | `resolve_download_options` still returns `INVALID_URL` for a missing or invalid URL. Only the preview path skips the URL. | +| 7 | Preview has side effects. | The preview only resolves values. It adds no queue item and starts no download. | + +E2E acceptance: the WebdriverIO scenario `preset preview takes no URL and shows +backend values` records the renderer's calls during Apply and checks that the +command received only the preset id, with no call carrying `example.com`. It +checks that the controls show the preset values, that the URL-less preview +equals the URL-validated resolution for the same preset, that an unknown id +and a malformed payload return the `VALIDATION_ERROR` envelope, and that no +queue item was added. diff --git a/e2e/v5-fixes/flatpak-updates/failure-modes.md b/e2e/v5-fixes/flatpak-updates/failure-modes.md index ef7b565e..29043de0 100644 --- a/e2e/v5-fixes/flatpak-updates/failure-modes.md +++ b/e2e/v5-fixes/flatpak-updates/failure-modes.md @@ -32,7 +32,7 @@ a startup check is silent. Same as other builds. P2. Newer version in Flatpak: `available` carries `manualInstall: true`. The modal offers "Open Release Page" (primary) and "Later". No "Download & Install" button is shown. -P3. "Open Release Page" calls `window.api.openExternal` with exactly +P3. "Open Release Page" calls `window.__ROSI_E2E__.api.openExternal` with exactly `https://github.com/BurntToasters/ROSI/releases/tag/v`. P4. The release URL is built from the feed version with `encodeURIComponent`, so a version string cannot change the host or path. Semver versions @@ -69,6 +69,10 @@ extra field does not break them. ## E2E spec risks +Since 5.1.0-beta.1 the spec drives the Rust update engine against a local signed +feed (`e2e/helpers/updater-engine-fixture.js`). E1 and N4 describe the removed +renderer adapter and jsdom tests and are kept as history. + E1. The E2E adapter (`window.__ROSI_E2E__.updaterAdapter`) is only read when `VITE_ROSI_E2E === '1'`. Without it the spec would hit the real feed. The spec asserts the adapter is installed before it clicks the check button. diff --git a/e2e/v5-fixes/flatpak-updates/flatpak-update-notice.spec.js b/e2e/v5-fixes/flatpak-updates/flatpak-update-notice.spec.js index 6f4ac8ea..7ff5bcc6 100644 --- a/e2e/v5-fixes/flatpak-updates/flatpak-update-notice.spec.js +++ b/e2e/v5-fixes/flatpak-updates/flatpak-update-notice.spec.js @@ -4,13 +4,19 @@ import assert from "node:assert/strict"; import { fileURLToPath } from "node:url"; import { browser } from "@wdio/globals"; import { api, waitForAppReady } from "../../helpers/app-bridge.js"; +import { + captureUpdaterStatuses, + clickManualCheck, + setUpdateChannel, + startUpdaterFixture, +} from "../../helpers/updater-engine-fixture.js"; // Flatpak update notice. A Flatpak build checks the feed like other builds. // A newer version shows a prompt that opens the GitHub release page, and -// download and install never run. The E2E updater adapter stands in for the -// Tauri plugin: it reports is_flatpak, picks the feed result, and returns a -// fake update whose download and install calls are counted. +// download and install never run. The Rust updater runs for real; its feed is +// a local signed server, and the engine probe counts installs and restarts. const RELEASE_URL_BASE = "https://github.com/BurntToasters/ROSI/releases/tag/v"; +const BETA_TARGET = "linux-beta-x86_64"; const EXPECTED_CHECKS = 4; const here = path.dirname(fileURLToPath(import.meta.url)); const runDirectory = path.join( @@ -22,6 +28,7 @@ const runDirectory = path.join( new Date().toISOString().replace(/[:.]/g, "-"), ); const checks = []; +let fixture = null; function record(name, details) { checks.push({ name, passed: true, ...details }); @@ -42,6 +49,19 @@ function newerVersionThan(current) { return `${major}.${minor}.${patch + 1}`; } +// Without an explicit target the engine requests latest-{os}.json, then looks +// up {os}-{arch} inside that manifest. +function osName() { + return { darwin: "darwin", linux: "linux", win32: "windows" }[ + process.platform + ]; +} + +function stableTarget() { + const arch = { arm64: "aarch64", x64: "x86_64" }[process.arch]; + return `${osName()}-${arch}`; +} + async function freshRenderer() { await browser.execute(() => { window.__ROSI_E2E__.ready = false; @@ -50,61 +70,58 @@ async function freshRenderer() { await waitForAppReady(); } -async function installScenario(config) { - await browser.execute((scenario) => { - const probe = { - invokes: [], - checkTargets: [], - downloads: 0, - installs: 0, - restarts: 0, - closes: 0, - opened: [], - }; - window.flatpakUpdateProbe = probe; - window.api.openExternal = async (url) => { - probe.opened.push(url); +async function installScenario({ flatpak, channel, version }) { + if (fixture) await fixture.close(); + // The channel is set before the feed is configured, so no stale check runs. + await setUpdateChannel(channel); + fixture = await startUpdaterFixture({ + isPackaged: true, + isFlatpak: flatpak, + betaTarget: BETA_TARGET, + }); + const route = channel === "beta" ? BETA_TARGET : osName(); + if (version) { + fixture.server.publish({ + target: channel === "beta" ? BETA_TARGET : stableTarget(), + route, + version, + payload: Buffer.from(`flatpak scenario ${version}`), + fileName: `ROSI-${version}.bin`, + }); + } else { + // 204 No Content: the feed answers, and there is no newer version. + fixture.server.respond(route, 204); + } + await browser.execute(() => { + window.flatpakUpdateProbe = { opened: [] }; + window.__ROSI_E2E__.api.openExternal = async (url) => { + window.flatpakUpdateProbe.opened.push(url); return { ok: true, data: { opened: true } }; }; - window.__ROSI_E2E__.updaterAdapter = { - invoke: async (command, args = {}) => { - probe.invokes.push(command); - if (command === "is_packaged") return true; - if (command === "is_flatpak") return scenario.flatpak; - if (command === "get_settings") - return { updateChannel: scenario.channel }; - if (command === "get_beta_updater_target") return "linux-beta-x86_64"; - if (command === "restart_app") { - probe.restarts += 1; - return undefined; - } - return window.__TAURI__.core.invoke(command, args); - }, - check: async (target) => { - probe.checkTargets.push(target ?? null); - if (!scenario.version) return null; - return { - version: scenario.version, - body: `Scenario ${scenario.version}`, - async download() { - probe.downloads += 1; - }, - async install() { - probe.installs += 1; - }, - async close() { - probe.closes += 1; - }, - }; - }, - }; - }, config); + }); + await captureUpdaterStatuses("flatpakStatuses"); } async function readProbe() { - return browser.execute(() => - JSON.parse(JSON.stringify(window.flatpakUpdateProbe)), + const opened = await browser.execute(() => + window.flatpakUpdateProbe.opened.slice(), ); + const engine = await browser.executeAsync((done) => { + window.__TAURI__.core.invoke("e2e_updater_probe").then( + (data) => done(data), + (error) => done({ error: String(error) }), + ); + }); + const requests = fixture.server.requests.map((request) => request.path); + return { + opened, + downloads: requests.filter((item) => item.startsWith("/artifacts/")).length, + installs: engine.installs, + restarts: engine.restarts, + checkTargets: requests + .filter((item) => item.startsWith("/latest-")) + .map((item) => item.slice("/latest-".length, -".json".length)), + }; } function readModal() { @@ -144,15 +161,25 @@ async function clickModalButton(label) { }, label); } -async function runManualCheck() { - await browser.execute(() => - document.getElementById("checkUpdateBtn").click(), +async function invokeEngine(command, args) { + return browser.executeAsync( + (name, payload, done) => { + window.__TAURI__.core.invoke(name, payload).then( + (data) => done({ ok: true, data: data ?? null }), + (error) => done({ error: String(error) }), + ); + }, + command, + args, ); } describe("Flatpak update notice E2E", () => { before(waitForAppReady); - after(writeReport); + after(async () => { + if (fixture) await fixture.close(); + writeReport(); + }); it("prompts with the release page for a newer Flatpak build and never downloads or installs", async () => { const current = await api("getAppVersion"); @@ -160,7 +187,7 @@ describe("Flatpak update notice E2E", () => { await freshRenderer(); await installScenario({ flatpak: true, channel: "stable", version }); - await runManualCheck(); + await clickManualCheck(); const prompt = await waitForModal("Update Available!"); assert.ok(prompt.message.includes(`(v${version})`), prompt.message); assert.deepEqual(prompt.buttons, ["Open Release Page", "Later"]); @@ -180,14 +207,20 @@ describe("Flatpak update notice E2E", () => { const opened = await readProbe(); assert.deepEqual(opened.opened, [`${RELEASE_URL_BASE}${version}`]); assert.ok( - opened.checkTargets.every((target) => target === null), + opened.checkTargets.every((target) => target === osName()), JSON.stringify(opened), ); // Refusals hold even when the UI cannot reach them. - const download = await api("downloadUpdate"); - assert.ok(download?.error, JSON.stringify(download)); - await api("installUpdate"); + const candidateId = await browser.execute( + () => + window.flatpakStatuses + .filter((event) => event.status === "available") + .at(-1)?.candidateId, + ); + const download = await invokeEngine("download_update", { candidateId }); + assert.ok(download.data?.error, JSON.stringify(download)); + await invokeEngine("install_update", { candidateId }); const refused = await waitForModal("Update Error"); assert.ok(refused.message.includes("Flatpak"), refused.message); await clickModalButton("OK"); @@ -196,10 +229,6 @@ describe("Flatpak update notice E2E", () => { assert.equal(probe.downloads, 0); assert.equal(probe.installs, 0); assert.equal(probe.restarts, 0); - assert.ok( - !probe.invokes.includes("restart_app"), - JSON.stringify(probe.invokes), - ); record("flatpak-newer-release-prompt", { version, openedUrl: probe.opened[0], @@ -215,22 +244,21 @@ describe("Flatpak update notice E2E", () => { await freshRenderer(); await installScenario({ flatpak: true, channel: "beta", version }); - await runManualCheck(); + await clickManualCheck(); const prompt = await waitForModal("Update Available!"); assert.deepEqual(prompt.buttons, ["Open Release Page", "Later"]); const probe = await readProbe(); assert.ok(probe.checkTargets.length > 0, "the feed was not checked"); assert.ok( - probe.checkTargets.every((target) => target === "linux-beta-x86_64"), + probe.checkTargets.every((target) => target === BETA_TARGET), JSON.stringify(probe.checkTargets), ); - assert.ok(probe.invokes.includes("get_beta_updater_target")); await clickModalButton("Later"); const finalProbe = await readProbe(); assert.deepEqual(finalProbe.opened, []); assert.equal(finalProbe.downloads, 0); record("flatpak-beta-feed-target", { - target: "linux-beta-x86_64", + target: BETA_TARGET, version, }); }); @@ -240,7 +268,7 @@ describe("Flatpak update notice E2E", () => { await freshRenderer(); await installScenario({ flatpak: true, channel: "stable", version: null }); - await runManualCheck(); + await clickManualCheck(); const modal = await waitForModal("ROSI is up to date!"); assert.ok(modal.message.includes(`(v${current})`), modal.message); assert.deepEqual(modal.buttons, ["OK"]); @@ -257,12 +285,12 @@ describe("Flatpak update notice E2E", () => { await freshRenderer(); await installScenario({ flatpak: false, channel: "stable", version }); - await runManualCheck(); + await clickManualCheck(); const prompt = await waitForModal("Update Available!"); assert.deepEqual(prompt.buttons, ["Download & Install", "Later"]); await clickModalButton("Download & Install"); await browser.waitUntil(async () => (await readProbe()).downloads === 1, { - timeout: 10_000, + timeout: 15_000, timeoutMsg: "the update download was not started", }); await waitForModal("Update Ready!"); diff --git a/e2e/v5-fixes/platform/failure-modes.md b/e2e/v5-fixes/platform/failure-modes.md index 8dfc87ad..4be8bcd2 100644 --- a/e2e/v5-fixes/platform/failure-modes.md +++ b/e2e/v5-fixes/platform/failure-modes.md @@ -56,7 +56,7 @@ listed below are why a partial change is unsafe. 2. Other agents may add modules after this list is taken. Mitigation: re-list before reporting. 3. The frontend paragraph is wrong. Mitigation: read `src/main.ts`, - `src/tauri-bridge.ts`, and `src/modules` before rewriting it. + `src/api.ts`, and `src/modules` before rewriting it. 4. The PATCHES.md file may not exist yet (another agent writes it). The link must point to the real path `src-tauri/vendor/tauri-plugin-updater/PATCHES.md` and be checked for existence at the end. diff --git a/e2e/v5-fixes/queue-coordinator/failure-modes.md b/e2e/v5-fixes/queue-coordinator/failure-modes.md new file mode 100644 index 00000000..fc76ef2c --- /dev/null +++ b/e2e/v5-fixes/queue-coordinator/failure-modes.md @@ -0,0 +1,125 @@ +# Queue/session coordinator migration: failure modes + +Written before any Rust change. Current code references: `src-tauri/src/queue.rs` +(`QUEUE`, `START_GUARD`, `RUNNER_CHANGED`, `PERSIST_SIGNAL`, `run_queue`, +`stop`, `start_queue`, `cancel_queue_blocking`, `clear_queue_blocking`) and +`src-tauri/src/downloader.rs` (`ACTIVE`, `SESSION_CHANGED`, `FINALIZING`, +`FINALIZATION_CHANGED`, `STARTUP`, `EVENT_PUBLISH`, `CompletionCallback`, +`cancel_session`, `complete_session`, `start_download`, `download_video`). + +Each row names the failure, the mechanism that could cause it after the +migration, and the guard that must hold. `queue-coordinator.spec.js` covers +every row that is observable through `window.__ROSI_E2E__.api` or the existing E2E hooks. +Internal rows are guarded by design rules and review. + +## Races between commands + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 1 | Cancel lands between the runner's "still wanted" check and the session start, so the item starts after the user cancelled. | Runner claims an item, cancel arrives, start proceeds. | Coordinator orders cancel and start as commands on one queue. A start carries the item id and run generation; cancel bumps the generation, so a stale start is rejected and the item gets exactly one cancelled outcome. E2E: cancel during claim leaves the item `cancelled` with no completion event for it. | +| 2 | Start while stop is in progress replaces the runner that stop() is waiting for. | `start_queue` after `stop()` sets `stopping`. | Coordinator rejects Start while a stop is in flight with "Queue is stopping." Same status code as today. E2E: restart path after close. | +| 3 | Retry of an item still being finalized is accepted, then overwritten by the old completion. | Completion for session N arrives after retry set the item to pending. | Completion carries session id and attempt id; a completion whose attempt id is not the item's current attempt is dropped and logged. E2E: retry after cancel yields one terminal state. | +| 4 | Reorder during a running session moves the active item. | Pending-index math reads a stale snapshot. | Reorder is a coordinator command that only touches pending items. Existing "Only pending queue items can be reordered." error kept. E2E: reorder while a run is active. | +| 5 | Clear queue while running leaves a session that later records into a removed item. | Clear removes items; completion looks up by id. | Clear cancels the session first (notify), then removes items. A completion for a missing item records nothing (existing behaviour). E2E: clear during a download. | +| 6 | Remove of the downloading item races with its completion. | Remove sees a stale status. | Remove is decided from coordinator state; "Cannot remove an actively downloading item." kept. | +| 7 | Duplicate add of a URL already downloading. | Duplicate check reads state while the runner flips status. | Add is a coordinator command; the nonterminal URL set comes from coordinator state. Skipped-count semantics kept. | + +## Stale and duplicate session events + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 8 | A progress line from session N is applied to session N+1. | Reader threads outlive the session that spawned them. | Every worker event carries its session id; the coordinator drops events whose id is not the active id. E2E: back-to-back queue items keep their own progress and completion. | +| 9 | Two terminal results are published for one session (cancel path and natural exit both finish it). | Cancel and exit both call completion. | The coordinator publishes a terminal result only when it moves the session out of Active; the second attempt is a no-op. E2E: cancel during post-processing yields exactly one `download-complete` per item. | +| 10 | Completion for session N clears the slot of session N+1. | Slot cleared without an id check. | Slot is cleared only when the terminal result's session id equals the active id. E2E: sequential queue of several items finishes every item. | +| 11 | Terminal result reaches the queue and the activity log through different paths and disagrees. | Two consumers of one completion. | One terminal message per session; queue apply and activity record both read that message. | + +## Orphan processes and waits + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 12 | yt-dlp or ffmpeg survives cancel, stop, or close. | Child dropped without `terminate_tree`, or the coordinator publishes before the child exits. | Cancel and shutdown send Terminate to the session worker; cancel and stop publish their terminal result only after the worker acknowledges child exit. E2E: cancel leaves no child from the test profile. | +| 13 | Coordinator blocks on a child wait or disk write, freezing every command. | Waiting for exit inside the command loop. | Waits and file writes run on worker or writer threads. The coordinator only updates state and sends messages. Review rule; observable through the cancel scenario finishing within its timeout. | +| 14 | An ack never arrives, so close hangs. | Worker panics before acknowledging, or writer dies. | Every ack wait has a bounded timeout. On timeout the caller logs and takes the existing failure path. E2E: close-pending-timeout still reports the pending close. | +| 15 | Deadlock between coordinator and a caller holding a lock it needs. | Caller holds a window or settings lock while awaiting a reply. | Callers never hold a shared lock across send and recv. The coordinator never calls window, emit, or stats code while holding its own state. | + +## Persistence + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 16 | Close reports success while the latest queue revision is not durable. | Writer acknowledges an older revision, or a debounced write is skipped. | Close, restart, and update request durable revision R and wait for the writer's ack for R or newer. E2E: queue-latest-snapshot. | +| 17 | Persistence failure during close is hidden, so the app exits and loses the queue. | Flush error swallowed on the shutdown path. | Both flushes in `shutdown_with_close_generation` keep their error returns; a failed flush keeps the app open. E2E: queue-flush-backup-failure and the blocked-backup close/restart scenario. | +| 18 | A failed flush blocks command processing or retries forever. | Writer retries inside the coordinator loop. | Writer is its own thread. A failed flush returns an error to the requester and state stays dirty; the existing 300 ms debounce and retry-on-next-change behaviour is kept. | +| 19 | A newer-schema queue file is overwritten by an older build. | Flush after migration skips the schema guard. | The `is_newer_schema_file` path in `queue::flush` is kept as is: it returns Ok with a warning. | +| 20 | Out-of-order writes leave an older snapshot on disk. | Two writer threads or a delayed debounced write. | A single writer owns `QueuePersistence`. The `highest_attempted` / `last_persisted` rule is kept. | +| 21 | Persisted file format changes with no migration path. | New session or attempt fields serialized into `download-queue.json`. | Persisted `QueueItem` shape is unchanged; revisions and attempt ids stay in memory. `long-term-persistence` must pass unchanged. | + +## Admission: manual versus queue + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 22 | Manual download accepted while the queue runner is between items. | `download_video` checks the session slot, which is empty between items. | Coordinator admission checks both the active owner and the queue run state. `download_video` keeps "A queue download is already in progress." E2E: manual download during a queue run is refused. | +| 23 | Queue start accepted while a manual session holds the slot. | `start_queue` races a manual start. | Start command checks coordinator owner state and returns "A manual download is already in progress." | +| 24 | Queue runner stalls behind a manual download. | Old code slept 250 ms and retried. | Coordinator holds the queue start until the slot is free; the item stays pending. E2E: queue started right after a manual download completes. | +| 25 | Manual download recorded as a queue item, or the reverse. | Owner passed incorrectly. | Owner is part of the session identity and the terminal result; `download-complete` keeps its `owner` field. | + +## Restart and update during an active download + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 26 | Restart during an active item leaves it cancelled instead of pending. | Stop's terminal result recorded as a user cancel. | Stop is an interruption: the item is requeued to pending as today. E2E: restart during an active item leaves it pending with a clean attempt. | +| 27 | Update install starts while a child still writes into the output folder. | Install proceeds before the exit ack. | The update path waits for the coordinator's idle-with-children-exited state, bounded by the existing timeout. | +| 28 | Window closed during a queue run. | Runner checks the main window per item. | Coordinator produces the same synthetic failed completion, "Window closed", and continues. | + +## Ordering of published snapshots + +| # | Failure mode | Mechanism | Guard | +| --- | --- | --- | --- | +| 29 | Frontend applies an older queue snapshot after a newer one. | Two emitters race. | The single coordinator publishes in revision order and each `queue-update` carries a monotonically increasing `revision`. The renderer's `queue-update` consumer (`src/engine/bind/backend-events.ts`) drops older revisions. | +| 30 | A poisoned lock makes queue events panic. | `lock().unwrap()` after a worker panic. | Poison recovery (`unwrap_or_else(|p| p.into_inner())`) on every lock the migration touches. | + +## Test strategy + +- Observable rows (1-10, 12, 16-17, 22-24, 26, 28-29) are covered by + `queue-coordinator.spec.js` through `window.__ROSI_E2E__.api` and the existing E2E hooks. +- Internal rows (11, 13-15, 18-21, 25, 27, 30) are guarded by design rules and + review. AGENTS.md forbids writing unit tests after code, so they are exercised + through the observable scenarios above, not by isolated tests. +- Verification: targeted groups `queue`, `lifecycle`, `persistence`, + `downloads`, then one full `npm.bat run test:e2e`. + +## Stage 2: scenario map (current code) + +`queue-coordinator.spec.js` runs against the unmigrated code and must pass +there. Rows not listed here are covered by existing scenarios, not by this spec. + +| Spec scenario | Rows | +| --- | --- | +| runs queued items one at a time with exactly one outcome each | 8, 9, 10, 11 | +| skips a duplicate of a URL that is already downloading | 7 | +| refuses manual downloads and queue starts while the other owner runs | 22, 23 | +| cancels a running item, then retries it to one completed attempt | 1, 3, 9, 12 | +| rejects reorder and removal of the active item while the run continues | 4, 6 | +| clears a running queue without recording an outcome for removed items | 5, 12 | +| keeps the persisted queue equal to the live queue after a run | 16, 21 | +| publishes strictly increasing revisions and never renders a stale snapshot | 29 | + +Rows not covered by this spec: 2 (stop during start), 13-15 (internal waits and +locks), 17-20 (persistence failure paths, covered by `queue-flush-backup-failure` +and `long-term-persistence`), 24 (queue waiting behind a manual download), 25, +26 (restart during an active item, covered by `close-pending-timeout` and the +lifecycle group), 27, 28, 30. + +### Row 29 contract (status: implemented) + +- `queue-update` carries `{ revision, items }`. `revision` is assigned by the + coordinator on each commit and increases strictly. +- The renderer (`src/engine/bind/backend-events.ts`) drops a snapshot whose + revision is older than the newest one it rendered. Bare-array payloads have + no revision and are always applied. +- The startup `getQueue` read has no revision. It is applied only if no + snapshot arrived while it was in flight. A snapshot emitted before the read + but delivered after it can still be applied. That residual window is kept + because `get_queue` must remain a bare array for existing E2E specs. +- Covered by the spec scenario "publishes strictly increasing revisions and + never renders a stale snapshot", which injects a revision 0 snapshot through + the e2e-only `e2e_emit_stale_download_events` probe. diff --git a/e2e/v5-fixes/queue-coordinator/queue-coordinator.spec.js b/e2e/v5-fixes/queue-coordinator/queue-coordinator.spec.js new file mode 100644 index 00000000..30630430 --- /dev/null +++ b/e2e/v5-fixes/queue-coordinator/queue-coordinator.spec.js @@ -0,0 +1,344 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { spawnSync } from "node:child_process"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "../../helpers/app-bridge.js"; + +const env = process.env; +const MEDIA = env.ROSI_E2E_MEDIA_URL; +const DOWNLOADS = env.ROSI_E2E_DOWNLOADS; +const DATA_DIR = env.ROSI_E2E_DATA_DIR; +const TERMINAL = ["completed", "failed", "cancelled"]; + +function processesMatching(needle) { + const listing = + process.platform === "win32" + ? spawnSync( + "powershell.exe", + [ + "-NoProfile", + "-Command", + "Get-CimInstance Win32_Process | ForEach-Object { $_.CommandLine }", + ], + { encoding: "utf8" }, + ).stdout + : spawnSync("ps", ["-Ao", "command="], { encoding: "utf8" }).stdout; + return (listing || "") + .split("\n") + .filter((line) => line.includes(needle) && !line.includes("powershell")); +} + +async function waitForNoProcess(needle, timeoutMsg) { + await browser.waitUntil(async () => processesMatching(needle).length === 0, { + timeout: 15_000, + interval: 250, + timeoutMsg: `${timeoutMsg}: ${processesMatching(needle).join(" | ")}`, + }); +} + +async function activityFor(url) { + const activity = (await api("getDownloadActivity")).data; + return activity.filter((entry) => entry.url === url); +} + +async function waitForItemStatus(url, status, timeoutMsg, timeout = 60_000) { + await browser.waitUntil( + async () => + (await api("getQueue")).some( + (item) => item.url === url && item.status === status, + ), + { timeout, interval: 250, timeoutMsg }, + ); +} + +async function waitForAllTerminal(timeoutMsg) { + await browser.waitUntil( + async () => + (await api("getQueue")).every((item) => TERMINAL.includes(item.status)), + { timeout: 180_000, interval: 500, timeoutMsg }, + ); +} + +describe("queue and session coordinator behaviour", () => { + before(async () => { + await waitForAppReady(); + }); + + beforeEach(async () => { + await api("cancelQueue"); + await api("clearQueue"); + }); + + it("runs queued items one at a time with exactly one outcome each", async () => { + const urls = [ + `${MEDIA}/clip-two.mp4?coord=seq`, + `${MEDIA}/clip-three.mp4?coord=seq`, + `${MEDIA}/clip-one.mp4?coord=seq`, + ]; + const added = await api("addToQueue", urls); + assert.equal(added.data.added, 3); + assert.equal((await api("startQueue")).ok, true); + await waitForAllTerminal("sequential queue did not finish"); + + const queue = await api("getQueue"); + for (const item of queue) { + assert.equal(item.status, "completed", item.error ?? item.url); + } + const completedAt = []; + for (const url of urls) { + const entries = await activityFor(url); + assert.equal( + entries.length, + 1, + `${url} recorded ${entries.length} times`, + ); + assert.equal(entries[0].outcome, "success"); + completedAt.push(entries[0].completedAt); + } + assert.deepEqual( + completedAt, + [...completedAt].sort((a, b) => a - b), + "items did not finish in queue order", + ); + }); + + it("skips a duplicate of a URL that is already downloading", async () => { + const slow = `${MEDIA}/slow.mp4?coord=dup`; + assert.equal((await api("addToQueue", [slow])).data.added, 1); + assert.equal((await api("startQueue")).ok, true); + await waitForItemStatus(slow, "downloading", "item never started"); + const again = await api("addToQueue", [slow]); + assert.equal(again.data.added, 0); + assert.equal(again.data.skipped, 1); + await api("cancelQueue"); + await waitForNoProcess("coord=dup", "duplicate test process survived"); + }); + + it("refuses manual downloads and queue starts while the other owner runs", async () => { + const slow = `${MEDIA}/slow.mp4?coord=admit`; + const next = `${MEDIA}/clip-three.mp4?coord=admit`; + assert.equal((await api("addToQueue", [slow, next])).data.added, 2); + assert.equal((await api("startQueue")).ok, true); + await waitForItemStatus(slow, "downloading", "queue item never started"); + + const manual = await api("downloadVideo", { + url: `${MEDIA}/clip-one.mp4?coord=manual`, + outputPath: DOWNLOADS, + }); + assert.equal(manual.ok, false, "manual download ran during a queue run"); + assert.match( + manual.error.message, + /queue download is already in progress/i, + ); + + const restart = await api("startQueue"); + assert.equal(restart.ok, false, "second queue start was accepted"); + assert.match(restart.error.message, /already running/i); + + await api("cancelQueue"); + await waitForAllTerminal("admission queue did not settle"); + await waitForNoProcess("coord=admit", "admission test process survived"); + }); + + it("cancels a running item, retries it, and records one outcome per attempt", async () => { + const slow = `${MEDIA}/slow.mp4?coord=retry`; + assert.equal((await api("addToQueue", [slow])).data.added, 1); + assert.equal((await api("startQueue")).ok, true); + await waitForItemStatus(slow, "downloading", "queue item never started"); + await browser.pause(1000); + assert.equal((await api("cancelQueue")).ok, true); + await waitForItemStatus(slow, "cancelled", "cancel did not land"); + await waitForNoProcess("coord=retry", "cancelled yt-dlp survived"); + await browser.pause(500); + let entries = await activityFor(slow); + assert.equal(entries.length, 1, "cancelled item recorded more than once"); + assert.equal(entries[0].outcome, "cancelled"); + + const item = (await api("getQueue")).find((entry) => entry.url === slow); + assert.equal((await api("retryQueueItem", item.id)).ok, true); + assert.equal((await api("startQueue")).ok, true); + await waitForItemStatus(slow, "downloading", "retried item never started"); + await browser.pause(1000); + assert.equal((await api("cancelQueue")).ok, true); + await waitForItemStatus( + slow, + "cancelled", + "retried attempt did not cancel", + ); + await waitForNoProcess("coord=retry", "retried yt-dlp survived"); + await browser.pause(500); + entries = await activityFor(slow); + assert.equal(entries.length, 2, JSON.stringify(entries)); + assert.deepEqual( + entries.map((entry) => entry.outcome), + ["cancelled", "cancelled"], + "each attempt must record exactly one outcome", + ); + assert.equal( + (await api("getQueue")).find((entry) => entry.url === slow).status, + "cancelled", + ); + }); + + it("rejects reorder and removal of the active item while the run continues", async () => { + const slow = `${MEDIA}/slow.mp4?coord=mutate`; + const second = `${MEDIA}/clip-two.mp4?coord=mutate`; + const third = `${MEDIA}/clip-three.mp4?coord=mutate`; + assert.equal( + (await api("addToQueue", [slow, second, third])).data.added, + 3, + ); + assert.equal((await api("startQueue")).ok, true); + await waitForItemStatus(slow, "downloading", "queue item never started"); + + let queue = await api("getQueue"); + const active = queue.find((item) => item.url === slow); + const pendingLast = queue.find((item) => item.url === third); + + const moved = await api("reorderQueueItem", { + id: pendingLast.id, + direction: "up", + }); + assert.equal(moved.ok, true, moved.error?.message); + + const reorderActive = await api("reorderQueueItem", { + id: active.id, + direction: "down", + }); + assert.equal(reorderActive.ok, false, "active item was reordered"); + + const removeActive = await api("removeFromQueue", active.id); + assert.equal(removeActive.ok, false, "active item was removed"); + assert.match(removeActive.error.message, /actively downloading/i); + + await api("cancelQueue"); + await waitForAllTerminal("mutation queue did not settle"); + await waitForNoProcess("coord=mutate", "mutation test process survived"); + queue = await api("getQueue"); + assert.equal( + queue.filter((item) => item.url === second).length, + 1, + "pending item was lost", + ); + }); + + it("clears a running queue without recording an outcome for removed items", async () => { + const slow = `${MEDIA}/slow.mp4?coord=clear`; + const next = `${MEDIA}/clip-three.mp4?coord=clear`; + assert.equal((await api("addToQueue", [slow, next])).data.added, 2); + assert.equal((await api("startQueue")).ok, true); + await waitForItemStatus(slow, "downloading", "queue item never started"); + await browser.pause(1000); + assert.equal((await api("clearQueue")).ok, true); + assert.deepEqual(await api("getQueue"), []); + await waitForNoProcess("coord=clear", "cleared queue yt-dlp survived"); + await browser.pause(1000); + const slowEntries = await activityFor(slow); + assert.equal(slowEntries.length, 1, "running item recorded more than once"); + assert.equal(slowEntries[0].outcome, "cancelled"); + assert.equal( + (await activityFor(next)).length, + 0, + "removed item was recorded", + ); + }); + + it("keeps the persisted queue equal to the live queue after a run", async () => { + const urls = [ + `${MEDIA}/clip-two.mp4?coord=persist`, + `${MEDIA}/clip-one.mp4?coord=persist`, + ]; + assert.equal((await api("addToQueue", urls)).data.added, 2); + assert.equal((await api("startQueue")).ok, true); + await waitForAllTerminal("persisted run did not finish"); + const live = (await api("getQueue")).map((item) => [item.url, item.status]); + const queuePath = path.join(DATA_DIR, "download-queue.json"); + await browser.waitUntil( + () => { + if (!fs.existsSync(queuePath)) return false; + const raw = JSON.parse(fs.readFileSync(queuePath, "utf8")); + const list = Array.isArray(raw) ? raw : (raw.items ?? raw.queue ?? []); + const onDisk = list.map((item) => [item.url, item.status]); + return JSON.stringify(onDisk) === JSON.stringify(live); + }, + { + timeout: 15_000, + interval: 250, + timeoutMsg: "persisted queue lags the live queue", + }, + ); + }); + + it("publishes strictly increasing revisions and never renders a stale snapshot", async () => { + // Records every revision the renderer's queue-update listener receives. + await browser.execute(() => { + window.__rosiQueueRevisions = []; + window.__rosiQueueUnsubscribe = window.__ROSI_E2E__.api.onQueueUpdate( + (snapshot) => { + window.__rosiQueueRevisions.push(snapshot.revision); + }, + ); + }); + try { + const urls = [ + `${MEDIA}/clip-two.mp4?coord=revision`, + `${MEDIA}/clip-one.mp4?coord=revision`, + ]; + assert.equal((await api("addToQueue", urls)).data.added, 2); + assert.equal((await api("startQueue")).ok, true); + await waitForAllTerminal("revision run did not finish"); + + const revisions = await browser.execute(() => + window.__rosiQueueRevisions.slice(), + ); + assert.ok( + revisions.length >= 3, + `expected several snapshots, received ${revisions.length}`, + ); + for (let index = 1; index < revisions.length; index += 1) { + assert.ok( + revisions[index] > revisions[index - 1], + `revision ${revisions[index]} did not follow ${revisions[index - 1]}`, + ); + } + + const rowCount = () => + browser.execute( + () => document.querySelectorAll("#queueList .queue-item").length, + ); + const rendered = await rowCount(); + assert.equal(rendered, 2, "the finished run did not render both rows"); + + // Revision 0 is older than every snapshot the coordinator publishes. The + // probe sends it as a real queue-update with an empty queue. + await browser.execute(() => + window.__TAURI__.core.invoke("e2e_emit_stale_download_events", { + currentSessionId: 2, + staleQueueSnapshot: true, + }), + ); + await browser.waitUntil( + () => browser.execute(() => window.__rosiQueueRevisions.includes(0)), + { + timeout: 10_000, + interval: 250, + timeoutMsg: "the stale snapshot never reached the renderer", + }, + ); + await browser.pause(1000); + assert.equal( + await rowCount(), + rendered, + "a stale queue snapshot replaced the rendered queue", + ); + assert.equal((await api("getQueue")).length, 2); + } finally { + await browser.execute(() => { + window.__rosiQueueUnsubscribe?.(); + delete window.__rosiQueueUnsubscribe; + delete window.__rosiQueueRevisions; + }); + } + }); +}); diff --git a/e2e/v5-fixes/renderer/failure-modes.md b/e2e/v5-fixes/renderer/failure-modes.md index 8515ba6d..78e6b93e 100644 --- a/e2e/v5-fixes/renderer/failure-modes.md +++ b/e2e/v5-fixes/renderer/failure-modes.md @@ -30,7 +30,7 @@ Hosting: the new code lives in `src/modules/downloads.ts`, not a new file. Reaso 1. Double event binding: filter buttons (`.activity-filter` click) or `onDownloadActivityUpdate` could be registered twice if init runs twice. Mitigation: `initActivityPanel` has exactly one caller (the engine's startup, at the old `renderActivity()` position). No guard is added, so this rule depends on that single call site. 2. Init order: `renderActivity()` ran before filter wiring and before `activityReplayHandler` was set. The replay handler is now passed in at init. With no entries at init time, no replay button can render earlier, so the visible result is identical. Verified by reading the code path (`toActivityRows` returns legacy rows with no `request`). -3. Init order versus `window.api`: `window.api` is defined by tauri-bridge.ts, which main.ts imports first. The module reads `window.api` only inside functions called after init, so a late bind is fine. The module must not touch `window.api` at load time. +3. Init order versus the API: the API object is defined by `src/api.ts`, which main.ts imports first. The module reads `api` only inside functions called after init, so a late bind is fine. The module must not call `api` at load time. 4. Module-level state duplicated: `activityEntries` must exist once. The engine must not keep a second copy. `activityLoaded` gates the unseen-marker logic and must still skip the first load. 5. DOM ids not found at import time: `#download-history`, `#history-list`, `#history-count` are looked up inside `renderActivity` at call time, not at load time. Missing nodes must still return early. 6. Lost closures and `this`: `activityReplayHandler` previously captured `replayActivityDownload` (a closure in initializeRenderer). It now goes in through an `onReplay` option. `showToast` and `renderStatusText` are passed in as deps so the module does not reach back into the engine. diff --git a/e2e/v5-fixes/typed-formats/failure-modes.md b/e2e/v5-fixes/typed-formats/failure-modes.md new file mode 100644 index 00000000..af93b98b --- /dev/null +++ b/e2e/v5-fixes/typed-formats/failure-modes.md @@ -0,0 +1,83 @@ +# Typed format discovery failure modes + +1. **Invalid or unsafe URL accepted.** Format discovery must keep the existing + safe HTTP URL validation and network-security guard before yt-dlp runs. +2. **Unbounded process or output.** Format discovery must keep its tracked + process slot, timeout, bounded stdout/stderr capture, and cancellation path. +3. **Superseded lookup returns late.** A reply for an old URL or cancelled + request must not repopulate either picker or restore format selections. +4. **Malformed or incomplete JSON treated as success.** Missing, invalid, or + truncated structured metadata must surface as a failed lookup, never as a + valid empty list. +5. **Wrong stream classification.** Audio-only, video-only, and combined + audio/video formats must be classified from codec metadata, including codec + values represented by `none`; when both codec fields are missing, known + audio/video containers retain the existing combined-format fallback. + Non-media and storyboard entries must not be selectable. +6. **Format ID changed or guessed.** The renderer must submit the exact ID from + the structured entry when it matches the downloader's existing accepted + format-ID syntax, and must not parse IDs from display text. +7. **Optional metadata crashes or lies.** Missing codecs, resolution, fps, or + both size fields must remain representable; an approximate size must be + marked approximate rather than presented as exact. +8. **UI has no terminal state.** Loading must end on cancellation, empty + results, and errors; empty or failed results must clear selectable values + and invalidate URL-bound selections. +9. **Legacy completion text overrides structured completion.** Manual download + outcomes must continue to be driven by session-matched structured + `download-complete` events, while the legacy text event remains available + for diagnostic output. +10. **Playlist wrapper hides the selected video's formats.** Format lookup on a + URL with a playlist wrapper must stay scoped to the current video with + `--no-playlist`. If yt-dlp still returns playlist-only metadata, fail with + an actionable request for a specific video URL; never enumerate an + unbounded playlist to find formats. +11. **Explicit no-codec metadata is mistaken for absent metadata.** An + extension-based combined-stream fallback may cover missing codec fields, + but `vcodec: "none"` and `acodec: "none"` explicitly describe a non-media + entry and must be omitted. +12. **Unused progress text parser becomes a second authority.** The renderer's + `parseYtdlpProgress` helper has no production call sites; remove it and its + dedicated tests while keeping progress strings in the diagnostic console. +13. **Backend label drifts from the old renderer text.** `display_label` is built + in `media_info.rs` and must reproduce the pre-B5 `formatFormatEntry` output + byte for byte: `ID:` prefix, resolution, fps, codecs joined with ` + ` + (video codec first), ` (video + audio)` only for `audioVideo`, then the size + suffix. Guarded by golden strings from the old function on the local HLS and + MP4 fixtures in `typed-formats.spec.js`. +14. **Rounding differs from JavaScript.** `toFixed(2)` rounds exact binary ties + up; Rust's `{:.2}` rounds them to even. A fps such as 23.976 must become + `23.98fps`, and a size such as 1152 bytes (1.125 KB) must become `1.13 KB`. + Integer fps must print without decimals (`25fps`). Fixtures do not reach the + size branch, so the byte and fps helpers are also checked against the old + JavaScript function in a differential run outside the repository (see the + E2E section). +15. **Byte-size boundaries drift.** Sizes just below a power of 1024, and exact + powers, must pick the same unit as `Math.floor(Math.log(n) / Math.log(1024))` + with the unit capped at `PB`. Zero stays `0 B`. A size is never shown as + `NaN`, `Infinity`, or an exponent form. +16. **Missing fields leave stray separators.** Absent resolution, fps, codecs, + or both sizes must not add a space, an empty pair of parentheses, or `~`. + Empty codec strings are skipped. A non-finite fps is skipped. The HLS + audio-only variant (no resolution) and the MP4 fixture (no codecs) cover + the missing-field path. +17. **Stream kind and label disagree.** `(video + audio)` follows `streamKind`, + not codec presence. Audio-only and video-only entries must never carry it, + and must never show the `audio only` resolution text. Fixtures cover the + combined HLS variant plus audio-only and video-only variants. +18. **Free-text notes leak into the option text.** `format_note`, titles, and + HLS `NAME` values are not read by the label builder, so unicode or very long + notes cannot change the option text. Only structured fields are read. +19. **Renderer shows a missing or stale label.** Option text comes only from + `displayLabel`. The renderer has no label fallback, so a missing field would + show as `undefined`. The TypeScript type requires the field, and the spec + asserts every option's text equals its entry's `displayLabel`. + +## E2E acceptance + +Use the native E2E media server and app bridge to verify structured IDs and +metadata reach both picker controls, a local manifest carrying a playlist-like +query stays usable as one current video, cancellation and URL changes retire +stale results, and a failed/empty response leaves no usable stale selections. +The existing E2E runner writes the repeatable report and app/source hashes +under `e2e/artifacts/`. diff --git a/e2e/v5-fixes/typed-formats/typed-formats.spec.js b/e2e/v5-fixes/typed-formats/typed-formats.spec.js new file mode 100644 index 00000000..deb48cbe --- /dev/null +++ b/e2e/v5-fixes/typed-formats/typed-formats.spec.js @@ -0,0 +1,356 @@ +import assert from "node:assert/strict"; +import http from "node:http"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "../../helpers/app-bridge.js"; + +const MEDIA = process.env.ROSI_E2E_MEDIA_URL; +const HAS_FFMPEG = process.env.ROSI_E2E_HAS_FFMPEG === "1"; + +// HLS master with a combined variant, a video-only variant with a fractional +// frame rate (23.976 rounds to 23.98), an integer fps variant without a +// resolution, and an audio-only variant. yt-dlp lists these without fetching +// the variant playlists, so the spec serves only this master. +const HLS_MASTER = [ + "#EXTM3U", + "#EXT-X-VERSION:3", + '#EXT-X-STREAM-INF:BANDWIDTH=1200000,RESOLUTION=1280x720,FRAME-RATE=23.976,CODECS="avc1.64001f,mp4a.40.2"', + "hi.m3u8", + '#EXT-X-STREAM-INF:BANDWIDTH=600000,RESOLUTION=640x360,FRAME-RATE=29.970,CODECS="avc1.4d401e"', + "mid.m3u8", + '#EXT-X-STREAM-INF:BANDWIDTH=300000,FRAME-RATE=25.000,CODECS="avc1.42c01e"', + "lo.m3u8", + '#EXT-X-STREAM-INF:BANDWIDTH=128000,CODECS="mp4a.40.2"', + "aud.m3u8", + "", +].join("\n"); + +// Exact text the pre-5.1 renderer (formatFormatEntry) produced for these entries. +const LEGACY_LABELS = { + 128: "ID: 128 (mp4a.40.2)", + 300: "ID: 300 25fps (avc1.42c01e)", + 600: "ID: 600 640x360 29.97fps (avc1.4d401e)", + 1200: "ID: 1200 1280x720 23.98fps (avc1.64001f + mp4a.40.2) (video + audio)", +}; + +async function startManifestServer() { + const server = http.createServer((request, response) => { + if (request.url?.split("?")[0] !== "/master.m3u8") { + response.writeHead(404).end(); + return; + } + response + .writeHead(200, { "content-type": "application/vnd.apple.mpegurl" }) + .end(HLS_MASTER); + }); + await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); + const { port } = server.address(); + return { + baseUrl: `http://127.0.0.1:${port}`, + close: () => new Promise((resolve) => server.close(resolve)), + }; +} + +async function setUrlAndFetch(url) { + await browser.execute((value) => { + const input = document.getElementById("url"); + input.value = value; + input.dispatchEvent(new Event("input", { bubbles: true })); + document.getElementById("fetchFormatsBtn").click(); + }, url); +} + +async function readFormatPickers() { + return browser.execute(() => { + const read = (id) => { + const select = document.getElementById(id); + return [...select.options].map((option) => ({ + value: option.value, + text: option.textContent, + })); + }; + return { + video: read("videoFormat"), + audio: read("audioFormat"), + }; + }); +} + +describe("typed format discovery", () => { + before(async () => { + await waitForAppReady(); + }); + + after(async () => { + await browser.execute(() => { + const original = window.__typedFormatsOriginalApi; + if (!original) return; + window.__ROSI_E2E__.api.getFormats = original.getFormats; + window.__ROSI_E2E__.api.cancelFormats = original.cancelFormats; + delete window.__typedFormatsOriginalApi; + delete window.__typedFormatsPending; + }); + }); + + it("returns typed entries and renders their exact IDs in the matching picker", async () => { + const url = HAS_FFMPEG + ? `${MEDIA}/dash/manifest.mpd` + : `${MEDIA}/clip-one.mp4`; + const result = await api("getFormats", url); + assert.equal(result.ok, true, result.error?.message); + assert.ok(Array.isArray(result.data.formats)); + assert.ok( + result.data.formats.length > 0, + "yt-dlp returned no media formats", + ); + assert.ok( + result.data.formats.every( + (format) => + typeof format.formatId === "string" && + ["audio", "video", "audioVideo"].includes(format.streamKind), + ), + JSON.stringify(result.data.formats), + ); + + const wrappedUrl = HAS_FFMPEG + ? `${MEDIA}/dash/manifest.mpd?list=local-wrapper` + : `${MEDIA}/clip-one.mp4?list=local-wrapper`; + const wrapped = await api("getFormats", wrappedUrl); + assert.equal(wrapped.ok, true, wrapped.error?.message); + assert.ok(Array.isArray(wrapped.data.formats)); + if (HAS_FFMPEG) { + assert.ok( + wrapped.data.formats.length > 0, + "playlist-like URL did not return the current manifest's formats", + ); + } + + await setUrlAndFetch(url); + await browser.waitUntil( + async () => + browser.execute( + () => + !document + .getElementById("fetchFormatsBtn") + .classList.contains("loading"), + ), + { timeout: 60_000, timeoutMsg: "format picker did not finish loading" }, + ); + const pickers = await readFormatPickers(); + for (const format of result.data.formats) { + const expectedPicker = + format.streamKind === "audio" ? pickers.audio : pickers.video; + assert.ok( + expectedPicker.some((option) => option.value === format.formatId), + `format ${format.formatId} was not rendered as an exact option value`, + ); + } + }); + + it("labels each option with the backend displayLabel, matching the pre-5.1 text", async () => { + const server = await startManifestServer(); + try { + const url = `${server.baseUrl}/master.m3u8`; + const result = await api("getFormats", url); + assert.equal(result.ok, true, result.error?.message); + const formats = result.data.formats; + const byId = new Map(formats.map((format) => [format.formatId, format])); + + for (const [formatId, legacy] of Object.entries(LEGACY_LABELS)) { + const format = byId.get(formatId); + assert.ok(format, `manifest format ${formatId} was not listed`); + assert.equal( + format.displayLabel, + legacy, + `displayLabel for ${formatId}`, + ); + } + assert.equal(byId.get("128").streamKind, "audio"); + assert.equal(byId.get("300").streamKind, "video"); + assert.equal(byId.get("1200").streamKind, "audioVideo"); + + // Fixtures report no byte sizes, so no label may carry a size or "~". + for (const format of formats) { + assert.equal(typeof format.displayLabel, "string", format.formatId); + assert.ok( + format.displayLabel.startsWith(`ID: ${format.formatId}`), + format.displayLabel, + ); + assert.doesNotMatch( + format.displayLabel, + /~| (B|KB|MB|GB|TB|PB)$/, + format.displayLabel, + ); + } + + const clip = await api("getFormats", `${MEDIA}/clip-one.mp4`); + assert.equal(clip.ok, true, clip.error?.message); + const mp4 = clip.data.formats.find((format) => format.formatId === "mp4"); + assert.ok(mp4, "direct MP4 fixture was not listed"); + assert.equal(mp4.displayLabel, "ID: mp4 (video + audio)"); + + await setUrlAndFetch(url); + await browser.waitUntil( + async () => + browser.execute( + () => + !document + .getElementById("fetchFormatsBtn") + .classList.contains("loading"), + ), + { + timeout: 60_000, + timeoutMsg: "manifest format lookup did not finish", + }, + ); + const pickers = await readFormatPickers(); + for (const format of formats) { + const picker = + format.streamKind === "audio" ? pickers.audio : pickers.video; + const option = picker.find((entry) => entry.value === format.formatId); + assert.ok(option, `format ${format.formatId} has no picker option`); + assert.equal(option.text, format.displayLabel); + } + } finally { + await server.close(); + } + }); + + it("clears cancelled and stale replies before they can restore selections", async () => { + await browser.execute(() => { + window.__typedFormatsOriginalApi = { + getFormats: window.__ROSI_E2E__.api.getFormats, + cancelFormats: window.__ROSI_E2E__.api.cancelFormats, + }; + window.__typedFormatsPending = []; + window.__ROSI_E2E__.api.getFormats = () => + new Promise((resolve) => window.__typedFormatsPending.push(resolve)); + }); + + await setUrlAndFetch(`${MEDIA}/clip-one.mp4`); + await browser.waitUntil( + async () => + browser.execute(() => window.__typedFormatsPending?.length === 1), + { + timeout: 10_000, + timeoutMsg: "controlled format request did not start", + }, + ); + await browser.execute(() => + document.getElementById("fetchFormatsBtn").click(), + ); + await browser.execute(() => + window.__typedFormatsPending[0]({ + ok: true, + data: { + formats: [ + { + formatId: "stale-cancelled", + streamKind: "video", + vcodec: "avc1", + }, + ], + }, + }), + ); + await browser.waitUntil( + async () => + browser.execute(() => + [...document.getElementById("videoFormat").options].every( + (option) => option.value !== "stale-cancelled", + ), + ), + { + timeout: 10_000, + timeoutMsg: "cancelled reply restored a format option", + }, + ); + + await setUrlAndFetch(`${MEDIA}/clip-one.mp4`); + await browser.waitUntil( + async () => + browser.execute(() => window.__typedFormatsPending?.length === 2), + { + timeout: 10_000, + timeoutMsg: "second controlled format request did not start", + }, + ); + await browser.execute((value) => { + const input = document.getElementById("url"); + input.value = value; + input.dispatchEvent(new Event("input", { bubbles: true })); + }, `${MEDIA}/clip-two.mp4`); + await browser.execute(() => + window.__typedFormatsPending[1]({ + ok: true, + data: { + formats: [ + { formatId: "stale-url", streamKind: "audio", acodec: "mp4a" }, + ], + }, + }), + ); + await browser.waitUntil( + async () => + browser.execute(() => + [...document.getElementById("audioFormat").options].every( + (option) => option.value !== "stale-url", + ), + ), + { + timeout: 10_000, + timeoutMsg: "stale URL reply restored a format option", + }, + ); + const pickers = await readFormatPickers(); + assert.ok( + [...pickers.video, ...pickers.audio].every((option) => !option.value), + ); + }); + + it("shows explicit empty and failure states without usable selections", async () => { + await browser.execute(() => { + window.__ROSI_E2E__.api.getFormats = async () => ({ + ok: true, + data: { formats: [] }, + }); + }); + await setUrlAndFetch(`${MEDIA}/clip-one.mp4`); + await browser.waitUntil( + async () => + browser.execute( + () => + !document + .getElementById("fetchFormatsBtn") + .classList.contains("loading"), + ), + { timeout: 10_000, timeoutMsg: "empty format lookup did not finish" }, + ); + let pickers = await readFormatPickers(); + assert.equal(pickers.video[0].text, "No video formats found"); + assert.equal(pickers.audio[0].text, "No audio formats found"); + + await browser.execute(() => { + window.__ROSI_E2E__.api.getFormats = async () => ({ + ok: false, + error: { code: "INTERNAL_ERROR", message: "fixture failure" }, + }); + }); + await setUrlAndFetch(`${MEDIA}/clip-one.mp4`); + await browser.waitUntil( + async () => + browser.execute( + () => + !document + .getElementById("fetchFormatsBtn") + .classList.contains("loading"), + ), + { timeout: 10_000, timeoutMsg: "failed format lookup did not finish" }, + ); + pickers = await readFormatPickers(); + assert.equal(pickers.video[0].text, "Error loading formats"); + assert.equal(pickers.audio[0].text, "Error loading formats"); + assert.ok( + [...pickers.video, ...pickers.audio].every((option) => !option.value), + ); + }); +}); diff --git a/e2e/v5-fixes/ui-polish/failure-modes.md b/e2e/v5-fixes/ui-polish/failure-modes.md new file mode 100644 index 00000000..336496f2 --- /dev/null +++ b/e2e/v5-fixes/ui-polish/failure-modes.md @@ -0,0 +1,291 @@ +# UI polish failure modes + +This inventory is written before UI behavior changes. E2E acceptance should drive +the real renderer and native bridge, and leave a JSON report plus screenshots +whose source revision, dirty-file hashes, platform, and E2E binary hash are +recorded. A static renderer helper passing is not full-app acceptance. + +## Effective options and readiness + +1. **Summary disagrees with the selected profile.** Changing compatible, best + video, audio format, custom formats, or a saved preset can leave the summary + stale. Keep `#downloadOutputSummary` synchronized with visible controls. +2. **Profile summary is mistaken for resolved backend options.** A renderer + estimate cannot account for format availability, backend defaults, or + normalization. Label it as a profile preview until an API returns resolved + options; never imply it is the final command/options. +3. **Failed or delayed option resolution leaves old content visible.** A prior + request can finish after the URL or profile changes. Surface unavailable or + pending state and ignore stale responses. +4. **Invalid input has no actionable inline feedback.** Invalid URL, unsupported + custom format, and invalid subtitle language input must identify the field, + explain correction, expose `aria-invalid`/descriptions, and keep focus on + the failing control when submission is blocked. +5. **Readiness appears successful when prerequisites fail.** Missing runtime, + unavailable destination, or failed format lookup must not look like a + ready-to-download state. Keep the reason and next action visible. + +## Progress, outcomes, and queue + +6. **A terminal failure looks like successful completion.** Exercise complete, + failed, cancelled, and partial playlist success separately, including + conversion failure after a source file was retained. +7. **Saved outputs have no usable action.** For one and multiple output paths, + expose the right open/reveal action and report bridge failures without + silently claiming success. +8. **Activity re-render loses the user's place.** Filters, new entries, and + action completion must retain sensible keyboard focus and announce material + updates without announcing every progress tick. +9. **Queue state/action mismatch.** Pending, downloading, completed, failed, + and cancelled rows must present only valid actions; retry/requeue, remove, + reorder, and open-location errors must restore controls and explain failure. +10. **Queue refresh drops focus or context.** After progress snapshots or action + results replace rows, preserve focus by queue item/action identity when it + still exists and explain why disabled actions cannot run. +11. **Long paths and source URLs break the layout.** Very long filesystem paths, + URLs, titles, error messages, and multiple outputs must wrap or truncate + without covering actions or expanding past the viewport. + +## Settings and onboarding + +12. **Settings save failure looks saved.** Rejected or thrown saves must retain + the current values, show retryable feedback, and avoid false success; a + successful retry must clear the failure state. +13. **Section reset changes values before confirmation.** Cancel leaves values + untouched; confirm resets only that section; a save failure reports the + failure and keeps a retry path. +14. **Dependent controls are silently disabled.** Disabled options (for + example conversion under audio-only) explain the dependency in text that is + available to keyboard and assistive-technology users. +15. **Folder selection is cancelled or fails during setup.** Preserve the + existing destination, do not show a stale chosen path, and explain when + asking for a destination before each download is selected. +16. **Deno check or install fails, or setup is skipped.** Distinguish checking, + installed, unavailable, cancelled, and failed states; offer the right + install instructions/action; do not imply setup persisted when the save + failed; Skip must reset exactly its documented wizard settings. +17. **Modal/wizard exit loses keyboard control.** Escape confirmation, cancel, + save failure, and completion must keep focus trapped while open and restore + focus to the invoking control on close. + +## Viewport, theme, and accessibility matrix + +18. **Small window clips controls.** Exercise every theme at 900x560 and + 1200x900 with increased text scale; settings, queue actions, dialogs, and + wizard navigation must remain reachable without horizontal overflow. +19. **Theme or reduced-motion state lowers contrast or motion access.** Check + system, light, dark, and purple themes with keyboard focus, status/error + states, and `prefers-reduced-motion`; reduced motion must suppress + nonessential transitions while preserving state changes. +20. **Keyboard and screen-reader semantics regress.** Tab/Shift+Tab, Escape, + modal focus return, settings search/reset, wizard navigation, live status, + progress names/values, and action labels must remain operable and + understandable without a pointer. + +## Readiness hint, folder feedback, and long content (D1, D4 to D6) + +These rows were written before the code for them. The download readiness hint +is `#downloadReadiness`, placed after the Download button. The folder "Change…" +button is in the destination strip of the main panel (`#changeDownloadFolderBtn`), +not in the settings sidebar, so the feedback sits in that strip. + +5a. **Blocking readiness is silent next to Download.** With "Custom" formats and +no format selected, or an invalid playlist range, Download only shows a toast +or does nothing. The hint next to Download names the blocker and the next +action (select a format, fix the playlist range). Download stays enabled and +still refuses to start. +5b. **A failed runtime (Deno) check leaves no trace after startup.** The check +failure is a one-time modal. The hint next to Download keeps the reason and +the install-instructions next action until a later check succeeds. Not covered +by an E2E scenario: the check runs once at startup, and the harness cannot make +the bridge fail without a product test hook. The hint branch is therefore +unverified by E2E. +5c. **A failed effective-options lookup is shown only in the summary line.** The +hint repeats the reason and says Download still validates the options when it +starts, so the failure does not read as a ready state. +5d. **"Ask every time" off with no folder.** Decision: an empty folder is not a +blocker. `resolve_output_path` falls back to the Downloads directory, and the +readiness state is `ready` without `outputPath`. The Download button used to +open a folder picker in this case (`bind/download.ts`); it now sends no +`outputPath`, so Rust uses the Downloads directory, and the hint says so. +Scenario: `missing-folder-ask-off-uses-default`. +5e. **"Ask every time" on.** Decision: the folder is chosen per download, so the +hint says ROSI will ask where to save this download. It is informational, +not a blocker. Scenario: `ask-each-time-hint`. +5f. **Turning "Ask every time" off with no folder set gives no feedback.** The +switch changes nothing visible, and the next download's destination is not +explained. Decision: switching off with no folder opens the folder picker +(the same picker the old Download path used). A cancelled pick shows +`UI_MESSAGES.wizard.folderCancelled` in the folder strip, and a failed pick +shows `UI_MESSAGES.wizard.folderFailed`. The toggle keeps the user's choice. +Scenario: `ask-off-cancelled-folder-feedback`. +11a. **Long content overflows at 900x560.** A 400-character URL, output path, +title, and error text must wrap or truncate in the queue, activity, console, +and folder summary. No unclipped box may spill past its own width, clipped +boxes must stay inside their region, and the document must not scroll +horizontally. Scenario: `long-content-no-horizontal-overflow`. +15a. **Change folder cancel or failure is silent.** A cancelled pick returns +without feedback, and a thrown pick is an unhandled rejection. Both now show +the wizard strings (`folderCancelled` only while "Ask every time" is off, +matching the wizard, and `folderFailed` on a thrown pick). A successful pick +clears the feedback and updates the path, so no stale path is shown. +Scenario: `change-folder-cancelled-and-failed`. +D6. **`#queueStatusMessage` live-region attributes set at runtime.** The markup +in `src/index.html` already has `role="status"`, `aria-live="polite"`, and +`aria-atomic="true"`. The runtime copy in `src/rosiEngine.ts` is removed, so +the markup is the single source. Scenario: `queue-status-live-region-markup` +(checks the served `index.html` tag and the live DOM). + +## Activity focus, queue row errors, and screenshot evidence (D2, D3, D7) + +Written before the code for them. The D2 and D3 scenarios are in +`ui-polish-focus.spec.js` and drive a real queue item (`slow.mp4` holds it in +`downloading`; `clip-one.mp4` completes quickly). Where a scenario needs a +control that the renderer has already replaced, it clicks the detached element +the user had pressed, so the handler runs with the id it was rendered with. + +8a. **Activity re-render drops focus.** `renderActivity` replaces every row, so a +focused row action falls back to BODY on each `download-activity-update`. +Expected: focus returns to the same row's action, matched by the row id +(`data-activity-id`) and the action (`data-activity-action`). Scenario: +`activity-focus-retained-on-update`. +8b. **Announcements are missing or repeated.** New entries must be announced +once through a polite live region (`#activity-live-status`). A re-sent update +with no new entry and real `job-progress` ticks must not change it. Scenario: +`activity-announces-new-entries-once`. +9a. **Remove of a downloading item fails silently.** The backend refuses it with +`VALIDATION_ERROR` ("Cannot remove an actively downloading item."), but the +row shows only a toast and a status line. Expected: the message appears on +the row, the row still says Downloading, the clicked control is enabled and +not busy, and the row's other controls stay enabled. The inline message +does not outlive the state it describes. Scenario: +`queue-row-remove-error-inline`. +9b. **Open location failure is silent on the row.** An `openFileLocation` error +envelope shows only a toast. Expected: the message appears on the completed +row, its Open folder and Remove controls stay enabled. Scenario: +`queue-open-location-error-inline`. +18a. **Screenshots never reach the gate report.** `ui-polish.spec.js` wrote its +PNGs under its own artifact folder, and the v5-fixes pass did not receive +`ROSI_E2E_SCREENSHOTS`, so `report.screenshots` and `verifyScreenshots` only +covered `ui-screenshots`. Expected: the 12 ui-polish shots (4 themes at +900x560 and 1200x900, plus 900x560 at 125% text) are written to +`e2e/artifacts/screenshots/-/`, attached to the +`v5-fixes/ui-polish` scenario, listed in `report.screenshots`, and counted by +the release check next to the `ui-screenshots` shots. Scenario: +`theme-viewport-keyboard-layout` (gate report). +18b. **A release check that counts one scenario's shots would accept a gate with +the ui-polish shots missing.** `verifyFullE2eEvidence` must count the shots +of every screenshot scenario, so a missing ui-polish shot fails the same +count and name checks that cover `ui-screenshots`. Scenario: the existing +`scripts/security-release-repairs.test.mjs` release fixture. + +## Multi-spec area pass attaches to the wrong window (harness, H1 to H3) + +Written before the harness change. The `v5-fixes/ui-polish` area pass runs +`ui-polish-focus`, `ui-polish-readiness`, and `ui-polish.spec.js` as three +workers. The tauri-service launcher logs "Embedded WebDriver on port 4445 ... +is unreachable, restarting..." at each worker start, because the previous +worker's `after` hook has exited the app, so each spec file starts a fresh app. +A splash window (`create_splash`) and a hidden main window (`visible: false`) +exist at startup, but the splash theory was measured and refuted (see H1). + +H1. **Page reloads in the readiness spec stall or lose the main UI in a pass.** +Measured in `d1-area-diag-1.log` and `d1-area-diag-2.log`: at each scenario +start the session was on its only window (`handles=1`, `tauri://localhost`, +main UI present). The failures were 30 s WebDriver script timeouts and missing +`#url` or `window.__ROSI_E2E__.api` right after `browser.refresh()`, and each failure +followed a reload. No app process was alive 1 s after a worker's teardown, and +E2E builds disable the single-instance plugin, so neither is the cause. The +readiness spec was reduced to one reload, in `before()`; later scenarios drive +settings through the real controls, and the scenarios are ordered so each starts +from the state the previous one leaves. An in-place alternative (`saveSettings` +then a `settings-imported` event) was rejected: the renderer stays +`settings-unsaved` after an imported snapshot (`d1-area-5.log`). The root cause +of the reload stalls is in the Reload stall section below. Evidence that the fix holds: area passes +`d1-area-run-b.log`, `d1-area-run-c.log`, and `d1-area-run-d.log` each pass all +three spec files, 100% completed. +H2. **`bail: 1` ends the area pass after the first failing spec.** The later +spec files never run, so their evidence is missing. Expected: the gate fails +and names the first failing spec. Decision: keep `bail` (it is the release +gate's setting and changing it is out of scope); the fix is H1, not a retry. +H3. **Retried WebDriver errors look like test failures.** `WebDriverError` WARN +lines from polling predicates are not failures by themselves. Expected: a +scenario fails only on its own assertion, not on a retried poll error. + +## Reload stall (readiness spec, `reloadApp`) + +Cause: `browser.refresh()` is the trigger. The first `execute/sync` after a +refresh, which runs in the new document, sometimes did not return for the full +30 s script timeout. WDIO retried it and the retry worked, but in the area pass +the stall and its retry left later commands without `window.__ROSI_E2E__.api`, `#url`, or +the E2E hook. The WebKit reason for the stall is not confirmed. + +Evidence: a temporary probe (`ROSI_E2E_ONLY`, deleted after use) alternated +`browser.refresh()` with a deferred `location.reload()` 25 times in each mode. + +- Background: one 30 s stall, in the first execute after `refresh` (cycle 3). + No stall in 25 deferred reloads. +- Foreground: two 30 s stalls, both after `refresh`. No stall in 25 deferred + reloads. +- Probe logs: `oversee2/reload-probe-bg.json` and `reload-probe-fg.json` in the + scratchpad. The area diagnostics `d1-area-diag-1.log` and `d1-area-diag-2.log` + show the same timeouts and the later `window.__ROSI_E2E__.api` and `#url` errors. +- Not the cause: an open `` (zero before and after every reload) and + the background occlusion (the stall also happened in foreground). The ready + flag was true after every reload. + +Fix: `reloadApp` sets `__ROSI_E2E__.ready = false` and reloads with +`window.setTimeout(() => location.reload(), 50)`, the same pattern as +`state-updater.spec.js` and `updater-engine.spec.js`. It then waits for the +new document's ready flag before it checks the controls. The seven scenarios +that reloaded before commit 580d89c reload again. `before()` no longer reloads. + +Proof: `npm run test:e2e -- --group ui-polish` passed three times in a row +(logs `oversee2/reload-group-1.log`, `reload-group-2.log`, +`reload-group-3.log`). Each run passed all three spec files with no WebDriver +warnings. + +## E2E evidence requirements + +- Keep existing suite ownership and platform skip allowances. Add a + `ui-polish` feature group to `e2e/suites.json` without moving current specs. +- The UI group is targeted evidence (`fullSuite: false`); it cannot satisfy + release proof. Full release evidence still requires the canonical complete + suite and its fresh binary/report hashes. +- Capture screenshots for each required viewport/theme combination and a + machine-readable report with per-scenario outcomes. Distinguish discovered + cases from executed results and include failures rather than dropping them. +- Record source identity including dirty-file hashes as well as `HEAD`, the + platform, runner/tool versions, and the exact tested binary hash. + +## D0 triage of foreground failures (macOS, `ROSI_E2E_FOREGROUND=1`) + +Each row names the assertion, the verdict (spec assumption or product gap), +the reason, and the fix. Product-gap rows were written before their code change. + +| Row | Assertion | Verdict | Reason | Fix | +| --- | --------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| T1 | `effective-options-summary` (`:333`): summary never reaches `resolved` for a valid URL on a fresh profile | Product gap (rows 2 and 5) | `buildEffectiveOptionsReadiness` returns `destination` for an empty folder even when "Ask every time" is off. `resolve_output_path` (`download_options.rs`) falls back to the downloads directory in that case, and the renderer would still be blocked. Sending `outputPath: ""` would not work either: `resolve_value` lets a non-null override replace the fallback, and `validate_download_request` rejects an empty `outputPath`. Keep `destination` for "Ask every time" on, because the save location is chosen per download. | Renderer omits `outputPath` when the folder is empty and "Ask every time" is off, so Rust fills in the downloads directory. "Ask every time" on still reports `destination`. | +| T2 | `settings-section-reset-confirmation` (`:423`): focus not inside the reset prompt | Spec assumption | `showModal` moves focus into `#app-modal` in a `requestAnimationFrame` (`overlays.ts`). The spec reads focus in the first WebDriver round trip after `.active` is set, which can run before that frame. The product contract holds once the frame runs, so the spec must wait for focus, not assume it. | Spec waits for focus inside `#app-modal` (condition-based, 5 s). Product unchanged. | +| T3 | `keyboard-reset-escape-focus` (`:478`): reset button not keyboard focusable | Spec assumption (cascade of T2) | T2 fails before Cancel, so the reset prompt stays open. Its focus-in handler then pulls focus back into the prompt, so `focus()` on the reset button cannot stick. The sidebar uses `transform`, not `visibility`, so focus does not depend on the sidebar transition. | Fixed by T2 and by the sidebar-in-view wait in T5. | +| T4 | `dependent-controls-and-queue-focus` (`:586`): `execute/async` timeout on the first `addToQueue` | Open. Not yet classified as spec or product | The timeout is on the first add (`firstUrl`), not the second, so the plan's wording is off. `add_to_queue` waits for the coordinator, and admission does not start the queue (`startQueue` is explicit). The scenario uses live youtube.com URLs, and the earlier effective-options scenario typed a youtube URL that schedules an auto `getVideoInfo` (450 ms debounce) which the spec never cancels. That lookup is the leading hypothesis for the hang, not confirmed. `src-tauri/` is out of scope for this task. | Not reproduced in the passing foreground run (`2026-11-07T05-44-49-412Z-26812`). No code change was made for it. Root cause unconfirmed, and the earlier timeout may be intermittent. | +| T5 | `theme-viewport-keyboard-layout` (`:789`): `settingsSearch` not focused | Spec assumption (cascade of T2, plus a timing gap) | The prompt left open by T2 keeps focus trapped, so `settingsSearch.focus()` lands on a prompt button with no id. Separately, `setSidebarOpen(true)` returns once the `open` class is set, before the sidebar has finished sliding into view. | Spec waits for the sidebar to be fully in view, then focuses. | +| T6 | `queue refresh stole focused action` (`:644`) and focus trap Tab (`:485`) | Background-only, see T8 and T9 | Background mode only. The focus trap failure is explained by T8. The queue failure did not reproduce in the background run recorded under T9. | See T8 and T9. | + +## Background-mode triage (macOS, `ROSI_E2E_BACKGROUND=1`, the local default) + +Background mode runs the E2E app below other windows, so the page is occluded. +The probe run (`e2e/v5-fixes/ui-polish/zz-diag-probe.spec.js`, deleted after +use) measured the page state in that mode: `document.visibilityState` is +`hidden`, `document.hasFocus()` is `false`, no `requestAnimationFrame` callback +ran within 2 s, and the sidebar's transform transition stayed `running` at +`currentTime` 0 with `getBoundingClientRect().left` at -372 while the `open` +class was set. `element.focus()` still updates `document.activeElement`, `focusin` +still fires, and a WebDriver `Tab` still arrives as a synthetic, untrusted +`keydown` that does not move focus natively. + +| Row | Assertion | Verdict | Reason | Fix | +| --- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| T7 | `settings sidebar did not finish opening` (`setSidebarOpen`, `:215`) in `settings-section-reset-confirmation`, `keyboard-reset-escape-focus`, `settings-save-retry`, `theme-viewport-keyboard-layout` (gate run `2026-11-07T06-05-11-941Z-57407`, repro `2026-11-07T06-24-04-258Z`) | Spec assumption (background mode only) | The spec waits for the sidebar's 500 ms transform transition to rest. WebKit does not advance CSS transitions in a hidden page (probe above), so the rest check can only pass in foreground, where frames run. Nothing in the product is stuck: the `open` class is set and the transition would finish once the window is visible. | The spec finishes the sidebar's running animations (`Animation.finish()`) before the rest check, only when `document.visibilityState` is not `visible`. The rest check and its 10 s timeout stay. Foreground still waits for the real transition. Product unchanged. | +| T8 | `focus did not move into the open prompt` (`waitForModalFocus`) and `Tab moved focus out of the reset prompt` (`:485`); focus stays on BODY | Product gap (frame dependency), reachable by users at sub-frame timing | `showModal` (`src/engine/overlays.ts`) moves initial focus into the prompt only inside `requestAnimationFrame`. A hidden page runs no frames, so focus stays on BODY. The Tab trap only moves focus when the active element is the first or last control, so with focus on BODY it does nothing. The gap also exists in a visible window: until the next frame, keys go to BODY and outside the prompt's keydown trap. Focus behavior does not depend on `hasFocus()`: `focus()` and `focusin` work in the probe, so the trap logic itself is not the problem. Control run (T7 spec fix kept, this product change reverted): both `waitForModalFocus` checks failed with "focus did not move into the open prompt", so the product change is required for this assertion. Not covered by this change: a click on non-focusable prompt text also leaves focus on BODY, where the modal's keydown trap does not see Tab. This was not reproduced here. | Product: `showModal` moves focus into the prompt synchronously once its buttons are in place. The `requestAnimationFrame` call stays as a fallback that only moves focus when focus is still outside the prompt, so it cannot steal focus from a control the user already reached. Spec assertions unchanged. | +| T9 | `queue refresh stole focused action` (`:644`) | Cascade of T8, not a separate product gap | The earlier background run `2026-11-07T04-41-27-508Z-91968` failed the reset prompt checks (T8) before this check. The control run with T8 reverted failed it only after the reset prompt stayed open, which keeps the main content inert and blocks focus. With T8 in place it passed in every background run after the T7 fix (`2026-11-07T06-24-04-258Z` and the two that followed) and in the foreground run `2026-11-07T05-44-49-412Z-26812`. The queue render path has no frame-based focus restore (no `requestAnimationFrame` in `src/modules/queue.ts`). | No change of its own. The fix is T8. If it fails with the T8 fix in place, record the row here before changing code. | diff --git a/e2e/v5-fixes/ui-polish/ui-polish-focus.spec.js b/e2e/v5-fixes/ui-polish/ui-polish-focus.spec.js new file mode 100644 index 00000000..8d3d4ba0 --- /dev/null +++ b/e2e/v5-fixes/ui-polish/ui-polish-focus.spec.js @@ -0,0 +1,595 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import crypto from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "../../helpers/app-bridge.js"; +import { REPO_ROOT } from "../../helpers/profile.js"; + +const MEDIA = process.env.ROSI_E2E_MEDIA_URL; + +const stamp = new Date() + .toISOString() + .replaceAll(":", "-") + .replaceAll(".", "-"); +const artifactDir = path.join( + REPO_ROOT, + "e2e", + "artifacts", + "v5-fixes-ui-polish", + `${stamp}-focus-${process.pid}`, +); +const reportPath = path.join(artifactDir, "report.json"); +const report = { + suite: "v5-fixes-ui-polish-focus", + startedAt: new Date().toISOString(), + platform: process.platform, + arch: process.arch, + runtime: { node: process.version }, + source: null, + checks: [], +}; + +const sha256 = (value) => + crypto.createHash("sha256").update(value).digest("hex"); + +// Source identity for this report: HEAD, a hash of the tracked diff, and the +// hash of each untracked file. Enough to tell which working tree produced it. +function sourceIdentity() { + const head = execFileSync("git", ["rev-parse", "HEAD"], { + cwd: REPO_ROOT, + encoding: "utf8", + }).trim(); + const diff = execFileSync("git", ["diff", "HEAD", "--binary"], { + cwd: REPO_ROOT, + maxBuffer: 256 * 1024 * 1024, + }); + const untracked = execFileSync( + "git", + ["ls-files", "--others", "--exclude-standard"], + { cwd: REPO_ROOT, encoding: "utf8" }, + ) + .split("\n") + .filter(Boolean) + .sort(); + return { + head, + workingTree: + diff.length === 0 && untracked.length === 0 ? "clean" : "dirty", + dirtyPatchSha256: sha256(diff), + untrackedFiles: untracked.map((file) => ({ + path: file, + sha256: sha256(fs.readFileSync(path.join(REPO_ROOT, file))), + })), + }; +} + +function writeReport() { + fs.mkdirSync(artifactDir, { recursive: true }); + const contents = `${JSON.stringify(report, null, 2)}\n`; + const temporaryPath = `${reportPath}.tmp`; + fs.writeFileSync(temporaryPath, contents); + fs.renameSync(temporaryPath, reportPath); + fs.writeFileSync( + `${reportPath}.sha256`, + `${sha256(contents)} report.json\n`, + ); +} + +async function scenario(name, body) { + try { + const details = await body(); + report.checks.push({ name, status: "passed", ...details }); + writeReport(); + } catch (error) { + report.checks.push({ + name, + status: "failed", + reason: error instanceof Error ? error.message : String(error), + }); + writeReport(); + throw error; + } +} + +async function waitFor( + predicate, + message, + timeout = 10_000, + argument = undefined, +) { + await browser.waitUntil(async () => browser.execute(predicate, argument), { + timeout, + interval: 100, + timeoutMsg: message, + }); +} + +async function selectDock(tab) { + await browser.execute( + (name) => window.__ROSI_E2E__.modules.dock.selectTab(name), + tab, + ); +} + +async function waitForQueueItemStatus(url, status, message, timeout = 60_000) { + await browser.waitUntil( + async () => + (await api("getQueue")).some( + (item) => item.url === url && item.status === status, + ), + { timeout, interval: 250, timeoutMsg: message }, + ); +} + +async function resetQueue() { + await api("cancelQueue"); + assert.equal((await api("clearQueue")).ok, true); +} + +// Records each change to the activity live region and each job-progress tick +// the page receives, so the flow can check announcements against ticks. +function installActivityProbe() { + const region = document.getElementById("activity-live-status"); + if (!region) throw new Error("activity live region is missing"); + window.__uiPolishFocusProbe?.stop(); + const probe = { + announcements: [], + ticks: 0, + observer: null, + unsubscribe: null, + stop() { + probe.observer?.disconnect(); + probe.unsubscribe?.(); + }, + }; + probe.observer = new MutationObserver(() => { + probe.announcements.push(region.textContent.trim()); + }); + probe.observer.observe(region, { + childList: true, + characterData: true, + subtree: true, + }); + probe.unsubscribe = window.__ROSI_E2E__.api.onJobProgress(() => { + probe.ticks += 1; + }); + window.__uiPolishFocusProbe = probe; +} + +function activitySnapshot() { + return browser.execute(() => { + const probe = window.__uiPolishFocusProbe; + const focused = document.activeElement; + return { + announcements: [...probe.announcements], + ticks: probe.ticks, + focus: { + rowId: focused?.closest(".history-item")?.dataset.activityId ?? null, + action: focused?.dataset?.activityAction ?? null, + }, + liveText: + document.getElementById("activity-live-status")?.textContent.trim() ?? + null, + }; + }); +} + +async function runActivityFlow(observed) { + await selectDock("activity"); + await browser.execute(installActivityProbe); + + // A finished download becomes a real activity entry, so the row survives the + // later re-renders that come from the backend. + const seedUrl = `${MEDIA}/clip-one.mp4?ui-polish-focus=seed`; + assert.equal((await api("addToQueue", [seedUrl])).data.added, 1); + assert.equal((await api("startQueue")).ok, true); + await waitForQueueItemStatus( + seedUrl, + "completed", + "seed download did not complete", + ); + const seed = (await api("getDownloadActivity")).data.find( + (entry) => entry.url === seedUrl, + ); + assert.ok(seed, "seed download is missing from the activity log"); + observed.seedId = seed.id; + await waitFor( + (id) => + [...document.querySelectorAll(".history-item")].some( + (row) => row.dataset.activityId === id, + ), + "seed activity row did not render", + 8_000, + seed.id, + ); + observed.afterSeed = await activitySnapshot(); + + await browser.execute((id) => { + const row = [...document.querySelectorAll(".history-item")].find( + (candidate) => candidate.dataset.activityId === id, + ); + const copy = row?.querySelector('[data-activity-action="copy"]'); + if (!copy) throw new Error("seed row has no copy action"); + copy.focus(); + }, seed.id); + observed.focused = await activitySnapshot(); + + // Progress ticks from a running item must not touch the activity list. + const slowUrl = `${MEDIA}/slow.mp4?ui-polish-focus=progress`; + assert.equal((await api("addToQueue", [slowUrl])).data.added, 1); + assert.equal((await api("startQueue")).ok, true); + await waitFor( + () => window.__uiPolishFocusProbe.ticks >= 3, + "job-progress ticks did not reach the page", + 60_000, + ); + observed.duringProgress = await activitySnapshot(); + + // Cancelling the run records a new activity entry, which must be announced once. + assert.equal((await api("cancelQueue")).ok, true); + await waitFor( + () => window.__uiPolishFocusProbe.announcements.length >= 2, + "cancelled activity entry was not announced", + 20_000, + ); + await browser.pause(500); + observed.afterCancel = await activitySnapshot(); + + // A re-sent update with no new entry is a re-render only. + const latest = (await api("getDownloadActivity")).data; + await browser.execute((list) => { + window.__TAURI__.event.emit("download-activity-update", list); + }, latest); + await browser.pause(300); + observed.afterResend = await activitySnapshot(); +} + +describe("ROSI UI polish focus and row errors", () => { + before(async () => { + await waitForAppReady(); + report.source = sourceIdentity(); + writeReport(); + }); + + beforeEach(async () => { + await resetQueue(); + }); + + after(async () => { + report.completedAt = new Date().toISOString(); + report.passed = report.checks.filter( + (check) => check.status === "passed", + ).length; + report.failed = report.checks.filter( + (check) => check.status === "failed", + ).length; + report.result = + report.failed === 0 && report.checks.length > 0 ? "passed" : "failed"; + writeReport(); + }); + + it("keeps activity focus across updates and announces each new entry once", async () => { + const observed = {}; + let flowError = null; + try { + await runActivityFlow(observed); + } catch (error) { + flowError = error; + } finally { + await browser + .execute(() => { + window.__uiPolishFocusProbe?.stop(); + delete window.__uiPolishFocusProbe; + }) + .catch(() => {}); + await api("cancelQueue").catch(() => {}); + await api("clearQueue").catch(() => {}); + } + + let failed = false; + try { + await scenario("activity-focus-retained-on-update", async () => { + const expected = { rowId: observed.seedId, action: "copy" }; + for (const stage of [ + "focused", + "duringProgress", + "afterCancel", + "afterResend", + ]) { + assert.deepEqual( + observed[stage]?.focus, + expected, + `focus left the row action at ${stage}`, + ); + } + return { focusedRow: observed.seedId, stages: 4 }; + }); + } catch { + failed = true; + } + try { + await scenario("activity-announces-new-entries-once", async () => { + assert.ok(observed.afterSeed, "the seed download was never observed"); + assert.equal( + observed.afterSeed.announcements.length, + 1, + "a new entry was not announced exactly once", + ); + assert.ok( + observed.duringProgress.ticks >= 3, + "too few progress ticks to test against", + ); + assert.equal( + observed.duringProgress.announcements.length, + 1, + "progress ticks changed the live region", + ); + assert.equal( + observed.afterCancel.announcements.length, + 2, + "the cancelled entry was not announced exactly once", + ); + assert.notEqual( + observed.afterCancel.liveText, + observed.afterSeed.liveText, + "the live region did not change for the new entry", + ); + assert.equal( + observed.afterResend.announcements.length, + 2, + "a re-sent update without a new entry was announced", + ); + return { + announcementsAfterSeed: observed.afterSeed.announcements.length, + progressTicks: observed.duringProgress.ticks, + announcementsAfterCancel: observed.afterCancel.announcements.length, + }; + }); + } catch { + failed = true; + } + if (flowError) throw flowError; + if (failed) throw new Error("activity focus or announcement checks failed"); + }); + + it("shows a refused remove of a downloading item inline on its row", async () => { + await scenario("queue-row-remove-error-inline", async () => { + const slow = `${MEDIA}/slow.mp4?ui-polish-focus=remove`; + const pendingB = `${MEDIA}/clip-two.mp4?ui-polish-focus=remove-b`; + const pendingC = `${MEDIA}/clip-three.mp4?ui-polish-focus=remove-c`; + assert.equal( + (await api("addToQueue", [slow, pendingB, pendingC])).data.added, + 3, + ); + const queue = await api("getQueue"); + const idFor = (url) => queue.find((item) => item.url === url).id; + const slowId = idFor(slow); + const bId = idFor(pendingB); + const cId = idFor(pendingC); + await waitFor( + (ids) => + ids.every((id) => + [...document.querySelectorAll(".queue-item")].some( + (row) => row.dataset.queueId === id, + ), + ), + "queue rows did not render", + 8_000, + [slowId, bId, cId], + ); + // The Remove button the user sees while the item is still pending. + await browser.execute((id) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === id, + ); + const remove = row?.querySelector( + '[data-queue-action="queue-item-remove"]', + ); + if (!remove) throw new Error("pending row has no Remove control"); + window.__uiPolishStaleRemove = remove; + }, slowId); + + assert.equal((await api("startQueue")).ok, true); + await waitFor( + (id) => + [...document.querySelectorAll(".queue-item")] + .find((row) => row.dataset.queueId === id) + ?.classList.contains("queue-downloading") === true, + "active item did not show as downloading", + 60_000, + slowId, + ); + // The renderer has replaced that row, so the click runs the handler of the + // control the user pressed, with the id it was rendered with, against the + // item the backend is now downloading. + await browser.execute(() => window.__uiPolishStaleRemove.click()); + await waitFor( + (id) => + Boolean( + [...document.querySelectorAll(".queue-item")] + .find((row) => row.dataset.queueId === id) + ?.querySelector(".queue-item-error"), + ), + "refusal was not shown on the row", + 10_000, + slowId, + ); + + const activeRow = await browser.execute((id) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === id, + ); + return { + status: row.querySelector(".queue-item-meta")?.textContent.trim(), + refusal: row.querySelector(".queue-item-error")?.textContent.trim(), + hasRemove: Boolean( + row.querySelector('[data-queue-action="queue-item-remove"]'), + ), + }; + }, slowId); + assert.match(activeRow.status ?? "", /downloading/i); + assert.match(activeRow.refusal ?? "", /actively downloading/i); + assert.equal( + activeRow.hasRemove, + false, + "a downloading row offers Remove", + ); + + // The control that was clicked is enabled again and not busy. + await waitFor( + () => + !window.__uiPolishStaleRemove.disabled && + !window.__uiPolishStaleRemove.hasAttribute("aria-busy"), + "clicked control stayed disabled after the refusal", + ); + + // The pending rows keep every action they had, and show no error. + const others = await browser.execute( + (ids) => + ids.map((id) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === id, + ); + const enabled = (action) => { + const button = row.querySelector( + `[data-queue-action="${action}"]`, + ); + return button ? !button.disabled : null; + }; + return { + hasRefusal: Boolean(row.querySelector(".queue-item-error")), + up: enabled("queue-item-move-up"), + down: enabled("queue-item-move-down"), + remove: enabled("queue-item-remove"), + }; + }), + [bId, cId], + ); + assert.deepEqual(others[0], { + hasRefusal: false, + up: false, + down: true, + remove: true, + }); + assert.deepEqual(others[1], { + hasRefusal: false, + up: true, + down: false, + remove: true, + }); + + // Once the item leaves Downloading the inline message no longer applies. + assert.equal((await api("cancelQueue")).ok, true); + await waitFor( + (id) => + [...document.querySelectorAll(".queue-item")] + .find((row) => row.dataset.queueId === id) + ?.classList.contains("queue-cancelled") === true, + "cancelled item did not render as cancelled", + 20_000, + slowId, + ); + const finished = await browser.execute((id) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === id, + ); + return { + hasRefusal: Boolean(row.querySelector(".queue-item-error")), + requeue: Boolean( + row.querySelector('[data-queue-action="queue-item-retry"]'), + ), + }; + }, slowId); + assert.deepEqual(finished, { hasRefusal: false, requeue: true }); + return { + refusal: activeRow.refusal, + otherRowsEnabled: true, + }; + }); + }); + + it("shows a refused open-location on the completed row inline", async () => { + await scenario("queue-open-location-error-inline", async () => { + const url = `${MEDIA}/clip-one.mp4?ui-polish-focus=open`; + assert.equal((await api("addToQueue", [url])).data.added, 1); + const id = (await api("getQueue")).find((item) => item.url === url).id; + assert.equal((await api("startQueue")).ok, true); + await waitForQueueItemStatus( + url, + "completed", + "open-location item did not complete", + ); + await waitFor( + (target) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === target, + ); + return Boolean( + row?.classList.contains("queue-completed") && + row.querySelector('[data-queue-action="queue-item-open"]'), + ); + }, + "completed row has no Open folder control", + 10_000, + id, + ); + + // Refuse the native call so the row path runs without a file manager. + await browser.execute(() => { + window.__uiPolishOriginalOpen = + window.__ROSI_E2E__.api.openFileLocation; + window.__ROSI_E2E__.api.openFileLocation = async () => ({ + ok: false, + error: { code: "NOT_AVAILABLE", message: "Test location refusal." }, + }); + }); + try { + await browser.execute((target) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === target, + ); + row.querySelector('[data-queue-action="queue-item-open"]').click(); + }, id); + await waitFor( + (target) => + [...document.querySelectorAll(".queue-item")] + .find((row) => row.dataset.queueId === target) + ?.querySelector(".queue-item-error") + ?.textContent.includes("Test location refusal.") === true, + "open-location refusal was not shown on the row", + 10_000, + id, + ); + } finally { + await browser.execute(() => { + if (window.__uiPolishOriginalOpen) { + window.__ROSI_E2E__.api.openFileLocation = + window.__uiPolishOriginalOpen; + delete window.__uiPolishOriginalOpen; + } + }); + } + + const row = await browser.execute((target) => { + const element = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === target, + ); + const open = element.querySelector( + '[data-queue-action="queue-item-open"]', + ); + const remove = element.querySelector( + '[data-queue-action="queue-item-remove"]', + ); + return { + openEnabled: + Boolean(open) && !open.disabled && !open.hasAttribute("aria-busy"), + removeEnabled: Boolean(remove) && !remove.disabled, + }; + }, id); + assert.deepEqual(row, { openEnabled: true, removeEnabled: true }); + return { openEnabled: row.openEnabled, removeEnabled: row.removeEnabled }; + }); + }); +}); diff --git a/e2e/v5-fixes/ui-polish/ui-polish-readiness.spec.js b/e2e/v5-fixes/ui-polish/ui-polish-readiness.spec.js new file mode 100644 index 00000000..d13487cc --- /dev/null +++ b/e2e/v5-fixes/ui-polish/ui-polish-readiness.spec.js @@ -0,0 +1,1001 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import crypto from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "../../helpers/app-bridge.js"; +import { e2eBinaryPath, REPO_ROOT } from "../../helpers/profile.js"; + +// Readiness hint next to Download, folder feedback, long content, and the +// queue live-region markup. Failure modes: ui-polish/failure-modes.md rows 5a to 5f, +// 11a, 15a, and D6. + +const MEDIA = process.env.ROSI_E2E_MEDIA_URL; +const CLIP_BASE = MEDIA || "https://example.test"; +// The E2E app only accepts download folders inside its profile (its home), so folder +// fixtures live under the profile's downloads folder, not the repository. +const DOWNLOADS = process.env.ROSI_E2E_DOWNLOADS; +const FOLDERS = DOWNLOADS ? path.join(DOWNLOADS, "rosi-readiness") : null; + +const stamp = new Date() + .toISOString() + .replaceAll(":", "-") + .replaceAll(".", "-"); +const artifactDir = path.join( + REPO_ROOT, + "e2e", + "artifacts", + "v5-fixes-ui-polish-readiness", + `${stamp}-${process.pid}`, +); +const screenshotDir = path.join(artifactDir, "screenshots"); +const reportPath = path.join(artifactDir, "report.json"); +const report = { + suite: "v5-fixes-ui-polish-readiness", + startedAt: new Date().toISOString(), + platform: process.platform, + arch: process.arch, + runtime: { node: process.version }, + source: null, + binary: null, + checks: [], + screenshots: [], +}; + +// Copied from ui-polish.spec.js on purpose: that spec belongs to another worker. +const sha256 = (value) => + crypto.createHash("sha256").update(value).digest("hex"); + +function sourceIdentity() { + const head = execFileSync("git", ["rev-parse", "HEAD"], { + cwd: REPO_ROOT, + encoding: "utf8", + }).trim(); + const trackedChanges = execFileSync( + "git", + ["diff", "HEAD", "--name-only", "-z"], + { cwd: REPO_ROOT, encoding: "buffer" }, + ) + .toString() + .split("\0") + .filter(Boolean); + const untracked = execFileSync( + "git", + ["ls-files", "--others", "--exclude-standard", "-z"], + { cwd: REPO_ROOT, encoding: "buffer" }, + ) + .toString() + .split("\0") + .filter(Boolean); + const dirtyFiles = [...new Set([...trackedChanges, ...untracked])] + .sort() + .map((relativePath) => { + const filePath = path.join(REPO_ROOT, relativePath); + return { + path: relativePath.replaceAll(path.sep, "/"), + sha256: + fs.existsSync(filePath) && fs.statSync(filePath).isFile() + ? sha256(fs.readFileSync(filePath)) + : null, + }; + }); + const dirtyFingerprint = dirtyFiles + .map((file) => `${file.path}\0${file.sha256 ?? "deleted"}`) + .join("\n"); + return { + head, + workingTree: dirtyFiles.length === 0 ? "clean" : "dirty", + dirtyFiles, + dirtyFingerprintSha256: sha256(dirtyFingerprint), + }; +} + +function writeReport() { + fs.mkdirSync(screenshotDir, { recursive: true }); + const contents = `${JSON.stringify(report, null, 2)}\n`; + const temporaryPath = `${reportPath}.tmp`; + fs.writeFileSync(temporaryPath, contents); + fs.renameSync(temporaryPath, reportPath); + fs.writeFileSync( + `${reportPath}.sha256`, + `${sha256(contents)} report.json\n`, + ); +} + +async function scenario(name, body) { + try { + const details = await body(); + report.checks.push({ name, status: "passed", ...details }); + writeReport(); + } catch (error) { + report.checks.push({ + name, + status: "failed", + reason: error instanceof Error ? error.message : String(error), + }); + writeReport(); + throw error; + } +} + +async function clickById(id) { + await browser.execute((target) => { + const element = document.getElementById(target); + if (!element) throw new Error(`missing element ${target}`); + element.click(); + }, id); +} + +async function setControl(id, value) { + await browser.execute( + (target, next) => { + const control = document.getElementById(target); + if (!control) throw new Error(`missing control ${target}`); + if (control.type === "checkbox") control.checked = Boolean(next); + else control.value = String(next); + control.dispatchEvent(new Event("change", { bubbles: true })); + }, + id, + value, + ); +} + +async function setUrl(value) { + await browser.execute((next) => { + const url = document.getElementById("url"); + url.value = next; + url.dispatchEvent(new Event("input", { bubbles: true })); + }, value); +} + +async function waitFor( + predicate, + message, + timeout = 10_000, + argument = undefined, +) { + await browser.waitUntil(async () => browser.execute(predicate, argument), { + timeout, + interval: 100, + timeoutMsg: message, + }); +} + +/** + * Reload the page and wait until its controls and bridge are installed. + * Uses a deferred location.reload, like the other reloading specs. WebDriver + * refresh left the next script waiting for the full 30 s script timeout. + */ +async function reloadApp() { + await browser.execute(() => { + window.__ROSI_E2E__.ready = false; + window.setTimeout(() => window.location.reload(), 50); + }); + // Waits for the new document: the old page still has the bridge until it unloads. + await waitForAppReady(); + await browser.waitUntil( + () => + browser.execute( + () => + document.readyState === "complete" && + typeof window.__ROSI_E2E__?.api?.resolveDownloadOptions === + "function" && + typeof window.__ROSI_E2E__?.api?.addToQueue === "function" && + Boolean(document.getElementById("profileCustomBtn")) && + Boolean(document.getElementById("downloadBtn")), + ), + { + timeout: 60_000, + timeoutMsg: "reloaded page never rendered the main window controls", + }, + ); +} + +/** Save folder-related settings through the API, then reload so the renderer reads them. */ +async function setFolderSettings(settings) { + const saved = await api("saveSettings", { + downloadMode: "compatible", + advancedOptions: false, + bestQuality: false, + audioOnly: false, + showConsoleOutput: true, + ...settings, + }); + assert.equal(saved.ok, true, saved.error?.message); + await reloadApp(); +} + +async function readHint() { + return browser.execute(() => { + const hint = document.getElementById("downloadReadiness"); + return { + text: hint?.textContent.trim() ?? "", + hidden: hint?.hidden ?? true, + tone: hint?.dataset.tone ?? null, + describedBy: + document + .getElementById("downloadBtn") + ?.getAttribute("aria-describedby") ?? null, + }; + }); +} + +async function waitForSummaryState(state, timeout = 10_000) { + try { + await waitFor( + (want) => + document.getElementById("downloadOutputSummary")?.dataset.state === + want, + `effective options never reached ${state}`, + timeout, + state, + ); + } catch (error) { + const seen = await browser.execute(() => ({ + summary: + document.getElementById("downloadOutputSummary")?.dataset.state ?? null, + text: + document.getElementById("downloadOutputSummary")?.textContent.trim() ?? + "", + save: + document.getElementById("settingsSaveFeedback")?.dataset.state ?? null, + ask: + document.getElementById("askDownloadLocationToggle")?.checked ?? null, + folder: + document.getElementById("downloadFolderSummary")?.textContent.trim() ?? + "", + })); + throw new Error(`${error.message}; saw ${JSON.stringify(seen)}`); + } +} + +/** Record calls to the download bridge and refuse to start a real download. */ +async function stubDownloadVideo() { + await browser.execute(() => { + window.__uiReadinessDownloadCalls = []; + window.__uiReadinessOriginalDownloadVideo = + window.__ROSI_E2E__.api.downloadVideo; + window.__ROSI_E2E__.api.downloadVideo = async (options) => { + window.__uiReadinessDownloadCalls.push( + JSON.parse(JSON.stringify(options)), + ); + return { + ok: false, + error: { + code: "INTERNAL_ERROR", + message: "Download start stubbed by the readiness scenario", + }, + }; + }; + }); +} + +async function downloadCalls() { + return browser.execute(() => window.__uiReadinessDownloadCalls?.length ?? 0); +} + +async function restoreDownloadVideo() { + await browser.execute(() => { + if (window.__uiReadinessOriginalDownloadVideo) { + window.__ROSI_E2E__.api.downloadVideo = + window.__uiReadinessOriginalDownloadVideo; + } + delete window.__uiReadinessOriginalDownloadVideo; + }); +} + +/** Replace the folder picker. Mode "cancel" returns null, "fail" throws, "path" returns the fixture. */ +async function setPicker(mode, fixturePath = "") { + await browser.execute( + (nextMode, nextPath) => { + if (!window.__uiReadinessPicker) { + const state = { + original: window.__ROSI_E2E__.api.selectDownloadLocation, + calls: 0, + mode: "cancel", + fixturePath: "", + }; + window.__uiReadinessPicker = state; + window.__ROSI_E2E__.api.selectDownloadLocation = async () => { + state.calls += 1; + if (state.mode === "fail") throw new Error("stub picker failure"); + if (state.mode === "cancel") return null; + return state.fixturePath; + }; + } + window.__uiReadinessPicker.mode = nextMode; + window.__uiReadinessPicker.fixturePath = nextPath; + }, + mode, + fixturePath, + ); +} + +async function pickerCalls() { + return browser.execute(() => window.__uiReadinessPicker?.calls ?? 0); +} + +async function restorePicker() { + await browser.execute(() => { + if (window.__uiReadinessPicker) { + window.__ROSI_E2E__.api.selectDownloadLocation = + window.__uiReadinessPicker.original; + delete window.__uiReadinessPicker; + } + }); +} + +/** The folder the backend stored, so a pick that only changed the UI fails here. */ +async function persistedFolder() { + const result = await api("getSettings"); + const settings = result?.data ?? result; + return settings?.downloadFolder ?? ""; +} + +async function folderFeedback() { + return browser.execute(() => { + const feedback = document.getElementById("downloadFolderFeedback"); + return { + text: feedback?.textContent.trim() ?? "", + hidden: feedback?.hidden ?? true, + }; + }); +} + +async function saveScreenshotFor(name, theme) { + const destination = path.join(screenshotDir, name); + await browser.saveScreenshot(destination); + report.screenshots.push({ + path: path.relative(artifactDir, destination).replaceAll(path.sep, "/"), + sha256: sha256(fs.readFileSync(destination)), + theme, + }); +} + +/** + * Find overflow inside the given regions. Clipped boxes (overflow other than + * visible) truncate by design, so they must stay inside their region's box. + * Unclipped boxes must not have content that spills past their own box. + */ +async function measureRegions(selectors) { + return browser.execute((targets) => { + const violations = []; + const docOverflow = + document.documentElement.scrollWidth - window.innerWidth; + if (docOverflow > 1) { + violations.push({ + selector: "document", + reason: `scrolls ${docOverflow}px wide`, + }); + } + const checked = []; + for (const selector of targets) { + const region = document.querySelector(selector); + if (!region || region.getClientRects().length === 0) { + violations.push({ selector, reason: "region not rendered" }); + continue; + } + const regionRect = region.getBoundingClientRect(); + if (regionRect.right > window.innerWidth + 1) { + violations.push({ + selector, + reason: "region extends past the viewport", + }); + } + const nodes = [region, ...region.querySelectorAll("*")]; + for (const node of nodes) { + if (node.getClientRects().length === 0) continue; + const style = getComputedStyle(node); + checked.push(selector); + if (style.overflowX === "visible") { + if (node.scrollWidth > node.clientWidth + 1) { + violations.push({ + selector, + tag: node.tagName.toLowerCase(), + className: String(node.className), + reason: `content spills ${node.scrollWidth - node.clientWidth}px past its box`, + }); + } + } else { + const box = node.getBoundingClientRect(); + if (box.right > regionRect.right + 1) { + violations.push({ + selector, + tag: node.tagName.toLowerCase(), + className: String(node.className), + reason: "clipped box extends past its region", + }); + } + } + } + } + return { + violations, + nodesChecked: checked.length, + documentOverflowPx: Math.max(0, docOverflow), + }; + }, selectors); +} + +describe("ROSI UI readiness, folder feedback, and long content", () => { + let originalWindowSize = null; + + before(async () => { + fs.mkdirSync(screenshotDir, { recursive: true }); + assert.ok(DOWNLOADS, "ROSI_E2E_DOWNLOADS is required for folder fixtures"); + fs.mkdirSync(FOLDERS, { recursive: true }); + await waitForAppReady(); + report.source = sourceIdentity(); + const binaryPath = e2eBinaryPath(); + report.binary = { + path: path.relative(REPO_ROOT, binaryPath).replaceAll(path.sep, "/"), + sha256: fs.existsSync(binaryPath) + ? sha256(fs.readFileSync(binaryPath)) + : null, + mtime: fs.existsSync(binaryPath) + ? fs.statSync(binaryPath).mtime.toISOString() + : null, + }; + assert.ok(report.binary.sha256, "fresh E2E binary is missing"); + writeReport(); + }); + + after(async () => { + if (originalWindowSize) { + await browser.setWindowSize( + originalWindowSize.width, + originalWindowSize.height, + ); + } + report.completedAt = new Date().toISOString(); + report.passed = report.checks.filter( + (check) => check.status === "passed", + ).length; + report.failed = report.checks.filter( + (check) => check.status === "failed", + ).length; + report.result = + report.failed === 0 && report.checks.length > 0 ? "passed" : "failed"; + writeReport(); + }); + + it("uses the Downloads folder without a picker when the folder is empty and ask-each-time is off", async () => + scenario("missing-folder-ask-off-uses-default", async () => { + await setFolderSettings({ + askDownloadLocation: false, + downloadFolder: "", + }); + await setUrl(`${CLIP_BASE}/readiness-default-folder.mp4`); + await waitForSummaryState("resolved"); + const before = await readHint(); + assert.match(before.text, /Downloads folder/); + assert.equal(before.hidden, false, "default-folder hint is hidden"); + assert.equal(before.tone, "info"); + assert.match(before.describedBy ?? "", /downloadReadiness/); + + await stubDownloadVideo(); + try { + await clickById("downloadBtn"); + await waitFor( + () => (window.__uiReadinessDownloadCalls?.length ?? 0) === 1, + "download request was not sent", + 10_000, + ); + const request = await browser.execute( + () => window.__uiReadinessDownloadCalls[0], + ); + assert.equal( + Object.prototype.hasOwnProperty.call(request, "outputPath"), + false, + "an empty folder must not send an outputPath from the renderer", + ); + assert.equal(await pickerCalls(), 0, "Download opened a folder picker"); + } finally { + await restoreDownloadVideo(); + } + return { hintTone: before.tone, sentOutputPath: false }; + })); + + it("explains that a folder is asked for each download and keeps the blocker-free flow", async () => + scenario("ask-each-time-hint", async () => { + await setFolderSettings({ + askDownloadLocation: true, + downloadFolder: "", + }); + await setControl("askDownloadLocationToggle", true); + await setUrl(`${CLIP_BASE}/readiness-ask-each-time.mp4`); + await waitForSummaryState("destination"); + const hint = await readHint(); + assert.match(hint.text, /ROSI will ask where to save this download/); + assert.equal(hint.hidden, false); + assert.equal(hint.tone, "info"); + + await setPicker("cancel"); + await stubDownloadVideo(); + try { + await clickById("downloadBtn"); + await waitFor( + () => window.__uiReadinessPicker?.calls >= 1, + "ask-each-time did not open the folder picker", + 10_000, + ); + await waitFor( + () => + document + .getElementById("output") + ?.textContent.includes("No save location selected"), + "cancelled per-download picker did not report the cancel", + 10_000, + ); + assert.equal( + await downloadCalls(), + 0, + "download started without a folder", + ); + } finally { + await restoreDownloadVideo(); + await restorePicker(); + } + return { hintTone: hint.tone }; + })); + + it("names a blocking format choice next to Download and does not start", async () => + scenario("formats-blocker-next-to-download", async () => { + await setFolderSettings({ + askDownloadLocation: false, + downloadFolder: "", + }); + await clickById("profileCustomBtn"); + await waitFor( + () => + document + .getElementById("profileCustomBtn") + ?.getAttribute("aria-pressed") === "true", + "custom profile was not selected", + 5_000, + ); + await setUrl(`${CLIP_BASE}/readiness-formats.mp4`); + await waitFor( + () => + /video or audio format/.test( + document.getElementById("downloadReadiness")?.textContent ?? "", + ), + "format blocker was not shown next to Download", + 10_000, + ); + const hint = await readHint(); + assert.equal(hint.tone, "blocked"); + assert.match(hint.text, /Check available formats/); + + await stubDownloadVideo(); + try { + await clickById("downloadBtn"); + await browser.pause(300); + assert.equal( + await downloadCalls(), + 0, + "a blocked download reached the bridge", + ); + } finally { + await restoreDownloadVideo(); + } + await clickById("profileCompatibleBtn"); + return { blocker: "formats", tone: hint.tone }; + })); + + it("keeps the failed effective-options reason and next action next to Download", async () => + scenario("resolve-failure-hint-next-to-download", async () => { + await setFolderSettings({ + askDownloadLocation: false, + downloadFolder: "", + }); + await browser.execute(() => { + window.__uiReadinessResolveOriginal = + window.__ROSI_E2E__.api.resolveDownloadOptions; + window.__ROSI_E2E__.api.resolveDownloadOptions = async () => ({ + ok: false, + error: { + code: "INTERNAL_ERROR", + message: "Format lookup stub failed", + }, + }); + }); + try { + await setUrl(`${CLIP_BASE}/readiness-resolve-failed.mp4?case=failed`); + await waitForSummaryState("error"); + const failed = await readHint(); + assert.equal(failed.tone, "error"); + assert.match(failed.text, /Format lookup stub failed/); + assert.match(failed.text, /still checks these options/); + } finally { + await browser.execute(() => { + window.__ROSI_E2E__.api.resolveDownloadOptions = + window.__uiReadinessResolveOriginal; + delete window.__uiReadinessResolveOriginal; + }); + } + await setUrl(`${CLIP_BASE}/readiness-resolve-recovered.mp4?case=ok`); + await waitForSummaryState("resolved"); + const recovered = await readHint(); + assert.match( + recovered.text, + /Downloads folder/, + "hint did not clear after recovery", + ); + return { recoveredTone: recovered.tone }; + })); + + it("explains turning ask-each-time off with no folder, including a cancelled pick", async () => + scenario("ask-off-cancelled-folder-feedback", async () => { + await setFolderSettings({ + askDownloadLocation: true, + downloadFolder: "", + }); + const fixture = path.join(FOLDERS, "switched-folder"); + fs.mkdirSync(fixture, { recursive: true }); + await setPicker("cancel"); + try { + await setControl("askDownloadLocationToggle", false); + await waitFor( + () => + document.getElementById("downloadFolderFeedback")?.hidden === false, + "turning ask-each-time off with no folder showed no feedback", + 10_000, + ); + const cancelled = await folderFeedback(); + assert.equal( + cancelled.text, + "No folder was chosen. Choose a folder or ask ROSI before each download.", + ); + const toggled = await browser.execute( + () => document.getElementById("askDownloadLocationToggle").checked, + ); + assert.equal( + toggled, + false, + "a cancelled pick turned ask-each-time back on", + ); + + await setControl("askDownloadLocationToggle", true); + await setPicker("path", fixture); + await setControl("askDownloadLocationToggle", false); + await waitFor( + (expected) => + document + .getElementById("downloadFolderSummary") + ?.textContent.includes(expected), + "folder chosen after switching ask-each-time off was not saved", + 10_000, + path.basename(fixture), + ); + assert.equal((await folderFeedback()).hidden, true); + await browser.waitUntil( + async () => + path.basename(await persistedFolder()) === path.basename(fixture), + { timeout: 10_000, timeoutMsg: "chosen folder was not saved" }, + ); + return { cancelledText: cancelled.text }; + } finally { + await restorePicker(); + } + })); + + it("explains a cancelled or failed Change folder pick and keeps the stale path out", async () => + scenario("change-folder-cancelled-and-failed", async () => { + await setFolderSettings({ + askDownloadLocation: false, + downloadFolder: "", + }); + const fixture = path.join(FOLDERS, "picked-folder"); + fs.mkdirSync(fixture, { recursive: true }); + await setPicker("cancel"); + try { + const beforeText = await browser.execute(() => + document.getElementById("downloadFolderSummary")?.textContent.trim(), + ); + await clickById("changeDownloadFolderBtn"); + await waitFor( + () => !document.getElementById("downloadFolderFeedback")?.hidden, + "cancelled pick showed no feedback", + 10_000, + ); + const cancelled = await folderFeedback(); + assert.equal( + cancelled.text, + "No folder was chosen. Choose a folder or ask ROSI before each download.", + ); + + await setPicker("fail"); + await clickById("changeDownloadFolderBtn"); + await waitFor( + () => + document + .getElementById("downloadFolderFeedback") + ?.textContent.includes("could not open the folder picker"), + "failed pick did not explain the failure", + 10_000, + ); + const failed = await folderFeedback(); + assert.equal( + failed.text, + "ROSI could not open the folder picker. Try again or ask before each download.", + ); + const afterText = await browser.execute(() => + document.getElementById("downloadFolderSummary")?.textContent.trim(), + ); + assert.equal( + afterText, + beforeText, + "a failed pick changed the shown folder", + ); + + await setControl("askDownloadLocationToggle", true); + await waitFor( + () => + document.getElementById("downloadFolderFeedback")?.hidden === true, + "switching ask-each-time on did not clear the folder feedback", + 5_000, + ); + await setPicker("cancel"); + await clickById("changeDownloadFolderBtn"); + await waitFor( + () => window.__uiReadinessPicker?.calls >= 1, + "picker was not called", + 5_000, + ); + await browser.pause(200); + const askOnCancel = await folderFeedback(); + assert.equal( + askOnCancel.hidden, + true, + "cancel explained while ask-each-time is on", + ); + + await setPicker("path", fixture); + await clickById("changeDownloadFolderBtn"); + await waitFor( + (expected) => + document + .getElementById("downloadFolderSummary") + ?.textContent.includes(expected), + "chosen folder was not shown", + 10_000, + path.basename(fixture), + ); + assert.equal((await folderFeedback()).hidden, true); + await browser.waitUntil( + async () => + path.basename(await persistedFolder()) === path.basename(fixture), + { timeout: 10_000, timeoutMsg: "chosen folder was not saved" }, + ); + return { + cancelled: cancelled.text, + failed: failed.text, + askOnCancelHidden: askOnCancel.hidden, + }; + } finally { + await restorePicker(); + } + })); + + it("keeps long URLs, paths, titles, and errors inside their regions at 900x560", async () => + scenario("long-content-no-horizontal-overflow", async () => { + originalWindowSize = await browser.getWindowSize(); + // Two 200-character folder names: one name may not exceed 255 bytes, and the + // path only needs to exist as a setting (validation walks up to a real parent). + const longFolder = path.join(FOLDERS, "p".repeat(200), "q".repeat(200)); + const longUrl = `${CLIP_BASE}/${"u".repeat(380)}.mp4`; + assert.ok( + longFolder.length >= 400, + `folder path is ${longFolder.length} characters`, + ); + assert.ok(longUrl.length >= 400, `URL is ${longUrl.length} characters`); + + await browser.setWindowSize(900, 560); + await setFolderSettings({ + askDownloadLocation: false, + downloadFolder: longFolder, + }); + await setPicker("path", longFolder); + try { + await setControl("askDownloadLocationToggle", false); + await clickById("changeDownloadFolderBtn"); + await waitFor( + (expected) => + document.getElementById("downloadFolderSummary")?.title === + expected, + "long folder was not chosen", + 10_000, + longFolder, + ); + } finally { + await restorePicker(); + } + await setControl("consoleToggle", true); + await browser.pause(250); + + await clickById("dockTabQueue"); + assert.equal((await api("clearQueue")).ok, true); + assert.equal((await api("addToQueue", [longUrl])).ok, true); + await waitFor( + () => document.querySelectorAll("#queueList .queue-item").length >= 1, + "long queue item did not render", + 10_000, + ); + + await clickById("dockTabActivity"); + await waitFor( + () => document.getElementById("download-history")?.hidden === false, + "activity panel did not open", + 5_000, + ); + await browser.execute( + (outputPath, longTitle, longError) => { + window.__TAURI__.event.emit("download-activity-update", [ + { + id: "ui-readiness-long-content", + owner: "manual", + outcome: "failed", + statusMessage: longError, + url: longTitle, + request: { url: longTitle, outputPath }, + filename: longTitle, + outputPath, + outputPaths: [outputPath], + error: longError, + startedAt: Date.now() - 2000, + completedAt: Date.now(), + }, + ]); + window.__TAURI__.event.emit("progress", `${"c".repeat(400)}`); + }, + path.join(longFolder, `${"o".repeat(200)}.mkv`), + `https://example.test/${"t".repeat(380)}`, + "E".repeat(400), + ); + await waitFor( + () => + [...document.querySelectorAll("#history-list .history-item")].some( + (row) => + row.querySelector(".history-error")?.textContent.length >= 400, + ), + "long activity entry did not render", + 10_000, + ); + await waitFor( + () => + document + .getElementById("output") + ?.textContent.includes("c".repeat(400)), + "long console line did not render", + 10_000, + ); + + await browser.execute((longError) => { + window.__uiReadinessResolveOriginal = + window.__ROSI_E2E__.api.resolveDownloadOptions; + window.__ROSI_E2E__.api.resolveDownloadOptions = async () => ({ + ok: false, + error: { code: "INTERNAL_ERROR", message: longError }, + }); + }, "R".repeat(400)); + try { + await setUrl(`${CLIP_BASE}/readiness-long-error.mp4?case=long-error`); + await waitForSummaryState("error"); + } finally { + await browser.execute(() => { + window.__ROSI_E2E__.api.resolveDownloadOptions = + window.__uiReadinessResolveOriginal; + delete window.__uiReadinessResolveOriginal; + }); + } + + // A region is measured only while it is rendered, so the activity panel is + // measured on its own tab and the queue on its tab. + const onActivity = await measureRegions([ + "#download-history", + ".download-destination", + "#downloadOutputSummary", + "#downloadReadiness", + ]); + // The console is its own dock tab; #output is measured only while it is shown. + await clickById("dockTabConsole"); + await waitFor( + () => document.getElementById("output")?.getClientRects().length > 0, + "console panel did not open", + 5_000, + ); + const onConsole = await measureRegions(["#output"]); + await clickById("dockTabQueue"); + await waitFor( + () => !document.getElementById("queueSection")?.hidden, + "queue panel did not open", + 5_000, + ); + // #queueStatusMessage is :empty (display none) here, so it has no box to measure. + const onQueue = await measureRegions(["#queueSection"]); + const measured = { + violations: [ + ...onActivity.violations, + ...onConsole.violations, + ...onQueue.violations, + ], + nodesChecked: + onActivity.nodesChecked + + onConsole.nodesChecked + + onQueue.nodesChecked, + documentOverflowPx: Math.max( + onActivity.documentOverflowPx, + onConsole.documentOverflowPx, + onQueue.documentOverflowPx, + ), + }; + assert.equal( + measured.violations.length, + 0, + `layout overflow: ${JSON.stringify(measured.violations.slice(0, 8))}`, + ); + assert.equal( + measured.documentOverflowPx, + 0, + "document scrolls horizontally", + ); + const theme = await browser.execute( + () => document.documentElement.dataset.theme ?? "default", + ); + await saveScreenshotFor("long-content-900x560.png", theme); + return { + viewport: "900x560", + nodesChecked: measured.nodesChecked, + folderPathLength: longFolder.length, + urlLength: longUrl.length, + }; + })); + + it("keeps the queue live region announced from the markup", async () => + scenario("queue-status-live-region-markup", async () => { + const indexHtml = fs.readFileSync( + path.join(REPO_ROOT, "src", "index.html"), + "utf8", + ); + const tag = + indexHtml.match(/]*\bid="queueStatusMessage"[^>]*>/)?.[0] ?? ""; + assert.match(tag, /\brole="status"/, "markup lacks role=status"); + assert.match( + tag, + /\baria-live="polite"/, + "markup lacks aria-live=polite", + ); + assert.match( + tag, + /\baria-atomic="true"/, + "markup lacks aria-atomic=true", + ); + + const live = await browser.execute(() => { + const element = document.getElementById("queueStatusMessage"); + return { + tagName: element?.tagName ?? null, + role: element?.getAttribute("role") ?? null, + ariaLive: element?.getAttribute("aria-live") ?? null, + ariaAtomic: element?.getAttribute("aria-atomic") ?? null, + }; + }); + assert.equal(live.tagName, "P"); + assert.equal(live.role, "status"); + assert.equal(live.ariaLive, "polite"); + assert.equal(live.ariaAtomic, "true"); + + const engineSource = fs.readFileSync( + path.join(REPO_ROOT, "src", "rosiEngine.ts"), + "utf8", + ); + assert.doesNotMatch( + engineSource, + /queueStatusMessage\.setAttribute/, + "rosiEngine.ts still sets live-region attributes at runtime", + ); + return { markupTag: tag.length > 0, live }; + })); +}); diff --git a/e2e/v5-fixes/ui-polish/ui-polish.spec.js b/e2e/v5-fixes/ui-polish/ui-polish.spec.js new file mode 100644 index 00000000..84f17e3e --- /dev/null +++ b/e2e/v5-fixes/ui-polish/ui-polish.spec.js @@ -0,0 +1,891 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import crypto from "node:crypto"; +import fs from "node:fs"; +import path from "node:path"; +import { browser } from "@wdio/globals"; +import { api, waitForAppReady } from "../../helpers/app-bridge.js"; +import { e2eBinaryPath, REPO_ROOT } from "../../helpers/profile.js"; + +const stamp = new Date() + .toISOString() + .replaceAll(":", "-") + .replaceAll(".", "-"); +const artifactDir = path.join( + REPO_ROOT, + "e2e", + "artifacts", + "v5-fixes-ui-polish", + `${stamp}-${process.pid}`, +); +// The gate passes ROSI_E2E_SCREENSHOTS, so the shots land in the folder that +// verifyScreenshots re-hashes. A standalone run keeps them beside its report. +const screenshotDir = + process.env.ROSI_E2E_SCREENSHOTS || path.join(artifactDir, "screenshots"); +// Screenshot records the gate reads from this pass's results file. The gate +// attaches them to the v5-fixes/ui-polish scenario (scripts/test-e2e.js). +const GATE_SCREENSHOT_RECORD = "v5-screenshots"; +const reportPath = path.join(artifactDir, "report.json"); +const report = { + suite: "v5-fixes-ui-polish", + startedAt: new Date().toISOString(), + platform: process.platform, + arch: process.arch, + runtime: { node: process.version }, + source: null, + binary: null, + checks: [], + screenshots: [], +}; + +const sha256 = (value) => + crypto.createHash("sha256").update(value).digest("hex"); + +function sourceIdentity() { + const head = execFileSync("git", ["rev-parse", "HEAD"], { + cwd: REPO_ROOT, + encoding: "utf8", + }).trim(); + const trackedChanges = execFileSync( + "git", + ["diff", "HEAD", "--name-only", "-z"], + { + cwd: REPO_ROOT, + encoding: "buffer", + }, + ) + .toString() + .split("\0") + .filter(Boolean); + const untracked = execFileSync( + "git", + ["ls-files", "--others", "--exclude-standard", "-z"], + { cwd: REPO_ROOT, encoding: "buffer" }, + ) + .toString() + .split("\0") + .filter(Boolean); + const dirtyFiles = [...new Set([...trackedChanges, ...untracked])] + .sort() + .map((relativePath) => { + const filePath = path.join(REPO_ROOT, relativePath); + return { + path: relativePath.replaceAll(path.sep, "/"), + sha256: + fs.existsSync(filePath) && fs.statSync(filePath).isFile() + ? sha256(fs.readFileSync(filePath)) + : null, + }; + }); + const dirtyFingerprint = dirtyFiles + .map((file) => `${file.path}\0${file.sha256 ?? "deleted"}`) + .join("\n"); + return { + head, + workingTree: dirtyFiles.length === 0 ? "clean" : "dirty", + dirtyFiles, + dirtyFingerprintSha256: sha256(dirtyFingerprint), + }; +} + +function writeReport() { + // The report folder is separate from the screenshot folder, which the gate + // may pass in through ROSI_E2E_SCREENSHOTS. + fs.mkdirSync(artifactDir, { recursive: true }); + const contents = `${JSON.stringify(report, null, 2)}\n`; + const temporaryPath = `${reportPath}.tmp`; + fs.writeFileSync(temporaryPath, contents); + fs.renameSync(temporaryPath, reportPath); + fs.writeFileSync( + `${reportPath}.sha256`, + `${sha256(contents)} report.json\n`, + ); +} + +async function scenario(name, body) { + try { + const details = await body(); + report.checks.push({ name, status: "passed", ...details }); + writeReport(); + } catch (error) { + report.checks.push({ + name, + status: "failed", + reason: error instanceof Error ? error.message : String(error), + }); + writeReport(); + throw error; + } +} + +async function clickById(id) { + await browser.execute((target) => { + const element = document.getElementById(target); + if (!element) throw new Error(`missing element ${target}`); + element.click(); + }, id); +} + +async function setControl(id, value) { + await browser.execute( + (target, next) => { + const control = document.getElementById(target); + if (!control) throw new Error(`missing control ${target}`); + if (control.type === "checkbox") control.checked = Boolean(next); + else control.value = String(next); + control.dispatchEvent(new Event("change", { bubbles: true })); + }, + id, + value, + ); +} + +async function waitFor( + predicate, + message, + timeout = 10_000, + argument = undefined, +) { + await browser.waitUntil(async () => browser.execute(predicate, argument), { + timeout, + interval: 100, + timeoutMsg: message, + }); +} + +async function waitForModal(open) { + await waitFor( + (want) => + document.getElementById("app-modal")?.classList.contains("active") === + want, + `modal did not ${open ? "open" : "close"}`, + 5_000, + open, + ); +} + +async function clickModalButton(label) { + await browser.execute((wantedLabel) => { + const button = [...document.querySelectorAll("#modal-buttons button")].find( + (candidate) => candidate.textContent.trim() === wantedLabel, + ); + if (!button) throw new Error(`missing modal action ${wantedLabel}`); + button.click(); + }, label); +} + +// The WebDriver plugin dispatches keys as synthetic KeyboardEvents, which do not +// run a button's native Enter activation. When Enter did not open the prompt, +// activate the focused control the way the browser would. Assertions still +// check that the prompt opens and that focus returns to the control. +async function pressEnterOnFocusedControl() { + await browser.keys("Enter"); + await browser.execute(() => { + const focused = document.activeElement; + const modalOpen = document + .getElementById("app-modal") + ?.classList.contains("active"); + if (!modalOpen && focused instanceof HTMLButtonElement) focused.click(); + }); +} + +// The prompt moves focus into itself on the next animation frame, so a check made +// in the same round trip that reports the prompt open can run before that frame. +async function waitForModalFocus() { + await waitFor( + () => { + const modal = document.getElementById("app-modal"); + return Boolean(modal?.contains(document.activeElement)); + }, + "focus did not move into the open prompt", + 5_000, + ); +} + +async function setSidebarOpen(open) { + const isOpen = await browser.execute( + () => + document.getElementById("sidebar")?.classList.contains("open") === true, + ); + if (isOpen !== open) { + await clickById(open ? "settingsBtn" : "closeSidebar"); + await waitFor( + (want) => + document.getElementById("sidebar")?.classList.contains("open") === want, + `settings did not ${open ? "open" : "close"}`, + 10_000, + open, + ); + } + // The sidebar slides in with a transform. Wait until it rests at its open + // position, so focus and layout checks never run against a moving panel. + if (open) { + // A hidden page (background mode) runs no animation frames, so the slide + // never advances on its own. Finish the running slide to its resting end + // state there. Visible runs still wait for the real transition. + const visibility = await browser.execute(() => document.visibilityState); + if (visibility !== "visible") { + await browser.execute(() => { + document + .getElementById("sidebar") + ?.getAnimations() + .forEach((animation) => animation.finish()); + }); + } + await waitFor( + () => { + const sidebar = document.getElementById("sidebar"); + if (!sidebar) return false; + const rect = sidebar.getBoundingClientRect(); + const restingLeft = parseFloat(getComputedStyle(sidebar).left); + return Math.abs(rect.left - restingLeft) < 1; + }, + "settings sidebar did not finish opening", + 10_000, + ); + } +} + +async function setProfile(mode) { + const id = { + compatible: "profileCompatibleBtn", + "best-video": "profileBestVideoBtn", + audio: "profileAudioBtn", + custom: "profileCustomBtn", + }[mode]; + await clickById(id); + await waitFor( + (target) => + document.getElementById(target)?.getAttribute("aria-pressed") === "true", + `${mode} profile was not selected`, + 5_000, + id, + ); +} + +async function captureViewport(theme, width, height, increasedText) { + await browser.setWindowSize(width, height); + await setSidebarOpen(true); + await setControl("themeSelect", theme); + await setSidebarOpen(false); + await browser.execute((increased) => { + document.documentElement.style.fontSize = increased ? "125%" : ""; + document.documentElement.dataset.reducedMotionProbe = "true"; + }, increasedText); + await browser.pause(250); + const actual = await browser.execute(() => ({ + width: window.innerWidth, + height: window.innerHeight, + rootFontSize: getComputedStyle(document.documentElement).fontSize, + horizontalOverflow: + document.documentElement.scrollWidth > window.innerWidth, + focusable: [ + ...document.querySelectorAll("button, input, select, textarea, a[href]"), + ].filter((element) => element.offsetParent !== null && !element.disabled) + .length, + })); + assert.ok(actual.width >= 840, `window too narrow at ${actual.width}px`); + assert.ok(actual.height >= 500, `window too short at ${actual.height}px`); + assert.equal( + actual.horizontalOverflow, + false, + "page has horizontal overflow", + ); + const name = `ui-polish-${theme}-${width}x${height}${increasedText ? "-text-125" : ""}`; + const destination = path.join(screenshotDir, `${name}.png`); + await browser.saveScreenshot(destination); + const bytes = fs.statSync(destination).size; + assert.ok(bytes > 1000, `${name} screenshot is empty`); + report.screenshots.push({ + name, + path: path.relative(REPO_ROOT, destination).replaceAll(path.sep, "/"), + sha256: sha256(fs.readFileSync(destination)), + bytes, + width: actual.width, + height: actual.height, + theme, + increasedText, + }); + return actual; +} + +/** + * Appends the screenshot list to this pass's results file. Other records already + * in the file are kept, so each spec in the pass adds its own. + */ +function writeGateScreenshotRecord(shots) { + const resultsPath = process.env.ROSI_E2E_RESULTS; + if (!resultsPath) return; + let records = []; + try { + if (fs.existsSync(resultsPath)) { + const parsed = JSON.parse(fs.readFileSync(resultsPath, "utf8")); + if (Array.isArray(parsed)) records = parsed; + } + } catch { + records = []; + } + records.push({ name: GATE_SCREENSHOT_RECORD, status: "passed", shots }); + fs.writeFileSync(resultsPath, `${JSON.stringify(records, null, 2)}\n`); +} + +describe("ROSI full-app UI polish", () => { + before(async () => { + fs.mkdirSync(screenshotDir, { recursive: true }); + await waitForAppReady(); + report.source = sourceIdentity(); + const binaryPath = e2eBinaryPath(); + report.binary = { + path: path.relative(REPO_ROOT, binaryPath).replaceAll(path.sep, "/"), + sha256: fs.existsSync(binaryPath) + ? sha256(fs.readFileSync(binaryPath)) + : null, + mtime: fs.existsSync(binaryPath) + ? fs.statSync(binaryPath).mtime.toISOString() + : null, + }; + assert.ok(report.binary.sha256, "fresh E2E binary is missing"); + writeReport(); + }); + + after(() => { + report.completedAt = new Date().toISOString(); + report.passed = report.checks.filter( + (check) => check.status === "passed", + ).length; + report.failed = report.checks.filter( + (check) => check.status === "failed", + ).length; + report.result = + report.failed === 0 && report.checks.length > 0 ? "passed" : "failed"; + writeReport(); + }); + + it("resolves and announces the effective request summary", async () => + scenario("effective-options-summary", async () => { + const before = await browser.execute(() => ({ + state: + document.getElementById("downloadOutputSummary")?.dataset.state ?? + null, + text: + document + .getElementById("downloadOutputSummary") + ?.textContent.trim() ?? "", + role: + document + .getElementById("downloadOutputSummary") + ?.getAttribute("role") ?? null, + })); + assert.equal( + before.state, + "profile-preview", + "summary must not claim resolution without a URL", + ); + assert.equal( + before.role, + "status", + "summary is not announced as a status", + ); + + await setProfile("audio"); + await setControl("profileAudioFormatSelect", "flac"); + const summaryBeforeUrl = await browser.execute(() => ({ + state: document.getElementById("downloadOutputSummary")?.dataset.state, + text: document + .getElementById("downloadOutputSummary") + ?.textContent.trim(), + })); + assert.equal(summaryBeforeUrl.state, "profile-preview"); + assert.match(summaryBeforeUrl.text, /audio|flac/i); + + await browser.execute(() => { + const url = document.getElementById("url"); + url.value = "https://www.youtube.com/watch?v=rosi-ui-polish"; + url.dispatchEvent(new Event("input", { bubbles: true })); + }); + await waitFor( + () => + document.getElementById("downloadOutputSummary")?.dataset.state === + "resolved", + "effective options were not resolved for a valid URL", + ); + const resolved = await browser.execute(() => ({ + text: document + .getElementById("downloadOutputSummary") + .textContent.trim(), + profile: document.getElementById("downloadOutputSummary").dataset + .profile, + })); + assert.equal(resolved.profile, "audio"); + assert.match(resolved.text, /audio|flac/i); + return { initialState: before.state, resolvedProfile: resolved.profile }; + })); + + it("keeps invalid input inline and associated with its field", async () => + scenario("inline-readiness-validation", async () => { + await browser.execute(() => { + const input = document.getElementById("url"); + input.value = "not a URL"; + input.dispatchEvent(new Event("input", { bubbles: true })); + input.dispatchEvent(new Event("blur", { bubbles: true })); + }); + const result = await browser.execute(() => ({ + invalid: document.getElementById("url").getAttribute("aria-invalid"), + message: document + .getElementById("urlValidationMessage") + .textContent.trim(), + describedBy: document + .getElementById("url") + .getAttribute("aria-describedby"), + summaryState: document.getElementById("downloadOutputSummary").dataset + .state, + })); + assert.equal(result.invalid, "true"); + assert.ok( + result.message.length > 0, + "invalid URL has no correction hint", + ); + assert.match(result.describedBy ?? "", /urlValidationMessage/); + assert.notEqual( + result.summaryState, + "resolved", + "invalid input kept stale resolved options", + ); + return { field: "url", summaryState: result.summaryState }; + })); + + it("confirms per-section reset and restores focus after closing", async () => + scenario("settings-section-reset-confirmation", async () => { + const defaultsResult = await api("getDefaultSettings"); + assert.equal(defaultsResult.ok, true); + const defaults = defaultsResult.data; + await setSidebarOpen(true); + const convertToggle = await browser.execute( + () => document.getElementById("convertToggle").checked, + ); + const changed = !defaults.convertEnabled; + if (convertToggle !== changed) await setControl("convertToggle", changed); + await waitFor( + (expected) => + document.getElementById("convertToggle").checked === expected, + "conversion toggle did not change", + 10_000, + changed, + ); + await clickById("closeSidebar"); + await waitFor( + () => !document.getElementById("sidebar").classList.contains("open"), + "settings did not close", + ); + // The reset control lives in the settings sidebar, so reopen it the way a + // user would before opening the prompt; focus can only return to a control + // that is visible. + await setSidebarOpen(true); + await browser.execute(() => { + document.querySelector('[data-reset-section="download"]').click(); + }); + await waitForModal(true); + await waitForModalFocus(); + const modal = await browser.execute(() => ({ + title: document.getElementById("modal-title").textContent.trim(), + focusedInside: document + .getElementById("app-modal") + .contains(document.activeElement), + text: document.getElementById("modal-message").textContent.trim(), + })); + assert.match(modal.title, /reset/i); + assert.equal(modal.focusedInside, true); + assert.match(modal.text, /conversion/i); + await clickModalButton("Cancel"); + await waitForModal(false); + assert.equal( + await browser.execute( + () => document.getElementById("convertToggle").checked, + ), + changed, + "cancelled reset changed the setting", + ); + const focusReturned = await browser.execute( + () => + document.activeElement === + document.querySelector('[data-reset-section="download"]'), + ); + assert.equal( + focusReturned, + true, + "closing reset prompt did not restore focus", + ); + + await browser.execute(() => { + document.querySelector('[data-reset-section="download"]').click(); + }); + await waitForModal(true); + await clickModalButton("Reset section"); + await waitForModal(false); + await waitFor( + (expected) => + document.getElementById("convertToggle").checked === expected, + "confirmed section reset did not restore defaults", + 10_000, + defaults.convertEnabled, + ); + return { defaultConvertEnabled: defaults.convertEnabled }; + })); + + it("runs the reset prompt keyboard-only and restores focus on Escape", async () => + scenario("keyboard-reset-escape-focus", async () => { + await setSidebarOpen(true); + const resetButtonSelector = '[data-reset-section="download"]'; + const before = await browser.execute( + () => document.getElementById("convertToggle").checked, + ); + await browser.execute((selector) => { + const button = document.querySelector(selector); + if (!button) throw new Error(`missing ${selector}`); + button.focus(); + }, resetButtonSelector); + const reachable = await browser.execute( + (selector) => + document.activeElement === document.querySelector(selector), + resetButtonSelector, + ); + assert.equal(reachable, true, "reset button is not keyboard focusable"); + await pressEnterOnFocusedControl(); + await waitForModal(true); + await waitForModalFocus(); + for (let press = 0; press < 3; press += 1) await browser.keys("Tab"); + const trapped = await browser.execute(() => + document.getElementById("app-modal").contains(document.activeElement), + ); + assert.equal(trapped, true, "Tab moved focus out of the reset prompt"); + await browser.keys("Escape"); + await waitForModal(false); + const restored = await browser.execute( + (selector) => + document.activeElement === document.querySelector(selector), + resetButtonSelector, + ); + assert.equal( + restored, + true, + "Escape did not restore focus to the reset button", + ); + const after = await browser.execute( + () => document.getElementById("convertToggle").checked, + ); + assert.equal(after, before, "Escape changed the setting"); + return { trapped, restored }; + })); + + it("shows settings save failure and supports a successful retry", async () => + scenario("settings-save-retry", async () => { + await setSidebarOpen(true); + const state = await browser.execute(() => { + window.__uiPolishSaveCalls = 0; + window.__uiPolishOriginalSaveSettings = + window.__ROSI_E2E__.api.saveSettings; + window.__ROSI_E2E__.api.saveSettings = async (settings) => { + window.__uiPolishSaveCalls += 1; + if (window.__uiPolishSaveCalls === 1) { + return { + ok: false, + error: { + code: "INTERNAL_ERROR", + message: "Temporary settings write failure", + }, + }; + } + return window.__uiPolishOriginalSaveSettings(settings); + }; + return document.getElementById("notificationsToggle").checked; + }); + await setControl("notificationsToggle", !state); + await waitFor( + () => + document.getElementById("settingsSaveFeedback")?.dataset.state === + "error", + "settings save failure was not shown inline", + 8_000, + ); + const failedState = await browser.execute(() => ({ + text: document + .getElementById("settingsSaveFeedback") + .textContent.trim(), + retryVisible: !document.getElementById("retrySettingsSave").hidden, + valueRetained: document.getElementById("notificationsToggle").checked, + })); + assert.match(failedState.text, /did not save|save failed/i); + assert.equal(failedState.retryVisible, true); + assert.equal(failedState.valueRetained, !state); + await clickById("retrySettingsSave"); + await waitFor( + () => + document.getElementById("settingsSaveFeedback")?.dataset.state === + "saved", + "retry did not report saved settings", + 8_000, + ); + const saved = await api("getSettings"); + assert.equal(saved.notifications, !state); + const calls = await browser.execute(() => window.__uiPolishSaveCalls); + await browser.execute(() => { + window.__ROSI_E2E__.api.saveSettings = + window.__uiPolishOriginalSaveSettings; + delete window.__uiPolishOriginalSaveSettings; + }); + return { saveCalls: calls, notifications: saved.notifications }; + })); + + it("explains dependent controls and preserves queue focus on refresh", async () => + scenario("dependent-controls-and-queue-focus", async () => { + // The queue is in the main dock, which is inert while the settings sidebar + // is open, so focus can only be placed on it with the sidebar closed. + await setSidebarOpen(false); + await setProfile("audio"); + const explanation = await browser.execute(() => ({ + disabled: document.getElementById("convertToggle").disabled, + describedBy: document + .getElementById("convertToggle") + .getAttribute("aria-describedby"), + text: + document.getElementById("convertDisabledHint")?.textContent.trim() ?? + "", + })); + assert.equal(explanation.disabled, true); + assert.match(explanation.describedBy ?? "", /convertDisabledHint/); + assert.match(explanation.text, /audio.only/i); + + const clear = await api("clearQueue"); + assert.equal(clear.ok, true); + const firstUrl = "https://www.youtube.com/watch?v=rosi-ui-polish-queue-a"; + const secondUrl = + "https://www.youtube.com/watch?v=rosi-ui-polish-queue-b"; + assert.equal((await api("addToQueue", [firstUrl])).ok, true); + await waitFor( + (url) => + [...document.querySelectorAll(".queue-item")].some( + (row) => + row.dataset.queueId && + row.textContent.includes(new URL(url).hostname), + ), + "first queue item did not render", + 8_000, + firstUrl, + ); + const first = (await api("getQueue")).find( + (item) => item.url === firstUrl, + ); + assert.ok(first); + const initial = await browser.execute((id) => { + const row = [...document.querySelectorAll(".queue-item")].find( + (candidate) => candidate.dataset.queueId === id, + ); + const up = row.querySelector( + '[data-queue-action="queue-item-move-up"]', + ); + const remove = row.querySelector( + '[data-queue-action="queue-item-remove"]', + ); + remove.focus(); + return { + status: row.querySelector(".queue-item-meta")?.textContent ?? "", + disabledReason: up.getAttribute("aria-description"), + }; + }, first.id); + assert.match(initial.status, /pending/i); + const srStatus = await browser.execute( + (id) => + [...document.querySelectorAll(".queue-item")] + .find((row) => row.dataset.queueId === id) + ?.querySelector(".sr-only")?.textContent ?? "", + first.id, + ); + assert.match(srStatus, /Pending. Waiting for the queue to start./); + assert.match(initial.disabledReason, /first/i); + assert.equal((await api("addToQueue", [secondUrl])).ok, true); + await waitFor( + (url) => + [...document.querySelectorAll(".queue-item")].some((row) => + row.textContent.includes(new URL(url).hostname), + ), + "second queue item did not render", + 8_000, + secondUrl, + ); + const retained = await browser.execute( + (id) => + document.activeElement?.dataset.queueId === id && + document.activeElement?.dataset.queueAction === "queue-item-remove", + first.id, + ); + assert.equal(retained, true, "queue refresh stole focused action"); + assert.equal((await api("clearQueue")).ok, true); + return { initialStatus: "pending", focusRetained: retained }; + })); + + it("renders partial failure actions from the native activity event", async () => + scenario("activity-partial-success-output-action", async () => { + const outputPath = "C:/rosi-e2e/partial-output.mkv"; + await browser.execute((filePath) => { + window.__uiPolishOpenedPaths = []; + window.__uiPolishOriginalOpenFileLocation = + window.__ROSI_E2E__.api.openFileLocation; + window.__ROSI_E2E__.api.openFileLocation = async (target) => { + window.__uiPolishOpenedPaths.push(target); + return { ok: true, data: { opened: true } }; + }; + const entry = { + id: "ui-polish-partial-outcome", + owner: "manual", + outcome: "failed", + statusMessage: "One playlist item failed after another was saved.", + url: "https://www.youtube.com/playlist?list=ui-polish", + request: { + url: "https://www.youtube.com/playlist?list=ui-polish", + outputPath: filePath, + }, + filename: "ui-polish-playlist", + outputPath: filePath, + outputPaths: [filePath, `${filePath}.part`], + failedPaths: [`${filePath}.part`], + error: "One item could not be converted.", + startedAt: Date.now() - 2000, + completedAt: Date.now(), + }; + window.__TAURI__.event.emit("download-activity-update", [entry]); + }, outputPath); + await waitFor( + () => + [...document.querySelectorAll("#history-list .history-item")].some( + (row) => row.textContent.includes("ui-polish-playlist"), + ), + "partial activity entry did not render", + 5_000, + ); + const row = await browser.execute(() => { + const item = [ + ...document.querySelectorAll("#history-list .history-item"), + ].find((candidate) => + candidate.textContent.includes("ui-polish-playlist"), + ); + return { + status: item.querySelector(".history-status")?.textContent.trim(), + errorText: item.querySelector(".history-error")?.textContent.trim(), + action: [...item.querySelectorAll(".history-open-btn")] + .map((button) => button.getAttribute("aria-label")) + .find((label) => /file location/i.test(label ?? "")), + }; + }); + // One output was saved before the failure, so the 5.1 activity model + // reports a partial completion rather than a plain failure. + assert.equal(row.status, "Partially completed"); + assert.match(row.errorText, /could not be converted/i); + assert.match(row.action, /file location/i); + await browser.execute(() => + [ + ...document.querySelectorAll( + "#history-list .history-item .history-open-btn", + ), + ] + .find((button) => + /file location/i.test(button.getAttribute("aria-label") ?? ""), + ) + ?.click(), + ); + await browser.waitUntil( + async () => + (await browser.execute(() => window.__uiPolishOpenedPaths.length)) === + 1, + { + timeout: 5_000, + timeoutMsg: "Open folder action did not invoke the native bridge", + }, + ); + const paths = await browser.execute(() => { + window.__ROSI_E2E__.api.openFileLocation = + window.__uiPolishOriginalOpenFileLocation; + delete window.__uiPolishOriginalOpenFileLocation; + const captured = window.__uiPolishOpenedPaths; + delete window.__uiPolishOpenedPaths; + return captured; + }); + assert.deepEqual(paths, [outputPath]); + return { + outcome: row.status, + action: row.action, + outputPath, + fixture: "native-event", + }; + })); + + it("keeps keyboard access and layout across themes and text scales", async () => + scenario("theme-viewport-keyboard-layout", async () => { + const originalSize = await browser.getWindowSize(); + const matrix = []; + for (const theme of ["system", "light", "dark", "purple"]) { + matrix.push({ + theme, + width: 900, + height: 560, + ...(await captureViewport(theme, 900, 560, false)), + }); + matrix.push({ + theme, + width: 1200, + height: 900, + ...(await captureViewport(theme, 1200, 900, false)), + }); + matrix.push({ + theme, + width: 900, + height: 560, + ...(await captureViewport(theme, 900, 560, true)), + }); + } + await browser.execute(() => { + document.documentElement.style.fontSize = ""; + delete document.documentElement.dataset.reducedMotionProbe; + }); + await browser.setWindowSize(originalSize.width, originalSize.height); + await setSidebarOpen(true); + await browser.execute(() => + document.getElementById("settingsSearch").focus(), + ); + const keyboard = await browser.execute(() => ({ + focused: document.activeElement?.id, + focusVisible: + document.activeElement?.matches(":focus-visible") ?? false, + reducedMotionRule: [...document.styleSheets].some((sheet) => { + try { + return [...sheet.cssRules].some((rule) => + rule.conditionText?.includes("prefers-reduced-motion"), + ); + } catch { + return false; + } + }), + })); + assert.equal(keyboard.focused, "settingsSearch"); + assert.equal(keyboard.reducedMotionRule, true); + await setSidebarOpen(false); + // Four themes, each at 900x560 and 1200x900, plus 900x560 at 125% text. + assert.equal( + report.screenshots.length, + 12, + "screenshot matrix is incomplete", + ); + writeGateScreenshotRecord( + report.screenshots.map((shot) => ({ + name: shot.name, + file: path.basename(shot.path), + sha256: shot.sha256, + bytes: shot.bytes, + })), + ); + return { + viewportCases: matrix.length, + keyboardFocus: keyboard.focused, + screenshots: report.screenshots.length, + }; + })); +}); diff --git a/e2e/v5-fixes/updater-engine/failure-modes.md b/e2e/v5-fixes/updater-engine/failure-modes.md new file mode 100644 index 00000000..590545fa --- /dev/null +++ b/e2e/v5-fixes/updater-engine/failure-modes.md @@ -0,0 +1,93 @@ +# Updater engine: failure modes (written before the Rust engine) + +Goal: `src-tauri/src/updater.rs` owns channel and target selection, the +generation fences, single-flight download and install, the Flatpak feed-only +rule, and the compact-feed fallback. The renderer only draws. Every guard that +`src/updater.ts` (572 lines, deleted by this change) encodes today is listed +below with its source line, the Rust function that replaces it, and the E2E +scenario that proves it against a real signed manifest server. + +Line numbers refer to `src/updater.ts` at the start of this change. + +## Status + +Rows marked "(passes)" have a scenario that ran against the real engine on macOS: 27 in +`e2e/v5-fixes/updater-engine/updater-engine.spec.js`. Eleven were there first (dev-mode refusal, +retired package, candidate mismatch, restart refusal with retry, download cancel, checking order, +feed error, download error, compact routing, stale check after a channel change, channel save +failure). Sixteen cover the remaining guards (channel change during install, install identity +stale, feed empty retry, feed error retry, target changed during feed, feed error recheck, feed +error unresolved, installed identity reported, same candidate redownload skipped, not-available +releases candidate, event variants, download progress throttle, check timeout, download timeout, +download failure releases candidate, pre-install flush refusal with retry). Also `updater-compact-target-fallback` and +`updater-generation-retry` in `e2e/state-updater.spec.js`, `updater-channel-and-singleflight` +in `e2e/renderer-updates.spec.js`, and the four flatpak scenarios in +`e2e/v5-fixes/flatpak-updates`. G33 is proven by the pre-install flush scenario: the probe runs the plugin's before-exit hook in the plugin's order. + +## Guards + +| ID | Guard | Source (src/updater.ts) | Rust home | E2E scenario | +| --- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| G01 | Dev-mode refusal: an unpackaged build returns `dev-mode` before any feed request | L282-289 | `check_flow`, `platform::is_packaged` | `updater-engine-dev-mode-refusal` (passes) | +| G02 | Retired Linux deb/rpm target refuses the check with a fixed message, before any feed request | L195-199, L293-295 | `retired_package_message` | `updater-engine-retired-linux-package` (passes) | +| G03 | Flatpak builds read the feed but never download or install; the candidate carries `manualInstall: true` | L290-292, L385, L415, L522-525 | `check_flow`, `download_update`, `install_update` | `flatpak-newer-release-prompt` (passes) | +| G04 | A check result from before a channel change is discarded; the check restarts for the new channel | L169, L274-275, L314-317, L327-333 | `CheckGen` fence in `Command::TargetKnown` and `Command::Decide` | `updater-engine-stale-check-after-channel-change` (passes) | +| G05 | Channel save must succeed before revalidation; a failed save refuses the target and reports a feed error, not a silent result | L129-137, L166 | `set_update_channel` saves first; `resolve_target` refuses while `channel_unsaved` | `updater-engine-channel-save-failure` (passes) | +| G06 | Channel change during a download cancels it, emits one `cancelled`, and rechecks after the transfer settles | L178-188 | `Command::SetChannel` | `updater-generation-retry (state-updater.spec.js)` (passes) | +| G07 | Channel change during install waits for the install; it releases the identity only before the install started | L170-176 | `Command::SetChannel` (`recheck_after_install`) | `updater-engine-channel-change-during-install` (passes) | +| G08 | A download that completes after cancel is discarded; no `downloaded` event, no bytes kept | L440-443, L466-469, L509-519 | `Command::FinishDownload` (`is_current`) | `updater-engine-download-cancel-discards` (passes) | +| G09 | The effective target is confirmed after the download; a target change releases the candidate and rechecks | L470-478 | `Command::FinishDownload` | `updater-generation-retry (state-updater.spec.js)` (passes) | +| G10 | Single-flight: a second download is refused while one runs; install is refused while a download runs | L421, L536 | `Command::BeginDownload`, `Command::BeginInstall` | `updater-channel-and-singleflight (renderer-updates.spec.js)` (passes) | +| G11 | A download for a candidate that is not the pending one is cancelled silently | L417-419 | `Command::BeginDownload` | `updater-engine-candidate-mismatch` (passes) | +| G12 | Install of a candidate that was not downloaded refuses with an error; a stale candidate id is ignored | L527-535 | `Command::BeginInstall` | `updater-engine-candidate-mismatch` (passes) | +| G13 | Install revalidates the pending identity and target after the await; a stale identity exits without effects | L544, L552 | `Command::ConfirmInstallTarget`, `Command::FinishInstall` | `updater-engine-install-identity-stale` (passes) | +| G14 | Install target changed since download releases the candidate and rechecks | L545-549 | `Command::ConfirmInstallTarget` | `updater-channel-and-singleflight (renderer-updates.spec.js)` (passes) | +| G15 | Restart refusal keeps the installed identity so the next install only restarts; the user sees an install error | L553, L555-559, L561-563, L542 | `Command::FinishInstall`, `restart_failed` | `updater-engine-restart-refusal-retry` (passes) | +| G16 | Checks do not start while a download or install runs | L276, L300, L312 | `Command::BeginCheck` | `updater-generation-retry (state-updater.spec.js)` (passes) | +| G17 | Compact `-app-zst` target: one check with no in-place retry, then the legacy `-beta-` target without `-zst` | L147-153, L205-216 | `check_feed`, `legacy_target` | `updater-compact-target-fallback` (passes) | +| G18 | The compact failure is logged; logging never changes the check | L219-228 | `check_feed` (`logging::warn`) | `updater-compact-target-fallback` (passes) | +| G19 | A feed that answers with no update is retried once when a target was requested (beta manifests are renamed in two steps) | L257-259 | `check_target` | `updater-engine-feed-empty-retry` (passes) | +| G20 | A feed error is retried once in place for explicit targets (non-compact) | L246-252 | `check_target` | `updater-engine-feed-error-retry` (passes) | +| G21 | A check whose target changed during the feed request is discarded and restarted | L322-333 | `Command::Decide` | `updater-engine-target-changed-during-feed` (passes) | +| G22 | A feed error re-resolves the target; a changed target restarts the check; a failed resolve ends silently | L388-402 | `Command::CheckFailed` | `updater-engine-feed-error-recheck` and `updater-engine-feed-error-unresolved` (passes) | +| G23 | A feed error is emitted only while the check is current | L403-405 | `Command::CheckFailed` | `updater-engine-feed-error` (passes) | +| G24 | Installed identity still pending: a check reports `downloaded` without touching the feed | L301-308 | `Command::TargetKnown` | `updater-engine-installed-identity-reported` (passes) | +| G25 | Same version, same target, already downloaded: the feed result is closed and `downloaded` is reported with the existing candidate id | L357-370 | `Command::Decide` | `updater-engine-same-candidate-redownload-skipped` (passes) | +| G26 | No update for the same target while downloaded: `downloaded`; otherwise the pending identity is released and `not-available` is emitted | L335-355 | `Command::Decide` | `updater-engine-not-available-releases-candidate` (passes) | +| G27 | `not-available` and `available` carry `isBeta` computed from the version string, not from the renderer | L23, L353, L384 | `is_beta_version` | `updater-engine-event-variants` (passes) | +| G28 | Download progress is emitted only for the current download, and at most every 100 ms; percent is clamped to 100 | L38, L447, L454, L458 | `Command::DownloadProgress` | `updater-engine-download-progress-throttle` (passes) | +| G29 | Check timeout is 30 s; download timeout is 30 min | L35-37, L244, L464 | `check_target`, `download_worker` | `updater-engine-check-timeout` (30 s, no override) and `updater-engine-download-timeout` (override) (passes) | +| G30 | A download that fails after completing releases the candidate; one that fails before completing keeps it | L486-491 | `Command::FinishDownload` | `updater-engine-download-timeout` (fails before completing keeps it) and `updater-engine-download-failure-releases-candidate` (fails after completing releases it) (passes) | +| G31 | Finally block: a download that held the candidate releases it on cancel or recheck, and clears the single-flight lock | L492-506 | `Command::FinishDownload` | `updater-engine-download-cancel-discards` (passes) | +| G32 | Install failure keeps the candidate only while it is still pending; the error is an `install` error | L560-563 | `Command::FinishInstall` | `updater-engine-restart-refusal-retry` (passes) | +| G33 | The plugin's `on_before_exit` flush can refuse before an install; the candidate and its bytes are kept for retry | vendored `updater.rs` (`run_preinstall_flush`), `main.rs` | `install_flow` (plugin `install`) | (passes) `updater-engine-pre-install-flush-retry`: the install probe runs the same hook main.rs registers (`crate::window::shutdown`) after the signature check and before it records the install, which is the plugin's order (`install`: verify, `run_preinstall_flush`, install). A refused flush (queue backup path blocked) records no install and no restart, and the candidate stays pending; with the fault removed the retry installs the kept bytes (no new download) and restarts. Also `updater-generation-retry` in `e2e/state-updater.spec.js`. | +| G34 | Compact routing: a stable compact target is asked once and used; a failed compact feed falls back to the default target once (no in-place retry); a compact feed that answers with no update is asked again but never falls back; with no compact target, stable asks the default target and beta asks the beta target | L147-153, L205-216, L257-259 | `resolve_target`, `check_feed`, `check_target` | `updater-engine-compact-routing` (passes) | + +## Ordering rules that carry over + +1. A channel change, a cancel, a check, a download and an install all bump or + read the same generations as before (`checks`, `downloads`, `sequence`). + Every async step re-checks its generation before it commits. +2. The state thread never performs I/O. It decides and emits. Workers perform + I/O (feed requests, settings reads, downloads, installs) and report back. +3. Events are emitted from the state thread only, so their order follows the + order of decisions. + +## Notes on what cannot be exercised as-is + +- A real macOS or Linux install replaces the app bundle. E2E builds therefore + run with an install probe (`e2e_configure_updater` `installProbe: true`): + signature verification is real (`Update::verify` runs on the downloaded + bytes), and the replacement step is recorded instead of run. +- Restart is never performed in an E2E build. The probe answers restart with a + configurable number of refusals, then success. +- The E2E build also takes `checkTimeoutMs`, `downloadTimeoutMs`, + `installConfirmHoldMs` and `installWriteHoldMs` (`E2eUpdaterConfig`). They + shorten the timeouts or hold an install at one point, so G07, G13 and G29 can + be exercised without races. Production never sets them. +- The E2E install probe runs the same before-exit flush the plugin runs + (`window::shutdown()`), after the signature check and before it records the + install, so G33 is exercised. Only the bundle replacement itself is skipped. +- Signatures come from a minisign key generated at test time into the + scenario's temporary directory (`e2e/helpers/updater-signing.js`). No private + key is committed. diff --git a/e2e/v5-fixes/updater-engine/updater-engine.spec.js b/e2e/v5-fixes/updater-engine/updater-engine.spec.js new file mode 100644 index 00000000..10d16cbf --- /dev/null +++ b/e2e/v5-fixes/updater-engine/updater-engine.spec.js @@ -0,0 +1,1621 @@ +import fs from "node:fs"; +import path from "node:path"; +import assert from "node:assert/strict"; +import { fileURLToPath } from "node:url"; +import { browser } from "@wdio/globals"; +import { waitForAppReady } from "../../helpers/app-bridge.js"; +import { readListFile } from "../../helpers/persisted.js"; +import { + captureUpdaterStatuses, + clickManualCheck, + setUpdateChannel, + startUpdaterFixture, +} from "../../helpers/updater-engine-fixture.js"; + +// Updater engine failure modes (e2e/v5-fixes/updater-engine/failure-modes.md). +// Each scenario runs the Rust engine against a local signed update server. The +// engine probe counts installs and restarts; scenarios read deltas because the +// probe belongs to the app process. +const EXPECTED_CHECKS = 27; +const BETA = "darwin-beta-aarch64-app"; +const here = path.dirname(fileURLToPath(import.meta.url)); +const runDirectory = path.join( + here, + "..", + "..", + "artifacts", + "v5-fixes-updater-engine", + new Date().toISOString().replace(/[:.]/g, "-"), +); +const checks = []; +let fixture = null; + +function record(name, details) { + checks.push({ name, passed: true, ...details }); +} + +function writeReport() { + fs.mkdirSync(runDirectory, { recursive: true }); + const passed = + checks.length === EXPECTED_CHECKS && checks.every((check) => check.passed); + fs.writeFileSync( + path.join(runDirectory, "report.json"), + `${JSON.stringify({ area: "updater-engine", passed, checks }, null, 2)}\n`, + ); +} + +const DATA_DIR = process.env.ROSI_E2E_DATA_DIR; + +function settingsFile() { + assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); + return path.join(DATA_DIR, "settings.json"); +} + +/** Edits the channel on disk only, so the engine gets no channel event. */ +function writeChannelOnDisk(channel) { + const value = JSON.parse(fs.readFileSync(settingsFile(), "utf8")); + value.updateChannel = channel; + fs.writeFileSync(settingsFile(), JSON.stringify(value)); +} + +/** Makes the next channel save fail: the file claims a newer schema. */ +function makeSettingsUnsavable() { + const value = JSON.parse(fs.readFileSync(settingsFile(), "utf8")); + value.settingsVersion = 9_999; + fs.writeFileSync(settingsFile(), JSON.stringify(value)); +} + +function artifactRequestCount() { + return fixture.server.requests.filter((request) => + request.path.startsWith("/artifacts/"), + ).length; +} + +/** Holds a response until the returned release function runs. */ +function holdResponse() { + let release = () => {}; + const gate = new Promise((resolve) => { + release = resolve; + }); + return { gate, release }; +} + +async function dismissModal() { + const modal = await readModal(); + if (modal.active) { + await clickModal(modal.buttons.includes("Later") ? "Later" : "OK"); + } +} + +async function latestCandidate() { + return (await statuses("engineStatuses")) + .filter((event) => event.status === "available") + .at(-1); +} + +function feedTargets(index) { + return fixture.server.requests + .slice(index) + .map((request) => request.path) + .filter((item) => item.startsWith("/latest-")) + .map((item) => item.replace(/^\/latest-|\.json$/g, "")); +} + +function osName() { + return { darwin: "darwin", linux: "linux", win32: "windows" }[ + process.platform + ]; +} + +function stableTarget() { + const arch = { arm64: "aarch64", x64: "x86_64" }[process.arch]; + return `${osName()}-${arch}`; +} + +async function freshRenderer() { + await browser.execute(() => { + window.__ROSI_E2E__.ready = false; + window.setTimeout(() => window.location.reload(), 50); + }); + await waitForAppReady(); +} + +async function invoke(command, args) { + return browser.executeAsync( + (name, payload, done) => { + window.__TAURI__.core.invoke(name, payload).then( + (data) => done({ ok: true, data: data ?? null }), + (error) => done({ error: String(error) }), + ); + }, + command, + args, + ); +} + +async function engineProbe() { + const result = await invoke("e2e_updater_probe"); + assert.ok(result.ok, JSON.stringify(result)); + return result.data; +} + +async function statuses(name) { + return browser.execute((store) => window[store].slice(), name); +} + +async function readModal() { + return browser.execute(() => { + const modal = document.getElementById("app-modal"); + return { + active: modal?.classList.contains("active") === true, + title: document.getElementById("modal-title")?.textContent?.trim() ?? "", + message: document.getElementById("modal-message")?.textContent ?? "", + buttons: [...document.querySelectorAll("#modal-buttons button")].map( + (button) => button.textContent.trim(), + ), + }; + }); +} + +async function waitForModal(title) { + await browser.waitUntil( + async () => { + const modal = await readModal(); + return modal.active && modal.title === title; + }, + { + timeout: 20_000, + interval: 100, + timeoutMsg: `modal "${title}" did not appear`, + }, + ); + return readModal(); +} + +async function clickModal(label) { + await browser.execute((expected) => { + const button = [...document.querySelectorAll("#modal-buttons button")].find( + (candidate) => candidate.textContent.trim() === expected, + ); + if (!button) throw new Error(`modal button "${expected}" was not found`); + button.click(); + }, label); +} + +async function waitForStatus(store, predicate, message, timeout = 20_000) { + await browser.waitUntil(async () => (await statuses(store)).some(predicate), { + timeout, + interval: 100, + timeoutMsg: message, + }); +} + +async function startScenario(options) { + if (fixture) await fixture.close(); + await freshRenderer(); + await setUpdateChannel(options.channel ?? "stable"); + fixture = await startUpdaterFixture(options); + await captureUpdaterStatuses("engineStatuses"); +} + +describe("Updater engine failure modes", () => { + before(waitForAppReady); + after(async () => { + if (fixture) await fixture.close(); + writeReport(); + }); + + it("refuses a check in an unpackaged build without any feed request", async () => { + await startScenario({ isPackaged: false }); + const before = await engineProbe(); + await clickManualCheck(); + const modal = await waitForModal("Development Mode"); + assert.ok(modal.message.includes("development mode"), modal.message); + await clickModal("OK"); + const feeds = fixture.server.requests.filter((request) => + request.path.startsWith("/latest-"), + ); + assert.equal(feeds.length, 0, JSON.stringify(feeds)); + assert.deepEqual(await engineProbe(), before); + record("updater-engine-dev-mode-refusal", { feedRequests: feeds.length }); + }); + + it("refuses a check on a retired Linux package target without any feed request", async () => { + await startScenario({ + channel: "beta", + betaTarget: "linux-beta-x86_64-deb", + }); + await clickManualCheck(); + const modal = await waitForModal("Update Check Failed"); + assert.ok(modal.message.includes("DEB and RPM"), modal.message); + await clickModal("OK"); + const feeds = fixture.server.requests.filter((request) => + request.path.startsWith("/latest-"), + ); + assert.equal(feeds.length, 0, JSON.stringify(feeds)); + record("updater-engine-retired-linux-package", { + feedRequests: feeds.length, + message: modal.message.split("\n").at(-1), + }); + }); + + it("ignores install and download requests for a candidate that is not pending", async () => { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.1", + payload: Buffer.from("candidate mismatch payload"), + fileName: "ROSI-9.0.1.bin", + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Later"); + await waitForStatus( + "engineStatuses", + (event) => event.status === "available", + "the candidate was not offered", + ); + const offered = (await statuses("engineStatuses")).find( + (event) => event.status === "available", + ); + const beforeProbe = await engineProbe(); + const beforeCount = (await statuses("engineStatuses")).length; + + const stale = await invoke("download_update", { + candidateId: offered.candidateId + 100, + }); + assert.equal(stale.data?.cancelled, true, JSON.stringify(stale)); + + // Nothing is downloaded yet, so install of the offered candidate is an error. + await invoke("install_update", { candidateId: offered.candidateId }); + await waitForModal("Update Error"); + await clickModal("OK"); + + // A stale candidate id is ignored without any event. + await invoke("install_update", { candidateId: offered.candidateId + 100 }); + await browser.pause(800); + const after = await statuses("engineStatuses"); + assert.equal( + after.slice(beforeCount).filter((event) => event.status === "error") + .length, + 1, + `stale install produced an event: ${JSON.stringify(after.slice(beforeCount))}`, + ); + assert.deepEqual(await engineProbe(), beforeProbe); + assert.equal( + fixture.server.requests.filter((request) => + request.path.startsWith("/artifacts/"), + ).length, + 0, + ); + record("updater-engine-candidate-mismatch", { + staleDownloadCancelled: stale.data.cancelled, + candidateId: offered.candidateId, + }); + }); + + it("keeps the downloaded candidate when a restart is refused and restarts on retry", async () => { + await startScenario({ restartRefusals: 1 }); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.2", + payload: Buffer.from("restart retry payload"), + fileName: "ROSI-9.0.2.bin", + }); + const before = await engineProbe(); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const candidateId = (await statuses("engineStatuses")).find( + (event) => event.status === "downloaded", + )?.candidateId; + assert.ok(candidateId !== undefined, "the download did not finish"); + + await invoke("install_update", { candidateId }); + const refused = await waitForModal("Update Error"); + assert.ok(refused.message.includes("refused"), refused.message); + await clickModal("OK"); + const afterRefusal = await engineProbe(); + assert.equal(afterRefusal.installs - before.installs, 1); + assert.equal(afterRefusal.refusedRestarts - before.refusedRestarts, 1); + assert.equal(afterRefusal.restarts - before.restarts, 0); + + // The retry only restarts: the verified bytes are not installed again. + const retry = await invoke("install_update", { candidateId }); + assert.ok(retry.ok, JSON.stringify(retry)); + await browser.pause(800); + const afterRetry = await engineProbe(); + assert.equal(afterRetry.installs - before.installs, 1); + assert.equal(afterRetry.restarts - before.restarts, 1); + record("updater-engine-restart-refusal-retry", { + candidateId, + refusedRestarts: afterRetry.refusedRestarts - before.refusedRestarts, + installsAfterRetry: afterRetry.installs - before.installs, + }); + }); + + it("keeps the candidate and its bytes when the pre-install flush refuses, and installs on retry", async () => { + assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); + const queueFile = path.join(DATA_DIR, "download-queue.json"); + const backupPath = path.join(DATA_DIR, "download-queue.backup.json"); + const priorBackup = fs.existsSync(backupPath) + ? fs.readFileSync(backupPath) + : null; + try { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.3", + payload: Buffer.from("pre-install flush payload"), + fileName: "ROSI-9.0.3.bin", + }); + const before = await engineProbe(); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const candidateId = (await statuses("engineStatuses")).find( + (event) => event.status === "downloaded", + )?.candidateId; + assert.ok(candidateId !== undefined, "the download did not finish"); + const artifactsBefore = artifactRequestCount(); + + // Fault: the queue backup path is a directory, so the shutdown flush refuses. + await invoke("clear_queue"); + fs.rmSync(backupPath, { recursive: true, force: true }); + fs.mkdirSync(backupPath); + const queued = await invoke("add_to_queue", { + urls: ["https://93.184.216.34/updater-pre-install-flush-fault"], + options: null, + }); + assert.equal(queued.data?.data?.added, 1, JSON.stringify(queued)); + const latestQueueId = (await invoke("get_queue")).data?.at(-1)?.id; + assert.ok(latestQueueId); + await browser.waitUntil( + () => { + try { + return readListFile(queueFile).some( + (item) => item.id === latestQueueId, + ); + } catch { + return false; + } + }, + { + timeout: 10_000, + interval: 100, + timeoutMsg: "faulted queue item did not reach the primary file", + }, + ); + + await invoke("install_update", { candidateId }); + const refused = await waitForModal("Update Error"); + assert.ok( + refused.message.trim().length > 0, + "the refusal had no message", + ); + await clickModal("OK"); + // The flush runs before the install, so nothing is installed or restarted. + const afterRefusal = await engineProbe(); + assert.equal(afterRefusal.installs - before.installs, 0); + assert.equal(afterRefusal.restarts - before.restarts, 0); + assert.equal(afterRefusal.refusedRestarts - before.refusedRestarts, 0); + assert.equal(artifactRequestCount(), artifactsBefore); + + // Remove the fault. The retry installs the kept bytes without a new download. + fs.rmSync(backupPath, { recursive: true, force: true }); + if (priorBackup) fs.writeFileSync(backupPath, priorBackup); + const retry = await invoke("install_update", { candidateId }); + assert.ok(retry.ok, JSON.stringify(retry)); + await browser.pause(800); + const afterRetry = await engineProbe(); + assert.equal(afterRetry.installs - before.installs, 1); + assert.equal(afterRetry.restarts - before.restarts, 1); + assert.equal(afterRetry.refusedRestarts - before.refusedRestarts, 0); + assert.equal(artifactRequestCount(), artifactsBefore); + record("updater-engine-pre-install-flush-retry", { + candidateId, + refusal: refused.message, + installsAfterRefusal: afterRefusal.installs - before.installs, + installsAfterRetry: afterRetry.installs - before.installs, + restartsAfterRetry: afterRetry.restarts - before.restarts, + downloadsDuringRetry: artifactRequestCount() - artifactsBefore, + }); + } finally { + fs.rmSync(backupPath, { recursive: true, force: true }); + if (priorBackup) fs.writeFileSync(backupPath, priorBackup); + await browser.execute(() => { + if ( + document.getElementById("app-modal")?.classList.contains("active") + ) { + const close = [ + ...document.querySelectorAll("#modal-buttons button"), + ].find((button) => + ["Later", "OK"].includes(button.textContent.trim()), + ); + close?.click(); + } + }); + await invoke("clear_queue"); + await browser.waitUntil( + () => { + try { + return ( + readListFile(queueFile).length === 0 && + Array.isArray(readListFile(backupPath)) + ); + } catch { + return false; + } + }, + { + timeout: 10_000, + interval: 100, + timeoutMsg: "pre-install flush test queue did not clean up", + }, + ); + } + }); + + it("discards a download that completes after cancel", async () => { + let releaseArtifact; + const gate = new Promise((resolve) => { + releaseArtifact = resolve; + }); + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.3", + payload: Buffer.from("cancelled download payload"), + fileName: "ROSI-9.0.3.bin", + gate, + }); + const before = await engineProbe(); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Download & Install"); + await browser.waitUntil( + () => + fixture.server.requests.some((request) => + request.path.startsWith("/artifacts/"), + ), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the download never started", + }, + ); + await invoke("cancel_update_download"); + await waitForModal("Download Cancelled"); + await clickModal("OK"); + + releaseArtifact(); + await browser.pause(2_000); + const events = (await statuses("engineStatuses")).map( + (event) => event.status, + ); + assert.ok(!events.includes("downloaded"), JSON.stringify(events)); + assert.equal( + (await readModal()).active, + false, + "a late download opened a prompt", + ); + const after = await engineProbe(); + assert.equal(after.installs - before.installs, 0); + assert.equal(after.restarts - before.restarts, 0); + record("updater-engine-download-cancel-discards", { + events, + installs: after.installs - before.installs, + }); + }); + + it("emits checking before the result of a manual check", async () => { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.4", + payload: Buffer.from("checking order payload"), + fileName: "ROSI-9.0.4.bin", + }); + const before = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Later"); + const seen = (await statuses("engineStatuses")) + .slice(before) + .map((event) => event.status); + const checking = seen.indexOf("checking"); + const available = seen.indexOf("available"); + assert.ok(checking >= 0 && available > checking, JSON.stringify(seen)); + record("updater-engine-checking-before-result", { sequence: seen }); + }); + + it("reports a feed failure as a feed error and shows it for a manual check", async () => { + await startScenario({}); + fixture.server.respond(osName(), 500, "controlled feed failure"); + const before = (await statuses("engineStatuses")).length; + await clickManualCheck(); + const modal = await waitForModal("Update Error"); + assert.ok(modal.message.length > 0, modal.message); + await clickModal("OK"); + const errors = (await statuses("engineStatuses")) + .slice(before) + .filter((event) => event.status === "error"); + assert.equal(errors.length, 1, JSON.stringify(errors)); + assert.equal(errors[0].kind, "feed"); + record("updater-engine-feed-error", { kind: errors[0].kind }); + }); + + it("reports a download failure when the archive signature does not match", async () => { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.5", + payload: Buffer.from("signed payload"), + fileName: "ROSI-9.0.5.bin", + }); + fixture.server.tamper("ROSI-9.0.5.bin", Buffer.from("unsigned substitute")); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Later"); + const offered = (await statuses("engineStatuses")).find( + (event) => event.status === "available", + ); + const before = (await statuses("engineStatuses")).length; + const result = await invoke("download_update", { + candidateId: offered.candidateId, + }); + assert.ok(result.data?.error, JSON.stringify(result)); + await waitForModal("Update Error"); + await clickModal("OK"); + const errors = (await statuses("engineStatuses")) + .slice(before) + .filter((event) => event.status === "error"); + assert.equal(errors.length, 1, JSON.stringify(errors)); + assert.equal(errors[0].kind, "download"); + record("updater-engine-download-error", { kind: errors[0].kind }); + }); + + it("routes compact targets and falls back only when the compact feed fails", async () => { + // Z03.1, Z03.3 (stable), Z03.4, Z03.6 of e2e/updater-zst.failure-modes.md. + const compact = `${osName()}-aarch64-app-zst`; + const feedsSince = (index) => + fixture.server.requests + .slice(index) + .map((request) => request.path) + .filter((item) => item.startsWith("/latest-")) + .map((item) => item.replace(/^\/latest-|\.json$/g, "")); + const manualCheck = async (expectedTitle) => { + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await waitForModal(expectedTitle); + await clickModal( + expectedTitle === "ROSI is up to date!" ? "OK" : "Later", + ); + const settled = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + return { feeds: feedsSince(requestIndex), settled }; + }; + + // Z03.1: the stable compact target is asked once and its answer is used. + await startScenario({ compactTarget: compact, disableCompact: false }); + fixture.server.publish({ + target: compact, + version: "9.0.6", + payload: Buffer.from("compact payload"), + fileName: "ROSI-9.0.6.app.tar.zst", + }); + const used = await manualCheck("Update Available!"); + assert.deepEqual(used.feeds, [compact]); + assert.ok(used.settled.includes("available"), JSON.stringify(used)); + + // Z03.4: a compact feed with no newer version is asked again, never falls back. + fixture.server.publish({ + target: compact, + version: "1.0.0", + payload: Buffer.from("older compact payload"), + fileName: "ROSI-1.0.0.app.tar.zst", + }); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.7", + payload: Buffer.from("legacy payload that must not be offered"), + fileName: "ROSI-9.0.7.app.tar.gz", + }); + const empty = await manualCheck("ROSI is up to date!"); + assert.deepEqual(empty.feeds, [compact, compact]); + assert.ok(empty.settled.includes("not-available"), JSON.stringify(empty)); + + // Z03.3 (stable): a missing compact feed is not retried in place; the + // default target is asked once and its update is offered. + fixture.server.unpublish(compact); + const fallback = await manualCheck("Update Available!"); + assert.deepEqual(fallback.feeds, [compact, osName()]); + const offered = (await statuses("engineStatuses")) + .filter((event) => event.status === "available") + .at(-1); + assert.equal(offered?.version, "9.0.7", JSON.stringify(offered)); + + // Z03.6: with no compact target, stable asks the default target and beta + // asks the beta target, as before 5.1. + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.0.8", + payload: Buffer.from("default target payload"), + fileName: "ROSI-9.0.8.app.tar.gz", + }); + const plain = await manualCheck("Update Available!"); + assert.deepEqual(plain.feeds, [osName()]); + const betaIndex = fixture.server.requests.length; + await setUpdateChannel("beta"); + await browser.waitUntil(() => feedsSince(betaIndex).length >= 1, { + timeout: 20_000, + interval: 100, + timeoutMsg: "the channel change did not recheck the beta target", + }); + await browser.pause(500); + const betaFeeds = feedsSince(betaIndex); + assert.ok( + betaFeeds.every((target) => target === "darwin-beta-aarch64-app"), + JSON.stringify(betaFeeds), + ); + await setUpdateChannel("stable"); + await browser.pause(500); + record("updater-engine-compact-routing", { + compactUsed: used.feeds, + compactEmpty: empty.feeds, + compactMissing: fallback.feeds, + noCompactStable: plain.feeds, + noCompactBeta: betaFeeds, + }); + }); + + it("discards a check result that arrives after the channel changed", async () => { + // G04: the beta answer is held while the channel moves to stable. + await startScenario({ channel: "beta" }); + await browser.pause(1_000); + let releaseBeta = () => {}; + const betaGate = new Promise((resolve) => { + releaseBeta = resolve; + }); + try { + fixture.server.publish({ + target: "darwin-beta-aarch64-app", + version: "9.1.0-beta.1", + payload: Buffer.from("stale beta payload"), + fileName: "ROSI-9.1.0-beta.1.bin", + manifestGate: betaGate, + }); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.1.0", + payload: Buffer.from("stable payload"), + fileName: "ROSI-9.1.0.bin", + }); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + // Not awaited: the command returns only when the held check settles. + await browser.execute(() => { + window.__TAURI__.core.invoke("check_for_updates").catch(() => {}); + }); + await browser.waitUntil( + () => feedTargets(requestIndex).includes("darwin-beta-aarch64-app"), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the beta feed was not requested", + }, + ); + await setUpdateChannel("stable"); + await waitForStatus( + "engineStatuses", + (event) => event.status === "available" && event.version === "9.1.0", + "the stable update was not offered after the channel change", + ); + releaseBeta(); + // Give the released beta answer time to reach the engine and be fenced. + await browser.pause(1_500); + const seen = (await statuses("engineStatuses")).slice(statusIndex); + assert.ok( + !seen.some((event) => event.version === "9.1.0-beta.1"), + JSON.stringify(seen), + ); + const offered = seen.filter((event) => event.status === "available"); + assert.equal(offered.at(-1)?.version, "9.1.0", JSON.stringify(seen)); + const modal = await readModal(); + if (modal.active && modal.buttons.includes("Later")) { + await clickModal("Later"); + } + record("updater-engine-stale-check-after-channel-change", { + feeds: feedTargets(requestIndex), + offered: offered.map((event) => event.version), + }); + } finally { + releaseBeta(); + } + }); + + it("refuses to revalidate until the channel is saved, then rechecks", async () => { + // G05: a settings.json from a newer schema makes every save fail. + assert.ok(DATA_DIR, "ROSI_E2E_DATA_DIR is not set"); + const settingsPath = path.join(DATA_DIR, "settings.json"); + await startScenario({ channel: "stable" }); + await browser.pause(1_000); + fixture.server.publish({ + target: "darwin-beta-aarch64-app", + version: "9.2.0-beta.1", + payload: Buffer.from("beta payload after save"), + fileName: "ROSI-9.2.0-beta.1.bin", + }); + const original = fs.readFileSync(settingsPath); + try { + const newer = JSON.parse(original.toString("utf8")); + newer.settingsVersion = 9_999; + fs.writeFileSync(settingsPath, JSON.stringify(newer)); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + await setUpdateChannel("beta"); + await waitForStatus( + "engineStatuses", + (event) => event.status === "error", + "the unsaved channel did not refuse the background check", + ); + await clickManualCheck(); + const modal = await waitForModal("Update Error"); + assert.match(modal.message, /could not be saved before revalidation/); + await clickModal("OK"); + const errors = (await statuses("engineStatuses")) + .slice(statusIndex) + .filter((event) => event.status === "error"); + assert.ok(errors.length >= 2, JSON.stringify(errors)); + assert.ok( + errors.every((event) => event.kind === "feed"), + JSON.stringify(errors), + ); + const feedsWhileUnsaved = feedTargets(requestIndex); + assert.deepEqual(feedsWhileUnsaved, []); + assert.equal( + JSON.parse(fs.readFileSync(settingsPath, "utf8")).settingsVersion, + 9_999, + "the refused save replaced the newer settings file", + ); + + // The same channel saved successfully counts as a change and rechecks. + fs.writeFileSync(settingsPath, original); + const savedIndex = fixture.server.requests.length; + await setUpdateChannel("beta"); + await waitForStatus( + "engineStatuses", + (event) => + event.status === "available" && event.version === "9.2.0-beta.1", + "the saved channel did not recheck the beta feed", + ); + assert.ok( + feedTargets(savedIndex).every( + (target) => target === "darwin-beta-aarch64-app", + ), + JSON.stringify(feedTargets(savedIndex)), + ); + record("updater-engine-channel-save-failure", { + refusedErrors: errors.length, + feedsWhileUnsaved, + feedsAfterSave: feedTargets(savedIndex), + }); + } finally { + fs.writeFileSync(settingsPath, original); + const modal = await readModal(); + if (modal.active) { + await clickModal(modal.buttons.includes("Later") ? "Later" : "OK"); + } + await setUpdateChannel("stable"); + await browser.pause(500); + } + }); + + it("retries a feed that answers no update once for an explicit target", async () => { + await startScenario({ channel: "beta" }); + await browser.pause(1_000); + fixture.server.queueFeed(BETA, [{ status: 204 }]); + fixture.server.publish({ + target: BETA, + version: "9.4.0-beta.1", + payload: Buffer.from("empty feed retry payload"), + fileName: "ROSI-9.4.0-beta.1.bin", + }); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await waitForModal("Beta Update Available!"); + await clickModal("Later"); + const seen = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [BETA, BETA], JSON.stringify(seen)); + assert.ok(seen.includes("available"), JSON.stringify(seen)); + record("updater-engine-feed-empty-retry", { feeds, sequence: seen }); + }); + + it("retries a feed error once in place for an explicit target", async () => { + await startScenario({ channel: "beta" }); + await browser.pause(1_000); + fixture.server.queueFeed(BETA, [ + { status: 500, body: "controlled retry failure" }, + ]); + fixture.server.publish({ + target: BETA, + version: "9.4.1-beta.1", + payload: Buffer.from("feed error retry payload"), + fileName: "ROSI-9.4.1-beta.1.bin", + }); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await waitForModal("Beta Update Available!"); + await clickModal("Later"); + const seen = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [BETA, BETA], JSON.stringify(seen)); + assert.ok(!seen.includes("error"), JSON.stringify(seen)); + record("updater-engine-feed-error-retry", { feeds, sequence: seen }); + }); + + it("discards a check whose target changed during the feed request", async () => { + await startScenario({}); + await browser.pause(1_000); + const original = fs.readFileSync(settingsFile()); + const held = holdResponse(); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.5.0", + payload: Buffer.from("stale stable payload"), + fileName: "ROSI-9.5.0.bin", + manifestGate: held.gate, + }); + fixture.server.publish({ + target: BETA, + version: "9.5.1-beta.1", + payload: Buffer.from("beta target payload"), + fileName: "ROSI-9.5.1-beta.1.bin", + }); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + try { + // Not awaited: the command returns only when the held check settles. + await browser.execute(() => { + window.__TAURI__.core.invoke("check_for_updates").catch(() => {}); + }); + await browser.waitUntil( + () => feedTargets(requestIndex).includes(osName()), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the stable feed was not requested", + }, + ); + // Only the file changes, so the check gets no channel event and stays current. + writeChannelOnDisk("beta"); + held.release(); + await waitForStatus( + "engineStatuses", + (event) => + event.status === "available" && event.version === "9.5.1-beta.1", + "the beta target was not offered after the target changed", + ); + await dismissModal(); + const seen = (await statuses("engineStatuses")).slice(statusIndex); + assert.ok( + !seen.some((event) => event.version === "9.5.0"), + JSON.stringify(seen), + ); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [osName(), BETA]); + record("updater-engine-target-changed-during-feed", { + feeds, + offered: seen + .filter((event) => event.status === "available") + .map((event) => event.version), + }); + } finally { + held.release(); + fs.writeFileSync(settingsFile(), original); + await dismissModal(); + } + }); + + it("re-resolves the target after a feed error and restarts when it changed", async () => { + await startScenario({ channel: "beta" }); + await browser.pause(1_000); + const original = fs.readFileSync(settingsFile()); + const held = holdResponse(); + fixture.server.respond(BETA, 500, "held feed failure", { gate: held.gate }); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.6.0", + payload: Buffer.from("recheck stable payload"), + fileName: "ROSI-9.6.0.bin", + }); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + try { + await browser.execute(() => { + window.__TAURI__.core.invoke("check_for_updates").catch(() => {}); + }); + await browser.waitUntil(() => feedTargets(requestIndex).includes(BETA), { + timeout: 20_000, + interval: 100, + timeoutMsg: "the beta feed was not requested", + }); + writeChannelOnDisk("stable"); + held.release(); + await waitForStatus( + "engineStatuses", + (event) => event.status === "available" && event.version === "9.6.0", + "the stable target was not offered after the failed check", + ); + await dismissModal(); + const seen = (await statuses("engineStatuses")).slice(statusIndex); + assert.ok( + !seen.some((event) => event.status === "error"), + JSON.stringify(seen), + ); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [BETA, BETA, osName()]); + record("updater-engine-feed-error-recheck", { + feeds, + sequence: seen.map((event) => event.status), + }); + } finally { + held.release(); + fs.writeFileSync(settingsFile(), original); + await dismissModal(); + } + }); + + it("ends a feed error silently when the target cannot be resolved", async () => { + await startScenario({ channel: "beta" }); + await browser.pause(1_000); + const original = fs.readFileSync(settingsFile()); + const held = holdResponse(); + fixture.server.respond(BETA, 500, "held feed failure", { gate: held.gate }); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + try { + await browser.execute(() => { + window.__TAURI__.core.invoke("check_for_updates").catch(() => {}); + }); + await browser.waitUntil(() => feedTargets(requestIndex).includes(BETA), { + timeout: 20_000, + interval: 100, + timeoutMsg: "the beta feed was not requested", + }); + // The refused save leaves the channel unsaved; no recheck starts. + makeSettingsUnsavable(); + await setUpdateChannel("beta"); + held.release(); + await browser.waitUntil(() => feedTargets(requestIndex).length >= 2, { + timeout: 20_000, + interval: 100, + timeoutMsg: "the feed error was not retried in place", + }); + await browser.pause(1_000); + const seen = (await statuses("engineStatuses")).slice(statusIndex); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [BETA, BETA]); + assert.ok( + !seen.some((event) => event.status === "error"), + JSON.stringify(seen), + ); + assert.equal( + (await readModal()).active, + false, + "a silent failure opened a prompt", + ); + record("updater-engine-feed-error-unresolved", { + feeds, + sequence: seen.map((event) => event.status), + }); + } finally { + held.release(); + fs.writeFileSync(settingsFile(), original); + // A successful save clears the unsaved channel and rechecks. + await setUpdateChannel("beta"); + await browser.pause(1_000); + await dismissModal(); + } + }); + + it("reports an installed identity as downloaded without asking the feed", async () => { + await startScenario({ restartRefusals: 1 }); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.7.0", + payload: Buffer.from("installed identity payload"), + fileName: "ROSI-9.7.0.bin", + }); + const before = await engineProbe(); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const candidateId = (await statuses("engineStatuses")).find( + (event) => event.status === "downloaded", + )?.candidateId; + assert.ok(candidateId !== undefined, "the download did not finish"); + await invoke("install_update", { candidateId }); + const refused = await waitForModal("Update Error"); + assert.ok(refused.message.includes("refused"), refused.message); + await clickModal("OK"); + const afterRefusal = await engineProbe(); + assert.equal(afterRefusal.installs - before.installs, 1); + assert.equal(afterRefusal.restarts - before.restarts, 0); + + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await browser.waitUntil( + async () => + (await statuses("engineStatuses")) + .slice(statusIndex) + .some( + (event) => + event.status === "downloaded" && + event.candidateId === candidateId, + ), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the installed identity was not reported", + }, + ); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const seen = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, []); + assert.ok(!seen.includes("available"), JSON.stringify(seen)); + assert.deepEqual(await engineProbe(), afterRefusal); + + // The retry finishes the pending restart and releases the candidate. + const retry = await invoke("install_update", { candidateId }); + assert.ok(retry.ok, JSON.stringify(retry)); + await browser.pause(800); + const done = await engineProbe(); + assert.equal(done.installs - before.installs, 1); + assert.equal(done.restarts - before.restarts, 1); + record("updater-engine-installed-identity-reported", { + candidateId, + feeds, + sequence: seen, + }); + }); + + it("keeps a downloaded candidate when the same version is offered again", async () => { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.8.0", + payload: Buffer.from("same candidate payload"), + fileName: "ROSI-9.8.0.bin", + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const { candidateId } = await latestCandidate(); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + const artifactsBefore = artifactRequestCount(); + await clickManualCheck(); + await browser.waitUntil( + async () => + (await statuses("engineStatuses")) + .slice(statusIndex) + .some( + (event) => + event.status === "downloaded" && + event.candidateId === candidateId, + ), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the downloaded candidate was not reported again", + }, + ); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const seen = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + assert.deepEqual(feedTargets(requestIndex), [osName()]); + assert.ok(!seen.includes("available"), JSON.stringify(seen)); + assert.equal(artifactRequestCount() - artifactsBefore, 0); + record("updater-engine-same-candidate-redownload-skipped", { + candidateId, + sequence: seen, + }); + await invoke("install_update", { candidateId }); + await browser.pause(800); + }); + + it("keeps a downloaded candidate on no update and releases an undownloaded one", async () => { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.10.0", + payload: Buffer.from("kept candidate payload"), + fileName: "ROSI-9.10.0.bin", + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const keptId = (await latestCandidate()).candidateId; + + // Downloaded: a no-update answer reports the download, not "not available". + fixture.server.respond(osName(), 204); + let statusIndex = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await browser.waitUntil( + async () => + (await statuses("engineStatuses")) + .slice(statusIndex) + .some( + (event) => + event.status === "downloaded" && event.candidateId === keptId, + ), + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the downloaded candidate was not kept", + }, + ); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const keptEvents = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + assert.ok( + !keptEvents.includes("not-available"), + JSON.stringify(keptEvents), + ); + await invoke("install_update", { candidateId: keptId }); + await browser.pause(800); + + // Offered but not downloaded: a no-update answer releases it. + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.10.1", + payload: Buffer.from("offered candidate payload"), + fileName: "ROSI-9.10.1.bin", + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + await clickModal("Later"); + const offeredId = (await latestCandidate()).candidateId; + fixture.server.respond(osName(), 204); + statusIndex = (await statuses("engineStatuses")).length; + await clickManualCheck(); + await waitForModal("ROSI is up to date!"); + await clickModal("OK"); + const released = await invoke("download_update", { + candidateId: offeredId, + }); + assert.equal(released.data?.cancelled, true, JSON.stringify(released)); + const notAvailable = (await statuses("engineStatuses")) + .slice(statusIndex) + .find((event) => event.status === "not-available"); + assert.ok(notAvailable, "no not-available event followed the release"); + record("updater-engine-not-available-releases-candidate", { + keptId, + keptEvents, + offeredId, + releasedCancelled: released.data.cancelled, + }); + }); + + it("computes isBeta from the version string on available and not-available events", async () => { + await startScenario({}); + const statusIndex = (await statuses("engineStatuses")).length; + const checkAndDismiss = async (version, title, button) => { + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version, + payload: Buffer.from(`variant ${version}`), + fileName: `ROSI-${version}.bin`, + }); + await clickManualCheck(); + await waitForModal(title); + await clickModal(button); + }; + await checkAndDismiss("9.9.0-beta.1", "Beta Update Available!", "Later"); + await checkAndDismiss("9.9.1-RC.2", "Beta Update Available!", "Later"); + await checkAndDismiss("9.9.2", "Update Available!", "Later"); + fixture.server.respond(osName(), 204); + await clickManualCheck(); + await waitForModal("ROSI is up to date!"); + await clickModal("OK"); + const events = (await statuses("engineStatuses")) + .slice(statusIndex) + .filter((event) => ["available", "not-available"].includes(event.status)) + .map((event) => ({ + status: event.status, + version: event.version, + isBeta: event.isBeta, + })); + assert.deepEqual( + events.map((event) => event.isBeta), + [true, true, false, true], + JSON.stringify(events), + ); + for (const event of events) { + assert.equal( + event.isBeta, + /-(beta|alpha|rc)/i.test(event.version), + JSON.stringify(event), + ); + } + record("updater-engine-event-variants", { events }); + }); + + it("throttles download progress to 100 ms and never reports above 100 percent", async () => { + await startScenario({}); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.14.0", + payload: Buffer.alloc(3 * 1024 * 1024, 7), + fileName: "ROSI-9.14.0.bin", + drip: { chunkBytes: 32 * 1024, intervalMs: 10 }, + }); + await browser.execute(() => { + window.__progress = []; + window.__TAURI__.event.listen("updater-progress", (event) => { + window.__progress.push({ ...event.payload, at: performance.now() }); + }); + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + const { candidateId } = await latestCandidate(); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + const progress = await browser.execute(() => window.__progress.slice()); + assert.ok(progress.length >= 2, JSON.stringify(progress)); + const gaps = progress + .slice(1) + .map((event, index) => event.at - progress[index].at); + // Gaps are measured at page arrival, which IPC jitter can shorten; the + // count bound below is the primary proof, so the median only guards gross bursts. + const sortedGaps = [...gaps].sort((a, b) => a - b); + const medianGap = sortedGaps[Math.floor(sortedGaps.length / 2)]; + assert.ok(medianGap >= 90, `progress gaps: ${JSON.stringify(gaps)}`); + assert.ok( + progress.every((event) => event.percent >= 0 && event.percent <= 100), + JSON.stringify(progress.map((event) => event.percent)), + ); + const spanMs = progress.at(-1).at - progress[0].at; + assert.ok( + progress.length <= Math.ceil(spanMs / 100) + 1, + `${progress.length} events in ${spanMs} ms`, + ); + + // A cancelled download emits no more progress. + await browser.execute((id) => { + window.__TAURI__.core + .invoke("download_update", { candidateId: id }) + .catch(() => {}); + }, candidateId); + await browser.waitUntil( + async () => + (await browser.execute(() => window.__progress.length)) >= + progress.length + 2, + { + timeout: 20_000, + interval: 50, + timeoutMsg: "the second download made no progress", + }, + ); + await invoke("cancel_update_download"); + await waitForModal("Download Cancelled"); + await clickModal("OK"); + const atCancel = await browser.execute(() => window.__progress.length); + await browser.pause(1_500); + const afterCancel = await browser.execute(() => window.__progress.length); + assert.equal(afterCancel, atCancel, "progress arrived after the cancel"); + record("updater-engine-download-progress-throttle", { + events: progress.length, + minGapMs: Math.min(...gaps), + spanMs, + progressAfterCancel: afterCancel - atCancel, + }); + }); + + it("times out a check at 30 seconds without an override", async () => { + await startScenario({}); + const held = holdResponse(); + fixture.server.respond(osName(), 200, "", { gate: held.gate }); + const statusIndex = (await statuses("engineStatuses")).length; + try { + const started = Date.now(); + // Not awaited: the command returns only when the held check settles. + await browser.execute(() => { + window.__TAURI__.core.invoke("check_for_updates").catch(() => {}); + }); + await waitForStatus( + "engineStatuses", + (event) => event.status === "error", + "the held check never timed out", + 60_000, + ); + const elapsedMs = Date.now() - started; + const error = (await statuses("engineStatuses")) + .slice(statusIndex) + .find((event) => event.status === "error"); + assert.equal(error.kind, "feed", JSON.stringify(error)); + assert.ok( + elapsedMs >= 29_000 && elapsedMs < 45_000, + `check timed out after ${elapsedMs} ms`, + ); + record("updater-engine-check-timeout", { + elapsedMs, + kind: error.kind, + message: error.message, + }); + } finally { + held.release(); + } + }); + + it("times out a download at its configured limit and keeps the candidate", async () => { + await startScenario({ downloadTimeoutMs: 1_500 }); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.15.0", + payload: Buffer.alloc(4 * 1024 * 1024, 9), + fileName: "ROSI-9.15.0.bin", + drip: { chunkBytes: 64 * 1024, intervalMs: 100 }, + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + const { candidateId } = await latestCandidate(); + await clickModal("Later"); + const started = Date.now(); + const first = await invoke("download_update", { candidateId }); + const elapsedMs = Date.now() - started; + assert.ok(first.data?.error, JSON.stringify(first)); + // The full body takes about 6 s, so the limit is what ended the transfer. + assert.ok(elapsedMs >= 1_400 && elapsedMs < 5_000, `${elapsedMs} ms`); + await waitForModal("Update Error"); + await clickModal("OK"); + const errors = (await statuses("engineStatuses")).filter( + (event) => event.status === "error", + ); + assert.equal(errors.length, 1, JSON.stringify(errors)); + assert.equal(errors[0].kind, "download"); + + // A failed transfer keeps the candidate, so a retry times out, not cancels. + const second = await invoke("download_update", { candidateId }); + assert.ok(second.data?.error, JSON.stringify(second)); + await waitForModal("Update Error"); + await clickModal("OK"); + record("updater-engine-download-timeout", { + candidateId, + elapsedMs, + message: first.data.error, + retainedCandidate: second.data.cancelled !== true, + }); + }); + + it("releases a candidate whose download fails after the bytes arrived", async () => { + await startScenario({}); + const original = fs.readFileSync(settingsFile()); + const held = holdResponse(); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.16.0", + payload: Buffer.from("post completion failure payload"), + fileName: "ROSI-9.16.0.bin", + gate: held.gate, + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + const { candidateId } = await latestCandidate(); + const statusIndex = (await statuses("engineStatuses")).length; + try { + const artifactsBefore = artifactRequestCount(); + await clickModal("Download & Install"); + await browser.waitUntil(() => artifactRequestCount() > artifactsBefore, { + timeout: 20_000, + interval: 100, + timeoutMsg: "the download never started", + }); + // The channel cannot be saved while the bytes are in flight. + makeSettingsUnsavable(); + await setUpdateChannel("stable"); + held.release(); + const modal = await waitForModal("Update Error"); + assert.match(modal.message, /could not be saved before revalidation/); + await clickModal("OK"); + const seen = (await statuses("engineStatuses")).slice(statusIndex); + const errors = seen.filter((event) => event.status === "error"); + assert.equal(errors.length, 1, JSON.stringify(seen)); + assert.equal(errors[0].kind, "download"); + assert.ok(!seen.some((event) => event.status === "downloaded")); + const released = await invoke("download_update", { candidateId }); + assert.equal(released.data?.cancelled, true, JSON.stringify(released)); + record("updater-engine-download-failure-releases-candidate", { + candidateId, + errorKind: errors[0].kind, + releasedCancelled: released.data.cancelled, + }); + } finally { + held.release(); + fs.writeFileSync(settingsFile(), original); + await setUpdateChannel("stable"); + await browser.pause(1_000); + await dismissModal(); + } + }); + + it("waits for an install that already started before honoring a channel change", async () => { + await startScenario({ installWriteHoldMs: 1_500 }); + await browser.pause(1_000); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.12.0", + payload: Buffer.from("install hold payload"), + fileName: "ROSI-9.12.0.bin", + }); + fixture.server.publish({ + target: BETA, + version: "9.12.1-beta.1", + payload: Buffer.from("beta after install payload"), + fileName: "ROSI-9.12.1-beta.1.bin", + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + const { candidateId } = await latestCandidate(); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + + const before = await engineProbe(); + const requestIndex = fixture.server.requests.length; + // Not awaited: the command returns once the install has finished. + await browser.execute((id) => { + window.__TAURI__.core + .invoke("install_update", { candidateId: id }) + .catch(() => {}); + }, candidateId); + // The install holds 1.5 s after it confirms its target; change the channel inside that window. + await browser.pause(400); + await setUpdateChannel("beta"); + const midInstall = await engineProbe(); + assert.equal(midInstall.installs - before.installs, 0); + assert.equal(midInstall.restarts - before.restarts, 0); + assert.deepEqual(feedTargets(requestIndex), []); + + await browser.waitUntil( + async () => (await engineProbe()).restarts - before.restarts === 1, + { + timeout: 20_000, + interval: 100, + timeoutMsg: "the install did not restart", + }, + ); + const done = await engineProbe(); + assert.equal(done.installs - before.installs, 1); + assert.equal(done.refusedRestarts - before.refusedRestarts, 0); + + // The held channel change rechecks the beta target once the install ends. + await waitForModal("Beta Update Available!"); + await clickModal("Later"); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [BETA]); + record("updater-engine-channel-change-during-install", { + midInstall: { + installs: midInstall.installs - before.installs, + restarts: midInstall.restarts - before.restarts, + }, + feeds, + }); + }); + + it("exits an install whose candidate a channel change released before it confirmed", async () => { + await startScenario({ installConfirmHoldMs: 1_500 }); + await browser.pause(1_000); + fixture.server.publish({ + target: stableTarget(), + route: osName(), + version: "9.13.0", + payload: Buffer.from("stale install payload"), + fileName: "ROSI-9.13.0.bin", + }); + fixture.server.publish({ + target: BETA, + version: "9.13.1-beta.1", + payload: Buffer.from("beta after stale install"), + fileName: "ROSI-9.13.1-beta.1.bin", + }); + await clickManualCheck(); + await waitForModal("Update Available!"); + const { candidateId } = await latestCandidate(); + await clickModal("Download & Install"); + await waitForModal("Update Ready!"); + await clickModal("Later"); + + const before = await engineProbe(); + const requestIndex = fixture.server.requests.length; + const statusIndex = (await statuses("engineStatuses")).length; + // Not awaited: the install waits 1.5 s before it confirms its target. + await browser.execute((id) => { + window.__TAURI__.core + .invoke("install_update", { candidateId: id }) + .catch(() => {}); + }, candidateId); + await browser.pause(400); + // Releases the candidate while the install waits for its target check. + await setUpdateChannel("beta"); + const midInstall = await engineProbe(); + assert.equal(midInstall.installs - before.installs, 0); + + await browser.waitUntil(() => feedTargets(requestIndex).includes(BETA), { + timeout: 20_000, + interval: 100, + timeoutMsg: "the channel change did not recheck the beta target", + }); + await waitForModal("Beta Update Available!"); + await clickModal("Later"); + const after = await engineProbe(); + assert.equal(after.installs - before.installs, 0); + assert.equal(after.restarts - before.restarts, 0); + assert.equal(after.refusedRestarts - before.refusedRestarts, 0); + const seen = (await statuses("engineStatuses")) + .slice(statusIndex) + .map((event) => event.status); + assert.ok(!seen.includes("error"), JSON.stringify(seen)); + const feeds = feedTargets(requestIndex); + assert.deepEqual(feeds, [BETA]); + + const released = await invoke("download_update", { candidateId }); + assert.equal(released.data?.cancelled, true, JSON.stringify(released)); + record("updater-engine-install-identity-stale", { + feeds, + installs: after.installs - before.installs, + sequence: seen, + }); + }); +}); diff --git a/e2e/v5-fixes/upstream-proxy/upstream-proxy.spec.js b/e2e/v5-fixes/upstream-proxy/upstream-proxy.spec.js index 097e0e38..fa264600 100644 --- a/e2e/v5-fixes/upstream-proxy/upstream-proxy.spec.js +++ b/e2e/v5-fixes/upstream-proxy/upstream-proxy.spec.js @@ -441,7 +441,7 @@ describe("V5 optional upstream HTTP proxy", () => { pageThumbnailUrl = `http://127.0.0.1:${pageServer.address().port}/thumb.png`; await browser.execute(() => { window.__upstreamProxyProgress = []; - window.api.onProgress((message) => { + window.__ROSI_E2E__.api.onProgress((message) => { window.__upstreamProxyProgress.push(String(message)); }); }); diff --git a/e2e/wdio.conf.js b/e2e/wdio.conf.js index 8298fa2e..466b1e6a 100644 --- a/e2e/wdio.conf.js +++ b/e2e/wdio.conf.js @@ -31,8 +31,8 @@ const specs = process.env.ROSI_E2E_SPECS // Process-repair specs batch many native failure cases into one `it`, so they // get a longer ceiling than the rest of the GUI suite. const LONG_PROCESS_SPECS = new Set([ - "./download-process-repairs.spec.js", - "./audit3-native-targeted.spec.js", + "./download-process.spec.js", + "./download-process-targeted.spec.js", ]); const processRepairRun = process.env.ROSI_E2E_PROCESS_REPAIRS === "1" && diff --git a/package-lock.json b/package-lock.json index f2ca2697..2583e958 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,15 @@ { "name": "rosi", - "version": "5.0.2", + "version": "5.1.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rosi", - "version": "5.0.2", + "version": "5.1.0-beta.1", "license": "MPL-2.0", "dependencies": { "@tauri-apps/api": "^2.12.0", - "@tauri-apps/plugin-updater": "2.14.0", "lucide-static": "1.49.0" }, "devDependencies": { @@ -38,8 +37,8 @@ "vitest": "4.1.11" }, "engines": { - "node": "^24.15.0 || >=26.0.0", - "npm": ">=12.0.2" + "node": "^24.22.1 || >=26.13.0", + "npm": ">=12.2.1" } }, "node_modules/@asamuzakjp/css-color": { @@ -2193,15 +2192,6 @@ "@tauri-apps/api": "^2.11.0" } }, - "node_modules/@tauri-apps/plugin-updater": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/@tauri-apps/plugin-updater/-/plugin-updater-2.14.0.tgz", - "integrity": "sha512-gdylJ9tger4hkyOn24QZd6MNOKVo2Eh53iw5th2Qj1vKTR/+u4PIwJWuiis5hohYvobn6iOvlnALfrqIPSzh7Q==", - "license": "MIT OR Apache-2.0", - "dependencies": { - "@tauri-apps/api": "^2.12.0" - } - }, "node_modules/@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", diff --git a/package.json b/package.json index 013a6945..4ad1914a 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "rosi", - "version": "5.0.2", + "version": "5.1.0-beta.1", "license": "MPL-2.0", "private": true, - "packageManager": "npm@12.0.2", + "packageManager": "npm@12.2.1", "description": "Cross-platform yt-dlp GUI built with Tauri.", "type": "module", "keywords": [ @@ -13,8 +13,8 @@ "cross-platform" ], "engines": { - "node": "^24.15.0 || >=26.0.0", - "npm": ">=12.0.2" + "node": "^24.22.1 || >=26.13.0", + "npm": ">=12.2.1" }, "repository": { "type": "git", @@ -37,8 +37,10 @@ "test:rust": "npm run prepare:rust-tests && cargo test --locked --manifest-path src-tauri/Cargo.toml --all-targets", "test:e2e": "node scripts/test-e2e.js", "test:e2e:stability": "node scripts/test-e2e.js --repeat 5", + "test:e2e:updater-zst": "node scripts/e2e-updater-zst.mjs", + "test:e2e:macos-native-packages": "node scripts/e2e-macos-native-packages.mjs", "test:all": "node scripts/test-all.js", - "test:cargo-safe-update": "node --test scripts/cargo-safe-update.test.mjs scripts/check-cargo-update-policy.test.mjs scripts/test-all.test.js scripts/run-release.test.js scripts/github-cli.test.cjs scripts/release-branch-protection.test.cjs scripts/release-licenses.test.mjs scripts/npm-dev-audit.test.cjs scripts/generate-cargo-licenses.test.mjs scripts/check-rustsec-ignore-policy.test.mjs scripts/legacy-v4-feed.test.mjs scripts/security-release-repairs.test.mjs scripts/round2-release-updater.test.mjs scripts/test-e2e-round2.test.mjs scripts/git-reset.test.mjs scripts/fetch-ytdlp-gpg-path.test.mjs scripts/release-preflight.test.mjs scripts/msstore-pack.test.mjs scripts/test-e2e-only.test.mjs scripts/test-e2e-background.test.mjs", + "test:cargo-safe-update": "node --test scripts/cargo-safe-update.test.mjs scripts/check-cargo-update-policy.test.mjs scripts/test-all.test.js scripts/run-release.test.js scripts/github-cli.test.cjs scripts/release-branch-protection.test.cjs scripts/release-licenses.test.mjs scripts/npm-dev-audit.test.cjs scripts/generate-cargo-licenses.test.mjs scripts/check-rustsec-ignore-policy.test.mjs scripts/legacy-v4-feed.test.mjs scripts/security-release-repairs.test.mjs scripts/round2-release-updater.test.mjs scripts/test-e2e-round2.test.mjs scripts/git-reset.test.mjs scripts/fetch-ytdlp-gpg-path.test.mjs scripts/release-preflight.test.mjs scripts/msstore-pack.test.mjs scripts/test-e2e-only.test.mjs scripts/test-e2e-background.test.mjs scripts/deps-majors.test.mjs", "check:cargo-update-policy": "node scripts/check-cargo-update-policy.mjs", "audit:dev-reviewed": "node scripts/npm-dev-audit.cjs", "check:rustsec-ignore-policy": "node scripts/check-rustsec-ignore-policy.mjs", @@ -86,8 +88,8 @@ "b": "git fetch origin && git reset --hard && git clean -fd && git switch -C beta origin/beta && git reset --hard origin/beta && git clean -fd && npm run vi", "r": "git fetch origin && git reset --hard && git clean -fd && git switch -C main origin/main && git reset --hard origin/main && git clean -fd && npm run vi && npm run gitprune:force", "u": "node scripts/npm-safe-update.mjs && node scripts/cargo-safe-update.mjs --manifest-path src-tauri/Cargo.toml && node scripts/sync-version.js && node scripts/update-metainfo.js && npm run check:tauri-alignment", + "deps:majors": "node scripts/deps-majors.mjs", "check:tauri-alignment": "node scripts/check-tauri-alignment.mjs", - "u2": "node scripts/npm-safe-update.mjs && node scripts/cargo-safe-update.mjs --manifest-path src-tauri/Cargo.toml && node scripts/sync-version.js && node scripts/update-metainfo.js && npm run check:tauri-alignment", "win-compiler:x64": "powershell -NoProfile -ExecutionPolicy Bypass -NoExit -File scripts/launch-vs-devshell.ps1 -Arch x64", "win-compiler:arm64": "powershell -NoProfile -ExecutionPolicy Bypass -NoExit -File scripts/launch-vs-devshell.ps1 -Arch arm64", "setup:win:artifact-signing": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/setup-windows-artifact-signing.ps1", @@ -105,10 +107,22 @@ "build:msstore": "npm run sync-version && npm run licenses && npm run prepare:sidecars && npm run build:msstore:win && dotenv -e .env -- node scripts/msstore-pack.js", "build:mac:universal:prepared": "dotenv -e .env -- tauri build --target universal-apple-darwin --bundles dmg,app -- --locked", "build:mac:universal": "npm run sync-version && npm run licenses && npm run prepare:sidecars && npm run build:mac:universal:prepared", - "build:mac:zip": "node scripts/zip-macos.js", + "build:mac:arm64:prepared": "dotenv -e .env -- tauri build --target aarch64-apple-darwin --bundles dmg,app -- --locked", + "build:mac:x64:prepared": "dotenv -e .env -- tauri build --target x86_64-apple-darwin --bundles dmg,app -- --locked", + "build:mac:native:prepared": "npm run build:mac:arm64:prepared && npm run build:mac:x64:prepared", + "build:mac:arm64": "npm run sync-version && npm run licenses && npm run prepare:sidecars && npm run build:mac:arm64:prepared && node scripts/zip-macos.js --target aarch64-apple-darwin", + "build:mac:x64": "npm run sync-version && npm run licenses && npm run prepare:sidecars && npm run build:mac:x64:prepared && node scripts/zip-macos.js --target x86_64-apple-darwin", + "build:mac:native": "npm run sync-version && npm run licenses && npm run prepare:sidecars && npm run build:mac:native:prepared && npm run build:mac:zip:native", + "build:mac:zip": "node scripts/zip-macos.js --target universal-apple-darwin", + "build:mac:zip:arm64": "node scripts/zip-macos.js --target aarch64-apple-darwin", + "build:mac:zip:x64": "node scripts/zip-macos.js --target x86_64-apple-darwin", + "build:mac:zip:native": "npm run build:mac:zip:arm64 && npm run build:mac:zip:x64", + "build:mac:updater-arches:prepared": "npm run build:mac:native:prepared", + "build:mac:updater-zst": "dotenv -e .env -- node scripts/pack-macos-updater-zst.js", + "build:mac:dmg:ulmo": "dotenv -e .env -- node scripts/convert-dmg-ulmo.mjs", "mac:ssh:keychain": "bash scripts/mac-keychain-ssh.sh", - "build:linux:x64:prepared": "dotenv -e .env -- tauri build --target x86_64-unknown-linux-gnu --bundles appimage -- --locked", - "build:linux:arm64:prepared": "dotenv -e .env -- tauri build --target aarch64-unknown-linux-gnu --bundles appimage -- --locked", + "build:linux:x64:prepared": "dotenv -e .env -v LDAI_COMP=zstd -- tauri build --target x86_64-unknown-linux-gnu --bundles appimage -- --locked", + "build:linux:arm64:prepared": "dotenv -e .env -v LDAI_COMP=zstd -- tauri build --target aarch64-unknown-linux-gnu --bundles appimage -- --locked", "build:linux:prepared": "npm run build:linux:x64:prepared", "build:linux:x64": "npm run sync-version && npm run licenses && npm run prepare:sidecars && npm run build:linux:x64:prepared", "build:linux:arm64": "npm run sync-version && npm run licenses && node scripts/prepare-sidecars.js --target aarch64-unknown-linux-gnu && npm run build:linux:arm64:prepared", @@ -116,12 +130,12 @@ "flatpak:bundle": "node scripts/prepare-flatpak-source.js && flatpak-builder --repo=flatpak-repo --force-clean flatpak-build run.rosie.rosi.yml && flatpak build-bundle flatpak-repo dist/ROSI-Linux-x64.flatpak run.rosie.rosi", "flatpak:clean": "node -e \"for (const d of ['flatpak-build','flatpak-repo']) require('fs').rmSync(d,{recursive:true,force:true})\"", "flatpak:run": "flatpak run run.rosie.rosi", - "rust:update": "rustup toolchain install 1.98.1 --profile minimal --component cargo,clippy,rustfmt", - "rust:targets:win": "rustup target add --toolchain 1.98.1 x86_64-pc-windows-msvc aarch64-pc-windows-msvc", - "rust:targets:mac": "rustup target add --toolchain 1.98.1 x86_64-apple-darwin aarch64-apple-darwin", - "rust:targets:linux": "rustup target add --toolchain 1.98.1 x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu", - "rust:target:linux:x64": "rustup target add --toolchain 1.98.1 x86_64-unknown-linux-gnu", - "rust:target:linux:arm64": "rustup target add --toolchain 1.98.1 aarch64-unknown-linux-gnu", + "rust:update": "node scripts/rust-toolchain.mjs --install", + "rust:targets:win": "node scripts/rust-toolchain.mjs --target x86_64-pc-windows-msvc aarch64-pc-windows-msvc", + "rust:targets:mac": "node scripts/rust-toolchain.mjs --target x86_64-apple-darwin aarch64-apple-darwin", + "rust:targets:linux": "node scripts/rust-toolchain.mjs --target x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu", + "rust:target:linux:x64": "node scripts/rust-toolchain.mjs --target x86_64-unknown-linux-gnu", + "rust:target:linux:arm64": "node scripts/rust-toolchain.mjs --target aarch64-unknown-linux-gnu", "workspace:bootstrap": "npm run rust:update && npm ci --ignore-scripts && npm run sync-version && npm run ytdlp:fetch && npm run ytdlp:check && npm run ffmpeg:ensure && npm run prepare:sidecars", "workspace:prepare": "npm run workspace:bootstrap && npm run test:all -- --require-clean-proof", "release:prepare": "npm run workspace:bootstrap && npm run test:all -- --require-clean-proof --skip-e2e && npm run dist:clean-release-artifacts", @@ -138,7 +152,7 @@ "release:win:continue": "npm run release:session:verify && npm run release:licenses && npm run release:draft && npm run release:legacy-v4-feed && npm run rust:targets:win && npm run build:win:prepared && npm run prepare:sidecars && npm run release:sign:gpg && npm run release:finalize", "release:win:resume": "npm run prerelease:prepare && npm run release:win:continue", "release:win": "node scripts/run-release.js win", - "release:mac:continue": "npm run release:session:verify && npm run release:licenses && npm run release:wait-draft && npm run rust:targets:mac && npm run build:mac:universal:prepared && npm run build:mac:zip && npm run release:sign:gpg && npm run release:finalize", + "release:mac:continue": "npm run release:session:verify && npm run release:licenses && npm run release:wait-draft && npm run rust:targets:mac && npm run build:mac:universal:prepared && npm run build:mac:zip && npm run build:mac:updater-arches:prepared && npm run build:mac:zip:native && npm run build:mac:dmg:ulmo && npm run build:mac:updater-zst && npm run test:e2e:macos-native-packages -- --require-real-builds && node scripts/e2e-updater-zst.mjs --require-real-builds && npm run release:sign:gpg && npm run release:finalize", "release:mac:resume": "npm run prerelease:prepare && npm run release:mac:continue", "release:mac": "node scripts/run-release.js mac", "release:mac:ssh": "npm run mac:ssh:keychain && node scripts/run-release.js mac", @@ -146,7 +160,7 @@ "release:linux:continue": "npm run release:linux:x64:continue", "release:linux": "node scripts/run-release.js linux", "release:linux:resume": "npm run prerelease:prepare && npm run release:linux:continue", - "release:linux:x64:continue": "npm run release:session:verify && npm run release:licenses && npm run release:wait-draft && npm run rust:target:linux:x64 && npm run build:linux:x64:prepared && node scripts/check-linux-glibc.js --target x86_64-unknown-linux-gnu && npm run flatpak:clean && npm run flatpak:bundle && npm run release:sign:gpg && npm run release:finalize", + "release:linux:x64:continue": "npm run release:session:verify && npm run release:licenses && npm run release:wait-draft && npm run rust:target:linux:x64 && npm run build:linux:x64:prepared && node scripts/check-linux-glibc.js --target x86_64-unknown-linux-gnu && node scripts/check-appimage-compression.js --target x86_64-unknown-linux-gnu && npm run flatpak:clean && npm run flatpak:bundle && npm run release:sign:gpg && npm run release:finalize", "release:linux:x64:resume": "npm run prerelease:prepare && npm run release:linux:x64:continue", "release:linux:x64": "node scripts/run-release.js linux:x64", "release:linux:arm64:continue": "npm run release:session:verify && npm run release:licenses && npm run release:wait-draft && npm run rust:target:linux:arm64 && node scripts/prepare-sidecars.js --target aarch64-unknown-linux-gnu && npm run build:linux:arm64:prepared && node scripts/check-linux-glibc.js --target aarch64-unknown-linux-gnu && npm run release:sign:gpg && npm run release:finalize", @@ -163,7 +177,6 @@ }, "dependencies": { "@tauri-apps/api": "^2.12.0", - "@tauri-apps/plugin-updater": "2.14.0", "lucide-static": "1.49.0" }, "devDependencies": { diff --git a/plan.md b/plan.md new file mode 100644 index 00000000..fc5ecf53 --- /dev/null +++ b/plan.md @@ -0,0 +1,816 @@ +# ROSI 5.1.0 audit and implementation plan + +Audit date: 2026-11-06. Branch `next-5.1.0`, commit `6f244bd`, version `5.1.0-beta.1`. + +**To the agent implementing this plan:** work the sections in the order given +in section 8 (A4, the full-gate evidence step, deliberately comes after A5 to +A7 and D0). Each workstream lists its failure-mode document, which must be +written before its code (AGENTS.md). Do not add unit tests after writing code; +prove each change with E2E scenarios that leave a report under `e2e/artifacts/`. +**Delete this file (`plan.md`) in the final commit of the implementation.** Do +not leave it in the repository once the work it describes has landed. + +--- + +## 1. What the audit covered + +Read in full or in large part: `ARCHITECTURE.md`, `CHANGELOG.md`, +`docs/ROADMAP-5.1.md`, `docs/IMPLEMENTATION-5.1.md`, `build-setup.md`, +`e2e/README.md`, `e2e/suites.json`, every `failure-modes.md` added for 5.1, +`src-tauri/src/{main,build,coordinator,queue,downloader,download_options, +sidecars,ipc,types,network_security,network_security_async,ffmpeg_guard, +media_info,platform}.rs`, `src-tauri/vendor/tauri-plugin-updater/PATCHES.md`, +`src/rosiEngine.ts`, `src/updater.ts`, `src/tauri-bridge.ts`, `src/commands.ts`, +`src/engine/*.ts` (core, formats, presets, playlist, url-actions, progress, +messages, settings-store, bind/backend-events, bind/settings-controls diff, +wizard diff, deno diff), `src/modules/downloads.ts`, `src/modules/activity.ts`, +`scripts/prepare-sidecars.js`, `scripts/zip-macos.js`, `scripts/pack-macos-updater-zst.js`, +`scripts/gpg-sign.js` (outline), `scripts/test-e2e.js` (outline), +`scripts/test-all.js`, `.github/workflows/ci.yml`, `run.rosie.rosi.yml`, +`src-tauri/tauri.conf.json`, `src-tauri/Cargo.toml`, `package.json`, and the +full `git diff --stat 352acee..HEAD` (5.0.2 to HEAD: 124 files, +13,755/-2,858). + +Checks run on this Mac (arm64, macOS 27.2): + +| Check | Result | +| --- | --- | +| `npm run typecheck` | pass | +| `npm run lint` (eslint + comment lint, 777 files) | pass | +| `npm run format:check` | pass | +| `vitest run` | 6 files, 76 tests pass | +| `cargo clippy --locked --all-targets -- -D warnings` | pass | +| `cargo test --locked --all-targets` | 32 + 1 pass (includes `ts_bindings`, so `src/generated/ipc-types.ts` is current) | +| `npm run test:e2e` (full gate, run twice) | **fails** both times at `6f244bd`; details in 2.1 | +| `npm run test:e2e -- --group ...` and `ROSI_E2E_ONLY=...` for the passes the gate never reached | see 2.1, item 1c | + +--- + +## 2. Findings + +Severity: **B** = blocks a 5.1.0 stable, **H** = fix in 5.1.0, **M** = fix in +5.1.x, **L** = cleanup. + +### 2.1 Evidence and release hygiene + +1. **(B) The full E2E gate fails on the 5.1 tree, and no platform has a + passing report.** Before the audit, the newest local report was from + 2026-10-22 (5.0.1, `onlySpec`). `gh run list --branch next-5.1.0` returns + nothing (CI runs only for `main`/`beta` pushes and PRs to them; no PR + exists), and the last three `beta` runs (2026-10-18/19) were failure, + cancelled, failure. `docs/IMPLEMENTATION-5.1.md` records a Windows + inventory that executed nothing. The audit ran `npm run test:e2e` twice on + this Mac (macOS arm64, commit `6f244bd`, E2E binary + `bdab121c3f62…`). Both runs failed. Three distinct causes: + + **1a. (B, deterministic) `e2e/state-updater-repairs.spec.js:1089` fails:** + `expected 'darwin-beta-e2e-app', actual 'darwin-beta-aarch64-app-zst'`. + The 5.1 updater (`src/updater.ts` `updateCheckTarget`) now calls + `get_compact_updater_target` before `get_beta_updater_target`. The spec's + `__ROSI_E2E__.updaterAdapter.invoke` stubs `get_beta_updater_target` but + lets every other command fall through to the real `invoke` + (`state-updater-repairs.spec.js:989-1008`). `platform::get_compact_updater_target` + returns `Some` whenever Tauri reports bundle type `App`, and + `tauri_utils::platform::bundle_type()` returns `App` for **any** macOS + binary, including the unbundled E2E build (tauri-utils 2.10.1 + `platform.rs:370-371`). So the scenario written for 5.0 asserts the old + target. The updater change in `a07a5a8` (2026-10-28) was never run through + the gate. Fix in A5. + + **1b. (B, structural) One failing pass hides every later pass.** + `scripts/test-e2e.js:1999-2070` runs the WebdriverIO passes in one `try`; + `runPass` throws on failure, so after 1a the security pass, the + `round2-renderer` pass, every `v5-fixes` area without a runner + (`download-options`, `flatpak-updates`, `platform`, `queue-coordinator`, + `typed-formats`, `ui-polish`, `upstream-proxy`) and `specs/main.spec.js` + (82 of the 115 expected scenarios) never ran. The report lists them as + "did not run" / "reported 0 times", which reads like a mass failure. The + runner-owned suites (process repairs, round2 native, long-term, audit + probes, async-proxy, deno, downloader, network, persistence) did run and + passed in run 2. Fix in E2 (continue after a failed pass; report each pass + on its own). + + **1c. (B, flaky on macOS, 2 of 3 runs) the shared overload probe resets.** + `v5-fixes/async-proxy` and `v5-fixes/network` runners failed in run 1 and + passed in run 2; in the group run, `specs/security-release-repairs.spec.js` + failed its `bracketed-ipv6-classification` and + `proxy-rejects-unreviewed-pipelined-destination` scenarios through the + same `e2e_network_pipelining_probe`, with + `could not read overload response: Connection reset by peer (os error 54)`. + `network_security_async.rs:636-649` `reject_client` writes the 503, + calls `shutdown()` and drops the socket while the client's CONNECT request + is still unread in the receive buffer. macOS (BSD stack) then sends RST, + and the probe's `read_to_end` after the status line fails. Linux keeps the + sent bytes readable, which is why the Ubuntu CI job would not show it. Fix + in A6: after `shutdown()`, read and discard client bytes until EOF or a + short deadline before dropping the stream; the probe keeps its strict + `read_to_end`. + + **1d. Results for the passes the gate never reached**, obtained with + `ROSI_E2E_ONLY=` one spec at a time (reports are not release proof; + they only show whether the code behind each pass works): + + | Pass | Result alone (macOS arm64, `6f244bd`) | + | --- | --- | + | `v5-fixes/queue-coordinator` | passed, 8 scenarios | + | `v5-fixes/download-options` | passed, 2 | + | `v5-fixes/platform` | passed, 3 | + | `v5-fixes/typed-formats` | passed, 3 | + | `v5-fixes/upstream-proxy` | passed, 9 | + | `round2-renderer-repairs.spec.js` | **fails** at `:269`, same class as 1a: expects `darwin-beta-round2-app`, gets `darwin-beta-aarch64-app-zst` | + | `v5-fixes/flatpak-updates` | **fails** 2 of 4, same class as 1a: the Flatpak adapter stubs `is_flatpak: true` but not `get_compact_updater_target`, so `checkTargets` is `darwin-aarch64-app-zst` instead of the beta/stable target | + | `specs/main.spec.js` | **background mode (the local macOS default): fails** `settings-reset-all` ("confirming did not reset", `main.spec.js:3692`) and loses the WebDriver session in `close-flow`; **foreground (`ROSI_E2E_FOREGROUND=1`): passes**, 63 of 64 with the allowed `xdg-download-dir` skip | + | `v5-fixes/ui-polish` | **fails in both modes**: background 4 of 8, foreground 5 of 8. Foreground failures: "effective options were not resolved for a valid URL" (`ui-polish.spec.js:333`, summary never reaches `data-state="resolved"`; the fresh profile has no download folder, so readiness stays at `destination`); modal focus not inside the section-reset prompt (`:423`); "reset button is not keyboard focusable" (`:478`); `execute/async` script timeout while adding a second queue item (`:586`); `settingsSearch` not focused after the theme and text-scale matrix (`:789`). Background mode also fails the focus-trap Tab check (`:485`) and "queue refresh stole focused action" (`:644`) | + + So, counting only passes the gate can reach today: the 5.1 backend work + (coordinator, option resolution, typed formats, upstream proxy, platform) + passes; the three updater-related specs are stale against the 5.1 target + selection; the UI polish acceptance spec does not pass against the UI it + was written for; and the macOS background-window mode is not a reliable + way to run `main.spec.js`. Fixes: A5 (updater stubs, all three specs), A6 + (RST), A7 (background mode), D0 (ui-polish triage). + + The implementing agent must re-run the full gate after A5 to A7 and D0 and + keep the passing report. +2. **(H) Tracked junk files.** `Microsoft/Windows/PowerShell/ModuleAnalysisCache` + and `e2e/Microsoft/Windows/PowerShell/ModuleAnalysisCache` (binary + PowerShell caches from a Windows VM) were committed in `6f244bd`. Remove + them and add `Microsoft/` and `**/Microsoft/Windows/PowerShell/` to + `.gitignore`. +3. **(H) CHANGELOG is incomplete for 5.1.0-beta.1.** It lists only the updater + and packaging items. It omits: the queue/session coordinator, the async + proxy relay (256 tunnels, bounded admission), typed format listing, shared + download-option resolution (`resolve_download_options`), the effective + options summary, settings-save feedback and retry, wizard error states, the + Node.js 26 toolchain move, Rust 1.99.1 pin, and `e2e/suites.json` groups. + `validate:changelog` only checks the version header, so this passes CI. +4. **(H) Docs are stale against the code.** `docs/ROADMAP-5.1.md` item 4 says + "implementation not started" and item 5 says the blocking worker pool + remains; both are implemented (`src-tauri/src/coordinator.rs`, + `network_security_async.rs`). `ARCHITECTURE.md`'s module table lacks + `coordinator.rs`, `download_options.rs`, `network_security_async.rs`. + `docs/IMPLEMENTATION-5.1.md` carries a "Worker choice recorded: GPT-6 Luna + max" line that has no place in a project document. +5. **(M) `resources/ffmpeg/README.md` says "use static builds"** but the Linux + x64 binary is `ELF ... dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2` + (`file` output). `scripts/check-linux-glibc.js` already exists because of + this. Correct the README so the next FFmpeg bump does not "fix" it. +6. **(L) `package.json` scripts `u` and `u2` are identical.** Remove `u2`. + +### 2.2 Roadmap items accepted for 5.1: status versus acceptance criteria + +| Item | Done | Not done (evidence) | +| --- | --- | --- | +| 1 Renderer split | `src/rosiEngine.ts` is 454 lines; feature modules under `src/engine/` and `src/engine/bind/` | `initializeRenderer` still exists (`src/rosiEngine.ts:70`); `window.rosiModules` has 46 references; the IIFE modules in `src/modules/` still attach to `window` | +| 2 Typed commands | `src/commands.ts` + `src/generated/ipc-types.ts` + contract test | `window.api` has 104 references outside tests; `src/rosiEngine.ts:95-134` still holds a hand-written default `Settings` literal although `get_default_settings` exists | +| 3 Typed IPC structs | settings enums; `FalliblePayload` for `download_video`, `add_to_queue`, `resolve_download_options` | 10 commands still take `serde_json::Value`: `get_formats`, `get_video_info` (`media_info.rs:462,484`), `open_external`, `open_file_location`, `show_notification` (`platform.rs:182,204,242`), `save_settings` (`settings.rs:620`), `log_error` (`logging.rs:145`), `remove_from_queue`, `retry_queue_item`, `reorder_queue_item` (`queue.rs:1215-1231`) | +| 4 Coordinator | `coordinator.rs` (one command thread, reply channels, revisioned `queue-update`); the condition variables are gone | `queue.rs:40` still has the global `QUEUE: OnceLock>`; `downloader.rs:79-85` still has `ACTIVE`, `STARTUP`, `EVENT_PUBLISH` mutexes. Acceptance said "no global Mutex or Condvar" | +| 5 Async proxy | Tokio relay, 256 active / 128 pending, 503 on overload, E2E probe | Polling remains: `network_security_async.rs:37,174-185` (`EXTERNAL_CANCELLATION_POLL` 25 ms per client task), `:686-702` (DNS reply polled with `try_recv` + 25 ms sleep); the DNS pool is still blocking threads with a condvar (`network_security.rs:56,398-440`). Acceptance said "no polling sleep" and "no measurable idle CPU" | +| 6 E2E regroup | `e2e/suites.json`, `--group` selection, `scenarioGroups` in reports | 23 files in `e2e/` still named `round*`/`audit*`/`*repair*`; `scripts/test-e2e.js` is 2,430 lines (target < 800) | + +The coordinator and relay are sound as read (see 2.4), so items 4 and 5 are +"delivered with residue", not failures. The residue is scheduled in section 4. + +### 2.3 FFmpeg size: measurements that shape the "gzip before packaging" ask + +Sizes measured on this machine from `resources/ffmpeg/` (FFmpeg 9.0.2 builds, +all already stripped per `file`): + +| Binary | Raw | gzip -6 | zstd -19 | +| --- | ---: | ---: | ---: | +| mac arm64 ffmpeg | 50.2 MB | 22.4 MB | 17.1 MB | +| linux x64 ffmpeg | 144.9 MB | 56.0 MB | 44.8 MB | +| win x64 ffmpeg.exe | 143.9 MB | 55.0 MB | 43.8 MB | +| mac arm64 ffmpeg+ffprobe tar | 100.3 MB | 44.7 MB (gzip) | **19.6 MB** (zstd --long=27) | +| win x64 ffmpeg+ffprobe tar | 287.6 MB | 110.0 MB (gzip) | 85.4 MB (zstd --long=27) | + +Published 5.0.2 assets (`gh release view v5.0.2`): + +| Asset | Size | Raw payload it contains (approx.) | +| --- | ---: | ---: | +| ROSI-Windows-x64.exe (NSIS, solid LZMA) | 63.7 MB | ~320 MB | +| ROSI-Windows-arm64.exe | 54.6 MB | ~190 MB | +| ROSI-MacOS-universal.dmg | 146.9 MB | ~300 MB | +| ROSI-MacOS-universal.zip | 145.7 MB | ~300 MB | +| ROSI.app.tar.gz (universal updater) | 149.4 MB | ~300 MB | +| ROSI-Linux-x64.AppImage (squashfs) | 175.9 MB | ~345 MB | +| ROSI-Linux-x64.flatpak | 99.3 MB | ~345 MB | + +Conclusions the implementer must not skip: + +- Every shipped container already compresses. The Windows installer's solid + LZMA gets the whole payload to 63.7 MB, which is smaller than the two + pre-gzipped FFmpeg files alone (110 MB). **Pre-gzipping FFmpeg makes the + Windows installer larger**, because gzip output is incompressible to LZMA + and solid compression can no longer share data between ffmpeg and ffprobe. +- The macOS compact updater (`.app.tar.zst --long=27`) already dedupes + ffmpeg against ffprobe (19.6 MB for the pair). Pre-gzipped members would + cost about +25 MB per per-arch update, reversing the 5.1 updater gain. +- DMG (UDZO zlib), ZIP (deflate) and AppImage (squashfs gzip) are roughly + neutral: they compress about as well as gzip, so a pre-gzipped payload + neither shrinks nor grows them much. +- On disk after install, the extracted binaries are still needed to run, so + "gzip in the bundle plus extracted copy in app data" is a larger installed + footprint, not a smaller one. On macOS the bundle's copy cannot be deleted + after extraction without breaking the code signature. + +What does reduce download size, measured or known: + +| Lever | Expected effect | Cost | +| --- | --- | --- | +| Drop `rosi-ffprobe` and probe with `ffmpeg -i` | halves raw FFmpeg payload: DMG/ZIP/AppImage about -40%; Windows about -5% (LZMA already dedupes) | yt-dlp calls ffprobe directly for some post-processors; `ffmpeg_guard.rs` already intercepts those calls, so a launcher that maps `ffprobe` onto `ffmpeg -i` is feasible but needs careful output parsing; largest risk item | +| AppImage with zstd squashfs (`APPIMAGE_COMP=zstd` / appimagetool `--comp zstd`) | AppImage about 176 MB to ~120 MB | verify Tauri's appimage script honours the env var; runtime must support zstd (type 2 runtime does since 2020) | +| DMG converted to `ULMO` (LZMA) after Tauri builds it | DMG about 147 MB to ~90 MB | re-sign and re-verify the DMG; `zip-macos.js` and `e2e-macos-native-packages.mjs` already own DMG verification | +| Native (per-arch) macOS DMG/ZIP, already shipped in 5.1 | about -40% for arm64/x64 downloads versus universal | done | + +**Decision required before workstream C (section 4) starts.** The ask was +"gzip the FFmpeg binaries before packaging". The numbers above say that as +stated it increases the Windows installer and the macOS compact update and +reduces nothing else measurably. The plan therefore (a) keeps the requested +implementation fully specified in workstream C so it can be built if the goal +is something the numbers do not capture (for example, a size limit on an +intermediate artifact store or the Microsoft Store MSIX), and (b) puts a +mandatory measure-and-decide gate (C0) in front of it that produces a +before/after table per artifact from real builds. If C0 confirms the numbers +above, implement the "what reduces size" levers instead and record the +decision in `docs/IMPLEMENTATION-5.1.md`. + +### 2.4 Code review notes on the new 5.1 code + +Reviewed for races and lock discipline; no defect found that needs a code +change before beta.2, but record these so they are not re-derived: + +- `coordinator.rs`: `evaluate_start` spawns `run_queue` while the queue guard + is held. Safe: the runner's first action is a `ClaimNext` request, which the + coordinator only handles after the current command returns and the guard + drops. `register` is a non-blocking send made under the downloader lock, so + a `Terminal` for the same session is always ordered after it. +- Cancel while the runner is between `ClaimNext` and `start_download`: + `CancelBegin` sees `active_item_id`, `cancel_session` finds no session and + returns via `await_finalized(None)`, the runner's `Attempt` answers false and + `ItemUnstarted` records exactly one cancelled outcome. If the session became + visible first, `SessionStarted` returns `Some(true)` and the runner cancels + it. Matches failure-mode rows 1 and 9 in + `e2e/v5-fixes/queue-coordinator/failure-modes.md`. +- `queue::stop()` (used on close/restart) cancels whatever session is active, + including a manual one. That is the documented intent of `kill_all_processes`. +- `network_security_async.rs`: `ProxyShared::cancelled()` wakes every 25 ms + per client because the downloader's cancellation is an `AtomicBool` + (`downloader.rs` `network_cancellation`). With 256 tunnels that is about + 10,000 wakeups per second at idle. Not a correctness bug; it is the item 5 + residue (workstream B8). +- `download_options.rs` is the single precedence rule (settings < preset < + explicit); the renderer still builds its own override map in + `src/engine/presets.ts` `buildOnScreenPresetOverrides`. Two sources of + truth; workstream B2 removes the renderer copy. +- `downloader.rs` is 3,207 lines (session start, yt-dlp exit handling, + caption sidecars, conversion, publication). Not a 5.1.0 blocker; split is + workstream B10. + +--- + +## 3. Workstream A: hygiene and evidence (do first) + +A1. Remove the two `ModuleAnalysisCache` files; add ignore rules; confirm +`git ls-files | grep -i ModuleAnalysisCache` is empty. + +A2. Rewrite the `5.1.0-beta.1` section of `CHANGELOG.md` to cover every +user-visible change in `git diff 352acee..HEAD` (list in finding 3). Keep the +existing updater and packaging bullets. One bullet per feature, in the +established `**Area:** text` style. No em dashes (`validate:no-em-dash`). + +A3. Update `docs/ROADMAP-5.1.md` statuses for items 4, 5, 6 to "implemented +with residue, see IMPLEMENTATION-5.1.md" and list the residue exactly as in +section 2.2. Add `coordinator.rs`, `download_options.rs`, +`network_security_async.rs` to the `ARCHITECTURE.md` module table. Remove the +"Worker choice" line from `docs/IMPLEMENTATION-5.1.md`. Fix the FFmpeg README +"static" claim. Delete the `u2` script. + +A5. Fix the stale updater scenarios (findings 1a and 1d). In +`e2e/state-updater-repairs.spec.js`, `e2e/round2-renderer-repairs.spec.js` +and `e2e/v5-fixes/flatpak-updates/flatpak-update-notice.spec.js` make each +adapter's `invoke` return `null` for `get_compact_updater_target` so the +existing scenarios keep proving what they were written for (beta-target +generation fencing, single-flight downloads, Flatpak feed-only mode). Add one +scenario for the 5.1 compact path: the adapter returns +`darwin-beta-aarch64-app-zst` from `get_compact_updater_target`, `check()` +throws once for the compact target, and the renderer falls back to +`darwin-beta-aarch64-app` (`legacyTarget` in `src/updater.ts`) and emits +`available`; assert both feed records in `auditFeedRecords`. Keep this +scenario when B1 moves the updater to Rust (it becomes the Rust fallback +proof). Also give `scenarioNames` in `e2e/suites.json` the new name. + +A6. Fix the macOS RST in the proxy overload path (finding 1c). +`reject_client` in `src-tauri/src/network_security_async.rs`: after +`write_all` and `shutdown()`, drain the client with a bounded read loop (for +example up to 64 KiB or 250 ms, whichever first) so the kernel does not reset +the connection with unread input, then drop. Run +`e2e/v5-fixes/async-proxy/run.mjs` ten times on macOS +(`for i in $(seq 10); do node e2e/v5-fixes/async-proxy/run.mjs || break; done` +after a gate build) and record the ten reports under the ledger. The same +drain applies to the "Proxy Admission Timeout" 503 in `run_proxy`. + +A7. Decide the macOS window mode for release evidence (finding 1d, +`main.spec.js`). `e2e/README.md` makes background mode +(`ROSI_E2E_BACKGROUND=1`, accessory activation policy, window below other +apps) the local macOS default, but in that mode the Reset-All modal click is +not registered within the scenario's 300 ms settle and the close-flow +scenario loses the WebDriver session, while the same spec passes in +foreground. Either make background mode reliable (the modal confirm click in +`clickModalButton` and the close-flow wait at `main.spec.js:4382` are the two +places to instrument; an accessory-policy app may need an explicit +`activate` before synthetic clicks) or require `ROSI_E2E_FOREGROUND=1` for +release evidence on macOS and say so in `e2e/README.md` and +`docs/RELEASE-STABLE.md`. Do not leave the default in a state where the +documented local command fails on a clean tree. + +A4. Produce real full-gate evidence for the current commit (after A5, A6, +A7, D0): + +```sh +npm run test:all -- --require-clean-proof # macOS, this machine +``` + +then the same on Windows x64 and Linux x64 release machines (Windows arm64 at +least `npm run test:e2e`). Open a PR from `next-5.1.0` to `beta` so CI runs the +six-job matrix; attach the `e2e-*` artifacts to the 5.1 ledger +(`docs/IMPLEMENTATION-5.1.md`, "Required support and proof matrix"). The +memory note for this repo says the macOS `download-process-repairs` scenario +flakes on execute/async timeouts: re-run once before debugging a failure +there. + +Acceptance: a passing `fullSuite: true` report per required platform whose +`commit` equals HEAD, referenced from the ledger. Until then the beta stays +unpromotable by the stable runbook. + +--- + +## 4. Workstream B: start of the Rust migration (non-UI code out of TypeScript) + +Principle: the renderer keeps DOM, focus, and presentation. Policy, state +machines, parsing and validation move to Rust behind typed commands and +events. Each sub-item is one change with its own failure-mode note and E2E +scenario. Order is by value over risk. + +### B1. Updater orchestration to Rust (biggest non-UI module: `src/updater.ts`, 572 lines) + +Today `src/updater.ts` owns channel/target selection, the compact-feed +fallback, generation counters for check/download/install, cancellation +semantics ("the plugin cannot abort an in-flight download"), and the Flatpak +manual-install rule, all on top of `@tauri-apps/plugin-updater`'s JS API. The +vendored Rust plugin already exposes everything needed +(`UpdaterBuilder::target`, `timeout`, `on_before_exit`, `Update::download` +with a progress closure, `install`, `download_and_install`; see +`src-tauri/vendor/tauri-plugin-updater/src/{lib,updater}.rs`). + +Plan: + +1. Failure modes first: `e2e/v5-fixes/updater-engine/failure-modes.md`. Port + every guard that `src/updater.ts` encodes today: stale check result after a + channel change, download completing after cancel, install of a candidate + that is not the downloaded one, channel save failing before revalidation, + compact target failing over to the universal feed, retired Linux deb/rpm + targets, Flatpak feed-only mode, dev-mode refusal, `restart_app` refusal + keeping the identity for retry. +2. New module `src-tauri/src/updater.rs` with one state-owning thread (same + pattern as `coordinator.rs`): commands `check_for_updates`, + `download_update { candidate_id }`, `install_update { candidate_id }`, + `cancel_update_download`, `set_update_channel { channel }`; events + `updater-status` and `updater-progress` with the same payload shapes as + `UpdaterStatusEvent` / `UpdaterProgressEvent` (add them to `types.rs` so + `ts_bindings` generates them). Target selection reuses + `platform::get_beta_updater_target` and `get_compact_updater_target`. +3. The e2e feature: add `e2e_configure_updater { endpoint, pubkey }` so the + E2E media server can serve `latest-*.json` manifests signed with a test + minisign key (vendored builder has `endpoints()` and `pubkey()`). This + replaces the jsdom-only `round3-renderer-repairs/updater.cjs` checks with + real app scenarios. +4. Renderer: `src/engine/updater-ui.ts` subscribes to the two events and calls + the commands through `commands.ts`. Delete `src/updater.ts`, the + `__ROSI_E2E__.updaterAdapter` seam, the `@tauri-apps/plugin-updater` + dependency in `package.json`, and `updater:allow-check/download/install` + from `src-tauri/capabilities/default.json`. `src/modules/updates.ts` + `isPrereleaseVersion` becomes a `version` field in `updater-status`. +5. E2E: `e2e/v5-fixes/updater-engine/updater-engine.spec.js` covering the + failure-mode rows; keep `state-updater-repairs.spec.js` passing unchanged. + Then `npm run test:e2e:updater-zst` on macOS. + +Acceptance: no `@tauri-apps/plugin-updater` import in `src/`; every +`UpdaterStatusEvent` variant is produced by a Rust path and observed by an E2E +scenario; the capability file no longer grants the updater plugin to the +webview. + +### B2. One source of truth for download-option precedence + +`download_options::resolve_value` is authoritative. Remove the renderer's +copy: `buildOnScreenPresetOverrides` and the field-by-field +`applyPresetToSettings` in `src/engine/presets.ts`. The renderer sends +`{ url, outputPath, presetId, formats, playlist, ...explicit on-screen +changes }` and renders what `resolve_download_options` returns, including +for the effective-options summary (`src/engine/messages.ts`) and the manual +Download button. Extend `e2e/v5-fixes/download-options/` with a scenario that +changes a preset's stored value after it was selected and checks that the +summary and the started download agree with Rust, not with the cached +renderer settings. + +### B3. Default settings from Rust only + +Replace the hand-written `Settings` literal in `src/rosiEngine.ts:95-134` with +`get_default_settings` (fall back to a minimal `{ settingsVersion, theme: +'system' }` only if that call also fails, and surface the error). Add an E2E +scenario that corrupts `settings.json` and checks the defaults the app +renders match the Rust defaults (compare the sidebar values to +`get_default_settings`). This closes the roadmap item 2 criterion "no +hand-written copy of `Settings`". + +### B4. Typed IPC for the remaining `serde_json::Value` commands (roadmap item 3) + +Convert the ten commands in section 2.2 to `FalliblePayload` with typed +request structs (`QueueItemId`, `QueueReorder`, `NotificationRequest` already +exists in `types.rs`, `Url`, `FilePath`, `LogMessage`, `Settings` partial). +Keep the validators (`validation.rs`) running on the typed values so every +security rejection still fires; keep each error message string identical so +existing E2E expectations hold. Add the new structs to `ts_bindings` and +tighten `src/commands.ts`. E2E: the settings-rejection and security suites +already assert the error envelopes; run them (`--group settings,network-policy`) +then the full gate. + +Acceptance: `grep -n "Value" src-tauri/src/*.rs | grep "tauri::command" -A2` +shows no command parameter typed as `Value`; `validation.rs` loses the +shape checks the types now enforce and keeps the policy checks. + +### B5. Format labels in Rust + +Add `display_label: String` to `FormatEntry` (built in `media_info.rs` from +the same rules as `formatFormatEntry`) and delete +`src/modules/downloads.ts` `formatFormatEntry`. `formatBytes` stays in the +renderer (it is presentation). Extend `typed-formats.spec.js` to assert the +option text equals `displayLabel`. + +### B6. Renderer seams (roadmap items 1 and 2 residue) + +Not a 5.1.0 blocker. After B1 to B5, count the remaining `window.api` and +`window.rosiModules` references and schedule their removal per feature in +5.1.x: convert `src/modules/*.ts` IIFEs to ES modules with explicit +dependency objects, then delete `src/renderer-globals.d.ts` entries as they +become unused. `tauri-bridge.ts` stays until the E2E specs that drive +`window.api` are migrated with it, as the roadmap already states. + +### B7. Finish the coordinator ownership model (roadmap item 4 residue) + +Target: `queue::state()` becomes private to the coordinator thread (no +`OnceLock>` read outside `coordinator.rs`; `get_queue` +answers through a `Snapshot` request), and the downloader's session slot +(`ACTIVE`, `STARTUP`, `EVENT_PUBLISH`) is replaced by a `Session` owned by a +session thread that the coordinator starts and addresses by id. Write the +failure-mode rows for every transition in `downloader::cancel_session`, +`complete_session`, `start_download`, and `on_ytdlp_exit` before touching +them. This is the riskiest change in the plan; do it after B1 to B5 and only +with the full gate green on all platforms. If it does not fit 5.1.0, record it +as 5.1.x in the roadmap with the exact remaining globals listed. + +### B8. Remove the relay's polling (roadmap item 5 residue) + +- Replace `network_cancellation: Arc` with a + `tokio::sync::watch::Sender` (or a `Notify`) created in + `start_download` and set in `cancel_session`; `ProxyShared::cancelled()` + then awaits the change instead of sleeping 25 ms. +- Replace the DNS reply polling in `network_security_async::resolve_destination` + with a `tokio::sync::oneshot` reply from the resolver worker, or move system + DNS to `tokio::task::spawn_blocking(lookup_host)` bounded by a semaphore of + `DNS_RESOLVER_WORKERS`; keep cancellation and the answer-count cap. +- Keep `ip_policy.rs` as the only destination check. + +Acceptance (from the roadmap): no `time::sleep`-based polling in the relay; +an idle guard with one open tunnel shows no measurable CPU over 60 s (record +with the existing `e2e_network_pipelining_probe`: add `idleWakeups` counted +from a debug counter behind `cfg(feature = "e2e")`); the 256-tunnel, +503-overload, cancel and drop scenarios in `e2e/v5-fixes/async-proxy/` pass +unchanged. + +### B9. Queue URL extraction in Rust (optional) + +`extractHttpUrls` / `normalizeHttpUrl` in `src/engine/core.ts` duplicate +`normalize_queue_url` in Rust. Add `extract_queue_urls { text }` returning +`{ urls, rejected }` and use it for the batch-paste path; keep the per-keystroke +`isValidUrl` in the renderer for instant feedback. Low value; do last or defer. + +### B10. Split `downloader.rs` (no behaviour change) + +Move conversion (`execute_ffmpeg`, `convert_one`, `run_conversion`, +`complete_conversion_batch`) to `conversion.rs` and publication +(`install_download_output*`, caption sidecars, `publish_*`, `retire_staged_source`) +to `publication.rs`. Pure move; the full gate is the proof. Do after B7 or +skip for 5.1.0. + +--- + +## 5. Workstream C: FFmpeg compressed sidecars ("workers gzip before packaging") + +Interpretation used here: "workers" are the release build machines +(`release:win`, `release:mac`, `release:linux` in `package.json`), which run +`prepare-sidecars` before `tauri build`. If "workers" meant something else +(for example a CDN worker), stop and ask before C1. + +### C0. Measure-and-decide gate (mandatory, one day) + +1. On each release machine, build the current artifacts and record sizes: + `build:win:x64`, `build:win:arm64`, `build:mac:native` + `build:mac:updater-zst`, + `build:linux:x64`, `flatpak:bundle`. +2. Build the same with the sidecar archive from C1 (behind + `ROSI_COMPRESSED_SIDECARS=1` so both layouts can be produced from one tree). +3. Write both rows into `docs/IMPLEMENTATION-5.1.md` ("Performance and + artifact acceptance" already demands before/after evidence) with sha256 and + host identity, using `scripts/benchmark-51.mjs --compare`. +4. Decision rule: proceed with C2 to C5 only for platforms where the + download size or an explicitly stated other goal improves. If no platform + improves (section 2.3 predicts this), implement C6 instead and leave C1 + behind the environment flag, or remove it. + +### C1. Build-side archive (release machines) + +- `scripts/prepare-sidecars.js`: new option `--compressed-ffmpeg`. For the + target triple, verify ffmpeg/ffprobe against `resources/ffmpeg/checksums.json` + as today, **sign them first** (Windows: run the same `signCommand` from + `src-tauri/tauri.windows.conf.json` via `scripts/windows-artifact-sign.ps1`; + macOS: `codesign --force --timestamp --options runtime --sign "$APPLE_SIGNING_IDENTITY"` + with `src-tauri/entitlements.plist`; Linux: none), then write + `src-tauri/binaries/media-tools.tar.gz` containing exactly `ffmpeg` and + `ffprobe` (plus `.exe` on Windows) and `src-tauri/binaries/media-tools.json` + `{ triple, ffmpegVersion, archiveSha256, members: { ffmpeg: { sha256, size, mode } , ffprobe: {...} } }`. + gzip level 6 by default; keep a `--format zstd` switch so C0 can compare + (zstd dedupes the pair: 19.6 MB vs 44.7 MB on macOS arm64). +- The archive path is fixed, so each `build:*:prepared` step for a different + triple must re-run `prepare-sidecars --target --compressed-ffmpeg` + immediately before its `tauri build --target`. `package.json` already + sequences prepare before each build; add the per-target call where two + targets share one prepare today (`build:win:prepared`, `build:mac:native:prepared`). +- `src-tauri/tauri.conf.json`: remove `binaries/rosi-ffmpeg` and + `binaries/rosi-ffprobe` from `externalBin`; add + `"binaries/media-tools.tar.gz": "media-tools/media-tools.tar.gz"` and the + JSON manifest to `bundle.resources`. `rosi-yt-dlp` stays an externalBin. +- `src-tauri/build.rs`: verify the archive's sha256 against the manifest, the + manifest `triple` against `TARGET`, and refuse stub members in release + profile (stub = a member under 4 KiB containing `ROSI-SIDECAR-STUB`). +- Flatpak (`run.rosie.rosi.yml`): copy the archive and manifest into + `/app/lib/rosi/media-tools/`; the runtime path below reads them from the + resource dir. + +### C2. Runtime extraction (`src-tauri/src/sidecars.rs`) + +- `media_tools_dir()` = `/media-tools//`. +- `ensure_media_tools() -> Result`: + return at once when `/.complete` exists and both member hashes match + the manifest (hash check once per process, cached in a `OnceLock`). + Otherwise extract into `.tmp-` with a bounded reader (member + count exactly 2, regular files only, no links, name must equal the manifest + entry, decompressed size capped by manifest size + 1 MiB, path confined), + verify each member's sha256, `chmod 755`, fsync, rename the directory into + place, write `.complete`. Serialize concurrent callers with a process + mutex; a second process racing on the rename sees the winner's `.complete`. + Remove older `/media-tools/*` directories on startup. +- Dependencies: `flate2` and `tar` (both already compiled for the vendored + updater on macOS). Adding them to `src-tauri/Cargo.toml` needs the usual + review: `npm run licenses:cargo:strict`, `cargo audit`, + `check:cargo-update-policy`. If `--format zstd` wins C0, use the `zstd` + crate the vendored updater already depends on. +- Callers: `bundled_ffmpeg()` becomes `ensure_media_tools().map(|t| t.ffmpeg)`; + `verify_bundled` runs the extraction on the existing startup thread so the + first download rarely waits; `start_download` sends a + "Preparing media tools…" progress line if extraction is still running and + fails closed with a clear message if it fails (never fall back to a PATH + ffmpeg silently; `effective_ffmpeg`'s existing custom-path and PATH order + stays). `ffmpeg_guard.rs` and `gpu.rs` resolve through the same function. +- Windows AppLocker or a non-executable app-data mount: extraction succeeds + but spawn fails; report the path in the error and point at the custom + FFmpeg path setting. + +### C3. Signing and verification pipeline changes + +- `scripts/zip-macos.js`: today it requires every `Contents/MacOS` sidecar's + signed entitlements to equal the host's. Replace the ffmpeg/ffprobe checks + with: extract the archive to a temp dir, `codesign --verify --strict` each + member, check Developer ID team and timestamp, check `lipo -archs` and + `minos` for the target arch (reuse `verifyMachOCompatibility`). +- `scripts/pack-macos-updater-zst.js`: remove ffmpeg/ffprobe from + `THIN_MEMBERS`; add the archive and manifest to the members that must be + present; keep yt-dlp in `MULTI_ARCH_MEMBERS`. +- Vendored updater `install_safety.rs` + `macos_bundle_executable_supports_host_arch`: keep the check for `rosi` + and `rosi-yt-dlp`; add a manifest `triple` check for the archive. Record + the change in `PATCHES.md` and regenerate `ROSI.patch`. +- `scripts/gpg-sign.js` `assertNoStubSidecars` and `scripts/msstore-pack.js` + `planSidecars`: read `media-tools.json` instead of the two sidecar entries. +- Notarization dry run (macOS): build, sign, submit with `notarytool`, and + confirm the pre-signed members inside the archive do not fail the scan. + Do this once on a throwaway build before changing the release chain. +- `scripts/e2e-macos-native-packages.mjs` and `verify-release-draft.js`: the + bundle inventory and size comparison must include the archive. + +### C4. E2E + +`e2e/v5-fixes/media-tools/failure-modes.md` (write first), then +`media-tools.spec.js` and `run.mjs` (needs its own profile and env): + +1. Fresh profile: first download extracts, verifies, and converts + successfully; the report records the extracted hashes. +2. Corrupted archive (one flipped byte, via an e2e-only env override of the + resource path): download fails closed with the documented message; no + partial directory remains. +3. Manifest hash mismatch for one member: same as 2. +4. Tampered extracted binary (edit a byte in app data after extraction): + re-extraction on next start replaces it. +5. Two concurrent operations on a cold profile (manual download + format + fetch): exactly one extraction, both succeed. +6. Read-only app-data directory: fails closed; app stays usable for + yt-dlp-only downloads that need no FFmpeg. +7. Upgrade: a stale `media-tools//` directory is removed on start. +8. Custom FFmpeg path set: the archive is still verified but the custom path + is used (existing behaviour). + +Evidence: `e2e/artifacts/v5-fixes-media-tools//report.json`. +Add the group to `e2e/suites.json`. + +### C5. Docs + +`ARCHITECTURE.md` ("Sidecars and releases"), `build-setup.md` ("Bundled +sidecars"), `resources/ffmpeg/README.md`, CHANGELOG bullet, and the +key-compromise doc if the macOS signing identity now signs files on the +worker before Tauri runs. + +### C6. If C0 says no: the levers that do shrink downloads + +Implement in this order, each with its own before/after row in the ledger: + +1. AppImage zstd squashfs: set the compression in the Linux build step + (Tauri honours `APPIMAGE_COMP`; verify in the installed `@tauri-apps/cli` + version, otherwise post-process with `appimagetool --comp zstd`), confirm + the AppImage still launches on Ubuntu 24.04 and the updater's + `appimage_archive.rs` bounds still hold. +2. DMG as `ULMO`: convert after `tauri build`, re-sign the DMG, and run + `e2e-macos-native-packages.mjs --require-real-builds`. +3. ffprobe removal study: measure how many yt-dlp code paths call ffprobe + with the current argument set (`ffmpeg_guard.rs` can log them in the e2e + feature), prototype an `ffprobe` launcher that runs `ffmpeg -i` and + formats the JSON yt-dlp expects, and run the conversion and caption + scenarios against it. Ship only if every scenario passes on all three + platforms. This is the only lever that helps Windows. + +--- + +## 6. Workstream D: UI improvements to finish for 5.1.0 + +`e2e/v5-fixes/ui-polish/failure-modes.md` lists 20 failure modes; the spec +covers rows 1 to 4, 6, 7, 10, 12 to 14, 17 to 20 in eight scenarios, and +five of the eight fail on macOS today (finding 1d). Start with: + +D0. Triage each failing ui-polish assertion as "spec assumption" or "product +gap" and fix on the right side, one scenario per change: + +- `:333` effective summary never resolves: the scenario starts on a fresh + profile with no download folder. Either the scenario must set + `downloadFolder` (spec) or the summary must resolve with the app default + folder when `askDownloadLocation` is off (product; check + `buildEffectiveOptionsReadiness` in `src/engine/bind/settings-controls.ts`, + which returns `destination` for an empty folder even though + `download_options::resolve_output_path` would fall back to the downloads + directory). The product reading is the better one: the renderer should not + block a preview that the backend can resolve. +- `:423` and `:478` section-reset focus: confirm that `showModal` moves focus + into `#app-modal` and that the `[data-reset-section]` buttons are real + ` + +

Download Videos Presets -

+

Prefer MP4 when available; otherwise use the best available format. Often low resolution

@@ -843,6 +869,13 @@

Saved presets

Change… +
Set Up Downloads Choose…
+