Skip to content

Commit 4d3ef68

Browse files
committed
fix(examples): tidy store imports and cover all redaction write paths in tests
1 parent 3ebd0f9 commit 4d3ef68

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

examples/skills_code_review_agent/storage/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# tRPC-Agent-Python is licensed under Apache-2.0.
66
"""ReviewStore: persistence built on the SDK's SqlStorage (SQLite by default,
77
any SQLAlchemy db_url works)."""
8+
import uuid
89
from datetime import datetime
910

1011
from trpc_agent_sdk.storage import SqlCondition, SqlKey, SqlStorage
@@ -38,7 +39,6 @@ async def create_task(self, input_type: str, input_ref: str, runtime: str,
3839
runtime=runtime, dry_run=dry_run, status="running")
3940
task_id = row.id or ""
4041
if not task_id:
41-
import uuid
4242
task_id = uuid.uuid4().hex
4343
row.id = task_id
4444
await self._add(row)

examples/skills_code_review_agent/tests/test_store.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from storage.store import ReviewStore
99

1010

11-
async def _new_store(tmp_path):
11+
def _new_store(tmp_path):
1212
return ReviewStore(db_url=f"sqlite:///{tmp_path}/cr.db")
1313

1414

1515
async def test_task_roundtrip(tmp_path):
16-
store = await _new_store(tmp_path)
16+
store = _new_store(tmp_path)
1717
task_id = await store.create_task("fixture", "clean.diff", "local", True)
1818
assert task_id
1919
await store.update_task(task_id, status="completed",
@@ -26,7 +26,7 @@ async def test_task_roundtrip(tmp_path):
2626

2727

2828
async def test_bundle_collects_all_tables(tmp_path):
29-
store = await _new_store(tmp_path)
29+
store = _new_store(tmp_path)
3030
task_id = await store.create_task("fixture", "x.diff", "local", True)
3131
await store.add_sandbox_run(task_id, script="check_security.py", category="security",
3232
status="ok", exit_code=0, duration_ms=12, timed_out=False,
@@ -51,23 +51,30 @@ async def test_bundle_collects_all_tables(tmp_path):
5151

5252

5353
async def test_store_redacts_evidence_and_output(tmp_path):
54-
store = await _new_store(tmp_path)
54+
store = _new_store(tmp_path)
5555
task_id = await store.create_task("fixture", "x.diff", "local", True)
5656
secret = "sk-abcdefghijklmnopqrstuvwxyz123456"
5757
await store.add_findings(task_id, [Finding(
5858
severity="critical", category="secret_leak", file="a.py", line=3,
5959
title="secret", evidence=f'key = "{secret}"', confidence=0.95)], status="reported")
6060
await store.add_sandbox_run(task_id, script="s.py", category="c", status="ok",
6161
exit_code=0, duration_ms=1, timed_out=False,
62-
stdout_summary=f"leaked {secret}", stderr_summary="", error_type="")
62+
stdout_summary=f"leaked {secret}",
63+
stderr_summary=f"stderr leaked {secret}", error_type="")
64+
await store.add_filter_event(task_id, target=f"/path/{secret}/config",
65+
decision="deny", rule="risk_secret", reason="file contains secret")
66+
await store.add_report(task_id, {"conclusion": "blocked"}, f"# Report\nSecret was: {secret}")
6367
bundle = await store.get_task_bundle(task_id)
6468
assert secret not in bundle["findings"][0]["evidence"]
6569
assert secret not in bundle["sandbox_runs"][0]["stdout_summary"]
70+
assert secret not in bundle["sandbox_runs"][0]["stderr_summary"]
71+
assert secret not in bundle["filter_events"][0]["target"]
72+
assert secret not in bundle["report"]["report_md"]
6673
await store.close()
6774

6875

6976
async def test_unknown_task_returns_none_task(tmp_path):
70-
store = await _new_store(tmp_path)
77+
store = _new_store(tmp_path)
7178
bundle = await store.get_task_bundle("nope")
7279
assert bundle["task"] is None
7380
await store.close()

0 commit comments

Comments
 (0)