# Continuous integration for a MysteryForge game

Every game carries its own check suite, so a studio gets the same safety net the engine's authors have: **a broken door, a
puzzle that cannot be won, a way to make the game unwinnable, a picture that no longer fits in memory, or a screen that falls
apart in German is caught on the push that caused it — not by a tester in week eleven.**

Two files do it, both written into a new game by `create_game` (and refreshed by `upgrade_engine`, which owns `tools/`):

| file | what it is |
|---|---|
| `tools/check.sh` | the suite. Run it by hand, from a git hook, or from CI. |
| `.github/workflows/mysteryforge.yml` | a ready workflow (GitHub Actions; Gitea and Forgejo read the same syntax) copied from `tools/ci/github.yml`. |

## What the suite proves

```bash
bash tools/check.sh                      # everything
SKIP="fuzz lint" bash tools/check.sh     # leave steps out (e.g. SKIP=autoplay for a game that needs the case board)
LENIENT=1 bash tools/check.sh            # warnings don't fail the run (errors always do)
GODOT=/path/to/godot bash tools/check.sh
```

| step | passes when | when it fails |
|---|---|---|
| `validate` | 0 errors, 0 warnings — every reference resolves, every file exists | the message names the file and the field |
| `story` | the story check finds no problem, reaches every room and the ending can be won | it names the room, item or puzzle that cannot be reached |
| `softlocks` | the exact search over everything a player can do finds no way to make the game unwinnable (`SOFTLOCK_SECONDS` per difficulty level, default 180; `SOFTLOCK_STATES`, default 60000) | `godot --headless --path . -s res://tools/softlocks.gd` prints the shortest path into the trap |
| `puzzles` | every puzzle instance, each difficulty level too, is proved winnable | the puzzle id, level and why |
| `budget` | video memory per room (and with the next rooms preloaded) is inside `budget.*` | `-s res://tools/budget.gd -- --text` lists the rooms, biggest first |
| `walkthrough` | each recorded playthrough in `game/walkthroughs/` still plays to its expectations through the real UI | which step, and what was on screen |
| `autoplay` | a goal-driven bot, with nobody at the keyboard, plays the game to its **win** through the real UI (`AUTOPLAY_STEPS`, default 4000; `AUTOPLAY_SECONDS` of real time per game, default 480) | the room it stalled in, the rooms and puzzles it reached and what it held — a hole in the game the data checks did not see |
| `fuzz` | a bot playing at random (`FUZZ_STEPS`, default 120; `FUZZ_SEED`) never leaves the game waiting for input nothing can give, and the engine prints no script error | writes the steps that led there as a walkthrough so the failure replays exactly |
| `lint` | the whole UI, pseudo-localised at 150% text, has nothing off the screen, cut off or untranslatable | the control, its text and where it sits |

Every step ends with one line, and the script exits non-zero if any step failed — so it is a gate in any CI system.

A game that outgrows a default (a big game's soft-lock search needs more than 180 s) keeps its own limits in `check.env` beside
`project.godot` — one `VAR=number` a line (`SOFTLOCK_SECONDS`, `SOFTLOCK_STATES`, `AUTOPLAY_STEPS`, `AUTOPLAY_SECONDS`, `FUZZ_STEPS`,
`FUZZ_SEED`) — so CI, the release gate and a developer's run all use the same ones; a variable set in the environment still wins.

## Wiring it up

**New games** already have the workflow; push the repository and it runs.

**An older game:** run `upgrade_engine` (it brings in `tools/check.sh` and `tools/ci/github.yml`) and copy the workflow:

```bash
mkdir -p .github/workflows && cp tools/ci/github.yml .github/workflows/mysteryforge.yml
```

**Other CI systems:** the whole job is three commands — install Godot, import once, run the script:

```bash
godot --headless --import --path . || true      # the first import can exit non-zero while it writes .godot/
GODOT=godot bash tools/check.sh
```

`python3` must be on the runner (the script reads the tools' JSON reports with it). Nothing needs a display: the walkthrough,
fuzz and lint steps drive the real UI headless.

## Releases

The workflow's second job, `export`, runs only for a tag such as `v1.0.0` (or when started by hand) and only after the check
passed. It installs the export templates for the pinned Godot and builds the Web, Windows and Linux presets from
`export_presets.cfg`, attaching them to the run. macOS builds need a Mac runner and a signing identity; see the roadmap's
"Platform & release" item.

Keep `GODOT_VERSION` in the workflow equal to the Godot the engine copy was built for (`config/features` in `project.godot`).

## Releasing

The whole path from a new game to a signed, supported release — roles, milestones, checklists, what to do when a step fails — is in [HANDBOOK.md](https://mysteryforge.vivalainsurreccion.com/docs/handbook.md).

`tools/release.sh <alpha|beta|gold>` is the same gate plus the data checks (identity, pictures, voice, translations, review comments, export presets, the macOS bundle identifier, a licence file, playtests); `make release` / `python3 tools/package.py` runs it, exports every platform
with a template, and writes zips with notices, `SHA256SUMS` and `manifest.json` — see the SPEC's "Release packaging" for the signing environment variables. In CI, run the packager on a tag with the signing variables as secrets (never in the repository).

## What it deliberately does not do

- **No provider is ever called.** Art and voice generation cost money and need keys in *your* environment; CI never has them
  and never needs them. The check reads what is already in the repository.
- **Loudness** (`node mcp/dist/cli.js loudness <game>`) and the **producer dashboard** are not part of the gate: they belong to
  whoever has the final audio, not to every commit. Run them from the MCP or the Studio.
