Skip to content

Extract chat page monolith, add tests and Playwright#28

Merged
RuneLind merged 4 commits intomainfrom
refactor/chat-page-architecture
Mar 16, 2026
Merged

Extract chat page monolith, add tests and Playwright#28
RuneLind merged 4 commits intomainfrom
refactor/chat-page-architecture

Conversation

@RuneLind
Copy link
Copy Markdown
Owner

First phase of the chat page architecture refactoring. Extracts CSS and pure inspector functions from the 3,026-line monolith, adds 78 new unit tests, sets up Playwright e2e, and documents key modules.

The chat page has been the source of recurring token tracking and inspector bugs because all state and logic lived in a single file with global variables. This extraction makes the data flow explicit and enables unit testing of client-side logic via a dual-export pattern (TypeScript functions for tests + JS strings for the browser).

  • Extract 847 lines of CSS into chat-styles.ts (page.ts: 3,026 → 2,167 lines)
  • Extract pure inspector functions (aggregateToolCalls, fmtToolTime, fmtNum, computeContextUsage) with dual-export pattern
  • Add 78 unit tests: inspector panel (34), agent-status (17), activity-log (13), route-utils (14)
  • Set up Playwright with 10 chat page e2e scenarios
  • Add CLAUDE.md for src/chat/, src/dashboard/, src/ai/, src/db/

Testing

  • Unit tests (186 pass, up from 108)
  • TypeScript compiles clean
  • Manual verification of chat page
  • Playwright e2e against running app

Extract 847 lines of CSS from the 3,026-line chat page monolith into
chat-styles.ts. Extract pure inspector panel functions (aggregateToolCalls,
fmtToolTime, fmtNum, computeContextUsage) with dual-export pattern for
testability. Add 78 new unit tests for inspector panel logic, route-utils,
agent-status tracker, and activity-log. Set up Playwright e2e with 10
chat page test scenarios. Add CLAUDE.md files for chat/, dashboard/, ai/,
and db/ subdirectories.

The chat page monolith has been the source of recurring token tracking
and inspector bugs because all state and logic was in a single 3k-line
file with global variables. This is the first step of a phased extraction
to make the code testable and the data flow explicit. The dual-export
pattern (TypeScript function + browser JS string) enables unit testing
of client-side logic that was previously untestable.
Add new test files to the main test script so bun run test includes
all 78 new tests. Add phase 2 prep comment to inspectorPanelScript()
to clarify it is intentionally exported but not yet consumed. Fix
activity-log tests to be order-independent by using dynamic prefixes
and relative assertions instead of hardcoded values.
Use ?? (nullish coalescing) instead of || (logical or) when falling
back from contextTokens to inputTokens. The || operator treats 0 as
falsy, which would incorrectly fall back to inputTokens when a
connector reports contextTokens: 0.
Replace waitForTimeout(500) with expect().toBeVisible() so Playwright
waits for the bot pill to actually get the active class instead of
hoping 500ms is enough. The deep link triggers async API calls that
can take longer on slow connections.
@RuneLind RuneLind changed the title Extract chat page monolith and add tests, docs, and Playwright Extract chat page monolith, add tests and Playwright Mar 16, 2026
@RuneLind RuneLind merged commit 1255f41 into main Mar 16, 2026
@RuneLind RuneLind deleted the refactor/chat-page-architecture branch March 16, 2026 08:14
RuneLind added a commit that referenced this pull request Mar 16, 2026
Extract CSS and pure inspector functions from the 3,026-line chat page monolith, add 78 new unit tests, set up Playwright e2e, and document key modules with CLAUDE.md files.

The chat page has been the source of recurring token tracking and inspector bugs because all state and logic lived in a single file with global variables. This extraction makes the data flow explicit and enables unit testing of client-side logic via a dual-export pattern (TypeScript functions for tests + JS strings for the browser).

- Extract 847 lines of CSS into chat-styles.ts (page.ts: 3,026 to 2,167 lines)
- Extract pure inspector functions (aggregateToolCalls, fmtToolTime, fmtNum, computeContextUsage) with dual-export pattern
- Add 78 unit tests: inspector panel (34), agent-status (17), activity-log (13), route-utils (14)
- Set up Playwright with 10 chat page e2e scenarios
- Add CLAUDE.md for src/chat/, src/dashboard/, src/ai/, src/db/
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