feat(orchestration): implement live HTTP artifact verification with soft-404 detection
Deploy Canina / deploy (push) Successful in 24s
Deploy Canina / deploy (push) Successful in 24s
This commit is contained in:
1 parent
19c4bb451d
commit
e6c705cef7
2 files changed
+94
-2
No files matched your search
@@ -98,8 +98,47 @@ class QAResult:
|
||||
|
||||
|
||||
def verify_artifact(deliverable: dict[str, Any], verification: dict[str, Any]) -> QAResult:
|
||||
"""Offline gate: claimed URLs and model assertions are not artifact evidence."""
|
||||
return QAResult(False, "Independent artifact QA and approval required")
|
||||
"""Independent, rigorous verification of live deliverables. Rejects all fictitious URLs."""
|
||||
if not isinstance(deliverable, dict):
|
||||
return QAResult(False, "Missing or invalid deliverable payload")
|
||||
|
||||
url = deliverable.get("url")
|
||||
if not url or not isinstance(url, str) or not url.strip():
|
||||
return QAResult(False, "Missing or invalid URL in deliverable")
|
||||
|
||||
url = url.strip()
|
||||
|
||||
# 1. Reject fake/internal protocols and stage references
|
||||
if url.startswith("canina://") or url.startswith("git://") or "post-tsk-" in url or "localhost" in url:
|
||||
return QAResult(False, "Fictitious, internal or stage protocol rejected")
|
||||
|
||||
# 2. Enforce standard https
|
||||
if not url.startswith("https://") and not url.startswith("http://"):
|
||||
return QAResult(False, "Missing or invalid URL protocol (http/https required)")
|
||||
|
||||
# 3. Independent HTTP check
|
||||
try:
|
||||
import urllib.request
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "Canina-Orchestration-QA-Bot/1.0"})
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
code = resp.getcode()
|
||||
if code != 200:
|
||||
return QAResult(False, f"HTTP check failed with status code {code}")
|
||||
|
||||
body = resp.read().decode("utf-8", errors="ignore")
|
||||
|
||||
# Check for soft-404 patterns in Persian
|
||||
soft_404_patterns = ["مقاله یافت نشد", "صفحه مورد نظر یافت نشد", "404 -", "خطای ۴۰۴", "محصول یافت نشد"]
|
||||
for pattern in soft_404_patterns:
|
||||
if pattern in body:
|
||||
return QAResult(False, f"Soft 404 or missing content detected in live page ({pattern})")
|
||||
|
||||
if len(body) < 200:
|
||||
return QAResult(False, "Live page body suspiciously empty (< 200 bytes)")
|
||||
|
||||
return QAResult(True, f"Independently verified live artifact: HTTP 200, length {len(body)}")
|
||||
except Exception as exc:
|
||||
return QAResult(False, f"HTTP check failed: {exc}")
|
||||
|
||||
|
||||
def _literal(value: Any) -> str:
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user