# Justfile for crater - CSS Layout Engine

# Default target
default: check

# === Setup ===

# Initialize submodules and dependencies
setup:
    git submodule update --init --recursive
    moon update
    pnpm install

# === Testing ===

# Run default JS-target MoonBit tests across the workspace
test:
    moon test --target js

# Run JS-target MoonBit tests across the workspace
test-js:
    moon test --target js

# Run `moon test` with the mizchi/v8 native dep excluded, for environments where
# rusty_v8 can't be built (e.g. the web sandbox; see #312). Args pass through:
#   just test-no-v8 -p mizchi/crater-dom/html
# just test-no-v8 -p mizchi/crater-layout/grid --target js
test-no-v8 *ARGS:
    scripts/moon-test-no-v8.sh {{ ARGS }}

# Dynamic-reflow VRT harness: assert incremental re-render geometry == full
# rebuild across a corpus of (before, after) page states. Runs on the js target
# with no V8 (browser-free equivalent of a paint VRT for the reflow path).
reflow-vrt:
    scripts/moon-test-no-v8.sh -p mizchi/crater-browser/shell -f "reflow VRT*" --target js

# Regenerate the embedded real-world reflow-VRT fixture corpus from
# real-world/*/index.html (run after changing the fixtures or the generator).
gen-reflow-vrt-fixtures:
    node scripts/gen-reflow-vrt-fixtures.mjs

# Run all repository Vitest suites with an explicit include/exclude boundary
test-vitest:
    pnpm test:vitest

# Run node:test-based JS/WASM/browser contract tests
test-node:
    pnpm test:node

# Run the crater self-contained JS/TS test suites end-to-end
test-all:
    just test-vitest
    just test-node

# Run native-target smoke tests for the native browser host facade
test-native:
    moon -C browser/native test -p mizchi/crater-browser-native --target native -j 1

# Explicit alias for the native facade smoke suite
test-native-smoke:
    just test-native

# Run native-target V8 runtime tests without browser shell / sqlite-backed e2e helpers
test-native-v8:
    moon -C browser/native test -p mizchi/crater-browser-native/js_v8 --target native -j 1

# Run full native browser e2e tests.
# This suite pulls browser shell/http and may require libsqlite3 headers on the host.
test-native-full:
    moon -C testing test -p mizchi/crater-testing/e2e/native_v8 --target native -j 1

# Run wasm-target MoonBit tests for the wasm component module
test-wasm-mbt:
    moon -C wasm test --target wasm

# Run JS-target tests for a specific package
test-pkg-js pkg:
    moon test -p {{ pkg }} --target js

# Run the image-VRT suite (paint tree -> gfx software backend -> pixels)
test-gfx-vrt:
    moon test -p gfx_vrt --target js

# Re-baseline the image-VRT snapshots after an intentional pixel change
test-gfx-vrt-update:
    moon test -p gfx_vrt --target js --update

# Browser-free PNG image VRT: render fixtures and diff against baselines
test-image-vrt:
    cd js && moon build --target js --release && node scripts/image-vrt.mjs

# Re-baseline the PNG image-VRT fixtures
test-image-vrt-update:
    cd js && moon build --target js --release && node scripts/image-vrt.mjs --update

# Accuracy gate: crater pixels vs real Chromium (skips if no browser)
test-accuracy:
    cd js && npm run build && node scripts/accuracy.mjs

# Real-browser E2E for the gfx web backend (WebGPU when the browser has it,
# else CPU); asserts in-browser pixels and GPU==CPU. Skips if no browser.
test-webgpu-e2e:
    cd js && npm run build && node scripts/webgpu-e2e.mjs

# Run native-target tests for a specific browser/native package
test-pkg-native pkg:
    moon -C browser/native test -p {{ pkg }} --target native -j 1

# Run wasm-target tests for a specific wasm package
test-pkg-wasm pkg:
    moon -C wasm test -p {{ pkg }} --target wasm -j 1

