tasks.md 13 KB

Tasks: 通用HTTP客户端多平台账户管理

Input: Design documents from /Users/he/projects/binance-api/specs/002-httpclient-http-api/ Prerequisites: plan.md, research.md, data-model.md, contracts/, quickstart.md

Execution Flow (main)

1. Load plan.md from feature directory ✅
   → Tech stack: TypeScript + Node.js 18.12+, Jest, Winston, https-proxy-agent
   → Structure: Integrated into existing src/ directory, not independent library
2. Load design documents ✅
   → data-model.md: 6 core entities (HttpClient, PlatformAccount, etc.)
   → contracts/: 2 contract files (http-client, platform-adapter)
   → quickstart.md: 4 usage scenarios + extensive proxy configuration examples
3. Generate tasks by category ✅
   → Setup: project structure, dependencies, TypeScript types
   → Tests: contract tests, integration scenarios, platform adapters
   → Core: entities, adapters, client implementation
   → Integration: credential manager, proxy support, logging
   → Polish: performance verification, documentation, quickstart validation
4. Apply task rules ✅
   → Different files = mark [P] for parallel
   → Tests before implementation (TDD)
   → Integration architecture with existing codebase
5. Number tasks sequentially (T001-T037) ✅
6. Generate dependency graph ✅
7. Create parallel execution examples ✅

Format: [ID] [P?] Description

  • [P]: Can run in parallel (different files, no dependencies)
  • Include exact file paths in descriptions

Path Conventions

  • Source: src/ (integrated into existing codebase)
  • Tests: tests/ (using existing structure)
  • Types: src/types/ (new directory)
  • Adapters: src/adapters/ (new directory)

Phase 3.1: Setup

  • T001 Create type definitions directory src/types/ with httpClient.ts, platformAdapter.ts, and common.ts
  • T002 Create adapters directory src/adapters/ with base/, pacifica/, aster/, and binance/ subdirectories
  • T003 [P] Update project dependencies in package.json to include https-proxy-agent and ensure winston is available
  • T004 [P] Configure TypeScript paths in tsconfig.json for new src/types/ and src/adapters/ directories

Phase 3.2: Tests First (TDD) ⚠️ MUST COMPLETE BEFORE 3.3

CRITICAL: These tests MUST be written and MUST FAIL before ANY implementation

Contract Tests [P]

  • T005 [P] Contract test IUniversalHttpClient.request() in tests/contract/httpClient.contract.test.ts
  • T006 [P] Contract test IUniversalHttpClient.batchRequest() in tests/contract/httpClientBatch.contract.test.ts
  • T007 [P] Contract test IUniversalHttpClient.registerPlatform() in tests/contract/platformRegistration.contract.test.ts
  • T008 [P] Contract test IPlatformAdapter.request() for all platforms in tests/contract/platformAdapter.contract.test.ts
  • T009 [P] Contract test IPlatformAdapter.prepareRequest() authentication in tests/contract/platformAuth.contract.test.ts
  • T010 [P] Contract test ProxyConfig functionality in tests/contract/proxyConfig.contract.test.ts

Integration Tests [P]

  • T011 [P] Integration test scenario 1: multi-platform balance query in tests/integration/multiPlatformBalance.test.ts
  • T012 [P] Integration test scenario 2: platform-specific orders in tests/integration/platformOrders.test.ts
  • T013 [P] Integration test scenario 3: proxy configuration scenarios in tests/integration/proxyScenarios.test.ts
  • T014 [P] Integration test scenario 4: performance monitoring in tests/integration/performanceMonitoring.test.ts

Phase 3.3: Core Implementation (ONLY after tests are failing)

Type Definitions [P]

  • T015 [P] HttpClient core entity types in src/types/httpClient.ts (HttpClient, HttpClientRequest, HttpClientResponse, RequestOptions, TimeoutConfig, RetryConfig)
  • T016 [P] PlatformAccount and authentication types in src/types/platformAdapter.ts (IPlatformAdapter, PlatformRequest, PlatformResponse, AuthConfig, ProxyConfig)
  • T017 [P] HTTPRequest and HTTPResponse types in src/types/common.ts (HTTPRequest, HTTPResponse, AuthenticationContext, PlatformConfiguration, PerformanceMetrics)
  • T018 [P] ProxyConfig and proxy-related types in src/types/common.ts (ProxyStatus, ProxyControlOptions, RateLimitInfo)
  • T019 [P] Error handling types in src/types/common.ts (HttpClientError, PlatformError, ValidationError)

