Files
kappa 1e750a863b refactor: 추천 시스템 제거
삭제된 파일:
- src/routes/recommend.ts
- src/services/recommendation.ts
- src/services/recommendation.test.ts
- src/services/stackConfig.ts
- src/services/regionFilter.ts

수정된 파일:
- src/index.ts: /recommend 라우트 제거
- src/routes/index.ts: handleRecommend export 제거
- src/constants.ts: RECOMMENDATIONS TTL, rate limit 제거
- src/middleware/rateLimit.ts: /recommend 설정 제거
- src/types.ts: 추천 관련 타입 제거
- scripts/e2e-tester.ts: recommend 시나리오 제거
- scripts/api-tester.ts: recommend 테스트 제거

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 00:35:59 +09:00
..

API Testing Scripts

This directory contains two types of API testing scripts:

  • api-tester.ts: Endpoint-level testing (unit/integration)
  • e2e-tester.ts: End-to-end scenario testing (workflow validation)

e2e-tester.ts

End-to-End testing script that validates complete user workflows against the deployed production API.

Quick Start

# Run all scenarios
npm run test:e2e

# Dry run (preview without actual API calls)
npm run test:e2e:dry

# Run specific scenario
npx tsx scripts/e2e-tester.ts --scenario wordpress
npx tsx scripts/e2e-tester.ts --scenario budget

Scenarios

Scenario 1: WordPress Server Recommendation

Flow: Recommendation → Detail Lookup → Validation

  1. POST /recommend with WordPress stack (nginx, php-fpm, mysql)
  2. Extract instance_id from first recommendation
  3. GET /instances to fetch detailed specs
  4. Validate specs meet requirements (memory >= 3072MB, vCPU >= 2)

Run: npx tsx scripts/e2e-tester.ts --scenario wordpress


Flow: Price Filter → Validation

  1. GET /instances?max_price=50&sort_by=price&order=asc
  2. Validate all results are within budget ($50/month)
  3. Validate ascending price sort order

Run: npx tsx scripts/e2e-tester.ts --scenario budget


Scenario 3: Cross-Region Price Comparison

Flow: Multi-Region Query → Price Analysis

  1. GET /instances?region=ap-northeast-1 (Tokyo)
  2. GET /instances?region=ap-northeast-2 (Seoul)
  3. Calculate average prices and compare regions

Run: npx tsx scripts/e2e-tester.ts --scenario region


Scenario 4: Provider Sync Verification

Flow: Sync → Health Check → Data Validation

  1. POST /sync with provider: linode
  2. GET /health to verify sync_status
  3. GET /instances?provider=linode to confirm data exists

Run: npx tsx scripts/e2e-tester.ts --scenario sync


Scenario 5: Rate Limiting Test

Flow: Burst Requests → Rate Limit Detection

  1. Send 10 rapid requests to /instances
  2. Check for 429 Too Many Requests response
  3. Verify Retry-After header

Run: npx tsx scripts/e2e-tester.ts --scenario ratelimit


E2E Command Line Options

Run All Scenarios:

npm run test:e2e

Run Specific Scenario:

npx tsx scripts/e2e-tester.ts --scenario <name>

Available scenarios: wordpress, budget, region, sync, ratelimit

Dry Run (Preview Only):

npm run test:e2e:dry

Combine Options:

npx tsx scripts/e2e-tester.ts --scenario wordpress --dry-run

E2E Example Output

🎬 E2E Scenario Tester
================================
API: https://cloud-instances-api.kappa-d8e.workers.dev

▶️  Scenario 1: WordPress Server Recommendation → Detail Lookup
  Step 1: Request WordPress server recommendation...
    ✅ POST /recommend - 200 OK (150ms)
    Recommended: Linode 4GB ($24/mo) in Tokyo
  Step 2: Fetch instance details...
    ✅ GET /instances - 80ms
  Step 3: Validate specs...
    ✅ Memory: 4096MB >= 3072MB required
    ✅ vCPU: 2 >= 2 required
  ✅ Scenario PASSED (230ms)

================================
📊 E2E Report
  Scenarios: 1
  Passed: 1 ✅
  Failed: 0 ❌
  Total Duration: 0.2s

E2E Exit Codes

  • 0 - All scenarios passed
  • 1 - One or more scenarios failed

api-tester.ts

Comprehensive API endpoint tester for the Cloud Instances API.

