fix(viewer): handle sessions missing ids#366
Conversation
|
@honor2030 is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR adds helper functions to derive normalized session ids and labels when raw session.id may be missing, then updates all session-facing UI surfaces (Dashboard, Timeline, Activity, Sessions list, Session detail, and Replay selector) to use those derived values; includes Vitest sandbox tests for missing-id cases. ChangesSession ID Resilience
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
test/viewer-session-id.test.ts (1)
97-100: 💤 Low valueThe auto-start regex pattern is fragile and tightly coupled to script output format.
This pattern will break if function names, order, whitespace, or additional auto-start calls change in the viewer script. Consider extracting the expected pattern as a named constant with a comment explaining the dependency, or use a more flexible approach like multiple small replacements for each function call.
♻️ More maintainable approach
- const scriptWithoutAutoStart = scriptMatch[1].replace( - /\n\s*loadTab\('dashboard'\);\n\s*connectWs\(\);\n\s*startDashboardAutoRefresh\(\);\s*$/, - "\n", - ); + // Strip viewer auto-start calls that would interfere with test control + let scriptWithoutAutoStart = scriptMatch[1]; + scriptWithoutAutoStart = scriptWithoutAutoStart.replace(/\bloadTab\s*\([^)]*\)\s*;?\s*/g, ""); + scriptWithoutAutoStart = scriptWithoutAutoStart.replace(/\bconnectWs\s*\([^)]*\)\s*;?\s*/g, ""); + scriptWithoutAutoStart = scriptWithoutAutoStart.replace(/\bstartDashboardAutoRefresh\s*\([^)]*\)\s*;?\s*/g, "");This approach removes each function call independently, making it resilient to order changes and whitespace variations.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/viewer-session-id.test.ts` around lines 97 - 100, The current fragile single-regex removal in scriptWithoutAutoStart tightly couples to exact order/whitespace of loadTab('dashboard'); connectWs(); startDashboardAutoRefresh(); — replace it with a more resilient approach: extract the expectation into a named constant (e.g., AUTO_START_CALLS_PATTERN) and/or perform separate, small regex replacements that each target loadTab\('dashboard'\)\s*;, connectWs\(\)\s*; and startDashboardAutoRefresh\(\)\s*; independently (using flexible whitespace flags) so order changes or extra whitespace won't break the test; update the code that constructs scriptWithoutAutoStart to use these constants/replacements and add a short comment explaining why this is necessary.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/viewer/index.html`:
- Around line 2586-2590: The selection mismatch comes from normalizing IDs with
sessionId(s) when rendering (used for data-session-id) but still comparing raw
x.id === state.sessions.selectedId when opening details; fix by using the same
normalization function for the detail lookup (i.e., compare sessionId(x) ===
state.sessions.selectedId) or otherwise convert both sides to the same canonical
string form before comparing so numeric/typed IDs match; update any logic that
sets or compares state.sessions.selectedId to consistently use sessionId(...)
(references: sessionId, state.sessions.selectedId, the detail lookup that
compares x.id, and the session rendering that uses data-session-id).
- Around line 2224-2227: The default timeline selection currently assigns
state.timeline.sessionId = sorted[0].id which uses the raw upstream id and can
be invalid; change the initialization to use the normalized sessionId helper (or
pick the first sorted entry whose sessionId(s) returns a non-empty value) and
assign that normalized id (or '' fallback) to state.timeline.sessionId so the
initial selected option matches the normalized/disabled logic used when
rendering options (see sessionId, sorted, sessionLabel, and
state.timeline.sessionId).
In `@test/viewer-session-id.test.ts`:
- Around line 41-57: The mock document's querySelectorAll currently returns []
which prevents the viewer script from attaching event listeners; update the mock
in test/viewer-session-id.test.ts so document.querySelectorAll(selector) returns
an array of appropriate mock elements for selectors used by the viewer (at least
'.tab-bar button', '.view', and 'input[type="checkbox"]'). Each returned mock
element should implement addEventListener, getAttribute/setAttribute, classList
toggle/contains (or className), and for checkbox inputs a checked property;
reuse the existing createElement/getElement behaviors to construct these mocks
so the forEach loops in the viewer script execute and event handlers can be
attached.
---
Nitpick comments:
In `@test/viewer-session-id.test.ts`:
- Around line 97-100: The current fragile single-regex removal in
scriptWithoutAutoStart tightly couples to exact order/whitespace of
loadTab('dashboard'); connectWs(); startDashboardAutoRefresh(); — replace it
with a more resilient approach: extract the expectation into a named constant
(e.g., AUTO_START_CALLS_PATTERN) and/or perform separate, small regex
replacements that each target loadTab\('dashboard'\)\s*;, connectWs\(\)\s*; and
startDashboardAutoRefresh\(\)\s*; independently (using flexible whitespace
flags) so order changes or extra whitespace won't break the test; update the
code that constructs scriptWithoutAutoStart to use these constants/replacements
and add a short comment explaining why this is necessary.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 15c16191-1c09-4467-a7a9-2bf8ead94fd8
📒 Files selected for processing (2)
src/viewer/index.htmltest/viewer-session-id.test.ts
b3d4c3a to
0eb640a
Compare
|
Addressed the review feedback in the latest push (
Verification:
Current checks after push: CodeRabbit is passing/skipped. Vercel is still blocked by repository deployment authorization, unrelated to this diff. |
Summary
Unknown session/missing idinstead of throwing.undefinedaction payloads.Red / Green
PATH=/opt/homebrew/bin:$PATH npm test -- test/viewer-session-id.test.ts --reporter=verbosefailed before the implementation withTypeError.PATH=/opt/homebrew/bin:$PATH npm test -- test/viewer-session-id.test.ts test/viewer-security.test.ts --reporter=verbose— 2 files / 4 tests passed.PATH=/opt/homebrew/bin:$PATH npm run build— passed.PATH=/opt/homebrew/bin:$PATH npm test -- --reporter=dot— 84 files / 905 tests passed.Closes #340
Closes #347
Summary by CodeRabbit
New Features
Tests