JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(ut): 修复补充兼容测试与技能刷新竞态
wangjiudongf6190956bca1
diff --git a/jiuwenswarm/agents/harness/flash/skill_selection/service.py b/jiuwenswarm/agents/harness/flash/skill_selection/service.pyindex 29b40ecf46..4803beca35 100644--- a/jiuwenswarm/agents/harness/flash/skill_selection/service.py+++ b/jiuwenswarm/agents/harness/flash/skill_selection/service.py@@ -229,7 +229,15 @@ class SelectionService:else:build = self._buildwhile True:- await asyncio.shield(asyncio.wrap_future(build))+ try:+ await asyncio.shield(asyncio.wrap_future(build))+ except SelectionBusy:+ # A forced refresh may already supersede a failed installation+ # snapshot. Follow that build; keep unrecovered failures visible.+ self._after_build(build)+ with self._lock:+ if self._build is None and self._error is not None:+ raiseself._after_build(build)with self._lock:if self.retired:diff --git a/tests/transport/test_dispatch_matrix.py b/tests/transport/test_dispatch_matrix.pyindex 9cebfbacd1..ade0abb219 100644--- a/tests/transport/test_dispatch_matrix.py+++ b/tests/transport/test_dispatch_matrix.py@@ -47,7 +47,8 @@ class _Req:_DISPATCH_TABLE_METHODS = frozenset({"AGENTS_CREATE", "AGENTS_DELETE", "AGENTS_DISABLE", "AGENTS_ENABLE", "AGENTS_GET","AGENTS_LIST", "AGENTS_TOOLS_LIST", "AGENTS_UPDATE", "AGENT_PREWARM_SYNC",- "AGENT_RELOAD_CONFIG", "BROWSER_RUNTIME_RESTART", "CHAT_CANCEL", "COMMAND_ADD_DIR",+ "AGENT_RELOAD_CONFIG", "BROWSER_RUNTIME_RESTART", "CHAT_CANCEL",+ "CHAT_STEER", "CHAT_STEER_STATUS", "COMMAND_ADD_DIR","COMMAND_BTW", "COMMAND_CHROME", "COMMAND_COMPACT", "COMMAND_COMPACT_PARTIAL","COMMAND_CONTEXT", "COMMAND_DIFF", "COMMAND_MCP", "MCP_SERVER_ADD","MCP_SERVER_GET", "MCP_SERVER_LIST", "MCP_SERVER_REMOVE", "MCP_SERVER_UPDATE",diff --git a/tests/unit_tests/agentserver/test_chat_steering_core_integration.py b/tests/unit_tests/agentserver/test_chat_steering_core_integration.pyindex 2b80178f00..391fc34fe3 100644--- a/tests/unit_tests/agentserver/test_chat_steering_core_integration.py+++ b/tests/unit_tests/agentserver/test_chat_steering_core_integration.py@@ -8,6 +8,7 @@ normal single-agent streaming, steering dispatch, binding and Core are real.from __future__ import annotationsimport asyncio+from importlib.util import find_specimport uuidfrom types import SimpleNamespacefrom unittest.mock import AsyncMock@@ -36,6 +37,11 @@ from jiuwenswarm.server.runtime.agent_adapter.interface_deep import ()+# The locked official SDK predates steering. Check the independent schema+# marker so a broken capability implementation in a newer SDK still fails.+_CORE_HAS_STEERING = find_spec("openjiuwen.core.single_agent.schema.steering") is not None++class _BlockingTool(Tool):def __init__(self):super().__init__(ToolCard(name="blocked_tool", description="Wait for test"))@@ -270,6 +276,29 @@ async def test_chat_pipeline_steers_real_core_during_tool_without_replacing_origreturn parse_agent_server_wire_unary(sink.wires[0])capability = await control(ReqMethod.CHAT_STEER_STATUS, input_id="")+ if not _CORE_HAS_STEERING:+ assert capability.payload["supported"] is False+ assert capability.payload["reason"] == "STEER_UNSUPPORTED"+ rejected = await control(ReqMethod.CHAT_STEER, content="legacy correction")+ assert not rejected.ok+ assert rejected.payload["reason"] == "STEER_UNSUPPORTED"+ assert not main_task.done()+ assert core.active_round.task_id == active_task+ assert core._interaction_output.current_lease() is owner+ assert len(model.calls) == tool.calls == 1+ tool.release.set()+ await asyncio.wait_for(main_task, 15)+ assert len(model.calls) == 2 and tool.calls == 1+ assert original_sink.chunks and not original_sink.wires+ assert all(chunk.request_id == original.request_id for chunk in original_sink.chunks)+ assert any("Corrected original task result" in str(chunk.payload)+ for chunk in original_sink.chunks)+ assert not any(isinstance(chunk.payload, dict)+ and chunk.payload.get("event_type") == "chat.steering_consumed"+ for chunk in original_sink.chunks)+ assert not any("legacy correction" in str(message.content)+ for message in model.calls[1])+ returnassert capability.payload["supported"] is Truefirst = await control(ReqMethod.CHAT_STEER, content="Only analyse East China")duplicate = await control(@@ -376,7 +405,7 @@ async def test_team_adapter_controls_real_native_leader_with_literal_fifo_inputsasync def model_stream(messages, **kwargs):calls.append(list(messages))- round_handles.append(core.get_active_steering_request_id())+ round_handles.append(core.active_round.task_id)if len(calls) == 1:entered.set()await release.wait()@@ -471,7 +500,7 @@ async def test_team_adapter_controls_real_native_leader_with_literal_fifo_inputsmain_task = asyncio.create_task(consume())await asyncio.wait_for(entered.wait(), 10)- native_handle = leader.get_active_steering_request_id()+ native_handle = core.active_round.task_idassert native_handle and native_handle != original.request_idoutput_queue = core._st.output_queue# After initial send, strict controls may not start, abort or resume a round.@@ -520,6 +549,29 @@ async def test_team_adapter_controls_real_native_leader_with_literal_fifo_inputsreturn responsecapability = await control(ReqMethod.CHAT_STEER_STATUS, input_id="")+ if not _CORE_HAS_STEERING:+ assert capability.payload["supported"] is False+ assert capability.payload["reason"] == "STEER_UNSUPPORTED"+ rejected = await control(ReqMethod.CHAT_STEER, content="legacy correction")+ assert not rejected.ok+ assert rejected.payload["reason"] == "STEER_UNSUPPORTED"+ assert core.active_round.task_id == native_handle+ assert core._st.output_queue is output_queue+ assert not main_task.done() and len(calls) == 1+ existing_pool.get.assert_awaited_with("active-team")+ release.set()+ await asyncio.wait_for(finished.wait(), 10)+ assert len(calls) == 1 and round_handles == [native_handle]+ send_spy.assert_not_awaited()+ abort_spy.assert_not_awaited()+ resume_spy.assert_not_awaited()+ await harness.stop()+ await asyncio.wait_for(main_task, 10)+ assert any("old answer" in str(chunk.payload) for chunk in outputs)+ assert all(chunk.request_id == original.request_id for chunk in outputs)+ assert not any("legacy correction" in str(message.content)+ for message in calls[0])+ returnassert capability.payload["supported"] is Trueassert capability.payload["target"] == "team_leader"first_text, second_text = (diff --git a/tests/unit_tests/agentserver/test_flash_skill_selection.py b/tests/unit_tests/agentserver/test_flash_skill_selection.pyindex 2139175fb8..c9947428a0 100644--- a/tests/unit_tests/agentserver/test_flash_skill_selection.py+++ b/tests/unit_tests/agentserver/test_flash_skill_selection.py@@ -1116,6 +1116,55 @@ async def test_search_serves_snapshot_while_background_check_runs(harness, monkeawait svc.current_snapshot()[email protected]("force_refresh", [False, True])+async def test_snapshot_handles_failed_build_with_pending_refresh(tmp_path, monkeypatch, force_refresh):+ """A waiter follows the forced replacement, but an unrecovered failure stays visible."""+ import threading++ root = tmp_path / "skills"+ root.mkdir()+ write_skill(root, "slides")+ svc = service.SelectionService((root,), SelectionSettings())+ prepare = svc._prepare_checked+ entered, release = threading.Event(), threading.Event()+ attempts = 0++ def interrupted_install(*args):+ nonlocal attempts+ attempts += 1+ if attempts == 1:+ entered.set()+ assert release.wait(timeout=5)+ raise execution.SelectionBusy("Skill files are changing")+ return prepare(*args)++ monkeypatch.setattr(svc, "_prepare_checked", interrupted_install)+ pending = None+ try:+ svc.refresh()+ assert await asyncio.to_thread(entered.wait, 5)+ pending = asyncio.create_task(svc.current_snapshot())+ # Let the waiter capture the first build before the install completes.+ await asyncio.sleep(0)+ if force_refresh:+ write_skill(root, "installed")+ svc.refresh(force=True)+ release.set()+ if force_refresh:+ pipeline, generation = await asyncio.wait_for(pending, 5)+ assert attempts == 2 and generation == 1+ assert len(pipeline.documents) == 2+ assert svc._error is None+ else:+ with pytest.raises(execution.SelectionBusy, match="Skill files are changing"):+ await asyncio.wait_for(pending, 5)+ assert attempts == 1 and not svc._ready+ finally:+ release.set()+ if pending is not None:+ await asyncio.gather(pending, return_exceptions=True)++async def test_live_mixed_load_arguments_succeed_without_another_model_turn(harness):"""Replay the exact extra-field pattern observed in all three live tasks."""from openjiuwen.core.foundation.llm.schema.tool_call import ToolCall