From e485bc60cd9de56077a0bd219e1a4c5a95d3c956 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Mon, 20 Apr 2026 12:49:31 +0530 Subject: [PATCH] test(kimi): cover api.moonshot.cn direct-call regressions\n\n- add run_agent coverage for the Moonshot China endpoint\n- add sync/async trajectory compressor coverage for api.moonshot.cn --- tests/run_agent/test_run_agent.py | 10 ++++++++ tests/test_trajectory_compressor.py | 24 +++++++++++++++++++ tests/test_trajectory_compressor_async.py | 29 +++++++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.py index 6498bd0dd..13ecb0c4d 100644 --- a/tests/run_agent/test_run_agent.py +++ b/tests/run_agent/test_run_agent.py @@ -928,6 +928,16 @@ class TestBuildApiKwargs: assert kwargs["temperature"] == 1.0 + def test_public_moonshot_cn_kimi_k2_5_forces_temperature_1(self, agent): + agent.base_url = "https://api.moonshot.cn/v1" + agent._base_url_lower = agent.base_url.lower() + agent.model = "kimi-k2.5" + messages = [{"role": "user", "content": "hi"}] + + kwargs = agent._build_api_kwargs(messages) + + assert kwargs["temperature"] == 1.0 + def test_kimi_coding_endpoint_keeps_kimi_k2_5_at_0_6(self, agent): agent.base_url = "https://api.kimi.com/coding/v1" agent._base_url_lower = agent.base_url.lower() diff --git a/tests/test_trajectory_compressor.py b/tests/test_trajectory_compressor.py index 1332674bf..b42ca1254 100644 --- a/tests/test_trajectory_compressor.py +++ b/tests/test_trajectory_compressor.py @@ -78,6 +78,30 @@ def test_generate_summary_public_moonshot_kimi_k2_5_forces_temperature_1(): assert compressor.client.chat.completions.create.call_args.kwargs["temperature"] == 1.0 +def test_generate_summary_public_moonshot_cn_kimi_k2_5_forces_temperature_1(): + config = CompressionConfig( + summarization_model="kimi-k2.5", + base_url="https://api.moonshot.cn/v1", + temperature=0.3, + summary_target_tokens=100, + max_retries=1, + ) + compressor = TrajectoryCompressor.__new__(TrajectoryCompressor) + compressor.config = config + compressor.logger = MagicMock() + compressor._use_call_llm = False + compressor.client = MagicMock() + compressor.client.chat.completions.create.return_value = SimpleNamespace( + choices=[SimpleNamespace(message=SimpleNamespace(content="[CONTEXT SUMMARY]: summary"))] + ) + + metrics = TrajectoryMetrics() + result = compressor._generate_summary("tool output", metrics) + + assert result.startswith("[CONTEXT SUMMARY]:") + assert compressor.client.chat.completions.create.call_args.kwargs["temperature"] == 1.0 + + # --------------------------------------------------------------------------- # CompressionConfig # --------------------------------------------------------------------------- diff --git a/tests/test_trajectory_compressor_async.py b/tests/test_trajectory_compressor_async.py index 977e16ae9..028f43eff 100644 --- a/tests/test_trajectory_compressor_async.py +++ b/tests/test_trajectory_compressor_async.py @@ -169,3 +169,32 @@ async def test_generate_summary_async_public_moonshot_kimi_k2_5_forces_temperatu assert result.startswith("[CONTEXT SUMMARY]:") assert async_client.chat.completions.create.call_args.kwargs["temperature"] == 1.0 + + + +@pytest.mark.asyncio +async def test_generate_summary_async_public_moonshot_cn_kimi_k2_5_forces_temperature_1(): + from trajectory_compressor import CompressionConfig, TrajectoryCompressor, TrajectoryMetrics + + config = CompressionConfig( + summarization_model="kimi-k2.5", + base_url="https://api.moonshot.cn/v1", + temperature=0.3, + summary_target_tokens=100, + max_retries=1, + ) + compressor = TrajectoryCompressor.__new__(TrajectoryCompressor) + compressor.config = config + compressor.logger = MagicMock() + compressor._use_call_llm = False + async_client = MagicMock() + async_client.chat.completions.create = MagicMock(return_value=SimpleNamespace( + choices=[SimpleNamespace(message=SimpleNamespace(content="[CONTEXT SUMMARY]: summary"))] + )) + compressor._get_async_client = MagicMock(return_value=async_client) + + metrics = TrajectoryMetrics() + result = await compressor._generate_summary_async("tool output", metrics) + + assert result.startswith("[CONTEXT SUMMARY]:") + assert async_client.chat.completions.create.call_args.kwargs["temperature"] == 1.0