Files
pedwfrontend/memory-bank/refactor-backlog.md
T

74 lines
3.7 KiB
Markdown

# Refactor Backlog (Maintainability + System Integrity)
Last updated: 2026-03-12
## Priority 1 — Split `actions/index.js` by concern
- **Problem:** Single high-coupling module mixes API clients, hash/token helpers, logging, file/email/domain operations.
- **Why it matters:** Hard to reason about changes; high regression risk from unrelated edits.
- **Target outcome:** Small modules with explicit boundaries (e.g. `relayClient`, `fileClient`, `notifyClient`, `caseService`, `authService`).
- **Initial scope:** create façade layer first, then migrate call sites incrementally.
- **Detailed plan:** `memory-bank/refactor-plan-actions-index.md`
- **Test gate:** add unit regression tests + coverage reporting as part of this refactor.
## Priority 2 — Centralize relay/hash/token forwarding logic
- **Problem:** `pages/api/endpoint/**` and related routes duplicate request-signing + token + forwarding behavior.
- **Why it matters:** Security-sensitive drift and inconsistent error handling.
- **Target outcome:** Shared relay utility enforcing one signing contract, one timeout/retry policy, one error map, one redacted logging strategy.
- **Initial scope:** pilot on a small endpoint group, then roll out pattern.
## Priority 3 — Extract breadcrumb/back-link route-state rules
- **Problem:** Navigation logic in `components/breadcrumbs.js` and case summary is branch-heavy and query-dependent.
- **Why it matters:** Frequent regressions in search -> case -> myportal paths.
- **Target outcome:** Pure route-state helpers with table-driven tests; UI component mainly renders output.
- **Initial scope:** isolate `va/adv/ads/key` decision matrix first.
## Priority 4 — Standardize security guards in `pages/api/file/**`
- **Problem:** Hash/guard enforcement appears inconsistent across file endpoints.
- **Why it matters:** Uneven protection for document upload/download/delete paths.
- **Target outcome:** Shared guard middleware for hash/auth/input validation + consistent negative-path responses.
- **Initial scope:** enforce a common pre-handler contract on high-risk routes first.
### Priority 4 — Current slice status (2026-03-23)
- Completed on `TASK22224-file-endpoint-contract-bundle`:
- `pages/api/file/downloadblob.js` hardening + hotfix closure
- path normalization compatibility (filename-only + prefixed path)
- encoded/raw hash validation compatibility guard
- Confirmed outcome:
- user-reported download failures resolved
- phase21 file + combined contract suites passing
### Priority 4 — Next recommended slice on this branch
- Target routes:
- `pages/api/file/deleteblob.js`
- `pages/api/file/deleteblobcase.js`
- `pages/api/file/deleteblobrep.js`
- Scope:
- align hash canonicalization strategy with `downloadblob.js`
- enforce explicit `respondError` contracts (`MISSING_REQUIRED_QUERY`, `INVALID_HASH`, route-specific `*_FAILED`)
- preserve existing success payload shapes
- extend `tests/phase21/file-handler-contract.test.cjs` with mixed encoded/raw hash variants and negative paths
## Priority 5 — Establish minimum automated regression baseline
- **Problem:** Limited automated tests for high-risk logic.
- **Why it matters:** Repeated regressions and heavy manual verification burden.
- **Target outcome:** Focused test suite for pure logic and high-risk decisions.
- **Initial scope:**
1. breadcrumb decision matrix
2. representation eligibility/date windows
3. hash utility behavior
4. locale rewrite mapping sanity checks
## Sequencing recommendation
1. Priorities 2 + 4 (security/integrity foundation)
2. Priority 3 (high-change regression hotspot)
3. Priority 1 (structural maintainability)
4. Priority 5 (continuous safety net, starts early and expands)