"""Hidden interface test for the Record Manager (blank must fail, solved must pass). Runs with pytest's cwd = the assembled submission (/work/submission). Blank (M1 starter) fails because `save`/`load` are unimplemented ("not yet"); the full reference implements the store round-trip. """ import pathlib import subprocess def _root() -> pathlib.Path: return pathlib.Path.cwd() def _run(cmd, timeout=180, **kw): return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, **kw) def test_record_manager_interface(): root = _root() build = _run(["make", "-C", str(root), "-j2"]) assert build.returncode == 0, "BUILD FAILED:\n" + build.stdout + build.stderr recman = root / "build" / "recman" assert recman.exists(), "build/recman missing after make" # add two records, save to a file session1 = ( "add\nAda Lovelace\nada@x\n555-0100\n" "add\nGrace Hopper\ngrace@x\n444-0200\n" "save\n/tmp/rm_hidden.txt\nquit\n" ) r = _run([str(recman)], input=session1) assert "added: Ada Lovelace" in r.stdout, "add failed:\n" + r.stdout assert "added: Grace Hopper" in r.stdout, "add failed:\n" + r.stdout assert "saved" in r.stdout, "save did not persist (blank starter prints 'not yet'):\n" + r.stdout # load back in a fresh session and confirm the round-trip session2 = "load\n/tmp/rm_hidden.txt\nlist\nquit\n" r2 = _run([str(recman)], input=session2) assert "Ada Lovelace" in r2.stdout and "Grace Hopper" in r2.stdout, ( "save/load round-trip failed:\n" + r2.stdout )