import os

target = r"C:\Users\intel\AppData\Local\OptimusRuntime\Labs\AR74\12_ar88_authority_operational_closure\candidate_workspace\tests\test_teitan_self_repair_phase5a_rollback.py"

with open(target, "r", encoding="utf-8") as f:
    content = f.read()

old_manual = """    artifact = RollbackArtifact(
        promotion_id="test_manual_promo",
        target_path=str(target),
        original_hash=orig_hash,
        candidate_hash="MUTATED_HASH",
        original_bytes_snapshot=orig_bytes,
        rollback_ready=True,
    )

    # Mutate file
    target.write_text("CORRUPTED VERSION\\n", encoding="utf-8")
    assert hashlib.sha256(target.read_bytes()).hexdigest().upper() != orig_hash

    # Execute manual rollback
    ok = executor.rollback(artifact)"""

new_manual = """    artifact = RollbackArtifact(
        promotion_id="test_manual_promo",
        target_path=str(target),
        original_hash=orig_hash,
        candidate_hash="MUTATED_HASH",
        original_bytes_snapshot=orig_bytes,
        rollback_ready=True,
    )
    # Register artifact in executor registry as required by AR-88
    executor.rollback_artifacts["test_manual_promo"] = artifact

    # Mutate file
    target.write_text("CORRUPTED VERSION\\n", encoding="utf-8")
    assert hashlib.sha256(target.read_bytes()).hexdigest().upper() != orig_hash

    # Execute manual rollback
    ok = executor.rollback(artifact)"""

if old_manual in content:
    content = content.replace(old_manual, new_manual)
    with open(target, "w", encoding="utf-8") as f:
        f.write(content)
    print("SUCCESS: test_teitan_self_repair_phase5a_rollback.py updated with artifact registration!")
else:
    print("ERROR: old_manual block not found in test_teitan_self_repair_phase5a_rollback.py")

