fix(场景): 准确报告策略阻断并对齐文本路径

在解码 SSE 前检查 HTTP 状态和响应类型,避免将 JSON 错误响应误报为 PluginFailure。增加 verbose 插件执行日志及 403、502 回归测试,修正响应插件的 data.content 路径,并保留本地关闭网络审核插件的配置。
This commit is contained in:
starrrLight committed 2026-10-16 14:25:02 +08:00
1 parent 48f7dfc59f
commit 17c56cac3c
4 files changed
+61 -7

No files matched your search

+20
View File
@@ -96,6 +96,26 @@ async def test_runner_executes_sse_post_and_file_with_real_matching(tmp_path, ca
assert len(capsys.readouterr().out.splitlines()) == 3
@pytest.mark.parametrize(
("hook", "expected"),
[
("return {action='block'}", r"status 403 != 200 \(PolicyBlocked\)"),
("error('private-plugin-message')", r"status 502 != 200 \(MiddlewareFailure\)"),
],
)
async def test_sse_rejection_reports_http_status_before_decoding(tmp_path, hook, expected):
config = write_config(tmp_path)
(tmp_path / "marker.lua").write_text(
f"return {{on_request=function(ctx,r) {hook} end}}", encoding="utf-8"
)
with pytest.raises(ScenarioError, match=expected) as failure:
await run_scenarios(config, write_scenarios(tmp_path))
assert "scenario sse:" in str(failure.value)
assert "private-plugin-message" not in str(failure.value)
def test_scenario_schema_and_file_path_safety(tmp_path):
scenario = tmp_path / "scenario.json"
scenario.write_text(json.dumps({"scenarios": []}), encoding="utf-8")