diff --git a/.github/workflows/frontend-editor-ci.yml b/.github/workflows/frontend-editor-ci.yml index e09bcbb..d8ff01b 100644 --- a/.github/workflows/frontend-editor-ci.yml +++ b/.github/workflows/frontend-editor-ci.yml @@ -30,6 +30,7 @@ jobs: python3 tools/test-doc-translations.py python3 tools/check-doc-translations.py python3 tools/check-doc-examples.py --links-only + python3 tools/test-doc-playgrounds.py - name: Test server transfer with toolchain downloads run: python3 tools/test-server-transfer.py @@ -44,7 +45,7 @@ jobs: timeout-minutes: 10 steps: - uses: actions/checkout@v4 - - name: Test latest-only installer and recovery + - name: Test pinned Wave and latest Vex installer and recovery shell: powershell run: ./frontend/tests/install_latest_test.ps1 @@ -65,13 +66,13 @@ jobs: editor/package-lock.json frontend/package-lock.json - - name: Check latest-only shell installer + - name: Check pinned Wave and latest Vex shell installer run: | bash frontend/tests/install_checksum_test.sh bash frontend/tests/install_latest_test.sh python3 frontend/tests/install_latest_test.py - - name: Check latest-only PowerShell installer + - name: Check pinned Wave and latest Vex PowerShell installer shell: pwsh run: ./frontend/tests/install_latest_test.ps1 @@ -105,6 +106,14 @@ jobs: working-directory: frontend run: npm run test:toolchains + - name: Run browser playground host tests + working-directory: frontend + run: npm run test:playground + + - name: Test Wave syntax highlighting + working-directory: frontend + run: npm run test:syntax + - name: Build frontend working-directory: frontend run: npm run build diff --git a/.github/workflows/playground-ci.yml b/.github/workflows/playground-ci.yml new file mode 100644 index 0000000..14d1e72 --- /dev/null +++ b/.github/workflows/playground-ci.yml @@ -0,0 +1,94 @@ +name: Wave Playground + +on: + pull_request: + paths: + - 'playground/**' + - 'http/**' + - 'wave/source-analyzer/**' + - 'native/tests/source_analyzer_smoke.c' + - 'native/include/wave_source_analyzer.h' + - 'translate/src/**' + - 'translate/tests/test_http.py' + - 'frontend/src/services/playground/**' + - 'frontend/tests/playground*' + - 'wavedoc/**' + - 'frontend/src/services/documentMarkdown.ts' + - 'wave-version' + - 'tools/check-wave-version.py' + - 'tools/test-wave-version.py' + - 'Dockerfile' + - 'compose.yml' + - '.github/workflows/playground-ci.yml' + push: + branches: [master] + paths: + - 'playground/**' + - 'http/**' + - 'wave/source-analyzer/**' + - 'native/tests/source_analyzer_smoke.c' + - 'native/include/wave_source_analyzer.h' + - 'translate/src/**' + - 'translate/tests/test_http.py' + - 'frontend/src/services/playground/**' + - 'frontend/tests/playground*' + - 'wavedoc/**' + - 'frontend/src/services/documentMarkdown.ts' + - 'wave-version' + - 'tools/check-wave-version.py' + - 'tools/test-wave-version.py' + - 'Dockerfile' + - 'compose.yml' + - '.github/workflows/playground-ci.yml' + +permissions: + contents: read + +jobs: + compile-and-run: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + - name: Build and start the isolated Wave service + run: | + docker compose up --build -d playground + container=$(docker compose ps -q playground) + address=$(docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container") + echo "PLAYGROUND_URL=http://$address:8092" >> "$GITHUB_ENV" + curl --retry 15 --retry-delay 1 --retry-connrefused --fail "http://$address:8092/healthz" + - name: Test the shared HTTP library and Translation consumer + run: | + container=$(docker compose ps -q playground) + sdk="$RUNNER_TEMP/wave-http-sdk" + docker cp "$container:/opt/wave" "$sdk" + python3 tools/test-wave-version.py + python3 tools/check-wave-version.py "$sdk/wavec" + "$sdk/wavec" --std-root "$sdk/std" --dep "wave_http=$PWD/http" build http/tests/request.wave --target-dir /tmp/http-tests-build -o /tmp/http-tests + /tmp/http-tests + "$sdk/wavec" --std-root "$sdk/std" --dep "wave_http=$PWD/http" build http/examples/hello.wave --target-dir /tmp/http-example-build -o /tmp/wave-http-example + python3 http/tests/test_server.py + "$sdk/wavec" --std-root "$sdk/std" --dep "wave_http=$PWD/http" build translate/src/main.wave --target-dir /tmp/translate-build -o /tmp/wave-translation-server + python3 translate/tests/test_http.py + - name: Test Wave source highlighting + run: | + sdk="$RUNNER_TEMP/wave-http-sdk" + "$sdk/wavec" --std-root "$sdk/std" build wave/source-analyzer/main.wave --emit=obj --target-dir /tmp/highlight-build -o /tmp/highlight.o + cc -Inative/include native/tests/source_analyzer_smoke.c /tmp/highlight.o -o /tmp/highlight-test + /tmp/highlight-test + - name: Test real compilation and browser host execution + run: | + python3 playground/tests/test_server.py + python3 playground/tests/test_http.py + node --experimental-strip-types --test frontend/tests/playground-live.test.ts + docker compose exec -T playground test ! -e /work/injected + docker compose exec -T playground test ! -e /work/job + - name: Service logs + if: failure() + run: docker compose logs playground + - name: Stop CI service + if: always() + run: docker compose down diff --git a/.github/workflows/translation-ci.yml b/.github/workflows/translation-ci.yml index 3136270..5f3d389 100644 --- a/.github/workflows/translation-ci.yml +++ b/.github/workflows/translation-ci.yml @@ -4,11 +4,13 @@ on: pull_request: paths: - 'translate/**' + - 'wave-version' - '.github/workflows/translation-ci.yml' push: branches: [master] paths: - 'translate/**' + - 'wave-version' - '.github/workflows/translation-ci.yml' permissions: @@ -23,7 +25,7 @@ jobs: - uses: actions/setup-python@v5 with: python-version: '3.12' - - name: Test snapshot retention and build isolation + - name: Test pinned release retention and build isolation env: PYTHONDONTWRITEBYTECODE: '1' run: python3 translate/tests/test_tooling.py diff --git a/Caddyfile b/Caddyfile index 9b5a159..57884c7 100644 --- a/Caddyfile +++ b/Caddyfile @@ -2,12 +2,24 @@ encode zstd gzip header { -Server - Content-Security-Policy "default-src 'self'; base-uri 'self'; connect-src 'self' https://challenges.cloudflare.com; font-src 'self' data:; form-action 'self'; frame-ancestors 'none'; frame-src https://challenges.cloudflare.com; img-src 'self' data:; object-src 'none'; script-src 'self' https://challenges.cloudflare.com; style-src 'self' 'unsafe-inline'" + Content-Security-Policy "default-src 'self'; base-uri 'self'; connect-src 'self' https://challenges.cloudflare.com; font-src 'self' data:; form-action 'self'; frame-ancestors 'none'; frame-src https://challenges.cloudflare.com; img-src 'self' data:; object-src 'none'; script-src 'self' 'wasm-unsafe-eval' https://challenges.cloudflare.com; style-src 'self' 'unsafe-inline'" Permissions-Policy "camera=(), geolocation=(), microphone=()" Referrer-Policy strict-origin-when-cross-origin X-Content-Type-Options nosniff X-Frame-Options DENY } + handle /api/playground/compile { + @oversized expression `{http.request.header.Content-Length} != "" && int({http.request.header.Content-Length}) > 32768` + respond @oversized "Source limit exceeded (32 KiB)." 413 + request_body { + max_size 32KB + } + reverse_proxy playground:8092 { + transport http { + response_header_timeout 15s + } + } + } # Keep the public SDK directory separate from all private platform data. handle_path /downloads/toolchains/* { root * /srv/toolchains diff --git a/Dockerfile b/Dockerfile index a579b32..bd9e2fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN if [ -f package-lock.json ]; then \ fi COPY frontend/ ./ -COPY wavedoc/redirects.json wavedoc/locales.json /src/wavedoc/ +COPY wavedoc/redirects.json wavedoc/locales.json wavedoc/examples.json /src/wavedoc/ RUN npm run build @@ -36,13 +36,13 @@ RUN apt-get update \ pkg-config \ && rm -rf /var/lib/apt/lists/* -ARG WAVE_VERSION=0.2.0-pre-beta +COPY wave-version /opt/wave-version ARG VEX_VERSION=0.0.1 -# The server keeps a pinned toolchain. Public installers only install latest, -# so provision these explicit historical versions from release archives directly. +# All platform Wave components use wave-version and the bundled standard library. RUN <<'INSTALL' set -eu +WAVE_VERSION="$(cat /opt/wave-version)" case "$(uname -m)" in x86_64) arch=x86_64 ;; aarch64) arch=aarch64 ;; @@ -83,6 +83,27 @@ ENV PATH="/root/.wave/bin:${PATH}" RUN wavec --version RUN vex --version +FROM wave-toolchain AS playground-builder +WORKDIR /src +COPY playground/src ./playground/src +COPY http/ ./http/ +RUN wavec --std-root /root/.wave/bin/std --dep wave_http=/src/http build playground/src/main.wave \ + --target-dir /tmp/playground-build -o /tmp/wave-playground + +FROM debian:trixie-slim AS playground +RUN apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates curl util-linux \ + && rm -rf /var/lib/apt/lists/* \ + && groupadd --gid 10002 playground \ + && useradd --uid 10002 --gid playground --no-create-home playground +COPY --from=playground-builder /root/.wave/bin /opt/wave +RUN ln -s ld.lld /opt/wave/llvm/bin/wasm-ld +COPY --from=playground-builder /tmp/wave-playground /usr/local/bin/wave-playground +WORKDIR /work +USER 10002:10002 +EXPOSE 8092 +CMD ["/usr/local/bin/wave-playground"] + FROM wave-toolchain AS application-builder WORKDIR /src diff --git a/Makefile b/Makefile index 034553e..87bce03 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ GOCACHE ?= /tmp/wave-platform-gocache +WAVEC ?= wavec -.PHONY: frontend-install frontend-dev frontend-build test build run clean +.PHONY: frontend-install frontend-dev frontend-build test build run clean wave-version-check + +wave-version-check: + python3 tools/check-wave-version.py "$(WAVEC)" frontend-install: cd frontend && npm install @@ -18,12 +22,13 @@ test: cd frontend && npm run test:docs cd frontend && npm run test:seo cd frontend && npm run test:toolchains + cd frontend && npm run test:playground -build: frontend-build +build: wave-version-check frontend-build mkdir -p bin GOCACHE=$(GOCACHE) go build -trimpath -o bin/wave-platform ./cmd/server -run: frontend-build +run: wave-version-check frontend-build GOCACHE=$(GOCACHE) go run ./cmd/server clean: diff --git a/README.md b/README.md index a525409..82f0b46 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,16 @@ make run The development server listens on . Run `make frontend-dev` in another terminal when Vite hot reload is needed. +Wave components use the version pinned in `wave-version`, with the matching +bundled standard library. `make build` and `make run` reject another compiler. +The homepage, documentation examples, and `/playground` use the Wave compiler +service included in Docker Compose. See [Playground](playground/README.md) for +its execution limits and integration checks. + +Wave services share the small [HTTP library](http/README.md). Playground and +Translation remain independent processes with their own routes and lifecycle; +the Go platform remains a single host application. + ### LLVM toolchain downloads The `/toolchains` page reads `/downloads/toolchains/index.json`. In development, diff --git a/compose.yml b/compose.yml index 32a20d4..087c3f7 100644 --- a/compose.yml +++ b/compose.yml @@ -66,6 +66,11 @@ services: depends_on: wave-platform: condition: service_healthy + playground: + condition: service_started + networks: + - default + - playground environment: WAVE_SITE_ADDRESS: "${WAVE_SITE_ADDRESS:-http://localhost}" ports: @@ -90,6 +95,31 @@ services: retries: 5 start_period: 5s + playground: + build: + context: . + target: playground + image: wave-playground:development + restart: unless-stopped + init: true + read_only: true + user: "10002:10002" + cap_drop: [ALL] + security_opt: ["no-new-privileges:true"] + pids_limit: 64 + mem_limit: 1g + cpus: 1.0 + tmpfs: + - /work:rw,noexec,nosuid,nodev,size=64m,uid=10002,gid=10002,mode=0700 + networks: [playground] + expose: ["8092"] + healthcheck: + test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8092/healthz"] + interval: 30s + timeout: 15s + retries: 3 + start_period: 5s + wave-platform-data-init: image: alpine:3.22 restart: "no" @@ -117,3 +147,7 @@ services: volumes: caddy-data: caddy-config: + +networks: + playground: + internal: true diff --git a/docs/document-authoring.md b/docs/document-authoring.md index 3024342..16ab0b4 100644 --- a/docs/document-authoring.md +++ b/docs/document-authoring.md @@ -149,3 +149,45 @@ Hangul literals used in Unicode examples. Automated checks do not establish linguistic quality. Review translated prose for terminology, negation, boundary values, ownership, and error semantics. Do not remove an explanation or silently change an example to make a check pass. + +## Embedded playgrounds + +Use `wave playground` for a complete program that can run in the browser. It +renders an editable, highlighted program with Run, Stop, Reset, and output in +place. Opening a document never compiles or runs its examples automatically. +Ordinary `wave` fences remain read-only highlighted code, including fragments, +invalid examples, and programs needing native OS facilities. + +````markdown + +```wave playground +fun main() { + println("Hello, Wave!"); +} +``` +```` + +The fence works without metadata, but official documentation must keep its +adjacent `wave-example` marker and set `"playground": true` on the matching entry +in `wavedoc/examples.json`. The `stdin` field supplies initial input; `stdout` and `exit` remain +verification data for automated tests. Reset restores the +original source and input and clears the previous execution result. The same ID +in translations reuses this metadata; keep the fence modifier in translations. + +Enable only single-file programs that fit the browser execution limits and do +not require files, sockets, external services, or native-only imports. The live +playground CI compiles each enabled canonical example to Wasm and checks its +output and exit code, including alternate `runs` from the manifest: + +```shell +python3 tools/test-doc-playgrounds.py +python3 tools/check-doc-examples.py --links-only +cd frontend +npm run test:docs +node --experimental-strip-types --test tests/playground-live.test.ts +``` + +The live test uses the running local service at `http://localhost:8080` unless +`PLAYGROUND_URL` selects another instance. The document checker also rejects +unregistered playground fences and cases that require file fixtures or have +`check`/`reject` modes. Add new examples only after the live test passes. diff --git a/editor/README.md b/editor/README.md index e92e72b..afb3052 100644 --- a/editor/README.md +++ b/editor/README.md @@ -148,13 +148,12 @@ transform functions: import("wave_editor")::{editor_abi_version, analyze_document, transform_document}; ``` -The current tagged `wavec 0.2.0-pre-beta` binary predates public module -visibility even though the latest Wave source and Vex contract support `pub`. -Validate the Vex library with a compiler build that includes the public module -contract: +Use the compiler version pinned in the repository's `wave-version` file and its +bundled standard library. The same version builds the platform's native modules, +the playground, and the translation service. ```sh -VEX_WAVEC=/path/to/current/wavec vex check +VEX_WAVEC=/path/to/pinned/wavec vex check ``` Wave Platform keeps `wave/main.wave` as an ABI-compatible production adapter so diff --git a/frontend/package.json b/frontend/package.json index 212caea..df731eb 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -8,9 +8,11 @@ "build": "vue-tsc --noEmit && vite build", "preview": "vite preview", "typecheck": "vue-tsc --noEmit", - "test:docs": "node --experimental-strip-types --test tests/document-navigation.test.ts", + "test:docs": "node --experimental-strip-types --test tests/document-navigation.test.ts tests/document-markdown.test.ts", "test:seo": "node --experimental-strip-types --test tests/seo-image.test.ts", - "test:toolchains": "node --experimental-strip-types --test tests/toolchains.test.ts" + "test:toolchains": "node --experimental-strip-types --test tests/toolchains.test.ts", + "test:syntax": "node --experimental-strip-types --test tests/wave-syntax.test.ts", + "test:playground": "node --experimental-strip-types --test tests/playground.test.ts" }, "dependencies": { "@wavefnd/editor": "file:../editor", diff --git a/frontend/public/install.ps1 b/frontend/public/install.ps1 index 4a5c1c2..bd8293d 100644 --- a/frontend/public/install.ps1 +++ b/frontend/public/install.ps1 @@ -8,12 +8,12 @@ [switch]$Help, [Parameter(ValueFromRemainingArguments = $true)][string[]]$Remaining ) -# Wave installer channel policy: latest-only-v1 +# Wave installer channel policy: pinned-0.2.1-v1 $ErrorActionPreference = 'Stop' function Write-Info($Message) { Write-Host "[info] $Message" } function Manual-Only { - throw 'This installer only installs the latest public release. Install older versions or Nightly manually: https://github.com/wavefnd/Wave/releases' + throw 'This installer installs Wave v0.2.1-pre-beta. Install older versions or Nightly manually: https://github.com/wavefnd/Wave/releases' } function Get-LatestRelease($Repository) { $best = $null @@ -34,6 +34,11 @@ function Get-LatestRelease($Repository) { if ($null -eq $best) { throw "No public versioned release is available for $Repository." } return $best } +function Get-PinnedWaveRelease { + $release = Invoke-RestMethod -Headers @{Accept='application/vnd.github+json'} -TimeoutSec 60 -Uri 'https://api.github.com/repos/wavefnd/Wave/releases/tags/v0.2.1-pre-beta' + if ($release.tag_name -ne 'v0.2.1-pre-beta' -or $release.draft -ne $false) { throw 'Pinned Wave release metadata does not match.' } + return $release +} function Get-ReleaseAsset($Release, $Name, [bool]$Optional = $false) { $assets = @($Release.assets | Where-Object { $_.name -ceq $Name }) if ($assets.Count -eq 0 -and $Optional) { return $null } @@ -87,7 +92,8 @@ function Test-Installation($Directory, $Target, [bool]$InstallVex, $Work) { $wavec = Join-Path $Directory 'wavec.exe' & $wavec --version if ($LASTEXITCODE -ne 0) { throw 'wavec --version failed. Check the Visual C++ runtime.' } - $actual = & $wavec print host-target + $spec = & $wavec print target-spec --format=json + $actual = ($spec | ConvertFrom-Json).triple if ($LASTEXITCODE -ne 0 -or "$actual".Trim() -ne $Target) { throw "Compiler host target differs from $Target." } $source = Join-Path $Work 'install-smoke.wave' [IO.File]::WriteAllText($source, @' @@ -112,7 +118,7 @@ fun main() -> i32 { function Install-Wave { if ($Help) { Write-Host @' -Wave Toolchain Installer — latest public release only +Wave Toolchain Installer — Wave v0.2.1-pre-beta Usage: .\install.ps1 [-Latest] [-WithVex | -WithoutVex] [-NoModifyPath] Default: install Wave and install Vex when its latest release supports this platform. -WithVex requires Vex; -WithoutVex installs Wave only. @@ -138,7 +144,7 @@ Older versions and Nightly: download manually from https://github.com/wavefnd/Wa throw "Refusing to replace a directory not managed by Wave: $installDir" } } - $wave = Get-LatestRelease 'wavefnd/Wave' + $wave = Get-PinnedWaveRelease $waveName = "wave-$($wave.tag_name)-$target.zip" $waveAsset = Get-ReleaseAsset $wave $waveName $vex = $null; $vexAsset = $null; $vexName = '' diff --git a/frontend/public/install.sh b/frontend/public/install.sh index 5873cf1..39d01a9 100755 --- a/frontend/public/install.sh +++ b/frontend/public/install.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash set -euo pipefail -# Wave installer channel policy: latest-only-v1 +# Wave installer channel policy: pinned-0.2.1-v1 info() { printf '[info] %s\n' "$*"; } fail() { printf '[error] %s\n' "$*" >&2; exit 1; } manual_only() { - fail 'This installer only installs the latest public release. Install older versions or Nightly manually: https://github.com/wavefnd/Wave/releases' + fail 'This installer installs Wave v0.2.1-pre-beta. Install older versions or Nightly manually: https://github.com/wavefnd/Wave/releases' } usage() { cat <<'HELP' -Wave Toolchain Installer — latest public release only +Wave Toolchain Installer — Wave v0.2.1-pre-beta Usage: bash install.sh [latest] [--with-vex | --without-vex] [--no-modify-path] Default: install Wave and install Vex when its latest release supports this platform. --with-vex Require Vex; fail before installation if its package is absent. @@ -42,6 +42,12 @@ latest_release() { [[ "$best" != null ]] || fail "No public versioned release is available for $repository." printf '%s\n' "$best" } +pinned_wave_release() { + local release + release="$(fetch -H 'Accept: application/vnd.github+json' 'https://api.github.com/repos/wavefnd/Wave/releases/tags/v0.2.1-pre-beta')" || fail 'Cannot fetch pinned Wave release.' + jq -e '.tag_name == "v0.2.1-pre-beta" and .draft == false' >/dev/null <<< "$release" || fail 'Pinned Wave release metadata does not match.' + printf '%s\n' "$release" +} asset() { # An absent optional Vex asset is distinct from an invalid published asset. local release="$1" name="$2" optional="${3:-false}" selected count @@ -101,7 +107,7 @@ configure_path() { verify_installation() { local directory="$1" target="$2" with_vex="$3" work="$4" actual "$directory/wavec" --version || return 1 - actual="$("$directory/wavec" print host-target)" || return 1 + actual="$("$directory/wavec" print target-spec --format=json | jq -er .triple)" || return 1 [[ "$actual" == "$target" ]] || { printf 'Expected %s; compiler reports %s\n' "$target" "$actual" >&2; return 1; } cat > "$work/install-smoke.wave" <<'WAVE' import("std::mem::layout")::{size_of}; @@ -141,7 +147,7 @@ main() { [[ ! -L "$INSTALL_DIR" ]] || fail 'The installation directory must not be a symbolic link.' if [[ -e "$INSTALL_DIR" && ! -f "$INSTALL_DIR/wavec" ]]; then fail "Refusing to replace a directory not managed by Wave: $INSTALL_DIR"; fi local wave_release wave_version wave_name wave_asset vex_release vex_version='' vex_name='' vex_asset='null' install_vex=false - wave_release="$(latest_release wavefnd/Wave)"; wave_version="$(jq -r '.tag_name' <<< "$wave_release")" + wave_release="$(pinned_wave_release)"; wave_version="$(jq -r '.tag_name' <<< "$wave_release")" wave_name="wave-$wave_version-$WAVE_SUFFIX.tar.gz"; wave_asset="$(asset "$wave_release" "$wave_name")" if [[ "$vex_mode" != off ]]; then vex_release="$(latest_release wavefnd/Vex)"; vex_version="$(jq -r '.tag_name' <<< "$vex_release")" diff --git a/frontend/src/components/MarkdownContent.vue b/frontend/src/components/MarkdownContent.vue index 6a63d83..184e7c5 100644 --- a/frontend/src/components/MarkdownContent.vue +++ b/frontend/src/components/MarkdownContent.vue @@ -1,12 +1,17 @@ diff --git a/frontend/src/components/WavePlayground.vue b/frontend/src/components/WavePlayground.vue new file mode 100644 index 0000000..9e66330 --- /dev/null +++ b/frontend/src/components/WavePlayground.vue @@ -0,0 +1,186 @@ + + +