Skip to content

Add scenario engine with Linux and Monitoring chapters - #1

Merged
royalpriest merged 1 commit into
mainfrom
feat/scenario-engine
Nov 20, 2026
Merged

royalpriest merged 1 commit into
mainfrom
feat/scenario-engine

Conversation

@royalpriest

@royalpriest royalpriest commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

What this adds

A Rails 8.1 API-only backend in backend/ with the simulator's engine and the first two playable chapters (Linux and Monitoring, built early as planned).

Engine (backend/lib/sim/)

  • world.rb: the whole fake environment as JSON (hosts, files with sizes, disk, services, processes, alerts, metrics, command history).
  • shell.rb: command interpreter for the bash subset beginners need: ssh/exit, ls, cd, cat, head, tail, grep, du, df, rm, truncate, sed -i, echo >, systemctl, journalctl, ps, top, free, kill, curl, alerts, hint. Supports sudo (system files need it), globs, pipes into grep/head/tail/sort/wc, and &&.
  • engine.rb: each command is one tick of time; POST /tick lets time pass while the player reads. Scenarios react each tick (logs grow, memory leaks, alerts fire and resolve). Objectives complete in order.
  • scenarios/: one class per chapter, each playable on its own.

Chapters

  • Linux: The disk is full. Site returns 502. SSH into web-01, read the journal, find a 15 GB debug.log, free space, turn off debug logging, restart, check health. Restarting with debug still on fills the disk again a few minutes later.
  • Monitoring: Memory is climbing. The memory graph climbs until an alert fires. Trace it to shop-worker and its REPORT_CACHE_MAX=0 (unlimited) from the last deploy. A restart alone only buys time; if ignored, the OOM killer kicks in.

API

  • GET /api/scenarios, POST /api/runs, GET /api/runs/:id, POST /api/runs/:id/commands, POST /api/runs/:id/tick
  • RunChannel (Action Cable at /cable) broadcasts every step: output, notices, completed objectives, alerts, metrics, service states.

Repo setup

  • Root README.md, CLAUDE.md (project notes), .gitignore, CI workflow at the root running brakeman, bundler-audit, rubocop and tests in backend/.
  • .ruby-version set to 3.3.14 because brakeman flags 3.3.6.

Not in this PR

  • React frontend (next, after picking a UI direction)
  • GitHub, CI and Deploy chapters
  • Accounts; a run id is the only handle for now

Checks

  • bin/rails test: 29 runs, 0 failures
  • bin/rubocop: no offenses
  • bin/bundler-audit: no vulnerabilities
  • bin/brakeman: only the local Ruby 3.3.6 version warning, fixed by the .ruby-version bump

The engine simulates a small shop's server (web-01) reached from a laptop.
A command interpreter covers the bash subset beginners need (ssh, df, du,
systemctl, journalctl, ps, free, sed -i, pipes, sudo). Time advances per
command or via the tick endpoint, which drives incidents, metrics and alerts.

Chapters:
- Linux: the disk is full and the app crashed; fixing it has to stick.
- Monitoring: a memory alert fires; trace it to the worker's cache config.
@royalpriest
royalpriest merged commit a50dd0b into main Nov 20, 2026
1 check passed
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