from __future__ import annotations import re import sys from pathlib import Path def main() -> int: source = Path(__file__).resolve().parents[1] / "src" / "app.cpp" text = source.read_text(encoding="utf-8-sig") match = re.search( r"Response Application::handle_get_info\(const Request &request\) \{(?P.*?)\n\}", text, re.S, ) if not match: raise AssertionError("handle_get_info definition not found") body = match.group("body") if 'body["level"] = user->level;' not in body: raise AssertionError('missing `body["level"] = user->level;` in handle_get_info') if 'body["uservip"] = membership_label(user->level);' not in body: raise AssertionError('missing dynamic `uservip` mapping in handle_get_info') print("get_info level contract test passed") return 0 if __name__ == "__main__": sys.exit(main())