代码修改
This commit is contained in:
1 parent
b60d9ed09e
commit
1d07025f74
9 files changed
+337
-53
No files matched your search
@@ -27,6 +27,14 @@ async def store(tmp_path):
|
||||
return PositionRoundtableRepository(async_sessionmaker(engine, expire_on_commit=False))
|
||||
|
||||
|
||||
def test_reject_node_request_allows_an_optional_reason():
|
||||
"""A rejection must work even when the reviewer leaves the reason blank."""
|
||||
request = position_roundtable_router.RejectNodeRequest()
|
||||
|
||||
assert request.title == "产物驳回"
|
||||
assert request.reason == ""
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_activation_freezes_chain_and_creates_nodes_once(store):
|
||||
created = await store.create_session(
|
||||
@@ -186,6 +194,122 @@ def test_all_nodes_delivered_requires_markdown_for_non_intent_nodes():
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_builtin_markdown_fallback_writes_visible_summary_to_thread_outputs(tmp_path, monkeypatch):
|
||||
target = tmp_path / "outputs" / "岗位会商方案总结报告.md"
|
||||
|
||||
async def resolve(thread_id: str, path: str):
|
||||
assert thread_id == "summary-thread"
|
||||
assert path == "mnt/user-data/outputs/岗位会商方案总结报告.md"
|
||||
return target
|
||||
|
||||
monkeypatch.setattr(position_roundtable_router, "aresolve_thread_virtual_path", resolve)
|
||||
|
||||
artifact = await position_roundtable_router._write_builtin_markdown_fallback(
|
||||
thread_id="summary-thread",
|
||||
kind="summary",
|
||||
content="# 岗位会商方案总结报告\n\n这是对话中生成的完整报告正文。",
|
||||
)
|
||||
|
||||
assert target.read_text(encoding="utf-8") == "# 岗位会商方案总结报告\n\n这是对话中生成的完整报告正文。\n"
|
||||
assert artifact["name"] == "岗位会商方案总结报告.md"
|
||||
assert artifact["path"] == "mnt/user-data/outputs/岗位会商方案总结报告.md"
|
||||
assert artifact["mime_type"] == "text/markdown"
|
||||
assert artifact["size_bytes"] == target.stat().st_size
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_builtin_summary_completion_persists_fallback_markdown_when_agent_skips_write_file(monkeypatch):
|
||||
node = {
|
||||
"id": "node-1",
|
||||
"session_id": "session-a",
|
||||
"node_key": "intent-node",
|
||||
"stage_index": 0,
|
||||
"seat_index": 0,
|
||||
"agent_id": "intent-agent",
|
||||
"position_id": "intelligence",
|
||||
"thread_id": "intent-thread",
|
||||
"status": "done",
|
||||
"latest_answer": "已确认任务意图",
|
||||
"artifact_manifest": [],
|
||||
"revision": 1,
|
||||
"upstream_revision": None,
|
||||
"rejection_count": 0,
|
||||
"last_rejection": None,
|
||||
"invalidated_by": None,
|
||||
}
|
||||
session = {
|
||||
"id": "session-a",
|
||||
"status": "active",
|
||||
"task_snapshot": {},
|
||||
"chain_id": "chain-a",
|
||||
"chain_snapshot": {},
|
||||
"intent_thread_id": "intent-thread",
|
||||
"intent_snapshot": {"objective": "形成方案", "constraints": []},
|
||||
"summary_thread_id": None,
|
||||
"summary_snapshot": None,
|
||||
"action_plan_thread_id": None,
|
||||
"action_plan_snapshot": None,
|
||||
}
|
||||
|
||||
class StubStore:
|
||||
updates: dict | None = None
|
||||
|
||||
async def get_session(self, session_id, user_id):
|
||||
assert (session_id, user_id) == ("session-a", "user-a")
|
||||
return session
|
||||
|
||||
async def list_nodes(self, session_id, user_id):
|
||||
assert (session_id, user_id) == ("session-a", "user-a")
|
||||
return [node]
|
||||
|
||||
async def update_session(self, session_id, user_id, **updates):
|
||||
assert (session_id, user_id) == ("session-a", "user-a")
|
||||
self.updates = updates
|
||||
return {**session, **updates}
|
||||
|
||||
store = StubStore()
|
||||
|
||||
async def write_fallback(**kwargs):
|
||||
assert kwargs["thread_id"] == "summary-thread"
|
||||
assert kwargs["kind"] == "summary"
|
||||
assert kwargs["content"] == "# 方案总结\n\n完整报告正文"
|
||||
return {
|
||||
"name": "岗位会商方案总结报告.md",
|
||||
"path": "mnt/user-data/outputs/岗位会商方案总结报告.md",
|
||||
"mime_type": "text/markdown",
|
||||
"modified_at": "2026-07-23T00:00:00+00:00",
|
||||
"size_bytes": 42,
|
||||
}
|
||||
|
||||
monkeypatch.setattr(position_roundtable_router, "_write_builtin_markdown_fallback", write_fallback)
|
||||
request = SimpleNamespace(
|
||||
app=SimpleNamespace(state=SimpleNamespace(position_roundtable_store=store)),
|
||||
state=SimpleNamespace(user=SimpleNamespace(id="user-a")),
|
||||
)
|
||||
body = position_roundtable_router.CompleteBuiltinRunRequest(
|
||||
thread_id="summary-thread",
|
||||
content="# 方案总结\n\n完整报告正文",
|
||||
artifact_manifest=[],
|
||||
source_revisions={"intent-node": 1},
|
||||
)
|
||||
|
||||
result = await position_roundtable_router._complete_builtin_run(
|
||||
request,
|
||||
"session-a",
|
||||
kind="summary",
|
||||
body=body,
|
||||
)
|
||||
|
||||
assert store.updates is not None
|
||||
snapshot = store.updates["summary_snapshot"]
|
||||
assert snapshot["content"] == "# 方案总结\n\n完整报告正文"
|
||||
assert snapshot["primary_artifact"]["name"] == "岗位会商方案总结报告.md"
|
||||
assert result.summary_snapshot["primary_artifact"]["path"] == (
|
||||
"mnt/user-data/outputs/岗位会商方案总结报告.md"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_node_updates_are_user_scoped_and_keep_thread_out_of_messages(store):
|
||||
created = await store.create_session("user-a", external_task_id=None, task_snapshot={})
|
||||
|
||||
Reference in new issue
Block a user