Fix the scope summary for an assistant's diff

Review the AI's codeEasy10 minStripe and Anthropic style

Your task

You asked an AI agent to add input validation to a deploy script. Its diff also reworked the argument parsing, renamed variables and turned on Bash strict mode. Before you open the PR, you want a summary of everything it did beyond the request, so the title cannot under-report what ships.

An assistant wrote summarize_diff_scope(hunk_kinds, behavior_changing, requested_kind). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • hunk_kinds, behavior_changing: two lists of the same length, one entry per hunk (a block of changed lines). hunk_kinds[i] is the kind of change, and behavior_changing[i] says whether that hunk changes what the script does at runtime.
  • requested_kind: the kind of change you asked for.
  • Return the scope summary as a list of strings.

Rules the tests check:

  • A hunk is in scope when its kind equals requested_kind exactly, case included. In-scope hunks add nothing to the summary, even when they change behavior.
  • List each out-of-scope kind once, sorted in ascending order by plain string comparison. The empty string is a kind like any other.
  • If any out-of-scope hunk changes behavior, put "behavior-change" first, before the sorted kinds. Any one such hunk is enough, even when an earlier hunk of the same kind did not change behavior.
  • If every hunk is in scope, return [].

Examples

summarize_diff_scope(hunk_kinds: list[str], behavior_changing: list[bool], requested_kind: str) -> list[str]
Example 1
Inputsummarize_diff_scope(["validation", "validation", "arg-parsing", "rename", "strict-mode"], [True, True, False, False, True], "validation")
Output["behavior-change", "arg-parsing", "rename", "strict-mode"]
Example 2
Inputsummarize_diff_scope(["validation"], [True], "validation")
Output[]
Example 3
Inputsummarize_diff_scope([], [], "validation")
Output[]