fix(场景): 默认输出插件运行日志
场景命令直接输出插件消息并保留各日志级别,详细模式继续显示生命周期。保持标准输出为场景结果 JSON,补充默认和详细模式的命令行回归测试并简化文档。
This commit is contained in:
1 parent
016c43f13e
commit
fa937803c7
5 files changed
+51
-6
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -169,3 +171,39 @@ def test_file_request_generates_multipart_headers(tmp_path):
|
||||
assert headers["x-test"] == "yes"
|
||||
assert headers["content-type"].startswith("multipart/form-data; boundary=")
|
||||
assert info["file_bytes"] in body
|
||||
|
||||
|
||||
@pytest.mark.parametrize("verbose", [False, True])
|
||||
def test_cli_displays_plugin_logs_without_verbose(tmp_path, verbose):
|
||||
config = write_config(tmp_path)
|
||||
(tmp_path / "marker.lua").write_text(
|
||||
"return {on_request=function() host.log.info('测试插件正文'); "
|
||||
"host.log.warning('测试警告'); host.log.error('测试错误') end}",
|
||||
encoding="utf-8",
|
||||
)
|
||||
command = [
|
||||
sys.executable,
|
||||
"-X",
|
||||
"utf8",
|
||||
"-m",
|
||||
"middleware.scenario_runner",
|
||||
"--config",
|
||||
str(config),
|
||||
"--scenarios",
|
||||
str(write_scenarios(tmp_path)),
|
||||
]
|
||||
if verbose:
|
||||
command.append("--verbose")
|
||||
result = subprocess.run(command, capture_output=True, encoding="utf-8", timeout=30)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
assert 'message="测试插件正文"' in result.stderr
|
||||
assert 'message="测试警告"' in result.stderr
|
||||
assert 'message="测试错误"' in result.stderr
|
||||
assert "plugin=marker" in result.stderr
|
||||
assert ("plugin_hook " in result.stderr) is verbose
|
||||
assert [json.loads(line)["id"] for line in result.stdout.splitlines()] == [
|
||||
"sse",
|
||||
"post",
|
||||
"file",
|
||||
]
|
||||
Reference in new issue
Block a user