From 982fcb4bc34a9c06aa4c7998e58070d9eab5bae6 Mon Sep 17 00:00:00 2001 From: test Date: Mon, 24 Aug 2026 02:36:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?test:=20=E6=98=BE=E5=BC=8F=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=20Steam=20fixture=20=E8=A7=A3=E9=87=8A=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/plugin-api-v3.yml | 1 + tests/test_manager_integration.py | 34 ++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/plugin-api-v3.yml b/.github/workflows/plugin-api-v3.yml index 404767a..5962e90 100644 --- a/.github/workflows/plugin-api-v3.yml +++ b/.github/workflows/plugin-api-v3.yml @@ -55,6 +55,7 @@ jobs: - name: Verify Steam v3 composition and migration env: AKASHIC_AGENT_ROOT: .akashic-core + AKASHIC_PLUGIN_FIXTURE_PYTHON: ${{ github.workspace }}/mcp/.venv/bin/python PYTHONPATH: .akashic-core:mcp:mcp/.venv/lib/python3.13/site-packages run: mcp/.venv/bin/python -m pytest -q mcp/tests tests - name: Check changed v3 sources diff --git a/tests/test_manager_integration.py b/tests/test_manager_integration.py index 7069c08..ba8486f 100644 --- a/tests/test_manager_integration.py +++ b/tests/test_manager_integration.py @@ -3,9 +3,9 @@ import asyncio import hashlib import json +import os import shutil import sqlite3 -import sys from datetime import UTC, datetime from pathlib import Path @@ -71,8 +71,9 @@ async def _eventually(predicate) -> None: def _stage_plugin(tmp_path: Path) -> Path: - """复制真实 Steam 插件并复用当前测试解释器。""" + """复制真实 Steam 插件并链接调用方声明的 artifact 运行时。""" + runtime = Path(os.environ["AKASHIC_PLUGIN_FIXTURE_PYTHON"]).parent.parent source = tmp_path / "plugins" / "steam" shutil.copytree( ROOT, @@ -87,11 +88,38 @@ def _stage_plugin(tmp_path: Path) -> Path: "tests", ), ) - runtime = Path(sys.executable).parent.parent (source / "mcp" / ".venv").symlink_to(runtime, target_is_directory=True) return source +def test_stage_plugin_links_declared_fixture_runtime( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, +) -> None: + runtime = tmp_path / "artifact" / ".venv" + fixture_python = runtime / "bin" / "python" + fixture_python.parent.mkdir(parents=True) + fixture_python.touch() + monkeypatch.setenv("AKASHIC_PLUGIN_FIXTURE_PYTHON", str(fixture_python)) + + source = _stage_plugin(tmp_path) + + assert (source / "mcp" / ".venv").readlink() == runtime + + +def test_stage_plugin_requires_fixture_python( + tmp_path: Path, + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.delenv("AKASHIC_PLUGIN_FIXTURE_PYTHON", raising=False) + + with pytest.raises(KeyError) as error: + _stage_plugin(tmp_path) + + assert error.value.args == ("AKASHIC_PLUGIN_FIXTURE_PYTHON",) + assert not (tmp_path / "plugins").exists() + + def _config(data_root: Path) -> Path: data_root.mkdir(parents=True, exist_ok=True) path = data_root / "steam_mcp_config.json" From 4eeebbc7b8c0f6299ab8d86a998b2c86f7ef6183 Mon Sep 17 00:00:00 2001 From: test Date: Mon, 24 Aug 2026 20:46:58 +0800 Subject: [PATCH 2/2] fix: load Steam runtime as a package --- context_source.py | 2 +- plugin.py | 2 +- steam_runtime/backend.py | 2 +- tests/conftest.py | 12 ++++++++++++ tests/test_context_source.py | 4 ++-- tests/test_plugin.py | 2 +- 6 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 tests/conftest.py diff --git a/context_source.py b/context_source.py index 8f66d19..15d72a4 100644 --- a/context_source.py +++ b/context_source.py @@ -12,7 +12,7 @@ from agent.lifecycle.types import BeforeTurnCtx from agent.plugin_composition import HealthHandle, PluginTimers -from steam_runtime import backend +from .steam_runtime import backend class SteamContextRuntime: diff --git a/plugin.py b/plugin.py index 7ed254e..3f4a1a0 100644 --- a/plugin.py +++ b/plugin.py @@ -12,7 +12,7 @@ McpServerDefinition, ) -from context_source import SteamContextRuntime +from .context_source import SteamContextRuntime class SteamConfig(BaseModel): diff --git a/steam_runtime/backend.py b/steam_runtime/backend.py index 409d34d..394e461 100644 --- a/steam_runtime/backend.py +++ b/steam_runtime/backend.py @@ -12,7 +12,7 @@ from urllib.parse import urlencode from urllib.request import urlopen -from steam_runtime.config import SteamRuntimeConfig, load_runtime_config +from .config import SteamRuntimeConfig, load_runtime_config _DB_NAME = "steam_proactive.sqlite3" diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..be3139c --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +import sys +from pathlib import Path +from types import ModuleType + + +repo_root = Path(__file__).resolve().parents[1] +package = ModuleType("steam_test_plugin") +package.__path__ = [str(repo_root)] +package.__package__ = "steam_test_plugin" +sys.modules["steam_test_plugin"] = package diff --git a/tests/test_context_source.py b/tests/test_context_source.py index e1600e1..91e9d4d 100644 --- a/tests/test_context_source.py +++ b/tests/test_context_source.py @@ -11,8 +11,8 @@ from agent.control.timer import TimerReceipt, TimerStatus from agent.lifecycle.types import BeforeTurnCtx from agent.plugin_composition import PluginTimers -from context_source import SteamContextRuntime -from steam_runtime import backend +from steam_test_plugin.context_source import SteamContextRuntime # pyright: ignore[reportMissingImports] +from steam_test_plugin.steam_runtime import backend # pyright: ignore[reportMissingImports] class _TimerHandle: diff --git a/tests/test_plugin.py b/tests/test_plugin.py index dfbbe5c..2f0af97 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -4,8 +4,8 @@ from pathlib import Path from typing import cast -import plugin import pytest +from steam_test_plugin import plugin # pyright: ignore[reportMissingImports] from agent.control.timer import OneShotTimer from agent.plugin_composition import ( MCP_SERVERS,