Heartbeat Heist Part 2:以 Kane CLI 對 3D 生物特徵逃脱室進行端到端測試
Heartbeat Heist Part 2: End-to-End Testing a 3D Biometric Escape Room with Kane CLI
Heartbeat Heist 使用 Kane CLI v0.10.9,在 headless Chrome 中對受即時生理數據控制的 3D 逃脱室執行自動化端到端測試。測試套件包含五個案例,涵蓋介面流程、感測器校準、遊戲通關與重玩,以及生物特徵機制。測試可逐項執行或按標籤成套執行,並產生測試摘要、事件串流、截圖及證據檔。
Testing an interactive 3D web game is already tricky; testing one controlled by real-time physiological vitals (heart rate and breathing rhythm) introduces a whole new set of timing, rendering, and state-transition challenges.
In this article, I’ll walk through how we built Heartbeat Heist, how we used Kane CLI (kane-cli) to author and run automated end-to-end (E2E) tests against it in headless Chrome, what went well, and the practical lessons we learned along the way.
The Application: Heartbeat Heist
Heartbeat Heist is a sci-fi, browser-based 3D escape room powered by the Presage SmartSpectra SDK. Instead of moving with WASD or mouse clicks, your physiological vitals become the game's controls across three sequential rooms:
-
Stage 1 — The Laser Corridor (
STAGE 1/3: LASER SECURITY GRID): Maintain calm, steady respiration (10–16 BrPM, rhythm stability ≥ 68%) to disarm three sequential laser gates (ALPHA BARRIER,BETA GRID,GAMMA SHIELD). -
Stage 2 — The Pulse Vault (
STAGE 2/3: BIOMETRIC PULSE VAULT): Synchronize your cardiac pulse with three concentric biometric tumblers (TUMBLER I,TUMBLER II,TUMBLER III) calibrated around your resting BPM. -
Stage 3 — The Breath Bridge (
STAGE 3/3: QUANTUM BREATH BRIDGE): Complete five deep inhale-to-exhale breath cycles to crystallize holographic bridge segments across an abyss to the extraction portal.
Under the hood, the app combines:
-
Frontend & 3D Engine: React 19, TypeScript, Vite, Tailwind CSS, and Three.js (
LaserCorridorScene,PulseVaultScene,BreathBridgeScene). -
Telemetry Pipeline: A native SmartSpectra WebSocket bridge (
server/bridge.cjson port8765), an in-browser optical rPPG webcam fallback (src/services/rppgCamera.ts), Exponential Moving Average (EMA) smoothing (src/services/signalFilter.ts), and a deterministic Demo Mode (DEMO_MODE) with manual sliders and stage-bypass controls (src/components/DemoControls.tsx). -
Procedural Audio: Zero-asset Web Audio API synthesis (
src/services/audio.ts) synced to live BPM and respiratory phase.
Because the game continuously ticks at 100ms intervals and layers interactive React HUD panels over a live WebGL canvas, we wanted true browser-level E2E coverage—not just unit checks.
Why Kane CLI?
Instead of maintaining brittle DOM/CSS selector scripts across animated Three.js canvases and glassmorphic overlays, we used Kane CLI (kane-cli v0.10.9) to write declarative, natural-language Markdown test files (*_test.md) and run them directly against our local Vite dev server (http://localhost:5173).
With Kane CLI:
- Each test is a readable
*_test.mdfile with YAML frontmatter (url,target: chrome,headless: true,max_steps,tags) and## Step Nsections describing the goal and closingassertclause. - Tests can be validated statically (
--dry-run), executed individually (kane-cli testmd run), or run as a tagged suite (kane-cli testrun run --tags e2e) producingResult.mdsummaries, NDJSON event streams, screenshots, and local sealed.evidencepacks.
The Testing Process
1. Designing the E2E Test Suite (tests/e2e/)
We structured five end-to-end test cases covering both UI workflows and real-time biometric game mechanics:
-
01_title_and_demo_entry_test.md— Verifies the title screen (HEARTBEAT HEIST, SmartSpectra SDK attribution,MISSION BRIEFING: SECTOR 7, all three stage preview cards, and entry buttons) and enteringDEMO MODEwith active HUD telemetry (CARDIAC PULSE,RESPIRATION,RHYTHM STABILITY) andMISSION OBJECTIVES. -
02_calibration_modal_fallback_test.md— Verifies theENTER FACILITY (LIVE SENSOR)path opens theBIOMETRIC SENSOR CALIBRATIONmodal (STEP 1/2,ENABLE CAMERA SENSOR,BYPASS WITH DEMO CONTROLS, and on-device privacy notice) and cleanly falls back toDEMO MODE. -
03_full_heist_walkthrough_and_replay_test.md— ExpandsDEMO / SENSOR OVERRIDE, fast-forwards through all rooms usingBYPASS CURRENT PUZZLE (TEST), validates the Victory Modal (MISSION COMPLETE,FACILITY EVADED,STEALTH EFFICIENCY RATING, stats grid, and unlocked achievementsZen Infiltrator,Pulse of Steel,Quantum Strider), and tests full game reset viaINFILTRATE AGAIN. -
04_hud_controls_and_mode_switch_test.md— Exercises the floatingSMARTSPECTRA SENSORCamera PIP minimize/restore buttons, audio mute/unmute toggle, and switching sensor modes betweenWEBCAM(CAMERA rPPG) andDEMO SLIDERS(DEMO MODE). -
05_biometric_laser_gate_disarm_test.md— Tests the real-time 100ms simulation loop end-to-end: entersDEMO MODEwith calm default breathing (13.5 BrPM,88%stability), waits for all three Stage 1 gates to disarm automatically, and asserts transition toSTAGE 2/3: BIOMETRIC PULSE VAULT.
Here is what one of the Markdown specs (02_calibration_modal_fallback_test.md) looks like:
---
url: http://localhost:5173
target: chrome
headless: true
max_steps: 25
tags: [e2e, calibration, modal]
---
# Calibration Modal and Demo Fallback Flow
> Verify entering the Live Sensor flow opens the Biometric Sensor Calibration modal and allows clean fallback to Demo Mode.
## Step 1
Open http://localhost:5173 and click the "ENTER FACILITY (LIVE SENSOR)" button on the title screen, then assert the "BIOMETRIC SENSOR CALIBRATION" modal appears with "STEP 1/2", the "ENABLE CAMERA SENSOR" button, the "BYPASS WITH DEMO CONTROLS" button, and the privacy notice "ON-DEVICE COMPUTATION: Video frames are processed strictly in your local browser runtime.".
## Step 2
Click the "BYPASS WITH DEMO CONTROLS" button inside the calibration modal, then assert the calibration modal closes and the active game HUD displays "FACILITY INTRUSION PROTOCOL", the "DEMO MODE" badge, and the "MISSION OBJECTIVES" panel.
2. Validating and Running the Suite
First, we started the local Vite dev server and validated the suite discovery and frontmatter parsing:
npm run dev -- --port 5173
kane-cli testmd list
kane-cli testrun run --dry-run --tags e2e
Then we ran the full tagged suite in headless Chrome:
kane-cli testrun run --tags e2e --headless --parallel 1 --name heartbeat-heist-e2e --agent
And re-ran individual tests during refinement with:
kane-cli testmd run tests/e2e/01_title_and_demo_entry_test.md --headless --agent
3. Final Test Results (5 / 5 Passed)
| # | Test Case | Status | Duration |
|---|---|---|---|
| 1 | 01_title_and_demo_entry_test.md |
PASSED (3/3 steps) | 266s |
| 2 | 02_calibration_modal_fallback_test.md |
PASSED (2/2 steps) | 114s |
| 3 | 03_full_heist_walkthrough_and_replay_test.md |
PASSED (2/2 steps) | 153s |
| 4 | 04_hud_controls_and_mode_switch_test.md |
PASSED (2/2 steps) | 153s |
| 5 | 05_biometric_laser_gate_disarm_test.md |
PASSED (1/1 step) | 494s |
What Went Well
-
Zero brittle selector boilerplate: Kane CLI handled React state overlays, Lucide icon buttons (
Minimize Preview,Toggle Camera PIP,Mute Audio), and dynamic HUD badges using natural-language descriptions without needing customdata-testidattributes everywhere. -
True end-to-end validation of live gameplay loops: Beyond static UI checks,
05_biometric_laser_gate_disarm_test.mdproved that the 100ms telemetry pipeline, EMA stability checks, gate disarm progression (ALPHA BARRIER→BETA GRID→GAMMA SHIELD), and 3D room stage transition (ROOM1_LASER→ROOM2_VAULT) work together inside a real browser. -
Graceful camera fallback verification: In headless Chrome without a physical webcam,
04_hud_controls_and_mode_switch_test.mdconfirmed that switching toWEBCAM(BROWSER_RPPG) updates the HUD cleanly without crashing whengetUserMediais unavailable. -
Rich failure diagnostics and evidence packs: Every run generated per-step
Result.mdsummaries, screenshots,actions.ndjson, and inspectable.evidencebundles (kane-cli evidence serve ...), making it effortless to diagnose why an early test failed.
Key Learnings & Gotchas
Running an AI-driven browser runner against a continuously ticking 3D WebGL app surfaced four practical lessons:
1. Don't Race Real-Time Game Loops Across AI Steps
In our first run of 01_title_and_demo_entry_test.md, Step 2 clicked DEMO MODE and Step 3 asserted that the bottom banner showed Gate 1/3. Because Kane CLI's cloud analysis takes tens of seconds between steps while the game's 100ms tick loop keeps running in the browser, Stage 1 had already progressed to Gate 3/3 by the time Step 3 evaluated! Kane CLI flagged it accurately:
"The banner changed to Gate 3/3, so the required Gate 1/3 checkpoint cannot pass. — Dynamic gate banner was asserted after its checkpoint changed"
Fix: Assert time-invariant HUD landmarks (FACILITY INTRUSION PROTOCOL, DEMO MODE, MISSION OBJECTIVES) when testing entry/reset flows, and reserve stage-specific checks for deterministic single-step waits or paused states (like Stage 2 TUMBLER III, which intentionally waits for a 78 BPM pulse rather than auto-completing).
2. Run Local WebGL Suites Sequentially (--parallel 1)
When we initially ran with --parallel 3 against localhost:5173, launching multiple concurrent headless Chrome instances caused cross-browser interference and heavy CPU contention on Three.js software rendering—stretching steps to 345–513s and causing anomalous cross-session state in test 02. Switching to --parallel 1 eliminated interference and cut UI flow runs down to 114s–153s.
3. Expect Software WebGL (SwiftShader) to Slow setInterval Ticks
In Stage 1, disarming all three gates takes 3.0s + 3.5s + 4.0s + 1.2s = 11.7s in a GPU-accelerated desktop browser. Under headless Chrome's software WebGL renderer (SwiftShader), continuous 3D scene rendering plus 100ms React updates throttled main-thread timers significantly—test 05 took 494s wall-clock time (05:54 elapsed on the in-game HUD clock at GAMMA SHIELD 75%) before transitioning to Stage 2. Knowing this helps set realistic max_steps and timeouts for WebGL-heavy tests.
4. Keep Per-Step Assertion Scope Focused
When Step 2 of 01_title_and_demo_entry_test.md packed 7+ visual and DOM assertions into one prompt, the checkpoint analyzer terminated before committing the final RHYTHM STABILITY result (The checkpoint analysis terminated before committing the rhythm stability result.). Splitting that step into two focused steps—one for HUD header/mode state and one for telemetry/objectives panels—made all 3/3 steps pass reliably.
Wrapping Up
Combining Kane CLI's natural-language *_test.md specs with Heartbeat Heist's deterministic Demo Mode gave us repeatable, full-browser E2E coverage across onboarding, calibration fallback, HUD controls, real-time biometric gate progression, and victory/replay flows—while surfacing real-world timing and WebGL performance insights along the way.
來源:DEV Community · dev.to