feat(orchestration): implement live HTTP artifact verification with soft-404 detection
Deploy Canina / deploy (push) Successful in 24s

This commit is contained in:
devops committed 2026-10-20 19:55:28 +00:00
1 parent 19c4bb451d
commit e6c705cef7
2 files changed
+94 -2

No files matched your search

@@ -0,0 +1,53 @@
import unittest
from unittest.mock import Mock, patch
from orchestration_worker import verify_artifact, QAResult
class ArtifactQAVerifierTests(unittest.TestCase):
def test_missing_or_empty_url_is_rejected(self):
deliverable = {"type": "CONTENT", "url": ""}
res = verify_artifact(deliverable, {"passed": True})
self.assertFalse(res.passed)
self.assertIn("Missing or invalid URL", res.reason)
def test_internal_or_mock_urls_are_rejected(self):
for bad_url in [
"canina://internal/review",
"git://stage/task-1",
"https://canina.ir/blog/post-tsk-9999",
"http://localhost:3000/preview"
]:
res = verify_artifact({"type": "CONTENT", "url": bad_url}, {"passed": True})
self.assertFalse(res.passed, f"URL {bad_url} should have been rejected")
self.assertIn("Fictitious, internal or stage protocol", res.reason)
@patch("urllib.request.urlopen")
def test_http_404_or_network_failure_is_rejected(self, mock_urlopen):
mock_urlopen.side_effect = Exception("HTTP 404: Not Found")
res = verify_artifact({"type": "CONTENT", "url": "https://canina.ir/blog/valid-slug"}, {"passed": True})
self.assertFalse(res.passed)
self.assertIn("HTTP check failed", res.reason)
@patch("urllib.request.urlopen")
def test_http_200_with_soft_404_content_is_rejected(self, mock_urlopen):
mock_resp = Mock()
mock_resp.getcode.return_value = 200
mock_resp.read.return_value = "<html><body><h1>مقاله یافت نشد</h1><p>متاسفانه این صفحه حذف شده است</p></body></html>".encode("utf-8")
mock_urlopen.return_value.__enter__.return_value = mock_resp
res = verify_artifact({"type": "CONTENT", "url": "https://canina.ir/blog/valid-slug"}, {"passed": True})
self.assertFalse(res.passed)
self.assertIn("Soft 404 or missing content detected in live page", res.reason)
@patch("urllib.request.urlopen")
def test_http_200_with_authentic_content_passes(self, mock_urlopen):
mock_resp = Mock()
mock_resp.getcode.return_value = 200
mock_resp.read.return_value = ("<html><body><article><h1>راهنمای مفاصل کنینا</h1><p>" + "متن کامل بالینی " * 100 + "</p></article></body></html>").encode("utf-8")
mock_urlopen.return_value.__enter__.return_value = mock_resp
res = verify_artifact({"type": "CONTENT", "url": "https://canina.ir/blog/joints-guide"}, {"passed": True})
self.assertTrue(res.passed)
self.assertIn("Independently verified live artifact", res.reason)
if __name__ == "__main__":
unittest.main()