# Run tests for a specific package with auto target selection.
test-pkg pkg target='auto':
    if [ "{{ target }}" = "auto" ]; then case "{{ pkg }}" in mizchi/crater-browser-native*) moon -C browser/native test -p {{ pkg }} --target native -j 1 ;; mizchi/crater-testing/e2e/native_v8) moon -C testing test -p {{ pkg }} --target native -j 1 ;; mizchi/crater-wasm*) moon -C wasm test -p {{ pkg }} --target wasm -j 1 ;; *) moon test -p {{ pkg }} --target js ;; esac; elif [ "{{ target }}" = "native" ]; then case "{{ pkg }}" in mizchi/crater-browser-native*) moon -C browser/native test -p {{ pkg }} --target native -j 1 ;; *) moon -C testing test -p {{ pkg }} --target native -j 1 ;; esac; elif [ "{{ target }}" = "wasm" ]; then moon -C wasm test -p {{ pkg }} --target wasm -j 1; else moon test -p {{ pkg }} --target {{ target }}; fi

# Update test snapshots
test-update:
    moon test --target js --update

# Run taffy compatibility tests
test-taffy:
    moon -C conformance test -p mizchi/crater-conformance/taffy --target js

# Verify moon test result does not regress from recorded baseline
test-baseline:
    scripts/test-baseline.sh

# Run the current MoonBit suite against the recorded failure baseline
test-moon-baseline:
    just test-baseline

# Update moon test baseline summary file
test-baseline-update:
    scripts/test-baseline-update.sh

# Verify WPT result does not regress from recorded baseline
wpt-baseline:
    scripts/test-wpt-baseline.sh

# Update WPT baseline summary file
wpt-baseline-update:
    scripts/test-wpt-baseline-update.sh

# === Code Quality ===

# Check compilation (main + browser + js)
check:
    moon info --target js
    moon info browser/native --target native
    moon info wasm --target wasm
    moon check aomx --target js -j 1
    moon check benchmarks --target js -j 1
    moon check browser_helpers --target js -j 1
    moon check testing --target js -j 1
    moon check webvitals --target js -j 1
    moon check http --target js -j 1
    moon check dom --target js -j 1
    moon check layout --target js -j 1
    moon check painter --target js -j 1
    moon check renderer --target js -j 1
    moon check runtime --target js -j 1
    moon check browser --target js -j 1
    moon check browser/native --target native -j 1
    moon check js --target js
    moon check wasm --target wasm -j 1

# Format code
fmt:
    moon fmt
    moon -C aomx fmt
    moon -C benchmarks fmt
    moon -C browser_helpers fmt
    moon -C testing fmt
    moon -C webvitals fmt
    moon -C http fmt
    moon -C dom fmt
    moon -C layout fmt
    moon -C painter fmt
    moon -C renderer fmt
    moon -C runtime fmt
    moon -C browser fmt
    moon -C browser/native fmt
    moon -C js fmt
    moon -C wasm fmt

# Update interface files (.mbti)
info:
    moon info --target js
    moon -C browser/native info --target native
    moon -C wasm info --target wasm

# Format and update interface (run before commit)
prepare:
    just info
    just fmt

# Analyze test coverage
coverage:
    moon coverage analyze > uncovered.log
    @echo "Coverage report written to uncovered.log"

# Show JS-target MoonBit test summary
status:
    @echo "Running tests..."
    @moon test --target js 2>&1 | tail -1

# === Test Generation ===

# Generate MoonBit tests from taffy fixtures
gen-taffy-tests input output *args:
    npx tsx scripts/gen-taffy-tests.ts {{ input }} {{ output }} {{ args }}

# Generate html5lib tests
gen-html5lib-tests *args:
    npx tsx scripts/gen-html5lib-tests.ts {{ args }}

# === WPT (Web Platform Tests) ===
# Uses wpt/ submodule directly

# List available WPT CSS modules
wpt-list:
    npx tsx scripts/wpt-runner.ts --list

# Run WPT CSS tests for a module (e.g., css-flexbox)
wpt module:
    npx tsx scripts/wpt-runner.ts {{ module }}

# Run all WPT CSS tests
wpt-all:
    npx tsx scripts/wpt-runner.ts --all

