From e6c705cef77a5f3ff7889d5406d265d04a6de113 Mon Sep 17 00:00:00 2001 From: devops Date: Tue, 20 Oct 2026 19:55:28 +0000 Subject: [PATCH] feat(orchestration): implement live HTTP artifact verification with soft-404 detection --- scripts/orchestration/orchestration_worker.py | 43 ++++++++++++++- .../test_artifact_qa_verifier.py | 53 +++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 scripts/orchestration/test_artifact_qa_verifier.py diff --git a/scripts/orchestration/orchestration_worker.py b/scripts/orchestration/orchestration_worker.py index 6f3e98e1..d2efc332 100644 --- a/scripts/orchestration/orchestration_worker.py +++ b/scripts/orchestration/orchestration_worker.py @@ -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: diff --git a/scripts/orchestration/test_artifact_qa_verifier.py b/scripts/orchestration/test_artifact_qa_verifier.py new file mode 100644 index 00000000..c488a534 --- /dev/null +++ b/scripts/orchestration/test_artifact_qa_verifier.py @@ -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 = "

مقاله یافت نشد

متاسفانه این صفحه حذف شده است

".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 = ("

راهنمای مفاصل کنینا

" + "متن کامل بالینی " * 100 + "

").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()