Features

  • Tests all API endpoints with various parameter combinations
  • Colorful console output with status indicators (⚠️)
  • Response time measurement for each test
  • Response schema validation
  • Support for filtered testing (specific endpoints)
  • Verbose mode for detailed response inspection
  • Environment variable support for API configuration

Usage

Basic Usage

Run all tests:

npx tsx scripts/api-tester.ts

Filter by Endpoint

Test only specific endpoint:

npx tsx scripts/api-tester.ts --endpoint=/health
npx tsx scripts/api-tester.ts --endpoint=/instances
npx tsx scripts/api-tester.ts --endpoint=/sync
npx tsx scripts/api-tester.ts --endpoint=/recommend

Verbose Mode

Show full response bodies:

npx tsx scripts/api-tester.ts --verbose

Combine with endpoint filter:

npx tsx scripts/api-tester.ts --endpoint=/instances --verbose

Environment Variables

Override API URL and key:

API_URL=https://my-api.example.com API_KEY=my-secret-key npx tsx scripts/api-tester.ts

Test Coverage

/health Endpoint

  • GET without authentication
  • GET with authentication
  • Response schema validation

/instances Endpoint

  • Basic query (no filters)
  • Provider filter (linode, vultr, aws)
  • Memory filter (min_memory_gb, max_memory_gb)
  • vCPU filter (min_vcpu, max_vcpu)
  • Price filter (max_price)
  • GPU filter (has_gpu=true)
  • Sorting (sort_by=price, order=asc/desc)
  • Pagination (limit, offset)
  • Combined filters
  • Invalid provider (error case)
  • No authentication (error case)

/sync Endpoint

  • Linode provider sync
  • Invalid provider (error case)
  • No authentication (error case)

/recommend Endpoint

  • Basic recommendation (nginx + mysql, small scale)
  • With budget constraint
  • Large scale deployment
  • Multiple stack components
  • Invalid stack (error case)
  • Invalid scale (error case)
  • No authentication (error case)

Example Output

🧪 Cloud Instances API Tester
================================
Target: https://cloud-instances-api.kappa-d8e.workers.dev
API Key: 0f955192075f7d36b143...

📍 Testing /health
  ✅ GET /health (no auth) - 200 (45ms)
  ✅ GET /health (with auth) - 200 (52ms)

📍 Testing /instances
  ✅ GET /instances (basic) - 200 (120ms)
  ✅ GET /instances?provider=linode - 200 (95ms)
  ✅ GET /instances?min_memory_gb=4 - 200 (88ms)
  ✅ GET /instances?min_vcpu=2&max_vcpu=8 - 200 (110ms)
  ✅ GET /instances?max_price=50 - 200 (105ms)
  ✅ GET /instances?has_gpu=true - 200 (98ms)
  ✅ GET /instances?sort_by=price&order=asc - 200 (115ms)
  ✅ GET /instances?limit=10&offset=0 - 200 (92ms)
  ✅ GET /instances (combined) - 200 (125ms)
  ✅ GET /instances?provider=invalid (error) - 400 (65ms)
  ✅ GET /instances (no auth - error) - 401 (55ms)

📍 Testing /sync
  ✅ POST /sync (linode) - 200 (2500ms)
  ✅ POST /sync (no auth - error) - 401 (60ms)
  ✅ POST /sync (invalid provider - error) - 200 (85ms)

📍 Testing /recommend
  ✅ POST /recommend (nginx+mysql) - 200 (150ms)
  ✅ POST /recommend (with budget) - 200 (165ms)
  ✅ POST /recommend (large scale) - 200 (175ms)
  ✅ POST /recommend (invalid stack - error) - 200 (80ms)
  ✅ POST /recommend (invalid scale - error) - 200 (75ms)
  ✅ POST /recommend (no auth - error) - 401 (58ms)

================================
📊 Test Report
  Total: 24 tests
  Passed: 24 ✅
  Failed: 0 ❌
  Duration: 4.5s

Exit Codes

  • 0: All tests passed
  • 1: One or more tests failed or fatal error occurred

Notes

  • Tests are designed to be non-destructive (safe to run against production)
  • Sync endpoint tests use only the 'linode' provider to minimize impact
  • Response validation checks basic structure and required fields
  • Timing measurements include network latency
  • Color output is optimized for dark terminal themes