Repository navigation
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/audio-api.md`:
- Around line 10-12: Update the docs to state that bookmark reads also require
the active profile headers: mention that the GET
/api/v1/audio/items/{content_id}/bookmarks endpoint enforces
apimw.RequireProfile (same as the write endpoints), so clients must include the
active profile headers used by first-party clients when performing bookmark
reads as well as writes.
In `@internal/api/handlers/audio_test.go`:
- Around line 149-152: After decoding into audioPlaybackResponse 'start' (from
json.Unmarshal of startRec.Body.Bytes()), add assertions that the start playback
actually succeeded before testing expiry: assert the HTTP status of startRec is
success (e.g., 200), assert start.SessionID (or the field name in
audioPlaybackResponse for session id) is non-empty, and fail the test with
t.Fatalf or t.Fatalf-like message if those checks fail so later 404 assertions
can't mask a failed start; update the test around variables startRec and start
to include these explicit checks.
In `@internal/api/handlers/audio.go`:
- Around line 305-307: The parsed seek value from strconv.ParseFloat can be
"Inf" and must be rejected before passing to remux; update the block that sets
seek (the parsed variable in the handler that assigns to seek and later calls
remux) to only accept finite, non-negative values by checking that the parsed
float is not infinite or NaN (use math.IsInf(parsed, 0) and math.IsNaN(parsed)
or equivalent) in addition to parsed >= 0, and only then assign to seek.
- Around line 273-283: The handler currently ignores JSON decode errors and
persistence errors then always deletes the session; change it to validate and
handle failures: check the error returned by
json.NewDecoder(r.Body).Decode(&req) and return a 400 if decoding fails; when
isFiniteNonNegative(req.Position) is true compute duration (falling back to
session.TotalSeconds), call persistProgress and check its error—if
persistProgress returns an error respond with a 500 (and do NOT call
deleteSession) so the caller sees the failure; only call
deleteSession(session.ID) after successful persist or when there was no position
to persist. Reference audioProgressRequest, isFiniteNonNegative,
persistProgress, deleteSession, and session.TotalSeconds in your edits.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e6d9e3e7-1df7-4717-8d6a-be7458aee149
📒 Files selected for processing (4)
docs/audio-api.mdinternal/api/handlers/audio.gointernal/api/handlers/audio_test.gointernal/api/router.go
| All endpoints require normal Silo user authentication. Playback start, sync, | ||
| close, and bookmark writes also require the active profile headers used by the | ||
| first-party clients. |
There was a problem hiding this comment.
Document the profile requirement for bookmark reads, not only writes.
The current router enforces apimw.RequireProfile for GET /api/v1/audio/items/{content_id}/bookmarks too (see internal/api/router.go, Lines 1784-1791). This section only mentions bookmark writes, which can mislead client implementers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/audio-api.md` around lines 10 - 12, Update the docs to state that
bookmark reads also require the active profile headers: mention that the GET
/api/v1/audio/items/{content_id}/bookmarks endpoint enforces
apimw.RequireProfile (same as the write endpoints), so clients must include the
active profile headers used by first-party clients when performing bookmark
reads as well as writes.
| var start audioPlaybackResponse | ||
| if err := json.Unmarshal(startRec.Body.Bytes(), &start); err != nil { | ||
| t.Fatalf("decode start: %v", err) | ||
| } |
There was a problem hiding this comment.
Assert successful playback start before asserting expiry behavior.
Line 149 decodes the response, but the test never checks that start playback succeeded first. If start fails (or session_id is empty), the later 404 can still pass and mask the real failure mode.
Suggested patch
startRec := httptest.NewRecorder()
handler.HandleStartPlayback(startRec, startReq)
+ if startRec.Code != http.StatusOK {
+ t.Fatalf("start status = %d body=%s", startRec.Code, startRec.Body.String())
+ }
var start audioPlaybackResponse
if err := json.Unmarshal(startRec.Body.Bytes(), &start); err != nil {
t.Fatalf("decode start: %v", err)
}
+ if start.SessionID == "" {
+ t.Fatalf("missing session_id in start response")
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| var start audioPlaybackResponse | |
| if err := json.Unmarshal(startRec.Body.Bytes(), &start); err != nil { | |
| t.Fatalf("decode start: %v", err) | |
| } | |
| startRec := httptest.NewRecorder() | |
| handler.HandleStartPlayback(startRec, startReq) | |
| if startRec.Code != http.StatusOK { | |
| t.Fatalf("start status = %d body=%s", startRec.Code, startRec.Body.String()) | |
| } | |
| var start audioPlaybackResponse | |
| if err := json.Unmarshal(startRec.Body.Bytes(), &start); err != nil { | |
| t.Fatalf("decode start: %v", err) | |
| } | |
| if start.SessionID == "" { | |
| t.Fatalf("missing session_id in start response") | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/api/handlers/audio_test.go` around lines 149 - 152, After decoding
into audioPlaybackResponse 'start' (from json.Unmarshal of
startRec.Body.Bytes()), add assertions that the start playback actually
succeeded before testing expiry: assert the HTTP status of startRec is success
(e.g., 200), assert start.SessionID (or the field name in audioPlaybackResponse
for session id) is non-empty, and fail the test with t.Fatalf or t.Fatalf-like
message if those checks fail so later 404 assertions can't mask a failed start;
update the test around variables startRec and start to include these explicit
checks.
| var req audioProgressRequest | ||
| _ = json.NewDecoder(r.Body).Decode(&req) | ||
| if isFiniteNonNegative(req.Position) { | ||
| duration := req.Duration | ||
| if duration <= 0 { | ||
| duration = session.TotalSeconds | ||
| } | ||
| position := clampFloat(req.Position, 0, duration) | ||
| _ = h.persistProgress(r.Context(), session.UserID, session.ProfileID, session.ContentID, position, duration) | ||
| } | ||
| h.deleteSession(session.ID) |
There was a problem hiding this comment.
Don’t silently drop final progress sync failures on close.
Line 274 ignores bad request bodies, and Line 281 ignores persistence errors; then Line 283 deletes the session and returns 204. That can lose final progress with no retry signal.
Suggested fix
import (
"context"
"encoding/json"
"errors"
"fmt"
+ "io"
"math"
"net/http"
@@
func (h *AudioHandler) HandleClosePlayback(w http.ResponseWriter, r *http.Request) {
session, ok := h.sessionForRequest(w, r)
if !ok {
return
}
var req audioProgressRequest
- _ = json.NewDecoder(r.Body).Decode(&req)
+ if err := json.NewDecoder(r.Body).Decode(&req); err != nil && !errors.Is(err, io.EOF) {
+ writeError(w, http.StatusBadRequest, "bad_request", "Invalid request body")
+ return
+ }
if isFiniteNonNegative(req.Position) {
duration := req.Duration
if duration <= 0 {
duration = session.TotalSeconds
}
position := clampFloat(req.Position, 0, duration)
- _ = h.persistProgress(r.Context(), session.UserID, session.ProfileID, session.ContentID, position, duration)
+ if err := h.persistProgress(r.Context(), session.UserID, session.ProfileID, session.ContentID, position, duration); err != nil {
+ writeError(w, http.StatusInternalServerError, "internal_error", "Failed to sync audio progress")
+ return
+ }
}
h.deleteSession(session.ID)
w.WriteHeader(http.StatusNoContent)
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/api/handlers/audio.go` around lines 273 - 283, The handler currently
ignores JSON decode errors and persistence errors then always deletes the
session; change it to validate and handle failures: check the error returned by
json.NewDecoder(r.Body).Decode(&req) and return a 400 if decoding fails; when
isFiniteNonNegative(req.Position) is true compute duration (falling back to
session.TotalSeconds), call persistProgress and check its error—if
persistProgress returns an error respond with a 500 (and do NOT call
deleteSession) so the caller sees the failure; only call
deleteSession(session.ID) after successful persist or when there was no position
to persist. Reference audioProgressRequest, isFiniteNonNegative,
persistProgress, deleteSession, and session.TotalSeconds in your edits.
| if raw := r.URL.Query().Get("seek"); raw != "" { | ||
| if parsed, err := strconv.ParseFloat(raw, 64); err == nil && parsed >= 0 { | ||
| seek = parsed |
There was a problem hiding this comment.
Reject non-finite seek values.
strconv.ParseFloat accepts "Inf", so Line 306 can pass a non-finite seek into remux. Gate it with the same finite/non-negative check you already use elsewhere.
Suggested fix
- if raw := r.URL.Query().Get("seek"); raw != "" {
- if parsed, err := strconv.ParseFloat(raw, 64); err == nil && parsed >= 0 {
+ if raw := r.URL.Query().Get("seek"); raw != "" {
+ if parsed, err := strconv.ParseFloat(raw, 64); err == nil && isFiniteNonNegative(parsed) {
seek = parsed
}
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/api/handlers/audio.go` around lines 305 - 307, The parsed seek value
from strconv.ParseFloat can be "Inf" and must be rejected before passing to
remux; update the block that sets seek (the parsed variable in the handler that
assigns to seek and later calls remux) to only accept finite, non-negative
values by checking that the parsed float is not infinite or NaN (use
math.IsInf(parsed, 0) and math.IsNaN(parsed) or equivalent) in addition to
parsed >= 0, and only then assign to seek.
Summary
Validation
go test ./internal/api/handlers ./internal/apigit diff --checkNotes
go test ./internal/playbackcurrently fails onorigin/mainin the NVENC fake-FFmpeg tests (signal: killedinTestFFmpegSupportsNVENCCachesByFFmpegPathandTestFFmpegSupportsNVENCSmokeProbeUsesSafeFrameDimensions). The detector/test files matchorigin/main, so that failure is separate from this PR.Summary by CodeRabbit
New Features
Documentation