Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

test: migrate residual dataset and archive ORM models (#40668)

Asuka Minato94323c0838f3
diff --git a/api/tests/unit_tests/services/agent/test_composer_candidates.py b/api/tests/unit_tests/services/agent/test_composer_candidates.py
index 5566d48c690..d1edf2cfa60 100644
--- a/api/tests/unit_tests/services/agent/test_composer_candidates.py
+++ b/api/tests/unit_tests/services/agent/test_composer_candidates.py
@@ -2,10 +2,9 @@
from __future__ import annotations
-from types import SimpleNamespace
-
from fields.agent_fields import AgentComposerCandidatesResponse
from models.agent_config_entities import AgentSoulConfig, DeclaredOutputConfig, DeclaredOutputType
+from models.dataset import Dataset
from services.agent.composer_candidates import (
MAX_CANDIDATES_PER_LIST,
previous_node_output_candidates,
@@ -142,9 +141,16 @@ def _soul() -> AgentSoulConfig:
def test_soul_candidates_lists_configured_items_only():
+ dataset = Dataset(
+ id="ds-1",
+ tenant_id="tenant-1",
+ name="产品手册",
+ description="desc",
+ created_by="account-1",
+ )
lists, truncated = soul_candidates(
agent_soul=_soul(),
- dataset_lookup=lambda ids: {"ds-1": SimpleNamespace(name="产品手册", description="desc")},
+ dataset_lookup=lambda ids: {"ds-1": dataset},
workspace_tools_loader=lambda: [
{"id": "tavily/tavily_search", "name": "tavily_search", "provider": "tavily", "plugin_id": "lg/tavily"}
],
diff --git a/api/tests/unit_tests/services/retention/workflow_run/test_bundle_archive_maintenance.py b/api/tests/unit_tests/services/retention/workflow_run/test_bundle_archive_maintenance.py
index 82b616f3b5e..4e8f12294fe 100644
--- a/api/tests/unit_tests/services/retention/workflow_run/test_bundle_archive_maintenance.py
+++ b/api/tests/unit_tests/services/retention/workflow_run/test_bundle_archive_maintenance.py
@@ -1,6 +1,5 @@
import datetime
import json
-from types import SimpleNamespace
from typing import Any, cast
from unittest.mock import MagicMock, call, patch
@@ -115,6 +114,13 @@ def _bundle_model(entry: ArchiveBundleCatalogEntry) -> WorkflowRunArchiveBundle:
return bundle
+def _cursor_bundle(*, year: int, tenant_id: str) -> WorkflowRunArchiveBundle:
+ bundle = _bundle_model(_catalog_entry())
+ bundle.year = year
+ bundle.tenant_id = tenant_id
+ return bundle
+
+
def _persist_catalog(session: Session, entry: ArchiveBundleCatalogEntry) -> None:
session.add(_bundle_model(entry))
session.flush()
@@ -291,31 +297,26 @@ def test_catalog_shard_preflight_uses_requested_tenant_scope(
[
(None, None, "does not exist"),
(
- SimpleNamespace(year=2024, month=3, tenant_id=TENANT_ID),
+ _cursor_bundle(year=2024, tenant_id=TENANT_ID),
None,
"requested archive month",
),
(
- SimpleNamespace(year=2025, month=3, tenant_id="other-tenant"),
+ _cursor_bundle(year=2025, tenant_id="other-tenant"),
[TENANT_ID],
"requested tenant scope",
),
],
)
def test_catalog_discovery_rejects_cursor_outside_requested_scope(
- cursor_bundle: SimpleNamespace | None,
+ cursor_bundle: WorkflowRunArchiveBundle | None,
tenant_ids: list[str] | None,
error_message: str,
sqlite_session_factory: sessionmaker[Session],
sqlite_session: Session,
) -> None:
if cursor_bundle is not None:
- entry = _catalog_entry()
- stored = _bundle_model(entry)
- stored.year = cursor_bundle.year
- stored.month = cursor_bundle.month
- stored.tenant_id = cursor_bundle.tenant_id
- sqlite_session.add(stored)
+ sqlite_session.add(cursor_bundle)
sqlite_session.commit()
maintenance = WorkflowRunBundleArchiveMaintenance(
storage=cast(MagicMock, MagicMock()),