# Run all WPT tests and generate report
wpt-run-all:
    npx tsx scripts/wpt-runner.ts --all

# Run WPT CSS tests and emit CI shard report JSON
wpt-css-report module report *args:
    npx tsx scripts/wpt-runner.ts {{ module }} --json {{ report }} {{ args }}

# Update WPT README
wpt-update-readme:
    npx tsx scripts/update-wpt-readme.ts

# Diff CSS math (calc/min/max/clamp) layout vs Chromium.
# No args runs the built-in fixture matrix; pass an HTML file to diff one page.
# Non-zero exit on any mismatch, so it doubles as a CI gate.
calc-diff *args:
    npx tsx scripts/calc-layout-diff.ts {{ args }}

# Aggregate Crater-vs-Chromium layout match rate on real-world snapshots
# (github-mizchi, example-com). No args measures all; pass a snapshot name.
match-rate *args:
    npx tsx scripts/real-world-match-rate.ts {{ args }}

# === WPT DOM Tests ===

# Run WPT DOM tests (single file or pattern)
wpt-dom pattern:
    npx tsx scripts/wpt-dom-runner.ts {{ pattern }}

# Run all WPT DOM tests
wpt-dom-all:
    npx tsx scripts/wpt-dom-runner.ts --all

# Run WPT DOM tests and emit CI shard report JSON
wpt-dom-report target report *args:
    npx tsx scripts/wpt-dom-runner.ts {{ target }} --json {{ report }} {{ args }}

# Run WPT SVG DOM tests
wpt-svg:
    npx tsx scripts/wpt-dom-runner.ts --svg

# Run curated WPT shadow-dom tests
wpt-dom-shadow:
    npx tsx scripts/wpt-dom-runner.ts --shadow

# List available WPT DOM tests
wpt-dom-list:
    npx tsx scripts/wpt-dom-runner.ts --list

# === WPT Filter Effects & Compositing ===

# Run WPT filter-effects tests
wpt-filter-effects:
    npx tsx scripts/wpt-runner.ts filter-effects

# Run WPT compositing tests
wpt-compositing:
    npx tsx scripts/wpt-runner.ts compositing

# Aggregate WPT CI shard reports and render markdown/json summary
wpt-ci-summary input json markdown:
    npx tsx scripts/wpt-ci-summary.ts --input {{ input }} --json {{ json }} --markdown {{ markdown }}

# Aggregate CI job timing report from GitHub run jobs JSON
ci-timing-summary input json markdown:
    npx tsx scripts/ci-timing-summary.ts --input {{ input }} --json {{ json }} --markdown {{ markdown }}

# === WebDriver BiDi Server ===

# Build BiDi server
build-bidi:
    moon -C webdriver build font_runtime --target js --release -j 1
    moon -C webdriver build bidi_main --target js --release -j 1
    moon -C tools build webdriver_fixture_builder --target js --release -j 1

# Start BiDi server (Deno)
start-bidi:
    bash -lc 'set -euo pipefail; for candidate in "_build/js/release/build/mizchi/crater-webdriver-bidi/bidi_main/bidi_main.js" "webdriver/_build/js/release/build/bidi_main/bidi_main.js" "webdriver/target/js/release/build/bidi_main/bidi_main.js"; do if [ -f "$candidate" ]; then exec deno run -A "$candidate"; fi; done; echo "BiDi server not built. Run: just build-bidi" >&2; exit 1'

# Start BiDi server with font metrics (for VRT)
start-bidi-with-font:
    deno run -A webdriver/bidi_main/start-with-font.ts

# === WPT WebDriver BiDi Tests ===

# List available WebDriver BiDi test modules
wpt-webdriver-list:
    npx tsx scripts/wpt-webdriver-runner.ts --list

# Run WebDriver BiDi tests for a module (e.g., session/status)
wpt-webdriver module:
    npx tsx scripts/wpt-webdriver-runner.ts {{ module }}

# Run WebDriver BiDi tests and emit CI shard report JSON
wpt-webdriver-report module report *args:
    npx tsx scripts/wpt-webdriver-runner.ts {{ module }} --json {{ report }} {{ args }}

