Fix the risk ranking for a large PR review

Review the AI's codeEasy15 minAnthropic and OpenAI style

Your task

An agent opened a 1,400-line PR that refactors auth, adds a rate limiter and updates 40 call sites. You have 45 minutes, so you read in risk order, not file order. Your team wants a helper that sorts the changed files into that order.

An assistant wrote rank_review_targets(changes). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • changes: one string per changed file, "path|added|removed", where added and removed are line counts.
  • Return the paths in the order to read them.

Rules the tests check:

  • Skip an entry unless it splits on | into exactly 3 parts, the path is not empty, and both counts are one or more digits 0 to 9. No signs, no spaces.
  • Each path gets an area weight. Check these in order and use the first match. Matches are case sensitive substring checks.
    1. Contains .test., tests/ or _test.: weight 0. Tests are read last, so src/auth/token.test.ts is a test.
    2. Contains auth, session, token or permission: weight 10.
    3. Contains migration: weight 8.
    4. Contains middleware, ratelimit or rate-limit: weight 6.
    5. Anything else: weight 1.
  • The size of a change is added plus removed, capped at 999.
  • Sort by weight, highest first. Within the same weight, by size, largest first. Then by path in plain string order, A to Z.
  • A path listed twice stays in the result twice.
  • Return only the paths. No valid entries returns an empty list.

Examples

rank_review_targets(changes: list[str]) -> list[str]
Example 1
Inputrank_review_targets(["src/auth/middleware.ts|120|80", "src/routes/users.ts|600|300", "src/auth/session.ts|10|2"])
Output["src/auth/middleware.ts", "src/auth/session.ts", "src/routes/users.ts"]
Example 2
Inputrank_review_targets(["db/migrations/001_add_limits.sql|40|0", "src/lib/ratelimit.ts|150|20", "src/ui/button.tsx|5|5"])
Output["db/migrations/001_add_limits.sql", "src/lib/ratelimit.ts", "src/ui/button.tsx"]
Example 3
Inputrank_review_targets(["src/auth/token.ts|30|10", "src/auth/token.test.ts|400|0"])
Output["src/auth/token.ts", "src/auth/token.test.ts"]