| 109 | |
| 110 | |
| 111 | class TestAI206: |
| 112 | def test_rule_metadata(self): |
| 113 | rule = _ai_rule("AI206") |
| 114 | assert rule["severity"] == "High" |
| 115 | assert rule["cwe"] == "CWE-94" |
| 116 | assert rule["ast_match"] == AI206_MATCHER |
| 117 | |
| 118 | def test_matcher_targets_true_keyword_only(self): |
| 119 | true_code = 'AutoModelForCausalLM.from_pretrained("example/model", trust_remote_code=True)' |
| 120 | false_code = 'AutoModelForCausalLM.from_pretrained("example/model", trust_remote_code=False)' |
| 121 | assert _matches_ai206(true_code) |
| 122 | assert not _matches_ai206(false_code) |
| 123 | |
| 124 | def test_trust_remote_code_true_fires(self): |
| 125 | code = """ |
| 126 | model = AutoModelForCausalLM.from_pretrained( |
| 127 | "example/model", |
| 128 | trust_remote_code=True, |
| 129 | ) |
| 130 | """ |
| 131 | assert fires(code, "AI206") |
| 132 | |
| 133 | def test_trust_remote_code_false_safe(self): |
| 134 | code = """ |
| 135 | model = AutoModelForCausalLM.from_pretrained( |
| 136 | "example/model", |
| 137 | trust_remote_code=False, |
| 138 | ) |
| 139 | """ |
| 140 | assert not fires(code, "AI206") |
| 141 | |
| 142 | |
| 143 | class TestAIModelDeserializationPatterns: |
nothing calls this directly
no outgoing calls
no test coverage detected