Core Classes

  • T020 UniversalHttpClient main class in src/utils/universalHttpClient.ts (implements IUniversalHttpClient)
  • T021 PlatformAdapterFactory base class in src/adapters/base/PlatformAdapterFactory.ts
  • T022 BaseAdapter abstract class in src/adapters/base/BaseAdapter.ts

Platform Adapters [P]

  • T023 [P] PacificaAdapter implementation in src/adapters/pacifica/PacificaAdapter.ts (Ed25519 authentication)
  • T024 [P] AsterAdapter implementation in src/adapters/aster/AsterAdapter.ts (EIP-191 authentication)
  • T025 [P] BinanceAdapter implementation in src/adapters/binance/BinanceAdapter.ts (HMAC-SHA256 authentication)

Advanced Features

  • T026 ProxyManager for proxy control and rotation in src/utils/ProxyManager.ts
  • T027 ConnectionPoolManager for connection optimization in src/utils/ConnectionPoolManager.ts
  • T028 HealthCheckManager for platform monitoring in src/utils/HealthCheckManager.ts
  • T029 BatchRequestProcessor for concurrent requests in src/utils/BatchRequestProcessor.ts

Phase 3.4: Integration

  • T030 Credential manager integration in src/utils/universalHttpClient.ts (import from libs/credential-manager)
  • T031 Winston logging setup with structured logs in src/utils/universalHttpClient.ts (integrate with existing logger)
  • T032 Timeout and retry logic configuration in src/utils/RetryManager.ts
  • T033 Platform configuration validation in src/utils/ConfigValidator.ts

Phase 3.5: Polish

Unit Tests [P]

  • T034 [P] Unit tests for proxy rotation in tests/unit/proxyRotation.test.ts
  • T035 [P] Unit tests for error handling in tests/unit/errorHandling.test.ts
  • T036 [P] Unit tests for connection pooling in tests/unit/connectionPool.test.ts

Documentation & Validation

  • T037 Performance verification and quickstart validation in tests/integration/quickstartValidation.test.ts

Dependencies

Sequential Dependencies:

  • Setup (T001-T004) before all other phases
  • Tests (T005-T014) before implementation (T015-T033)
  • Type definitions (T015-T019) before core classes (T020-T022)
  • Core classes (T020-T022) before platform adapters (T023-T025)
  • Platform adapters (T023-T025) before advanced features (T026-T029)
  • Implementation (T015-T033) before polish (T034-T037)

Blocking Dependencies:

  • T020 (UniversalHttpClient) blocks T026, T027, T028, T029
  • T021 (PlatformAdapterFactory) blocks T023, T024, T025
  • T030 (Credential integration) blocks T023, T024, T025
  • T031 (Logging setup) blocks T020

Parallel Execution Examples

Contract Tests (T005-T010)

# Launch all contract tests together:
Task: "Contract test IUniversalHttpClient.request() in tests/contract/httpClient.contract.test.ts"
Task: "Contract test IUniversalHttpClient.batchRequest() in tests/contract/httpClientBatch.contract.test.ts"
Task: "Contract test IUniversalHttpClient.registerPlatform() in tests/contract/platformRegistration.contract.test.ts"
Task: "Contract test IPlatformAdapter.request() for all platforms in tests/contract/platformAdapter.contract.test.ts"
Task: "Contract test IPlatformAdapter.prepareRequest() authentication in tests/contract/platformAuth.contract.test.ts"
Task: "Contract test ProxyConfig functionality in tests/contract/proxyConfig.contract.test.ts"

Integration Tests (T011-T014)

# Launch all integration tests together:
Task: "Integration test scenario 1: multi-platform balance query in tests/integration/multiPlatformBalance.test.ts"
Task: "Integration test scenario 2: platform-specific orders in tests/integration/platformOrders.test.ts"
Task: "Integration test scenario 3: proxy configuration scenarios in tests/integration/proxyScenarios.test.ts"
Task: "Integration test scenario 4: performance monitoring in tests/integration/performanceMonitoring.test.ts"

Type Definitions (T015-T019)

# Launch all type definition tasks together:
Task: "HttpClient core entity types in src/types/httpClient.ts"
Task: "PlatformAccount and authentication types in src/types/platformAdapter.ts"
Task: "HTTPRequest and HTTPResponse types in src/types/common.ts"
Task: "ProxyConfig and proxy-related types in src/types/common.ts"
Task: "Error handling types in src/types/common.ts"

