kuri-tool-guard/tests/test_policy_integration.py
XLion 06a7f93d18
refactor(kuri-tool-guard): modularise monolithic __init__.py and tests
Split the 1341-line __init__.py into 5 focused modules:
  _state.py    - home root helpers, mutable poll state
  _parser.py   - shell tokenizer (independent)
  _predicates.py - terminal predicates + bounded output
  _guards.py   - all 9 guard implementations + AST helpers
  __init__.py  - thin entry point + dispatcher + re-exports

Split the 2226-line test_guard.py into 14 dedicated files:
  13 test_*.py files + tests/_support.py (shared helpers)

Key changes:
- Package-relative imports throughout (Hermes loader compatible)
- No top-level module pollution (hermes_plugins.kuri_tool_guard.* only)
- Typechecked via ty with symlink alias for hyphenated dir name
- All 10 guard policies, messages, and block/allow behaviour preserved
- 338 tests (336 original + 2 new: isolation + loader contract)
- ty, ruff, bandit, vulture all pass in just verify
2026-07-31 02:23:02 +08:00

40 lines
1.4 KiB
Python

"""Tests for kuri-tool-guard — policy fixture integration."""
from __future__ import annotations
import unittest
from tests._support import load_mod
from tests.policy_fixtures import COMMON_POLICY_CASES, KNOWN_BYPASS_REGRESSIONS
class TestPolicyFixtures(unittest.TestCase):
"""Exercise allowed, hard-block, and known-bypass policy fixtures."""
def setUp(self):
self.mod = load_mod()
def test_common_policy_cases(self):
for case in COMMON_POLICY_CASES:
with self.subTest(case=case.name):
result = self.mod._on_pre_tool_call(
tool_name=case.tool_name,
args=case.args,
session_id=case.name,
)
if case.expected == "block":
self.assertIsNotNone(result)
self.assertEqual(result["action"], "block")
else:
self.assertIsNone(result)
def test_known_bypass_regressions_remain_blocked(self):
for case in KNOWN_BYPASS_REGRESSIONS:
with self.subTest(case=case.name):
result = self.mod._on_pre_tool_call(
tool_name=case.tool_name,
args=case.args,
session_id=case.name,
)
self.assertIsNotNone(result)
self.assertEqual(result["action"], "block")