Skip to content

fix(LSG): make current segment timing consider partInstances#1612

Open
ianshade wants to merge 2 commits intoSofie-Automation:mainfrom
tv2norge-collab:contribute/EAV-640
Open

fix(LSG): make current segment timing consider partInstances#1612
ianshade wants to merge 2 commits intoSofie-Automation:mainfrom
tv2norge-collab:contribute/EAV-640

Conversation

@ianshade
Copy link
Contributor

@ianshade ianshade commented Jan 23, 2026

About the Contributor

This pull request is posted on behalf of TV 2 Norge.

Type of Contribution

This is a:

Bug fix

Current Behavior

The calculateSegmentTiming() function in the Live Status Gateway did not consider part instance durations when calculating segment timing. It only used the original part definitions, which meant that if part durations were modified during playout on part instances, these changes were not reflected in the segment timing calculations the same way as they would be in the Sofie GUI.

New Behavior

The calculateSegmentTiming() function now accepts a segmentPartInstances parameter. When calculating the total duration, it checks if a matching part instance exists and uses the instance's part duration instead of the original part duration. If no instance exists for a part, it falls back to the original part definition.

This ensures that current segment timing correctly reflects any duration modifications made to parts through their instances during playout.

Testing

  • I have added one or more unit tests for this PR
  • I have updated the relevant unit tests
  • No unit test changes are needed for this PR

Affected areas

  • Live Status Gateway: The segment timing calculation now considers part instances during duration computation

Time Frame

Other Information

Status

  • PR is ready to be reviewed.
  • The functionality has been tested by the author.
  • Relevant unit tests has been added / updated.
  • Relevant documentation (code comments, system documentation) has been added / updated.

Summary

This PR fixes a bug in the Live Status Gateway's segment timing calculation to account for duration modifications made to parts at runtime via part instances. Previously, calculateSegmentTiming() only considered the original part definitions, missing any duration changes applied during playout. The fix introduces a segmentPartInstances parameter that enables duration lookups from part instances when available, with fallback to the original part definition.

Changes

segmentTiming.ts (10 lines changed):

  • Added imports for unprotectString and underscore utilities
  • Updated calculateSegmentTiming() signature to accept segmentPartInstances: DBPartInstance[] parameter
  • Implemented part instance resolution by building a mapping from part IDs to their instances using underscore's indexBy method
  • During expected duration calculation, the function now looks up each part's duration from the instance mapping if available, otherwise uses the original part definition
  • calculateCurrentSegmentTiming() now passes segmentPartInstances to calculateSegmentTiming()

segmentTiming.test.ts (53 lines added):

  • New test suite with two test cases validating the updated behavior
  • Test 1: Verifies that part instance durations override original part durations when instances are available
  • Test 2: Verifies fallback to original part durations when no matching part instance exists for a given part
  • Uses helper functions to construct mock Part and PartInstance objects with specified durations

segmentsTopic.ts (1 line changed):

  • Updated the call to calculateSegmentTiming() in SegmentsTopic.sendStatus() to pass an empty array for segmentPartInstances
  • Added TODO comment noting potential inaccuracy for current/next segments due to adlib-driven changes in part instances not being reflected in the timing calculation

Impact

The change enables the Live Status Gateway to accurately reflect segment timing when part durations are modified via part instances during playout, improving timing accuracy for current segment calculations. The fix includes comprehensive unit test coverage for both primary use case (instance duration used) and fallback behavior (original duration used).

@ianshade ianshade requested a review from a team as a code owner January 23, 2026 09:31
@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

The changes enhance segment timing calculation by introducing a segmentPartInstances parameter to calculateSegmentTiming, which creates a mapping to resolve part durations from PartInstance objects. A new test suite validates both the primary behavior (using partInstance duration) and fallback logic (using original part duration).

Changes

Cohort / File(s) Summary
Test Suite
packages/live-status-gateway/src/topics/helpers/__tests__/segmentTiming.test.ts
New test suite with two test cases verifying calculateSegmentTiming correctly uses partInstance duration when available and falls back to original part duration when unavailable.
Segment Timing Logic
packages/live-status-gateway/src/topics/helpers/segmentTiming.ts
Updated function signature to accept segmentPartInstances parameter. Implements partInstance-to-part mapping using unprotectString and underscore's indexBy to resolve part duration details during segment timing calculation.
Segment Topic
packages/live-status-gateway/src/topics/segmentsTopic.ts
Caller updated to pass empty array as segmentPartInstances argument to calculateSegmentTiming; includes comment noting potential accuracy issues for current/next segments due to ad-lib changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰✨ A rabbit hops through timing's weave,
Where partInstances retrieve,
The truest duration, no reprieve—
Mapping parts like morning's leave,
Segments now in perfect believe! 🥕⏱️

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating segment timing calculation to consider partInstances, which is the core fix across the modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ianshade ianshade added the Contribution from TV 2 Norge Contributions sponsored by TV 2 Norge (tv2.no) label Jan 23, 2026
@codecov
Copy link

codecov bot commented Jan 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@PeterC89
Copy link
Contributor

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@PeterC89 PeterC89 changed the base branch from release53 to main February 4, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Contribution from TV 2 Norge Contributions sponsored by TV 2 Norge (tv2.no)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants