Skip to content

Migrate Java execution from Docker to CheerpJ (browser-side) - #1

Merged
Prorickey merged 2 commits into
mainfrom
feat/browser-jvm
Mar 2, 2026
Merged

Migrate Java execution from Docker to CheerpJ (browser-side)#1
Prorickey merged 2 commits into
mainfrom
feat/browser-jvm

Conversation

@Prorickey

Copy link
Copy Markdown
Owner

Summary

  • Replace Docker sandbox with CheerpJ 3.0 — Java now compiles and runs entirely in the browser via a WASM JVM. Zero server-side containers, no rate limiting needed, scales infinitely.
  • Remove auth gate on Run button — anyone can run code now that execution is free; analytics still require a session.
  • Expose testCode to clientTest.java is included in LessonData so the browser executor can pass it to javac/CheerpJ.
  • New analytics endpointPOST /api/analytics/run records code_run and exercise_complete events after browser-side execution completes.
  • Build scriptscripts/build-cheerpj-assets.sh compiles ftc-stubs.jar (Java 8 target) and downloads OpenJDK 8 tools.jar (contains javac); run with bun run build:cheerpj.

Architecture

Before: Student clicks Run → POST /api/execute → Docker container → javac + java → JSON
After:  Student clicks Run → CheerpJ (WASM JVM in browser) → javac + java → JSON → POST /api/analytics/run

Timing profile (measured):

Phase Cold (1st click) Warm (2nd click)
CheerpJ init ~3–8s (background, while reading) 0ms
javac compile ~5.3s ~1.7s
Test execution ~700ms ~700ms

The main cold-start cost is javac lazy-loading classes from tools.jar (18MB) over the network. Subsequent runs in the same session are ~3x faster.

Files removed

  • lib/compiler.ts, lib/docker.ts — Docker orchestration
  • app/api/execute/route.ts — server-side execution endpoint
  • tests/sandbox.test.ts — Docker integration tests (replaced by Playwright browser tests)

Test plan

  • Run bun run build:cheerpj — verify public/cheerpj/ftc-stubs.jar and public/cheerpj/tools.jar are created
  • bun dev → open a lesson → click Run with starter code → verify failing test results appear (~6s)
  • Click Run again → verify faster response (~2s, warm)
  • Modify code to be invalid Java → verify compilation error displayed
  • Use solution code → verify all tests pass with "All passing" badge
  • Verify Run button is visible without signing in
  • Run npx playwright test tests/cheerpj-browser.test.ts — all 8 tests pass

🤖 Generated with Claude Code

Prorickey and others added 2 commits March 2, 2026 17:44
Replaces the server-side Docker sandbox with CheerpJ 3.0, a WASM-based
JVM that compiles and runs Java entirely in the browser. Students no
longer consume server resources when clicking Run — zero containers, no
rate limiting needed.

Key changes:
- Add CheerpJProvider context (loads runtime from CDN, calls cheerpjInit)
- Add cheerpj-executor: writes .java files to CheerpJ VFS, invokes javac
  via cheerpjRunMain, captures System.out via console.log interception,
  parses JSON test results from TestBase.printResults()
- Expose Test.java to client: add testCode field to LessonData/getLessonData
- Remove auth gate on Run button — execution is now free for all users
- Add POST /api/analytics/run to record code_run / exercise_complete events
- Add scripts/build-cheerpj-assets.sh: compiles ftc-stubs.jar (Java 8
  target) and downloads OpenJDK 8 tools.jar (contains javac)
- Remove lib/docker.ts, lib/compiler.ts, app/api/execute/route.ts
- Remove dockerode dependency and serverExternalPackages entry
- Add Playwright browser tests (8 tests, all passing in ~56s)

Timing profile: cold compile ~5s, warm compile ~1.7s, test run ~700ms.
The main cost is javac lazy-loading classes from tools.jar (18MB) on
first use; subsequent runs in the same session are 3x faster.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
bun test picked up the Playwright test file and crashed because
test.setTimeout() is a Playwright-only API. Moving browser tests to
e2e/ keeps them separate from the bun test runner.

- Move tests/cheerpj-browser.test.ts → e2e/cheerpj-browser.test.ts
- Add test:e2e script (playwright test e2e/)
- Replace CI workflow: drop Docker sandbox build, run tsc + eslint instead
  (execution tests are browser-side and don't run in CI without a display)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Prorickey
Prorickey merged commit cffc9cf into main Mar 2, 2026
2 checks passed
@Prorickey
Prorickey deleted the feat/browser-jvm branch March 2, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant