#!/usr/bin/env python3
"""Rebuild ADOPT section: insert missing lines between broken lambda and b2."""
p = '/tmp/p2w_test.py'
src = open(p).read()
broken = 'm.inventory = lambda: [{uuid: adopted-uuid-42,\nb2 = io.StringIO()'
clean = (
'm.inventory = lambda: [{"uuid": "adopted-uuid-42",\n'
' "source_description": "import_identity:" + ("f"*64)}]\n'
'q2 = c.execute("SELECT id FROM graphiti_import_queue WHERE '
"reconciliation_record_id='aa043:obsidian-general:p2wtest'\").fetchone()[0]\n"
'b2 = io.StringIO()'
)
assert broken in src, 'pattern not found'
src = src.replace(broken, clean)
open(p, 'w').write(src)
import py_compile
py_compile.compile(p, doraise=True)
print('ADOPT section rebuilt + SYNTAX_OK')