From cf72b4a8470ad42b47a61afa081f5b1191cdd7df Mon Sep 17 00:00:00 2001 From: mac Date: Mon, 7 Sep 2026 01:58:55 +0800 Subject: [PATCH 1/4] test(bot): realign unit tests with retention and compile prompt changes The bot suites have not run in CI, so they drifted silently against main: - compact-hook tests: commit_session now sends turn-budget retention kwargs (retention_mode/keep_recent_turn_count/...); fakes recorded only the dead physical-message keep_recent_count. Record the full retention contract and migrate configs to commit_keep_recent_turn_count (commit_keep_recent_count is the deprecated field). - agent-loop tests: token_usage now includes cache_read_input_tokens and the pre-model hook receives keep_recent_turn_count instead of keep_recent_count; align expectations and configs. - compile prompt test: the checkout rule now states Compile 'scans and validates the complete tree' instead of 'commits only validated changes'. - legacy workspace test: hardcoded 2026-08-20 timestamps crossed the 2-day STALE_SESSION_THRESHOLD window, so the session was skipped; derive timestamps relative to now. No production code changed. Full suite: 531 passed. --- bot/tests/test_agent_loop_outcome.py | 19 +-- bot/tests/test_compile.py | 2 +- bot/tests/test_openviking_api_key_type.py | 146 ++++++++++++++++++---- bot/tests/test_session_portable_paths.py | 8 +- 4 files changed, 138 insertions(+), 37 deletions(-) diff --git a/bot/tests/test_agent_loop_outcome.py b/bot/tests/test_agent_loop_outcome.py index 7b8f1780684..447f757f1f5 100644 --- a/bot/tests/test_agent_loop_outcome.py +++ b/bot/tests/test_agent_loop_outcome.py @@ -616,7 +616,12 @@ async def execute(self, tool_name, arguments, **kwargs): "tool result: useful context", "tool result: useful context", ] - assert token_usage == {"prompt_tokens": 17, "completion_tokens": 7, "total_tokens": 24} + assert token_usage == { + "prompt_tokens": 17, + "completion_tokens": 7, + "total_tokens": 24, + "cache_read_input_tokens": 0, + } @pytest.mark.asyncio @@ -643,7 +648,7 @@ async def fake_run_agent_loop(self, **kwargs): agents={ "session_context_enabled": True, "commit_token_threshold": 1, - "commit_keep_recent_count": 0, + "commit_keep_recent_turn_count": 0, }, ) loop = AgentLoop( @@ -1031,7 +1036,7 @@ async def fake_execute_hooks(context, **kwargs): ( "hook", kwargs["force_commit"], - kwargs.get("keep_recent_count"), + kwargs.get("keep_recent_turn_count"), kwargs.get("commit_message_threshold"), ) ) @@ -1078,7 +1083,7 @@ async def fake_run_agent_loop(self, **kwargs): "session_context_enabled": True, "session_context_token_budget": 321, "commit_token_threshold": 100, - "commit_keep_recent_count": 2, + "commit_keep_recent_turn_count": 2, }, ) loop = AgentLoop( @@ -1137,7 +1142,7 @@ async def fake_execute_hooks(context, **kwargs): ( "hook", kwargs["force_commit"], - kwargs.get("keep_recent_count"), + kwargs.get("keep_recent_turn_count"), kwargs.get("commit_message_threshold"), ) ) @@ -1182,7 +1187,7 @@ async def fake_run_agent_loop(self, **kwargs): "session_context_enabled": True, "session_context_token_budget": 321, "commit_token_threshold": 1000, - "commit_keep_recent_count": 2, + "commit_keep_recent_turn_count": 2, }, ) loop = AgentLoop( @@ -1249,7 +1254,7 @@ async def fake_execute_hooks(context, **kwargs): agents={ "session_context_enabled": True, "commit_token_threshold": 1000, - "commit_keep_recent_count": 2, + "commit_keep_recent_turn_count": 2, }, ) loop = AgentLoop( diff --git a/bot/tests/test_compile.py b/bot/tests/test_compile.py index facc5bfa6ff..e5105959678 100644 --- a/bot/tests/test_compile.py +++ b/bot/tests/test_compile.py @@ -2184,7 +2184,7 @@ def test_compile_prompt_describes_editable_target_checkout(): assert "update existing files in place" in system assert "submit_wiki_bundle with no arguments" in system assert "complete UTF-8 OKF Markdown file" in system - assert "commits only validated changes" in system + assert "scans and validates the complete tree" in system assert "Inspect the editable target checkout" in user diff --git a/bot/tests/test_openviking_api_key_type.py b/bot/tests/test_openviking_api_key_type.py index d9fb0c7b891..2e98621c135 100644 --- a/bot/tests/test_openviking_api_key_type.py +++ b/bot/tests/test_openviking_api_key_type.py @@ -71,7 +71,13 @@ async def get_session(self, session_id): async def batch_add_messages(self, session_id, messages): return {"session_id": session_id, "added": len(messages), "message_count": len(messages)} - async def commit_session(self, session_id, keep_recent_count=0, telemetry=False): + async def commit_session( + self, + session_id, + keep_recent_count=0, + telemetry=False, + **_retention_kwargs, + ): return { "session_id": session_id, "status": "committed", @@ -129,6 +135,7 @@ def _make_config(api_key_type: str, mode: str = "remote", **ov_overrides): "session_context_token_budget": 12000, "commit_token_threshold": 6000, "commit_keep_recent_count": 10, + "commit_keep_recent_turn_count": 3, } agent_overrides = {} for key in tuple(agent_defaults): @@ -1195,7 +1202,7 @@ async def test_compact_hook_session_context_commits_single_session_with_peer_mes "root", session_context_enabled=True, commit_token_threshold=100, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1238,7 +1245,14 @@ async def commit_session( user_id=None, **_retention_kwargs, ): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) return {"session_id": session_id, "status": "accepted"} fake_client = _FakeClient() @@ -1284,7 +1298,7 @@ async def _fake_get_client(_workspace_id): "admin", ) ] - assert fake_client.commit_calls == [(storage_session_id, 0, "admin")] + assert fake_client.commit_calls == [(storage_session_id, "turn_budget", 2, "admin")] assert {session_id for session_id, _user_id in fake_client.session_calls} == { storage_session_id } @@ -1346,7 +1360,7 @@ async def test_compact_hook_force_commit_does_not_resync_already_synced_messages "root", session_context_enabled=True, commit_token_threshold=100, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1371,8 +1385,21 @@ async def append_messages( async def get_session(self, session_id, user_id=None): return {"session_id": session_id, "pending_tokens": 120} - async def commit_session(self, session_id, keep_recent_count=0, user_id=None): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + async def commit_session( + self, + session_id, + keep_recent_count=0, + user_id=None, + **_retention_kwargs, + ): + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) return {"session_id": session_id, "status": "accepted"} fake_client = _FakeClient() @@ -1406,7 +1433,7 @@ async def _fake_get_client(_workspace_id): assert result["success"] is True assert fake_client.append_calls == [("cli__default__chat-1", ["new reply"])] - assert fake_client.commit_calls == [("cli__default__chat-1", 2, "admin")] + assert fake_client.commit_calls == [("cli__default__chat-1", "turn_budget", 2, "admin")] assert session.metadata["openviking"]["last_synced_local_index"] == 1 assert session.metadata["openviking"]["last_commit_local_index"] == 1 @@ -1424,7 +1451,7 @@ async def test_compact_hook_force_commit_commits_current_session_without_unsynce "root", session_context_enabled=True, commit_token_threshold=1000, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1449,8 +1476,21 @@ async def append_messages( async def get_session(self, session_id, user_id=None): return {"session_id": session_id, "pending_tokens": 120} - async def commit_session(self, session_id, keep_recent_count=0, user_id=None): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + async def commit_session( + self, + session_id, + keep_recent_count=0, + user_id=None, + **_retention_kwargs, + ): + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) return {"session_id": session_id, "status": "accepted"} fake_client = _FakeClient() @@ -1484,7 +1524,7 @@ async def _fake_get_client(_workspace_id): assert result["success"] is True assert fake_client.append_calls == [] - assert fake_client.commit_calls == [("cli__default__chat-1", 2, "admin")] + assert fake_client.commit_calls == [("cli__default__chat-1", "turn_budget", 2, "admin")] assert session.metadata["openviking"]["last_commit_performed"] is True @@ -1501,7 +1541,7 @@ async def test_compact_hook_session_context_append_failure_does_not_advance_sync "root", session_context_enabled=True, commit_token_threshold=100, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1528,8 +1568,21 @@ async def append_messages( async def get_session(self, session_id, user_id=None): return {"session_id": session_id, "pending_tokens": 120} - async def commit_session(self, session_id, keep_recent_count=0, user_id=None): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + async def commit_session( + self, + session_id, + keep_recent_count=0, + user_id=None, + **_retention_kwargs, + ): + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) return {"session_id": session_id, "status": "accepted"} fake_client = _FakeClient() @@ -1581,7 +1634,7 @@ async def test_compact_hook_session_context_commits_when_message_threshold_reach "root", session_context_enabled=True, commit_token_threshold=1000, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1606,8 +1659,21 @@ async def append_messages( async def get_session(self, session_id, user_id=None): return {"session_id": session_id, "pending_tokens": 0} - async def commit_session(self, session_id, keep_recent_count=0, user_id=None): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + async def commit_session( + self, + session_id, + keep_recent_count=0, + user_id=None, + **_retention_kwargs, + ): + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) return {"session_id": session_id, "status": "accepted"} fake_client = _FakeClient() @@ -1644,7 +1710,7 @@ async def _fake_get_client(_workspace_id): assert result["success"] is True assert result["admin_result"]["committed"] is True assert fake_client.append_calls == [("cli__default__chat-1", ["m3"])] - assert fake_client.commit_calls == [("cli__default__chat-1", 2, "admin")] + assert fake_client.commit_calls == [("cli__default__chat-1", "turn_budget", 2, "admin")] assert session.metadata["openviking"]["last_commit_local_index"] == 2 @@ -1661,7 +1727,7 @@ async def test_compact_hook_session_commit_failure_retries_without_resyncing_mes "root", session_context_enabled=True, commit_token_threshold=100, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1687,8 +1753,21 @@ async def append_messages( async def get_session(self, session_id, user_id=None): return {"session_id": session_id, "pending_tokens": 120} - async def commit_session(self, session_id, keep_recent_count=0, user_id=None): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + async def commit_session( + self, + session_id, + keep_recent_count=0, + user_id=None, + **_retention_kwargs, + ): + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) if session_id == "cli__default__chat-1" and self.fail_session_commit: raise RuntimeError("session commit failed") return {"session_id": session_id, "status": "accepted"} @@ -1719,7 +1798,7 @@ async def _fake_get_client(_workspace_id): assert first["success"] is False assert "session commit failed" in first["error"] assert fake_client.append_calls == [("cli__default__chat-1", ["u1 asks", "u1 reply"])] - assert fake_client.commit_calls == [("cli__default__chat-1", 2, "admin")] + assert fake_client.commit_calls == [("cli__default__chat-1", "turn_budget", 2, "admin")] state = session.metadata["openviking"] assert state["last_sync_status"] == "error" assert state["last_synced_local_index"] == 1 @@ -1733,7 +1812,7 @@ async def _fake_get_client(_workspace_id): assert second["success"] is True assert fake_client.append_calls == [] - assert fake_client.commit_calls == [("cli__default__chat-1", 2, "admin")] + assert fake_client.commit_calls == [("cli__default__chat-1", "turn_budget", 2, "admin")] assert session.metadata["openviking"]["last_commit_performed"] is True @@ -1750,7 +1829,7 @@ async def test_compact_hook_session_context_skips_message_threshold_after_recent "root", session_context_enabled=True, commit_token_threshold=1000, - commit_keep_recent_count=2, + commit_keep_recent_turn_count=2, ), ) @@ -1775,8 +1854,21 @@ async def append_messages( async def get_session(self, session_id, user_id=None): return {"session_id": session_id, "pending_tokens": 0} - async def commit_session(self, session_id, keep_recent_count=0, user_id=None): - self.commit_calls.append((session_id, keep_recent_count, user_id)) + async def commit_session( + self, + session_id, + keep_recent_count=0, + user_id=None, + **_retention_kwargs, + ): + self.commit_calls.append( + ( + session_id, + _retention_kwargs.get("retention_mode"), + _retention_kwargs.get("keep_recent_turn_count"), + user_id, + ) + ) return {"session_id": session_id, "status": "accepted"} fake_client = _FakeClient() diff --git a/bot/tests/test_session_portable_paths.py b/bot/tests/test_session_portable_paths.py index d45f4ab3908..ac2611d5e3a 100644 --- a/bot/tests/test_session_portable_paths.py +++ b/bot/tests/test_session_portable_paths.py @@ -4,6 +4,7 @@ import json import os import unicodedata +from datetime import datetime, timedelta, timezone from pathlib import Path from types import SimpleNamespace @@ -310,12 +311,15 @@ def test_sandbox_and_heartbeat_reuse_existing_legacy_workspace(tmp_path): assert sandbox_manager.to_workspace_id(key) == legacy_name assert sandbox_manager.get_workspace_path(key) == legacy_path + # Recent timestamps so the session never crosses the heartbeat staleness + # window (STALE_SESSION_THRESHOLD) no matter when the suite runs. + last_active = datetime.now(timezone.utc) - timedelta(minutes=5) session_manager = SimpleNamespace( list_sessions=lambda: [ { "key": key, - "created_at": "2026-08-20T00:00:00", - "updated_at": "2026-08-20T00:00:01", + "created_at": last_active.isoformat(), + "updated_at": last_active.isoformat(), "metadata": {}, } ] From b788c04c39d9f025116f69e199f27e9ce254c070 Mon Sep 17 00:00:00 2001 From: mac Date: Mon, 7 Sep 2026 01:58:55 +0800 Subject: [PATCH 2/4] ci(bot): run the VikingBot unit suites on bot changes None of the repo workflows exercise bot/tests or bot/vikingbot, so the 531-test suite had no CI signal and drifted red unnoticed (12 stale failures at the time of this change). Add a path-gated bot-tests job to the PR workflow: it runs when bot/, the shared dependency manifests, or this workflow change, installs via 'uv sync --frozen --extra bot', and runs pytest over both bot test trees. --- .github/workflows/pr.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fa4a80025c4..e32d397752b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -101,6 +101,7 @@ jobs: deps_changed: ${{ steps.check.outputs.deps_changed }} cuvs_changed: ${{ steps.check.outputs.cuvs_changed }} langchain_changed: ${{ steps.check.outputs.langchain_changed }} + bot_changed: ${{ steps.check.outputs.bot_changed }} steps: - uses: actions/checkout@v6 with: @@ -152,6 +153,20 @@ jobs: echo "langchain_changed=false" >> $GITHUB_OUTPUT fi + # Run the VikingBot unit test suites when bot code, its dependency + # set, or this workflow change. + BOT_PATTERN="^bot/|pyproject\.toml|uv\.lock|\.github/workflows/pr\.yml" + BOT_CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }} HEAD | grep -E "$BOT_PATTERN" || true) + + if [ -n "$BOT_CHANGED_FILES" ]; then + echo "Bot changes detected:" + echo "$BOT_CHANGED_FILES" + echo "bot_changed=true" >> $GITHUB_OUTPUT + else + echo "No bot changes detected." + echo "bot_changed=false" >> $GITHUB_OUTPUT + fi + build: needs: check-deps if: ${{ needs.check-deps.outputs.deps_changed == 'true' }} @@ -165,6 +180,30 @@ jobs: os_json: '["ubuntu-24.04"]' python_json: '["3.11"]' + bot-tests: + needs: check-deps + if: ${{ needs.check-deps.outputs.bot_changed == 'true' }} + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - uses: actions/setup-python@v6 + with: + python-version: '3.12' + + - uses: astral-sh/setup-uv@v7 + with: + enable-cache: true + + - name: Install bot dependencies + run: uv sync --frozen --extra bot + + - name: Run VikingBot unit tests + run: | + uv run python -m pytest -q -o addopts='' bot/tests bot/vikingbot + langchain-tests: needs: check-deps if: ${{ needs.check-deps.outputs.langchain_changed == 'true' }} From c267be4096627989b6fb28c1b428e7e9fb0f27dd Mon Sep 17 00:00:00 2001 From: mac Date: Mon, 7 Sep 2026 02:21:22 +0800 Subject: [PATCH 3/4] ci(bot): install the test extra so pytest-asyncio is available The first bot-tests run failed 239 async tests with "async def functions are not natively supported": 'uv sync --frozen --extra bot' only provides the dev group's bare pytest, while pyproject sets asyncio_mode=auto, which requires pytest-asyncio from the test extra. Add --extra test, matching the existing pattern in _test_lite.yml. --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e32d397752b..372e68a3d1e 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -198,7 +198,7 @@ jobs: enable-cache: true - name: Install bot dependencies - run: uv sync --frozen --extra bot + run: uv sync --frozen --extra bot --extra test - name: Run VikingBot unit tests run: | From 71606f8abee43a9397dfad928e845506827b59df Mon Sep 17 00:00:00 2001 From: mac Date: Mon, 7 Sep 2026 04:52:08 +0800 Subject: [PATCH 4/4] ci: retrigger integration run after known test_fs_cp path-busy flake