Fix the audit for a v3 migration guide

Review the AI's codeMedium15 minStripe style

Your task

You are shipping v3 of a database access library, and an AI drafted the upgrade guide for v2 users. It reads as thorough. Drafts like this tend to miss the failure paths: a replacement for each removed method, an index build that locks a live table, the order of migrate and deploy, and a way back. Your team runs an audit on the guide before it ships.

An assistant wrote audit_migration_guide(removed_symbols, guide_lines). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • removed_symbols: the public names v3 removes, from the API diff.
  • guide_lines: the guide, one line per entry, in order.
  • Return the gap codes found, sorted by plain character order. An empty list means no gaps.

Rules the tests check. Match against each guide line lowercased.

  • For each removed symbol, trim it and skip it if it is empty. Report "missing-replacement:<symbol>", with the trimmed symbol, unless some line contains replace <symbol> with (one space each side, symbol lowercased). Mentioning the symbol any other way does not count.
  • Symbols that differ only in case are one symbol. Report it once, spelled as it first appears.
  • Report "unsafe-index" once when any single line contains create index but does not contain concurrently. A plain CREATE INDEX blocks writes to the table while it builds.
  • Report "missing-rollback" when no line contains rollback.
  • Report "bad-ordering" when the first line containing deploy comes before the first line containing migrat (as in migrate or migration). Both must exist, and one line that has both is fine. New code deployed on the old schema fails until the migration runs.

Examples

audit_migration_guide(removed_symbols: list[str], guide_lines: list[str]) -> list[str]
Example 1
Inputaudit_migration_guide(["fetchAll", "PoolConfig"], ["Step 1: run the schema migration to add the v3 columns.", "Step 2: replace fetchAll with findMany in every call site.", "Step 3: replace PoolConfig with poolOptions in your client setup.", "Step 4: create index CONCURRENTLY idx_orders_customer on orders (customer_id).", "Step 5: deploy the v3 application.", "Rollback: pin back to v2 and drop the new index."])
Output[]
Example 2
Inputaudit_migration_guide(["fetchAll", "PoolConfig"], ["Step 1: deploy the v3 package from npm.", "Step 2: replace fetchAll with findMany.", "Step 3: create index idx_orders_customer on orders (customer_id).", "Step 4: run the migration for the new columns."])
Output["bad-ordering", "missing-replacement:PoolConfig", "missing-rollback", "unsafe-index"]
Example 3
Inputaudit_migration_guide(["fetchAll"], ["fetchAll is removed in v3.", "Rollback: reinstall v2."])
Output["missing-replacement:fetchAll"]