Skip to content

Conversation

@andreasjansson
Copy link
Collaborator

Deploy real workers to Cloudflare infrastructure for e2e testing, replacing local wrangler dev. This catches issues that local testing can't: R2 bucket mounting, container cold starts, Access auth flows.

Infrastructure (test/e2e/fixture/server/)

  • Terraform: Creates R2 bucket + service token (unique per test run)
  • create-access-app: Creates Access app via API after worker deploy
  • deploy: Generates dynamic wrangler config for unique container names
  • start/stop: Orchestrate full lifecycle with proper cleanup

Access protection

  • Access app protects worker URL externally
  • Service Auth policy for automated tests (service token headers)
  • Allow policy for @cloudflare.com emails (manual debugging)
  • Playwright sets headers via page.context().setExtraHTTPHeaders()

Test flow

  1. Terraform creates R2 bucket + service token
  2. Deploy worker with unique name (timestamp + random)
  3. Create Access app via API (must be after worker exists)
  4. Start browser, navigate to worker, wait for 'Pairing required'
  5. Video captures loading screen through full test
  6. Teardown: Access app → worker → R2 bucket → service token

Code changes

  • src/config.ts: getR2BucketName() for configurable bucket
  • src/gateway/r2.ts: Uses configurable bucket name
  • src/types.ts: Added R2_BUCKET_NAME to MoltbotEnv

GitHub Actions

  • Updated workflow with Terraform setup
  • Infrastructure secrets use E2E_ prefix
  • E2E_TEST_RUN_ID uses run_id + matrix name for isolation

Documentation

  • test/e2e/README.md: Comprehensive architecture docs
  • test/e2e/.dev.vars.example: Credential setup instructions

Deploy real workers to Cloudflare infrastructure for e2e testing,
replacing local wrangler dev. This catches issues that local testing
can't: R2 bucket mounting, container cold starts, Access auth flows.

## Infrastructure (test/e2e/fixture/server/)
- Terraform: Creates R2 bucket + service token (unique per test run)
- create-access-app: Creates Access app via API after worker deploy
- deploy: Generates dynamic wrangler config for unique container names
- start/stop: Orchestrate full lifecycle with proper cleanup

## Access protection
- Access app protects worker URL externally
- Service Auth policy for automated tests (service token headers)
- Allow policy for @cloudflare.com emails (manual debugging)
- Playwright sets headers via page.context().setExtraHTTPHeaders()

## Test flow
1. Terraform creates R2 bucket + service token
2. Deploy worker with unique name (timestamp + random)
3. Create Access app via API (must be after worker exists)
4. Start browser, navigate to worker, wait for 'Pairing required'
5. Video captures loading screen through full test
6. Teardown: Access app → worker → R2 bucket → service token

## Code changes
- src/config.ts: getR2BucketName() for configurable bucket
- src/gateway/r2.ts: Uses configurable bucket name
- src/types.ts: Added R2_BUCKET_NAME to MoltbotEnv

## GitHub Actions
- Updated workflow with Terraform setup
- Infrastructure secrets use E2E_ prefix
- E2E_TEST_RUN_ID uses run_id + matrix name for isolation

## Documentation
- test/e2e/README.md: Comprehensive architecture docs
- test/e2e/.dev.vars.example: Credential setup instructions

Required repo secrets:
- E2E_CLOUDFLARE_API_TOKEN, E2E_CF_ACCOUNT_ID, E2E_WORKERS_SUBDOMAIN
- E2E_CF_ACCESS_TEAM_DOMAIN, E2E_R2_ACCESS_KEY_ID, E2E_R2_SECRET_ACCESS_KEY
- AI_GATEWAY_API_KEY, AI_GATEWAY_BASE_URL (existing, for chat tests)
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

E2E Test Recording (discord)

✅ Tests passed

E2E Test Video

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

E2E Test Recording (base)

✅ Tests passed

E2E Test Video

@github-actions
Copy link

github-actions bot commented Feb 3, 2026

E2E Test Recording (telegram)

✅ Tests passed

E2E Test Video

@andreasjansson andreasjansson merged commit 36e49be into main Feb 3, 2026
7 checks 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