Fix the reviewer filter for snapshot test diffs
Your task
An agent added about 40 Jest snapshot tests before a refactor. When they all fail at once, people run jest -u and accept the whole diff unread, so a removed accessibility attribute slips through. Your team wants a filter that lists only the attribute changes a person must read.
An assistant wrote review_snapshot_diff(before, after). It is in the editor. It has a bug. Find it and fix it.
Input and output:
before: one component's attributes in the old snapshot, as strings like"aria-disabled=true".after: the same component's attributes in the new snapshot, in the same format.- Return the keys a reviewer must read, as a list of strings.
Rules the tests check:
- Split each entry at its first
=. The key is the text before it, the value is all the text after it. The value can be empty. - Skip an entry with no
=or with an empty key. - When a key appears more than once in one list, the last entry wins.
- Cosmetic keys are never reported. They are exactly
"class","style"and any key that starts with"data-". - Report every other key whose value changed, that is in
beforebut not inafter, or that is inafterbut not inbefore. - A key that appears or disappears counts as a change even when its value is empty.
- Keys and values compare exactly. Case and spaces matter.
- Return each reported key once, sorted by plain string order, so uppercase letters come before lowercase ones. Nothing to report returns an empty list.
Examples
review_snapshot_diff(before: list[str], after: list[str]) -> list[str]Example 1
Input
review_snapshot_diff(["class=btn primary", "aria-disabled=false", "text=Submit"], ["class=primary btn", "aria-disabled=false", "text=Submit"])Output
[]Example 2
Input
review_snapshot_diff(["aria-disabled=true", "text=Save"], ["text=Save"])Output
["aria-disabled"]Example 3
Input
review_snapshot_diff(["role=button", "text=Save"], ["role=button", "text=Saved"])Output
["text"]