优化sync_system代码质量

This commit is contained in:
strepsiades
2026-04-01 11:52:57 +08:00
parent eb02fd32a5
commit 8f4727a772
46 changed files with 1431 additions and 890 deletions
@@ -1,5 +1,6 @@
from __future__ import annotations
import logging
import tempfile
from pathlib import Path
@@ -29,6 +30,12 @@ from tests.fixtures.mock_domain import (
)
def _configure_strategy(strategy, **kwargs):
for key, value in kwargs.items():
setattr(strategy.config, key, value)
strategy.config.log_logic_warnings(node_type=strategy.node_type, logger=logging.getLogger(__name__))
@pytest_asyncio.fixture
async def setup_env():
register_test_domain()
@@ -109,7 +116,7 @@ async def test_dependency_resolution_migrated(setup_env):
local, remote, bm, _ = setup_env
project_strategy = TestProjectStrategy("test_project", local, remote, bm)
project_strategy.update_config(depend_fields={})
_configure_strategy(project_strategy, depend_fields={})
await local.add(build_project_node("proj_l", "P-1", name="Project A", code="P-A"))
await remote.add(build_project_node("proj_r", "P-1-R", name="Project A", code="P-A"))
@@ -123,7 +130,8 @@ async def test_dependency_resolution_migrated(setup_env):
assert local.get("proj_l").binding_status == BindingStatus.NORMAL
contract_strategy = TestContractStrategy("test_contract", local, remote, bm)
contract_strategy.update_config(
_configure_strategy(
contract_strategy,
depend_fields={"project_ref": "test_project"},
local_orphan_action=OrphanAction.CREATE_REMOTE,
remote_orphan_action=OrphanAction.NONE,
@@ -164,7 +172,7 @@ async def test_auto_binding_migrated(setup_env):
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(auto_bind=True, auto_bind_fields=["code"], depend_fields={})
_configure_strategy(strategy, auto_bind=True, auto_bind_fields=["code"], depend_fields={})
await local.add(build_project_node("l1", "P1", name="A", code="AUTO-1"))
await remote.add(build_project_node("r1", "RP1", name="A", code="AUTO-1"))
@@ -180,7 +188,7 @@ async def test_auto_binding_skip_on_ambiguous_migrated(setup_env):
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(auto_bind=True, auto_bind_fields=["code"], depend_fields={})
_configure_strategy(strategy, auto_bind=True, auto_bind_fields=["code"], depend_fields={})
await local.add(build_project_node("l1", "P1", name="A", code="AMB-1"))
await local.add(build_project_node("l2", "P2", name="A", code="AMB-1"))
@@ -198,7 +206,8 @@ async def test_auto_binding_many_to_one_can_bind_stable_pick_and_leave_rest_for_
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(
_configure_strategy(
strategy,
auto_bind=True,
auto_bind_fields=["code"],
depend_fields={},
@@ -222,7 +231,8 @@ async def test_pre_bind_data_id_works_when_auto_bind_disabled(setup_env):
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(
_configure_strategy(
strategy,
auto_bind=False,
auto_bind_fields=[],
pre_bind_data_id=[{"local_data_id": "PRE-DID-1", "remote_data_id": "PRE-DID-R-1"}],
@@ -245,7 +255,7 @@ async def test_dependency_check_data_missing_goes_abnormal(setup_env):
local, remote, bm, _ = setup_env
strategy = TestContractStrategy("test_contract", local, remote, bm)
strategy.update_config(depend_fields={"project_ref": "test_project"})
_configure_strategy(strategy, depend_fields={"project_ref": "test_project"})
await local.add(
build_contract_node(
@@ -270,7 +280,7 @@ async def test_auto_binding_key_missing_migrated(setup_env):
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(auto_bind=True, auto_bind_fields=["code", "never_exists"], depend_fields={})
_configure_strategy(strategy, auto_bind=True, auto_bind_fields=["code", "never_exists"], depend_fields={})
await local.add(build_project_node("km_l", "KM-L", name="KM", code="KM-1"))
@@ -286,7 +296,8 @@ async def test_auto_binding_key_id_resolve_fail_migrated(setup_env):
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(
_configure_strategy(
strategy,
auto_bind=True,
auto_bind_fields=["id", "code"],
depend_fields={"id": "test_project"},
@@ -308,7 +319,8 @@ async def test_create_prepare_e21_on_id_resolve_fail(setup_env, monkeypatch: pyt
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(
_configure_strategy(
strategy,
auto_bind=True,
auto_bind_fields=["code"],
depend_fields={"dummy_id": "test_project"},
@@ -347,7 +359,7 @@ async def test_update_prepare_target_missing_data_id_goes_precondition_failed(se
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(update_direction=UpdateDirection.PUSH, depend_fields={})
_configure_strategy(strategy, update_direction=UpdateDirection.PUSH, depend_fields={})
local_src = TestProjectNode(
node_id="upd_src",
@@ -382,7 +394,8 @@ async def test_update_prepare_e30b_on_id_resolve_fail(setup_env, monkeypatch: py
local, remote, bm, _ = setup_env
strategy = TestProjectStrategy("test_project", local, remote, bm)
strategy.update_config(
_configure_strategy(
strategy,
depend_fields={"dummy_id": "test_project"},
update_direction=UpdateDirection.PUSH,
)