"""Integration tests for perf.* commands — require a live browser.""" import time _VALID_PROFILES = {"auto", "normal", "gentle", "ultra"} def test_perf_status_returns_profile_field(browser): """perf.status returns a dict with a performanceProfile field.""" result = browser("perf.status") assert isinstance(result, dict) assert "performanceProfile" in result assert result["performanceProfile"] in _VALID_PROFILES def test_perf_status_has_throttle(browser): """perf.status includes a throttle dict with batchSize and pauseMs.""" result = browser("perf.status") throttle = result.get("throttle") assert isinstance(throttle, dict) assert "batchSize" in throttle assert "pauseMs" in throttle assert isinstance(throttle["batchSize"], int) assert isinstance(throttle["pauseMs"], int) assert throttle["batchSize"] > 0 assert throttle["pauseMs"] >= 0 def test_perf_status_has_audible_field(browser): """perf.status contains an audible boolean.""" result = browser("perf.status") assert "audible" in result assert isinstance(result["audible"], bool) def test_perf_status_has_jobs_field(browser): """perf.status contains a jobs list (may be empty).""" result = browser("perf.status") assert "jobs" in result assert isinstance(result["jobs"], list) def test_perf_set_profile_returns_profile(browser): """perf.set_profile responds with the applied profile.""" # Save current current = browser("perf.status").get("performanceProfile", "auto") target = "normal" if current != "normal" else "gentle" try: result = browser("perf.set_profile", {"profile": target}) assert isinstance(result, dict) assert result.get("performanceProfile") == target finally: browser("perf.set_profile", {"profile": current}) def test_perf_set_profile_updates_status(browser): """After set_profile the status command reflects the new profile.""" current = browser("perf.status").get("performanceProfile", "auto") target = "gentle" if current != "gentle" else "normal" try: browser("perf.set_profile", {"profile": target}) status = browser("perf.status") assert status.get("performanceProfile") == target finally: browser("perf.set_profile", {"profile": current}) def test_perf_profile_roundtrip_all_values(browser): """Every valid profile can be set and read back without error.""" original = browser("perf.status").get("performanceProfile", "auto") try: for profile in sorted(_VALID_PROFILES): result = browser("perf.set_profile", {"profile": profile}) assert result.get("performanceProfile") == profile status = browser("perf.status") assert status.get("performanceProfile") == profile finally: browser("perf.set_profile", {"profile": original})