Repository navigation
R5: simulator CLI, worker-backed web host, real Electron shell - #22
Open
CodeByBryant wants to merge 1 commit into
Open
CodeByBryant wants to merge 1 commit into
CodeByBryant wants to merge 1 commit into
Conversation
…l (R5) Three apps, each testable on its own. apps/simulator-cli: `pnpm sim --seed N --ticks N [--config f] [--save f | --load f] [--json | --summary]`. run(argv, io) is a pure function over an injected Io (37 tests, mutation-checked). Prints the 32-char state hash by default; --config reproduces a pinned scenario. The real binary reproduces a golden hash, round-trips through real files, and uses the documented exit codes (0 ok, 1 failed, 2 usage). Running it found a bug in-process tests could not: pnpm forwards a literal "--". apps/web: MapView no longer hand-assembles a world. SimulationHost runs World in a worker (world.worker.ts); readyMessage.ts builds the message as a pure function, sending COPIES of tile layers so the worker keeps its World, and transferring only buffers made for the occasion (a structuredClone-with-transfer test proves the world survives). The host takes an injected worker (21 tests). Generation failure now returns to the title screen instead of hanging. Nations are the contract's NationSnapshot. Verified identical to R4: 0 differing map pixels in all 7 states, identical hover/click results. The real worker's hash for a full 2000x2000 seed-1337 world equals the CLI's: 6b461ddd6eb60e50262f93eca686be6a. apps/desktop: real Electron shell (CJS main/preload, contextIsolation, no Node in the page, navigation and window.open locked to the app via pure, tested helpers). Launched under Xvfb and driven over CDP: loads the web build, generates a world, blocks navigation to the web and to other files. electron-builder packs the web build as resources/web; the unpacked package was built and run (found and fixed an executable name of "@sovereigndesktop"). release.yml ported to pnpm (YAML validated; not run here). Also fixes the last MapView hooks lint warning; lint is now warning-free. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cn5qp59UwGNst3umuaQf6u
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Sixth PR of the restructure stack, stacked on #21 (R4). Merge bottom-up; retarget to
mainonce the PRs below it merge.Makes the three apps real: a headless CLI, a web app whose simulation lives in a worker behind a testable host, and a working Electron shell. This closes the restructure's key exit criterion: the same seed produces the same hash in Node, in the worker, and in the CLI.
Stack: #17 R0 → #18 R1 → #19 R2 → #20 R3 → #21 R4 → R5 (this PR) → R6 tests/CI → R7 docs.
Changes
apps/simulator-clipnpm sim --seed N --ticks N [--config f.json] [--save f | --load f] [--json | --summary] [--validate].run(argv, io)is a pure function over an injectedIo(37 tests). It prints the state hash by default;--configreproduces a pinned scenario from the golden file; exit codes are 0 ok, 1 request failed (invalid config, bad save), 2 usage error. Errors are one clean line, never a stack trace.apps/webMapViewno longer assembles a world by hand.SimulationHostrunsWorldin a worker (world.worker.ts); the host takes an injected worker, so it is tested with a fake (21 tests).readyMessage.tsbuilds the worker→app message as a pure function. Design point: the worker must keep itsWorld(later phases step it there), so it sends copies of the tile layers and transfers only buffers made for the occasion. A test runs the message throughstructuredClonewith transfer and shows the sender's buffers are detached while the world still hashes, validates and steps.NationSnapshot(the UI never needed the engine class).apps/desktopA real Electron shell (CJS main/preload,
contextIsolation, no Node in the page). The window may show only the app: navigation to the web or to any other file, andwindow.open, are blocked through pure, tested helpers (isAppUrl,resolveWebEntry, with injectable path rules so Windows paths are tested on Linux).electron-builderships the web build asresources/web.Workflows
release.ymlported from the old npm scripts to a pnpm matrix job (Windows/Linux/macOS).Verification
SimulationHostin Chromium hashes to6b461ddd6eb60e50262f93eca686be6a, identical to the CLI's (Node 22). The same run showed an invalid config rejected cleanly and the host reusable afterwards.World.createinside the worker.08009323…from the golden config, saves and loads through real files, uses the documented exit codes, 2000×2000 in 4.6 s.window.sovereignis exposed, norequire/processin the page, the world generates (the module worker works fromfile://, which I had specifically worried about), no console errors; navigation tohttps://example.com, tofile:///etc/hostnameandwindow.openare all blocked while the app stays responsive.electron-builder --dir, then launched fromrelease/linux-unpacked/: it loadsresources/web/index.html(the packaged branch of the path logic) and generates a world.pnpm buildpasses.Bugs this verification found (and that unit tests could not)
pnpm start -- --seed 1: pnpm forwards the literal--and my parser treated it as an unknown option. Fixed with a test-first change (a bare--means "end of options").@sovereigndesktop(from the scoped package name). Windows already setexecutableName; Linux now does too.Known and intentional
nsis,dmg) and therelease.ymlworkflow itself. I can't run GitHub Actions or those OSes here; the YAML is syntax-checked and the Linux unpacked build was exercised. Treat the first real release run as the test.--no-sandbox --disable-gpuunder Xvfb (the container has neither a display nor a GPU), so WebGL ran in software; the shipped app does not pass--no-sandboxand setssandbox: trueon the window.file://. That worked, including the worker; a customapp://protocol would be the next hardening step if remote content is ever introduced.electron-updaterwas an unused dependency in the original; removed in R0).SimulationHostexposescreateandhashonly; stepping and time controls arrive with the first simulation systems (roadmap Phase 3).Related Issues
Part of the R0-R7 restructure stack.
Type of Change
Checklist
pnpm build)pnpm lint, now with zero warnings)pnpm typecheck)Generated by Claude Code