Fix the auth site sweep before a middleware refactor

Review the AI's codeEasy10 minAnthropic style

Your task

You are moving authentication into middleware in a large Python monolith. An AI agent mapped the code and claimed auth happens only in the @require_login decorator. Before you trust that, you sweep the source for every auth primitive and list the files the map did not mention.

An assistant wrote find_unmapped_auth_sites(source_lines, claimed_sites). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • source_lines: lines of source, each "path|code".
  • claimed_sites: the file paths the agent's map already lists.
  • Return the paths that touch auth but are not claimed.

Rules the tests check:

  • Split each line at its first |. Skip a line with no | or with an empty path.
  • A line is a comment when its code, after leading spaces and tabs (any character with a code of 32 or less), starts with #. Skip comment lines.
  • Any other line touches auth when its code contains one of @require_login, request.user, permission_classes, is_authenticated or check_auth(, anywhere, case included. A marker after a # later in the line still counts: only a line that starts as a comment is skipped.
  • Leave out paths that appear in claimed_sites, compared exactly.
  • Return each remaining path once, sorted in ascending order.

Examples

find_unmapped_auth_sites(source_lines: list[str], claimed_sites: list[str]) -> list[str]
Example 1
Inputfind_unmapped_auth_sites(["views/orders.py|@require_login", "views/orders.py|def list_orders(request):", "core/base_viewset.py|if not request.user.is_authenticated:", "middleware/legacy.py|check_auth(request)"], ["views/orders.py"])
Output["core/base_viewset.py", "middleware/legacy.py"]
Example 2
Inputfind_unmapped_auth_sites(["views/home.py|return render(request)"], [])
Output[]