Bug mode: design and implementation plan¶
Status: approved by the owner on 2026-12-03 and implemented in every repository at once (all 52 bugs, no MVP cut): backend-rs 1.3.0, frontend 3.17.0, warehouse-, payment- and notification-service-rs 1.2.0, delivery- and llm-service-rs 1.1.0. The decisions are in section 11; the e2e suite checks both modes (section 13).
1. Goal and constraints¶
A manual-testing course wants the local stack to start with intentionally planted bugs, so students can practise test techniques on a realistic shop with defects the trainer knows about.
- One switch, two modes. The stack runs either without bugs (the default, as today) or with bugs (every planted bug at once). No per-bug selection, presets or random sets (owner, 2026-12-03).
- Every service of the local stack. About 50 bugs over the backend, the frontend, the delivery micro-frontend and the warehouse, payment, notification, delivery and LLM services. Many show up in the order flow rather than on a single screen.
- Local Docker only. Production (awesome.byst.re, aitesters.byst.re) and the compatibility stack that gates the l20 course suite never run with bugs.
- Bugs stay hidden. They are in the code (all repositories are public), but not in this plan and not in the wiki. The trainer's answer key is built only into the wiki of a local bug-mode stack, as an unlisted page reachable by its URL; the production wiki never has it. Agents with repository access can still find it; that is accepted. The public wiki does say that a bugged version exists and how to start it locally (Training stack with planted bugs).
- Visible mode. The frontend shows a "Training mode" badge and every service logs one
WARNline at start-up, so nobody has to investigate which mode a stack is in. - The existing course bugs are not part of bug mode. The ai-testers-api bugs (l15–l20 bug reports) and the behaviour the l20 suite asserts stay always on and never move behind the flag.
- Quality policy unchanged. With bug mode off the product behaves exactly as now; every reproducible defect outside bug mode and the course bugs is still fixed.
2. Switch and configuration¶
| Variable | Values | Default | Read by |
|---|---|---|---|
APP_BUG_MODE |
true/false (also on/off/yes/no/1/0) |
false |
every app service and the frontend |
APP_DEPLOYMENT |
production or unset |
unset | every app service and the frontend (guard) |
APP_BUG_MODE is the switch. APP_DEPLOYMENT=production is a new, explicit production marker
(section 3). Each Rust service parses APP_BUG_MODE with the boolean parser it already has, so
an unparsable value stops start-up with that service's usual configuration error.
How it reaches each component:
| Component | Where the switch is read | Start-up WARN |
|---|---|---|
| backend-rs | src/config/mod.rs Config::from_properties, default in src/config/profiles.rs BASE |
src/main.rs after check_startup |
| warehouse-service-rs | src/config.rs Config::from_vars (env.boolean) |
src/main.rs serve() after logging::init |
| payment-service-rs | src/config.rs Config::from_map |
src/main.rs run() after the "Starting" log |
| notification-service-rs | src/config.rs Config::load |
src/main.rs after logging::init |
| delivery-service-rs | src/config.rs Config::from_map (env.bool) |
src/main.rs run() next to the token warning |
| llm-service-rs | src/config/mod.rs from_properties |
src/main.rs after logging::init |
| frontend | /config.js, written by the nginx entrypoint (section 6) |
badge in the header |
| delivery micro-frontend | one line prepended to remote.js by delivery-service (section 6) |
none (the host shows the badge) |
The WARN text is the same everywhere: Bug mode is ON: planted defects are active (training only).
3. Production guard¶
Three independent layers. Any one of them is enough to keep bugs out of production.
3a. A production marker, and services that refuse to start¶
Not every service can tell production by its profile: warehouse, payment and notification run
with docker both locally and in production (locally with docker,demo), and delivery-service
has no profile at all. So production gets an explicit marker: APP_DEPLOYMENT: production on
every app service in docker-compose.server.yml (backend, warehouse, payment, notification,
llm, delivery and frontend, for awesome and aitesters), set through one YAML anchor.
Every service refuses to start when APP_BUG_MODE is on and APP_DEPLOYMENT=production. The
backend and llm-service also refuse with the server or aitesters profile, reusing the
SHARED_PROFILES check that already guards password-reset.expose-token-in-response; that also
covers the compatibility stack (local,server). Backend example in Config::check_startup:
if self.bug_mode {
let shared: Vec<&str> = SHARED_PROFILES.into_iter().filter(|p| self.has_profile(p)).collect();
if self.production_deployment || !shared.is_empty() {
return Err(ConfigError(
"APP_BUG_MODE must be off in production: it plants defects for training".into(),
));
}
}
Refusing to start, rather than ignoring the switch, is deliberate: a misconfigured production
deploy fails its health check at once instead of running quietly with a dangerous flag. The
frontend entrypoint does the same (exits non-zero). Production secrets come from Ansible-written
env files (.env.runtime, .env.payment, …) that no static check can read on the server; this
layer covers them.
3b. Contract script: scripts/verify-bug-mode-local-only.sh¶
Modelled on scripts/verify-rag-local-only.sh and the static half of
scripts/verify-db-access.sh; runs without Docker. It fails when:
APP_BUG_MODEordocker-compose.bugs.ymlappears where production is defined:docker-compose.server.yml,ansible/(env file templates and vars included),nginx/.- It appears in
docker-compose.compatibility.yml(the l20 gate tests the real product). - It appears in
docker-compose.ymlorlightweight-docker-compose.yml(bug mode comes only with the opt-in overlay). - An app service in
docker-compose.server.ymllacksAPP_DEPLOYMENT: production(the script readsdocker compose config --format json, asverify-db-access.shdoes). - The overlay is missing, sets anything other than
APP_BUG_MODE, publishes a port, overrides an image, or touches a service that is not an app service.
CI: one step in .github/workflows/test.yml after Verify the docs RAG service stays local only.
3c. Frontend host check¶
The frontend also ignores bug mode when location.hostname ends with byst.re. Cheap, and it
protects against a stray config.js even if both layers above failed.
4. The bugs module (all Rust services)¶
Each Rust service gets the same small module, src/bugs.rs:
/// Planted defects for manual-testing training. Off unless APP_BUG_MODE (docs-site/docs/reference/BUG_MODE_PLAN.md).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Bug { /* one variant per planted bug of this service, neutral names: B01, B02, … */ }
static MODE: OnceLock<bool> = OnceLock::new();
pub fn init(on: bool) { let _ = MODE.set(on); }
/// Whether `bug` is planted. All bugs share the one switch; the argument labels the injection
/// point so `grep 'bugs::on(Bug::'` lists every one.
#[must_use]
pub fn on(_bug: Bug) -> bool {
#[cfg(test)]
if let Some(mode) = TEST_MODE.with(Cell::get) { return mode; }
MODE.get().copied().unwrap_or(false)
}
#[cfg(test)]
thread_local! { static TEST_MODE: Cell<Option<bool>> = const { Cell::new(None) }; }
/// Runs `f` with bug mode forced on or off on this thread (each test has its own thread).
#[cfg(test)]
pub fn with_mode<T>(on: bool, f: impl FnOnce() -> T) -> T { /* set, run, reset */ }
Why a process-wide flag rather than a value threaded through the application state: most
injection points are small pure functions (tier_for, classify, is_expired, courier_step)
that do not see the state. The flag keeps their signatures and keeps each bug to one if.
Every injection point has the same shape, so a reviewer can check that the correct branch is the untouched original:
if crate::bugs::on(Bug::B07) { /* planted behaviour */ return …; }
// original code below, unchanged
Where the code is SQL text (a sort order, a filter, an offset), the if chooses between the
original string and the planted one; the original string stays byte-for-byte the same.
Code comments name the bug by ID only. What it does and how to find it lives in the answer key.
Testing¶
- Unit tests per bug in the module of the injection point: one test with
bugs::with_mode(true, ..)asserting the planted symptom. The existing tests (mode unset, so off) keep asserting correct behaviour. A planted bug that stops reproducing, or that leaks into off mode, failscargo test. - One integration test binary per service,
tests/bug_mode.rs(its own process, so the global flag is safe), for bugs that live in SQL or HTTP handling, started the way the existing integration tests start the service, withAPP_BUG_MODE=true. - Guard tests per service: bug mode with
APP_DEPLOYMENT=production(and, for backend and llm, withserver,aitesters,local,server) is refused; local profiles start. - The e2e reference suite (
awesome-localstack-e2e-tests) and the l20 gate keep running with bug mode off and need no change. Their passing is the proof that off mode is untouched.
5. Frontend (vite-react-frontend)¶
Today every flag is a build-time VITE_* (src/lib/runtimeConfig.ts, baked by the
Dockerfile). Bug mode must not need a second build, so it becomes the first runtime setting.
public/config.js(shipped default):window.__APP_CONFIG__ = {};. Without a default, the SPA fallback would answer/config.jswithindex.html, which the gateway'snosniffblocks.deploy/docker-entrypoint.d/40-app-config.sh, run by the official nginx image before nginx starts:
#!/bin/sh
set -eu
on=$(printf %s "${APP_BUG_MODE:-}" | tr '[:upper:]' '[:lower:]')
case "$on" in true|on|yes|1) on=1 ;; *) on= ;; esac
if [ -n "$on" ] && [ "${APP_DEPLOYMENT:-}" = production ]; then
echo "APP_BUG_MODE must be off in production" >&2; exit 1
fi
if [ -n "$on" ]; then mode='"training"'; else mode=null; fi
printf 'window.__APP_CONFIG__ = { mode: %s };\n' "$mode" > /usr/share/nginx/html/config.js
index.html: a classic<script src="/config.js"></script>(notype="module") before the module script, so the value exists before the bundle runs. There is no CSP to update, andsrc/test/indexHtml.test.tsonly checks the boot fallback.deploy/nginx/default.conf:location = /config.js { add_header Cache-Control "no-cache" always; }, like/index.html, so switching modes needs no hard reload.src/lib/runtimeConfig.ts:isBugMode(config = window.__APP_CONFIG__, location = window.location)returnsconfig?.mode === 'training', andfalseon*.byst.re.src/lib/bugMode.ts:bugOn(id), the same one-switch-with-labels pattern as the Rust services.- Badge:
src/components/layout/Navigation.tsx, right after the brand link, outside the signed-in conditionals, so it also shows on the login page.
What devtools reveal: window.__APP_CONFIG__ holds only { mode: "training" }, which the
badge says anyway. There is no list of active bugs at runtime, because there is nothing to list.
The minified bundle does contain the planted branches; reading the source is out of bounds for
students, and the trainer says so.
Testing: Vitest per bug with __APP_CONFIG__ stubbed to { mode: 'training' }; the existing
tests run without it. The frontend runs Stryker; every planted branch is covered in both modes,
so its mutants are killed like any other branch's. The frontend's Playwright suites run in off mode.
6. Delivery micro-frontend¶
delivery-service serves the tracking micro-frontend (mfe/src/*.ts, embedded from mfe/dist
by src/mfe.rs). With bug mode on, src/mfe.rs serve prepends one line to remote.js only:
globalThis.__DELIVERY_BUG_MODE__ = true;. remote.js is already sent with no-cache, and the
hashed chunks stay untouched. The micro-frontend checks it through its own tiny bugOn. The
React host needs no change.
7. Compose: one overlay¶
docker-compose.bugs.yml, the "stack with bugs". The base files stay the "stack without bugs".
# Opt-in bug mode for manual-testing training (docs-site/docs/reference/BUG_MODE_PLAN.md). Local only: never part
# of docker-compose.server.yml, docker-compose.compatibility.yml, Ansible or the gateway
# (scripts/verify-bug-mode-local-only.sh).
#
# docker compose -f lightweight-docker-compose.yml -f docker-compose.bugs.yml up -d
# docker compose -f docker-compose.yml -f docker-compose.bugs.yml up -d
x-bug-mode: &bug-mode
APP_BUG_MODE: "true"
services:
backend: { environment: *bug-mode }
warehouse-service: { environment: *bug-mode }
payment-service: { environment: *bug-mode }
notification-service: { environment: *bug-mode }
delivery-service: { environment: *bug-mode }
llm-service: { environment: *bug-mode }
frontend: { environment: *bug-mode }
Why an overlay rather than APP_BUG_MODE: ${APP_BUG_MODE:-false} passthrough in the base files:
- It is literally "one stack with bugs, one without": base file versus base file plus overlay.
- A leftover
APP_BUG_MODE=truein someone's.envcannot turn bugs on, because the base files never read the variable. - The contract script can state a simple rule (the variable exists only in the overlay), the
same rule already used for
docker-compose.rag.ymlanddocker-compose.chaos.yml. - It works with both local profiles without editing either.
Switching modes is up -d with or without the overlay; Compose recreates only the app services.
The databases are shared between modes, so data created in one mode is visible in the other.
The overlay also builds the wiki with the trainer pages (TRAINER_PAGES=true, its own image tag
awesome-localstack/docs:bugs), so the answer key exists only in a local bug-mode stack.
Documentation for students: the wiki page "Training stack with planted bugs" (For testers), a
pointer on "Running locally", and a section in docs-site/docs/reference/STUDENT_GUIDE.md. They say how to start it
and that bugs are planted, never which ones.
8. Bug catalogue (summary only)¶
The catalogue has 52 bugs. Each has a neutral ID, the technique it trains, one injection point in a function read in the current code, an observable symptom, reproduction steps and the expected behaviour. Bugs that would mask each other (two bugs on the same field or the same amount) were dropped while choosing. The full catalogue is the trainer's answer key; it is not in this document or the wiki navigation.
| Component | Bugs |
|---|---|
| backend-rs | 16 |
| frontend | 11 |
| warehouse-service-rs | 7 |
| payment-service-rs | 6 |
| notification-service-rs | 4 |
| delivery-service-rs (incl. micro-frontend) | 5 |
| llm-service-rs | 3 |
| Total | 52 |
Techniques covered: boundary values (11), data consistency across the order flow (8), state transitions (7), equivalence classes (7), sorting, filtering and pagination (6), rounding and money (5), time and time zones (4), error handling (2), authorization (2). Validation is exercised inside the boundary and equivalence bugs. About three quarters are visible in the UI; the rest are found through the API, emails, webhooks or the effects of the order flow (stock, refunds, deliveries).
The answer key page¶
- Source:
docs-site/trainer/<hidden-path>/index.md, outside the wiki'sdocs/directory. - The wiki image copies it in only with the build argument
TRAINER_PAGES=true, which onlydocker-compose.bugs.ymlsets. The production wiki (built fromdocker-compose.server.yml) never contains it; the contract script and CI check that. - In the bug-mode wiki it is listed under
not_in_nav, excluded from search (front matter), markednoindex, nofollow(docs-site/overrides/main.html) and removed fromsitemap.xml(docs-site/hooks/hidden_pages.py). No page links to it.
9. Delivery plan¶
The owner chose to go straight to the finished product: all 52 bugs in one release of every repository, no MVP phase.
- One PR per repository (backend-rs, vite-react-frontend, warehouse-, payment-,
notification-, delivery- and llm-service-rs): switch, guard,
WARN,bugs.rs/bugOn, all of that repository's bugs with their unit tests, a minor version bump. Real defects found while surveying (section 12) are fixed in their own commits of the same PRs. - awesome-localstack: the overlay, the production marker, the contract script with its
--liveimage checks, CI steps, the trainer wiki build and the student documentation. - Release: tag and publish every image, pin them through the release train, run the e2e reference suite and the l20 gate with bug mode off, run every bug of the answer key with bug mode on, then deploy (production gets the new images dormant, plus the marker).
Estimated at about 16 developer-days of work; with agents working on the repositories in parallel, the elapsed time is mostly CI, image publishing and the walkthrough.
10. Rejected alternative: separate images built with a Cargo feature¶
A bugs Cargo feature, built as backend-rs:x.y.z-bugs and so on, would keep planted code out of
production binaries entirely. That is its real advantage. It loses on everything else:
- Two images per service per release, seven services: the release train, image pins,
verify-image-pins.py,verify-release-images.py, multi-arch builds and caches all double. - Planted code rots. Default CI builds compile without the feature, so a refactor breaks a bug branch unnoticed unless every repository runs a feature matrix.
- The frontend and the micro-frontend have no equivalent without second builds.
- Switching modes means pulling other images, instead of
up -dwith an overlay. - The guard is not simpler. A wrong tag pinned in production is as easy a mistake as a stray variable; the runtime flag's start-up refusal catches it wherever the variable came from.
11. Decisions¶
Owner, 2026-12-03:
- Answer key only in local builds, never on the production wiki; the production wiki only says that the bugged version exists and how to start it.
- No MVP cut: all 52 bugs at once.
- Catalogue approved as proposed, authorization bugs included.
- Badge in the frontend and a
WARNline in every service.
12. Side findings (real defects, fixed with this work)¶
Found while reading code for the catalogue; per the quality policy they are fixed (not planted) in the same PRs, in their own commits:
- delivery-service-rs
src/domain.rssteps_to_delivery: after the last failed attempt the next step is RETURNING, but the page still shows an estimated delivery. - vite-react-frontend
src/components/orders/OrderList.tsx: a one-item order shows "1 items". - vite-react-frontend
src/components/cart/AddToCartButton.tsxis not used anywhere.
13. The e2e reference suite in two modes¶
Owner request (2026-12-03): the reference suite (awesome-localstack-e2e-tests) must also prove
that a stack started with docker-compose.bugs.yml really has the planted bugs. Built the same
day; the owner accepted public specs and running them in normal mode too.
- Normal mode is unchanged and stays green: same jobs, same report on GitHub Pages.
- One spec per planted bug in the project
planted(tests/planted/b01.spec.ts…b52.spec.ts, tag@planted). Each sets up its own data, performs the repro and takes its expected value fromexpected({ normal, planted })(support/bug-mode.ts), so the assertion is unconditional: on the normal stack it is an edge-case test of the correct behaviour, on the bug-mode stack it asserts the exact planted symptom. A defect that leaks into normal mode, or disappears from bug mode, fails it. Better thantest.fail(), which also passes on an unrelated failure. - The mode is checked against the stack.
E2E_MODE=normal|bugs(defaultnormal) declares it;stack-healthreads the frontend's/config.jsand fails when the stack runs in the other mode. - The normal suite does not run in bug mode: with
E2E_MODE=bugs,playwright.config.tskeeps onlystack-healthandplanted. - Time-zone bugs (B19, B49) run with
timezoneId: 'Europe/Warsaw'. - CI (
commerce-e2e.yml): two more matrix jobs,bugs-1andbugs-2, withCOMPOSE_FILE=lightweight-docker-compose.yml:docker-compose.bugs.yml:../ci/fast-timers.compose.yml, on the same triggers. The three normal browser jobs also runplanted. - Reports: one per mode. The bug-mode report is a 7-day workflow artifact
(
playwright-report-bugs) and is never published to GitHub Pages. - Release check: before a release, run the suite against a normal and a bug-mode stack (the release train does not start stacks itself). The first run, on 2026-12-03 with the images above: 908 tests green on the normal stack, the 52 planted specs green on the bug-mode stack.
- Shared test data: generated test users have names of at least five letters, so they also sign up with B16 on.