Skip to content

Commit 28a4174

Browse files
committed
full tests
1 parent 97770e0 commit 28a4174

6 files changed

Lines changed: 524 additions & 50 deletions

File tree

docs/mkdocs/en/tool_safety_guard.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ tool/
393393
_telemetry.py # OTel span attrs + metrics (no-op safe)
394394
_tool_adapter.py # ToolInputAdapter + built-ins
395395
_filter.py # ToolScriptSafetyFilter (terminal)
396-
wrapper.py # SafetyWrappedCallable, SafetyCheckedExecutor
396+
wrapper.py # SafetyWrappedCallable, SafetyCheckedExecutor
397397
scripts/
398398
tool_safety_check.py # CLI
399399
tests/tool_safety/ # safety guard tests
@@ -402,7 +402,7 @@ trpc_agent_sdk/tools/safety/examples/
402402
samples/ # 14 public samples + manifest
403403
tool_safety_report.json # generated report
404404
tool_safety_audit.jsonl # generated audit log
405-
manifest_run.json # manifest execution summary
405+
manifest_run.json # 14 full reports plus expectation checks
406406
docs/
407407
tool_safety_guard.md # this document
408408
tool_safety_guard.zh_CN.md # Chinese version

docs/mkdocs/zh/tool_safety_guard.zh_CN.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,17 @@ python -m pytest tests/tool_safety/ -v
345345
## 文件布局
346346

347347
```text
348-
tool/
349-
safety/ # Guard、策略、规则、扫描器、审计和 Telemetry
348+
trpc_agent_sdk/tools/safety/ # Guard、策略、规则、扫描器、审计和 Telemetry
350349
wrapper.py # SafetyWrappedCallable、SafetyCheckedExecutor
350+
examples/
351+
tool_safety_policy.yaml # 示例策略
352+
samples/ # 14 个公开样例及 manifest
353+
tool_safety_report.json # 单次扫描完整报告
354+
tool_safety_audit.jsonl # JSONL 审计日志
355+
manifest_run.json # 14 份完整报告及预期结果核对
351356
scripts/
352357
tool_safety_check.py # CLI
353358
tests/tool_safety/ # 安全检查器测试
354-
trpc_agent_sdk/tools/safety/examples/ # 策略、14 个样例、报告和审计样例
355359
docs/
356360
tool_safety_guard.md # English version
357361
tool_safety_guard.zh_CN.md # 本文

scripts/tool_safety_check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def _run_manifest(guard: ToolSafetyGuard,
168168
"risk_level": report.risk_level.label(),
169169
"duration_ms": report.scan_duration_ms,
170170
"matches_expected": _decision_matches(report, expected),
171+
"report": report.model_dump(mode="json"),
171172
})
172173
blocked = report.decision != SafetyDecision.ALLOW
173174
asyncio.run(_emit_audit(

tests/tool_safety/test_cli.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ def test_manifest_writes_output(tmp_path):
9292
assert output.exists()
9393
payload = json.loads(output.read_text(encoding="utf-8"))
9494
assert len(payload) == 14
95+
for item in payload:
96+
report = item["report"]
97+
assert {
98+
"decision",
99+
"risk_level",
100+
"rule_ids",
101+
"findings",
102+
"recommendation",
103+
} <= report.keys()
104+
if report["decision"] != "allow":
105+
assert report["findings"]
106+
for finding in report["findings"]:
107+
assert {
108+
"category",
109+
"rule_id",
110+
"evidence",
111+
"recommendation",
112+
} <= finding.keys()
95113
# Audit file has one line per sample.
96114
lines = [ln for ln in audit.read_text(encoding="utf-8").splitlines()
97115
if ln.strip()]

trpc_agent_sdk/tools/safety/examples/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ and the generated report / audit outputs.
2525
| `samples/manifest.yaml` | Expected decisions for all 14 samples |
2626
| `tool_safety_report.json` | Single-sample report (regenerated by CLI) |
2727
| `tool_safety_audit.jsonl` | Audit events (regenerated by CLI) |
28-
| `manifest_run.json` | Manifest execution summary |
28+
| `manifest_run.json` | Expected-vs-actual results and full structured reports for all samples |
2929

3030
## Run
3131

@@ -54,8 +54,8 @@ python ../../../../scripts/tool_safety_check.py \
5454
hash.
5555
* `tool_safety_audit.jsonl` shows one line per scan. Note that no raw
5656
script text, env values, or unredacted arguments ever appear.
57-
* `manifest_run.json` shows expected-vs-actual decisions across all 14
58-
samples.
57+
* `manifest_run.json` shows expected-vs-actual decisions and the full
58+
structured report for each of the 14 samples.
5959

6060
See the full design document in
6161
[English](../../../../docs/mkdocs/en/tool_safety_guard.md) or

0 commit comments

Comments
 (0)