stock-bot/docs/development/backlog/tasks/CL06.md

4.8 KiB

CL06 — Use shared dataset response schemas and eligibility checks in the workbench

Parent epic: E10. Priority/severity: P2 / Medium. Complexity: M. Specialization: Shared contracts and frontend validation.

Scheduling metadata: manifest. Read the cleanup execution contract. Implementation and validated commits were authorized after planning; scheduling and completion evidence live in the manifest.

User story and outcome

As a researcher, I want the browser and API to interpret dataset responses consistently, so valid datasets do not fail because independent schema copies drift.

Expected benefit: Removes a large inline manifest schema and repeated eligibility rules from the backtest client.

Verified evidence

Implementation scope

  • Reuse the CL05 browser-safe structural schemas in dataset catalog/preparation response parsing.
  • Centralize workbench-specific structural eligibility checks used by response consistency checks and admission, without broadening the single-asset/single-series policy.
  • Keep expected-request/hash identity checks at the client boundary and full dataset-byte/hash validation at execution. Shared shape validation must not pretend to authenticate dataset content.
  • Preserve existing prepared/stored-source response contracts, explicit unavailable reasons and immutable retained inputs.

Likely existing files/modules:

  • apps/stock/web-app/src/features/backtest/services/backtestApiV2.ts
  • apps/stock/web-api/src/services/canonical-research.service.ts
  • apps/stock/config/src/contracts/canonical-research.ts
  • test/integration/dataset-source-preparation-ui.test.tsx
  • test/integration/canonical-workbench.test.tsx

Prerequisite output: libs/research/src/dataset-contracts.ts is proposed by CL05 and must exist before this story begins; it is not present at this audit baseline.

Exclusions

  • No new datasets UI, automatic calendar assumptions, changed content hashes or wider execution eligibility.
  • No browser hashing of full datasets, client-authoritative eligibility or weakened worker checks.

Dependencies and ownership

Implementation prerequisites: CL05.

Write locks: dataset-response-contracts, web-backtest-api.

Parallel execution: After CL05. Disjoint from CL07, which initially excludes backtestApiV2.ts; reserve this client file explicitly.

Acceptance criteria

  1. Calendar/series/bounds/action response structures have one shared schema definition used by the server and browser.
  2. Valid server preparation and catalog fixtures are accepted by the browser; malformed or mismatched identities still fail.
  3. Eligibility and unavailable-reason consistency match between UI response parsing and server admission for supported and unsupported fixtures.
  4. A browser build of this client contains no native/file/database or Node hashing dependencies.
  5. Stored snapshots, normalized bars, v1/v2 hash fixtures and exact run provenance remain unchanged.

Mandatory verification

Use existing workspace builds. Tests requiring PostgreSQL/Redis must use explicitly disposable safety fixtures.

bun test test/integration/dataset-source-preparation-ui.test.tsx test/integration/canonical-workbench.test.tsx
bun test test/integration/dataset-source-preparation.test.ts test/integration/historical-dataset-v2.test.ts
bun test scripts/test/architecture.test.ts
bun run typecheck

Required regression cases: eligible/unsupported series, missing calendars/actions, malformed fields, corrupt response hashes, expected-request mismatch and browser dependency boundaries.

Risks and definition of done

Manifest validation and full content integrity are different boundaries. Consolidate shared structures without dropping contextual checks or treating a catalog entry as proof that retained bars are valid.

Done means the acceptance criteria and relevant checks pass, an independent review accepts the focused diff, and the integrator records exact test results and a commit/reference in the manifest. Preserve the compatibility and financial invariants in the cleanup execution contract.