Skip to content

ci: block new /api/v1 paths in app sources - #351

Merged
Quick104 merged 2 commits into
mainfrom
apiv2-stack/03-guard-api-v1-paths
Sep 23, 2026
Merged

Quick104 merged 2 commits into
mainfrom
apiv2-stack/03-guard-api-v1-paths

Conversation

@Quick104

Copy link
Copy Markdown
Contributor

Problem

The Apple clients are moving from /api/v1 to /api/v2 across this stack. Nothing in CI stops a change from adding /api/v1 requests while the migration is under way, so v1 usage can grow unnoticed.

Solution

CI now fails when a file's /api/v1 match count rises above its recorded ceiling, or when a file with no ceiling starts to match.

  • scripts/ci/check-no-api-v1.sh scans iosApp/iosApp, iosApp/TopShelf, iosApp/NotificationService, iosApp/DownloadsActivity and iosApp/Tests for three patterns: api/v1, "api", "v1" component arrays, and appendingPathComponent("v1"). It counts every occurrence, including comments.
  • scripts/ci/api-v1-allowlist.txt records a ceiling per file, generated from the current tree (61 files, 524 matches). The check fails when a file's count rises above its ceiling or when an unlisted file matches. It prints the offending lines and the command to regenerate the allowlist: scripts/ci/check-no-api-v1.sh --print-counts > scripts/ci/api-v1-allowlist.txt. An empty allowlist, or one without its generated header, fails with exit code 2 instead of passing, so a truncated file (for example from a mistyped regeneration command) can't turn the guard off.
  • Counts that drop still pass, so later migration PRs don't need to edit the allowlist. --exact also fails on dropped counts; the final cleanup PR sets the permanent allowlist (ConnectionMonitor health probe, HostedDiagnosticsAPI.swift, DiagnosticsPathTemplateTests vectors) and switches CI to exact matching.
  • .github/workflows/ci-scripts.yml runs the guard's test (check-no-api-v1.test.sh) and the guard. The workflow also triggers on changes under the five scanned directories.

The guard uses only bash, grep, awk and sed. No Swift changes.

Validation

  • bash scripts/ci/check-no-api-v1.test.sh passed on macOS (bash 3.2, BSD grep/awk) and in a Debian bookworm container (GNU grep 3.8, mawk). It covers occurrence counting, skipping unscanned directories, a raised count, an unlisted file, an empty and a headerless allowlist, a lowered count with and without --exact, and the regeneration hint.
  • scripts/ci/check-no-api-v1.sh and --exact pass on this tree. In the Debian container, --print-counts reproduced the committed allowlist byte for byte.
  • Removing one entry from a copy of the allowlist made the check fail, name the file and list its two matching lines. A 0-byte allowlist exits 2 with an error on this tree (61 files, 524 matches); a header-only allowlist fails and reports every matching file as unlisted.
  • iOS, tvOS and macOS builds passed through the stack build helper. I didn't run the XCTest suites because this PR changes no Swift code.
  • Final stack: with all 50 PRs applied, the full iOS suite (1981 tests) and tvOS suite (1792 tests) passed with 0 failures, the macOS build passed, and the v1 path guard passed. Every branch in the stack, this one included, builds on its own.

Risks and follow-ups

  • The patterns are exactly the three listed above. The guard misses other ways to build a v1 path, such as string concatenation of "v1" or the external diagnostics host's v1/... paths in HostedDiagnosticsAPI.swift. The diagnostics host paths are deliberate.
  • Until the final cleanup PR lowers the ceilings and turns on --exact, a file whose count has dropped can take new v1 paths up to its old ceiling. Comments count too, so replacing a v1 comment with a v1 call keeps the count level and passes. Review still has to catch those cases during the stack.
  • The allowlist is a snapshot of this branch's tree (main at 81f27dc0 plus F0 and F1, which change no v1 counts). A branch that adds v1 matches before this merges will fail the guard until it regenerates the allowlist.
  • The workflow now runs on every PR that touches app or test sources. It needs only a checkout and a few seconds of shell.
  • The GitHub Actions run itself is unverified until CI runs on the PR.

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 3 of 50 in the Apple API v2 stack. Base: apiv2-stack/02-share-apiv2-client. Merge in order from the bottom of the stack. The plan and full index are in PR 01.

