Dev player rewrite (#883)
This commit is contained in:
1 parent
8c11272b92
commit
1ba454cdab
80 files changed
+8405
-921
No files matched your search
@@ -0,0 +1,95 @@
|
||||
' ErrorDialogController unit suite — the pure error decision logic in isolation. No node, no dialog: seed a
|
||||
' fake content AA + error info and assert the retry-vs-dialog decision + the next-stream-URL advance.
|
||||
|
||||
import "pkg:/components/VideoPlayerDev/ErrorDialogController.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class ErrorDialogControllerTests extends Rooibos.BaseTestSuite
|
||||
|
||||
@describe("next stream url")
|
||||
|
||||
@it("advances the index and returns the next non-empty url")
|
||||
function _()
|
||||
content = { playletStreamUrls: ["a", "b", "c"], playletStreamUrlIndex: 0, url: "a" }
|
||||
url = ErrorDialogController.NextStreamUrl(content)
|
||||
m.assertEqual(url, "b")
|
||||
m.assertEqual(content.playletStreamUrlIndex, 1)
|
||||
m.assertEqual(content.url, "b")
|
||||
end function
|
||||
|
||||
@it("returns invalid at the last url")
|
||||
function _()
|
||||
content = { playletStreamUrls: ["a", "b"], playletStreamUrlIndex: 1, url: "b" }
|
||||
m.assertInvalid(ErrorDialogController.NextStreamUrl(content))
|
||||
m.assertEqual(content.playletStreamUrlIndex, 1)
|
||||
end function
|
||||
|
||||
@it("returns invalid when the next url is empty")
|
||||
function _()
|
||||
content = { playletStreamUrls: ["a", ""], playletStreamUrlIndex: 0, url: "a" }
|
||||
m.assertInvalid(ErrorDialogController.NextStreamUrl(content))
|
||||
end function
|
||||
|
||||
@it("returns invalid when there are no stream urls")
|
||||
function _()
|
||||
content = { playletStreamUrlIndex: 0, url: "a" }
|
||||
m.assertInvalid(ErrorDialogController.NextStreamUrl(content))
|
||||
end function
|
||||
|
||||
@describe("content-job failure")
|
||||
|
||||
@it("returns a dialog action with the load-error title")
|
||||
function _()
|
||||
content = { videoId: "vid123" }
|
||||
d = ErrorDialogController.DecideContentJobFailure(content, "This video is unavailable")
|
||||
m.assertEqual(d.action, ErrorDialogController.Action.Dialog)
|
||||
m.assertEqual(d.title, Tr(Locale.VideoPlayer.VideoLoadError))
|
||||
m.assertTrue(d.message.Instr("vid123") >= 0)
|
||||
m.assertTrue(d.message.Instr("unavailable") >= 0)
|
||||
end function
|
||||
|
||||
@describe("playback error decision")
|
||||
|
||||
@it("retries the next stream url on an http error before playing")
|
||||
function _()
|
||||
content = { videoId: "v", playletStreamUrls: ["a", "b"], playletStreamUrlIndex: 0, url: "a" }
|
||||
d = ErrorDialogController.DecideVideoError(content, { category: "http" }, false)
|
||||
m.assertEqual(d.action, ErrorDialogController.Action.Retry)
|
||||
m.assertEqual(d.nextUrl, "b")
|
||||
m.assertEqual(content.url, "b")
|
||||
end function
|
||||
|
||||
@it("retries on a mediaerror category")
|
||||
function _()
|
||||
content = { videoId: "v", playletStreamUrls: ["a", "b"], playletStreamUrlIndex: 0, url: "a" }
|
||||
d = ErrorDialogController.DecideVideoError(content, { category: "mediaerror" }, false)
|
||||
m.assertEqual(d.action, ErrorDialogController.Action.Retry)
|
||||
m.assertEqual(d.nextUrl, "b")
|
||||
end function
|
||||
|
||||
@it("shows a dialog when no next url exists")
|
||||
function _()
|
||||
content = { videoId: "v", playletStreamUrls: ["a"], playletStreamUrlIndex: 0, url: "a" }
|
||||
d = ErrorDialogController.DecideVideoError(content, { category: "http" }, false)
|
||||
m.assertEqual(d.action, ErrorDialogController.Action.Dialog)
|
||||
end function
|
||||
|
||||
@it("shows a dialog once the stream has already played (no stream-swap)")
|
||||
function _()
|
||||
content = { videoId: "v", playletStreamUrls: ["a", "b"], playletStreamUrlIndex: 0, url: "a" }
|
||||
d = ErrorDialogController.DecideVideoError(content, { category: "http" }, true)
|
||||
m.assertEqual(d.action, ErrorDialogController.Action.Dialog)
|
||||
end function
|
||||
|
||||
@it("shows a dialog for a non-stream error category")
|
||||
function _()
|
||||
content = { videoId: "v", playletStreamUrls: ["a", "b"], playletStreamUrlIndex: 0, url: "a" }
|
||||
d = ErrorDialogController.DecideVideoError(content, { category: "drm" }, false)
|
||||
m.assertEqual(d.action, ErrorDialogController.Action.Dialog)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,252 @@
|
||||
' Unit tests for PlayerCoordinatorLogic: the remote-key-to-command map, the OK/Select 4-cell, and the
|
||||
' buffering-spinner gate. Pure functions, so they run on the main thread with no device.
|
||||
|
||||
import "pkg:/components/VideoPlayerDev/PlayerCoordinatorLogic.bs"
|
||||
import "pkg:/components/VideoPlayerDev/TransportController.bs"
|
||||
import "pkg:/source/utils/RemoteKeys.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class PlayerCoordinatorLogicTests extends Rooibos.BaseTestSuite
|
||||
|
||||
' =========================================================================================
|
||||
' KeyToCommand — the ECP key -> transport Command map
|
||||
' =========================================================================================
|
||||
@describe("KeyToCommand")
|
||||
|
||||
@it("maps every transport key to its own command")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Left), TransportController.Command.Left)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Right), TransportController.Command.Right)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.FastForward), TransportController.Command.Fwd)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Rewind), TransportController.Command.Rev)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Replay), TransportController.Command.Replay)
|
||||
end function
|
||||
|
||||
@it("Rewind is the reverse scan ladder, not the Left step")
|
||||
function _()
|
||||
m.assertTrue(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Rewind) <> TransportController.Command.Left)
|
||||
m.assertTrue(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.FastForward) <> TransportController.Command.Right)
|
||||
end function
|
||||
|
||||
@it("returns Command.None for non-transport keys")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Ok), TransportController.Command.None)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Back), TransportController.Command.None)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand(RemoteKeys.Down), TransportController.Command.None)
|
||||
m.assertEqual(PlayerCoordinatorLogic.KeyToCommand("bogus"), TransportController.Command.None)
|
||||
end function
|
||||
|
||||
' =========================================================================================
|
||||
' OkActionInIdle — the OK/Select 4-cell (VOD) + the live chrome toggle
|
||||
' =========================================================================================
|
||||
@describe("OkActionInIdle")
|
||||
|
||||
@it("VOD playing + chrome shown -> pause")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("playing", true, false), PlayerCoordinatorLogic.OkAction.Pause)
|
||||
end function
|
||||
|
||||
@it("VOD playing + chrome hidden -> reveal (no pause)")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("playing", false, false), PlayerCoordinatorLogic.OkAction.Reveal)
|
||||
end function
|
||||
|
||||
@it("VOD paused + chrome shown -> resume")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("paused", true, false), PlayerCoordinatorLogic.OkAction.Resume)
|
||||
end function
|
||||
|
||||
@it("VOD paused + chrome hidden -> reveal (stays paused)")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("paused", false, false), PlayerCoordinatorLogic.OkAction.Reveal)
|
||||
end function
|
||||
|
||||
@it("live always toggles chrome, never pauses (regardless of play state / chrome)")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("playing", true, true), PlayerCoordinatorLogic.OkAction.ToggleChrome)
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("playing", false, true), PlayerCoordinatorLogic.OkAction.ToggleChrome)
|
||||
m.assertEqual(PlayerCoordinatorLogic.OkActionInIdle("paused", true, true), PlayerCoordinatorLogic.OkAction.ToggleChrome)
|
||||
end function
|
||||
|
||||
' =========================================================================================
|
||||
' ShouldShowBuffering — mid-stream spinner gate (firstFrame AND idle AND fullscreen)
|
||||
' =========================================================================================
|
||||
@describe("ShouldShowBuffering")
|
||||
|
||||
@it("shows only past the first frame, while idle, and fullscreen")
|
||||
function _()
|
||||
m.assertTrue(PlayerCoordinatorLogic.ShouldShowBuffering(true, TransportController.Mode.Idle, true))
|
||||
end function
|
||||
|
||||
@it("never before the first frame (that is the loading overlay)")
|
||||
function _()
|
||||
m.assertFalse(PlayerCoordinatorLogic.ShouldShowBuffering(false, TransportController.Mode.Idle, true))
|
||||
end function
|
||||
|
||||
@it("never during an active transport (the bif covers a seek-rebuffer)")
|
||||
function _()
|
||||
m.assertFalse(PlayerCoordinatorLogic.ShouldShowBuffering(true, TransportController.Mode.Scrub, true))
|
||||
m.assertFalse(PlayerCoordinatorLogic.ShouldShowBuffering(true, TransportController.Mode.Scan, true))
|
||||
end function
|
||||
|
||||
@it("never while minimized (no UI in PiP)")
|
||||
function _()
|
||||
m.assertFalse(PlayerCoordinatorLogic.ShouldShowBuffering(true, TransportController.Mode.Idle, false))
|
||||
end function
|
||||
|
||||
' =========================================================================================
|
||||
' TransportSafetyAction — the TOTAL device-seam freeze decision (P-total: defined for every device state)
|
||||
' =========================================================================================
|
||||
@describe("TransportSafetyAction (total device-seam guard)")
|
||||
|
||||
@it("the guard decision is DEFINED and correct over the FULL axis cross-product (state x transport x live x eof)")
|
||||
function _()
|
||||
' the full Roku Video.state enum — including the ones the old guard ignored (none/paused/stopping/
|
||||
' stopped) — crossed with the live and at-end axes. Only playing-under-a-transport ever acts, and it
|
||||
' finishes (instead of freezing) exactly when VOD has both the device AND the cursor at the end.
|
||||
states = ["none", "buffering", "playing", "paused", "finished", "error", "stopping", "stopped"]
|
||||
durationMs = 210000
|
||||
endMs = 209000 ' within FINISH_EPSILON_MS of the duration
|
||||
midMs = 60000
|
||||
for each s in states
|
||||
for each inT in [true, false]
|
||||
for each isLive in [false, true]
|
||||
for each posAtEnd in [false, true]
|
||||
for each curAtEnd in [false, true]
|
||||
if posAtEnd
|
||||
posMs = endMs
|
||||
else
|
||||
posMs = midMs
|
||||
end if
|
||||
if curAtEnd
|
||||
curMs = endMs
|
||||
else
|
||||
curMs = midMs
|
||||
end if
|
||||
expected = PlayerCoordinatorLogic.SafetyAction.None
|
||||
if inT and s = "playing"
|
||||
if not isLive and posAtEnd and curAtEnd
|
||||
expected = PlayerCoordinatorLogic.SafetyAction.FinishEof
|
||||
else
|
||||
expected = PlayerCoordinatorLogic.SafetyAction.Freeze
|
||||
end if
|
||||
end if
|
||||
got = PlayerCoordinatorLogic.TransportSafetyAction(s, inT, isLive, posMs, curMs, durationMs)
|
||||
m.assertEqual(got, expected, "state=" + s + " inT=" + inT.ToStr() + " live=" + isLive.ToStr() + " posEnd=" + posAtEnd.ToStr() + " curEnd=" + curAtEnd.ToStr())
|
||||
end for
|
||||
end for
|
||||
end for
|
||||
end for
|
||||
end for
|
||||
end function
|
||||
|
||||
@it("an unmodeled / unexpected device state under a transport is a safe no-op, never an undefined freeze")
|
||||
function _()
|
||||
' the wedge's failure mode: a state the guard did not enumerate must NOT trigger a spurious freeze.
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("buffering", true, false, 60000, 60000, 210000), PlayerCoordinatorLogic.SafetyAction.None)
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("some_future_state", true, false, 60000, 60000, 210000), PlayerCoordinatorLogic.SafetyAction.None)
|
||||
end function
|
||||
|
||||
@it("VOD playing at the end under a transport whose cursor is ALSO at the end -> FinishEof, not Freeze")
|
||||
function _()
|
||||
' both the device and the cursor within the 2s epsilon of duration -> finish.
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 209500, 210000), PlayerCoordinatorLogic.SafetyAction.FinishEof)
|
||||
' cursor rewound away from the end -> the user is heading backwards: keep the freeze.
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 100000, 210000), PlayerCoordinatorLogic.SafetyAction.Freeze)
|
||||
' device not at the end -> freeze as usual.
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 60000, 209500, 210000), PlayerCoordinatorLogic.SafetyAction.Freeze)
|
||||
' LIVE has no EOF: always freeze.
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, true, 209000, 209500, 210000), PlayerCoordinatorLogic.SafetyAction.Freeze)
|
||||
' unknown duration -> no EOF concept -> freeze.
|
||||
m.assertEqual(PlayerCoordinatorLogic.TransportSafetyAction("playing", true, false, 209000, 209500, 0), PlayerCoordinatorLogic.SafetyAction.Freeze)
|
||||
end function
|
||||
|
||||
' =========================================================================================
|
||||
' NextButtonIndex — moving focus along the button row
|
||||
' =========================================================================================
|
||||
@describe("button row navigation")
|
||||
|
||||
@it("Left/Right move the focused button and clamp at the ends")
|
||||
function _()
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextButtonIndex(0, RemoteKeys.Right, 2), 1)
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextButtonIndex(1, RemoteKeys.Left, 2), 0)
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextButtonIndex(0, RemoteKeys.Left, 2), 0) ' clamp at the left end
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextButtonIndex(1, RemoteKeys.Right, 2), 1) ' clamp at the right end (count 2)
|
||||
' a larger row still clamps correctly (the count is a parameter, not a constant)
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextButtonIndex(2, RemoteKeys.Right, 4), 3)
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextButtonIndex(3, RemoteKeys.Right, 4), 3)
|
||||
end function
|
||||
|
||||
@it("Up/Down move focus between the bar and the buttons, no wrap")
|
||||
function _()
|
||||
buttons = PlayerCoordinatorLogic.FocusTarget.Buttons
|
||||
bar = PlayerCoordinatorLogic.FocusTarget.Bar
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextFocusTarget(buttons, RemoteKeys.Down), bar)
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextFocusTarget(bar, RemoteKeys.Up), buttons)
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextFocusTarget(buttons, RemoteKeys.Up), buttons) ' already the top tier
|
||||
m.assertEqual(PlayerCoordinatorLogic.NextFocusTarget(bar, RemoteKeys.Down), bar) ' already the bottom tier
|
||||
end function
|
||||
|
||||
' =========================================================================================
|
||||
' PickThumbnailTileSet / TileSetIntervalMs — read the native Video.thumbnailTiles tile-set
|
||||
' =========================================================================================
|
||||
@describe("PickThumbnailTileSet / TileSetIntervalMs")
|
||||
|
||||
@it("picks the first valid native tile-set")
|
||||
function _()
|
||||
ts = PlayerCoordinatorLogic.PickThumbnailTileSet(m.sampleThumbnailTiles())
|
||||
m.assertEqual(ts.htiles, 5)
|
||||
m.assertEqual(ts.vtiles, 5)
|
||||
m.assertEqual(ts.tiles.Count(), 6)
|
||||
m.assertEqual(ts.tiles[0][0], "https://x/M0.jpg")
|
||||
end function
|
||||
|
||||
@it("computes the per-thumbnail interval (per-sheet duration / tiles-per-sheet)")
|
||||
function _()
|
||||
ts = PlayerCoordinatorLogic.PickThumbnailTileSet(m.sampleThumbnailTiles())
|
||||
m.assertEqual(PlayerCoordinatorLogic.TileSetIntervalMs(ts), 5000) ' 125s / 25 tiles = 5s
|
||||
end function
|
||||
|
||||
@it("returns invalid when there is no tile-set")
|
||||
function _()
|
||||
m.assertInvalid(PlayerCoordinatorLogic.PickThumbnailTileSet(invalid))
|
||||
m.assertInvalid(PlayerCoordinatorLogic.PickThumbnailTileSet({}))
|
||||
end function
|
||||
|
||||
@it("returns invalid for a degenerate tile-set (no per-sheet duration, empty grid)")
|
||||
function _()
|
||||
noDuration = m.sampleThumbnailTiles()
|
||||
noDuration.set[0].duration = 0
|
||||
m.assertInvalid(PlayerCoordinatorLogic.PickThumbnailTileSet(noDuration))
|
||||
noGrid = m.sampleThumbnailTiles()
|
||||
noGrid.set[0].htiles = 0
|
||||
m.assertInvalid(PlayerCoordinatorLogic.PickThumbnailTileSet(noGrid))
|
||||
end function
|
||||
|
||||
' a tile-set shaped like the OS's Video.thumbnailTiles (one descriptor key -> [tileSet]).
|
||||
function sampleThumbnailTiles() as object
|
||||
return {
|
||||
set: [{
|
||||
duration: 125 ' seconds covered by ONE 5x5 sheet
|
||||
final_time: 634.566
|
||||
htiles: 5
|
||||
vtiles: 5
|
||||
width: 160
|
||||
height: 90
|
||||
tiles: [
|
||||
["https://x/M0.jpg", 0, ""]
|
||||
["https://x/M1.jpg", 125, ""]
|
||||
["https://x/M2.jpg", 250, ""]
|
||||
["https://x/M3.jpg", 375, ""]
|
||||
["https://x/M4.jpg", 500, ""]
|
||||
["https://x/M5.jpg", 625, ""]
|
||||
]
|
||||
}]
|
||||
}
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,100 @@
|
||||
import "pkg:/components/VideoPlayerDev/TransportController.bs"
|
||||
|
||||
' Pure invariant predicates for the transport brain. The catalog (with rationale) is the VideoPlayerDev README.
|
||||
'
|
||||
' Two tiers exist; this module is tier one:
|
||||
' INV-B* brain-level — a pure function of the brain's OUTPUT fields. Checkable off-device, so the exhaustive
|
||||
' + fuzz transport tests run CheckBrain after EVERY step. THIS module.
|
||||
' INV-D* device-seam — needs the live Video.state (which the brain has no field for), so they live in the
|
||||
' e2e harness (assertPlayerInvariants). The bug class "video playing while a transport is active"
|
||||
' is an INV-D — inexpressible here.
|
||||
'
|
||||
' CheckBrain takes a plain AA SNAPSHOT of the brain's fields (not the Controller instance) so the predicate
|
||||
' stays decoupled and trivially constructible in a test. Returns { ok, failed } — failed = the INV id that
|
||||
' broke, or "" when ok.
|
||||
|
||||
namespace PlayerInvariants
|
||||
|
||||
' Snapshot keys: transportMode, glyph, scanLevel, scanDir, scrubHeldDir, cursorMs, positionMs, durationMs,
|
||||
' edgeMs, liveOffsetMs, atLiveEdge, isLive, replayPending.
|
||||
function CheckBrain(s as object) as object
|
||||
hi = s.durationMs
|
||||
if s.isLive
|
||||
hi = s.edgeMs
|
||||
end if
|
||||
|
||||
' INV-B1 — the cursor stays within [0, hi] (hi = duration on VOD, the live edge on live).
|
||||
if s.cursorMs < 0
|
||||
return Fail("INV-B1")
|
||||
end if
|
||||
if hi > 0 and s.cursorMs > hi
|
||||
return Fail("INV-B1")
|
||||
end if
|
||||
|
||||
' INV-B3 — the live offset is never negative.
|
||||
if s.liveOffsetMs < 0
|
||||
return Fail("INV-B3")
|
||||
end if
|
||||
|
||||
' INV-B5 — scan ladder scratch is bounded; a non-zero level implies an active scan/live-ladder mode.
|
||||
if s.scanDir < -1 or s.scanDir > 1
|
||||
return Fail("INV-B5")
|
||||
end if
|
||||
if s.scanLevel < 0 or s.scanLevel > TransportController.SCAN_LEVEL_MAX
|
||||
return Fail("INV-B5")
|
||||
end if
|
||||
if s.scanLevel >= 1 and s.transportMode <> TransportController.Mode.Scan and s.transportMode <> TransportController.Mode.LiveDvr
|
||||
return Fail("INV-B5")
|
||||
end if
|
||||
|
||||
' INV-B8 — the held scrub direction is bounded.
|
||||
if s.scrubHeldDir < -1 or s.scrubHeldDir > 1
|
||||
return Fail("INV-B8")
|
||||
end if
|
||||
|
||||
' INV-B6 — at most one held input: the step (scrubHeldDir) and ladder (scanDir) scratch never bleed.
|
||||
if s.scrubHeldDir <> 0 and s.scanDir <> 0
|
||||
return Fail("INV-B6")
|
||||
end if
|
||||
|
||||
' INV-B4 — the glyph is legal for the current mode.
|
||||
if not GlyphOkForMode(s.transportMode, s.glyph)
|
||||
return Fail("INV-B4")
|
||||
end if
|
||||
|
||||
' (INV-B7 "idle => cursor==position" is intentionally NOT enforced: after a replay/SB seek the cursor
|
||||
' legitimately differs from positionMs until the next OnPosition lands, and the idle bar reads
|
||||
' positionMs anyway — so it's a harmless transient, not a safety property. See the VideoPlayerDev README.)
|
||||
|
||||
return { ok: true, failed: "" }
|
||||
end function
|
||||
|
||||
function Fail(id as string) as object
|
||||
return { ok: false, failed: id }
|
||||
end function
|
||||
|
||||
' Glyph ↔ mode: idle shows nothing or the transient replay icon; scrub shows the step glyphs; scan shows
|
||||
' the ffx/rwx ladder; live can be in either step (skip) or ladder (ffx/rwx) sub-mode, or none mid-release.
|
||||
function GlyphOkForMode(mode as integer, glyph as integer) as boolean
|
||||
if mode = TransportController.Mode.Idle
|
||||
return glyph = TransportController.Glyph.None or glyph = TransportController.Glyph.Replay
|
||||
else if mode = TransportController.Mode.Scrub
|
||||
return glyph = TransportController.Glyph.None or glyph = TransportController.Glyph.SkipBack or glyph = TransportController.Glyph.SkipAhead
|
||||
else if mode = TransportController.Mode.Scan
|
||||
return glyph >= TransportController.Glyph.Ffx1 and glyph <= TransportController.Glyph.Rwx3
|
||||
else if mode = TransportController.Mode.LiveDvr
|
||||
if glyph = TransportController.Glyph.None or glyph = TransportController.Glyph.SkipBack or glyph = TransportController.Glyph.SkipAhead
|
||||
return true
|
||||
end if
|
||||
return glyph >= TransportController.Glyph.Ffx1 and glyph <= TransportController.Glyph.Rwx3
|
||||
end if
|
||||
return false
|
||||
end function
|
||||
|
||||
' The brain INV ids this module enforces — the meta-test pins this set against the VideoPlayerDev README so a
|
||||
' catalog row can't be added without an implementation (or vice-versa).
|
||||
function BrainIds() as object
|
||||
return ["INV-B1", "INV-B3", "INV-B4", "INV-B5", "INV-B6", "INV-B8"]
|
||||
end function
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,202 @@
|
||||
' SponsorBlockController unit suite — the pure SponsorBlock decision logic in isolation. No real job: seed the
|
||||
' segments array directly + a fake `top` (for duration) and assert the find/skip/chapter decisions. The
|
||||
' notification + job plumbing live in the coordinator; manual-skip is tested via the stash + position guard.
|
||||
|
||||
import "pkg:/components/VideoPlayerDev/SponsorBlockController.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class SponsorBlockControllerTests extends Rooibos.BaseTestSuite
|
||||
|
||||
protected override function beforeEach()
|
||||
' a fake Video node: only `duration` (seconds) + `seekMode` are read/written by the controller.
|
||||
m.fakeTop = { duration: 282.0, seekMode: "default" }
|
||||
m.sb = new SponsorBlockController.Controller({
|
||||
jobQueue: invalid
|
||||
preferences: invalid
|
||||
notifications: invalid
|
||||
top: m.fakeTop
|
||||
})
|
||||
' Despacito-like segments: music_offtopic [0,21.808] manual, sponsor [100,110] auto, music_offtopic
|
||||
' [249.38,281.521] manual. Sorted by start.
|
||||
m.segments = [
|
||||
{ start: 0.0, end: 21.808, option: "manual_skip", title: "Music: Non-Music Section", shortTitle: "Non-Music", showNotification: true, UUID: "seg-a", category: "music_offtopic" }
|
||||
{ start: 100.0, end: 110.0, option: "auto_skip", title: "Sponsor", shortTitle: "Sponsor", showNotification: false, UUID: "seg-b", category: "sponsor" }
|
||||
{ start: 249.38, end: 281.521, option: "manual_skip", title: "Music: Non-Music Section", shortTitle: "Non-Music", showNotification: true, UUID: "seg-c", category: "music_offtopic" }
|
||||
]
|
||||
' seed the controller as if the job had returned (the enable gate + stored segments).
|
||||
m.sb.enabled = true
|
||||
m.sb.segments = m.segments
|
||||
end function
|
||||
|
||||
@describe("find segment by time")
|
||||
|
||||
@it("finds the segment containing the time")
|
||||
function _()
|
||||
seg = SponsorBlockController.FindSegmentByTime(m.segments, 12.0)
|
||||
m.assertEqual(seg.UUID, "seg-a")
|
||||
seg = SponsorBlockController.FindSegmentByTime(m.segments, 105.0)
|
||||
m.assertEqual(seg.UUID, "seg-b")
|
||||
end function
|
||||
|
||||
@it("returns invalid between segments")
|
||||
function _()
|
||||
m.assertInvalid(SponsorBlockController.FindSegmentByTime(m.segments, 50.0))
|
||||
m.assertInvalid(SponsorBlockController.FindSegmentByTime(m.segments, 200.0))
|
||||
end function
|
||||
|
||||
@it("includes the segment boundaries")
|
||||
function _()
|
||||
m.assertEqual(SponsorBlockController.FindSegmentByTime(m.segments, 0.0).UUID, "seg-a")
|
||||
m.assertEqual(SponsorBlockController.FindSegmentByTime(m.segments, 21.808).UUID, "seg-a")
|
||||
end function
|
||||
|
||||
@describe("skip target")
|
||||
|
||||
@it("returns the segment end (ms) as the seek target")
|
||||
function _()
|
||||
seg = m.segments[1] ' [100,110] auto
|
||||
result = SponsorBlockController.SkipTargetForSegment(seg, 102.0, m.fakeTop.duration)
|
||||
m.assertEqual(result.skipSeekMs, 110000)
|
||||
end function
|
||||
|
||||
@it("returns finish when the segment ends within 2s of the video end")
|
||||
function _()
|
||||
' [249.38,281.521], duration 282 -> end within 2s of duration -> finish.
|
||||
seg = m.segments[2]
|
||||
result = SponsorBlockController.SkipTargetForSegment(seg, 250.0, m.fakeTop.duration)
|
||||
m.assertTrue(result.finish = true)
|
||||
end function
|
||||
|
||||
@it("returns invalid when the skip distance is under 2s")
|
||||
function _()
|
||||
seg = m.segments[1] ' [100,110]
|
||||
result = SponsorBlockController.SkipTargetForSegment(seg, 109.0, m.fakeTop.duration)
|
||||
m.assertInvalid(result)
|
||||
end function
|
||||
|
||||
@it("clamps the segment end to the video duration")
|
||||
function _()
|
||||
m.fakeTop.duration = 105.0
|
||||
seg = m.segments[1] ' [100,110] -> clamped to 105 == duration -> within 2s -> finish
|
||||
result = SponsorBlockController.SkipTargetForSegment(seg, 101.0, m.fakeTop.duration)
|
||||
m.assertTrue(result.finish = true)
|
||||
end function
|
||||
|
||||
@describe("OnPosition auto-skip")
|
||||
|
||||
@it("returns a skip seek target while inside an auto-skip segment")
|
||||
function _()
|
||||
result = m.sb.OnPosition(105000) ' 105s, inside [100,110] auto
|
||||
m.assertEqual(result.skipSeekMs, 110000)
|
||||
end function
|
||||
|
||||
@it("returns invalid inside a manual-skip segment + stashes it for OK")
|
||||
function _()
|
||||
m.sb.notifications = CreateObject("roSGNode", "Group")
|
||||
result = m.sb.OnPosition(5000) ' inside [0,21.808] manual
|
||||
m.assertInvalid(result)
|
||||
m.assertEqual(m.sb.manualSkipSegment.UUID, "seg-a")
|
||||
end function
|
||||
|
||||
@it("TrySkip returns the stashed manual segment's end while still inside it")
|
||||
function _()
|
||||
m.sb.notifications = CreateObject("roSGNode", "Group")
|
||||
m.sb.OnPosition(5000) ' stash [0,21.808]
|
||||
target = m.sb.TrySkip(6000) ' still inside -> seek to 21.808s = 21808ms
|
||||
m.assertEqual(target, 21808)
|
||||
end function
|
||||
|
||||
@it("TrySkip returns -1 with nothing stashed")
|
||||
function _()
|
||||
m.assertEqual(m.sb.TrySkip(6000), -1)
|
||||
end function
|
||||
|
||||
@it("returns invalid outside any segment")
|
||||
function _()
|
||||
m.assertInvalid(m.sb.OnPosition(50000))
|
||||
end function
|
||||
|
||||
@it("returns invalid when disabled")
|
||||
function _()
|
||||
m.sb.enabled = false
|
||||
m.assertInvalid(m.sb.OnPosition(105000))
|
||||
end function
|
||||
|
||||
@describe("manual notice dismissal (Back)")
|
||||
|
||||
@it("DismissManual removes the armed notice and suppresses re-arm while inside the segment")
|
||||
function _()
|
||||
m.sb.notifications = CreateObject("roSGNode", "Group")
|
||||
m.sb.OnPosition(5000) ' arm + show the manual notice for [0,21.808]
|
||||
m.assertTrue(m.sb.DismissManual())
|
||||
m.assertInvalid(m.sb.manualSkipSegment)
|
||||
' still inside the segment: the notice must NOT re-arm/re-show on the next position ticks.
|
||||
m.assertInvalid(m.sb.OnPosition(6000))
|
||||
m.assertInvalid(m.sb.manualSkipSegment)
|
||||
m.assertEqual(m.sb.TrySkip(7000), -1)
|
||||
end function
|
||||
|
||||
@it("DismissManual is a no-op without an armed notice")
|
||||
function _()
|
||||
m.sb.notifications = CreateObject("roSGNode", "Group")
|
||||
m.assertFalse(m.sb.DismissManual())
|
||||
end function
|
||||
|
||||
@it("leaving the segment clears the dismissal, so a later re-entry re-arms the notice")
|
||||
function _()
|
||||
m.sb.notifications = CreateObject("roSGNode", "Group")
|
||||
m.sb.OnPosition(5000)
|
||||
m.assertTrue(m.sb.DismissManual())
|
||||
m.sb.OnPosition(50000) ' outside any segment -> the dismissal is forgotten
|
||||
m.sb.OnPosition(7000) ' back inside -> armed again
|
||||
m.assertEqual(m.sb.manualSkipSegment.UUID, "seg-a")
|
||||
end function
|
||||
|
||||
@describe("chapter text")
|
||||
|
||||
@it("returns the segment title while the cursor is inside a segment")
|
||||
function _()
|
||||
m.assertEqual(m.sb.ChapterTextForCursor(12000), "Music: Non-Music Section")
|
||||
end function
|
||||
|
||||
@it("returns empty between segments")
|
||||
function _()
|
||||
m.assertEqual(m.sb.ChapterTextForCursor(50000), "")
|
||||
end function
|
||||
|
||||
@it("returns empty when disabled")
|
||||
function _()
|
||||
m.sb.enabled = false
|
||||
m.assertEqual(m.sb.ChapterTextForCursor(12000), "")
|
||||
end function
|
||||
|
||||
@describe("content-ready gate")
|
||||
|
||||
@it("returns invalid on live")
|
||||
function _()
|
||||
sb = new SponsorBlockController.Controller({ jobQueue: invalid, preferences: { "sponsorblock.enabled": true }, notifications: invalid, top: m.fakeTop })
|
||||
m.assertInvalid(sb.OnContentReady({ videoId: "x", lengthSeconds: 100 }, true))
|
||||
end function
|
||||
|
||||
@it("returns invalid when the pref is off")
|
||||
function _()
|
||||
sb = new SponsorBlockController.Controller({ jobQueue: invalid, preferences: { "sponsorblock.enabled": false }, notifications: invalid, top: m.fakeTop })
|
||||
m.assertInvalid(sb.OnContentReady({ videoId: "x", lengthSeconds: 100 }, false))
|
||||
end function
|
||||
|
||||
@it("returns the job input when enabled + VOD")
|
||||
function _()
|
||||
prefs = { "sponsorblock.enabled": true, "sponsorblock.show_notifications": true, "sponsorblock.categories": {} }
|
||||
sb = new SponsorBlockController.Controller({ jobQueue: invalid, preferences: prefs, notifications: invalid, top: m.fakeTop })
|
||||
input = sb.OnContentReady({ videoId: "abc", lengthSeconds: 282 }, false)
|
||||
m.assertNotInvalid(input)
|
||||
m.assertEqual(input.videoId, "abc")
|
||||
m.assertEqual(input.lengthSeconds, 282)
|
||||
m.assertTrue(sb.enabled)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,309 @@
|
||||
' Completeness suite for the transport brain — the answer to "are ALL transitions accounted for?".
|
||||
' Where TransportController.spec.bs is example-by-example, this drives the WHOLE finite state x input space
|
||||
' (exhaustive) and random input sequences (seeded fuzz, with shrinking to a minimal repro), asserting
|
||||
' PlayerInvariants.CheckBrain after EVERY step. A regression that produces a contradictory brain state is
|
||||
' caught here and located by INV id + a short repro, not chased.
|
||||
|
||||
import "pkg:/components/VideoPlayerDev/TransportController.bs"
|
||||
import "pkg:/source/tests/VideoPlayerDev/PlayerInvariants.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class TransportControllerCompletenessTests extends Rooibos.BaseTestSuite
|
||||
|
||||
' ---------- brain builders / snapshot ----------
|
||||
|
||||
' a fresh brain at rest (idle, ready) with realistic content facts. windowMs = the live DVR window
|
||||
' (0 = unknown), the axis that decides the rewind floor and live rewindability.
|
||||
function Fresh(isLive as boolean, windowMs = 0 as integer) as object
|
||||
t = new TransportController.Controller()
|
||||
t.SetContent(isLive, 2000, true)
|
||||
t.SetLiveDvrWindow(windowMs)
|
||||
t.OnReady()
|
||||
if isLive
|
||||
t.OnLiveEdge(600000) ' clock-anchored live edge
|
||||
else
|
||||
t.OnDuration(600000) ' 10min VOD
|
||||
end if
|
||||
t.OnPosition(120000) ' 2:00
|
||||
return t
|
||||
end function
|
||||
|
||||
' the content variants the exhaustive matrix + fuzz sweep: VOD, live with an unknown window, live with
|
||||
' a buffer-sized (non-rewindable) window, and live with a real window (active rewind floor).
|
||||
function Variants() as object
|
||||
return [
|
||||
{ isLive: false, windowMs: 0, tag: " [vod] " }
|
||||
{ isLive: true, windowMs: 0, tag: " [live] " }
|
||||
{ isLive: true, windowMs: 30000, tag: " [live no-dvr] " }
|
||||
{ isLive: true, windowMs: 90000, tag: " [live windowed] " }
|
||||
]
|
||||
end function
|
||||
|
||||
' the brain's output fields in the shape PlayerInvariants.CheckBrain expects.
|
||||
function Snap(t as object) as object
|
||||
return {
|
||||
transportMode: t.transportMode
|
||||
glyph: t.glyph
|
||||
scanLevel: t.scanLevel
|
||||
scanDir: t.scanDir
|
||||
scrubHeldDir: t.scrubHeldDir
|
||||
cursorMs: t.cursorMs
|
||||
positionMs: t.positionMs
|
||||
durationMs: t.durationMs
|
||||
edgeMs: t.edgeMs
|
||||
liveOffsetMs: t.liveOffsetMs
|
||||
atLiveEdge: t.atLiveEdge
|
||||
isLive: t.isLive
|
||||
replayPending: t.replayPending
|
||||
}
|
||||
end function
|
||||
|
||||
function AssertInv(t as object, where as string) as void
|
||||
r = PlayerInvariants.CheckBrain(m.Snap(t))
|
||||
m.assertTrue(r.ok, r.failed + " violated after " + where)
|
||||
end function
|
||||
|
||||
' reachable-state labels — each built by DRIVING the brain (only reachable states are tested). On live
|
||||
' the same label reaches a live mode (left -> liveDvr step, fwd -> liveDvr ladder).
|
||||
function Labels() as object
|
||||
return ["idle", "scrub", "scrubHeld", "scan1", "scan2", "replay"]
|
||||
end function
|
||||
|
||||
function Build(label as string, isLive as boolean, windowMs = 0 as integer) as object
|
||||
t = m.Fresh(isLive, windowMs)
|
||||
if label = "scrub"
|
||||
t.HandleKey(TransportController.Command.Left, true)
|
||||
t.HandleKey(TransportController.Command.Left, false) ' release -> frozen, glyph cleared
|
||||
else if label = "scrubHeld"
|
||||
t.HandleKey(TransportController.Command.Left, true) ' held
|
||||
else if label = "scan1"
|
||||
t.HandleCommand(TransportController.Command.Fwd)
|
||||
else if label = "scan2"
|
||||
t.HandleCommand(TransportController.Command.Fwd)
|
||||
t.HandleCommand(TransportController.Command.Fwd)
|
||||
else if label = "replay"
|
||||
t.HandleCommand(TransportController.Command.Replay)
|
||||
end if
|
||||
return t
|
||||
end function
|
||||
|
||||
' ---------- exhaustive (state x input) matrix ----------
|
||||
|
||||
@describe("transport completeness")
|
||||
|
||||
@it("every (reachable state x input) preserves the brain invariants")
|
||||
function _()
|
||||
cmds = [TransportController.Command.Left, TransportController.Command.Right, TransportController.Command.Rev, TransportController.Command.Fwd, TransportController.Command.Replay, TransportController.Command.Commit]
|
||||
ticks = [TransportController.Timer.ScrubRepeat, TransportController.Timer.Scan, TransportController.Timer.ReplayToast]
|
||||
positions = [0, 120000, 300000]
|
||||
durations = [300000, 600000, 900000]
|
||||
for each v in m.Variants()
|
||||
tag = v.tag
|
||||
for each label in m.Labels()
|
||||
' the built state itself must be consistent.
|
||||
m.AssertInv(m.Build(label, v.isLive, v.windowMs), label + tag + "(built)")
|
||||
for each cmd in cmds
|
||||
t = m.Build(label, v.isLive, v.windowMs)
|
||||
t.HandleCommand(cmd)
|
||||
m.AssertInv(t, label + tag + "+cmd=" + cmd.ToStr())
|
||||
end for
|
||||
for each upKey in [TransportController.Command.Left, TransportController.Command.Right]
|
||||
t = m.Build(label, v.isLive, v.windowMs)
|
||||
t.HandleKey(upKey, false)
|
||||
m.AssertInv(t, label + tag + "+keyUp=" + upKey.ToStr())
|
||||
end for
|
||||
' live edge events: a 1s heartbeat step, a big jump (resume catch-up), and a regression
|
||||
' (a fallback re-anchor) — every state must absorb each of them.
|
||||
for each delta in [1000, 50000, -30000]
|
||||
t = m.Build(label, v.isLive, v.windowMs)
|
||||
t.OnLiveEdge(t.edgeMs + delta)
|
||||
m.AssertInv(t, label + tag + "+edge" + delta.ToStr())
|
||||
end for
|
||||
for each tid in ticks
|
||||
t = m.Build(label, v.isLive, v.windowMs)
|
||||
t.Tick(tid)
|
||||
m.AssertInv(t, label + tag + "+tick=" + tid.ToStr())
|
||||
end for
|
||||
for each p in positions
|
||||
t = m.Build(label, v.isLive, v.windowMs)
|
||||
t.OnPosition(p)
|
||||
m.AssertInv(t, label + tag + "+pos=" + p.ToStr())
|
||||
end for
|
||||
for each d in durations
|
||||
' on live, a large d is an abrupt edge jump past the built position -> exercises the idle
|
||||
' fall-behind detection (atLiveEdge clears, the offset grows) under the invariant check.
|
||||
t = m.Build(label, v.isLive, v.windowMs)
|
||||
t.OnDuration(d)
|
||||
m.AssertInv(t, label + tag + "+dur=" + d.ToStr())
|
||||
end for
|
||||
end for
|
||||
end for
|
||||
end function
|
||||
|
||||
' ---------- seeded fuzz with shrink ----------
|
||||
|
||||
' a 16-bit LCG (ZX-Spectrum constants): s*25173 < 2^31 so it never overflows Integer; deterministic +
|
||||
' reproducible (NOT Rnd, which is clock-seeded). Token = s mod 13 -> one input.
|
||||
function Lcg(s as integer) as integer
|
||||
return (s * 25173 + 13849) and 65535
|
||||
end function
|
||||
|
||||
function GenSeq(seed as integer, n as integer) as object
|
||||
seq = []
|
||||
s = seed
|
||||
for i = 0 to n - 1
|
||||
s = m.Lcg(s)
|
||||
seq.Push(s mod 13)
|
||||
end for
|
||||
return seq
|
||||
end function
|
||||
|
||||
function ApplyToken(t as object, tok as integer) as void
|
||||
if tok = 0
|
||||
t.HandleKey(TransportController.Command.Left, true)
|
||||
else if tok = 1
|
||||
t.HandleKey(TransportController.Command.Right, true)
|
||||
else if tok = 2
|
||||
t.HandleKey(TransportController.Command.Rev, true)
|
||||
else if tok = 3
|
||||
t.HandleKey(TransportController.Command.Fwd, true)
|
||||
else if tok = 4
|
||||
t.HandleCommand(TransportController.Command.Replay)
|
||||
else if tok = 5
|
||||
t.HandleCommand(TransportController.Command.Commit)
|
||||
else if tok = 6
|
||||
t.HandleKey(TransportController.Command.Left, false)
|
||||
else if tok = 7
|
||||
t.HandleKey(TransportController.Command.Right, false)
|
||||
else if tok = 8
|
||||
t.Tick(TransportController.Timer.ScrubRepeat)
|
||||
else if tok = 9
|
||||
t.Tick(TransportController.Timer.Scan)
|
||||
else if tok = 10
|
||||
t.OnLiveEdge(t.edgeMs + 7000) ' the live heartbeat / a resume catch-up step
|
||||
else if tok = 11
|
||||
t.Tick(TransportController.Timer.ReplayToast)
|
||||
else if tok = 12
|
||||
t.OnLiveEdge(t.edgeMs + 50000) ' a big edge jump (long pause's catch-up)
|
||||
end if
|
||||
end function
|
||||
|
||||
' replay a token sequence; return the index of the first invariant failure, or -1 if none.
|
||||
function ReplaySeq(seq as object, v as object) as integer
|
||||
t = m.Fresh(v.isLive, v.windowMs)
|
||||
for i = 0 to seq.Count() - 1
|
||||
m.ApplyToken(t, seq[i])
|
||||
if not PlayerInvariants.CheckBrain(m.Snap(t)).ok
|
||||
return i
|
||||
end if
|
||||
end for
|
||||
return -1
|
||||
end function
|
||||
|
||||
' shrink to the shortest failing prefix (a minimal repro, not a 150-step trace).
|
||||
function Shrink(seq as object, failAt as integer, v as object) as object
|
||||
for k = 0 to failAt
|
||||
prefix = []
|
||||
for j = 0 to k
|
||||
prefix.Push(seq[j])
|
||||
end for
|
||||
if m.ReplaySeq(prefix, v) >= 0
|
||||
return prefix
|
||||
end if
|
||||
end for
|
||||
return seq
|
||||
end function
|
||||
|
||||
@it("invariants hold after every step of seeded random input sequences (shrinkable)")
|
||||
function _()
|
||||
for each seed in [1, 2, 7, 42, 1337]
|
||||
for each v in m.Variants()
|
||||
seq = m.GenSeq(seed, 150)
|
||||
failAt = m.ReplaySeq(seq, v)
|
||||
if failAt >= 0
|
||||
minSeq = m.Shrink(seq, failAt, v)
|
||||
m.fail("seed=" + seed.ToStr() + v.tag + "failed; minimal repro (" + minSeq.Count().ToStr() + " tokens): " + FormatJson(minSeq))
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
end function
|
||||
|
||||
' ---------- meta: CheckBrain actually enforces each catalogued invariant ----------
|
||||
|
||||
@it("CheckBrain passes a good snapshot and catches each break by its INV id")
|
||||
function _()
|
||||
good = {
|
||||
transportMode: TransportController.Mode.Idle, glyph: TransportController.Glyph.None
|
||||
scanLevel: 0, scanDir: 0, scrubHeldDir: 0, cursorMs: 1000, positionMs: 1000
|
||||
durationMs: 600000, edgeMs: 0, liveOffsetMs: 0, atLiveEdge: true, isLive: false, replayPending: false
|
||||
}
|
||||
m.assertTrue(PlayerInvariants.CheckBrain(good).ok, "good snapshot should pass")
|
||||
|
||||
m.assertEqual(m.Break(good, "cursorMs", -1).failed, "INV-B1")
|
||||
m.assertEqual(m.Break(good, "cursorMs", 700000).failed, "INV-B1") ' > duration
|
||||
m.assertEqual(m.Break(good, "liveOffsetMs", -1).failed, "INV-B3")
|
||||
m.assertEqual(m.Break(good, "glyph", TransportController.Glyph.Ffx1).failed, "INV-B4") ' ffx illegal in idle
|
||||
m.assertEqual(m.Break(good, "scanDir", 2).failed, "INV-B5")
|
||||
m.assertEqual(m.Break(good, "scanLevel", 1).failed, "INV-B5") ' level>=1 but mode=idle
|
||||
m.assertEqual(m.Break(good, "scrubHeldDir", 5).failed, "INV-B8")
|
||||
|
||||
' INV-B6 needs BOTH held scratch non-zero.
|
||||
bleed = {}
|
||||
bleed.Append(good)
|
||||
bleed.scrubHeldDir = 1
|
||||
bleed.scanDir = 1
|
||||
m.assertEqual(PlayerInvariants.CheckBrain(bleed).failed, "INV-B6")
|
||||
|
||||
' the catalogued id set is pinned (the VideoPlayerDev README must match BrainIds).
|
||||
m.assertEqual(PlayerInvariants.BrainIds(), ["INV-B1", "INV-B3", "INV-B4", "INV-B5", "INV-B6", "INV-B8"])
|
||||
end function
|
||||
|
||||
' ---------- meta: the model accounts for EVERY mutable brain field (no unmodeled axis) ----------
|
||||
|
||||
@it("the completeness model accounts for every mutable brain field (catches an unmodeled axis)")
|
||||
function _()
|
||||
' Guards the headline fear: a NEW brain field (a new FSM axis) added without being modeled. A BS class
|
||||
' is an AA, so we reflect over the instance and require every non-method field to be consciously
|
||||
' classified. A new field fails this until someone decides where it belongs — it forces the decision,
|
||||
' it cannot prove the decision correct (the irreducible model-faithfulness limit).
|
||||
t = new TransportController.Controller()
|
||||
|
||||
' FSM AXES — discrete state the exhaustive matrix enumerates + the invariants constrain.
|
||||
axes = ["transportMode", "glyph", "scanLevel", "scanDir", "scrubHeldDir", "atLiveEdge", "isLive", "ready", "hasStoryboards", "replayPending", "seekSettling"]
|
||||
' CONTINUOUS — equivalence-classed by the guard predicates (cursor/edge/duration compares), not enumerated.
|
||||
continuous = ["cursorMs", "positionMs", "durationMs", "edgeMs", "liveOffsetMs", "storyboardStepMs", "replayTargetMs", "dvrWindowMs", "liveMinGapMs", "liveMinCandidateMs"]
|
||||
' OUTPUT / IO scratch — drained by the coordinator, not state the FSM branches on.
|
||||
io = ["videoIntent", "intentSeq", "commitSeq", "exitSeq", "finishSeq", "timerCmdAction", "timerCmdId", "timerCmdDelayMs", "timerCmdRepeat"]
|
||||
|
||||
accounted = {}
|
||||
for each name in axes : accounted[name] = "axis" : end for
|
||||
for each name in continuous : accounted[name] = "continuous" : end for
|
||||
for each name in io : accounted[name] = "io" : end for
|
||||
|
||||
found = 0
|
||||
for each key in t
|
||||
if type(t[key]) <> "Function" and type(t[key]) <> "roFunction" and Left(key, 2) <> "__"
|
||||
found = found + 1
|
||||
m.assertTrue(accounted.DoesExist(key), "UNMODELED brain field '" + key + "' — classify it (axis/continuous/io) in this meta-test + add an invariant if it is an axis")
|
||||
end if
|
||||
end for
|
||||
m.assertTrue(found >= 20, "reflection found only " + found.ToStr() + " fields — class iteration may not expose fields; the meta-test would pass vacuously")
|
||||
|
||||
' reverse: nothing we claim to account for has rotted away.
|
||||
for each name in accounted
|
||||
m.assertTrue(t.DoesExist(name), "stale accounted field '" + name + "' is no longer on the brain")
|
||||
end for
|
||||
end function
|
||||
|
||||
function Break(good as object, key as string, val as dynamic) as object
|
||||
s = {}
|
||||
s.Append(good)
|
||||
s[key] = val
|
||||
return PlayerInvariants.CheckBrain(s)
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
@@ -0,0 +1,92 @@
|
||||
' Pins the test mock's node tree to the real component's. VideoPlayerDevMock.xml is a hand-mirrored copy of
|
||||
' VideoPlayerDev.xml (same child ids so the coordinator's findNode()s resolve); silent drift between the two
|
||||
' weakens every seam test built on the mock. This suite parses both XMLs from pkg and asserts:
|
||||
' - every real child id exists in the mock (minus the documented omissions) and vice versa;
|
||||
' - same-id duration attributes (Timers/Animations) match.
|
||||
' Element TYPES may differ (the mock substitutes simpler nodes with the same field surface, e.g. Label for
|
||||
' ScrollingLabel), so type parity is intentionally not checked.
|
||||
|
||||
import "pkg:/source/utils/Types.bs"
|
||||
|
||||
namespace Tests
|
||||
|
||||
@suite
|
||||
class VideoPlayerDevMockParityTests extends Rooibos.BaseTestSuite
|
||||
|
||||
' ids of REAL children the mock intentionally omits (currently none — the mock mirrors everything,
|
||||
' including the PiP minimize animation, so OnFullScreenChange is runnable at the seam).
|
||||
function MockOmissions() as object
|
||||
return {}
|
||||
end function
|
||||
|
||||
' Parse a component XML from pkg and index its <children> subtree: id -> { duration } ("" if absent).
|
||||
function ChildIndex(path as string) as object
|
||||
text = ReadAsciiFile(path)
|
||||
xml = CreateObject("roXMLElement")
|
||||
parsed = (text <> "") and xml.Parse(text)
|
||||
index = {}
|
||||
if parsed
|
||||
for each section in xml.GetChildElements()
|
||||
if LCase(section.GetName()) = "children"
|
||||
m.Collect(section, index)
|
||||
end if
|
||||
end for
|
||||
end if
|
||||
return { parsed: parsed, index: index }
|
||||
end function
|
||||
|
||||
function Collect(el as object, index as object) as void
|
||||
kids = el.GetChildElements()
|
||||
if kids = invalid
|
||||
return
|
||||
end if
|
||||
for each kid in kids
|
||||
attrs = kid.GetAttributes()
|
||||
id = ValidString(attrs.id)
|
||||
if id <> ""
|
||||
index[id] = { duration: ValidString(attrs.duration) }
|
||||
end if
|
||||
m.Collect(kid, index)
|
||||
end for
|
||||
end function
|
||||
|
||||
@describe("mock parity")
|
||||
|
||||
@it("the mock mirrors the real component's children (ids + timer/animation durations)")
|
||||
function _()
|
||||
real = m.ChildIndex("pkg:/components/VideoPlayerDev/VideoPlayerDev.xml")
|
||||
mock = m.ChildIndex("pkg:/components/VideoPlayerDev/tests/VideoPlayerDevMock.xml")
|
||||
m.assertTrue(real.parsed, "VideoPlayerDev.xml read + parsed")
|
||||
m.assertTrue(mock.parsed, "VideoPlayerDevMock.xml read + parsed")
|
||||
m.assertTrue(real.index.Count() > 10, "real children found (sanity: the walker isn't vacuous)")
|
||||
|
||||
omissions = m.MockOmissions()
|
||||
for each id in real.index
|
||||
if not omissions.DoesExist(id)
|
||||
m.assertTrue(mock.index.DoesExist(id), "mock is missing child id '" + id + "' — mirror it (or add a documented omission)")
|
||||
end if
|
||||
end for
|
||||
for each id in mock.index
|
||||
m.assertTrue(real.index.DoesExist(id), "mock child id '" + id + "' no longer exists in VideoPlayerDev.xml")
|
||||
end for
|
||||
|
||||
' durations (Timers/Animations) must match where either side declares one.
|
||||
for each id in mock.index
|
||||
if real.index.DoesExist(id)
|
||||
realDur = real.index[id].duration
|
||||
mockDur = mock.index[id].duration
|
||||
if realDur <> "" or mockDur <> ""
|
||||
m.assertEqual(mockDur, realDur, "duration drift on '" + id + "'")
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
|
||||
' the omission allowlist can't rot: each entry must still exist in the real file.
|
||||
for each id in omissions
|
||||
m.assertTrue(real.index.DoesExist(id), "stale omission '" + id + "' — it left VideoPlayerDev.xml")
|
||||
end for
|
||||
end function
|
||||
|
||||
end class
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user