84 lines
5.7 KiB
Markdown
84 lines
5.7 KiB
Markdown
# CL05 — Extract shared dataset and reporting logic behind a research library boundary
|
|
|
|
Parent epic: E10. Priority/severity: P2 / High. Complexity: M. Specialization: TypeScript domain boundaries and package migration.
|
|
|
|
Scheduling metadata: [manifest](../manifest.json). Read the [cleanup execution contract](../../CLEANUP.md#execution-contract). This story defines planned work; implementation has not been requested.
|
|
|
|
## User story and outcome
|
|
|
|
As a backend or research-tool developer, I want reusable dataset and reporting logic to have a stable package interface, so clients do not import another application implementation directory.
|
|
|
|
Expected benefit: Creates a small shared boundary for the API, workers and future research clients while preserving existing behavior.
|
|
|
|
## Verified evidence
|
|
|
|
- **Verified — CL-F04:** Web admission imports worker-application implementation modules directly. [apps/stock/web-api/src/services/canonical-research.service.ts:31](../../../../apps/stock/web-api/src/services/canonical-research.service.ts#L31).
|
|
- **Verified — CL-F04:** Result reading imports the orchestrator reporting implementation. [apps/stock/web-api/src/services/backtest-v2.service.ts:37](../../../../apps/stock/web-api/src/services/backtest-v2.service.ts#L37).
|
|
- **Verified — CL-F04:** V2 validation mixes reusable normalization/hashing with a legacy conversion dependency. [apps/stock/orchestrator/src/data/historical-dataset-v2.ts:1](../../../../apps/stock/orchestrator/src/data/historical-dataset-v2.ts#L1).
|
|
|
|
## Implementation scope
|
|
|
|
- Introduce one focused libs/research workspace, @stock-bot/research, using the existing libs/* workspace pattern. Publish explicit browser-safe dataset-contract, server dataset-validation and pure result-analysis subpaths.
|
|
- Move only reusable V2 normalization/validation/hash and canonical statistical-report code. Keep provider IO, legacy source adaptation, worker supervision, build-file inspection and sandbox execution in application adapters.
|
|
- Keep thin compatibility re-exports at existing imports during migration; establish one implementation, not duplicate helpers. Do not relocate every historical contract or create a package per concept.
|
|
- Replace the API imports of these moved pure helpers and add import/bundle boundaries. Existing stock-config contract subpaths may remain dependencies when they load no configuration manager or application runtime.
|
|
|
|
Likely existing files/modules:
|
|
|
|
- `apps/stock/orchestrator/src/data/historical-dataset-v2.ts`
|
|
- `apps/stock/orchestrator/src/backtest/canonical-result.ts`
|
|
- `apps/stock/web-api/src/services/canonical-research.service.ts`
|
|
- `apps/stock/web-api/src/services/backtest-v2.service.ts`
|
|
- `apps/stock/web-api/src/services/dataset-preparation.service.ts`
|
|
- `apps/stock/web-api/src/services/validation-preview.ts`
|
|
- `apps/stock/web-api/src/services/chronological-validation.service.ts`
|
|
- `scripts/test/architecture.test.ts`
|
|
- `tsconfig.check.json`
|
|
|
|
Proposed new files/modules (names may be adjusted within this scope):
|
|
|
|
- `libs/research/package.json`
|
|
- `libs/research/tsconfig.json`
|
|
- `libs/research/src/dataset-contracts.ts`
|
|
- `libs/research/src/datasets.ts`
|
|
- `libs/research/src/results.ts`
|
|
|
|
## Exclusions
|
|
|
|
- No NAPI/Rust financial changes, new API routes, generic plugin/DI framework or relocation of provider adapters.
|
|
- No persisted schema/hash changes, edited historical artifact bytes, new feature caching, DSL or performance work.
|
|
|
|
## Dependencies and ownership
|
|
|
|
Implementation prerequisites: [D01](D01.md), [F08](F08.md), [R05](R05.md).
|
|
|
|
Write locks: `research-domain-package`, `dataset-domain`, `research-architecture-tests`.
|
|
|
|
Parallel execution: Code-ready against completed D01/F08/R05. Independent of the DI stories. Serialize exact API file edits with CL08 and dataset-client edits with CL06; CL06/CL08 depend on this boundary.
|
|
|
|
## Acceptance criteria
|
|
|
|
1. There is one implementation of moved V2 and report behavior; the old entrypoints are compatibility facades rather than copies.
|
|
2. The new library has no imports of apps/*/src implementation paths, service containers, databases, native bindings or application entrypoints.
|
|
3. The dataset-contract subpath bundles for the browser without node:crypto, filesystem access or native code; server hashing stays outside that entrypoint.
|
|
4. Existing dataset hash fixtures, acceptance/rejection cases and canonical analytics outputs remain identical.
|
|
5. The web API uses the shared package for moved helpers. Native-worker bundling and original-result reading still pass; old retained artifacts are preserved.
|
|
|
|
## Mandatory verification
|
|
|
|
Build the changed package and worker artifacts in the assigned checkout before integration tests. Preserve existing retained artifact fixtures rather than rebaselining economic output.
|
|
|
|
```sh
|
|
bun run build
|
|
bun test scripts/test/architecture.test.ts test/integration/historical-dataset-v2.test.ts test/integration/canonical-result.test.ts
|
|
bun test test/integration/canonical-sma.test.ts test/integration/retained-strategy-worker.test.ts
|
|
bun run typecheck
|
|
```
|
|
|
|
Required regression cases: browser-safe imports, one validation implementation, golden dataset hashes, metadata round trips, canonical analytics equivalence and retained-worker execution.
|
|
|
|
## Risks and definition of done
|
|
|
|
Hash property order, module-local prepared-object caches and worker build identities can change accidentally during moves. Preserve semantic outputs and retained executable bytes; new current builds must not overwrite original reproduction artifacts.
|
|
|
|
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.
|