🤖 Generated with Claude Code

@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.

@coderabbitai

coderabbitai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 12 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: c6eaeaff-4b76-4d20-8070-1e0b9f301379

📥 Commits

Reviewing files that changed from the base of the PR and between b3b90a1 and ea49de8.

📒 Files selected for processing (4)
  • .github/workflows/ci-scripts.yml
  • scripts/ci/api-v1-allowlist.txt
  • scripts/ci/check-no-api-v1.sh
  • scripts/ci/check-no-api-v1.test.sh

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.

@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:32:49.711439Z ea49de8 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e8e3cfbb2

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

allowlist="${allowlist:-${root}/scripts/ci/api-v1-allowlist.txt}"

scan_dirs=(iosApp/iosApp iosApp/TopShelf iosApp/NotificationService iosApp/DownloadsActivity iosApp/Tests)
pattern='api/v1|"api", *"v1"|appendingPathComponent\("v1"\)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Detect multiline v1 path construction

When a request uses normal multiline Swift formatting—such as placing "api" and "v1" on adjacent array lines or placing "v1" on the line after .appendingPathComponent(—this line-oriented pattern cannot match it. I tested both forms in a new Swift file under a scanned directory; --print-counts reported nothing and the check exited successfully, so a newly added v1 request can pass CI. Normalize or tokenize the source before matching across whitespace, and add multiline cases to the guard test.

Useful? React with 👍 / 👎.

@Quick104

Copy link
Copy Markdown
Contributor Author

Code review summary

Reviewed head: 4e8e3cfb (apiv2-stack/03-guard-api-v1-paths).

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, all fixed on this branch:

  • minor: Empty allowlist makes the guard pass everything
  • minor: PR body says the guard blocks any added v1 path; the ceiling allows re-adds up to the old count

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/03-guard-api-v1-paths branch from 4e8e3cf to ae7d6e1 Compare September 23, 2026 13:19
@Quick104
Quick104 force-pushed the apiv2-stack/02-share-apiv2-client branch from 21dff02 to 93cff73 Compare September 23, 2026 13:28
Base automatically changed from apiv2-stack/02-share-apiv2-client to main September 23, 2026 13:28
Quick104 and others added 2 commits September 23, 2026 09:28
The Apple clients are moving to /api/v2, but nothing stops a change from
adding a new /api/v1 request while the migration is under way.

Add scripts/ci/check-no-api-v1.sh. It scans the app, extension and test
sources for `api/v1`, `"api", "v1"` path arrays and
`appendingPathComponent("v1")`, and compares each file's count with a
ceiling in scripts/ci/api-v1-allowlist.txt, generated from the current
tree. The check fails when a count rises or an unlisted file matches, and
prints the offending lines plus the command that regenerates the
allowlist. --exact also fails on counts that dropped, for the final
cleanup. The CI scripts workflow now runs the guard and its test, and
triggers on changes to the scanned sources.

Stack-PR: F2

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An empty allowlist made the guard pass every tree. awk's FNR == NR test
never saw the allowlist as a separate file, so it read the match counts as
the allowlist and compared nothing. Truncating the file with a mistyped
regeneration command was enough to turn the guard off.

The guard now exits 2 when the allowlist is empty or lacks its generated
header, and the awk program identifies the allowlist by FILENAME instead of
FNR == NR. The test covers a 0-byte and a headerless allowlist.

Stack-PR: F2

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 force-pushed the apiv2-stack/03-guard-api-v1-paths branch from ae7d6e1 to ea49de8 Compare September 23, 2026 13:29
@Quick104
Quick104 merged commit 9fade54 into main Sep 23, 2026
3 checks passed
@Quick104
Quick104 deleted the apiv2-stack/03-guard-api-v1-paths branch September 23, 2026 13:29
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