From 3018ab0015d571c91999f5a87a9ae367551df8a7 Mon Sep 17 00:00:00 2001 From: wdx <2954089467@qq.com> Date: Fri, 30 Oct 2026 19:09:33 +0800 Subject: [PATCH 1/2] test: replace Mock() with unbound_session in test_app_package_service Replace session=Mock() with the unbound_session fixture in three test methods that call collect_icon() where the session is only passed through to a mocked _upload_files() method and never touches the DB. This is part of the effort tracked in issue #44973 to migrate unit tests away from mock SQLAlchemy sessions to real SQLite-backed or unbound session fixtures. --- .../services/test_app_package_service.py | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/api/tests/unit_tests/services/test_app_package_service.py b/api/tests/unit_tests/services/test_app_package_service.py index 94891030d01243..db4f5d833b64ab 100644 --- a/api/tests/unit_tests/services/test_app_package_service.py +++ b/api/tests/unit_tests/services/test_app_package_service.py @@ -1221,7 +1221,9 @@ def test_app_icon_export_deduplicates_uploads_and_restores_references( assert backend.files[source.key] == payload @staticmethod - def test_app_package_restores_independent_site_image_icon(monkeypatch: pytest.MonkeyPatch) -> None: + def test_app_package_restores_independent_site_image_icon( + monkeypatch: pytest.MonkeyPatch, unbound_session: Session + ) -> None: app_icon_id, site_icon_id = str(uuid4()), str(uuid4()) backend = Mock() backend.load_stream.side_effect = lambda key: iter([key.encode()]) @@ -1237,8 +1239,8 @@ def test_app_package_restores_independent_site_image_icon(monkeypatch: pytest.Mo ) app = {"mode": "chat", "icon_type": "image", "icon": app_icon_id} site = {"title": "Site", "icon_type": "image", "icon": site_icon_id} - exporter.collect_icon(session=Mock(), tenant_id="source", metadata=app) - exporter.collect_icon(session=Mock(), tenant_id="source", metadata=site) + exporter.collect_icon(session=unbound_session, tenant_id="source", metadata=app) + exporter.collect_icon(session=unbound_session, tenant_id="source", metadata=site) with AppPackageService().export( dsl=yaml.safe_dump({"kind": "app", "app": app, "site": site}), name="App", @@ -1260,12 +1262,16 @@ def test_app_package_restores_independent_site_image_icon(monkeypatch: pytest.Mo assert data["site"]["icon"] == "new-site-icon" @staticmethod - def test_icon_export_rejects_unavailable_tenant_upload(monkeypatch: pytest.MonkeyPatch) -> None: + def test_icon_export_rejects_unavailable_tenant_upload( + monkeypatch: pytest.MonkeyPatch, unbound_session: Session + ) -> None: exporter = AgentPackageResourceExporter(storage_backend=Mock()) monkeypatch.setattr(exporter, "_upload_files", Mock(return_value={})) with pytest.raises(RosterAgentPackageExportFailedError, match="unavailable"): exporter.collect_icon( - session=Mock(), tenant_id="tenant", metadata={"icon_type": "image", "icon": str(uuid4())} + session=unbound_session, + tenant_id="tenant", + metadata={"icon_type": "image", "icon": str(uuid4())}, ) @staticmethod @@ -1286,7 +1292,9 @@ def test_icon_image_limit_is_enforced(config_overrides: Callable[..., None]) -> AppPackageService().read_package(_icon_archive()) @staticmethod - def test_roster_export_embeds_agent_icon(monkeypatch: pytest.MonkeyPatch) -> None: + def test_roster_export_embeds_agent_icon( + monkeypatch: pytest.MonkeyPatch, unbound_session: Session + ) -> None: from models.agent_config_entities import AgentSoulConfig from models.model import App, AppMode from services.agent.dsl_entities import AgentPackage, AgentPackageMetadata, make_agent_app_dsl @@ -1308,7 +1316,7 @@ def test_roster_export_embeds_agent_icon(monkeypatch: pytest.MonkeyPatch) -> Non } ), ) - resources.collect_icon(session=Mock(), tenant_id="source", metadata=metadata) + resources.collect_icon(session=unbound_session, tenant_id="source", metadata=metadata) app = make_agent_app_dsl( App(name="Agent", mode=AppMode.AGENT), package_ref="agent_1", From 8dcbc696a7a2bd7842e6ac9acab0b760f322f7d9 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 30 Oct 2026 11:25:04 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- api/tests/unit_tests/services/test_app_package_service.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/tests/unit_tests/services/test_app_package_service.py b/api/tests/unit_tests/services/test_app_package_service.py index db4f5d833b64ab..28ee7d818b11ef 100644 --- a/api/tests/unit_tests/services/test_app_package_service.py +++ b/api/tests/unit_tests/services/test_app_package_service.py @@ -1292,9 +1292,7 @@ def test_icon_image_limit_is_enforced(config_overrides: Callable[..., None]) -> AppPackageService().read_package(_icon_archive()) @staticmethod - def test_roster_export_embeds_agent_icon( - monkeypatch: pytest.MonkeyPatch, unbound_session: Session - ) -> None: + def test_roster_export_embeds_agent_icon(monkeypatch: pytest.MonkeyPatch, unbound_session: Session) -> None: from models.agent_config_entities import AgentSoulConfig from models.model import App, AppMode from services.agent.dsl_entities import AgentPackage, AgentPackageMetadata, make_agent_app_dsl