Skip to main content
Synced from the repo — do not edit here

Canonical source: docs/claude/debugging-tools.md. This page is generated by docs/scripts/sync-handbook.mjs. Edit the source file in the repo; changes appear here on the next build.

Database Debugging Tools + Development Scripts

CRITICAL TESTING RULE: Before telling the user a feature is "fixed" or "working", you MUST run a test tool to verify end-to-end functionality.

Exception: Basic UI-only fixes (styling, layout, text changes) don't require tool verification.

If no test tool exists: Create one before claiming the feature works.

Prerequisites

gcloud auth application-default login
gcloud config set project basis-hybrid

Available Tools

Located in basis-functions/tools/:

ToolPurpose
query-events.jsScheduled events, unavailability, cancelled bookings
query-clients.jsClinic users/members, search by name/email
query-transactions.jsPayment transactions, activity logs
query-availability.jsStaff V1 blocks and V2 availability rules
query-memberships.jsMembership types and client subscriptions
test-booking.jsBooking flow integrity — slots, constraints, dry-run
test-unavailability-date.jsDate handling fix for unavailability
test-unavailability-createdby.jsVerify createdByUid field on events
test-unavailability-transactions.jsTransaction records for update/cancel
test-edit-single-instance.jsEdit single occurrence without affecting series
test-packages.jsPackage memberships — usage counts, session consumption
test-group-attendee.jsGroup class management — list events, simulate changes
test-reschedule.jsReschedule — list events, dry-run, move event, verify duration
test-protocol-presets.jsProtocol presets — validate structure across platforms
test-payment-sandbox.jsApple payment testing — test cards, Stripe config
diagnose_booking.pyBasis Web booking — availability, clinicians, service config

Test Clinic & Accounts

Demo Clinic ID: axuk-khwf-prkr (use --clinic axuk for short)

Developer UID: GoOU3d2QcyRZMD83IhbQeIclpwh2 (System Admin — real user data available for integration testing)

For agent/PR testing: Use the demo clinic with seeded data (5 demo users, services, appointments, memberships). See seed_demo_clinic.cjs. For System Admin testing: Use the developer UID — but be aware System Admin bypasses permission checks, so RBAC bugs won't surface.

Seeded Demo Data (via seed_demo_clinic.cjs)

DataDetails
ServicesInitial Consultation ($299/60min), Follow-up ($149/30min), Lab Review ($199/45min)
LocationMain Office (San Francisco, CA)
MembershipsBasic ($99/mo), Premium ($299/mo)
Demo Users5 users (demo_user_001 through demo_user_005), each with 2 appointments (1 past, 1 future)
Feature FlagslabsEnabled, supplementsEnabled, marketplaceEnabled, isDemoClinic
# Re-seed demo clinic (dry run first)
cd basis-functions
node scripts/seed_demo_clinic.cjs --clinic axuk-khwf-prkr
node scripts/seed_demo_clinic.cjs --clinic axuk-khwf-prkr --apply

Synthetic Test Usage

The synthetic tests (.github/scripts/synthetic_*.py) use this clinic and data. Test constants:

CLINIC_ID = 'axuk-khwf-prkr'
DEV_UID = 'GoOU3d2QcyRZMD83IhbQeIclpwh2'
DEMO_USER = 'demo_user_001' # James Wilson — active client

Quick Reference

cd basis-functions

# List all clinics
node tools/query-events.js --list-clinics

# Find a staff member by name
node tools/query-events.js --find-staff kekoa

# Get clinic info with staff list
node tools/query-events.js --clinic xdoz --info

# Query events for a staff member
node tools/query-events.js --clinic xdoz --staff <uid> --start 2026-02-20 --end 2026-03-01

# Only cancelled events
node tools/query-events.js --clinic xdoz --staff <uid> --canceled-only

# Check staff availability rules
node tools/query-availability.js --clinic xdoz --staff <uid>

# Check rules on specific date
node tools/query-availability.js --clinic xdoz --staff <uid> --date 2026-02-23

# Get client membership details
node tools/query-memberships.js --clinic xdoz --client <uid>

# List recent transactions
node tools/query-transactions.js --clinic xdoz --recent

# Test unavailability date handling
node tools/test-unavailability-date.js --clinic axuk --staff <uid> --date 2026-02-23 --dry-run

# Test booking flow — show services/locations/staff
node tools/test-booking.js --clinic axuk --info

# Test booking flow — check available slots
node tools/test-booking.js --clinic axuk --service <service_id> --slots

# Test booking flow — validate if booking would succeed
node tools/test-booking.js --clinic axuk --service <service_id> --location <loc_id> --client <uid> --validate

# Test package memberships
node tools/test-packages.js --clinic axuk --list-packages
node tools/test-packages.js --clinic axuk --client <uid> --usage

# Test group attendee management
node tools/test-group-attendee.js --clinic axuk --list-group-events
node tools/test-group-attendee.js --clinic axuk --event <event_id> --client <client_id> --status confirmed --dry-run

# Test reschedule
node tools/test-reschedule.js --clinic <id> --list
node tools/test-reschedule.js --clinic <id> --event <id> --dry-run

# Protocol preset validation
node tools/test-protocol-presets.js --clinic axuk --client <uid> --validate

# Diagnose Basis Web booking issues
python scripts/diagnose_booking.py --clinic xdoz
python scripts/diagnose_booking.py --clinic xdoz --service "Saturday Sweat"
python scripts/diagnose_booking.py --clinic xdoz --user <user_uid>

Common Debugging Scenarios

IssueCommand
Event not showingquery-events.js --clinic <id> --staff <uid> — check hidden and status
Staff unavailability wrongquery-availability.js --clinic <id> --staff <uid> --date <date>
Cancelled appointmentsquery-events.js --clinic <id> --staff <uid> --canceled-only
Payment issuesquery-transactions.js --clinic <id> --client <uid>
Booking constraintsquery-memberships.js --clinic <id> --client <uid>
Package usage not workingtest-packages.js --clinic <id> --client <uid> --usage
Group attendee managementtest-group-attendee.js --clinic <id> --list-group-events
Reschedule not workingtest-reschedule.js --clinic <id> --list -> pick event -> --dry-run
Booking not workingtest-booking.js --clinic <id> --service <svc> --location <loc> --client <uid> --validate
No slots showingtest-booking.js --clinic <id> --service <svc> --slots
Protocol presets missingtest-protocol-presets.js --clinic <id> --client <uid> --validate
Apple payment testingtest-payment-sandbox.js --apple-cards
Basis Web dates wrongpython scripts/diagnose_booking.py --clinic <id> --service <name>
Basis Web staff missingpython scripts/diagnose_booking.py --clinic <id>
Basis Web credits not consumingpython scripts/diagnose_booking.py --clinic <id> --user <uid>

Tip: Partial clinic IDs work! Use --clinic xdoz instead of full ID.

Development Scripts

Metric Trend Verification

cd /Users/G/basis/basis-functions/functions
source venv/bin/activate

# Verify HR Zone 5 trends (week view)
python ../scripts/verify_metric_trends.py --uid USER_ID --metric hrzone5 --period week

# Verify resting heart rate (month view)
python ../scripts/verify_metric_trends.py --uid USER_ID --metric rhr --period month

Arguments: --uid (required), --metric (e.g., hrzone5, ste, rhr, sleep), --period (week/month/3months/year), --no-compare (skip previous period comparison)

Zone Minutes Debugging

cd /Users/G/basis/basis-functions/functions
source venv/bin/activate
python ../scripts/debug_zone_minutes.py

Note: Edit the script to change the target user ID and clinic ID.