Skip to content

Commit 90b3426

Browse files
Violet2314claude
andcommitted
style(safety): apply yapf to satisfy CI formatting check
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b3fc85e commit 90b3426

5 files changed

Lines changed: 20 additions & 24 deletions

File tree

tests/tool_safety/test_review_p0_p1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_safe_git_status_still_allowed():
147147

148148

149149
def test_scanner_error_is_high_fail_closed():
150+
150151
class BoomRule(SafetyRule):
151152
rule_id = "BOOM_TEST"
152153
rule_name = "boom"

tests/tool_safety/test_rules.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ def test_dangerous_files_bash_rm_gnu_long_options():
4444
"""
4545
rule = DangerousFilesRule()
4646
for cmd in (
47-
"rm --recursive /",
48-
"rm --force /",
49-
"rm --recursive --force /",
50-
"rm --force --recursive /",
51-
"rm --recursive -f /",
52-
"rm -r --force /",
53-
"rm --recursive=yes /",
47+
"rm --recursive /",
48+
"rm --force /",
49+
"rm --recursive --force /",
50+
"rm --force --recursive /",
51+
"rm --recursive -f /",
52+
"rm -r --force /",
53+
"rm --recursive=yes /",
5454
):
5555
findings = rule.check(ScanInput(script=cmd, language="bash"), _policy())
5656
assert any("R001" in f.rule_id for f in findings), f"failed to flag: {cmd!r}"

trpc_agent_sdk/safety/_rules.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ def _finding(
113113
# Commands that mutate filesystem content when aimed at a system directory.
114114
_SYSTEM_DIR_MUTATORS = re.compile(
115115
r"(?i)(?:^|[\s;|&])(?:rm|cp|mv|install|ln|tee|sed|dd|chmod|chown|chgrp|truncate|"
116-
r"install|rsync|tar|unzip|gzip|bzip2|xz)\b|>|>>",
117-
)
116+
r"install|rsync|tar|unzip|gzip|bzip2|xz)\b|>|>>", )
118117

119118
_SYSTEM_DIRS = [
120119
"/etc",
@@ -938,6 +937,7 @@ def _is_process_call(lname: str) -> bool:
938937
return True
939938
return False
940939

940+
941941
_PRIVILEGE_CMDS = {"sudo", "su", "doas", "pkexec", "runuser"}
942942
_INJECTION_BUILTINS = {"eval", "exec", "compile", "builtins.eval", "builtins.exec"}
943943
_DECODE_EXEC_BASH = re.compile(
@@ -998,15 +998,14 @@ def _check_python(self, scan_input: ScanInput, policy: PolicyConfig) -> list[Saf
998998
attr_raw = get_string_literal(node.args[1]) if len(node.args) > 1 else None
999999
attr = attr_raw.lower() if isinstance(attr_raw, str) else None
10001000
# Match any process API attr, including exec*/spawn* families.
1001-
if obj in {"os", "subprocess", "pty"} and attr and (
1002-
attr in {
1003-
"system",
1004-
"popen",
1005-
"exec",
1006-
"run",
1007-
"call",
1008-
"spawn",
1009-
} or attr.startswith("exec") or attr.startswith("spawn")):
1001+
if obj in {"os", "subprocess", "pty"} and attr and (attr in {
1002+
"system",
1003+
"popen",
1004+
"exec",
1005+
"run",
1006+
"call",
1007+
"spawn",
1008+
} or attr.startswith("exec") or attr.startswith("spawn")):
10101009
findings.append(
10111010
self._finding(
10121011
f"getattr({obj}, {attr_raw!r})",

trpc_agent_sdk/safety/_scanner.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ def scan(self, scan_input: ScanInput) -> SafetyReport:
117117
# cannot slip through as ALLOW.
118118
if language == "python":
119119
script = scan_input.script or ""
120-
needs_bash = (
121-
parse_python_ast(script) is None
122-
or has_shell_command_lines(script)
123-
)
120+
needs_bash = (parse_python_ast(script) is None or has_shell_command_lines(script))
124121
if needs_bash:
125122
bash_input = ScanInput(
126123
script=script,

trpc_agent_sdk/safety/_wrapper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ async def execute_code(self, invocation_context, input_data):
211211
if report is not None:
212212
audit.log(report, intercepted=should_block)
213213
if should_block and report is not None:
214-
label = ("TOOL_SAFETY_DENY"
215-
if report.decision == Decision.DENY else "TOOL_SAFETY_NEEDS_REVIEW")
214+
label = ("TOOL_SAFETY_DENY" if report.decision == Decision.DENY else "TOOL_SAFETY_NEEDS_REVIEW")
216215
return _deny_code_result(report.rule_ids, label=label)
217216
return await inner.execute_code(invocation_context, input_data)
218217

0 commit comments

Comments
 (0)