Platform Adapters (T023-T025)

# Launch all platform adapter implementations together:
Task: "PacificaAdapter implementation in src/adapters/pacifica/PacificaAdapter.ts"
Task: "AsterAdapter implementation in src/adapters/aster/AsterAdapter.ts"
Task: "BinanceAdapter implementation in src/adapters/binance/BinanceAdapter.ts"

Unit Tests (T034-T036)

# Launch all unit tests together:
Task: "Unit tests for proxy rotation in tests/unit/proxyRotation.test.ts"
Task: "Unit tests for error handling in tests/unit/errorHandling.test.ts"
Task: "Unit tests for connection pooling in tests/unit/connectionPool.test.ts"

Task Implementation Guidelines

Setup Tasks (T001-T004)

  • Integrate with existing project structure in src/
  • Ensure TypeScript configuration supports new directories
  • Use existing Jest configuration and testing infrastructure
  • Maintain compatibility with current build process

Contract Tests (T005-T010)

  • Import interface definitions from contracts/ documents
  • Write tests that MUST FAIL initially (no implementation exists)
  • Cover all public methods defined in http-client.contract.md and platform-adapter.contract.md
  • Test proxy configuration scenarios from quickstart.md
  • Use existing testing patterns from the codebase

Type Definitions (T015-T019)

  • Implement interfaces from contracts/ exactly as specified
  • Include all entities from data-model.md (6 core entities)
  • Support TypeScript strict mode compliance
  • Organize types logically across httpClient.ts, platformAdapter.ts, and common.ts files

Platform Adapters (T023-T025)

  • Implement IPlatformAdapter interface exactly
  • Integrate with libs/credential-manager for authentication
  • Support platform-specific authentication: Ed25519 (Pacifica), EIP-191 (Aster), HMAC-SHA256 (Binance)
  • Include platform-specific error mapping as defined in contracts
  • Use existing httpClient.ts as reference for HTTP implementation patterns

Integration Tests (T011-T014)

  • Validate all 4 quickstart.md scenarios work end-to-end
  • Test with real API endpoints (as specified in plan.md constitution check)
  • Include performance benchmarks (<100ms response time)
  • Verify extensive proxy switching scenarios from quickstart.md
  • Cover proxy pool, failover, and health checking functionality

Advanced Features (T026-T029)

  • Implement proxy pool management with round-robin, health checks, and failover
  • Support connection pooling for performance optimization
  • Provide comprehensive health monitoring across all platforms
  • Enable batch request processing with concurrency control

Validation Checklist

GATE: Checked before task completion

  • All contracts (2 files) have corresponding tests (T005-T010)
  • All entities (6 core entities) have type definitions (T015-T019)
  • All tests come before implementation (T005-T014 before T015+)
  • Parallel tasks truly independent (different files)
  • Each task specifies exact file path in src/ or tests/
  • No task modifies same file as another [P] task
  • Integration architecture maintained throughout (not independent library)
  • Platform extensibility requirements addressed (factory pattern)
  • Performance targets verified (T037, <100ms response time)
  • Integration with existing libs/credential-manager (T030)
  • Comprehensive proxy functionality (proxy pools, failover, health checks)

Notes

  • [P] tasks = different files, no dependencies
  • Verify tests fail before implementing (TDD)
  • Commit after each task completion
  • Maintain integration with existing codebase (not independent library)
  • Focus on extensibility per research.md (dynamic platform registration)
  • All proxy features must support extensive configuration scenarios from quickstart.md
  • Performance tests must verify <100ms response time goal
  • Use existing httpClient.ts patterns and winston logging setup

Success Criteria

Upon completion of all tasks:

  1. ✅ Integrated HTTP client functionality in src/utils/universalHttpClient.ts
  2. ✅ Support for 3 platforms (Pacifica, Aster, Binance) with platform adapters
  3. ✅ Easy platform extensibility via PlatformAdapterFactory
  4. ✅ All quickstart.md scenarios functional including extensive proxy configurations
  5. ✅ Performance targets met (<100ms, 1000+ concurrent)
  6. ✅ Comprehensive proxy support (pools, failover, health checks, rotation)
  7. ✅ Full integration with existing libs/credential-manager
  8. ✅ 90%+ test coverage with contract-first TDD methodology