Playback telemetry

This commit is contained in:
Brahim Hadriche committed 2026-10-05 16:57:49 -04:00
1 parent 6e964fa2e5
commit 332e1e7ef6
11 files changed
+1526 -195

No files matched your search

@@ -0,0 +1,196 @@
import "pkg:/components/VideoPlayerDev/VideoNode.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"
namespace Tests
@SGNode("VideoPlayerDevMock")
@suite
class PlaybackTelemetryWiringTests extends Rooibos.BaseTestSuite
protected override function beforeEach()
m.top.callFunc("TestSetup")
end function
function State(state as string) as void
m.top.callFunc("TestSetState", state)
end function
function SetContent(urls as object) as void
content = CreateObject("roSGNode", "ContentNode")
content.addField("videoId", "string", false)
content.addField("backend", "string", false)
content.addField("playletStreamUrls", "array", false)
content.addField("playletStreamUrlIndex", "integer", false)
content.addField("playletStreamSource", "string", false)
content.setFields({
videoId: "vid1"
backend: "playlet"
url: urls[0]
playletStreamUrls: urls
playletStreamUrlIndex: 0
playletStreamSource: "adaptiveFormats"
})
m.top.content = content
end function
function BufferingStatus(isUnderrun as boolean) as void
m.top.bufferingStatus = { actualStart: 0, isUnderrun: isUnderrun, percentage: 0, prebufferDone: false }
end function
function SentSummary() as object
event = m.global.telemetry.LogEvent
m.assertEqual(event.fingerprint, ["playback summary"])
return StringUtils.ParseJsonSafe(event.message)
end function
function Close() as object
m.top.close = true
' an error dialog still up was closed by OnClose; drop it from the scene for the next test.
m.top.getScene().dialog = invalid
return m.SentSummary()
end function
function HttpError() as void
m.top.errorMsg = "There was an error in the HTTP response."
m.top.errorCode = -1
m.top.errorStr = "reader pick stream error:HTTP error"
m.top.errorInfo = { category: "http", source: "buffer:reader", ignored: false }
end function
@describe("playback telemetry wiring")
@it("state edges and bufferingStatus reach the summary: an underrun counts")
function _()
m.SetContent(["http://stream"])
m.State(VideoState.Playing)
m.State(VideoState.Buffering)
m.BufferingStatus(true)
m.State(VideoState.Playing)
summary = m.Close()
m.assertEqual(summary.underrun_count, 1)
m.assertTrue(ValidInt(summary.first_playing_at_ms) >= 0, "the first playing was recorded")
m.assertEqual(summary.backend, "playlet")
m.assertEqual(summary.stream_source, "adaptiveFormats")
m.assertFalse(summary.DoesExist("drm"), "an unset drmParams on a ContentNode reads as no DRM")
m.assertFalse(summary.DoesExist("stream_url_index"))
m.assertEqual(summary.outcome, "closed")
end function
@it("a buffering whose bufferingStatus is no underrun is not counted")
function _()
m.SetContent(["http://stream"])
m.State(VideoState.Playing)
m.State(VideoState.Buffering)
m.BufferingStatus(false)
m.State(VideoState.Playing)
m.assertFalse(m.Close().DoesExist("underrun_count"))
end function
@it("every playStartInfo reaches the summary")
function _()
m.SetContent(["http://stream"])
m.State(VideoState.Playing)
m.top.playStartInfo = { start_type: "init", total_dur: 0.5 }
m.top.playStartInfo = { start_type: "cseek", total_dur: 0.25 }
summary = m.Close()
m.assertEqual(summary.play_start_count, 2)
m.assertEqual(summary.play_start_infos[0].start_type, "init")
m.assertEqual(summary.play_start_infos[1].start_type, "cseek")
end function
@it("a retry: the report names the url that failed; the summary, the one that played")
function _()
m.SetContent(["http://a", "http://b"])
m.HttpError()
m.State(VideoState.Error)
report = m.global.telemetry.LogEvent
m.assertEqual(report.level, "warning", "retried: not shown to the viewer")
m.assertTrue(report.message.InStr("Url: http://a") > 0 and report.message.InStr("Url index: 0") > 0, "got: " + report.message)
m.State(VideoState.Playing)
summary = m.Close()
m.assertEqual(summary.error_count, 1)
m.assertEqual(summary.stream_url_index, 1)
m.assertEqual(summary.outcome, "closed")
end function
@it("an error with no retry left ends in error")
function _()
m.SetContent(["http://stream"])
m.State(VideoState.Playing)
m.HttpError()
m.State(VideoState.Error)
summary = m.Close()
m.assertEqual(summary.outcome, "error")
m.assertEqual(summary.error_count, 1)
end function
@it("content that never loaded ends in error, with no player error")
function _()
m.SetContent(["http://stream"])
m.top.callFunc("TestContentJobFailed", "content job failed")
summary = m.Close()
m.assertEqual(summary.outcome, "error")
m.assertFalse(summary.DoesExist("error_count"))
m.assertTrue(ValidInt(summary.metadata_done_at_ms) >= 0, "the content job's result is recorded")
end function
@it("after the close, a late playStartInfo or bufferingStatus reaches nothing")
function _()
m.SetContent(["http://stream"])
m.State(VideoState.Playing)
m.top.playStartInfo = { start_type: "init", total_dur: 0.5 }
m.State(VideoState.Buffering)
m.assertEqual(m.Close().play_start_count, 1)
m.top.playStartInfo = { start_type: "cseek", total_dur: 0.25 }
m.top.bufferingStatus = { isUnderrun: true, percentage: 0, prebufferDone: false, actualStart: 0 }
m.top.callFunc("TestResendSummary")
resent = m.SentSummary()
m.assertEqual(resent.play_start_count, 1)
m.assertFalse(resent.DoesExist("underrun_count"))
end function
@it("finishing ends in finished, sent from within the finish")
function _()
m.SetContent(["http://stream"])
m.top.callFunc("TestWireQueueClose") ' the stub queue closes the player on closePlayer, as the real one does
m.State(VideoState.Playing)
m.State(VideoState.Finished)
m.assertEqual(m.SentSummary().outcome, "finished")
end function
@it("a heal loop: every heal counted, the first 3 sampled, none sent on its own")
function _()
m.State(VideoState.Playing) ' the first playing opens the transport's ready gate
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
m.global.telemetry.LogEvent = {}
for i = 1 to 5
m.State(VideoState.Playing) ' playing under a scrub: healed
end for
m.assertInvalid(m.global.telemetry.LogEvent.message, "a heal sends nothing until the summary")
summary = m.Close()
m.assertEqual(summary.heal_count, 5)
m.assertEqual(summary.heal_samples.Count(), 3)
m.assertEqual(summary.heal_samples[0].source, "OnVideoState")
m.assertFalse(summary.DoesExist("tail_resolve_count"))
end function
@it("a live tail the sliding floor overtook is a tail resolve, not a heal")
function _()
m.State(VideoState.Playing) ' the first playing opens the transport's ready gate
m.top.callFunc("TestSetLive", 43200000)
m.top.position = 28805.0
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
m.State(VideoState.Playing) ' the device force-resumes the pause the tail overtook
summary = m.Close()
m.assertEqual(summary.tail_resolve_count, 1)
m.assertEqual(summary.tail_resolve_samples[0].source, "OnVideoState")
m.assertFalse(summary.DoesExist("heal_count"))
end function
end class
end namespace
@@ -26,7 +26,7 @@ function TestSetup() as void
m.global.logger = CreateObject("roSGNode", "Logger")
end if
' ReportVideoError -> LogTelemetryEvent writes m.global.telemetry.LogEvent; stub it so the error path runs.
' LogTelemetryEvent (error reports, the playback summary on close) writes m.global.telemetry.LogEvent; stub it.
if m.global.telemetry = invalid
m.global.addField("telemetry", "node", false)
telemetry = CreateObject("roSGNode", "Node")
@@ -80,7 +80,7 @@ function TestSetup() as void
' nudge counter above — stacked observers fire a handler once per prior TestSetup on every write,
' and OnPosition's latency learning reads two identical fires as a CONFIRMED min-gap, poisoning
' LiveEdgeMs for any live test that runs after another test in the suite.
for each deviceField in ["state", "position", "duration", "close", "thumbnailTiles", "control"]
for each deviceField in ["state", "position", "duration", "close", "thumbnailTiles", "control", "bufferingStatus", "playStartInfo"]
m.top.unobserveField(deviceField)
end for
@@ -196,6 +196,19 @@ function TestPlaybackErrorDialog(errorFields as object) as object
return result
end function
' TestContentJobFailed — the VideoContentJob's failure result, minus the job: runs the REAL OnVideoContentJobDone.
function TestContentJobFailed(errorMessage as string) as void
OnVideoContentJobDone({
info: { success: false, cancel: false, error: errorMessage }
getRoSGNode: function() as dynamic
return invalid
end function
getInfo: function() as object
return m.info
end function
})
end function
' TestCoordinatorFields — every non-function key on the coordinator's m, for the unmodeled-axis meta-test
' (the coordinator twin of the brain's reflection test). Call AFTER TestSetup so Initialize/OnNodeReady have
' populated m. The ONLY filtering here is the two DYNAMICALLY-named runtime families ("__delay_<uuid>" and
@@ -243,6 +256,12 @@ function TestWireQueueClose() as void
m.videoQueue.observeFieldScoped("closePlayer", FuncName(OnTestQueueClose))
end function
' TestResendSummary — send the playback summary again after the close, so a spec can see whether anything reached
' the Recorder since.
function TestResendSummary() as void
m.playbackTelemetry.SendSummary()
end function
function OnTestQueueClose() as void
if m.videoQueue.closePlayer
m.top.close = true
@@ -26,6 +26,8 @@
<field id="errorMsg" type="string" />
<field id="errorStr" type="string" />
<field id="errorInfo" type="assocarray" />
<field id="bufferingStatus" type="assocarray" alwaysNotify="true" />
<field id="playStartInfo" type="assocarray" alwaysNotify="true" />
<!-- AutoBind deps + layout (set by TestSetup; NOT bound). -->
<field id="appController" type="node" />
<field id="jobQueue" type="node" />
@@ -50,6 +52,7 @@
<function name="TestSetState" />
<function name="TestSnapshot" />
<function name="TestWireQueueClose" />
<function name="TestResendSummary" />
<function name="TestSetControl" />
<function name="TestSetLive" />
<function name="TestSeedSponsorBlock" />
@@ -58,6 +61,7 @@
<function name="TestFinishChromeFadeOut" />
<function name="TestPlaybackErrorDialog" />
<function name="TestCoordinatorFields" />
<function name="TestContentJobFailed" />
</interface>
<children>
<Timer id="autoHide" duration="5" repeat="false" />
@@ -108,23 +108,6 @@ namespace Tests
m.assertEqual(snap.transportMode, TransportController.Mode.Idle, "the transport resolved instead of fighting")
m.assertEqual(snap.control, VideoControl.Resume, "resumed forward, not re-paused")
m.assertEqual(Int(m.top.seek * 1000), 28860000, "the resume parks a full margin above the trigger (28800s + 60s)")
' the resolution telemeters at info level (never as a heal) with its per-content ordinal.
sent = m.global.telemetry.LogEvent
m.assertEqual(sent.level, "info")
m.assertTrue(sent.message.InStr("INV-D1 tail-resolve") = 0, "got: " + sent.message)
m.assertTrue(sent.message.InStr("resolve=1") > 0)
end function
@it("heal telemetry stops at the cap while the occurrences keep counting")
function _()
' a frozen VOD scrub the device keeps flipping to playing: 5 heals, but only 3 events may leave.
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
for i = 1 to 5
m.top.callFunc("TestSetState", VideoState.Playing)
end for
sent = m.global.telemetry.LogEvent
m.assertTrue(sent.message.InStr("heal=3") > 0, "telemetry must stop at the 3rd heal; last sent: " + sent.message)
end function
@it("a sentinel-valued duration report cannot anchor the live-edge fallback clock")
@@ -743,7 +726,7 @@ namespace Tests
classified[name] = "dep"
end for
' controllers (plain .bs class instances).
for each name in ["transport", "sponsorblock"]
for each name in ["transport", "sponsorblock", "playbackTelemetry"]
classified[name] = "controller"
end for
' cached child nodes / timers / animations / reusable helpers (structure, not state).
@@ -759,7 +742,7 @@ namespace Tests
classified[name] = "axis"
end for
' flags / scratch — one-shot latches and counters with a single consuming path.
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "seekToPercent", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive", "healCount", "tailResolveCount"]
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "seekToPercent", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive"]
classified[name] = "flag"
end for
' NOT coordinator state — node-scope + test-environment entries, pinned EXPLICITLY (no hidden
@@ -819,7 +802,7 @@ namespace Tests
container.fullscreen = true
' close the player (what the queue does when replacing the video), then throw every signal a dead
' player might still receive at it: fullscreen flips (the * key), device edges from the async stop,
' a stray control/seek write, late thumbnails, a second close. OnClose unobserves them all.
' a stray control/seek write, late thumbnails and buffering/start info, a second close. OnClose unobserves them all.
m.top.close = true
container.fullscreen = false
container.fullscreen = true
@@ -831,6 +814,8 @@ namespace Tests
m.top.duration = 99.0
m.top.seek = 5.0
m.top.thumbnailTiles = { x: [{ htiles: 1 }] }
m.top.bufferingStatus = { isUnderrun: true, percentage: 0, prebufferDone: false, actualStart: 0 }
m.top.playStartInfo = { start_type: "cseek", total_dur: 0.1 }
m.top.close = true
m.assertTrue(true, "no crash: the closed player ignored all post-close traffic")
end function
@@ -865,21 +850,6 @@ namespace Tests
m.assertTrue(m.Snap().onCloseCalled, "the finish closed the player from within the position tick")
end function
' Also at the end (closes the player): a heal loop that ran past the telemetry cap reports its
' true size in one tally event when the content ends.
@it("the close summary carries a capped heal loop's true size")
function _()
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.top.callFunc("TestKey", RemoteKeys.Left, false)
for i = 1 to 5
m.top.callFunc("TestSetState", VideoState.Playing)
end for
m.top.close = true
summary = m.global.telemetry.LogEvent
m.assertTrue(summary.message.InStr("5 heals") > 0, "got: " + summary.message)
m.assertTrue(summary.message.InStr("2 past the telemetry cap") > 0, "got: " + summary.message)
end function
end class
end namespace