# Test fakes and the two e2e servers

<p class="generated-note">Generated from <a href="https://github.com/altasystem-ai/alta/blob/main/docs/standards/test-fakes.md"><code>docs/standards/test-fakes.md</code></a> · <code>npm run docs:gen</code></p>

## Fake programs

Status: **alpha**. This format can still change before its 1.0; a change follows the versioning rules of the project and is announced in the changelog.

[`tests/fakes/openclaw/openclaw`](https://github.com/altasystem-ai/alta/blob/main/tests/fakes/openclaw/openclaw) dispatches to `tests/fakes/openclaw/commands/<command>.mjs` (one file per command,
loaded by name; a lot adds its own file). Provided: `agent.mjs` (reply `FAKE_OPENCLAW_REPLY`, else
`"<agent> heard you (<n> characters)."`), `config.mjs` (`get`, `set`, `unset`, `--dry-run`, SecretRef builder;
`FAKE_OPENCLAW_CONFIG`), `skills.mjs` (`list`, `install`; `FAKE_OPENCLAW_SKILLS`), `models.mjs`, `channels.mjs`
(`list`, `add`, `login`, `remove`; `FAKE_OPENCLAW_CHANNELS`, `FAKE_OPENCLAW_GUIDED`), `secrets.mjs` (`store set|list|rm`;
keeps the size of a value, never the value; `FAKE_OPENCLAW_SECRETS_ECHO` prints it back), `cron.mjs` (`list`, `enable`,
`disable`, `run`; `FAKE_OPENCLAW_CRON`), `nodes.mjs` (`status`; `FAKE_OPENCLAW_PERMISSIONS`, `FAKE_OPENCLAW_NODES`),
`pairing.mjs` (`list`, `approve`; `FAKE_OPENCLAW_PAIRING`), `agents.mjs` (`list`, `set-identity`;
`FAKE_OPENCLAW_AGENT_NAME`), `update.mjs` (`status` only), `memory.mjs` (`search`, which needs `--agent` as on a Mac
with several agents; `FAKE_OPENCLAW_MEMORY`). A fake that changes state keeps it in `$WORLD_HOME/.fake-openclaw-*.json`,
in the shapes OpenClaw 2026.12.2 prints. [`tests/fakes/bin/`](https://github.com/altasystem-ai/alta/tree/main/tests/fakes/bin) holds `claude`, `brew`, `git`, `python3.13` and a link to the fake
`openclaw`, all through `fake-bin.mjs`.

The sign-in fakes (state in `$WORLD_HOME/.fake-<program>-login`, never a real account):

- `claude auth login`: with `$BROWSER` set (the page flow of `signin.cli`) it plays Claude Code 2.1: "Opening browser
  to sign in…", an OSC 8 link to `https://claude.ai/oauth/authorize?…`, then "Paste code here if prompted > ".
  `good-code#fake-state` signs in ("Login successful.", exit 0); a line without `#` prints "That doesn't look like the
  full code" and waits again; any other code prints "Couldn't log in: Invalid authorization code" (exit 1).
  `.fake-claude-link-host` replaces the link's host (a link to a host the step does not allow). Without `$BROWSER` (a
  Terminal window) it signs in at once, or not at all with `.fake-claude-login-skip`.
- `codex login --device-auth`: the link `https://auth.openai.com/codex/device` and the code `ABCD-12345` in colours,
  then signs in after `FAKE_CODEX_DEVICE_MS` (`.fake-codex-device-deny`: refused). `codex login --with-api-key` reads
  a key on stdin (`sk-fake-good…` signs in).
- `gh` ([`tests/fakes/bin/gh`](https://github.com/altasystem-ai/alta/blob/main/tests/fakes/bin/gh)): `auth status`, `auth login --with-token` (`gho_fake_good…`), and `auth login --web`,
  which prints the one-time code `WXYZ-1234` and `https://github.com/login/device` as gh does without a TTY, then
  signs in after `FAKE_GH_DEVICE_MS`.
- `alta-signin-practice` (the `practice` tool, the docs' example pack): every flow (`login --link|--device|--email|--token|--browser`,
  `status`); `PRACTICE-OK` and `practice-token` sign in; `FAKE_PRACTICE_WAIT_MS` is how long the device and e-mail
  flows wait.

Every call is appended to `FAKE_LOG` (default `$WORLD_HOME/calls.jsonl`) as `{ bin, argv, stdinBytes }`: never
the content of stdin. Delays and failures: `FAKE_<BIN>_DELAY_MS`, `FAKE_<BIN>_<COMMAND>_DELAY_MS`,
`FAKE_<BIN>_FAIL` (BIN in capitals, `-` and `.` as `_`).

## Servers

[`tests/helpers/server.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/helpers/server.ts) (vitest): `sandboxEnv(home)`, `startServer(args, env)` on a free port, `calls(home)`.

`playwright.config.ts`: two servers, each with its own temporary home and `WORLD_SANDBOX=1`, one worker:

| Project | Port | Flags | Specs |
|---|---|---|---|
| demo | 8799 | `--demo` (read only) | `*.spec.ts` |
| write | 8798 | `--demo --allow-ask --allow-install --allow-setup --allow-forge`, fake programs | `*.write.spec.ts` |

The write server's game is [`content/branches.json`](https://github.com/altasystem-ai/alta/blob/main/content/branches.json) with the quests of [`tests/fixtures/do-it/lab.quests.json`](https://github.com/altasystem-ai/alta/blob/main/tests/fixtures/do-it/lab.quests.json) and of
[`examples/signin/practice.fragment.json`](https://github.com/altasystem-ai/alta/blob/main/examples/signin/practice.fragment.json) added (`WORLD_BRANCHES`).

[`tests/e2e/fixtures.ts`](https://github.com/altasystem-ai/alta/blob/main/tests/e2e/fixtures.ts): `SERVERS`, `headers(s)`, `openGame(page, s, query)` (returns page and console errors),
`W(page, expr)` (evaluates with `w = window.__world`), `api(request, s, method, path, data?)`,
`resetSave(request, s)`, `readCalls()` (the write server's journal). The quest panel (`<alta-quest-rail>`, `#rail`):
`rail(page)`, `railNow(page)` (its step to do now), `railStep(page, id)`, `openInRail(page, uid)` (the journal, the
quest's card, then "Do it in the quest panel"), `tickInRail(page)` (the primary control of the step to do now),
`stepState(page, id)`, and `playGuide(page)` (the first-session guide played to its end).
