Files
Jyotisha/scripts/research/generate_varga_api_golden.py
T
66f087b588 feat(rectification): submit varga-resolution implementation for review
Review-only snapshot for BUG-1115 through BUG-1117; not merge-ready. New opening and append-turn PostgreSQL permission failures remain blocked. Persisted joint replay has zero completed questions; segment ordering remains off by default. The existing offline replay JSON is retained stale and unchanged after a denied overwrite, including its CRLF line endings. Browser/provider validation and final serial gates remain pending. No deployment, role permission changes, or staging/main push.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-01 08:04:04 +08:00

61 lines
2.7 KiB
Python

"""Capture real loopback score/scan API responses for the optional metadata contract.
Uses the existing public AA request, never a private profile or a fabricated
engine payload. Run in the calibrated Linux runtime for final evidence.
"""
from __future__ import annotations
import hashlib
import json
import platform
import threading
import urllib.request
from http.server import ThreadingHTTPServer
from pathlib import Path
from scripts.jyotish_api_server import DEFAULT_ALLOWED_HOSTS, DEFAULT_ALLOWED_ORIGINS, JyotishAPIHandler
ROOT = Path(__file__).resolve().parents[2]
def main():
source = ROOT / "frontend/tests/fixtures/rectification-grounding-aa-30min.golden.json"
request = json.loads(source.read_text(encoding="utf-8"))["request"]
server = ThreadingHTTPServer(("127.0.0.1", 0), JyotishAPIHandler)
server.daemon_threads = True
origin = f"http://127.0.0.1:{server.server_port}"
server.allowed_origins = set(DEFAULT_ALLOWED_ORIGINS) | {origin}
server.allowed_hosts = set(DEFAULT_ALLOWED_HOSTS)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
def post(path, body):
req = urllib.request.Request(origin + path, data=json.dumps(body).encode(), method="POST",
headers={"Content-Type": "application/json", "Origin": origin})
with urllib.request.urlopen(req, timeout=180) as response:
return json.load(response)
try:
response = post("/api/rectification/v5/score", request)
intervals = response["decision_receipt"]["candidate_intervals"]
assert len(intervals) == 1
scan_request = {"start_at": intervals[0]["start_at"], "end_at": intervals[0]["end_at"],
"latitude": request["lat"], "longitude": request["lon"],
"timezone_offset": request["tz"], "target_charts": ["D1", "D9", "D10"]}
scan = post("/api/rectification/v5/varga-segments", scan_request)
payload = {"source": "real loopback API; existing public AA calibration request",
"python_version": platform.python_version(),
"source_request_sha256": hashlib.sha256(source.read_bytes()).hexdigest(),
"request": request, "response": response, "scan_request": scan_request, "scan": scan}
target = ROOT / "frontend/tests/fixtures/varga-api-response.golden.json"
target.write_text(json.dumps(payload, ensure_ascii=False, sort_keys=True, indent=2) + "\n", encoding="utf-8")
print("captured real score and minute scan API responses")
finally:
server.shutdown()
thread.join(timeout=10)
server.server_close()
if __name__ == "__main__":
main()