Browser host, screenshots, docs, CI, README, LICENSE

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
SpriteandClaude Sonnet 5.5 committed 2026-11-24 23:47:51 +00:00
1 parent e0bde1d150
commit de8abfaa26
17 files changed
+1019 -13

No files matched your search

+35 -12
View File
@@ -5,20 +5,43 @@
# components); each component's export bindings land in components/<n>/gen.
# The first run also writes moon.pkg for each package; later runs pass
# --ignore-stub so hand-edited moon.pkg / stub.mbt files are preserved.
# `scripts/gen-bindings.sh --check` fails if regeneration changes tracked files.
#
# scripts/gen-bindings.sh regenerate in place
# scripts/gen-bindings.sh --check regenerate into a temp dir and fail if the
# committed bindings differ (order-insensitive:
# wit-bindgen 0.63 emits helper fns in varying order)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT"
export PATH="$ROOT/.tools/bin:$PATH"
while read -r name world; do
case "$name" in ''|'#'*) continue;; esac
extra=()
[ -d "components/$name/gen" ] && extra+=(--ignore-stub)
wit-bindgen moonbit wit --world "$world" --out-dir . \
--gen-dir "components/$name/gen" --project-name moonplasma/desktop \
--ignore-module-file "${extra[@]}" >/dev/null 2>"$ROOT/.tools/bindgen.log" || { cat "$ROOT/.tools/bindgen.log" >&2; exit 1; }
echo "bindings: $name ($world)"
done < scripts/components.txt
mkdir -p .tools
log="$ROOT/.tools/bindgen.log"
generate() { # <out-dir> <ignore-stub: 0|1>
local out="$1" ignore="$2" name world extra
while read -r name world; do
case "$name" in ''|'#'*) continue;; esac
extra=(); [ "$ignore" = 1 ] && extra+=(--ignore-stub)
wit-bindgen moonbit wit --world "$world" --out-dir "$out" \
--gen-dir "components/$name/gen" --project-name moonplasma/desktop \
--ignore-module-file "${extra[@]}" >/dev/null 2>"$log" || { cat "$log" >&2; exit 1; }
done < scripts/components.txt
}
if [ "${1:-}" = "--check" ]; then
git diff --exit-code -- interface world components '*/gen/*' \
|| { echo "error: generated bindings are stale; run scripts/gen-bindings.sh and commit" >&2; exit 1; }
tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT
generate "$tmp" 0
bad=0
while IFS= read -r f; do
rel="${f#"$tmp"/}"
case "$rel" in */moon.pkg|*/README.md) continue;; esac # hand-edited / docs
if [ ! -f "$rel" ] || ! diff -q <(sort "$f") <(sort "$rel") >/dev/null; then
echo "stale binding: $rel" >&2; bad=1
fi
done < <(find "$tmp" -type f)
[ "$bad" = 0 ] || { echo "error: bindings differ from wit/; run scripts/gen-bindings.sh and commit" >&2; exit 1; }
echo "bindings up to date"
else
first=0; [ -d components/shell/gen ] || first=1
generate . $((1 - first))
echo "bindings regenerated"
fi
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env node
// Drive the browser host with headless Chromium and save PNG screenshots.
// CHROME_PATH=/path/to/chrome node scripts/screenshot.mjs <outdir> [--tag name]
// Uses playwright-core (devDependency of host/) with an already-installed
// Chromium; nothing is downloaded here.
import { mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import { serve } from '../host/serve.mjs';
const require = createRequire(join(fileURLToPath(import.meta.url), '..', '..', 'host', 'package.json'));
const { chromium } = require('playwright-core');
const outdir = process.argv[2];
if (!outdir) { console.error('usage: screenshot.mjs <outdir> [--tag name]'); process.exit(2); }
const tagI = process.argv.indexOf('--tag');
const tag = tagI > 0 ? process.argv[tagI + 1] : 'desktop';
const exe = process.env.CHROME_PATH;
if (!exe) { console.error('error: set CHROME_PATH to a Chromium/Chrome executable'); process.exit(2); }
await mkdir(outdir, { recursive: true });
const srv = await serve(0);
const url = `http://127.0.0.1:${srv.address().port}/host/web/index.html`;
const browser = await chromium.launch({ executablePath: exe, args: ['--no-sandbox'] });
const page = await browser.newPage({ viewport: { width: 1280, height: 748 } });
const errors = [];
page.on('pageerror', (e) => errors.push(String(e)));
page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });
const T = 'time=2026-11-24T14:07:37';
const shot = async (name, query, steps) => {
await page.goto(`${url}?${T}&${query}`);
await page.waitForFunction(() => window.moonPlasma?.ready || window.moonPlasmaError, null, { timeout: 30000 });
const err = await page.evaluate(() => window.moonPlasmaError);
if (err) throw new Error(`host failed in browser: ${err}`);
if (steps) await steps();
const f = join(outdir, `${tag}-${name}.png`);
await page.locator('#screen').screenshot({ path: f });
console.log(f);
};
const canvasPoint = async (x, y) => { const b = await page.locator('#screen').boundingBox(); return [b.x + x, b.y + y]; };
const click = async (x, y) => { const [px, py] = await canvasPoint(x, y); await page.mouse.move(px, py); await page.mouse.down(); await page.mouse.up(); };
await shot('1-desktop', 'config=desktop.json');
await shot('2-launcher-open', 'config=desktop.json', async () => {
await click(60, 700);
await page.keyboard.type('s');
const [px, py] = await canvasPoint(100, 450); await page.mouse.move(px, py);
});
await shot('3-binary-clock-swapped', 'config=desktop.json', async () => {
await page.evaluate(() => window.moonPlasma.swap('clock', 'clock-binary'));
});
await shot('4-day-theme', 'config=desktop.json&theme=moon-day', async () => { await click(60, 700); });
await browser.close(); srv.close();
if (errors.length) { console.error('browser errors:\n' + errors.join('\n')); process.exit(1); }
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Full verification, identical to CI:
# WIT parses -> bindings are fresh -> moon check/test (pure logic) ->
# build all components -> conformance -> host integration tests.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT"
export PATH="$ROOT/.tools/bin:$HOME/.moon/bin:$PATH"
step() { printf '\n== %s\n' "$*"; }
step "bindings are in sync with wit/"
scripts/gen-bindings.sh --check
step "moon check"
moon check
step "moon test (pure logic, wasm target)"
moon test
step "build components"
scripts/build.sh
if command -v wasmtime >/dev/null; then
step "wasmtime accepts every component (compile only; hosts supply the imports)"
for f in build/components/*.wasm; do
wasmtime compile "$f" -o "$(mktemp -u).cwasm" >/dev/null && echo " ok $(basename "$f")"
done
fi
step "host integration tests (jco + Node)"
(cd host && npm test)