feat(ai): add PixelRAG source contract replay worker
This commit is contained in:
@@ -1433,6 +1433,7 @@ def test_collect_ai_automation_smoke_uses_worst_status(monkeypatch):
|
||||
monkeypatch.setattr(smoke, "_sitewide_visual_qa_check", lambda: smoke._check("visual", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_external_mcp_rag_integration_check", lambda: smoke._check("external mcp rag", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_rag_candidate_replay_check", lambda: smoke._check("pixelrag replay", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_source_contract_replay_worker_check", lambda: smoke._check("pixelrag source contract", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_ocr_vlm_replay_check", lambda: smoke._check("pixelrag ocr vlm", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_vlm_route_readiness_check", lambda: smoke._check("pixelrag vlm route", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_vlm_replay_worker_check", lambda: smoke._check("pixelrag vlm worker", "ok", "ok"))
|
||||
@@ -1442,7 +1443,7 @@ def test_collect_ai_automation_smoke_uses_worst_status(monkeypatch):
|
||||
result = smoke.collect_ai_automation_smoke(record_history=False)
|
||||
|
||||
assert result["status"] == "critical"
|
||||
assert result["summary"] == {"ok": 36, "warning": 1, "critical": 1, "total": 38}
|
||||
assert result["summary"] == {"ok": 37, "warning": 1, "critical": 1, "total": 39}
|
||||
|
||||
|
||||
def test_pchome_controlled_apply_drift_monitor_reports_verified_zero_drift(monkeypatch):
|
||||
@@ -3971,6 +3972,7 @@ def test_collect_ai_automation_smoke_persists_recent_history(tmp_path, monkeypat
|
||||
monkeypatch.setattr(smoke, "_sitewide_visual_qa_check", lambda: smoke._check("visual", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_external_mcp_rag_integration_check", lambda: smoke._check("external mcp rag", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_rag_candidate_replay_check", lambda: smoke._check("pixelrag replay", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_source_contract_replay_worker_check", lambda: smoke._check("pixelrag source contract", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_ocr_vlm_replay_check", lambda: smoke._check("pixelrag ocr vlm", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_vlm_route_readiness_check", lambda: smoke._check("pixelrag vlm route", "ok", "ok"))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_vlm_replay_worker_check", lambda: smoke._check("pixelrag vlm worker", "ok", "ok"))
|
||||
@@ -4031,7 +4033,7 @@ def test_scheduled_automation_health_summary_reads_history_without_side_effects(
|
||||
json.dumps({
|
||||
"generated_at": datetime.now().isoformat(timespec="seconds"),
|
||||
"status": "ok",
|
||||
"summary": {"ok": 38, "warning": 0, "critical": 0, "total": 38},
|
||||
"summary": {"ok": 39, "warning": 0, "critical": 0, "total": 39},
|
||||
"checks": [
|
||||
{
|
||||
"name": "PChome 受控落地 drift monitor",
|
||||
@@ -4140,6 +4142,27 @@ def test_scheduled_automation_health_summary_reads_history_without_side_effects(
|
||||
"next_machine_action": "run_ocr_vlm_replay_then_promotion_gate",
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "PixelRAG source-contract replay worker",
|
||||
"status": "ok",
|
||||
"summary": "PixelRAG source-contract replay worker candidates=1, ready=1, blocked=0, dry_run=1, executed=0, receipts=0",
|
||||
"details": {
|
||||
"policy": "controlled_pixelrag_source_contract_replay_worker_v1",
|
||||
"candidate_count": 1,
|
||||
"ready_count": 1,
|
||||
"blocked_count": 0,
|
||||
"dry_run_count": 1,
|
||||
"executed_count": 0,
|
||||
"receipt_written_count": 0,
|
||||
"capture_runtime_gap_count": 0,
|
||||
"network_call_performed": False,
|
||||
"model_call_performed": False,
|
||||
"artifact_write_performed": False,
|
||||
"next_machine_action": "run_pixelrag_source_contract_replay_worker_execute",
|
||||
"writes_database_count": 0,
|
||||
"primary_human_gate_count": 0,
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "PixelRAG OCR/VLM replay contract",
|
||||
"status": "ok",
|
||||
@@ -4254,7 +4277,7 @@ def test_scheduled_automation_health_summary_reads_history_without_side_effects(
|
||||
)
|
||||
assert summary["policy"] == "read_only_ai_automation_scheduled_health_summary"
|
||||
assert summary["status"] == "ok"
|
||||
assert summary["summary"]["total"] == 35
|
||||
assert summary["summary"]["total"] == 36
|
||||
assert summary["summary"]["primary_human_gate_count"] == 0
|
||||
assert summary["summary"]["writes_database_count"] == 0
|
||||
assert pchome_family["status"] == "ok"
|
||||
@@ -6586,6 +6609,11 @@ def test_surface_html_readback_check_is_part_of_ai_smoke(monkeypatch):
|
||||
"ok",
|
||||
"pixelrag replay ok",
|
||||
))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_source_contract_replay_worker_check", lambda: smoke._check(
|
||||
"PixelRAG source-contract replay worker",
|
||||
"ok",
|
||||
"pixelrag source contract ok",
|
||||
))
|
||||
monkeypatch.setattr(smoke, "_pixelrag_ocr_vlm_replay_check", lambda: smoke._check(
|
||||
"PixelRAG OCR/VLM replay contract",
|
||||
"ok",
|
||||
@@ -6626,7 +6654,7 @@ def test_surface_html_readback_check_is_part_of_ai_smoke(monkeypatch):
|
||||
item for item in result["checks"]
|
||||
if item["name"] == "Sitewide visual QA readback"
|
||||
)
|
||||
assert result["summary"]["total"] == 38
|
||||
assert result["summary"]["total"] == 39
|
||||
assert surface_check["status"] == "ok"
|
||||
assert surface_check["details"]["checked_surface_count"] == 10
|
||||
assert sitewide_check["status"] == "ok"
|
||||
|
||||
169
tests/test_pixelrag_source_contract_replay_worker_service.py
Normal file
169
tests/test_pixelrag_source_contract_replay_worker_service.py
Normal file
@@ -0,0 +1,169 @@
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from tests.test_pixelrag_rag_candidate_replay_service import (
|
||||
_write_platform_probe_worker_receipt,
|
||||
)
|
||||
|
||||
|
||||
def test_pixelrag_source_contract_replay_worker_dry_run_reads_worker_receipts(tmp_path):
|
||||
from services.pixelrag_source_contract_replay_worker_service import (
|
||||
POLICY,
|
||||
run_pixelrag_source_contract_replay_worker,
|
||||
)
|
||||
|
||||
worker_root = tmp_path / "worker"
|
||||
_write_platform_probe_worker_receipt(
|
||||
worker_root,
|
||||
platform="coupang_tw",
|
||||
manifest_id="coupang-403",
|
||||
barrier_type="access_denied",
|
||||
)
|
||||
_write_platform_probe_worker_receipt(
|
||||
worker_root,
|
||||
platform="shopee_tw",
|
||||
manifest_id="shopee-runtime-gap",
|
||||
worker_status="capture_runtime_unavailable_structured_fallback_package",
|
||||
barrier_type="traffic_verification_interstitial",
|
||||
capture_runtime_unavailable=True,
|
||||
)
|
||||
|
||||
payload = run_pixelrag_source_contract_replay_worker(
|
||||
artifact_root=tmp_path / "visual_empty",
|
||||
platform_probe_worker_receipt_root=worker_root,
|
||||
platform=("coupang_tw", "shopee_tw"),
|
||||
)
|
||||
by_platform = {item["platform"]: item for item in payload["worker_items"]}
|
||||
|
||||
assert payload["policy"] == POLICY
|
||||
assert payload["status"] == "ok"
|
||||
assert payload["execute"] is False
|
||||
assert payload["summary"]["candidate_count"] == 2
|
||||
assert payload["summary"]["ready_count"] == 2
|
||||
assert payload["summary"]["dry_run_count"] == 2
|
||||
assert payload["summary"]["capture_runtime_gap_count"] == 1
|
||||
assert payload["summary"]["writes_database_count"] == 0
|
||||
assert payload["controlled_apply"]["network_call"] is False
|
||||
assert payload["controlled_apply"]["writes_database"] is False
|
||||
assert payload["controlled_apply"]["primary_human_gate_count"] == 0
|
||||
assert payload["next_machine_action"] == (
|
||||
"run_pixelrag_source_contract_replay_worker_execute"
|
||||
)
|
||||
assert by_platform["coupang_tw"]["worker_status"] == (
|
||||
"dry_run_ready_for_source_contract_replay"
|
||||
)
|
||||
assert by_platform["coupang_tw"]["source_contract_checks"][
|
||||
"blocked_page_not_product_data"
|
||||
] is True
|
||||
assert by_platform["shopee_tw"]["capture_runtime_unavailable"] is True
|
||||
|
||||
|
||||
def test_pixelrag_source_contract_replay_worker_execute_writes_receipts(tmp_path):
|
||||
from services.pixelrag_source_contract_replay_worker_service import (
|
||||
run_pixelrag_source_contract_replay_worker,
|
||||
)
|
||||
|
||||
worker_root = tmp_path / "worker"
|
||||
output_root = tmp_path / "source_contract_receipts"
|
||||
_write_platform_probe_worker_receipt(
|
||||
worker_root,
|
||||
platform="coupang_tw",
|
||||
manifest_id="coupang-403",
|
||||
barrier_type="access_denied",
|
||||
)
|
||||
|
||||
payload = run_pixelrag_source_contract_replay_worker(
|
||||
artifact_root=tmp_path / "visual_empty",
|
||||
platform_probe_worker_receipt_root=worker_root,
|
||||
output_root=output_root,
|
||||
platform="coupang_tw",
|
||||
execute=True,
|
||||
write_receipt=True,
|
||||
)
|
||||
|
||||
assert payload["status"] == "ok"
|
||||
assert payload["summary"]["executed_count"] == 1
|
||||
assert payload["summary"]["receipt_written_count"] == 1
|
||||
assert payload["controlled_apply"]["artifact_write"] is True
|
||||
assert payload["controlled_apply"]["writes_database"] is False
|
||||
assert payload["next_machine_action"] == (
|
||||
"run_marketplace_source_contract_adapter_replay_preflight"
|
||||
)
|
||||
receipt_path = (
|
||||
output_root
|
||||
/ "coupang_tw"
|
||||
/ "coupang-403"
|
||||
/ "source_contract_replay_receipt.json"
|
||||
)
|
||||
assert receipt_path.exists()
|
||||
receipt = json.loads(receipt_path.read_text(encoding="utf-8"))
|
||||
assert receipt["worker_status"] == "executed_source_contract_replay_ready"
|
||||
assert receipt["artifact_write_performed"] is True
|
||||
assert receipt["writes_database"] is False
|
||||
assert receipt["source_contract_preview"]["source_contract_version"] == (
|
||||
"pixelrag_marketplace_source_contract_v1"
|
||||
)
|
||||
|
||||
|
||||
def test_pixelrag_source_contract_replay_worker_cli_outputs_json(tmp_path):
|
||||
worker_root = tmp_path / "worker"
|
||||
_write_platform_probe_worker_receipt(
|
||||
worker_root,
|
||||
platform="coupang_tw",
|
||||
manifest_id="coupang-403",
|
||||
barrier_type="access_denied",
|
||||
)
|
||||
|
||||
completed = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"scripts/ops/run_pixelrag_source_contract_replay_worker.py",
|
||||
"--artifact-root",
|
||||
str(tmp_path / "visual_empty"),
|
||||
"--platform-probe-worker-receipt-root",
|
||||
str(worker_root),
|
||||
"--platform",
|
||||
"coupang_tw",
|
||||
],
|
||||
capture_output=True,
|
||||
check=False,
|
||||
text=True,
|
||||
)
|
||||
|
||||
assert completed.returncode == 0
|
||||
payload = json.loads(completed.stdout)
|
||||
assert payload["summary"]["candidate_count"] == 1
|
||||
assert payload["summary"]["ready_count"] == 1
|
||||
assert payload["controlled_apply"]["writes_database"] is False
|
||||
|
||||
|
||||
def test_pixelrag_source_contract_replay_worker_route_returns_readback(tmp_path, monkeypatch):
|
||||
from flask import Flask
|
||||
from routes import system_public_routes as routes
|
||||
from services import pixelrag_source_contract_replay_worker_service as service
|
||||
|
||||
worker_root = tmp_path / "worker"
|
||||
_write_platform_probe_worker_receipt(
|
||||
worker_root,
|
||||
platform="coupang_tw",
|
||||
manifest_id="coupang-403",
|
||||
barrier_type="access_denied",
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
service,
|
||||
"DEFAULT_PLATFORM_PROBE_WORKER_RECEIPT_ROOT",
|
||||
str(worker_root),
|
||||
)
|
||||
|
||||
app = Flask(__name__)
|
||||
with app.test_request_context(
|
||||
"/api/ai-automation/pixelrag-source-contract-replay-worker?platform=coupang_tw"
|
||||
):
|
||||
response = routes.ai_automation_pixelrag_source_contract_replay_worker_api.__wrapped__()
|
||||
payload = response.get_json()
|
||||
|
||||
assert payload["policy"] == "controlled_pixelrag_source_contract_replay_worker_v1"
|
||||
assert payload["summary"]["candidate_count"] == 1
|
||||
assert payload["summary"]["ready_count"] == 1
|
||||
assert payload["controlled_apply"]["writes_database"] is False
|
||||
Reference in New Issue
Block a user