Fix the semver bump check for a library release

Review the AI's codeEasy12 min

Your task

Your team asked an AI to write a library's changelog from the diff between two release tags. It filed a renamed export under Features and a changed signature under Fixes. Before you publish to npm, you now derive the version bump from the public API itself. Under semantic versioning (semver), a breaking change needs a major bump, a backward compatible addition a minor bump, and anything else a patch.

An assistant wrote classify_release_bump(old_api, new_api). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • old_api, new_api: the exports of the old and the new release, one entry each, like "query(sql,params)" or "DEFAULT_POOL_SIZE=10".
  • Return "major", "minor" or "patch".

Rules the tests check:

  • Remove every whitespace character from an entry, wherever it is. Skip entries that are then empty.
  • An entry's name is the text before its first (, or the whole entry when it has no (. Names are case sensitive.
  • When a name appears more than once in the same list, only its first entry counts.
  • The bump is "major" when any old name is missing from the new exports, or its entry text changed.
  • Otherwise it is "minor" when the new exports have a name the old ones do not.
  • Otherwise it is "patch".

Examples

classify_release_bump(old_api: list[str], new_api: list[str]) -> str
Example 1
Inputclassify_release_bump(["createClient(url,options)", "query(sql,params)", "close()"], ["createClient(url,options)", "query(sql,params,timeout)", "close()"])
Output"major"
Example 2
Inputclassify_release_bump(["query(sql,params)"], ["query(sql,params)", "stream(sql,params)"])
Output"minor"
Example 3
Inputclassify_release_bump(["query(sql,params)"], ["query(sql,params)"])
Output"patch"