tasks.md 9.9 KB

Tasks: HTTP客户端模块化重构

Input: Design documents from /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 5.1+, Node.js 18.12+, Jest 29.7+
   → Libraries: axios, ethers, tweetnacl, https-proxy-agent, winston
   → Structure: src/core/http-client/, src/adapters/, src/types/
2. Load design documents ✓:
   → data-model.md: 6 entities (HttpClient, PlatformAccount, HTTPRequest, HTTPResponse, AuthenticationContext, PlatformConfiguration)
   → contracts/: http-client.contract.md, platform-adapter.contract.md
   → research.md: Adapter pattern, credential-manager integration, performance optimization
3. Generate tasks by category:
   → Setup: TypeScript environment, ESLint config, credential integration
   → Tests: Contract tests, integration scenarios, performance validation
   → Core: HTTP client refactor, platform adapters, authentication integration
   → Integration: Credential-manager connection, proxy support, logging
   → Polish: Performance benchmarks, documentation, quality validation
4. Apply task rules: Different files = [P], TDD order maintained
5. Number tasks sequentially (T001-T032)
6. Validate completeness ✓

Format: [ID] [P?] Description

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

Phase 3.1: Setup

  • T001 Create src/core/http-client/ module directory structure per plan.md
  • T002 Initialize TypeScript strict mode configuration in src/core/http-client/tsconfig.json
  • T003 [P] Configure ESLint rules for import/extensions, import/order, import/no-unresolved in src/core/http-client/.eslintrc.json
  • T004 [P] Set up Jest test configuration for HTTP client module in tests/jest.config.http-client.js

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

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

  • T005 [P] Contract test IUniversalHttpClient.request() in tests/contract/http-client-core.contract.test.ts
  • T006 [P] Contract test IUniversalHttpClient.batchRequest() in tests/contract/http-client-batch.contract.test.ts
  • T007 [P] Contract test IUniversalHttpClient.registerPlatform() in tests/contract/http-client-platform.contract.test.ts
  • T008 [P] Contract test IPlatformAdapter.request() in tests/contract/platform-adapter-request.contract.test.ts
  • T009 [P] Contract test IPlatformAdapter.prepareRequest() in tests/contract/platform-adapter-auth.contract.test.ts
  • T010 [P] Contract test IPlatformAdapter.setProxyConfig() in tests/contract/platform-adapter-proxy.contract.test.ts
  • T011 [P] Integration test Pacifica account balance query in tests/integration/pacifica-balance.integration.test.ts
  • T012 [P] Integration test multi-platform concurrent requests in tests/integration/multi-platform-concurrent.integration.test.ts
  • T013 [P] Integration test credential-manager authentication in tests/integration/credential-auth.integration.test.ts
  • T014 [P] Integration test proxy configuration and routing in tests/integration/proxy-routing.integration.test.ts

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

  • T015 [P] Extend HttpClientRequest interface in src/types/httpClient.ts
  • T016 [P] Extend HttpClientResponse interface in src/types/httpClient.ts
  • T017 [P] Define IPlatformAdapter interface in src/types/platformAdapter.ts
  • T018 [P] Define IUniversalHttpClient interface in src/types/httpClientCore.ts
  • T019 Create HttpClientCore base class in src/core/http-client/HttpClientCore.ts
  • T020 Create PlatformAdapterFactory in src/core/http-client/PlatformAdapterFactory.ts
  • T021 Create AuthenticationManager in src/core/http-client/AuthenticationManager.ts
  • T022 [P] Enhance PacificaAdapter with credential-manager integration in src/adapters/pacifica/PacificaHttpAdapter.ts
  • T023 [P] Enhance AsterAdapter with credential-manager integration in src/adapters/aster/AsterHttpAdapter.ts
  • T024 [P] Enhance BinanceAdapter with credential-manager integration in src/adapters/binance/BinanceHttpAdapter.ts
  • T025 Refactor UniversalHttpClient to use HttpClientCore in src/utils/universalHttpClient.ts
  • T026 Implement createPlatformAdapter factory method in src/core/http-client/PlatformAdapterFactory.ts

Phase 3.4: Integration

  • T027 Connect AuthenticationManager to credential-manager SignerFactory in src/core/http-client/AuthenticationManager.ts
  • T028 Integrate proxy configuration from existing httpClient.ts in src/core/http-client/ProxyManager.ts
  • T029 Add performance monitoring and metrics collection in src/core/http-client/PerformanceMonitor.ts
  • T030 Integrate winston logging with structured request/response logging in src/core/http-client/HttpLogger.ts

Phase 3.5: Polish

  • T031 [P] Performance benchmark tests for <100ms response time in tests/performance/response-time.performance.test.ts
  • T032 [P] Unit tests for error handling and retry logic in tests/unit/error-handling.unit.test.ts
  • T033 [P] Unit tests for connection pooling in tests/unit/connection-pool.unit.test.ts
  • T034 [P] Update quickstart.md examples with new API in specs/002-httpclient-http-api/quickstart.md
  • T035 Run ESLint and fix all import/extensions violations across HTTP client module
  • T036 Validate TypeScript strict mode compliance and remove any 'any' types
  • T037 Execute quickstart scenarios from quickstart.md for acceptance validation

Dependencies

Critical Dependencies:

  • Setup (T001-T004) before all other phases
  • Contract tests (T005-T010) before implementation (T015-T026)
  • Integration tests (T011-T014) before implementation (T015-T026)
  • Core interfaces (T015-T018) before implementations (T019-T026)

Implementation Dependencies:

  • T019 (HttpClientCore) blocks T020, T021, T025
  • T020 (PlatformAdapterFactory) blocks T026
  • T021 (AuthenticationManager) blocks T027
  • T022-T024 (Platform adapters) can run in parallel
  • T025 (UniversalHttpClient refactor) needs T019, T020

Integration Dependencies:

  • T027 (credential-manager) needs T021
  • T028-T030 (supporting modules) can run in parallel
  • Polish phase (T031-T037) after all implementation

Parallel Execution Examples

# Phase 3.2: Launch contract tests together (all must fail initially)
Task: "Contract test IUniversalHttpClient.request() in tests/contract/http-client-core.contract.test.ts"
Task: "Contract test IUniversalHttpClient.batchRequest() in tests/contract/http-client-batch.contract.test.ts"
Task: "Contract test IUniversalHttpClient.registerPlatform() in tests/contract/http-client-platform.contract.test.ts"
Task: "Contract test IPlatformAdapter.request() in tests/contract/platform-adapter-request.contract.test.ts"

# Phase 3.3: Launch type definitions in parallel
Task: "Extend HttpClientRequest interface in src/types/httpClient.ts"
Task: "Define IPlatformAdapter interface in src/types/platformAdapter.ts"
Task: "Define IUniversalHttpClient interface in src/types/httpClientCore.ts"

# Phase 3.3: Launch platform adapters in parallel (after core interfaces)
Task: "Enhance PacificaAdapter with credential-manager integration in src/adapters/pacifica/PacificaHttpAdapter.ts"
Task: "Enhance AsterAdapter with credential-manager integration in src/adapters/aster/AsterHttpAdapter.ts"
Task: "Enhance BinanceAdapter with credential-manager integration in src/adapters/binance/BinanceHttpAdapter.ts"

# Phase 3.5: Launch polish tasks in parallel
Task: "Performance benchmark tests for <100ms response time in tests/performance/response-time.performance.test.ts"
Task: "Unit tests for error handling and retry logic in tests/unit/error-handling.unit.test.ts"
Task: "Unit tests for connection pooling in tests/unit/connection-pool.unit.test.ts"

Notes

  • [P] tasks: Different files, no dependencies, safe for parallel execution
  • TDD Order: All contract and integration tests (T005-T014) must fail before starting implementation
  • Credential Integration: Priority focus on integrating with existing src/core/credential-manager/
  • Performance Targets: <100ms response time, 99.9% availability, 1000+ concurrent requests
  • Quality Gates: ESLint compliance, TypeScript strict mode, no 'any' types
  • Architecture: Adapter pattern with credential-manager deep integration

Task Generation Rules Applied

  1. From Contracts:

    • http-client.contract.md → T005-T007 (core client tests)
    • platform-adapter.contract.md → T008-T010 (adapter tests)
  2. From Data Model:

    • HttpClient entity → T019 (HttpClientCore)
    • PlatformAccount entity → T022-T024 (platform adapters)
    • HTTPRequest/Response entities → T015-T016 (type definitions)
    • AuthenticationContext entity → T021 (AuthenticationManager)
  3. From Quickstart Scenarios:

    • Multi-platform balance query → T011 (Pacifica integration test)
    • Concurrent requests → T012 (multi-platform test)
    • Authentication flow → T013 (credential integration test)
    • Proxy configuration → T014 (proxy routing test)
  4. From Research Decisions:

    • Adapter pattern → T020 (PlatformAdapterFactory)
    • Performance optimization → T029 (PerformanceMonitor)
    • Credential-manager integration → T021, T027 (AuthenticationManager)

Validation Checklist ✓

  • All contracts have corresponding tests (T005-T010)
  • All entities have model/implementation tasks (T015-T026)
  • All tests come before implementation (Phase 3.2 → 3.3)
  • Parallel tasks are truly independent (different files)
  • Each task specifies exact file path
  • No task modifies same file as another [P] task
  • TDD approach maintained (tests fail before implementation)
  • Credential-manager integration covered (T013, T021, T027)
  • Performance requirements addressed (T031, T036, T037)