mjdi

Search documentation

Search the mjdi v0.10.0 documentation

mjdi docsv0.10.0latest

Playground (P2-13)

The playground is the website's guided tour of mjdi: four

Source: mjdi/docs/playground.md

The playground is the website's guided tour of mjdi: four verified example presets, each shown through five views — dependency declarations, registry composition (provider and lifetime per registration), the exported dependency graph, the exact runtime output, and what the compiler does when the wiring is broken.

The provenance contract

The playground never compiles or executes code on the server. Every byte it shows is precomputed at release time by the real toolchain and frozen into website/public/graph-fixtures/playground/artifacts.json (mjdi.playground/1 schema). The provenance banner on the page states the mjdi version, the compiler version, and the generation date, and every artifact carries the same fields:

ViewSource
Dependency declarationsthe example's real source (examples/<name>/app.mojo), read at request time from the repository
Registry compositionthe mjdi.graph/1 export of the same registrations (tools/playground_export.mojo)
Dependency graphgraph_json[registry]() and graph_dot[registry]() output, frozen at release time
Verified outputthe example's printed output captured by the generator — the same bytes the test runner's golden check pins
Validationa compile-fail fixture's source, the pinned expected fragment from scripts/run_tests.sh, and the real compiler's captured rejection

The generator verifies its own output before publishing: each preset's graph must parse as mjdi.graph/1, each captured output must not be an error, and each compiler rejection must contain the pinned fragment — so the playground cannot drift into wishful claims.

Presets

  • basic_wiring — the smallest complete wiring (two class providers, one Inject edge).
  • keyed_providers — one service type selected by two compile-time key types (P2-01/P2-02).
  • scope_hierarchy — named request scopes, child scopes, and the copy-inherit ownership rule (P2-10).
  • assisted_reports — assisted injection: the caller supplies one runtime parameter (P2-07).

Each preset names the runnable example it mirrors; run it locally with mojo run -I . examples/<name>/app.mojo.

Regenerating the artifacts

At release time, with the pixi toolchain built:

python3 scripts/export_playground_artifacts.py

The script runs tools/playground_export.mojo (per preset, JSON + DOT), runs each example application, compiles each validation fixture, checks every result against its pinned expectation, and writes the artifact. Regenerate after changing any example, registration, or diagnostic, and commit the refreshed artifacts.json — the playground is versioned with the release that produced it.

Why no live compilation?

Serving an interactive compiler requires a secure, isolated sandbox for untrusted Mojo source. mjdi's documentation infrastructure does not operate one, so the playground makes no such claim: it shows verified, frozen output and says so on the page. If a sandboxed compiler becomes available to this site later, the provenance contract above is the thing to update first.