import sys
from pathlib import Path

def apply(path, old, new, count=1):
    p = Path(path)
    s = p.read_text(encoding="utf-8")
    if old not in s:
        print(f"FAIL: old not in {path}", file=sys.stderr)
        sys.exit(2)
    s2 = s.replace(old, new, count)
    p.write_text(s2, encoding="utf-8")
    print(f"OK: {path} -> {len(s2)} bytes")

# ===== cli-08-nameplate.e2e.test.ts header =====
np_old_header = (
"// apps/client/test/e2e/cli-08-nameplate.e2e.test.ts\n"
"// [int->REQ-CLI-08]\n"
"//\n"
"// Plan 06.1-03 Task 2 — Wave 0 RED Playwright e2e skeleton for D-45 nametag\n"
"// color-rule assertion (local = cyan c_aqua; remote = white c_white per\n"
"// D6.1-11). GREEN gate after Wave 2 Nameplate.ts rewrite.\n"
"//\n"
"// Pattern: adapts sprite-state.e2e.test.ts lines 48-59 (DOM-mirror count +\n"
"// computed-style assertion via evaluate(el => getComputedStyle(el).color)).\n"
"//\n"
"// Two-context shape mirrors cli-08.e2e.test.ts — A and B log in separately;\n"
"// each sees its own nameplate in `c_aqua` and the OTHER's in `c_white`.\n"
"//\n"
"// RED today:\n"
"//   - Existing Nameplate.ts (Phase 6 D-27a) uses cyan for ALL nameplates\n"
"//     (local + remote); the D6.1-11 color split (local cyan / remote white)\n"
"//     has not landed.\n"
"//   - DOM mirror exists (per Phase 6 D-27a [data-nameplate=<username>]\n"
"//     surface) so the locator wiring is stable; only the computed `color`\n"
"//     style assertion fails today."
)

np_new_header = (
"// apps/client/test/e2e/cli-08-nameplate.e2e.test.ts\n"
"// [int->REQ-CLI-08]\n"
"//\n"
"// Plan 06.1-07 Task 1 — GREEN refinement of the 06.1-03 RED skeleton. Asserts\n"
"// the D6.1-11 BNO color rule (local c_aqua / remote c_white) via the DOM\n"
"// mirror's `data-nameplate-color` attribute (Plan 06.1-07 Rule 2 auto-fix on\n"
"// Nameplate.ts — Phaser canvas Text color is the visual source of truth; the\n"
"// attribute mirrors it 1:1 for Playwright assertability since getComputedStyle\n"
"// on the opacity:0 mirror DIV inherits the body color, not the canvas color).\n"
"//\n"
"// Two-context shape mirrors cli-08.e2e.test.ts — A logs in in context A, B in\n"
"// context B; A's perspective expects A's own nameplate=#00FFFF (c_aqua) and\n"
"// B's nameplate=#FFFFFF (c_white). If remote nameplate fails to attach within\n"
"// 10 s (server roundtrip / accountB seeding miss) we attribute that to the\n"
"// operator-driven HUMAN-UAT Test 4 fallback rather than RED here."
)

apply("apps/client/test/e2e/cli-08-nameplate.e2e.test.ts", np_old_header, np_new_header)
