Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions cockpit/web-test/README.md
Original file line number Diff line number Diff line change
@@ -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.
27 changes: 27 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Generate dev shells for supported host systems

When a contributor's Nix system is anything other than x86_64-linux (for example aarch64-linux or Darwin), nix develop will look for devShells.<system>.default (as documented by the Nix manual), but this flake only emits devShells.x86_64-linux.default. That makes the documented local web-test shell unavailable on those hosts even though the toolchain is otherwise not inherently x86-only; please generate shells for the supported systems or document the shell as Linux x86_64-only.

Useful? React with 👍 / 👎.

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
'';
};
};
}
Loading