import sys

p = '.spt/launch-battery.py'
s = open(p, encoding='utf-8').read()

anchor = "Exit codes:"
warning = '''!! READ THIS BEFORE TRUSTING ANY VERDICT THIS TOOL PRINTS !!
This tool is ADVISORY, not proof. It was measured failing in BOTH directions on
Windows 2026-09-07 against a 3-level wrapper chain (env -> env -> env -> python,
which is the shape cargo -> cargo-nextest -> test binary actually is):

  FALSE PROVEN  -- a violator at the innermost level was missed entirely. The
                  walk inspected ONE process (the root), found it clean, and
                  reported success. The descendant link did not survive the
                  chain.
  FALSE REFUSED -- the same chain with nothing violating was REFUSED, naming an
                  intermediate whose environment read back as missing the
                  variable while two sibling processes in the same listing
                  carried it.

Root cause as measured: on Windows the spawn chain does not reliably preserve a
parent/child link (one run saw 3 processes, another saw 1 for the same command
shape), and an environment read is a point-in-time sample of an identity that
can change under exec/spawn. Out-of-band inspection of a transient process tree
cannot be a gate.

THE SOUND METHOD IS IN-BAND: have the battery report the environment IT received
-- print the vars at the top of its own output -- and assert on that. An in-band
witness cannot be raced or reparented, and it lands in the .raw you already
keep. An owner-side WEB_SERVE_FOR > 0 is exactly this shape. Gate on that; use
this tool only to produce a .env sidecar for a human to read.

'''
assert s.count(anchor) == 1, s.count(anchor)
s = s.replace(anchor, warning + anchor)

old = '        print(f"LAUNCH PROVEN across {len(inspected)} process(es): {roster}")'
new = (
    '        print(f"NO VIOLATION OBSERVED across {len(inspected)} '
    'process(es): {roster}")\n'
    '        if len(inspected) < 2:\n'
    '            print("  WARNING: only the ROOT process was inspected. If your '
    'command is a\\n"\n'
    '                  "  wrapper chain (cargo, nextest, env, bash -lc) this '
    'proves NOTHING\\n"\n'
    '                  "  about the process under test -- the measured '
    'false-PROVEN case.")'
)
assert s.count(old) == 1, s.count(old)
s = s.replace(old, new)

open(p, 'w', encoding='utf-8', newline='\n').write(s)
print("patched")
