stock-bot/docs/cleanup-audit.md

50 lines
9.8 KiB
Markdown

# Shared-library cleanup: preservation and removal audit
This records the shared-library cleanup following `ccce401`. It does not
claim to audit every deletion from the earlier execution/strategy refactors. The first
pass inferred that no current imports meant no future value; that was too broad for a
trading/feature-engineering repository. This revision separates capabilities by ownership
and readiness instead of deleting them on usage alone.
| Previously removed item | Current disposition |
| ------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Active basic calculations, technical indicators, risk and performance modules | All 105 exported functions preserved in `libs/calculations/src/legacy/`, with original executable bodies. Explicit `@stock-bot/calculations/legacy` entry; not endorsed as reviewed core. |
| Tested orchestrator equity/return/trade/performance and window math | Moved into supported `@stock-bot/calculations/analytics` and `/indicators`; report/strategy consumers migrated. No strategy checkpoint/version changes. |
| Generic OHLCV extraction, features, grouping/filtering and timestamps | All 13 helpers restored to `@stock-bot/calculations/market-data`. SMA/return formulas delegate to reviewed core; invalid-input, VWAP and grouping behavior hardened as documented. |
| Seven `.disabled` math modules | Full original sources preserved as verified Markdown research snapshots, including unique indicators and numerical prototypes. Not activated or silently labeled production-ready. |
| `POSITION_SIZING_FIXES.md` | Preserved as historical research notes with an explicit warning that its correctness/production claims were not independently verified. |
| Proxy URL and sleep helpers | Restored to `@stock-bot/utils/common` and named root exports. |
| Date helpers | Restored to `@stock-bot/utils/dates`: validated UTC weekday/date functions; old `dateUtils` names retained as deprecated aliases. Not an exchange/holiday calendar. UTC semantics replace the old environment-dependent local calendar arithmetic. |
| `utils` assertion facade | Remains removed. `at`/`defined` are unchanged in `@stock-bot/invariants`; all consumers import the actual owner. This removes a duplicate entry point, not the functionality. |
| Domain-type re-exports through the calculation barrel | Domain types remain unchanged in `@stock-bot/types`; callers import the owner, rather than maintaining another re-export layer. |
| Empty `analyzePortfolio` API | Remains removed: it returned empty objects and implemented no calculation. Real legacy/research portfolio functions are preserved above. |
| Old generic utility test file | Its 21 existing cases were split into 13 market-data tests and 8 common/date tests at the owning packages, with UTC assertions and new boundary tests. No executed behavior coverage was discarded merely for being unused by apps. |
| `connection-manager.test.ts.old` and `redis-cache.test.ts.old` | Remain removed as `.old` files; full source/scenarios preserved in cache test references. These were not run by the test runner. They contain 27 and 47 cases, respectively, and are not all equivalent to the active tests. Some target absent APIs; the connection-manager suite is skipped and has broken mock names. No passing coverage is claimed. |
| Old handler-registry singleton implementation | Remains removed. The metadata/configuration/service/scheduling registry lives in `@stock-bot/handler-registry`; no imports used the `.old` singleton. Reintroducing it would create another registry authority. |
| `simple-statistics`, unused utility dependencies/references in orchestrator/coverage CLI, and config/cache/type dependencies in general utilities | Remain removed. No live imports required them. The orchestrator now declares the actual calculation workspace; the calculation package has no infrastructure/native dependencies. |
## Preservation evidence and readiness
[The calculation inventory](../libs/calculations/migration-audit.json) records every
previously exported math function, source provenance, legacy AST hashes and research
source hashes. Tests verify all 105 legacy exports and their unchanged executable bodies,
and all seven research snapshots. This proves source/capability preservation, **not**
algorithmic correctness. The reviewed core is tested separately; legacy functions can
still contain zero/Infinity fallbacks, inconsistent conventions or incomplete formulas.
[The calculation contract](../libs/calculations/README.md) specifies supported units,
warm-up/alignment, invalid-result policies and the promotion path for legacy/research
functions. [Research concerns](../libs/calculations/research/README.md) identify known
limitations before reuse. Supported stock application code cannot import the legacy
tier, and no supported math module can load it transitively.
The retired Redis test sources are retained as
[connection-manager scenarios](../libs/core/cache/test/references/connection-manager-tests.md)
and [cache scenarios](../libs/core/cache/test/references/redis-cache-tests.md). Their
valid assertions should be ported with correct public contracts and isolated fixtures;
archived source is deliberately not counted in any test totals.
This revision does not change cache production code, trading/execution behavior,
persisted data, environment files or WCAG. General date helpers and OHLCV edge-case
contracts are the explicit behavior corrections noted above; old legacy math remains
unchanged and opt-in.