fix(session-monitor): stop unmonitoring seasons other users still need#1186
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughAdds season-eligibility predicates and integrates them into Plex session monitoring to gate progressive cleanup; normalizes Plex SSE playing notifications by rewriting ChangesProgressive Cleanup & Buffering Normalization
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
🚥 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 docstrings
🧪 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: 1
🤖 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 `@test/unit/services/plex-session-monitor/cleanup-predicates.test.ts`:
- Around line 80-82: The test title is misleading: update the spec name for the
test in cleanup-predicates.test.ts so it matches the assertion for
collectSeasonsEligibleForCleanup(2, 5, []); change the description from "returns
empty when there are no active users" to something like "returns all seasons in
range when there are no active users" so the test name accurately reflects that
it expects [2, 3, 4].
🪄 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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: f9454809-be2d-4acd-a348-aa04c720e166
📒 Files selected for processing (6)
src/services/plex-server/sse/plex-event-source.tssrc/services/plex-session-monitor.service.tssrc/services/plex-session-monitor/cleanup-predicates.tstest/integration/services/plex-session-monitor/progressive-cleanup-workflow.test.tstest/unit/services/plex-server/sse/plex-event-source.test.tstest/unit/services/plex-session-monitor/cleanup-predicates.test.ts
56a7811 to
ee3cf8e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
test/unit/services/plex-session-monitor/cleanup-predicates.test.ts (1)
9-12: ⚡ Quick winAllow nullable
last_watched_seasoninmakeUseroverrides.The helper currently forces
number, which requires an unsafe cast at Line 67 (null as unknown as number). Making the override nullable keeps fixture construction type-safe.♻️ Proposed fix
function makeUser( overrides: Partial<RollingMonitoredShow> & { plex_username: string - last_watched_season: number + last_watched_season: number | null }, ): RollingMonitoredShow { @@ it('treats null last_watched_season as 0 - fresh entry protects S1', () => { const user = makeUser({ plex_username: 'a', - last_watched_season: null as unknown as number, + last_watched_season: null, })Also applies to: 64-68
🤖 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/unit/services/plex-session-monitor/cleanup-predicates.test.ts` around lines 9 - 12, The overrides type for the test helper forces last_watched_season to be a non-null number, causing unsafe casts in makeUser; change the overrides definition to allow last_watched_season to be number | null (i.e., Partial<RollingMonitoredShow> & { plex_username: string; last_watched_season?: number | null }) so makeUser and related fixtures can accept null without casting; update any call sites (e.g., the test at Lines ~64-68) if they rely on the previous non-null type to pass a nullable value or omit the field.
🤖 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
`@test/integration/services/plex-session-monitor/progressive-cleanup-workflow.test.ts`:
- Around line 265-271: The current assertions using expect(...).toContain(...)
only check that specific seasons were touched but allow extra removals; update
the tests around mockUpdateSeasonMonitoring to assert the exact set of
unmonitored seasons/files instead of subset checks: collect the
unmonitoredSeasons from mockUpdateSeasonMonitoring.mock.calls (as done) then
assert equality to the exact expected array (e.g.,
expect(unmonitoredSeasons.sort()).toEqual([2,3]) or equivalent) so the test
fails if any extra seasons are removed; apply the same change to the other two
occurrences that mirror this pattern.
- Around line 58-71: The test currently relies on a hardcoded sessionKey and
uses subset assertions which can miss extra/unexpected deletions; update the
setup so the in-memory SessionTracker/sessionKey is not treated as affecting
monitorSessions() (remove or stop asserting based on session.sessionKey or
ensure SessionTracker is cleared) and change all subset checks (toContain /
not.toContain) that verify unmonitored seasons and deleted file IDs into exact
set assertions by comparing sorted arrays with toEqual, thereby asserting
precise expected sets; when modifying, look for references to monitorSessions(),
processSession(), handlePlayingEvent(), and SessionTracker in the test to locate
and adjust the assertions and any sessionKey usage.
---
Nitpick comments:
In `@test/unit/services/plex-session-monitor/cleanup-predicates.test.ts`:
- Around line 9-12: The overrides type for the test helper forces
last_watched_season to be a non-null number, causing unsafe casts in makeUser;
change the overrides definition to allow last_watched_season to be number | null
(i.e., Partial<RollingMonitoredShow> & { plex_username: string;
last_watched_season?: number | null }) so makeUser and related fixtures can
accept null without casting; update any call sites (e.g., the test at Lines
~64-68) if they rely on the previous non-null type to pass a nullable value or
omit the field.
🪄 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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 7aacee50-6f35-4624-a1f4-d5cfd1c27815
📒 Files selected for processing (6)
src/services/plex-server/sse/plex-event-source.tssrc/services/plex-session-monitor.service.tssrc/services/plex-session-monitor/cleanup-predicates.tstest/integration/services/plex-session-monitor/progressive-cleanup-workflow.test.tstest/unit/services/plex-server/sse/plex-event-source.test.tstest/unit/services/plex-session-monitor/cleanup-predicates.test.ts
ee3cf8e to
02f7865
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/services/plex-session-monitor.service.ts`:
- Around line 262-266: The early return when positionUnchanged (computed from
rollingShow.last_watched_season, rollingShow.last_watched_episode,
currentSeason, currentEpisode) prevents retrying pilot-expansion logic for
repeated SxE1 events; change the guard so we only return early if the position
is unchanged AND it is not a season pilot retry candidate—i.e., allow continued
processing when currentEpisode === 1 and rollingShow.allSeasonPilotRolling (or
other pilot-expansion flag) is set so the pilot/all-season-pilot expansion
branches still run on repeated E01 events; leave the original unchanged-return
behavior for all other episodes/conditions.
🪄 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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 1cd76cfc-0b7e-41dc-8b2c-bab1398239d0
📒 Files selected for processing (6)
src/services/plex-server/sse/plex-event-source.tssrc/services/plex-session-monitor.service.tssrc/services/plex-session-monitor/cleanup-predicates.tstest/integration/services/plex-session-monitor/progressive-cleanup-workflow.test.tstest/unit/services/plex-server/sse/plex-event-source.test.tstest/unit/services/plex-session-monitor/cleanup-predicates.test.ts
02f7865 to
3c51f11
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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
`@test/integration/services/plex-session-monitor/progressive-cleanup-workflow.test.ts`:
- Around line 166-170: The test currently sorts season numbers using
Array.prototype.sort() which performs lexicographic ordering; update the sort
calls that operate on unmonitoredSeasons (and any similar arrays produced from
mockUpdateSeasonMonitoring.mock.calls) to use a numeric comparator sort((a, b)
=> a - b). Locate occurrences where unmonitoredSeasons is created via
mockUpdateSeasonMonitoring.mock.calls (the sites around the checks in
progressive-cleanup-workflow.test.ts) and replace .sort() with .sort((a, b) => a
- b) at each listed call site.
🪄 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: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 5a7dfb73-52ad-4790-9458-42b9ef7e7024
📒 Files selected for processing (6)
src/services/plex-server/sse/plex-event-source.tssrc/services/plex-session-monitor.service.tssrc/services/plex-session-monitor/cleanup-predicates.tstest/integration/services/plex-session-monitor/progressive-cleanup-workflow.test.tstest/unit/services/plex-server/sse/plex-event-source.test.tstest/unit/services/plex-session-monitor/cleanup-predicates.test.ts
3c51f11 to
2bde318
Compare
Description
Related Issues
Type of Change
Testing Performed
Screenshots
Checklist
Summary by CodeRabbit
Bug Fixes
Improvements
Tests