refactor: decompose oversized frontend files into tested helpers #7
No reviewers
Labels
No labels
backend
bug
chore
duplication
effort:complex
effort:medium
effort:trivial
enhancement
follow-up
frontend
fullstack
priority:high
ready-for-agent
refactor
security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
dries/ocman!7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "chore-fe"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implements the bulk of
spec/frontend-refactor/— extracts purehelpers, types, and SSE / message-conversion logic out of the five
largest frontend files into focused, fully-tested
lib/modules.No behaviour change; every consumer keeps importing from the same
paths via re-exports where needed.
What landed
useSyncRef,sseMessageHelpers,sessionStatus,taskId,mutedTools,sidebarHelpers.threadHelpers,convertMessages,sseHelpers,plus composer pure modules (
encodeWav,contextWindows,builtinCommands).api.tstypes split out intoapi.types.tswith re-exports for back-compat.
SessionDetail.tsxrelocated topages/session-detail/with anindex.tsxre-export.chartConfig.ts+format.tsextensions(
renderModel,shortSessionID) pulled out ofDashboard.tsx.coverage via a shared React + DebouncedTrigger mock harness.
File-size deltas
SessionDetail.tsxComposer.tsxOcmanRuntimeProvider.tsxAssistantThread.tsxapi.tsDashboard.tsxTotal frontend tests: 345 → 658 (+313).
Verification
make test,make lint,make buildall pass.Deferred to follow-ups
(7 Composer hooks) are out of scope for this PR. Those
extractions touch deeply-intertwined state (45
useState/43
useEffectin SessionDetail alone) where stale-closure ordep-array bugs are easy to introduce and hard to catch without
@testing-library/react(forbidden by NFR-3) or a manualsmoke-test pass. The biggest mechanical wins — pure-function
extraction, type split, helper deduplication — have all
landed and are unit-tested. The hook decomposition is a clean
follow-up once an integration-test approach is decided.
helpers are out, the per-tab file split (
StatsTab.tsx,UsageTab.tsx, …) is deferred.useSyncRefis shipped + tested; adopting it acrossthe 25+ existing ref-sync sites is deferred.
See
spec/frontend-refactor/(added in this PR) for the fullrequirements + architecture documents.
Moves frontend/src/pages/SessionDetail.{tsx,css} into a dedicated pages/session-detail/ directory and adds an index.tsx re-export so imports of '../pages/SessionDetail' keep resolving. Updates the single consumer (App.tsx) to import from the new directory path. Sets up the location for the per-page hooks extracted in the remaining Phase 4 steps.The five stub-only test files now exercise actual hook behaviour through a shared React + DebouncedTrigger mock harness: - useCapabilities.test.ts: network dedup, lazy-init cache, per-platform fallback, multi-platform detection, worktree-sessions flag. - useSessionInfo.test.ts: EMPTY_INFO fallback, initial fetch, abort on cleanup, refresh() flush. - useSessionChanges.test.ts: same shape, applied to file-changes. - useWorkingTreeDiff.test.ts: same shape, applied to git-diff. - useInfiniteRows.test.ts: initial-clamp math, hasMore derivation, no-IO graceful degradation, sentinel intersection bumps visibleCount. Total frontend tests: 626 → 658 (+32). make test / make lint / make build all pass.