ai-code-battle/scripts
jedarden 1a9c8374f2 fix(scripts): add test replay generation and R2 upload tools
Root cause: The R2 bucket 'acb-data' is empty - no replay files were ever
uploaded. The matches/index.json lists test matches, but the corresponding
replay files return 404 when accessed via the Pages Function at /r2/.

Fix: Add tooling to generate test replays matching index.json entries and
upload them to R2. The viewer already has proper error handling (response.ok
check + user-visible error messages in replay.ts:1397-1402).

Changes:
- scripts/generate-test-replays.sh: Generate all 8 test replays from index.json
  with correct match IDs, gzip them, place in test-replays/
- scripts/upload-test-replays.sh: Upload generated replays to R2 via wrangler
- scripts/README.md: Document the R2 setup and replay upload workflow
- .gitignore: Add test-replays/ (generated files, not committed)

Usage:
  1. bash scripts/generate-test-replays.sh
  2. npm install -g wrangler && wrangler login
  3. bash scripts/upload-test-replays.sh

Verified: Generated replays have correct match_id, format_version="1.0",
and valid JSON structure. The viewer error path handles 404 correctly.

Closes: bf-360t
2026-05-24 21:54:36 -04:00
..
analyze-combat-deaths.sh feat(monitoring): add combat death rate analysis script 2026-05-24 18:44:08 -04:00
build-wasm.sh feat(acb-api): implement bot registration, job coordination, and replay endpoints per plan §12 Phase 4 2026-04-21 08:58:42 -04:00
cloudflare-setup.sh feat(scripts): add Cloudflare setup and verification scripts 2026-03-29 14:50:08 -04:00
configure-dns.sh docs(scripts): add DNS configuration script with Cloudflare API 2026-03-29 20:12:26 -04:00
deploy-pages.sh docs(phase6): add deployment checklist and make scripts executable 2026-04-08 17:29:02 -04:00
generate-test-replays.sh fix(scripts): add test replay generation and R2 upload tools 2026-05-24 21:54:36 -04:00
README.md fix(scripts): add test replay generation and R2 upload tools 2026-05-24 21:54:36 -04:00
setup-r2.sh feat(scripts): add R2 bucket setup script with custom domain config 2026-04-06 06:42:53 -04:00
upload-test-replays.sh fix(scripts): add test replay generation and R2 upload tools 2026-05-24 21:54:36 -04:00
verify-combat-density.sh fix(script): use 2 cores per player in combat density verification 2026-05-24 21:07:25 -04:00
verify-deployment.sh feat(scripts): add Cloudflare setup and verification scripts 2026-03-29 14:50:08 -04:00

Scripts

This directory contains utility scripts for the AI Code Battle project.

Test Replay Management

Problem

The web viewer at /watch/replay loads replays from the R2 bucket (acb-data) via the Pages Function at web/functions/r2/[[path]].ts. The matches/index.json file lists test matches, but the corresponding replay files were never uploaded to R2, causing 404 errors.

Solution

Two scripts are provided to generate and upload test replays:

1. generate-test-replays.sh

Generates all test replays that match the entries in web/public/data/matches/index.json:

bash scripts/generate-test-replays.sh

This creates test-replays/*.json.gz files with proper match IDs.

2. upload-test-replays.sh

Uploads the generated replays to the R2 bucket:

# Install wrangler first (one-time)
npm install -g wrangler
wrangler login

# Upload the replays
bash scripts/upload-test-replays.sh

Verification

After uploading, verify the replays are accessible:

curl -I https://r2.aicodebattle.com/replays/m_test_upset_v1.json.gz

Or test directly in the viewer: https://ai-code-battle.pages.dev/#/watch/replay?url=/r2/replays/m_test_upset_v1.json.gz

R2 Bucket Configuration

  • Bucket Name: acb-data
  • Binding: ACB_BUCKET (configured in web/wrangler.toml)
  • Custom Domain: r2.aicodebattle.com
  • Public URL: https://r2.aicodebattle.com/

Expected R2 Layout

acb-data/
├── replays/           # Match replay JSON files (gzipped)
│   ├── m_test_upset_v1.json.gz
│   ├── m_test_6p_v1.json.gz
│   └── ...
├── matches/           # Per-match metadata
├── thumbnails/        # Match thumbnails
├── cards/            # Bot profile cards
└── evolution/        # Evolution live feed

Error Handling

The replay viewer (web/src/pages/replay.ts) already has proper error handling:

  • Checks response.ok before parsing JSON
  • Displays user-visible error messages via showLoadError()

No additional error handling code is needed.