import io
def edit(p, pairs):
    s=io.open(p,encoding='utf-8',newline='').read(); nl='\r\n' if '\r\n' in s else '\n'
    for old,new in pairs:
        old=old.replace('\n',nl); new=new.replace('\n',nl)
        assert s.count(old)==1,(p,s.count(old),old[:70]); s=s.replace(old,new)
    io.open(p,'w',encoding='utf-8',newline='').write(s)
edit('docs/GOLDEN-CI.md',[(
'''from the tree and fails if the two disagree. The default is `code=true`. A zero
`before`, a forced push, an unreachable `before`, a non-ancestor, a failed diff
and an empty range each run units and log `CLASSIFY code=true reason=<name>`.''',
'''from the tree and fails if the two disagree. The default is `code=true`. A zero
`before`, a forced push, an unreachable `before`, a graph still too shallow to
decide ancestry, a proven non-ancestor, a failed diff and an empty range each
run units and log `CLASSIFY code=true reason=<name>`.

**Deepen until CONNECTED, not until PRESENT.** The runner reuses its workspace,
so an old `before` object can sit in `.git` while the current depth-2 history
is grafted short of it. `cat-file` then says yes and `is-ancestor` says no on a
true ancestor. Measured on kitsubito, main run 35998753683: `c185326b` present,
`0854bbe8` grafted with no parents, logged as `before-not-ancestor`. The probe
now deepens until `merge-base --is-ancestor` succeeds. A "no" counts as a
fact (`before-not-ancestor`) only on a non-shallow graph; otherwise it is
`before-undecidable`.''')])
edit('traceable-reqs.toml',[(
'before unreachable after a bounded deepen, before not an ancestor,',
'before unreachable after a bounded deepen, a shallow graph that still cannot decide ancestry (before-undecidable; the deepen runs until merge-base --is-ancestor succeeds, never merely until the before object exists), before not an ancestor on a complete graph,')])
print('ok')
