Scenario compiler

How .molar.md scenarios are validated, compiled, and executed — P1 verbs and deterministic Playwright output.

Scenario compiler

The scenario compiler (@molar/scenario-spec) validates .molar.md files, resolves clone legs, and emits deterministic Playwright .spec.ts artifacts.

Commands

molar scenarios validate   # lint frontmatter + step grammar
molar scenarios compile      # write .molar/scenarios/*.spec.ts (gitignored)

Validation runs in CI and locally. Compilation is content-hash keyed — the same scenario always produces the same Playwright output for a given compiler version.

File format

Each scenario is a Markdown file with YAML frontmatter:

---
spec_version: '1.0'
id: '019301c0-cafe-7000-bea7-000000000001'
slug: checkout-happy-path
description: User completes checkout
priority: medium
tags: [smoke]
clones:
  - { kind: stripe, seed: stripe-base }
---

# Checkout

## Steps

1. Navigate to /checkout
2. Click "Pay now"
3. Wait for webhook stripe.checkout.session.completed {timeout: 30s}
4. Assert text "Thank you" is visible

Project-level config lives in repo-root .molar.md.

P1 verbs (shipped)

These verbs compile to Playwright today:

VerbPurpose
navigateGo to a path or URL
fillFill an input
clickClick an element
assertText/visibility/state assertion
waitFixed delay or condition
snapshotDOM snapshot checkpoint
screenshotCapture screenshot
inject_errorInject fault (chaos testing)
advance_clockAdvance clone virtual clock
requestHTTP request (API-only scenarios)
debugDebugger breakpoint

P2 verbs (hover, select, drag, upload, etc.) fail validation with MOLAR_S001 until the compiler ships them.

Frontmatter schema

Required keys: spec_version (must be '1.0'), id (UUIDv7), slug, description.

Optional: priority, tags, clones, schedule (Guard production), shadow_prod, mender.mode.

Unknown frontmatter keys are rejected (MOLAR_S004).

Clone integration

Clone declarations in frontmatter tell Guard and the runtime which vendor simulators to start. Setup steps can reset clone state before assertions.

See Clones scenario integration.

MCP equivalents

CLIMCP
molar scenarios validatemolar_validate_scenario
molar scenarios compilemolar_compile_scenario