mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-15 17:30:13 +08:00
fix: preserve unicode sample fixtures in runtime tests
This commit is contained in:
@@ -187,6 +187,8 @@ class WorkerSession:
|
||||
if existing_pythonpath
|
||||
else repo_src_dir
|
||||
)
|
||||
env.setdefault("PYTHONIOENCODING", "utf-8")
|
||||
env.setdefault("PYTHONUTF8", "1")
|
||||
|
||||
transport = StdioTransport(
|
||||
command=[
|
||||
|
||||
@@ -27,15 +27,20 @@ def _is_astrbot_sdk_installed_in_site_packages() -> bool:
|
||||
|
||||
|
||||
def _astr_console_script() -> str | None:
|
||||
scripts_dir = Path(sys.executable).resolve().parent
|
||||
candidates = [
|
||||
scripts_dir / "astr",
|
||||
scripts_dir / "astr.exe",
|
||||
scripts_dir / "astr.cmd",
|
||||
]
|
||||
for candidate in candidates:
|
||||
if candidate.exists():
|
||||
return str(candidate)
|
||||
executable_dir = Path(sys.executable).resolve().parent
|
||||
search_dirs = [executable_dir]
|
||||
if executable_dir.name.lower() != "scripts":
|
||||
search_dirs.append(executable_dir / "Scripts")
|
||||
|
||||
for scripts_dir in search_dirs:
|
||||
candidates = [
|
||||
scripts_dir / "astr",
|
||||
scripts_dir / "astr.exe",
|
||||
scripts_dir / "astr.cmd",
|
||||
]
|
||||
for candidate in candidates:
|
||||
if candidate.exists():
|
||||
return str(candidate)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "v4_plugin"
|
||||
copy_sample_plugin("new", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("new", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -85,7 +85,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "v4_plugin"
|
||||
copy_sample_plugin("new", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("new", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -156,7 +156,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "v4_plugin"
|
||||
copy_sample_plugin("new", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("new", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -193,7 +193,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "v4_plugin"
|
||||
copy_sample_plugin("new", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("new", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -236,7 +236,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "v4_plugin"
|
||||
copy_sample_plugin("new", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("new", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -261,7 +261,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "compat_plugin"
|
||||
copy_sample_plugin("old", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("old", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -298,7 +298,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "compat_plugin"
|
||||
copy_sample_plugin("old", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("old", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
@@ -381,7 +381,7 @@ class RuntimeIntegrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
plugins_root = Path(temp_dir) / "plugins"
|
||||
plugin_root = plugins_root / "compat_plugin"
|
||||
copy_sample_plugin("old", plugin_root, ascii_only=True)
|
||||
copy_sample_plugin("old", plugin_root)
|
||||
|
||||
runtime = SupervisorRuntime(
|
||||
transport=self.right,
|
||||
|
||||
@@ -24,7 +24,7 @@ def prepare_sample_plugin(
|
||||
python_version: str | None = None,
|
||||
include_requirements: bool = True,
|
||||
) -> Path:
|
||||
plugin_dir = copy_sample_plugin(sample_name, root / folder_name, ascii_only=True)
|
||||
plugin_dir = copy_sample_plugin(sample_name, root / folder_name)
|
||||
manifest_path = plugin_dir / "plugin.yaml"
|
||||
manifest = yaml.safe_load(manifest_path.read_text(encoding="utf-8")) or {}
|
||||
manifest["name"] = plugin_name or folder_name
|
||||
@@ -128,12 +128,23 @@ class SupervisorMigrationTest(unittest.IsolatedAsyncioTestCase):
|
||||
self.assertEqual(
|
||||
self.core.remote_metadata["plugins"], ["plugin_one", "plugin_two"]
|
||||
)
|
||||
self.assertEqual(len(self.core.remote_handlers), 18)
|
||||
plugin_one_handlers = [
|
||||
item.id
|
||||
for item in self.core.remote_handlers
|
||||
if item.id.startswith("plugin_one:")
|
||||
]
|
||||
plugin_two_handlers = [
|
||||
item.id
|
||||
for item in self.core.remote_handlers
|
||||
if item.id.startswith("plugin_two:")
|
||||
]
|
||||
self.assertTrue(plugin_one_handlers)
|
||||
self.assertTrue(plugin_two_handlers)
|
||||
|
||||
handler_id = next(
|
||||
item.id
|
||||
for item in self.core.remote_handlers
|
||||
if item.id.startswith("plugin_two:")
|
||||
if item.id.startswith("plugin_two:") and item.id.endswith(".hello")
|
||||
)
|
||||
await self.core.invoke(
|
||||
"handler.invoke",
|
||||
|
||||
Reference in New Issue
Block a user