Skip to content

Commit b282ee8

Browse files
Quick104claude
andcommitted
test(playback): cover local-cap fallback to a compliant version
Run the bitrate-cap alternate-version start test for a remote and a local client. Each case sets the other location's cap too low for any stream, so selecting the wrong cap refuses playback. Describe the refusal as the stream's bitrate limit rather than the remote one. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 0b84558 commit b282ee8

3 files changed

Lines changed: 36 additions & 18 deletions

File tree

‎internal/api/handlers/playback_v3.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5702,7 +5702,7 @@ const (
57025702
// out silently retired that fallback and refused playback outright.
57035703
//
57045704
// bitrate_policy_unavailable belongs here for the same reason: it replaces the
5705-
// 4K and HDR refusals of a version that exceeds the remote bitrate limit, and
5705+
// 4K and HDR refusals of a version that exceeds the stream's bitrate limit, and
57065706
// a lower-bitrate version may fit that limit.
57075707
func terminalAllowsAlternateFileV3(terminal *playback.TerminalV3) bool {
57085708
if terminal == nil {

‎internal/api/handlers/playback_v3_bitrate_policy_test.go‎

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package handlers
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net/http"
67
"net/http/httptest"
78
"strings"
@@ -13,9 +14,10 @@ import (
1314
"github.com/Silo-Server/silo-server/internal/playback"
1415
)
1516

16-
// A remote bitrate cap that the requested 4K version cannot meet must still
17-
// let the start fall back to a version that fits the cap.
18-
func TestHandleStartPlaybackV3RemoteBitrateCapTriesCompliantAlternate(t *testing.T) {
17+
// A bitrate cap that the requested 4K version cannot meet must still let the
18+
// start fall back to a version that fits the cap. The request's location
19+
// selects the local or remote cap.
20+
func TestHandleStartPlaybackV3BitrateCapTriesCompliantAlternate(t *testing.T) {
1921
source := v3HandlerFixtureFile(t)
2022
source.Resolution = "2160p"
2123
source.Bitrate = 32_000
@@ -40,19 +42,35 @@ func TestHandleStartPlaybackV3RemoteBitrateCapTriesCompliantAlternate(t *testing
4042
handler.PlaybackConfig = playbackTestConfig("", "")
4143
handler.ItemAccess = allowAllPlaybackItemAccess{}
4244

43-
start := v3HandlerStartRequest()
44-
start.QualityPreference = "auto"
45-
start.ClientPlaybackContext.Deliveries[playback.DeliveryClassHLSV3] = playback.DeliveryCapabilityV3{Enabled: true, SupportedOnDevice: true}
46-
ctx := access.SetScope(newAuthorizedPlaybackContext(), access.Scope{UserID: 1, ProfileID: "profile-1", MaxRemoteStreamBitrateKbps: 10_000})
47-
ctx = clientip.SetContext(ctx, "203.0.113.7")
48-
rr := httptest.NewRecorder()
49-
handler.HandleStartPlayback(rr, httptest.NewRequest(http.MethodPost, "/api/v1/playback/start", strings.NewReader(marshalV3StartRequest(t, start))).WithContext(ctx))
50-
51-
var response playback.DecisionResponseV3
52-
if rr.Code != http.StatusCreated || json.Unmarshal(rr.Body.Bytes(), &response) != nil {
53-
t.Fatalf("status=%d body=%s", rr.Code, rr.Body.String())
45+
// The other location's cap is too low for any stream, so applying it
46+
// instead would refuse playback.
47+
tests := []struct {
48+
name string
49+
clientIP string
50+
scope access.Scope
51+
}{
52+
{name: "remote", clientIP: "203.0.113.7", scope: access.Scope{MaxRemoteStreamBitrateKbps: 10_000, MaxLocalStreamBitrateKbps: 100}},
53+
{name: "local", clientIP: "192.168.1.20", scope: access.Scope{MaxLocalStreamBitrateKbps: 10_000, MaxRemoteStreamBitrateKbps: 100}},
5454
}
55-
if response.PlaybackPlan == nil || response.PlaybackPlan.EffectiveMediaFileID != alternate.ID {
56-
t.Fatalf("expected the compliant 1080p alternate, got terminal=%#v plan=%#v", response.Terminal, response.PlaybackPlan)
55+
for i, test := range tests {
56+
t.Run(test.name, func(t *testing.T) {
57+
start := v3HandlerStartRequest()
58+
start.PlaybackAttemptID = fmt.Sprintf("bitrate-cap-attempt-%d", i)
59+
start.QualityPreference = "auto"
60+
start.ClientPlaybackContext.Deliveries[playback.DeliveryClassHLSV3] = playback.DeliveryCapabilityV3{Enabled: true, SupportedOnDevice: true}
61+
scope := test.scope
62+
scope.UserID, scope.ProfileID = 1, "profile-1"
63+
ctx := clientip.SetContext(access.SetScope(newAuthorizedPlaybackContext(), scope), test.clientIP)
64+
rr := httptest.NewRecorder()
65+
handler.HandleStartPlayback(rr, httptest.NewRequest(http.MethodPost, "/api/v1/playback/start", strings.NewReader(marshalV3StartRequest(t, start))).WithContext(ctx))
66+
67+
var response playback.DecisionResponseV3
68+
if rr.Code != http.StatusCreated || json.Unmarshal(rr.Body.Bytes(), &response) != nil {
69+
t.Fatalf("status=%d body=%s", rr.Code, rr.Body.String())
70+
}
71+
if response.PlaybackPlan == nil || response.PlaybackPlan.EffectiveMediaFileID != alternate.ID {
72+
t.Fatalf("expected the compliant 1080p alternate, got terminal=%#v plan=%#v", response.Terminal, response.PlaybackPlan)
73+
}
74+
})
5775
}
5876
}

‎internal/playback/protocol_v3.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ const (
258258
)
259259

260260
// TerminalBitratePolicyUnavailableV3 reports that no route fits the
261-
// administrator's remote per-stream bitrate limit for this version.
261+
// administrator's local or remote per-stream bitrate limit for this version.
262262
const TerminalBitratePolicyUnavailableV3 = "bitrate_policy_unavailable"
263263

264264
type SubtitleModeV3 string

0 commit comments

Comments
 (0)