Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

fix(skill): honor environment keys after blank config values

Rudy Celekli1831356a273f
diff --git a/docs/skill/mpt_agent.py b/docs/skill/mpt_agent.py
index 6522fd30..972e3454 100644
--- a/docs/skill/mpt_agent.py
+++ b/docs/skill/mpt_agent.py
@@ -395,9 +395,9 @@ def missing_config(config_path: Path, cli_args: list[str]) -> tuple[str, list[st
# 与运行时 Provider 保持完全一致的凭据优先级,避免 Skill 预检通过后
# 主程序却读取了另一把 Key。ARK_API_KEY 语义过于宽泛,明确不再兼容。
value = (
- _plain_config_value(text, "volcengine_seedance_api_key")
+ _plain_config_value(text, "volcengine_seedance_api_key").strip()
or os.environ.get("VOLCENGINE_ARK_API_KEY", "").strip()
- or _plain_config_value(text, "volcengine_api_key")
+ or _plain_config_value(text, "volcengine_api_key").strip()
)
if not _has_configured_value(value):
missing.append("volcengine_seedance_api_key")
@@ -416,7 +416,7 @@ def missing_config(config_path: Path, cli_args: list[str]) -> tuple[str, list[st
# 与运行时 Provider 保持完全一致的凭据优先级:配置键优先,其次是
# 语义明确的 OFOX_API_KEY 环境变量。
value = (
- _plain_config_value(text, "ofox_api_key")
+ _plain_config_value(text, "ofox_api_key").strip()
or os.environ.get("OFOX_API_KEY", "").strip()
)
if not _has_configured_value(value):
@@ -427,7 +427,7 @@ def missing_config(config_path: Path, cli_args: list[str]) -> tuple[str, list[st
# 秘塔 Key 与 MiniMax 官方 LLM Key 不互通,Skill 必须沿用运行时的
# 独立配置优先级,不能因为已经配置 minimax_api_key 就误判为可用。
value = (
- _plain_config_value(text, "metaso_minimax_api_key")
+ _plain_config_value(text, "metaso_minimax_api_key").strip()
or os.environ.get("METASO_MINIMAX_API_KEY", "").strip()
)
if not _has_configured_value(value):
@@ -436,7 +436,7 @@ def missing_config(config_path: Path, cli_args: list[str]) -> tuple[str, list[st
missing.append("confirm_metaso_minimax_charge")
elif source == "muapi":
value = (
- _plain_config_value(text, "muapi_api_key")
+ _plain_config_value(text, "muapi_api_key").strip()
or os.environ.get("MUAPI_API_KEY", "").strip()
)
if not _has_configured_value(value):
diff --git a/test/services/test_skill_whitespace_key_env_fallback.py b/test/services/test_skill_whitespace_key_env_fallback.py
new file mode 100644
index 00000000..07a9aed7
--- /dev/null
+++ b/test/services/test_skill_whitespace_key_env_fallback.py
@@ -0,0 +1,26 @@
+import importlib.util
+from pathlib import Path
+from unittest.mock import patch
+
+import pytest
+
+from app.services import metaso_minimax, muapi, ofox, volcengine_seedance
+
+
+spec = importlib.util.spec_from_file_location("mpt_whitespace_keys_fixture", Path(__file__).parents[2] / "docs" / "skill" / "mpt_agent.py")
+helper = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(helper)
+
+
[email protected]("source,key,environment,service,confirmation", [
+ ("ofox", "ofox_api_key", "OFOX_API_KEY", ofox, "--confirm-ofox-charge"),
+ ("muapi", "muapi_api_key", "MUAPI_API_KEY", muapi, "--confirm-muapi-charge"),
+ ("metaso_minimax", "metaso_minimax_api_key", "METASO_MINIMAX_API_KEY", metaso_minimax, "--confirm-metaso-minimax-charge"),
+ ("volcengine_seedance", "volcengine_seedance_api_key", "VOLCENGINE_ARK_API_KEY", volcengine_seedance, "--confirm-seedance-charge"),
+])
+def test_helper_matches_runtime_environment_fallback_after_blank_config(tmp_path, source, key, environment, service, confirmation):
+ destination = tmp_path / "config.toml"
+ destination.write_text(f'[app]\nllm_provider = "ollama"\n{key} = " "\n', encoding="utf-8")
+ with patch.dict(helper.os.environ, {environment: "fixture-environment-key"}, clear=True):
+ assert service.get_api_key({key: " "}) == "fixture-environment-key"
+ assert helper.missing_config(destination, ["--video-source", source, confirmation]) == ("ollama", [])