Fix the round-trip check for a config serializer

Review the AI's codeEasy15 min

Your task

An AI wrote a property test for your config serializer that only checked that deserializing returns something, so it passed on every input. The team wants the real round-trip check: serialize, deserialize, then compare. The current format joins key=value pairs with ; and escapes nothing.

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

Input and output:

  • entries: the config's entries, in order. Each is usually "key=value", but an entry can lack = or be empty.
  • Return the keys the round trip gets wrong, as a sorted list of strings.

Rules the tests check:

  • Build the config. For each entry, the key is the text before the first = and the value is everything after it. With no =, the whole entry is the key and the value is "". Keys can be empty and can contain ;. Values can contain ; and =.
  • A repeated key keeps its first position and takes its last value.
  • Serialize: write each key as key=value, in config order, and join them with ;. Nothing is escaped.
  • Deserialize: an empty blob gives an empty config. Otherwise split the blob on every ; and read each part the same way as an entry, again with the last value winning.
  • Report a key in any of these cases:
    • it is in the config but missing after the round trip
    • it is in both, with different values
    • it appears after the round trip but was not in the config
  • Return each reported key once, in ascending order by plain string comparison. Case matters, and the empty key sorts first. No mismatches returns an empty list.

Examples

roundtrip_mismatches(entries: list[str]) -> list[str]
Example 1
Inputroundtrip_mismatches(["host=localhost", "port=8080"])
Output[]
Example 2
Inputroundtrip_mismatches(["motd=hello;world"])
Output["motd", "world"]
Example 3
Inputroundtrip_mismatches([])
Output[]