Harden VedAstro adapter and index PyJHora artifacts

This commit is contained in:
732642856
2026-06-27 14:26:28 +08:00
parent 6f46805fab
commit eb05dc3959
6 changed files with 433 additions and 9 deletions
@@ -0,0 +1,37 @@
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_pyjhora_oracle_artifact_manifest_reports_current_blackbox_assets() -> None:
completed = subprocess.run(
[sys.executable, "scripts/generate_pyjhora_oracle_artifact_manifest.py"],
cwd=ROOT,
text=True,
capture_output=True,
timeout=120,
check=False,
)
assert completed.returncode == 0, completed.stderr or completed.stdout
report = json.loads(completed.stdout)
assert report["scope"] == "pyjhora_oracle_artifact_manifest"
assert report["artifact_count"] >= 5
assert report["packet_count"] >= 4
assert report["fronts"]["dasha"]["artifact_count"] >= 2
assert report["fronts"]["shadbala"]["artifact_count"] >= 2
assert report["fronts"]["tajika_sahams"]["artifact_count"] >= 1
assert report["files"]["manifest"].endswith("references/oracle/artifacts/pyjhora_oracle_artifact_manifest.json")
manifest = ROOT / "references" / "oracle" / "artifacts" / "pyjhora_oracle_artifact_manifest.json"
assert manifest.exists()
manifest_data = json.loads(manifest.read_text(encoding="utf-8"))
assert manifest_data["scope"] == "pyjhora_oracle_artifact_manifest"
assert "pyjhora_steve_jobs_dasha_stdout_20260627.txt" in manifest_data["artifacts"]
assert "external_template_steve_jobs_dasha_lahiri_pyjhora_20260627.json" in manifest_data["pending_packets"]
@@ -198,3 +198,83 @@ def test_vedastro_service_adapter_classifies_http_error() -> None:
report = json.loads(completed.stdout)
assert report["status"] == "http_error"
assert "503" in report["reason"]
def test_vedastro_service_adapter_classifies_invalid_json_response() -> None:
class Handler(BaseHTTPRequestHandler):
def do_POST(self) -> None: # noqa: N802
body = b"not-json"
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format: str, *args) -> None: # noqa: A003
return
server = HTTPServer(("127.0.0.1", 0), Handler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
env = os.environ.copy()
env["VEDASTRO_API_ENDPOINT"] = f"http://127.0.0.1:{server.server_port}/vedastro"
env["VEDASTRO_ENABLE_NETWORK"] = "1"
completed = subprocess.run(
[sys.executable, "scripts/vedastro_service_adapter.py", "--case", "beijing_first_use_demo"],
cwd=ROOT,
text=True,
capture_output=True,
timeout=120,
check=False,
env=env,
)
finally:
server.shutdown()
thread.join(timeout=5)
assert completed.returncode == 0, completed.stderr or completed.stdout
report = json.loads(completed.stdout)
assert report["status"] == "invalid_json"
def test_vedastro_service_adapter_classifies_timeout() -> None:
class Handler(BaseHTTPRequestHandler):
def do_POST(self) -> None: # noqa: N802
import time
time.sleep(0.2)
body = b"{}"
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, format: str, *args) -> None: # noqa: A003
return
server = HTTPServer(("127.0.0.1", 0), Handler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
try:
env = os.environ.copy()
env["VEDASTRO_API_ENDPOINT"] = f"http://127.0.0.1:{server.server_port}/vedastro"
env["VEDASTRO_ENABLE_NETWORK"] = "1"
env["VEDASTRO_TIMEOUT_SECONDS"] = "0.05"
completed = subprocess.run(
[sys.executable, "scripts/vedastro_service_adapter.py", "--case", "beijing_first_use_demo"],
cwd=ROOT,
text=True,
capture_output=True,
timeout=120,
check=False,
env=env,
)
finally:
server.shutdown()
thread.join(timeout=5)
assert completed.returncode == 0, completed.stderr or completed.stdout
report = json.loads(completed.stdout)
assert report["status"] == "timeout"