|
| 1 | +# Devcontainer |
| 2 | + |
| 3 | +Self-contained dev environment for `wasmaudioworklet`: Node + Playwright |
| 4 | +browsers + the NEAR git-storage sandbox, all running as plain processes |
| 5 | +inside one Ubuntu container. The Playwright e2e suite can run end-to-end |
| 6 | +against the sandbox at `localhost:3030` with no `docker run …` from the |
| 7 | +test code. |
| 8 | + |
| 9 | +## How it's wired |
| 10 | + |
| 11 | +`Dockerfile` is a multi-stage build that bakes the sandbox artifacts |
| 12 | +into the dev image — no docker access needed at runtime, which keeps |
| 13 | +the setup working on GitHub Codespaces (no docker-outside-of-docker |
| 14 | +needed) as well as locally: |
| 15 | + |
| 16 | +- `FROM ghcr.io/petersalomonsen/near-git-storage/sandbox:main AS sandbox` |
| 17 | + — pulled purely to `COPY --from=…`. |
| 18 | +- `FROM mcr.microsoft.com/devcontainers/base:ubuntu-24.04` — the actual |
| 19 | + base. Installs `pulseaudio` (Web Audio sink — without it audio-worklet |
| 20 | + code never starts and the broadcast / audio-comparison specs hang on |
| 21 | + the play-toggle check) and copies in the sandbox's `git-server` binary, |
| 22 | + `/app` (which contains `res/*.wasm`), and `.near` state. |
| 23 | +- Drops a `near-git-sandbox` launcher onto PATH that chdirs into |
| 24 | + `/opt/near-sandbox` and runs `git-server` on `localhost:3030`. |
| 25 | + |
| 26 | +`post-create.sh` then just does the Node side: |
| 27 | + |
| 28 | +1. Boots `pulseaudio`. |
| 29 | +2. `yarn install` + `yarn playwright install chromium` in `wasmaudioworklet/`. |
| 30 | +3. `npm install` in `tools/faust2as/` (Faust → AS source generator used |
| 31 | + by `e2e/faust2as-compilation.spec.js`) and `tools/claude-bridge/` |
| 32 | + (relay spawned by `e2e/claude-bridge.spec.js`). |
| 33 | + |
| 34 | +## Running the e2e suite |
| 35 | + |
| 36 | +```sh |
| 37 | +# 1. Boot the sandbox (port 3030). Picks up the wasm contracts from |
| 38 | +# /opt/near-sandbox/res/. |
| 39 | +near-git-sandbox & |
| 40 | + |
| 41 | +# 2. Regenerate the Faust test sources (only needed when transpiler or |
| 42 | +# upstream Faust examples change — committed output lives under |
| 43 | +# wasmaudioworklet/faust/faust-test-sources.js so this is optional). |
| 44 | +node tools/faust2as/generate-test-sources.js |
| 45 | + |
| 46 | +# 3. Run the suite. --workers=1 because the sandbox-using specs share a |
| 47 | +# single NEAR_REPO_CONTRACT; running in parallel causes pushBaseline |
| 48 | +# conflicts. |
| 49 | +cd wasmaudioworklet |
| 50 | +yarn playwright test --workers=1 |
| 51 | +``` |
| 52 | + |
| 53 | +## Why "sandbox as a process", not a sibling docker container |
| 54 | + |
| 55 | +Earlier iterations of the test setup booted the sandbox image with |
| 56 | +`docker run -p 3030:8080` from outside the dev environment. That's fine |
| 57 | +on Linux hosts but breaks on macOS: |
| 58 | + |
| 59 | +- Docker Desktop / colima on macOS routes container networking through |
| 60 | + a VM, so `--network host` *doesn't* share the actual host network. |
| 61 | + A container started with `--network host` can't reach a sandbox |
| 62 | + bound on the host's `localhost:3030`. |
| 63 | +- The workaround (shared bridge network with named aliases) requires |
| 64 | + rewriting helpers that hard-code `localhost:3030`. |
| 65 | + |
| 66 | +Running the sandbox **inside** the dev container sidesteps all of that: |
| 67 | +both the test runner and `git-server` live in the same Linux process |
| 68 | +space and just talk over `localhost`. CI does the same thing (the |
| 69 | +GitHub workflow `docker run`s the sandbox image alongside, but on a |
| 70 | +proper Linux host) — this devcontainer setup matches that behaviour. |
| 71 | + |
| 72 | +## Matching Playwright versions |
| 73 | + |
| 74 | +When using an off-the-shelf playwright Docker image to reproduce CI |
| 75 | +locally, the image's playwright version **must** match |
| 76 | +`wasmaudioworklet/package.json`'s pinned `playwright` (currently |
| 77 | +`1.59.1`). Mismatch surfaces as: |
| 78 | + |
| 79 | +``` |
| 80 | +Error: browserType.launch: Executable doesn't exist at |
| 81 | + /ms-playwright/chromium_headless_shell-1217/chrome-linux/headless_shell |
| 82 | +… current: mcr.microsoft.com/playwright:v1.60.0-noble |
| 83 | +… required: mcr.microsoft.com/playwright:v1.59.1-noble |
| 84 | +``` |
| 85 | + |
| 86 | +`./node_modules/.bin/playwright install chromium` inside the container |
| 87 | +fixes that ad-hoc, but matching the image tag is the cleaner approach. |
0 commit comments