Add web game (plan2.md) on the independent runtime, merge-blocking gates
Builds the browser game around the existing Rust runtime: a window into the universe, not a second simulation. Pure std, no external crates. New crates: - protocol: versioned, hashable client/server messages + hand-rolled JSON value and total parser (malformed packet -> Err, never panic). - game_runtime: authoritative match state. Resolves turns through the INDEPENDENT interpreter (runtime_under_test::native_resolve), not the reference engine; filters visibility/knowledge; records and regenerates replays. A match is a pure function of (seed, roster, ordered inputs). - web_assets/web_client: embedded browser client (arena, rune editor, knowledge panels, replay viewer) + static HTTP delivery. - server: std::net HTTP + WebSocket (hand-rolled SHA-1/base64/RFC-6455 framing), turn timer, disconnect handling, panic-proof dispatch, poison-tolerant lock. - web_tests: dependency-free WebSocket test client + Phase H gates. Trust hardening per review: - game_runtime no longer delegates to reference_runtime::execute; it runs the independent interpreter that the runtime-equivalence gate proves correct. - Protocol/socket/replay/visibility/resilience gates are merge-blocking (added to the merge_group-required job in merge-gates.yml): 1k matches/0 drift, 10k fuzz/0 panics, 100 headless socket E2E, 0 hidden-state leaks. - Rendered-browser E2E is marked EXTERNAL-BLOCKED: Playwright runs advisory-only (continue-on-error, artifacts) until CI infrastructure with a browser exists; it is treated as unsatisfied, not green. The headless 100-match gate is labeled protocol-level coverage, not rendered-browser coverage. - README documents the hand-rolled crypto/parser audit risk explicitly. Fixes an integer-overflow panic in observed-volatility inference (i64 sum / abs near i64::MIN) that could poison the server mutex. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "magicka-web-e2e",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Playwright rendered-browser E2E for the Magicka VM web game.",
|
||||
"scripts": {
|
||||
"test": "playwright test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.40.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// Playwright config for the rendered-browser E2E layer. This complements the
|
||||
// headless Rust protocol E2E in `crates/web_tests/tests/e2e.rs`: here a real
|
||||
// Chromium drives the actual DOM client. It boots the real server (short turns)
|
||||
// via `webServer` so `npm test` is self-contained.
|
||||
//
|
||||
// Requires Node + `npx playwright install chromium`. The Rust CI gates do not
|
||||
// depend on this; it is the optional rendered-browser proof.
|
||||
|
||||
const { defineConfig } = require("@playwright/test");
|
||||
|
||||
module.exports = defineConfig({
|
||||
testDir: "./specs",
|
||||
timeout: 30000,
|
||||
expect: { timeout: 10000 },
|
||||
use: {
|
||||
baseURL: "http://127.0.0.1:8099",
|
||||
headless: true,
|
||||
},
|
||||
webServer: {
|
||||
// Build once, then run the server with fast turns for E2E.
|
||||
command: "cargo run --release -p server --bin magicka-server",
|
||||
cwd: "../../..",
|
||||
env: { MAGICKA_ADDR: "127.0.0.1:8099", MAGICKA_TURN_MS: "1500" },
|
||||
url: "http://127.0.0.1:8099/",
|
||||
reuseExistingServer: true,
|
||||
timeout: 120000,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
// Rendered-browser E2E: a real Chromium joins a match, the turn timer runs, the
|
||||
// player edits + saves a rune program, casts, sees filtered results, and replays
|
||||
// the match — verifying the recorded replay hashes match what was seen live.
|
||||
//
|
||||
// This is the browser layer of plan2.md Phase H ("Playwright end-to-end tests").
|
||||
|
||||
const { test, expect } = require("@playwright/test");
|
||||
|
||||
test("a player can join, cast, and replay a browser match", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
|
||||
// Connects to the authoritative server.
|
||||
await expect(page.locator("#conn")).toHaveText("connected", { timeout: 10000 });
|
||||
|
||||
// The turn timer is running (header shows a turn + countdown).
|
||||
await expect(page.locator("#timer")).toContainText("turn", { timeout: 10000 });
|
||||
|
||||
// The arena rendered with the player's marker.
|
||||
await expect(page.locator(".cell.self")).toHaveCount(1, { timeout: 10000 });
|
||||
|
||||
// Domains panel shows the hidden-state redaction notice (visibility layer).
|
||||
await expect(page.locator("#redactions")).toContainText("withheld", { timeout: 10000 });
|
||||
|
||||
// Edit a rune program: add a couple of runes and save.
|
||||
await page.fill("#tok-a", "1");
|
||||
await page.fill("#tok-b", "2");
|
||||
await page.click("#btn-add");
|
||||
await page.click("#btn-add");
|
||||
await page.click("#btn-save");
|
||||
// Observed diagnostics appear (names/counts only).
|
||||
await expect(page.locator("#diag-body")).toContainText("known reads", { timeout: 10000 });
|
||||
|
||||
// Cast and wait for a resolved-turn log line.
|
||||
await page.click("#btn-cast");
|
||||
await expect(page.locator("#log")).toContainText("cast a rune program", { timeout: 15000 });
|
||||
|
||||
// Request and step the replay; the client verifies hashes vs. what it saw live.
|
||||
await page.click("#btn-replay");
|
||||
await expect(page.locator("#replay-status")).toContainText("replay loaded", { timeout: 10000 });
|
||||
await page.click("#btn-replay-step");
|
||||
// A matching hash line is shown (no MISMATCH).
|
||||
await expect(page.locator(".hash-bad")).toHaveCount(0);
|
||||
});
|
||||
Reference in New Issue
Block a user