# Run a predefined WebDriver BiDi profile (e.g., strict, network-no-auth)
wpt-webdriver-profile profile:
    npx tsx scripts/wpt-webdriver-runner.ts --profile {{ profile }}

# Run all WebDriver BiDi tests
wpt-webdriver-all:
    npx tsx scripts/wpt-webdriver-runner.ts --all

# === Integration Tests ===

# Test Preact compatibility (requires BiDi server to be running)
test-preact:
    pnpm test:preact

# Test Playwright integration (requires BiDi server to be running)
test-playwright:
    pnpm test:bidi-e2e

# Test Playwright adapter with locator APIs
test-playwright-adapter:
    pnpm test:playwright

# Test website loading and browser user scenarios
test-website:
    pnpm test:website

# Compare a URL between Chromium and Crater (one-command VRT)
vrt-url *args:
    npx tsx scripts/vrt-url.ts {{ args }}

# Compare a URL using native paint backend
vrt-url-native *args:
    npx tsx scripts/vrt-url.ts {{ args }} --backend native

# Run relaxed paint visual regression tests against Chromium screenshots
test-vrt:
    pnpm test:vrt

# Run WPT visual regression tests against Chromium screenshots
test-wpt-vrt:
    pnpm test:wpt-vrt

# Run responsive VRT tests at multiple viewports
test-vrt-responsive:
    pnpm exec playwright test tests/paint-vrt-responsive.test.ts

# Run VRT levels tests
test-vrt-levels:
    pnpm exec playwright test tests/paint-vrt-levels.test.ts

# Capture a real-world snapshot for VRT testing
vrt-capture *args:
    npx tsx scripts/capture-real-world-snapshot.ts {{ args }}

# Re-capture all URL snapshots
vrt-capture-all:
    npx tsx scripts/capture-real-world-snapshot.ts "https://example.com" --name example-com --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://info.cern.ch" --name info-cern-ch --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://news.ycombinator.com/" --name hackernews --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://www.google.com" --name google --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://en.wikipedia.org/wiki/Main_Page" --name wikipedia --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://craigslist.org" --name craigslist --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://lobste.rs" --name lobsters --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://lite.cnn.com" --name lite-cnn --width 800 --height 600
    npx tsx scripts/capture-real-world-snapshot.ts "https://www.npmjs.com/package/express" --name npmjs-express --width 800 --height 600

# Update WPT VRT baseline
wpt-vrt-baseline-update:
    WPT_VRT_UPDATE_BASELINE=1 pnpm test:wpt-vrt

# Run Playwright benchmark
bench-playwright:
    pnpm bench:playwright

# Run VRT API end-to-end benchmarks
bench-vrt:
    npx tsx scripts/vrt-bench.ts --group api

# Run VRT phase benchmarks (parse / node+layout / paint / json / diff)
bench-vrt-phases:
    npx tsx scripts/vrt-bench.ts --group phases

# Run all VRT API benchmarks
bench-vrt-all:
    npx tsx scripts/vrt-bench.ts --group all

# List resolved VRT benchmark indices
bench-vrt-list group="all":
    npx tsx scripts/vrt-bench.ts --group {{ group }} --list

# Run VRT benchmarks and write parsed reports
bench-vrt-report group output_dir="vrt-bench":
    mkdir -p {{ output_dir }}
    bash -lc 'set -euo pipefail; npx tsx scripts/vrt-bench.ts --group {{ group }} --json {{ output_dir }}/{{ group }}.json --markdown {{ output_dir }}/{{ group }}.md | tee {{ output_dir }}/{{ group }}.log'

# Compact flaker entrypoint
flaker *args:
    node scripts/flaker-entry.ts {{ args }}

# List flaker-managed Playwright tasks
flaker-list:
    node scripts/flaker-entry.ts config list

# Validate flaker config against tracked Playwright specs
flaker-check:
    node scripts/flaker-entry.ts config check

# Resolve affected Playwright tasks from changed repo paths
flaker-affected *paths:
    node scripts/flaker-entry.ts config affected {{ paths }}

