CAS-382: Consolidate test-us into web app and API
Goal
Retire test-us as a standalone Cloudflare Workers app. Move the public-facing
HTTP endpoints into the main Python API worker and the queue consumer into a
dedicated packages/scan-worker TypeScript Worker. The React /try-me page
already exists; wire it to the main API.
Schema Note
test-us and api share the same D1 database but both define a scans table
with conflicting schemas. Resolution: add new tables with an anon_ prefix
via a fresh API migration. Rename references in the consumer accordingly.
Changes
1. api/ — Python Worker (new anonymous scan endpoints)
New migration (api/migrations/NNNN_anon_scans.sql):
anon_scans— anonymous scan records (ip_hash, turnstile_verified, ttl)anon_scan_findings— CVE findings per anon scananon_dockerfile_issues— Dockerfile lint issues per anon scananon_rate_limits— sliding-window rate limit (3/day per IP hash)
New route file (api/src/routes/anon_scans.py):
POST /api/v1/scans/anonymous— Turnstile verify → rate limit → enqueueGET /api/v1/scans/:scan_id/results— poll results, enforce 1-h TTL
New binding additions to api/wrangler.toml:
SCAN_QUEUE— queue producer (per env: dev / staging / production)ANON_ARTIFACTS— R2 bucket for anonymous scan result JSON (separate from CISCAN_ARTIFACTS)TURNSTILE_SECRET_KEY— secret note added to vars comment
index.py updates:
- Import and register
handle_post_anon_scan,handle_get_anon_scan_results - Add to
_EXACT_ROUTESand_PARAM_ROUTES
2. packages/scan-worker/ — TS Queue Consumer (renamed from test-us)
Keep only:
src/queue/consumer.ts— queue handler (update table names →anon_*)src/scanner/engine.ts— scan enginesrc/parsers/— lockfile parserssrc/db/— DB helpers (if any)src/types.ts— type definitionswrangler.toml— strip[assets], remove HTTP route bindings, keep D1 + R2 + queue consumerpackage.json— rename tocascadeguard-scan-worker
Remove:
src/routes/src/middleware/src/index.tsfetch handler (replace with consumer-only export)frontend/
Registered automatically via root "workspaces": ["packages/*"].
3. packages/web/ — React Frontend
src/pages/try-me/index.tsx: replaceTEST_US_APIconstant withVITE_API_BASE_URL(already defined). Endpoints move fromcascadeguard-test-us.workers.dev/api/v1/...→<API_BASE>/api/v1/....src/App.tsx: add/tryroute as alias forTryMePage(keep/try-mefor backward compat).
4. deploy.yaml — CI/CD
- Add
packages/scan-worker/**topush.pathsandpull_request.paths. - Add
deploy-scan-workerjob (wrangler deploy, mirrorsdeploy-apipattern).
5. Cleanup
- Delete
test-us/directory entirely. - Update any README references.
Definition of Done
-
/trypage inpackages/webhits main API endpoints -
POST /api/v1/scans/anonymousandGET /api/v1/scans/:scan_id/resultslive in Python API -
packages/scan-workerprocesses queue jobs (usesanon_*tables) -
test-us/removed - CI deploy includes scan-worker
- All CI checks pass