Skip to content

refactor(repl): extract setResponseLength pure helper (audit §1.1.1 slice #18) - #188

Merged
dahai80 merged 1 commit into
mainfrom
audit/repl-split-slice18-setresponselength
Aug 28, 2026
Merged

dahai80 merged 1 commit into
mainfrom
audit/repl-split-slice18-setresponselength

Conversation

@dahai80

@dahai80 dahai80 commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

Audit §1.1.1 god-module split — slice #18. Extracts the 16-LOC setResponseLength useCallback body from src/screens/REPL.tsx into a pure routing helper src/utils/responseLengthState.ts.

Extraction class

Pure-helper (lowest byte-identical risk). The body:

REPL keeps a thin useCallback wrapper (deps [] unchanged) calling applySetResponseLengthImpl once. Downstream reads the same const name → byte-identical behavior. The 3 body comments move into the helper file header (equivalent semantic documentation).

Behavior preserved

setResponseLength(f):

  1. responseLengthRef.current = f(prev) (always)
  2. Only when new value > prev (growth, not flat/shrink) → update the last metrics entry: lastTokenTime = now + endResponseLength = new value
  3. Empty metrics array → safe no-op (length > 0 guard)

Gates

  • bun run typecheck — 0 errors
  • bun test src/__tests__/ — 887 pass (+6 new for the helper)
  • bunx biome check — clean (1 noNonNullAssertion warning = pre-existing style; original body used the same !)
  • bun run build:dev — passes
  • Zero REPL import churn (verified via diff grep)

Tests

New src/__tests__/utils/responseLengthState.test.ts (6 tests, 15 assertions): f(prev) application, growth updates last entry (mocked Date.now), flat no-op, shrink no-op, empty-array safe no-op, last-entry-only update.

Progress

REPL: 6420 → 6415 (−5 net). Cumulative −681 across 17 slices (7096 → 6415).

Co-Authored-By: Claude Fable 5 [email protected]

…lice #18)

Extract the 16-LOC setResponseLength useCallback body from REPL.tsx into
a pure routing helper src/utils/responseLengthState.ts. The body mutates
two refs (responseLengthRef + apiMetricsRef) with no JSX, hooks, or async
— a pure-helper extraction (lowest byte-identical risk class, same proven
pattern as slice #17 applySetInputValue).

REPL keeps a thin useCallback wrapper (deps [] unchanged) calling
applySetResponseLengthImpl once; downstream reads the same const name →
byte-identical behavior. The 3 body comments move into the helper file
header (equivalent semantic documentation).

Gates: typecheck 0 / 887 tests pass (+6 new for the helper) / biome clean
(1 noNonNullAssertion warning = pre-existing style, original body used the
same `!`) / build:dev passes / zero REPL import churn.

REPL: 6420 → 6415 (−5 net), cumulative −681 across 17 slices (7096 → 6415).

Co-Authored-By: Claude Fable 5 <[email protected]>
@dahai80
dahai80 merged commit e7377b4 into main Aug 28, 2026
1 check passed
@dahai80
dahai80 deleted the audit/repl-split-slice18-setresponselength branch August 28, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant