{"id":"jannik-ritter/checkpoint","name":"checkpoint","scope":"jannik-ritter","platform":"roblox","description":"End-to-end tests for Rojo-synced Luau games, run inside a real Roblox Studio playtest.","version":"0.2.0","latest":"0.2.0","versions":["0.1.0","0.1.1","0.1.2","0.2.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"osyrisrblx/t":{"version":"^3.1.1","alias":"t"}},"integrity":"1e4ab4f537604bef42e9c059f42742a72d675f413061e2e228afb368bd022e74","likes":0,"downloads":0,"install":"forest install jannik-ritter/checkpoint","url":"https://forest.dev/p/roblox/jannik-ritter/checkpoint","files":"https://api.forest.dev/ai/package/roblox/jannik-ritter/checkpoint/files","readme":"# Checkpoint\n\nEnd-to-end tests for Rojo-synced Luau games. Scenarios are Luau modules that run inside a real Roblox Studio playtest; a Lune CLI drives Studio over the Studio MCP, reports each step, sends real mouse and keyboard input when a scenario asks for it, and saves a screenshot and the console log when a step fails.\n\n```text\n$ lune run checkpoint run\nrunning 2 scenario(s) in MyGame\ngame ready\n\ncore/boot  Server and client finish loading, and no module fails to require.\n  ✓ server loaded (server, 4ms)\n  ✓ client loaded (client, 9ms)\n\nshop/buy  Buying an item spends coins once.\n  ✓ open shop (client, 120ms)\n  ✗ coins spent (server, 10003ms)\n      expected coins to be 50 within 10s, last 100\n      .checkpoint/shop-buy--coins-spent.jpg\n      .checkpoint/shop-buy--coins-spent.log\n\n1 passed, 1 failed\n```\n\nOne Wally package holds both halves: the in-game harness (`src/`) and the Lune runner (`runner/`). They always come from the same version.\n\n## Setup\n\nRequirements: [Rokit](https://github.com/rojo-rbx/rokit) with Wally, Rojo and Lune, and Roblox Studio with its MCP server enabled. On Windows and from WSL the runner starts Studio's MCP (`%LOCALAPPDATA%\\Roblox\\mcp.bat`) through `cmd.exe`; elsewhere, or for another MCP, pass its command with `--mcp` or `CHECKPOINT_MCP`.\n\n1. Add the package as a dev dependency and install it:\n\n   ```toml\n   # wally.toml\n   [dev-dependencies]\n   checkpoint = \"jannik-ritter/checkpoint@0.2.0\"\n   ```\n\n   ```bash\n   rokit add lune-org/lune\n   wally install\n   ```\n\n   Dev dependencies install into `DevPackages/`, apart from the game's `Packages/`.\n\n2. Copy the templates from `DevPackages/_Index/jannik-ritter_checkpoint@<version>/checkpoint/templates/` into the project root:\n\n   - `.lune/checkpoint.luau`: the shim behind `lune run checkpoint`. It finds the installed version, so it never needs editing.\n   - `tests/adapter.luau` and `tests/core/boot.luau`: a starting adapter and scenario.\n\n3. For type checking, map `DevPackages` in `default.project.json` so luau-lsp can follow Wally's link files. This syncs the package into the place's ServerStorage, where clients never see it and nothing runs:\n\n   ```json\n   \"ServerStorage\": {\n   \t\"DevPackages\": { \"$path\": { \"optional\": \"DevPackages\" } }\n   }\n   ```\n\n   `optional` keeps Rojo working when dev dependencies aren't installed.\n\n4. Optionally copy `skill/` to `.agents/skills/checkpoint/` so coding agents know how to write and run scenarios.\n\n## Running\n\nOpen the game in Studio, sync it with `rojo serve`, and stay in Edit mode. Then:\n\n```bash\nlune run checkpoint list                    # scenarios, grouped by domain\nlune run checkpoint run                     # every scenario\nlune run checkpoint run shop                # a domain, a path (shop/buy) or a name (buy)\nlune run checkpoint run lobby/b lobby/a     # in the order given\nlune run checkpoint run --json              # one JSON event per line, for agents and CI\n```\n\n| Option | |\n| --- | --- |\n| `--studio <name>` | Pick a Studio when several are connected (or `CHECKPOINT_STUDIO`). |\n| `--retries <n>` | Run a failed scenario again up to n times. One that passes on a retry is reported as flaky. |\n| `--bail` | Stop at the first failed scenario. |\n| `--failed` | Run the scenarios that failed last time (`.checkpoint/last-run.json`). |\n| `--isolate` | A fresh playtest for each scenario, instead of one for the run. |\n| `--shuffle`, `--seed <n>` | A random order, to find scenarios that depend on each other. The seed is printed; `--seed` repeats an order. |\n| `--no-sync-check`, `--rojo <url>` | See \"Sync check\" below. |\n| `--mcp <command>` | The Studio MCP command (or `CHECKPOINT_MCP`). |\n| `--timeout <seconds>` | Give up on the whole run after this long (default 600). |\n\nExit codes: 0 all passed (flaky ones included), 1 a scenario failed, 2 the run could not complete (no Studio, another run in progress, a stale sync, a timeout). Failure screenshots, console logs, `ctx.screenshot` images and `last-run.json` go to `.checkpoint/`; add it to `.gitignore`.\n\n### How a run works\n\n1. The runner checks that Studio holds the scripts Rojo serves (the sync check).\n2. It starts a playtest with `StudioTestService:ExecutePlayModeAsync`, whose test args carry the run's config under `checkpoint`.\n3. Into the running server it injects the selected scenarios, the adapter, the helper folders and the dev packages the tests use at `ReplicatedStorage.Checkpoint`, mirroring the project layout, plus a server `Script` and a client harness the server puts in the player's PlayerGui. **Nothing is added to the Edit place**, so a crash, an autosave or a killed run can't leave the harness behind or get it published.\n4. The server waits for the test player and the adapter's `ready` hook on both sides, then runs the scenarios in order and writes progress events to `ServerStorage.CheckpointStatus`. The runner reads the new ones four times a second and answers the harness's requests (input, screenshots, the capture of a failed step).\n5. When the run is done the harness ends the playtest itself with `StudioTestService:EndTest`. If the runner stops polling for 30 s (killed, crashed), the harness ends the playtest too, so Studio always returns to Edit.\n\nA run that finds Studio in a playtest refuses to start unless it is a Checkpoint playtest whose runner has stopped polling, which it then stops. A Checkpoint playtest another runner is still polling is never touched: one run per Studio at a time.\n\n### Game code under test\n\nGame code tells it is under test from the test args, which are there before any script runs:\n\n```luau\nlocal function isTestRun(): boolean\n\tif not RunService:IsStudio() then\n\t\treturn false\n\tend\n\tlocal args = StudioTestService:GetTestArgs() :: any\n\treturn type(args) == \"table\" and args.checkpoint ~= nil\nend\n```\n\nUse it for what must be decided at start-up, such as mock persistence. Everything else belongs in the adapter's `reset`. A normal Play never has these args, so it never runs as a test.\n\n### Sync check\n\nBefore each run the runner reads every script from the Rojo serve (`http://127.0.0.1:34872`, or `--rojo <url>` / `CHECKPOINT_ROJO`) and compares its length and hash with Studio's. If any differ (a serve that died, a disconnected Rojo plugin), the run stops and lists them, instead of testing stale code. When no serve answers, or it serves a model rather than a place, the check is skipped with a note. `--no-sync-check` turns it off.\n\n## Writing tests\n\n```text\ntests/\n\tadapter.luau             hooks: ready, reset\n\t<domain>/<name>.luau     one scenario per module\n\t_<anything>/             helper modules (not scenarios)\n```\n\n### Adapter\n\n```luau\nlocal Checkpoint = require(\"../DevPackages/checkpoint\")\n\nreturn Checkpoint.adapter({\n\t-- Polled on the server and the client until both return true.\n\tready = function(side)\n\t\treturn workspace:GetAttribute(if side == \"server\" then \"ServerLoaded\" else \"ClientLoaded\") == true\n\tend,\n\n\t-- Runs on the server before every scenario: restore a neutral state and apply the scenario's fixture.\n\treset = function(player, fixture) end,\n})\n```\n\n### Scenarios\n\n```luau\n--!strict\nlocal Checkpoint = require(\"../../DevPackages/checkpoint\")\nlocal PlayerData = require(\"@game/ReplicatedStorage/Modules/Shared/PlayerData\")\nlocal RewardData = require(\"@game/ReplicatedStorage/Modules/Data/RewardData\")\n\nlocal t = Checkpoint.t\n\nreturn Checkpoint.scenario({\n\tdescription = \"Claiming the daily reward grants coins once.\",\n\tfixture = { Coins = 0 },\n\tsteps = {\n\t\tCheckpoint.client(\"claim\", function(ctx)\n\t\t\tlocal button = ctx.player.PlayerGui:WaitForChild(\"Daily\"):WaitForChild(\"Claim\")\n\t\t\tctx.click(button) -- a real click, as a player would\n\t\tend),\n\t\tCheckpoint.server(\"coins granted once\", function(ctx)\n\t\t\tctx.poll(function()\n\t\t\t\treturn PlayerData.Server.Get(ctx.player).Coins.Get()\n\t\t\tend, \"coins\"):toBe(100)\n\t\t\tctx.holds(function()\n\t\t\t\treturn PlayerData.Server.Get(ctx.player).Coins.Get()\n\t\t\tend, \"coins\", 2):toBe(100) -- and not granted again\n\t\t\tctx.expect(RewardData.Daily, \"daily reward\"):toMatch(t.interface({ Coins = t.numberPositive }))\n\t\tend),\n\t},\n})\n```\n\n- The relative `require` resolves on disk (luau-lsp) and in Studio (the injected tree mirrors the project), so scenarios are type-checked against Checkpoint and the game.\n- A scenario module loads on both sides. Require side-specific game modules inside the step that uses them.\n- Steps run in order on their side. After a failure the remaining steps are skipped. Each step times out after 30s; pass a third argument to change it. Long steps are fine: the harness reports a heartbeat while they run.\n- There is no sleep: wait for an observable condition with `poll`, `waitFor` or `waitForSignal`, check that something stays true with `holds`, and wait a frame with `nextFrame`.\n\n### The step context (`ctx`)\n\nNamed `ctx` by convention so `t` stays free for the type checker.\n\n| | |\n| --- | --- |\n| `player`, `side` | The test player and the side this step runs on. |\n| `state` | A table shared by the scenario's steps on both sides; it travels with each client step and comes back. Keep to values a RemoteFunction can carry. |\n| `expect(value, label?)` | Checks a value once. |\n| `poll(read, label?, timeout?)` | Retries `read` until the matcher passes (10s by default). |\n| `holds(read, label?, duration?)` | Samples `read` for `duration` (1s by default) and fails as soon as the matcher doesn't pass: \"stays closed\", \"is never granted twice\". |\n| `waitFor(read, label?, timeout?)` | Returns the first truthy value `read` produces. |\n| `waitForSignal(signal, label?, timeout?, predicate?)` | Waits for the signal (with arguments `predicate` accepts) and returns its arguments. |\n| `nextFrame(count?)` | Waits frames. |\n| `click(target, button?)` | Client steps. Clicks a GuiObject through Studio's input, the way a player would; it must be visible and on screen (the step waits up to 5 s for it, then fails saying why). Or a `Vector2` in `AbsolutePosition` space. |\n| `press(key, hold?)`, `keyDown(key)`, `keyUp(key)`, `type(text)` | Client steps. Real keyboard input (an `Enum.KeyCode` or its name). |\n| `screenshot(name)` | Saves a screenshot of the playtest to `.checkpoint/` and returns its path. |\n| `log(...)` | Prints under the step in the report (an event in `--json`): measurements, what a step saw. |\n| `afterStep(fn)` | Runs at the end of this step, pass or fail. |\n| `onCleanup(fn)` | Runs at the end of the scenario, pass or fail, on the side that registered it. |\n\nMatchers: `toBe`, `toEqual`, `toBeTruthy`, `toBeFalsy`, `toBeNil`, `toBeGreaterThan`, `toBeLessThan`, `toBeAtLeast`, `toBeAtMost`, `toBeCloseTo(expected, tolerance?)` (numbers, Vector2, Vector3, CFrame positions), `toContain`, and `toMatch(check)` for any [`t`](https://github.com/osyrisrblx/t) check (`Checkpoint.t`). Every matcher has a negated form: `ctx.expect(window).never:toBe(\"Shop\")`.\n\n- Scenarios and the adapter are validated when they load, so a malformed one fails with a message instead of mid-run. An adapter that fails to load on the client says so.\n- Keep scenarios independent: use `fixture` and the adapter's `reset`, and `onCleanup` for anything else a scenario changes. `--shuffle` finds the ones that aren't; `--isolate` gives each its own playtest.\n\n## Limits\n\n- Real input goes through the Studio window: a click lands on whatever is drawn at that point, and the strip under Roblox's top bar takes no clicks.\n- One player per run.\n- A step that times out is cancelled, but threads it spawned keep running.\n- Runs need a running Studio, so they cannot run on hosted CI.\n\n## Development\n\nSee [AGENTS.md](AGENTS.md). `scripts/install-local.sh <project>` installs the working copy into a game's `DevPackages` to try changes before publishing.\n\n## License\n\nMIT\n","readmeTruncated":false}