fix(agent): add stable debug conversation (#37744)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
zyssyz123
2026-06-22 09:21:09 +00:00
committed by GitHub
co-authored by autofix-ci[bot]
parent 7c20ffe6c4
commit 4065f63dce
9 changed files with 116 additions and 7 deletions
@@ -219,14 +219,22 @@ def test_agent_app_list_and_create_use_agent_route(
roster_controller.AgentRosterService,
"load_app_backing_agents_by_app_id",
lambda _self, **kwargs: {
"app-list": SimpleNamespace(id="agent-list", role="List role", active_config_snapshot_id=None)
"app-list": SimpleNamespace(
id="agent-list",
role="List role",
debug_conversation_id="debug-conversation-list",
active_config_snapshot_id=None,
)
},
)
monkeypatch.setattr(
roster_controller.AgentRosterService,
"get_app_backing_agent",
lambda _self, **kwargs: SimpleNamespace(
id="agent-created", role="Created role", active_config_snapshot_id=None
id="agent-created",
role="Created role",
debug_conversation_id="debug-conversation-created",
active_config_snapshot_id=None,
),
)
monkeypatch.setattr(
@@ -263,6 +271,7 @@ def test_agent_app_list_and_create_use_agent_route(
assert listed["total"] == 1
assert listed["data"][0]["id"] == "agent-list"
assert listed["data"][0]["app_id"] == "app-list"
assert listed["data"][0]["debug_conversation_id"] == "debug-conversation-list"
assert listed["data"][0]["role"] == "List role"
assert listed["data"][0]["active_config_is_published"] is False
assert listed["data"][0]["published_reference_count"] == 1
@@ -296,6 +305,7 @@ def test_agent_app_list_and_create_use_agent_route(
assert status == 201
assert created["id"] == "agent-created"
assert created["app_id"] == "app-created"
assert created["debug_conversation_id"] == "debug-conversation-created"
assert created["role"] == "Created role"
assert created["active_config_is_published"] is False
assert "bound_agent_id" not in created
@@ -336,7 +346,12 @@ def test_agent_app_detail_update_delete_resolve_app_from_agent_id(
monkeypatch.setattr(
roster_controller.AgentRosterService,
"get_app_backing_agent",
lambda _self, **kwargs: SimpleNamespace(id=agent_id, role="Resolved role", active_config_snapshot_id=None),
lambda _self, **kwargs: SimpleNamespace(
id=agent_id,
role="Resolved role",
debug_conversation_id="debug-conversation-detail",
active_config_snapshot_id=None,
),
)
monkeypatch.setattr(
roster_controller.FeatureService,
@@ -361,6 +376,7 @@ def test_agent_app_detail_update_delete_resolve_app_from_agent_id(
detail = unwrap(AgentAppApi.get)(AgentAppApi(), "tenant-1", agent_id)
assert detail["id"] == agent_id
assert detail["app_id"] == "app-1"
assert detail["debug_conversation_id"] == "debug-conversation-detail"
assert detail["role"] == "Resolved role"
assert detail["active_config_is_published"] is False
assert "bound_agent_id" not in detail
@@ -374,6 +390,7 @@ def test_agent_app_detail_update_delete_resolve_app_from_agent_id(
assert updated["name"] == "Renamed"
assert updated["id"] == agent_id
assert updated["app_id"] == "app-1"
assert updated["debug_conversation_id"] == "debug-conversation-detail"
assert updated["role"] == "Resolved role"
assert updated["active_config_is_published"] is False
assert "bound_agent_id" not in updated
@@ -445,7 +462,12 @@ def test_agent_app_update_rejects_empty_role(app: Flask, monkeypatch: pytest.Mon
monkeypatch.setattr(
roster_controller.AgentRosterService,
"get_app_backing_agent",
lambda _self, **kwargs: SimpleNamespace(id=agent_id, role="", active_config_snapshot_id=None),
lambda _self, **kwargs: SimpleNamespace(
id=agent_id,
role="",
debug_conversation_id="debug-conversation-detail",
active_config_snapshot_id=None,
),
)
monkeypatch.setattr(
roster_controller.FeatureService,
@@ -23,7 +23,8 @@ from models.agent_config_entities import (
DeclaredOutputType,
WorkflowNodeJobConfig,
)
from models.model import IconType
from models.enums import ConversationFromSource, ConversationStatus
from models.model import Conversation, IconType
from models.workflow import Workflow
from services.agent import composer_service, roster_service
from services.agent.agent_soul_state import agent_soul_has_model
@@ -1353,6 +1354,7 @@ class TestAgentAppBackingAgent:
assert agent.agent_kind == AgentKind.DIFY_AGENT
assert agent.name == "Iris"
assert agent.role == "research assistant"
assert agent.debug_conversation_id is not None
# A v1 snapshot + revision are seeded and wired as the active version.
snapshots = [a for a in session.added if isinstance(a, AgentConfigSnapshot)]
assert len(snapshots) == 1
@@ -1362,6 +1364,14 @@ class TestAgentAppBackingAgent:
a for a in session.added if getattr(a, "operation", None) == AgentConfigRevisionOperation.CREATE_VERSION
]
assert len(revisions) == 1
conversations = [a for a in session.added if isinstance(a, Conversation)]
assert len(conversations) == 1
assert agent.debug_conversation_id == conversations[0].id
assert conversations[0].app_id == "app-1"
assert conversations[0].mode == "agent"
assert conversations[0].status == ConversationStatus.NORMAL
assert conversations[0].from_source == ConversationFromSource.CONSOLE
assert conversations[0].from_account_id == "account-1"
# Caller (AppService.create_app) owns the commit — helper must not commit.
assert session.commits == 0