Fix the route list for a Next.js smoke check

Review the AI's codeEasy10 min

Your task

An AI agent made a handful of edits across your Next.js app to add a settings page. Before calling the change done, your team runs a 60 second smoke check: load the home page and every page the diff touched. A helper builds that list of URLs from the changed files.

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

Input and output:

  • changed_files: the paths the diff changed, relative to the repo root, such as app/settings/page.tsx.
  • Return the URLs to load: "/" first, then the other routes, sorted.

Rules the tests check:

  • Only a path that starts with app/ can add a route. Case matters.
  • Only a page file adds a route: the last part of the path must be exactly page.tsx, page.ts, page.jsx or page.js. Layouts, loading files, API route handlers and every other file add nothing.
  • The route is the folders between app/ and the page file, joined with / and starting with /. Skip empty folder names, and skip route groups: folders whose name starts with ( and ends with ), such as (shell). Keep every other folder name as it is, including [slug].
  • If no folders are left, the route is /.
  • Return "/" first, always, even when no page changed. Then every other route once, sorted as plain strings in ascending order.

Examples

smoke_check_routes(changed_files: list[str]) -> list[str]
Example 1
Inputsmoke_check_routes(["app/(shell)/settings/page.tsx", "components/SettingsForm.tsx"])
Output["/", "/settings"]
Example 2
Inputsmoke_check_routes(["lib/format.ts", "app/settings/page.tsx", "app/page.tsx"])
Output["/", "/settings"]