Fix the file selection in a log compression loop

Review the AI's codeEasy10 min

Your task

Nobody on your team understood a Bash loop that compresses log files, so an AI added comments to it. One comment says the loop skips files over 10 MB, and the code does the opposite. Your team is rewriting the loop's file selection as a tested function. In Bash, for f in *.log loops over the names that match *.log. When nothing matches, Bash passes the literal text *.log instead.

An assistant wrote select_logs_to_compress(file_names, file_sizes, max_bytes). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • file_names: the names the loop sees, in order. This can include the literal *.log.
  • file_sizes: the size of each file in bytes. file_sizes[i] belongs to file_names[i].
  • max_bytes: the size limit.
  • Return the names to compress, in input order.

Rules the tests check:

  • Pair the two lists by position. If one list is longer, ignore its extra items.
  • Only names ending in .log are in scope, and .log alone counts. Case matters: app.LOG is out of scope.
  • Never select the literal name *.log. It is what an unmatched glob leaves behind, not a file.
  • Select a file when its size is strictly greater than max_bytes. A file exactly at the limit stays.
  • A name that appears more than once is checked each time it appears.

Examples

select_logs_to_compress(file_names: list[str], file_sizes: list[int], max_bytes: int) -> list[str]
Example 1
Inputselect_logs_to_compress(["app.log", "debug.log", "notes.txt"], [12000000, 500, 99999999], 10000000)
Output["app.log"]
Example 2
Inputselect_logs_to_compress(["*.log"], [5], 10000000)
Output[]
Example 3
Inputselect_logs_to_compress(["a.log", "b.log"], [10000001, 10000000], 10000000)
Output["a.log"]