add minimal error diagnosis agent
This commit is contained in:
63
test_main.py
Normal file
63
test_main.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import unittest
|
||||
|
||||
from main import ValidationError, analyze
|
||||
|
||||
|
||||
class AnalyzeTests(unittest.TestCase):
|
||||
def test_unsupported_operator_is_identified(self):
|
||||
result = analyze(
|
||||
{
|
||||
"error_log": (
|
||||
"RuntimeError: unsupported operator "
|
||||
"aten::_scaled_dot_product_attention"
|
||||
),
|
||||
"hardware": "目标国产算力卡",
|
||||
"sdk_version": "1.0",
|
||||
"framework": "PyTorch",
|
||||
"framework_version": "2.3",
|
||||
"inference_engine": "Transformers",
|
||||
}
|
||||
)
|
||||
self.assertEqual(result["verdict"], "matched_known_failure_patterns")
|
||||
self.assertEqual(result["findings"][0]["category"], "unsupported_operator")
|
||||
|
||||
def test_out_of_memory_is_identified(self):
|
||||
result = analyze({"error_log": "RuntimeError: device out of memory"})
|
||||
categories = {finding["category"] for finding in result["findings"]}
|
||||
self.assertIn("out_of_memory", categories)
|
||||
|
||||
def test_version_mismatch_is_identified(self):
|
||||
result = analyze(
|
||||
{"error_log": "ImportError: libbackend.so: undefined symbol: xc_runtime"}
|
||||
)
|
||||
categories = {finding["category"] for finding in result["findings"]}
|
||||
self.assertIn("version_mismatch", categories)
|
||||
|
||||
def test_secrets_are_redacted_from_evidence(self):
|
||||
result = analyze(
|
||||
{
|
||||
"error_log": (
|
||||
"Authorization: Bearer secret-token-123\n"
|
||||
"RuntimeError: unsupported operator aten::example"
|
||||
)
|
||||
}
|
||||
)
|
||||
evidence = "\n".join(
|
||||
line for finding in result["findings"] for line in finding["evidence"]
|
||||
)
|
||||
self.assertNotIn("secret-token-123", evidence)
|
||||
self.assertTrue(result["redaction_applied"])
|
||||
|
||||
def test_unknown_pattern_requests_more_context(self):
|
||||
result = analyze({"error_log": "application exited unexpectedly"})
|
||||
self.assertEqual(result["verdict"], "unknown_pattern")
|
||||
self.assertIn("hardware", result["missing_fields"])
|
||||
self.assertGreaterEqual(len(result["recommendations"]), 3)
|
||||
|
||||
def test_empty_log_is_rejected(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
analyze({"error_log": " "})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user