From 84b4a7eca246bd858463b520be7887986a4b5925 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 13 Jun 2026 17:15:35 +0800 Subject: [PATCH] fix: change logging level to debug for plugin restoration and add tests for warning filters --- app/chain/system.py | 4 ++-- tests/test_startup_warnings.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/test_startup_warnings.py diff --git a/app/chain/system.py b/app/chain/system.py index 874e3012..4456cb01 100644 --- a/app/chain/system.py +++ b/app/chain/system.py @@ -135,12 +135,12 @@ class SystemChain(ChainBase): if target_path.exists(): shutil.rmtree(target_path) shutil.copytree(item, target_path) - logger.info(f"已恢复插件目录: {item.name}") + logger.debug(f"已恢复插件目录: {item.name}") restored_count += 1 # 如果是文件 elif item.is_file(): shutil.copy2(item, target_path) - logger.info(f"已恢复插件文件: {item.name}") + logger.debug(f"已恢复插件文件: {item.name}") restored_count += 1 except Exception as e: logger.error(f"恢复插件 {item.name} 时发生错误: {str(e)}") diff --git a/tests/test_startup_warnings.py b/tests/test_startup_warnings.py new file mode 100644 index 00000000..ecc842a3 --- /dev/null +++ b/tests/test_startup_warnings.py @@ -0,0 +1,17 @@ +import warnings + +import app + + +def test_app_installs_known_oss2_invalid_escape_warning_filter(): + """ + app 初始化过滤器应覆盖 oss2 在 Python 3.12 下产生的无害转义警告。 + """ + app._filter_third_party_startup_warnings() + action, message, category, module, lineno = warnings.filters[0] + + assert action == "ignore" + assert message.match("invalid escape sequence '\\&'") + assert category is SyntaxWarning + assert module is None + assert lineno == 0