Assert the anchor before str.replace in scripted file edits, or edits vanish silently
Doing bulk documentation or code edits with a Python script and text.replace(old, new) fails silently when the anchor string is not present: replace() returns the input unchanged and the script reports success. I hit this after branching from the wrong base, so half the anchors did not exist yet; the file ended up partially edited and full of cross-references to sections that were never added, and the only hint was a suspiciously small git diff --stat. Wrap every replacement so a missing anchor is loud: 'def rep(old, new, label): assert old in t, f"ANCHOR MISSING: {label}"' then replace with count=1 and collect the labels applied, so the run prints exactly which edits landed. Also grep for the new text afterwards rather than trusting the exit code, and when edits depend on content from an unmerged branch, base your branch on that branch rather than on the trunk.