# -*- coding: utf-8 -*- from __future__ import annotations import ast import asyncio from pathlib import Path import unittest class R1MaintenanceTests(unittest.TestCase): @classmethod def setUpClass(cls): source_path = Path(__file__).resolve().parents[1] / "daily_state.py" tree = ast.parse(source_path.read_text(encoding="utf-8")) function = next(node for node in tree.body if isinstance(node, ast.ClassDef) and node.name == "DailyStateMixin" for node in node.body if isinstance(node, ast.AsyncFunctionDef) and node.name == "_run_proactive_maintenance_tasks") namespace = {"logger": type("Logger", (), {"warning": staticmethod(lambda *args, **kwargs: None)})(), "_single_line": lambda value, limit=160: str(value or "")[:limit]} module = ast.Module(body=[function], type_ignores=[]) ast.fix_missing_locations(module) exec(compile(module, str(source_path), "exec"), namespace) cls._maintenance = namespace["_run_proactive_maintenance_tasks"] def test_core_schedule_maintenance_runs_when_proactive_generation_disabled(self): calls = [] class Harness: def _proactive_generation_disabled(self): return True async def _agenda_maintenance_tick(self): calls.append("agenda") async def _maybe_settle_skill_growth(self): calls.append("skill") async def _maybe_trigger_jm_cosmos_boredom_read(self): calls.append("reading") async def _maybe_schedule_private_reading_recommendation_request(self): calls.append("recommendation") asyncio.run(R1MaintenanceTests._maintenance(Harness())) self.assertEqual(calls, ["agenda"]) def test_tick_source_runs_disabled_maintenance_before_lock(self): source = (Path(__file__).resolve().parents[1] / "daily_state.py").read_text(encoding="utf-8") disabled_call = "if self._proactive_generation_disabled():\n await self._run_proactive_maintenance_tasks()" self.assertIn(disabled_call, source) tick_start = source.index(" async def _tick(self):") self.assertLess(source.index(disabled_call, tick_start), source.index("async with self._data_lock:", tick_start)) if __name__ == "__main__": unittest.main()