Protokoll #28173

ID28173
Zeitstempel2025-12-28 12:56:55.635816
Clientroot
IP145.224.72.140
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens1,015 (Input: 872, Output: 143)
Dauer146428 ms
Request-Zeit2025-12-28 12:56:55.635816
Response-Zeit2025-12-28 12:59:22.063967

Request

{
    "event": "PreToolUse",
    "tool_name": "Bash",
    "tool_input": {
        "command": "python3 << 'PYEOF'\nfrom quality import pre_rules, post_rules\n\nprint('=== Module geladen ===')\nprint('Pre-Rules PHP:', len(pre_rules.PHP_RULES))\nprint('Post-Rules:', len(post_rules.RULES))\n\nprint('\\n=== P14.x Test-Isolation Tests (Pre-Hook BLOCK) ===')\n\n# Test P14.1: Produktions-DB in Tests\ntest_prod_db = '''<?php\ndeclare(strict_types=1);\nnamespace Tests\\\\Unit;\nclass MyTest {\n    public function testSomething() {\n        $db = new Database(\"ki_content\");\n    }\n}\n'''\nresult = pre_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_prod_db)\nprint('P14.1 Produktions-DB blockiert:', 'P14.1' in result.get('message', ''))\n\n# Test P14.1: Test-DB ist erlaubt\ntest_ok_db = '''<?php\ndeclare(strict_types=1);\nnamespace Tests\\\\Unit;\nclass MyTest {\n    public function testSomething() {\n        $db = new Database(\"ki_content_test\");\n    }\n}\n'''\nresult = pre_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_ok_db)\nprint('P14.1 Test-DB erlaubt:', result.get('allowed', False))\n\n# Test P14.5: DROP TABLE in Tests\ntest_drop = '''<?php\ndeclare(strict_types=1);\nnamespace Tests\\\\Unit;\nclass MyTest {\n    public function testCleanup() {\n        $this->db->query(\"DROP TABLE users\");\n    }\n}\n'''\nresult = pre_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_drop)\nprint('P14.5 DROP TABLE blockiert:', 'P14.5' in result.get('message', ''))\n\n# Test P14.6: Static ohne tearDown\ntest_static = '''<?php\ndeclare(strict_types=1);\nnamespace Tests\\\\Unit;\nclass MyTest {\n    private static $instance;\n    public function testSomething() {\n        self::$instance = new Something();\n    }\n}\n'''\nresult = pre_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_static)\nprint('P14.6 Static ohne tearDown blockiert:', 'P14.6' in result.get('message', ''))\n\n# Test: Nicht-Test-Datei wird nicht geprüft\nresult = pre_rules.check('\/var\/www\/src\/Service\/MyService.php', test_prod_db)\nprint('Nicht-Test-Datei ignoriert:', result.get('allowed', False) or 'P14' not in result.get('message', ''))\n\nprint('\\n=== W14.x Test-Isolation Tests (Post-Hook WARN) ===')\n\n# Test W14.1: setUp ohne tearDown\ntest_setup = '''<?php\nclass MyTest extends TestCase {\n    protected function setUp(): void {\n        parent::setUp();\n        $this->connection = new Connection();\n    }\n    public function testSomething(): void {\n        $this->assertTrue(true);\n    }\n}\n'''\nresult = post_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_setup)\nprint('W14.1 setUp ohne tearDown warnt:', any('W14.1' in w for w in result.get('warnings', [])))\n\n# Test W14.5: sleep in Tests\ntest_sleep = '''<?php\nclass MyTest extends TestCase {\n    public function testTimeout(): void {\n        sleep(5);\n        $this->assertTrue(true);\n    }\n}\n'''\nresult = post_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_sleep)\nprint('W14.5 sleep() in Tests warnt:', any('W14.5' in w for w in result.get('warnings', [])))\n\n# Test W14.7: Test ohne Assertion\ntest_no_assert = '''<?php\nclass MyTest extends TestCase {\n    public function testDoNothing(): void {\n        $result = doSomething();\n    }\n}\n'''\nresult = post_rules.check('\/var\/www\/tests\/Unit\/MyTest.php', test_no_assert)\nprint('W14.7 Test ohne Assertion warnt:', any('W14.7' in w for w in result.get('warnings', [])))\n\nprint('\\nAlle Tests bestanden!')\nPYEOF\n",
        "description": "Test new test isolation rules"
    }
}

Response

{
    "tool_response": {
        "stdout": "=== Module geladen ===\nPre-Rules PHP: 29\nPost-Rules: 38\n\n=== P14.x Test-Isolation Tests (Pre-Hook BLOCK) ===\nP14.1 Produktions-DB blockiert: True\nP14.1 Test-DB erlaubt: True\nP14.5 DROP TABLE blockiert: True\nP14.6 Static ohne tearDown blockiert: True\nNicht-Test-Datei ignoriert: True\n\n=== W14.x Test-Isolation Tests (Post-Hook WARN) ===\nW14.1 setUp ohne tearDown warnt: True\nW14.5 sleep() in Tests warnt: True\nW14.7 Test ohne Assertion warnt: True\n\nAlle Tests bestanden!",
        "stderr": "",
        "interrupted": false,
        "isImage": false
    }
}
← Vorheriger Zur Liste Nächster →