Harden VedAstro adapter and index PyJHora artifacts
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate a tracked manifest for PyJHora black-box oracle artifacts."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from collections import defaultdict
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ARTIFACTS_DIR = ROOT / "references" / "oracle" / "artifacts"
|
||||
PENDING_DIR = ARTIFACTS_DIR / "pending_packets"
|
||||
OUTPUT_PATH = ARTIFACTS_DIR / "pyjhora_oracle_artifact_manifest.json"
|
||||
|
||||
|
||||
def _front_for_name(name: str) -> str:
|
||||
lowered = name.lower()
|
||||
if "varshaphala" in lowered or "sahams" in lowered or "tajika" in lowered:
|
||||
return "tajika_sahams"
|
||||
if "shadbala" in lowered or "moon_longitude" in lowered:
|
||||
return "shadbala"
|
||||
return "dasha"
|
||||
|
||||
|
||||
def _relative(path: Path) -> str:
|
||||
return str(path.relative_to(ROOT))
|
||||
|
||||
|
||||
def build_manifest() -> dict[str, Any]:
|
||||
artifacts = sorted(
|
||||
path for path in ARTIFACTS_DIR.glob("pyjhora_*")
|
||||
if path.is_file()
|
||||
)
|
||||
pending_packets = sorted(
|
||||
path for path in PENDING_DIR.glob("*pyjhora_20260627.json")
|
||||
if path.is_file()
|
||||
)
|
||||
|
||||
fronts: dict[str, dict[str, Any]] = defaultdict(lambda: {"artifact_count": 0, "packet_count": 0, "artifacts": [], "pending_packets": []})
|
||||
for artifact in artifacts:
|
||||
front = _front_for_name(artifact.name)
|
||||
fronts[front]["artifact_count"] += 1
|
||||
fronts[front]["artifacts"].append(artifact.name)
|
||||
for packet in pending_packets:
|
||||
front = _front_for_name(packet.name)
|
||||
fronts[front]["packet_count"] += 1
|
||||
fronts[front]["pending_packets"].append(packet.name)
|
||||
|
||||
report = {
|
||||
"scope": "pyjhora_oracle_artifact_manifest",
|
||||
"generated_at": datetime.now(timezone.utc).isoformat(),
|
||||
"artifact_count": len(artifacts),
|
||||
"packet_count": len(pending_packets),
|
||||
"artifacts": [path.name for path in artifacts],
|
||||
"pending_packets": [path.name for path in pending_packets],
|
||||
"fronts": {
|
||||
front: {
|
||||
"artifact_count": payload["artifact_count"],
|
||||
"packet_count": payload["packet_count"],
|
||||
"artifacts": payload["artifacts"],
|
||||
"pending_packets": payload["pending_packets"],
|
||||
}
|
||||
for front, payload in sorted(fronts.items())
|
||||
},
|
||||
"files": {
|
||||
"manifest": _relative(OUTPUT_PATH),
|
||||
"artifacts_dir": _relative(ARTIFACTS_DIR),
|
||||
"pending_packets_dir": _relative(PENDING_DIR),
|
||||
},
|
||||
"boundary": (
|
||||
"These files are black-box external evidence only. They document PyJHora outputs and "
|
||||
"pending oracle packets without importing AGPL code into the local skill implementation."
|
||||
),
|
||||
}
|
||||
OUTPUT_PATH.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
||||
return report
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print(json.dumps(build_manifest(), ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -11,6 +11,7 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from urllib import request, error
|
||||
@@ -59,6 +60,7 @@ PARITY_CASES = {
|
||||
}
|
||||
|
||||
DEFAULT_TIMEOUT_SECONDS = 8
|
||||
TIMEOUT_ENV = "VEDASTRO_TIMEOUT_SECONDS"
|
||||
RETRY_POLICY = {
|
||||
"max_attempts": 2,
|
||||
"backoff_seconds": 1,
|
||||
@@ -67,6 +69,16 @@ RETRY_POLICY = {
|
||||
ALLOW_NETWORK_ENV = "VEDASTRO_ENABLE_NETWORK"
|
||||
|
||||
|
||||
def _timeout_seconds() -> float:
|
||||
raw = os.environ.get(TIMEOUT_ENV, "").strip()
|
||||
if not raw:
|
||||
return DEFAULT_TIMEOUT_SECONDS
|
||||
try:
|
||||
return float(raw)
|
||||
except ValueError:
|
||||
return DEFAULT_TIMEOUT_SECONDS
|
||||
|
||||
|
||||
def schema() -> dict[str, Any]:
|
||||
request_example = {
|
||||
**PARITY_CASES["beijing_first_use_demo"],
|
||||
@@ -130,7 +142,7 @@ def _unconfigured(reason: str) -> dict[str, Any]:
|
||||
"endpoint_env": "VEDASTRO_API_ENDPOINT",
|
||||
"api_key_env": "VEDASTRO_API_KEY",
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
},
|
||||
}
|
||||
@@ -156,7 +168,7 @@ def _normalize_success(payload: dict[str, Any], endpoint: str) -> dict[str, Any]
|
||||
"transport": "http_json_service_boundary",
|
||||
"endpoint": endpoint,
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
**(payload.get("source_metadata") or {}),
|
||||
},
|
||||
@@ -189,7 +201,7 @@ def run_case(case_id: str) -> dict[str, Any]:
|
||||
"transport": "http_json_service_boundary",
|
||||
"endpoint": endpoint,
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
"network_execution_env": ALLOW_NETWORK_ENV,
|
||||
},
|
||||
@@ -201,7 +213,7 @@ def run_case(case_id: str) -> dict[str, Any]:
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
with request.urlopen(req, timeout=DEFAULT_TIMEOUT_SECONDS) as resp:
|
||||
with request.urlopen(req, timeout=_timeout_seconds()) as resp:
|
||||
raw = resp.read().decode("utf-8")
|
||||
payload = json.loads(raw)
|
||||
except error.HTTPError as exc:
|
||||
@@ -215,7 +227,7 @@ def run_case(case_id: str) -> dict[str, Any]:
|
||||
"transport": "http_json_service_boundary",
|
||||
"endpoint": endpoint,
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
"network_execution_env": ALLOW_NETWORK_ENV,
|
||||
},
|
||||
@@ -231,12 +243,12 @@ def run_case(case_id: str) -> dict[str, Any]:
|
||||
"transport": "http_json_service_boundary",
|
||||
"endpoint": endpoint,
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
"network_execution_env": ALLOW_NETWORK_ENV,
|
||||
},
|
||||
}
|
||||
except TimeoutError:
|
||||
except (TimeoutError, socket.timeout):
|
||||
return {
|
||||
"backend": "vedastro_service_adapter_candidate",
|
||||
"available": False,
|
||||
@@ -247,7 +259,7 @@ def run_case(case_id: str) -> dict[str, Any]:
|
||||
"transport": "http_json_service_boundary",
|
||||
"endpoint": endpoint,
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
"network_execution_env": ALLOW_NETWORK_ENV,
|
||||
},
|
||||
@@ -263,7 +275,7 @@ def run_case(case_id: str) -> dict[str, Any]:
|
||||
"transport": "http_json_service_boundary",
|
||||
"endpoint": endpoint,
|
||||
"provenance_mode": "external_service_candidate",
|
||||
"timeout_seconds": DEFAULT_TIMEOUT_SECONDS,
|
||||
"timeout_seconds": _timeout_seconds(),
|
||||
"retry_policy": RETRY_POLICY,
|
||||
"network_execution_env": ALLOW_NETWORK_ENV,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user