Test that wildcard patterns work correctly.
()
| 205 | |
| 206 | |
| 207 | def test_pattern_matching(): |
| 208 | """Test that wildcard patterns work correctly.""" |
| 209 | print("\n" + "=" * 70) |
| 210 | print("TEST 5: Pattern matching (swift*)") |
| 211 | print("=" * 70) |
| 212 | |
| 213 | with tempfile.TemporaryDirectory() as tmpdir: |
| 214 | project_dir = Path(tmpdir) |
| 215 | |
| 216 | # Create project config with swift* pattern |
| 217 | autoforge_dir = project_dir / ".autoforge" |
| 218 | autoforge_dir.mkdir() |
| 219 | (autoforge_dir / "allowed_commands.yaml").write_text("""version: 1 |
| 220 | commands: |
| 221 | - name: swift* |
| 222 | description: All Swift tools |
| 223 | """) |
| 224 | |
| 225 | # Try to run swiftlint (should match swift* pattern) |
| 226 | input_data = {"tool_name": "Bash", "tool_input": {"command": "swiftlint"}} |
| 227 | context = {"project_dir": str(project_dir)} |
| 228 | |
| 229 | result = asyncio.run(bash_security_hook(input_data, context=context)) |
| 230 | |
| 231 | if result.get("decision") != "block": |
| 232 | print("✅ PASS: swiftlint matched swift* pattern") |
| 233 | return True |
| 234 | else: |
| 235 | print("❌ FAIL: swiftlint should have matched swift*") |
| 236 | print(f" Reason: {result.get('reason', 'N/A')}") |
| 237 | return False |
| 238 | |
| 239 | |
| 240 | def test_org_blocklist_enforcement(): |
nothing calls this directly
no test coverage detected