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

5.6 KiB

W01 — Make existing run controls and selection truthful

Parent epic: E5. Priority/severity: P1 / High. Relative complexity: M. Recommended specialization: Full-stack React/API.

Scheduling source of truth: manifest entry W01. No task is authorized until the plan is approved. Dependencies and decision references below describe the design; the manifest controls current readiness.

Evidence and root cause

Intended behavior and implementation scope

Repair the existing UI flow only: wire cancel, show cancel-requested until persisted terminal state, use one nonoverlapping polling authority, and guard requests by selection generation/abort. Websocket messages invalidate/refetch persisted state, not a competing state store. Repair the current reconnect guard/cleanup as needed. Expose cancel as the supported shared execution control; leave legacy pause/resume/speed endpoints intact but do not advertise them without per-run support. No capability registry, SQL migration or new backend job protocol.

Exclusions

No unrelated refactor, new service or broker activation.

Likely files and ownership

  • apps/stock/web-app/src/features/backtest/BacktestDetailPageV2.tsx
  • apps/stock/web-app/src/features/backtest/hooks/useBacktestV2.ts
  • apps/stock/web-app/src/features/backtest/components/RunControlsCompact.tsx
  • apps/stock/web-app/src/features/backtest/services/backtestApiV2.ts
  • apps/stock/web-app/src/hooks/useWebSocket.ts
  • test/integration/backtest-run-controls.test.tsx (new)
  • apps/stock/web-app/package.json and bun.lock (only if a focused DOM test dependency is necessary)

Write locks: web-backtest-detail, websocket-hook, frontend-test-dependencies. Review concrete file overlap; first-wave writable paths are further restricted by FIRST-WAVE.md.

Dependencies and blockers

No code prerequisite. Global execution approval and write-lock acquisition still required.

No additional economic-policy approval is needed for this narrowly scoped task.

Parallel eligibility: only with disjoint actual files and reserved write locks; read FIRST-WAVE.md for the initial exact ownership boundaries.

Acceptance criteria

  • Late getRun(A) AND getResults(A) cannot replace selected B, including completion/error callbacks.
  • At most one poll is outstanding per mounted selection; switching/unmount invalidates previous requests and cleans timers/subscriptions.
  • Pending cancellation can persist as cancelled immediately; active cancellation remains requested until stored acknowledgement. Failed/cancelled never display successful completion.
  • Current native-unsupported server pause/resume/speed controls are absent/disabled; chart playback controls are unaffected.
  • Reconnect or polling fallback recovers actual status; completed zero-trade data is distinct from missing results.

Mandatory tests

  • New backtest-run-controls.test.tsx: stale_status_response, stale_results_response, one_poll_in_flight, no_publish_after_unmount, pending_vs_active_cancel, unsupported_controls, reconnect_or_poll_recovery.
  • bun test test/integration/backtest-run-controls.test.tsx test/integration/analytics-ui.test.tsx test/integration/backtest-result-mapping.test.ts test/integration/backtest-workflow.test.ts; bun run typecheck; bun run test:contracts.
  • Reuse Bun and existing React tests. One minimal DOM test adapter is allowed if needed; W04 owns real browser E2E, not a second harness here.

Apply relevant quality gates. Report exact commands/results and unavailable checks; named new cases are requirements, not claims of existing passing tests.

Regression risks and rollback

Compatibility or lifecycle regression; preserve frozen inputs, old results and existing failure tests. Keep migrations additive and previous results readable. Do not add a switch that restores a correctness defect. Versioned cutover/migration is required only when persisted contracts or active engines change; never silently fall back to old economics.

Web/API contract and user states

  • API: Existing v2 getRun/getResults/cancel and websocket invalidation only. No new capability schema or financial fields.
  • Backend/data dependencies: Existing persisted cancellation/status contract; backend source is read-only for this task.
  • Loading/error/empty behavior: Preserve selected B during stale A responses; retry errors; requested versus acknowledged cancellation; zero trades versus unavailable result.
  • Parallelism: Independent of first-wave native finance, TS finance and ModeManager files. Owns frontend test-dependency changes if needed.

Handoff

Report scope changes (if any), fixture expectations, API/schema changes, measurements, remaining limitations and commit/PR references once authorized. Request independent review; only the integration/planning owner may mark the manifest done.