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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: add command cli to migration rbac scope to automatic_include_workspace_members (#41304)
wangxiaolei0047522b0df4
diff --git a/api/commands/__init__.py b/api/commands/__init__.pyindex 08ce86368d7..58ca5d6ffb3 100644--- a/api/commands/__init__.py+++ b/api/commands/__init__.py@@ -22,7 +22,11 @@ from .plugin import (setup_system_trigger_oauth_client,transform_datasource_credentials,)-from .rbac import migrate_dataset_permissions_to_rbac, migrate_member_roles_to_rbac+from .rbac import (+ migrate_dataset_permissions_to_rbac,+ migrate_member_roles_to_rbac,+ migrate_resource_whitelist_scopes_to_automatic_include,+)from .retention import (archive_workflow_runs,archive_workflow_runs_plan,@@ -82,6 +86,7 @@ __all__ = ["migrate_knowledge_vector_database","migrate_member_roles_to_rbac","migrate_oss",+ "migrate_resource_whitelist_scopes_to_automatic_include","migration_data_wizard","old_metadata_migration","remove_orphaned_files_on_storage",diff --git a/api/commands/data_migrate.py b/api/commands/data_migrate.pyindex 35c2be999b7..7573bc92ad8 100644--- a/api/commands/data_migrate.py+++ b/api/commands/data_migrate.py@@ -7,7 +7,7 @@ from typing import castimport click-from commands.rbac import migrate_dataset_permissions_to_rbac+from commands.rbac import migrate_dataset_permissions_to_rbac, migrate_resource_whitelist_scopes_to_automatic_includefrom extensions.ext_database import dbfrom graphon.model_runtime.entities.model_entities import ModelTypefrom services.legacy_model_type_migration import (@@ -179,3 +179,4 @@ def legacy_model_types(data_migrate.add_command(legacy_model_types)data_migrate.add_command(migrate_dataset_permissions_to_rbac)+data_migrate.add_command(migrate_resource_whitelist_scopes_to_automatic_include)diff --git a/api/commands/rbac.py b/api/commands/rbac.pyindex 22b7fe777b7..27c9f02e718 100644--- a/api/commands/rbac.py+++ b/api/commands/rbac.py@@ -11,10 +11,11 @@ from sqlalchemy.orm import Sessionfrom configs import dify_configfrom core.db.session_factory import session_factoryfrom core.rbac import RBACResourceWhitelistScope-from models import Dataset, DatasetPermission, DatasetPermissionEnum, TenantAccountJoin, TenantAccountRole+from models import App, Dataset, DatasetPermission, DatasetPermissionEnum, TenantAccountJoin, TenantAccountRolefrom services.enterprise.rbac_service import ListOption, RBACService, ReplaceMemberBindings, ReplaceUserAccessPolicies_RBAC_DEFAULT_ACCESS_POLICY_ID = "default"+_RBAC_RESOURCE_ACCESS_POLICY_BATCH_SIZE = 500_LEGACY_ROLE_TO_BUILTIN_TAG = {TenantAccountRole.OWNER.value: "owner",@@ -310,6 +311,356 @@ def _emit_dataset_permission_migration_event(payload: dict[str, object]) -> Noneclick.echo(json.dumps(payload, sort_keys=True))+def _emit_resource_whitelist_scope_migration_event(payload: dict[str, object]) -> None:+ click.echo(json.dumps(payload, sort_keys=True))+++def _normalize_rbac_whitelist_scope(scope: object) -> RBACResourceWhitelistScope | None:+ if scope is None:+ return None+ try:+ return RBACResourceWhitelistScope(str(scope))+ except ValueError as exc:+ raise ValueError(f"Unsupported RBAC whitelist scope: {scope}") from exc+++def _owner_account_id(tenant_id: str, *, session: Session) -> str:+ account_id = session.scalar(+ select(TenantAccountJoin.account_id)+ .where(TenantAccountJoin.tenant_id == tenant_id, TenantAccountJoin.role == TenantAccountRole.OWNER)+ .order_by(TenantAccountJoin.id.asc())+ .limit(1)+ )+ if not account_id:+ raise ValueError(f"Workspace owner not found for tenant={tenant_id}")+ return str(account_id)+++def _workspace_member_account_id_batches(tenant_id: str, batch_size: int) -> Iterator[list[str]]:+ last_join_id: str | None = None+ while True:+ with session_factory.create_session() as session:+ stmt = (+ select(TenantAccountJoin.id, TenantAccountJoin.account_id)+ .where(TenantAccountJoin.tenant_id == tenant_id)+ .order_by(TenantAccountJoin.id.asc())+ .limit(batch_size)+ )+ if last_join_id:+ stmt = stmt.where(TenantAccountJoin.id > last_join_id)++ rows = list(session.execute(stmt).all())+ if not rows:+ return++ yield [str(row.account_id) for row in rows]+ last_join_id = str(rows[-1].id)+++def _replace_resource_whitelist(+ resource_type: str,+ *,+ tenant_id: str,+ operator_account_id: str,+ resource_id: str,+ automatic_include_workspace_members: bool,+) -> None:+ payload = ReplaceMemberBindings(automatic_include_workspace_members=automatic_include_workspace_members)+ if resource_type == "app":+ RBACService.AppAccess.replace_whitelist(+ tenant_id=tenant_id,+ account_id=operator_account_id,+ app_id=resource_id,+ payload=payload,+ )+ return+ RBACService.DatasetAccess.replace_whitelist(+ tenant_id=tenant_id,+ account_id=operator_account_id,+ dataset_id=resource_id,+ payload=payload,+ )+++def _replace_resource_default_access_policies(+ resource_type: str,+ *,+ tenant_id: str,+ operator_account_id: str,+ resource_id: str,+ account_ids: list[str],+) -> None:+ if not account_ids:+ return+ payload = ReplaceUserAccessPolicies(+ access_policy_ids=[_RBAC_DEFAULT_ACCESS_POLICY_ID],+ account_ids=account_ids,+ )+ if resource_type == "app":+ RBACService.AppAccess.replace_user_access_policies(+ tenant_id=tenant_id,+ account_id=operator_account_id,+ app_id=resource_id,+ target_account_id=None,+ payload=payload,+ )+ return+ RBACService.DatasetAccess.replace_user_access_policies(+ tenant_id=tenant_id,+ account_id=operator_account_id,+ dataset_id=resource_id,+ target_account_id=None,+ payload=payload,+ )+++def _resource_legacy_whitelist_config(+ resource_type: str,+ *,+ tenant_id: str,+ operator_account_id: str,+ resource_id: str,+):+ if resource_type == "app":+ return RBACService.AppAccess.legacy_whitelist_config(+ tenant_id=tenant_id,+ account_id=operator_account_id,+ app_id=resource_id,+ )+ return RBACService.DatasetAccess.legacy_whitelist_config(+ tenant_id=tenant_id,+ account_id=operator_account_id,+ dataset_id=resource_id,+ )+++def _iter_rbac_resource_rows(+ resource_type: str,+ *,+ tenant_id: str | None,+ resource_id: str | None,+ batch_size: int,+) -> Iterator[tuple[str, str, str, str | None]]:+ model = App if resource_type == "app" else Dataset+ last_resource_id: str | None = None+ while True:+ with session_factory.create_session() as session:+ stmt = select(model.id, model.tenant_id, model.maintainer).order_by(model.id.asc()).limit(batch_size)+ if tenant_id:+ stmt = stmt.where(model.tenant_id == tenant_id)+ if resource_id:+ stmt = stmt.where(model.id == resource_id)+ if last_resource_id:+ stmt = stmt.where(model.id > last_resource_id)++ rows = list(session.execute(stmt).all())+ if not rows:+ return++ for row in rows:+ yield resource_type, str(row.tenant_id), str(row.id), str(row.maintainer) if row.maintainer else None++ last_resource_id = str(rows[-1].id)+ if resource_id:+ return+++def _iter_selected_rbac_resource_rows(+ resource_type: str,+ *,+ tenant_id: str | None,+ resource_id: str | None,+ batch_size: int,+) -> Iterator[tuple[str, str, str, str | None]]:+ if resource_type in {"app", "all"}:+ yield from _iter_rbac_resource_rows(+ "app",+ tenant_id=tenant_id,+ resource_id=resource_id if resource_type == "app" else None,+ batch_size=batch_size,+ )+ if resource_type in {"dataset", "all"}:+ yield from _iter_rbac_resource_rows(+ "dataset",+ tenant_id=tenant_id,+ resource_id=resource_id if resource_type == "dataset" else None,+ batch_size=batch_size,+ )+++ "rbac-migrate-resource-whitelist-scopes",+ help=(+ "Migrate RBAC app/dataset whitelist scope values to automatic_include_workspace_members. "+ "Old scope all becomes true; specific and only_me become false."+ ),+)[email protected]("--tenant-id", help="Only migrate resources in a single workspace.")+ "--resource-type",+ type=click.Choice(["app", "dataset", "all"]),+ default="all",+ show_default=True,+ help="Resource type to migrate.",+)[email protected]("--resource-id", help="Only migrate a single resource. Requires --resource-type app or dataset.")[email protected]("--batch-size", default=500, show_default=True, type=click.IntRange(min=1))+ "--member-batch-size",+ default=_RBAC_RESOURCE_ACCESS_POLICY_BATCH_SIZE,+ show_default=True,+ type=click.IntRange(min=1),+ help="Workspace members written per default-policy call when migrating old scope all.",+)+ "--dry-run/--apply",+ default=True,+ show_default=True,+ help="Preview the migration without writing RBAC bindings. Use --apply to write changes.",+)+def migrate_resource_whitelist_scopes_to_automatic_include(+ tenant_id: str | None,+ resource_type: str,+ resource_id: str | None,+ batch_size: int,+ member_batch_size: int,+ dry_run: bool,+) -> None:+ """Backfill RBAC app/dataset automatic workspace-member inclusion from old RBAC scope."""+ if resource_id and resource_type == "all":+ raise click.BadParameter("--resource-id requires --resource-type app or dataset", param_hint="--resource-id")++ click.echo(click.style("Starting RBAC resource whitelist scope migration.", fg="green"))++ scanned_count = 0+ migrated_count = 0+ member_policy_batch_count = 0+ owner_account_ids_by_tenant_id: dict[str, str] = {}++ for (+ current_resource_type,+ workspace_id,+ current_resource_id,+ maintainer_account_id,+ ) in _iter_selected_rbac_resource_rows(+ resource_type,+ tenant_id=tenant_id,+ resource_id=resource_id,+ batch_size=batch_size,+ ):+ scanned_count += 1+ with session_factory.create_session() as session:+ operator_account_id = maintainer_account_id or owner_account_ids_by_tenant_id.get(workspace_id)+ if not operator_account_id:+ operator_account_id = _owner_account_id(workspace_id, session=session)+ owner_account_ids_by_tenant_id[workspace_id] = operator_account_id++ legacy_config = _resource_legacy_whitelist_config(+ current_resource_type,+ tenant_id=workspace_id,+ operator_account_id=operator_account_id,+ resource_id=current_resource_id,+ )+ scope = _normalize_rbac_whitelist_scope(legacy_config.rbac_whitelist_scope)+ if scope is None:+ _emit_resource_whitelist_scope_migration_event(+ {+ "event": "resource_whitelist_scope_migration_skipped",+ "reason": "missing_legacy_scope",+ "dry_run": dry_run,+ "tenant_id": workspace_id,+ "resource_type": current_resource_type,+ "resource_id": current_resource_id,+ }+ )+ continue++ automatic_include_workspace_members = scope is RBACResourceWhitelistScope.ALL+ if scope is RBACResourceWhitelistScope.SPECIFIC:+ member_account_ids = sorted(set(legacy_config.account_ids))+ member_source = "legacy_specific_members"+ elif scope is RBACResourceWhitelistScope.ONLY_ME:+ member_account_ids = [maintainer_account_id] if maintainer_account_id else []+ member_source = "resource_maintainer"+ else:+ member_account_ids = []+ member_source = "workspace_members"++ _emit_resource_whitelist_scope_migration_event(+ {+ "event": "resource_whitelist_scope_migration_proposed_change",+ "dry_run": dry_run,+ "tenant_id": workspace_id,+ "operator_account_id": operator_account_id,+ "resource_type": current_resource_type,+ "resource_id": current_resource_id,+ "before": {+ "rbac_whitelist_scope": scope.value,+ "legacy_account_ids": sorted(set(legacy_config.account_ids)),+ },+ "after": {+ "automatic_include_workspace_members": automatic_include_workspace_members,+ "default_policy_member_source": member_source,+ "default_policy_account_ids": member_account_ids,+ },+ }+ )++ if dry_run:+ continue++ _replace_resource_whitelist(+ current_resource_type,+ tenant_id=workspace_id,+ operator_account_id=operator_account_id,+ resource_id=current_resource_id,+ automatic_include_workspace_members=automatic_include_workspace_members,+ )+ migrated_count += 1++ if scope is RBACResourceWhitelistScope.ALL:+ for batch in _workspace_member_account_id_batches(workspace_id, member_batch_size):+ _replace_resource_default_access_policies(+ current_resource_type,+ tenant_id=workspace_id,+ operator_account_id=operator_account_id,+ resource_id=current_resource_id,+ account_ids=batch,+ )+ member_policy_batch_count += 1+ else:+ _replace_resource_default_access_policies(+ current_resource_type,+ tenant_id=workspace_id,+ operator_account_id=operator_account_id,+ resource_id=current_resource_id,+ account_ids=member_account_ids,+ )+ if member_account_ids:+ member_policy_batch_count += 1++ if scanned_count == 0:+ click.echo(click.style("No RBAC resources found for migration.", fg="yellow"))+ return++ if dry_run:+ click.echo(+ click.style(+ f"Dry run completed. Scanned {scanned_count} RBAC resources. No RBAC bindings were written.",+ fg="yellow",+ )+ )+ else:+ click.echo(+ click.style(+ "RBAC resource whitelist scope migration completed. "+ f"Scanned {scanned_count} resources, migrated {migrated_count}, "+ f"wrote {member_policy_batch_count} default-policy batches.",+ fg="green",+ )+ )++@click.command("rbac-migrate-dataset-permissions",help=(diff --git a/api/core/app/apps/workflow_app_runner.py b/api/core/app/apps/workflow_app_runner.pyindex 7821e6c9fbc..6399ea3d089 100644--- a/api/core/app/apps/workflow_app_runner.py+++ b/api/core/app/apps/workflow_app_runner.py@@ -58,6 +58,7 @@ from core.workflow.workflow_entry import WorkflowEntryfrom core.workflow.workflow_run_outputs import project_node_outputs_for_workflow_runfrom graphon.entities.graph_config import NodeConfigDictAdapterfrom graphon.entities.pause_reason import HitlRequired+from graphon.enums import BuiltinNodeTypesfrom graphon.graph import Graphfrom graphon.graph_engine.layers import GraphEngineLayerfrom graphon.graph_events import (@@ -534,6 +535,17 @@ class WorkflowBasedAppRunner:outputs=node_run_result.outputs,)execution_metadata = node_run_result.metadata+ if event.node_type == BuiltinNodeTypes.ANSWER and (event.in_iteration_id or event.in_loop_id):+ answer = outputs.get("answer")+ if isinstance(answer, str) and answer:+ self._publish_event(+ QueueTextChunkEvent(+ text=answer,+ from_variable_selector=[event.node_id, "answer"],+ in_iteration_id=event.in_iteration_id,+ in_loop_id=event.in_loop_id,+ )+ )self._publish_event(QueueNodeSucceededEvent(node_execution_id=event.id,diff --git a/api/services/enterprise/rbac_service.py b/api/services/enterprise/rbac_service.pyindex 278e1475cd1..bbfea2db812 100644--- a/api/services/enterprise/rbac_service.py+++ b/api/services/enterprise/rbac_service.py@@ -239,6 +239,22 @@ class ResourceWhitelistConfig(_RBACModel):automatic_include_workspace_members: bool+class _LegacyResourceWhitelistConfig(_RBACModel):+ """RBAC service's pre-toggle whitelist payload, used only by data migrations."""++ account_ids: list[str] = Field(default_factory=list)+ rbac_whitelist_scope: str | None = Field(+ default=None, validation_alias=AliasChoices("rbac_whitelist_scope", "scope")+ )++ @field_validator("account_ids", mode="before")+ @classmethod+ def _coerce_account_ids(cls, value: Any) -> list[str]:+ if value is None:+ return []+ return value++class ResourceWhitelistResources(_RBACModel):unrestricted: bool = Falseresource_ids: list[str] = Field(default_factory=list)@@ -1180,6 +1196,19 @@ class RBACService:)return ResourceWhitelistConfig.model_validate(data or {})+ @staticmethod+ def legacy_whitelist_config(+ tenant_id: str, account_id: str | None, app_id: str+ ) -> _LegacyResourceWhitelistConfig:+ data = _inner_call(+ "GET",+ f"{_INNER_PREFIX}/apps/whitelist",+ tenant_id=tenant_id,+ account_id=account_id,+ params={"app_id": app_id},+ )+ return _LegacyResourceWhitelistConfig.model_validate(data or {})+@staticmethoddef replace_whitelist(tenant_id: str,@@ -1365,6 +1394,19 @@ class RBACService:)return ResourceWhitelistConfig.model_validate(data or {})+ @staticmethod+ def legacy_whitelist_config(+ tenant_id: str, account_id: str | None, dataset_id: str+ ) -> _LegacyResourceWhitelistConfig:+ data = _inner_call(+ "GET",+ f"{_INNER_PREFIX}/datasets/whitelist",+ tenant_id=tenant_id,+ account_id=account_id,+ params={"dataset_id": dataset_id},+ )+ return _LegacyResourceWhitelistConfig.model_validate(data or {})+@staticmethoddef replace_whitelist(tenant_id: str,diff --git a/api/tests/unit_tests/commands/test_legacy_model_type_migration.py b/api/tests/unit_tests/commands/test_legacy_model_type_migration.pyindex 23102154f1a..39c849e69d2 100644--- a/api/tests/unit_tests/commands/test_legacy_model_type_migration.py+++ b/api/tests/unit_tests/commands/test_legacy_model_type_migration.py@@ -19,7 +19,7 @@ from sqlalchemy.exc import OperationalErrorfrom sqlalchemy.orm import Session, SessionTransaction, sessionmakerfrom graphon.model_runtime.entities.model_entities import ModelType-from models import Dataset, DatasetPermission, DatasetPermissionEnum+from models import Dataset, DatasetPermission, DatasetPermissionEnum, TenantAccountJoin, TenantAccountRolefrom models.account import Tenantfrom models.base import TypeBasefrom models.enums import CredentialSourceType@@ -69,7 +69,7 @@ def rbac_session(sqlite_engine: sa.Engine, monkeypatch: pytest.MonkeyPatch) -> ITypeBase.metadata.create_all(sqlite_engine,- tables=[Dataset.__table__, DatasetPermission.__table__],+ tables=[Dataset.__table__, DatasetPermission.__table__, TenantAccountJoin.__table__],)factory = sessionmaker(bind=sqlite_engine, expire_on_commit=False)monkeypatch.setattr("commands.rbac.session_factory.create_session", factory)@@ -84,6 +84,7 @@ def _persist_dataset(tenant_id: str = "tenant-1",permission: DatasetPermissionEnum = DatasetPermissionEnum.ONLY_ME,created_by: str = "creator-account-1",+ maintainer: str | None = None,) -> Dataset:dataset = Dataset(id=dataset_id,@@ -91,6 +92,7 @@ def _persist_dataset(name=f"Dataset {dataset_id}",permission=permission,created_by=created_by,+ maintainer=maintainer,)session.add(dataset)session.commit()@@ -372,6 +374,12 @@ def test_data_migrate_group_registers_dataset_permission_rbac_migration(command_assert "operator_account_id" not in {param.name for param in command.params}+def test_data_migrate_group_registers_resource_whitelist_scope_migration(command_module) -> None:+ command = command_module.data_migrate.commands["rbac-migrate-resource-whitelist-scopes"]++ assert command is command_module.migrate_resource_whitelist_scopes_to_automatic_include++def test_dataset_permission_rbac_migration_help_mentions_binding_clear_side_effect(command_module) -> None:result = CliRunner().invoke(command_module.data_migrate,@@ -490,6 +498,104 @@ def test_dataset_permission_rbac_migration_dry_run_outputs_structured_proposed_cassert events[1]["call"]["kwargs"]["payload"] == {"access_policy_ids": ["default"]}+def test_resource_whitelist_scope_migration_specific_preserves_existing_members(+ command_module,+ rbac_session: Session,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ rbac_module = importlib.import_module("commands.rbac")+ _persist_dataset(rbac_session, maintainer="maintainer-account-1")+ replace_whitelist_calls: list[dict[str, object]] = []+ replace_policy_calls: list[dict[str, object]] = []++ monkeypatch.setattr(+ rbac_module.RBACService.DatasetAccess,+ "legacy_whitelist_config",+ lambda **kwargs: SimpleNamespace(+ rbac_whitelist_scope="specific",+ account_ids=["member-account-2", "member-account-1", "member-account-1"],+ ),+ )+ monkeypatch.setattr(+ rbac_module.RBACService.DatasetAccess,+ "replace_whitelist",+ lambda **kwargs: replace_whitelist_calls.append(kwargs),+ )+ monkeypatch.setattr(+ rbac_module.RBACService.DatasetAccess,+ "replace_user_access_policies",+ lambda **kwargs: replace_policy_calls.append(kwargs),+ )++ command_module.migrate_resource_whitelist_scopes_to_automatic_include.callback(+ tenant_id=None,+ resource_type="dataset",+ resource_id=None,+ batch_size=500,+ member_batch_size=500,+ dry_run=False,+ )++ assert replace_whitelist_calls[0]["payload"].automatic_include_workspace_members is False+ assert replace_policy_calls[0]["payload"].access_policy_ids == ["default"]+ assert replace_policy_calls[0]["payload"].account_ids == ["member-account-1", "member-account-2"]+++def test_resource_whitelist_scope_migration_all_syncs_workspace_members(+ command_module,+ rbac_session: Session,+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ rbac_module = importlib.import_module("commands.rbac")+ _persist_dataset(rbac_session, maintainer="maintainer-account-1")+ rbac_session.add_all(+ [+ TenantAccountJoin(+ tenant_id="tenant-1",+ account_id="maintainer-account-1",+ role=TenantAccountRole.OWNER,+ ),+ TenantAccountJoin(+ tenant_id="tenant-1",+ account_id="member-account-1",+ role=TenantAccountRole.NORMAL,+ ),+ ]+ )+ rbac_session.commit()+ replace_whitelist_calls: list[dict[str, object]] = []+ replace_policy_calls: list[dict[str, object]] = []++ monkeypatch.setattr(+ rbac_module.RBACService.DatasetAccess,+ "legacy_whitelist_config",+ lambda **kwargs: SimpleNamespace(rbac_whitelist_scope="all", account_ids=[]),+ )+ monkeypatch.setattr(+ rbac_module.RBACService.DatasetAccess,+ "replace_whitelist",+ lambda **kwargs: replace_whitelist_calls.append(kwargs),+ )+ monkeypatch.setattr(+ rbac_module.RBACService.DatasetAccess,+ "replace_user_access_policies",+ lambda **kwargs: replace_policy_calls.append(kwargs),+ )++ command_module.migrate_resource_whitelist_scopes_to_automatic_include.callback(+ tenant_id=None,+ resource_type="dataset",+ resource_id=None,+ batch_size=500,+ member_batch_size=500,+ dry_run=False,+ )++ assert replace_whitelist_calls[0]["payload"].automatic_include_workspace_members is True+ assert replace_policy_calls[0]["payload"].access_policy_ids == ["default"]+ assert set(replace_policy_calls[0]["payload"].account_ids) == {"maintainer-account-1", "member-account-1"}++def test_data_migrate_command_defaults_output_to_stdout_stream(command_module,monkeypatch: pytest.MonkeyPatch,diff --git a/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.py b/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.pyindex 69d470f0ced..fbe5035d3fa 100644--- a/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.py+++ b/api/tests/unit_tests/core/app/apps/test_workflow_app_runner_core.py@@ -543,6 +543,70 @@ class TestWorkflowBasedAppRunner:assert isinstance(queue_event, QueueHumanInputFormFilledEvent)assert queue_event.submitted_data == {"decision": StringSegment(value="approve")}+ def test_handle_nested_answer_success_publishes_text_chunk(self):+ published: list[object] = []++ class _QueueManager:+ def publish(self, event, publish_from):+ published.append(event)++ runner = WorkflowBasedAppRunner(queue_manager=_QueueManager(), app_id="app")+ graph_runtime_state = GraphRuntimeState(+ variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),+ start_at=0.0,+ )+ workflow_entry = SimpleNamespace(graph_engine=SimpleNamespace(graph_runtime_state=graph_runtime_state))++ runner._handle_event(+ workflow_entry,+ NodeRunSucceededEvent(+ id="exec",+ node_id="answer-in-iteration",+ node_type=BuiltinNodeTypes.ANSWER,+ start_at=datetime.now(UTC),+ finished_at=datetime.now(UTC),+ node_run_result=NodeRunResult(outputs={"answer": "inside iteration"}),+ in_iteration_id="iteration",+ ),+ )++ text_chunk = published[0]+ assert isinstance(text_chunk, QueueTextChunkEvent)+ assert text_chunk.text == "inside iteration"+ assert text_chunk.from_variable_selector == ["answer-in-iteration", "answer"]+ assert text_chunk.in_iteration_id == "iteration"+ assert any(isinstance(event, QueueNodeSucceededEvent) for event in published)++ def test_handle_root_answer_success_does_not_publish_extra_text_chunk(self):+ published: list[object] = []++ class _QueueManager:+ def publish(self, event, publish_from):+ published.append(event)++ runner = WorkflowBasedAppRunner(queue_manager=_QueueManager(), app_id="app")+ graph_runtime_state = GraphRuntimeState(+ variable_pool=VariablePool.from_bootstrap(system_variables=default_system_variables()),+ start_at=0.0,+ )+ workflow_entry = SimpleNamespace(graph_engine=SimpleNamespace(graph_runtime_state=graph_runtime_state))++ runner._handle_event(+ workflow_entry,+ NodeRunSucceededEvent(+ id="exec",+ node_id="answer",+ node_type=BuiltinNodeTypes.ANSWER,+ start_at=datetime.now(UTC),+ finished_at=datetime.now(UTC),+ node_run_result=NodeRunResult(outputs={"answer": "root answer"}),+ ),+ )++ assert not any(isinstance(event, QueueTextChunkEvent) for event in published)+ assert len(published) == 1+ assert isinstance(published[0], QueueNodeSucceededEvent)+@pytest.mark.parametrize(("event_factory", "queue_event_cls"),[diff --git a/api/tests/unit_tests/services/enterprise/test_rbac_service.py b/api/tests/unit_tests/services/enterprise/test_rbac_service.pyindex 7ba01ee3537..6bb6bea7866 100644--- a/api/tests/unit_tests/services/enterprise/test_rbac_service.py+++ b/api/tests/unit_tests/services/enterprise/test_rbac_service.py@@ -419,6 +419,7 @@ class TestResourceAccess:mock_send.return_value = {"account_ids": ["acct-1"],"automatic_include_workspace_members": False,+ "scope": "specific",}out = svc.RBACService.DatasetAccess.whitelist_config("tenant-1", "acct-1", "dataset-1")@@ -429,6 +430,22 @@ class TestResourceAccess:assert call.params == {"dataset_id": "dataset-1"}assert out.model_dump(mode="json") == {"automatic_include_workspace_members": False}+ def test_dataset_legacy_whitelist_config_reads_old_scope_without_public_dump(self, mock_send: MagicMock):+ mock_send.return_value = {+ "account_ids": ["acct-1"],+ "automatic_include_workspace_members": False,+ "scope": "specific",+ }++ out = svc.RBACService.DatasetAccess.legacy_whitelist_config("tenant-1", "acct-1", "dataset-1")++ call = _call_args(mock_send)+ assert call.method == "GET"+ assert call.endpoint == "/rbac/datasets/whitelist"+ assert call.params == {"dataset_id": "dataset-1"}+ assert out.account_ids == ["acct-1"]+ assert out.rbac_whitelist_scope == "specific"+def test_app_matrix(self, mock_send: MagicMock):mock_send.return_value = {"resource_id": "app-1", "items": []}out = svc.RBACService.AppAccess.matrix("tenant-1", "acct-1", "app-1")