refactor: concentrate playback transition ownership
This commit is contained in:
@@ -75,7 +75,80 @@ struct AutomaticQualityPlaybackChecks {
|
||||
qualityClock: { clock.now })
|
||||
require(manual.automaticYouTubeQuality, "manual session override does not replace startup configuration")
|
||||
manual.shutdown()
|
||||
// Control only the external extractor; media decoding and all model transitions stay real.
|
||||
guard let controlPath = ProcessInfo.processInfo.environment["TEREBI_QUALITY_CONTROL"] else {
|
||||
require(false, "isolated extraction controls are available")
|
||||
return
|
||||
}
|
||||
let control = URL(fileURLWithPath: controlPath, isDirectory: true)
|
||||
func mark(_ name: String) {
|
||||
require(FileManager.default.createFile(atPath: control.appendingPathComponent(name).path,
|
||||
contents: Data()), "publish extraction control " + name)
|
||||
}
|
||||
func marked(_ name: String) -> Bool {
|
||||
FileManager.default.fileExists(atPath: control.appendingPathComponent(name).path)
|
||||
}
|
||||
model.setYouTubeQuality(720)
|
||||
until(model, "manual selection opens real healthy 720p media") {
|
||||
model.youtubeHeight == 720 && model.canChangeYouTubeQuality && model.state.status == PLAYER_PLAYING &&
|
||||
!model.state.seek_pending && (model.bufferedRange.map { $0.upperBound - model.state.position >= 20 } ?? false)
|
||||
}
|
||||
let selectedTitle = model.fileName
|
||||
let selectedQuality = model.youtubeQuality
|
||||
mark("gate-1080")
|
||||
clock.now = 3000
|
||||
model.setAutomaticYouTubeQuality(true)
|
||||
polled(model)
|
||||
let healthyPosition = model.state.position
|
||||
until(model, "healthy native playback continues before the controlled upshift") {
|
||||
model.state.position > healthyPosition + 0.02
|
||||
}
|
||||
clock.now = 3060
|
||||
until(model, "automatic upshift reaches the selected extraction gate") {
|
||||
marked("entered-1080") && model.resolvingYouTube
|
||||
}
|
||||
require(model.setPlayback(playing: false), "pause is accepted during automatic extraction")
|
||||
mark("release-1080")
|
||||
until(model, "cancelled extraction finishes and native pause is acknowledged") {
|
||||
marked("finished-1080") && !model.resolvingYouTube && model.canTogglePlayback &&
|
||||
model.state.status == PLAYER_PAUSED && !model.state.seek_pending
|
||||
}
|
||||
let cancelledPosition = model.state.position
|
||||
for _ in 0..<3 {
|
||||
polled(model)
|
||||
require(model.state.status == PLAYER_PAUSED && abs(model.state.position - cancelledPosition) < 0.05 &&
|
||||
model.state.has_video && model.state.has_audio &&
|
||||
model.youtubeHeight == 720 && model.youtubeQuality == selectedQuality &&
|
||||
model.fileName == selectedTitle && model.errorText == nil,
|
||||
"late extraction cannot reopen different quality or resume deliberately paused media")
|
||||
}
|
||||
try! FileManager.default.removeItem(at: control.appendingPathComponent("gate-1080"))
|
||||
require(model.seekRelative(37 - model.state.position), "original paused media accepts a nonzero seek")
|
||||
until(model, "native original media acknowledges the seek") {
|
||||
model.canChangeYouTubeQuality && model.state.status == PLAYER_PAUSED &&
|
||||
!model.state.seek_pending && abs(model.state.position - 37) < 0.05
|
||||
}
|
||||
mark("fail-1080")
|
||||
for playing in [false, true] {
|
||||
require(model.setPlayback(playing: playing), "original playback state is selectable before quality failure")
|
||||
until(model, "original native playback reaches the requested state before quality failure") {
|
||||
model.canChangeYouTubeQuality && model.state.status == (playing ? PLAYER_PLAYING : PLAYER_PAUSED) &&
|
||||
(!playing || model.state.position > 37.1)
|
||||
}
|
||||
let originalPosition = model.state.position
|
||||
model.setYouTubeQuality(1080)
|
||||
until(model, "failed manual quality switch restores the original native playback state") {
|
||||
model.errorText != nil && !model.resolvingYouTube && model.canTogglePlayback &&
|
||||
model.state.status == (playing ? PLAYER_PLAYING : PLAYER_PAUSED) &&
|
||||
(!playing || model.state.position > originalPosition + 0.1)
|
||||
}
|
||||
require(model.state.has_video && model.state.has_audio && model.youtubeHeight == 720 &&
|
||||
model.youtubeQuality == selectedQuality && model.fileName == selectedTitle &&
|
||||
model.state.position >= originalPosition - 0.05 &&
|
||||
model.state.position < originalPosition + (playing ? 2 : 0.05),
|
||||
"failed manual quality switch retains original selected media and playback progress")
|
||||
}
|
||||
model.closeFile()
|
||||
print("PASS native adaptive playback: default-off/stalled downshift/healthy upshift/progress preservation/current+default manual override/session-only settings")
|
||||
print("PASS native adaptive playback: default-off/stalled downshift/healthy upshift/progress preservation/current+default manual override/session-only settings/cancelled extraction pause/failed manual quality playing+paused preservation")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user