Skip to content

Move runtime sessions and saved company profiles out of App() into hooks - #478

Merged
lamemustafa merged 3 commits into
masterfrom
tapish-claude/persisted-company-profiles-hook
Sep 17, 2026
Merged

lamemustafa merged 3 commits into
masterfrom
tapish-claude/persisted-company-profiles-hook

Conversation

@lamemustafa

@lamemustafa lamemustafa commented Sep 16, 2026

Copy link
Copy Markdown
Owner

What

Steps 2 and 3 of the order in docs/frontend-module-conventions.md (#470): the two App() state clusters that no reset hub touches become hooks. main.tsx goes from 2,290 to 2,241 lines.

hook moved from App() new file pinned
useTallyRuntimeSessions runtimeSessions, runtimeError, refreshRuntime, cancelTallyRequest src/tally-runtime-sessions.ts no
usePersistedCompanyProfiles 5 states, the load-version ref, refreshPersistedCompanyProfiles, PersistedCompanyProfilePage src/persisted-company-profiles.ts yes (267)

The bodies move verbatim, with one exception. The line that wrote App's company list, setCompanies((current) => mergeTallyCompanies(page.profiles, current)), becomes mergeProfiles(page.profiles). App passes a stable React.useCallback around that exact expression, so company identity merging stays in the pinned main.tsx. The hook's useCallback dependency changes from [] to [mergeProfiles], and mergeProfiles never changes identity.

Checklist (from docs/frontend-module-conventions.md)

  1. Duplicates: none. This follows Share the mirror screen's duplicated Tally types and presentation with App #468's dedupe.
  2. Pins:
    • tally-runtime-sessions.ts stays unpinned: session display and request cancellation attribute nothing to a book.
    • persisted-company-profiles.ts is pinned, with its reason beside MAX_SURFACE_FILES. It decides which saved-profile load may merge into App's company list, and a broken stale-load guard could put an older page's identity fields back on a company the switcher and drawer select.
    • Resealed with --pins-changed: 5 digests plus 1 added pin, none removed.
  3. Source-text tests:
    • ux1-shell.test.mjs asserted the hook's useState, ref and stale-load guard in main.tsx. It now reads them from the hook module and asserts that main.tsx imports it.
    • tally-setup-safety.test.mjs sliced main.tsx between two anchors, one of which moved. It now slices the hook module and asserts both anchors exist first, so a missing anchor fails instead of slicing the wrong region.
    • Its doesNotMatch(profileLoad, /setCompanyError\(/) now holds trivially, because the hook has no access to setCompanyError.
  4. Exports: only the hooks.
  5. Behaviour tests: new, both in pnpm test, and every guard mutation-checked (each mutation fails at least one test):
    • scripts/tally-runtime-sessions.test.tsx, 4 tests. Mutations: removing the "already completed" message, dropping the refresh after a cancel, and not clearing the error on a successful refresh.
    • scripts/persisted-company-profiles.test.tsx, 4 tests. Mutations: removing the success-path stale guard, the error-path stale guard, the finally guard, and the error clear at load start.
  6. Verification after commit: tsc --noEmit OK, pnpm build OK; corepack pnpm test node 250/250, vitest 121/121 (10 files), Playwright 10/10; cargo test -p bridge-tally-compatibility --lib 24/24 (private CARGO_TARGET_DIR). Seal check without the binary: 267 pins, 0 digest mismatches, matrix → manifest OK, pins added {src/persisted-company-profiles.ts}, removed none.

Queue

Joins the tail of the shared merge queue; CI runs pushed early are cancelled until it's near the head.

🤖 Generated with Claude Code

Rebased onto 1a9dc1f4 (#483), 266 → 267 pins, resealed with --pins-changed (private CARGO_TARGET_DIR). Seal re-verified, tsc OK, node 250/250, compat lib 24/24.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

t and others added 3 commits September 17, 2026 09:29
The smallest state cluster in App(): runtimeSessions and runtimeError,
refreshRuntime and cancelTallyRequest. No reset hub clears it and no
source-text test asserts on it. The bodies move verbatim into
src/tally-runtime-sessions.ts; App() destructures the same four names.

Adds behaviour tests for the hook (refresh success/failure, the
already-finished cancel message and the refresh that follows, a failed
cancel) and puts them in pnpm test. Each was mutation-checked.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Five states, the load-version ref and refreshPersistedCompanyProfiles move
verbatim into src/persisted-company-profiles.ts. The one line that wrote
App's company list becomes a call to mergeProfiles, which App supplies
as a stable callback around its own mergeTallyCompanies, so company
identity merging stays in the pinned main.tsx. No reset hub clears this
state.

ux1-shell and tally-setup-safety read the useState, ref, stale-load guard
and error handling out of main.tsx; they now read the hook module, assert
main.tsx imports it, and check the slice anchors exist before slicing.

Adds four behaviour tests (merge and counts; an older success or failure
settling after a newer load writes nothing; a failure keeps counts and
clears on the next load), each guard mutation-checked.

Pending before push: pin src/persisted-company-profiles.ts. It decides
which load may write App's company list, so a broken guard could merge a
stale page over newer company records.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
It decides which saved-profile load may write App's company list; the
reason is recorded beside MAX_SURFACE_FILES (251 -> 252).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@lamemustafa
lamemustafa force-pushed the tapish-claude/persisted-company-profiles-hook branch from fa5fcd6 to 8520845 Compare September 17, 2026 04:02
@lamemustafa
lamemustafa merged commit 2481ed0 into master Sep 17, 2026
13 checks passed
@lamemustafa
lamemustafa deleted the tapish-claude/persisted-company-profiles-hook branch September 17, 2026 04:14
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