# Generate a task-scoped flaker.toml from flaker.star
flaker-task-config task_id output="":
    if [ -n "{{ output }}" ]; then node scripts/flaker-task-config.ts --task {{ task_id }} --write {{ output }}; else node scripts/flaker-task-config.ts --task {{ task_id }}; fi

# Run flaker with a task-scoped generated config
flaker-task task_id *args:
    node scripts/flaker-task-run.ts --task {{ task_id }} -- {{ args }}

# Sample tests using flaker for a single task
flaker-task-sample task_id *args:
    node scripts/flaker-entry.ts task sample {{ task_id }} {{ args }}

# Import a Playwright JSON report into the shared flaker store for a task
flaker-task-import task_id report_path *args:
    node scripts/flaker-entry.ts task import {{ task_id }} {{ report_path }} {{ args }}

# Run a Playwright task, persist its JSON report, and import it into flaker
flaker-task-record task_id report_path="" summary_dir="" vrt_summary_dir="" *args:
    bash -lc 'set -euo pipefail; cmd=(node scripts/flaker-task-record.ts --task "$1"); report_path="$2"; summary_dir="$3"; vrt_summary_dir="$4"; shift 4; if [ -n "$report_path" ]; then cmd+=(--report-path "$report_path"); fi; if [ -n "$summary_dir" ]; then cmd+=(--summary-dir "$summary_dir"); fi; if [ -n "$vrt_summary_dir" ]; then cmd+=(--vrt-summary-dir "$vrt_summary_dir"); fi; if [ "$#" -gt 0 ]; then cmd+=(-- "$@"); fi; "${cmd[@]}"' -- {{ task_id }} {{ report_path }} {{ summary_dir }} {{ vrt_summary_dir }} {{ args }}

# Run tests using flaker for a single task
flaker-task-run task_id *args:
    node scripts/flaker-entry.ts task run {{ task_id }} {{ args }}

# Render task-scoped flaker eval/reason summary
flaker-task-summary task_id output_dir=".flaker/task-summary":
    mkdir -p {{ output_dir }}
    node scripts/flaker-task-summary.ts --task {{ task_id }} --json {{ output_dir }}/{{ task_id }}.json --markdown {{ output_dir }}/{{ task_id }}.md | tee {{ output_dir }}/{{ task_id }}.log

# Render full-batch plan for scheduled flaker runs
flaker-batch-plan output_dir=".flaker/batch-plan" tasks="" nodes="":
    mkdir -p {{ output_dir }}
    if [ -n "{{ tasks }}" ] && [ -n "{{ nodes }}" ]; then node scripts/flaker-batch-plan.ts --tasks {{ tasks }} --nodes {{ nodes }} --json {{ output_dir }}/plan.json --markdown {{ output_dir }}/plan.md | tee {{ output_dir }}/plan.log; elif [ -n "{{ tasks }}" ]; then node scripts/flaker-batch-plan.ts --tasks {{ tasks }} --json {{ output_dir }}/plan.json --markdown {{ output_dir }}/plan.md | tee {{ output_dir }}/plan.log; elif [ -n "{{ nodes }}" ]; then node scripts/flaker-batch-plan.ts --nodes {{ nodes }} --json {{ output_dir }}/plan.json --markdown {{ output_dir }}/plan.md | tee {{ output_dir }}/plan.log; else node scripts/flaker-batch-plan.ts --json {{ output_dir }}/plan.json --markdown {{ output_dir }}/plan.md | tee {{ output_dir }}/plan.log; fi

# Aggregate full-batch flaker artifacts
flaker-batch-summary input_dir output_dir=".flaker/batch-summary" collect_task_id="":
    mkdir -p {{ output_dir }}
    if [ -n "{{ collect_task_id }}" ]; then node scripts/flaker-batch-summary.ts --input {{ input_dir }} --collect-task-id {{ collect_task_id }} --json {{ output_dir }}/summary.json --markdown {{ output_dir }}/summary.md; else node scripts/flaker-batch-summary.ts --input {{ input_dir }} --json {{ output_dir }}/summary.json --markdown {{ output_dir }}/summary.md; fi | tee {{ output_dir }}/summary.log

# Render flaker config summary for CI or local inspection
flaker-report output_dir=".flaker/report":
    mkdir -p {{ output_dir }}
    node scripts/flaker-entry.ts config report {{ output_dir }} | tee {{ output_dir }}/summary.log

# Validate tracked flaker quarantine entries
flaker-quarantine-check:
    node scripts/flaker-entry.ts quarantine check

# Render flaker quarantine summary for CI or local inspection
flaker-quarantine-report output_dir=".flaker/quarantine":
    mkdir -p {{ output_dir }}
    node scripts/flaker-entry.ts quarantine report {{ output_dir }} | tee {{ output_dir }}/quarantine.log

# Render upstream ownership inventory for flaker/crater boundaries
flaker-upstream-inventory output_dir=".flaker/upstream":
    mkdir -p {{ output_dir }}
    node scripts/flaker-entry.ts upstream inventory {{ output_dir }} | tee {{ output_dir }}/inventory.log

# Stage one ready-to-upstream group into an export directory
flaker-upstream-export group output_dir=".flaker/upstream-export":
    mkdir -p {{ output_dir }}
    node scripts/flaker-entry.ts upstream export {{ group }} {{ output_dir }} | tee {{ output_dir }}/{{ group }}.log

# Normalize a Playwright JSON report into JSON/Markdown summary
playwright-report-summary input label output_dir=".playwright-report" collect_task_id="":
    mkdir -p {{ output_dir }}
    if [ -n "{{ collect_task_id }}" ]; then npx tsx scripts/playwright-report-summary.ts --input {{ input }} --label {{ label }} --collect-task-id {{ collect_task_id }} --json {{ output_dir }}/{{ label }}.json --markdown {{ output_dir }}/{{ label }}.md; else npx tsx scripts/playwright-report-summary.ts --input {{ input }} --label {{ label }} --json {{ output_dir }}/{{ label }}.json --markdown {{ output_dir }}/{{ label }}.md; fi | tee {{ output_dir }}/{{ label }}.log

# Compare normalized Playwright summaries against a baseline
playwright-report-diff base_input head_input label output_dir=".playwright-report":
    mkdir -p {{ output_dir }}
    npx tsx scripts/playwright-report-diff.ts --base {{ base_input }} --head {{ head_input }} --label {{ label }} --json {{ output_dir }}/{{ label }}-diff.json --markdown {{ output_dir }}/{{ label }}-diff.md | tee {{ output_dir }}/{{ label }}-diff.log

# Summarize a WPT VRT shard result JSON
wpt-vrt-report input label output_dir="wpt-vrt-summary" collect_task_id="":
    mkdir -p {{ output_dir }}
    if [ -n "{{ collect_task_id }}" ]; then npx tsx scripts/wpt-vrt-summary.ts --input {{ input }} --label {{ label }} --collect-task-id {{ collect_task_id }} --json {{ output_dir }}/{{ label }}.json --markdown {{ output_dir }}/{{ label }}.md; else npx tsx scripts/wpt-vrt-summary.ts --input {{ input }} --label {{ label }} --json {{ output_dir }}/{{ label }}.json --markdown {{ output_dir }}/{{ label }}.md; fi | tee {{ output_dir }}/{{ label }}.log

# Aggregate WPT VRT shard summaries
wpt-vrt-report-aggregate input_dir output_dir="wpt-vrt-summary" collect_task_id="":
    mkdir -p {{ output_dir }}
    if [ -n "{{ collect_task_id }}" ]; then npx tsx scripts/wpt-vrt-summary.ts --aggregate {{ input_dir }} --collect-task-id {{ collect_task_id }} --json {{ output_dir }}/wpt-vrt-summary.json --markdown {{ output_dir }}/wpt-vrt-summary.md; else npx tsx scripts/wpt-vrt-summary.ts --aggregate {{ input_dir }} --json {{ output_dir }}/wpt-vrt-summary.json --markdown {{ output_dir }}/wpt-vrt-summary.md; fi | tee {{ output_dir }}/wpt-vrt-summary.log

