Skip to content

feat(library): browse library sections and collections on v2 - #383

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/35-library-sections-v2
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/35-library-sections-v2

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

The library landing page and the Collections tab still read two v1 routes:

  • GET /api/v1/library/{id}/sections (inventory row 50): the section shelves on the iOS/macOS library screen and the tvOS library landing page, loaded through StartupContentPrefetcher.fetchLibrarySections.
  • GET /api/v1/library/{id}/collections (row 59): the Collections tab on iOS/macOS (CollectionsView) and tvOS (TVLibraryCollectionsView).

A 1.0 server answers every /api/v1/* call except health with 410 client_upgrade_required, so these pages show an error or an empty tab. The collections read also carried a tolerant decoder for three response shapes that no v2 server sends.

Solution

  • SiloAPI.librarySections calls the existing APIv2Client.librarySections (listLibrarySections) under a captured owner and returns APIv2LibrarySectionsRead. The prefetcher checks that the owner is still current before it caches or returns the sections, the same way Home does. The response keeps the SectionsResponse shape, so the three cache readers are unchanged. ResponseCache is in-memory only, so the cache key does not need a version bump.
  • APIv2Client.libraryCollectionTab now takes a captured auth, requires a profile (X-Profile-Id is required by the contract), runs under withOwnerFence, accepts only 200, and rejects a tab whose library_id differs from the one requested. SiloAPI.libraryCollections also refuses the result if the profile changed while the read was in flight, because the tab contains the viewer's personal collections.
  • A new APIv2LibraryModels.swift maps APIv2LibraryCollectionTab onto the existing LibraryCollectionsResponse:
    • admin groups become .regular, user_collections groups become .userCollections, and any other kind becomes .regular. This matches Android (SectionApi.getLibraryCollections) and main's v1 behavior, and it never treats an unknown kind as personal.
    • Groups keep the server's display order. The ungrouped bucket goes after every group whose sort_order does not exceed its own.
    • An empty poster_url ("empty when none" in the contract) becomes nil. collection_type comes from the curated definition with the same id.
    • With no groups and no ungrouped bucket, the curated list becomes the single flat section, as before.
  • The v1 path literals, LibraryCollectionsWireResponse and its private wire types and tolerant-decode helpers are deleted.

Both reads are GETs, so no mutation failure-outcome table applies.

Validation

  • iOS, tvOS and macOS builds passed.
  • Focused tests passed on iOS and tvOS: LibraryBrowseV2Tests (new), CatalogV2Tests, CollectionsV2Tests, HomeSectionsAPITests, LibraryVisibilityTests and HTTPClientDiagnosticsClassificationTests.
  • LibraryBrowseV2Tests runs through StubURLProtocol and covers the inputs to the tvOS library landing page and collections grid:
    • sections use the v2 path, send X-Profile-Id, and stay bound to the profile they were read for
    • a 404 problem response throws instead of producing an empty library
    • duplicate section IDs are rejected
    • the grouped tab maps kinds, poster, collection type and creator, places the ungrouped bucket by sort order, and builds the flat list
    • a tab without groups renders as one flat section
    • a tab for another library is rejected
    • a tab is not returned after a profile switch mid-read
  • scripts/ci/check-no-api-v1.sh passed. Owner-fence lines (withOwnerFence/sameCredentialIdentity) under iosApp/iosApp went from 60 to 61.
  • The final stack passed the full suites (iOS 1981 tests and tvOS 1792 tests, 0 failures), the macOS build and the v1 path guard. Every branch in the stack, this one included, builds on its own.
  • Not run: the app on a simulator or device. The Collections tab and library landing page have not been checked against a live v2 server.

Risks and follow-ups

  • The v2 tab decode is strict. v1 skipped malformed cards; now one malformed card fails the whole tab. That matches the contract and invariant I2.
  • TVLibraryCollectionsView.loadCollections still turns any error into an empty tab ("No collections yet"). This is existing behavior and this PR does not change it. A later change should show an error state instead.
  • HTTPClientDiagnosticsClassificationTests still contains the /api/v1/library/{id}/sections template as a classification fixture that sends no request. Z1 owns the final guard allowlist.
  • Collection item paging behind this screen goes through the catalog funnel (W5-I). Personal collection management is W5-O.

AI disclosure

Code and description written by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.


Part 35 of 50 in the Apple API v2 stack. Base: apiv2-stack/34-catalog-cursor-paging. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 072ca088-4626-4c1d-9ad3-a3ebf86163cd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T13:25:47.771699Z fb0a56c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: 278db7f5 (apiv2-stack/35-library-sections-v2).

Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration.

Verified findings: none.

Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no /api/v1 request from the new builds except the retained health probe.

Remaining: no open verified findings. Merge in stack order.

Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack.

Review by Claude Opus 5.5 (claude-opus-5-5) agents in Claude Code (T3 Code).

@Quick104
Quick104 force-pushed the apiv2-stack/34-catalog-cursor-paging branch from 141bc83 to ff7d1da Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/35-library-sections-v2 branch from 278db7f to fb0a56c Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/34-catalog-cursor-paging branch from ff7d1da to d449f74 Compare September 23, 2026 13:42
The library landing page and the Collections tab still read
/api/v1/library/{id}/sections and /api/v1/library/{id}/collections. A 1.0
server answers both with 410, so every library page showed an error or an
empty tab. The v1 collections read also carried a tolerant three-shape
decoder that no v2 server sends.

SiloAPI.librarySections now calls the existing v2 listLibrarySections
client and returns the read with the owner it was fetched for. The startup
prefetcher checks that owner before it caches or returns the sections, as
Home already does. SiloAPI.libraryCollections calls getLibraryCollections
under a captured owner, rejects a tab for another library, refuses the
result after a profile switch, and maps the tab onto the existing section
model: admin groups become regular, user_collections become personal,
unknown kinds resolve as regular (as on Android), the ungrouped bucket goes
after the groups it sorts behind, and empty poster URLs become nil.

The v1 wire decoder (LibraryCollectionsWireResponse and its private wire
types) is deleted.

Stack-PR: W5-H
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Base automatically changed from apiv2-stack/34-catalog-cursor-paging to main September 23, 2026 13:42
Handle the ungrouped-free, group-free tab first with an early return and
drop a redundant bounds clamp on the ungrouped insert position.

Stack-PR: W5-H
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/35-library-sections-v2 branch from fb0a56c to 26bbdbb Compare September 23, 2026 13:42
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Quick104
Quick104 merged commit 6e666bf into main Sep 23, 2026
3 checks passed
@Quick104
Quick104 deleted the apiv2-stack/35-library-sections-v2 branch September 23, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant