From 741eb387ed7a42386eed5a6fbd0ca0e3add59b7d Mon Sep 17 00:00:00 2001 From: host Date: Sun, 1 Nov 2026 08:29:52 +0000 Subject: [PATCH] test: retarget v2 coverage monkeypatch targets to definition modules after handler split (assertions unchanged) --- cloud/tests/test_v2cov_server_handlers.py | 4 +-- cloud/tests/test_v2cov_server_handlers2.py | 2 +- cloud/tests/test_v2cov_server_handlers3.py | 36 +++++++++++----------- cloud/tests/test_v2cov_server_handlers4.py | 16 +++++----- cloud/tests/test_v2cov_server_handlers5.py | 4 +-- cloud/tests/test_v2cov_server_handlers6.py | 8 ++--- cloud/tests/test_v2cov_server_handlers7.py | 23 +++++++------- 7 files changed, 45 insertions(+), 48 deletions(-) diff --git a/cloud/tests/test_v2cov_server_handlers.py b/cloud/tests/test_v2cov_server_handlers.py index 3db018c..b0d66c4 100644 --- a/cloud/tests/test_v2cov_server_handlers.py +++ b/cloud/tests/test_v2cov_server_handlers.py @@ -32,11 +32,9 @@ REPO_ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(REPO_ROOT)) import cloud.server as server_mod +from cloud.handler_fullauto import FullAutoError, _full_auto_branch_protection_ok, _full_auto_github_request from cloud.server import ( CloudControlPlaneHandler, - FullAutoError, - _full_auto_branch_protection_ok, - _full_auto_github_request, init_db, ) diff --git a/cloud/tests/test_v2cov_server_handlers2.py b/cloud/tests/test_v2cov_server_handlers2.py index b4c2e9f..549cf72 100644 --- a/cloud/tests/test_v2cov_server_handlers2.py +++ b/cloud/tests/test_v2cov_server_handlers2.py @@ -350,7 +350,7 @@ class AutomationTestCase(_Base): def test_automation_create_generic_error_502(self): self._project() h = self._h(body={"name": "a1", "prompt": "p"}) - with mock.patch("cloud.server._auto_create", + with mock.patch("cloud.handler_automation._auto_create", side_effect=RuntimeError("db boom")): h._automation_create("u1", "p1") code, payload = self._last(h) diff --git a/cloud/tests/test_v2cov_server_handlers3.py b/cloud/tests/test_v2cov_server_handlers3.py index ac1e98a..f244afc 100644 --- a/cloud/tests/test_v2cov_server_handlers3.py +++ b/cloud/tests/test_v2cov_server_handlers3.py @@ -387,7 +387,7 @@ class TodosAutomationLoopTestCase(_Base): def test_todos_update_generic_error_502(self): todo = self._todo() h = self._h(body={"title": "new"}) - with mock.patch("cloud.server._todo_update", + with mock.patch("cloud.handler_automation._todo_update", side_effect=RuntimeError("db down")): h._todos_update("u1", "p1", todo["id"]) self.assertEqual(self._last(h)[0], 502) @@ -509,7 +509,7 @@ class TodosAutomationLoopTestCase(_Base): def test_auto_memory_run_extracted_audits(self): h = self._h(body={}) - with mock.patch("cloud.server._auto_process_due", + with mock.patch("cloud.handler_identity._auto_process_due", return_value=[{"status": "extracted", "task_id": "t1"}, {"status": "skipped", @@ -756,7 +756,7 @@ class OauthGatewayTestCase(_Base): h.path = ("/oauth/github/login?client_id=c" "&redirect_uri=https://example.com/cb") err = OAuthError("denied", reason="bad_client") - with mock.patch("cloud.server.start_oauth_login", + with mock.patch("cloud.handler_oauth.start_oauth_login", side_effect=err): h._oauth_login("/oauth/github/login") code, payload = self._last(h) @@ -767,7 +767,7 @@ class OauthGatewayTestCase(_Base): h = self._h() h.path = ("/oauth/github/login?client_id=c" "&redirect_uri=https://example.com/cb") - with mock.patch("cloud.server.start_oauth_login", + with mock.patch("cloud.handler_oauth.start_oauth_login", side_effect=ValueError("bad scope")): h._oauth_login("/oauth/github/login") self.assertEqual(self._last(h)[0], 400) @@ -784,7 +784,7 @@ class OauthGatewayTestCase(_Base): "redirect_uri": "https://example.com/cb"}) h._authenticate = lambda: "u1" err = OAuthError("denied", reason="bad_client") - with mock.patch("cloud.server.build_authorization_url", + with mock.patch("cloud.handler_oauth.build_authorization_url", side_effect=err): h._oauth_bind_initiate("github") code, payload = self._last(h) @@ -795,7 +795,7 @@ class OauthGatewayTestCase(_Base): h = self._h(body={"client_id": "c", "redirect_uri": "https://example.com/cb"}) h._authenticate = lambda: "u1" - with mock.patch("cloud.server.build_authorization_url", + with mock.patch("cloud.handler_oauth.build_authorization_url", side_effect=ValueError("bad scope")): h._oauth_bind_initiate("github") self.assertEqual(self._last(h)[0], 400) @@ -813,8 +813,8 @@ class OauthGatewayTestCase(_Base): def create_state(self, provider, redirect_uri, client_id=None, bind_user_id=None): return "st1" - with mock.patch("cloud.server.OAuthStateStore", _Store), \ - mock.patch("cloud.server.build_authorization_url", + with mock.patch("cloud.handler_oauth.OAuthStateStore", _Store), \ + mock.patch("cloud.handler_oauth.build_authorization_url", return_value="https://example.com/auth"): h._oauth_bind_initiate("github") code, payload = self._last(h) @@ -824,7 +824,7 @@ class OauthGatewayTestCase(_Base): def _finish_h(self, identity): h = self._h() h._oauth_clients = lambda provider: (None, None) - patcher = mock.patch("cloud.server.handle_oauth_callback", + patcher = mock.patch("cloud.handler_oauth.handle_oauth_callback", return_value=dict(identity)) patcher.start() self.addCleanup(patcher.stop) @@ -864,7 +864,7 @@ class OauthGatewayTestCase(_Base): h = self._finish_h({"external_id": "ext-new"}) with mock.patch.dict(os.environ, {"SUB2API_BASE_URL": "https://gw.example"}), \ - mock.patch("cloud.server._ensure_sub2api_key", + mock.patch("cloud.handler_oauth._ensure_sub2api_key", side_effect=RuntimeError("gw down")): result = h._oauth_finish("github", "code", "st", "c", "r") self.assertTrue(result[1]) @@ -888,8 +888,8 @@ class OauthGatewayTestCase(_Base): def __init__(self, db_path): self.conn = mock.Mock() self.conn.close.side_effect = RuntimeError("close down") - with mock.patch("cloud.server.OAuthStateStore", _Store), \ - mock.patch("cloud.server.handle_oauth_callback", + with mock.patch("cloud.handler_oauth.OAuthStateStore", _Store), \ + mock.patch("cloud.handler_oauth.handle_oauth_callback", return_value={"bind_user_id": uid, "external_id": "ext1"}): result = h._oauth_finish("github", "code", "st", "c", "r") @@ -1174,7 +1174,7 @@ class WebhookBrowserFullAutoTestCase(_Base): h = self._full_auto_h({"repo": "o/r"}) with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1", "FULL_AUTO_ENABLED": "1"}), \ - mock.patch("cloud.server._resolve_app_token", + mock.patch("cloud.handler_fullauto._resolve_app_token", return_value=None): h._full_auto_execute("u1") code, payload = self._last(h) @@ -1189,7 +1189,7 @@ class WebhookBrowserFullAutoTestCase(_Base): from cloud.full_auto import FullAutoError with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1", "FULL_AUTO_ENABLED": "1"}), \ - mock.patch("cloud.server.auto_config_plan", + mock.patch("cloud.handler_fullauto.auto_config_plan", side_effect=FullAutoError( "bad plan", reason="bad")): h._full_auto_execute("u1") @@ -1205,9 +1205,9 @@ class WebhookBrowserFullAutoTestCase(_Base): from cloud.full_auto import FullAutoDenied with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1", "FULL_AUTO_ENABLED": "1"}), \ - mock.patch("cloud.server.auto_config_plan", + mock.patch("cloud.handler_fullauto.auto_config_plan", return_value=[{"step": "s1"}]), \ - mock.patch("cloud.server.run_plan", + mock.patch("cloud.handler_fullauto.run_plan", side_effect=FullAutoDenied( "nope", reason="step_denied")): h._full_auto_execute("u1") @@ -1223,9 +1223,9 @@ class WebhookBrowserFullAutoTestCase(_Base): from cloud.full_auto import FullAutoError with mock.patch.dict(os.environ, {"CODEX_GLOBAL_ADMINS": "u1", "FULL_AUTO_ENABLED": "1"}), \ - mock.patch("cloud.server.auto_config_plan", + mock.patch("cloud.handler_fullauto.auto_config_plan", return_value=[{"step": "s1"}]), \ - mock.patch("cloud.server.run_plan", + mock.patch("cloud.handler_fullauto.run_plan", side_effect=FullAutoError( "boom", reason="plan")): h._full_auto_execute("u1") diff --git a/cloud/tests/test_v2cov_server_handlers4.py b/cloud/tests/test_v2cov_server_handlers4.py index ac84e39..e5a37cd 100644 --- a/cloud/tests/test_v2cov_server_handlers4.py +++ b/cloud/tests/test_v2cov_server_handlers4.py @@ -255,7 +255,7 @@ class MemoryIdentityTestCase(_Base): def add_summary(self, *a, **k): return 99 h = self._h(body={"goal": "g", "conclusion": "c"}) - with mock.patch("cloud.server.MemoryStore", _Store): + with mock.patch("cloud.handler_identity.MemoryStore", _Store): h._memory_create("u1", "p1") code, payload = self._last(h) self.assertEqual(code, 201) @@ -272,12 +272,12 @@ class MemoryIdentityTestCase(_Base): def build_prompt_context(self, project_id, top_k=5): return "" h = self._h() - with mock.patch("cloud.server.MemoryStore", _Store): + with mock.patch("cloud.handler_identity.MemoryStore", _Store): h._memory_list("p1", {}) self.assertEqual(self._last(h)[0], 200) def test_memory_supersede_close_failure_swallowed(self): - from cloud.server import MemoryStore + from cloud.handler_identity import MemoryStore store = MemoryStore(self.db_path) try: mid = store.add_summary("p1", "", "g", "c") @@ -291,7 +291,7 @@ class MemoryIdentityTestCase(_Base): def deprecate(self, mid): pass h = self._h() - with mock.patch("cloud.server.MemoryStore", _Store): + with mock.patch("cloud.handler_identity.MemoryStore", _Store): h._memory_supersede("u1", "p1", str(mid)) code, payload = self._last(h) self.assertEqual(code, 200) @@ -344,7 +344,7 @@ class MemoryIdentityTestCase(_Base): def supersede_memory(self, *a, **k): raise KeyError("gone") h = self._h(body={}) - with mock.patch("cloud.server.IdentityStore", _Store): + with mock.patch("cloud.handler_identity.IdentityStore", _Store): h._identity_user_memory_supersede("u1", "m1") self.assertEqual(self._last(h)[0], 404) @@ -359,7 +359,7 @@ class MemoryIdentityTestCase(_Base): def delete_memory(self, mem_id, user_id): raise KeyError("gone") h = self._h() - with mock.patch("cloud.server.IdentityStore", _Store): + with mock.patch("cloud.handler_identity.IdentityStore", _Store): h._identity_user_memory_delete("u1", "m1") self.assertEqual(self._last(h)[0], 404) @@ -405,7 +405,7 @@ class MemoryIdentityTestCase(_Base): def build_prompt_context(self, project_id): return "" h = self._h() - with mock.patch("cloud.server.MemoryStore", _Store): + with mock.patch("cloud.handler_identity.MemoryStore", _Store): h._identity_context("u1", {"project_id": ["p1"]}) self.assertEqual(self._last(h)[0], 200) @@ -479,7 +479,7 @@ class MemoryIdentityTestCase(_Base): def supersede_memory(self, *a, **k): raise PermissionError("not yours") h = self._h(body={}) - with mock.patch("cloud.server.IdentityStore", _Store): + with mock.patch("cloud.handler_identity.IdentityStore", _Store): h._project_identity_memory_supersede("u1", "p1", "m1") self.assertEqual(self._last(h)[0], 404) diff --git a/cloud/tests/test_v2cov_server_handlers5.py b/cloud/tests/test_v2cov_server_handlers5.py index 53d6a83..47dbbee 100644 --- a/cloud/tests/test_v2cov_server_handlers5.py +++ b/cloud/tests/test_v2cov_server_handlers5.py @@ -147,7 +147,7 @@ class CostRelayTestCase(_Base): def search(self, project_id, q, top_k=5): return [] h = self._h() - with mock.patch("cloud.server.KBStore", _Store): + with mock.patch("cloud.handler_identity.KBStore", _Store): h._kb_search("p1", {"q": ["x"]}) self.assertEqual(self._last(h)[0], 200) @@ -199,7 +199,7 @@ class CostRelayTestCase(_Base): with mock.patch.dict(os.environ, {"CLOUD_GATEWAY": "sub2api"}), \ mock.patch("cloud.server._validate_sub2api_key", return_value=("ok", "key", "sub", "kid")), \ - mock.patch("cloud.server._list_sub2api_models", + mock.patch("cloud.handler_identity._list_sub2api_models", side_effect=RuntimeError("gw down")): h._relay_models("u1") self.assertEqual(self._last(h)[0], 502) diff --git a/cloud/tests/test_v2cov_server_handlers6.py b/cloud/tests/test_v2cov_server_handlers6.py index 72511b8..a9bf529 100644 --- a/cloud/tests/test_v2cov_server_handlers6.py +++ b/cloud/tests/test_v2cov_server_handlers6.py @@ -937,7 +937,7 @@ class MetricsOauthAppTestCase(_Base): with mock.patch.dict(os.environ, { "CODEX_GLOBAL_ADMINS": "u1", "GITHUB_APP_PUBLIC_BASE": "https://api.example.test"}), \ - mock.patch("cloud.server.SetupStateStore", _Store): + mock.patch("cloud.handler_oauth.SetupStateStore", _Store): h._github_app_setup_state() self.assertEqual(self._last(h)[0], 200) @@ -981,8 +981,8 @@ class MetricsOauthAppTestCase(_Base): def consume_state(self, state, allowed_issuers=None): return True from cloud.github_app import AppError - with mock.patch("cloud.server.SetupStateStore", _Store), \ - mock.patch("cloud.server.exchange_manifest_code", + with mock.patch("cloud.handler_oauth.SetupStateStore", _Store), \ + mock.patch("cloud.handler_oauth.exchange_manifest_code", side_effect=AppError("bad code", reason="exchange_failed")): h._github_app_callback() @@ -998,7 +998,7 @@ class MetricsOauthAppTestCase(_Base): class FullAutoKeysPushTestCase(_Base): def test_full_auto_config_plan_error(self): h = self._h() - with mock.patch("cloud.server.auto_config_plan", + with mock.patch("cloud.handler_fullauto.auto_config_plan", side_effect=FullAutoError("boom", reason="x")): h._full_auto_config_plan("u1", {"repo": ["o/r"]}) code, payload = self._last(h) diff --git a/cloud/tests/test_v2cov_server_handlers7.py b/cloud/tests/test_v2cov_server_handlers7.py index 6eb7d05..5fe0078 100644 --- a/cloud/tests/test_v2cov_server_handlers7.py +++ b/cloud/tests/test_v2cov_server_handlers7.py @@ -22,6 +22,7 @@ from unittest import mock REPO_ROOT = Path(__file__).resolve().parents[2] sys.path.insert(0, str(REPO_ROOT)) +from cloud.handler_fullauto import _full_auto_installation_verified, _full_auto_parse_plan_params from cloud.server import ( CloudControlPlaneHandler, RateLimiter, @@ -31,8 +32,6 @@ from cloud.server import ( _classify_goal_followup, _deployed_commit, _default_executor, - _full_auto_installation_verified, - _full_auto_parse_plan_params, _make_rate_limiter, _read_agent_entries, _read_agent_entries_multi, @@ -311,23 +310,23 @@ class HelpersTestCase(_Base): def test_installation_verified_config_none(self): c = _conn(self.db_path) - with mock.patch("cloud.server.get_app_config", + with mock.patch("cloud.handler_fullauto.get_app_config", return_value=None): self.assertFalse(_full_auto_installation_verified(c)) c.close() def test_installation_verified_config_error(self): c = _conn(self.db_path) - with mock.patch("cloud.server.get_app_config", + with mock.patch("cloud.handler_fullauto.get_app_config", side_effect=RuntimeError("config down")): self.assertFalse(_full_auto_installation_verified(c)) c.close() def test_installation_verified_repo(self): c = _conn(self.db_path) - with mock.patch("cloud.server.get_app_config", + with mock.patch("cloud.handler_fullauto.get_app_config", return_value={"id": 1}), \ - mock.patch("cloud.server.find_installation_for_repo", + mock.patch("cloud.handler_fullauto.find_installation_for_repo", return_value={"id": 9}): self.assertTrue( _full_auto_installation_verified(c, "o/r")) @@ -335,9 +334,9 @@ class HelpersTestCase(_Base): def test_installation_verified_any(self): c = _conn(self.db_path) - with mock.patch("cloud.server.get_app_config", + with mock.patch("cloud.handler_fullauto.get_app_config", return_value={"id": 1}), \ - mock.patch("cloud.server.list_installations", + mock.patch("cloud.handler_fullauto.list_installations", return_value=[{"id": 9}]): self.assertTrue(_full_auto_installation_verified(c)) c.close() @@ -391,7 +390,7 @@ class HelpersTestCase(_Base): def __init__(self, db_path): self.conn = mock.Mock() self.conn.close.side_effect = RuntimeError("down") - with mock.patch("cloud.server.AuthStore", _FakeStore): + with mock.patch("cloud.handler_support.AuthStore", _FakeStore): with _auth_store_cm(self.db_path) as store: self.assertIsNotNone(store) @@ -475,7 +474,7 @@ class HandlerLeftoversTestCase(_Base): def index_file(self, project_id, path, content, kind="file"): return "d1" - with mock.patch("cloud.server.KBStore", _Store): + with mock.patch("cloud.handler_identity.KBStore", _Store): h._kb_index("u1", "p1") code, payload = self._last(h) self.assertEqual(code, 201) @@ -539,7 +538,7 @@ class HandlerLeftoversTestCase(_Base): self.assertTrue(h._check_coordinator_reserve("u1", 1)) def test_oauth_login_close_failure_swallowed(self): - from cloud.server import OAuthStateStore as _RealStore + from cloud.handler_oauth import OAuthStateStore as _RealStore class _ClosingProxy: def __init__(self, real): @@ -558,7 +557,7 @@ class HandlerLeftoversTestCase(_Base): h = self._h() h.path = ("/oauth/github/login?client_id=c" "&redirect_uri=https://x.test/cb") - with mock.patch("cloud.server.OAuthStateStore", _Store): + with mock.patch("cloud.handler_oauth.OAuthStateStore", _Store): h._oauth_login("/oauth/github/login") # Either 200 (login started) or 400 (no client config): both # pass through the close-failure swallow in the finally.