# Aggregate VRT artifact report.json files under an output directory
vrt-report-summary input_dir label="vrt-artifacts" output_dir="vrt-report-summary" collect_task_id="":
    mkdir -p {{ output_dir }}
    if [ -n "{{ collect_task_id }}" ]; then node --import tsx scripts/vrt-report-summary.ts --input {{ input_dir }} --label {{ label }} --collect-task-id {{ collect_task_id }} --json {{ output_dir }}/{{ label }}.json --markdown {{ output_dir }}/{{ label }}.md; else node --import tsx scripts/vrt-report-summary.ts --input {{ input_dir }} --label {{ label }} --json {{ output_dir }}/{{ label }}.json --markdown {{ output_dir }}/{{ label }}.md; fi | tee {{ output_dir }}/{{ label }}.log

# Regenerate the local current paint VRT summary while ignoring stale WPT/url scratch reports
paint-vrt-current-summary input_dir="output/playwright/vrt" output_prefix="output/playwright/vrt-current-summary":
    node --import tsx scripts/vrt-report-summary.ts --input {{ input_dir }} --label paint-vrt-current --include-task-id paint-vrt --include-task-id paint-vrt-font-fallback --include-task-id paint-vrt-gradients --include-task-id paint-vrt-svg-intrinsic --exclude-filter wikipedia --json {{ output_prefix }}.json --markdown {{ output_prefix }}.md

# Check that the local current paint VRT summary is newer than all selected report.json files
paint-vrt-current-summary-check input_dir="output/playwright/vrt" output_prefix="output/playwright/vrt-current-summary":
    node --import tsx scripts/vrt-report-summary.ts --input {{ input_dir }} --label paint-vrt-current --include-task-id paint-vrt --include-task-id paint-vrt-font-fallback --include-task-id paint-vrt-gradients --include-task-id paint-vrt-svg-intrinsic --exclude-filter wikipedia --json {{ output_prefix }}.json --markdown {{ output_prefix }}.md --check-fresh

# Capture a live site into real-world/ (gitignored)
capture-realworld *args:
    pnpm capture:realworld -- {{ args }}

# Run real-world paint benchmark against Chromium and Crater
bench-realworld *args:
    pnpm bench:realworld -- {{ args }}

# Run all Playwright-based tests
test-playwright-all: test-playwright test-playwright-adapter test-website

# Run BiDi manual tests (Python, requires BiDi server to be running)
test-bidi-manual:
    uv run --no-project scripts/test-bidi-manual.py

# === Build ===

# Build JS module
build-js:
    moon -C js build --target js --release

# Build JS module for WASM-GC
build-js-wasm:
    moon -C js build --target wasm-gc --release

# Build WASM component
build-wasm:
    moon -C wasm build --target wasm --release
    wasm-tools component embed --world crater wasm/wit wasm/_build/wasm/release/build/mizchi/crater-wasm/gen/gen.wasm -o wasm/_build/crater-embedded.wasm
    wasm-tools component new wasm/_build/crater-embedded.wasm -o wasm/_build/crater.wasm

# Transpile WASM with jco
transpile-wasm:
    npx jco transpile wasm/_build/crater.wasm -o wasm/dist --name crater

# Test transpiled WASM component from Node/JCO
test-wasm:
    node --test wasm/test/component.test.mjs

# Full WASM build pipeline
wasm: build-wasm transpile-wasm test-wasm

# === Release ===

# Print the Moon publish plan for public workspace modules
release-moon-list:
    node scripts/moon-publish-workspace.mjs --list

# Run moon check in dependency order for public workspace modules
release-moon-check:
    node scripts/moon-publish-workspace.mjs --check

# Run moon publish --dry-run in dependency order for public workspace modules
release-moon-dry-run:
    node scripts/moon-publish-workspace.mjs --dry-run

# Publish public workspace modules in dependency order
release-moon:
    node scripts/moon-publish-workspace.mjs --publish

# === Utilities ===

# Clean build artifacts
clean:
    moon clean
    moon -C browser clean
    moon -C js clean
