diff --git a/cockpit/web-test/README.md b/cockpit/web-test/README.md new file mode 100644 index 00000000..368a401c --- /dev/null +++ b/cockpit/web-test/README.md @@ -0,0 +1,58 @@ +# cockpit web-test — running it locally + +The `cockpit-web-test` suite builds the cockpit to wasm, serves it, and drives +the **real** cockpit in headless Chromium (Playwright). CI runs it on every PR; +the repo-root `flake.nix` makes the *exact same* run reproducible locally, so +browser acceptance is a normal local check rather than a cloud-only oracle. + +## Run it + +From the repository root, with a flakes-enabled Nix: + +```sh +nix develop # the toolchain shell (see "What the shell provides") +./cockpit/build-web.sh # cargo build wasm + version-matched wasm-bindgen → cockpit/dist +cd cockpit/web-test +npm ci +npm test # Playwright + Chromium against cockpit/dist +``` + +The flake does **not** replace those commands or duplicate any version — it only +provides an environment in which the existing scripts work unchanged. + +## What the shell provides + +- **Rust via `rustup`** — the toolchain and components come from the repo's + `rust-toolchain.toml`; `build-web.sh` adds the `wasm32-unknown-unknown` target. +- **`wasm-bindgen-cli`** — the shell hook installs *exactly* the version pinned + in `cockpit/Cargo.toml` (read from there, not re-pinned here); `build-web.sh` + still enforces the version match itself. +- **Node 22** and the **Playwright browser** — `nixpkgs` is pinned to + `nixos-25.11`, whose `playwright-driver` is **1.56.1**, the exact version in + `cockpit/web-test/package.json`. So the Nix-provided Chromium revision matches + what the npm Playwright expects, and the downloaded (non-NixOS-runnable) browser + is skipped (`PLAYWRIGHT_BROWSERS_PATH`). +- **A target-scoped wasm C toolchain.** The C in the Guitar Pro reader's `zstd` + subtree must be cross-compiled to wasm. The standard Nix cc-wrapper forces the + *host* target, which silently produces x86 objects and an undefined-`ZSTD_*` + link failure. The fix is an *unwrapped* `clang` driven only for the wasm + target: + + ``` + CC_wasm32_unknown_unknown = clang + AR_wasm32_unknown_unknown = llvm-ar + CFLAGS_wasm32_unknown_unknown = --target=wasm32-unknown-unknown + ``` + + These are **target-scoped** (`*_wasm32_unknown_unknown`), so a plain native + `cargo test` / `cargo clippy` in the same shell uses the host `gcc` with no + wasm flags — the host build is untouched. + +## Notes + +- CI is **not** on Nix; it keeps its own working setup. The flake is a local-dev + convenience, not a CI rewrite. +- `cockpit/dist/`, `node_modules/`, and `target/` are gitignored build outputs. +- Without Nix, replicate the shell by hand: a matching Rust toolchain, the pinned + `wasm-bindgen-cli`, Node 22, a Playwright-1.56 Chromium, and a wasm-target C + compiler. diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..227b2120 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1782847189, + "narHash": "sha256-twXPFqFsrrY5r28Zh7Homgcp2gUMBgQ6WDS98Q/3xFI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b6018f87da91d19d0ab4cf979885689b469cdd41", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..cdb1eb38 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + description = "griff cockpit web-test dev shell — full local wasm build + Playwright (3C-B0)"; + + # Pinned to nixos-25.11: its `playwright-driver` is 1.56.1 — the exact version + # cockpit/web-test/package.json pins — so the Nix-provided Chromium revision + # matches what the npm Playwright expects. Its clang cross-compiles wasm too, + # so one input covers the whole flow. + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + # Unwrapped clang for the wasm C cross-compile: the standard Nix cc-wrapper + # forces the host target, which silently compiled zstd's C to x86 objects + # (undefined ZSTD_* at the wasm link). The wasm target must get a plain + # `clang --target=wasm32-unknown-unknown`, and only that target. + wasmClang = pkgs.llvmPackages.clang-unwrapped; + in + { + devShells.${system}.default = pkgs.mkShell { + packages = [ + pkgs.rustup # the repo's rust-toolchain.toml pins stable + rustfmt/clippy + pkgs.nodejs_22 # match CI + pkgs.clang # host cc for native cargo builds inside the shell + pkgs.lld + pkgs.llvm # llvm-ar for the wasm archive + pkgs.pkg-config + pkgs.cacert # cargo install / npm fetch over TLS + pkgs.git + wasmClang + ]; + + # Target-scoped so host (x86_64) builds are untouched — cc-rs reads the + # `*_wasm32_unknown_unknown` triples only when building for that target. + CC_wasm32_unknown_unknown = "${wasmClang}/bin/clang"; + AR_wasm32_unknown_unknown = "${pkgs.llvm}/bin/llvm-ar"; + CFLAGS_wasm32_unknown_unknown = "--target=wasm32-unknown-unknown"; + + # Playwright runs the Nix-provided browser instead of downloading a + # dynamically-linked one that will not run on NixOS. + PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}"; + PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = "true"; + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1"; + + shellHook = '' + # rustup/cargo installs land here; put it ahead of the Nix rustup shim. + export PATH="$HOME/.cargo/bin:$PATH" + # wasm-bindgen-cli must match the crate version build-web.sh checks. We + # do not pin it in the flake (that would duplicate cockpit/Cargo.toml); + # we install exactly what the repo asks for, once. + want=$(grep -m1 -E '^wasm-bindgen[[:space:]]*=' cockpit/Cargo.toml | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true) + have=$(wasm-bindgen --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1 || true) + if [ -n "$want" ] && [ "$have" != "$want" ]; then + echo "flake: installing wasm-bindgen-cli $want (matching cockpit/Cargo.toml)…" + cargo install wasm-bindgen-cli --version "$want" --locked + fi + ''; + }; + }; +}