56 lines
3.1 KiB
Python
56 lines
3.1 KiB
Python
"""Exercise the isolated development sidecar with fictional data only."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
# Authentication stays inside the container; neither secrets nor model text are logged.
|
|
program = r'''
|
|
import json
|
|
import os
|
|
import time
|
|
import urllib.request
|
|
|
|
records = []
|
|
def request(path, payload, field):
|
|
started = time.monotonic()
|
|
req = urllib.request.Request("http://127.0.0.1:8001" + path,
|
|
data=json.dumps(payload).encode(),
|
|
headers={"Content-Type": "application/json", "X-AI-Service-Token": os.environ["AI_SERVICE_TOKEN"]})
|
|
with urllib.request.urlopen(req, timeout=240) as response:
|
|
result = json.load(response)
|
|
value = result.get(field)
|
|
assert isinstance(value, str) and value.strip(), "Missing generated content: " + field
|
|
records.append({"path": path, "status": "PASS", "seconds": round(time.monotonic() - started, 3), "characters": len(value)})
|
|
|
|
assert os.environ["OLLAMA_BASE_URL"] == "http://jobjakt-dev-ollama:11434"
|
|
assert os.environ["AI_ROUTING_MODE"] == "local_only"
|
|
assert os.environ["EXTERNAL_AI_ENABLED"].lower() == "false"
|
|
request("/summarize", {"text": "Fictional Systems seeks a software engineer. Responsibilities include developing C# APIs, writing SQL queries and maintaining Docker services. Candidates should communicate clearly and work with a small team. This fictional advertisement is solely a development check.", "max_length": 60, "min_length": 10}, "summary")
|
|
request("/cv/rewrite", {"instruction": "Correct grammar only. Return exactly one sentence. Preserve the facts and add no headings.", "text": "A fictional engineer build reliable software.", "max_length": 48, "min_length": 8}, "rewritten_text")
|
|
print(json.dumps({"status": "PASS", "model": os.environ["OLLAMA_MODEL"], "routing": "local_only", "checks": records,
|
|
"limits": "Synthetic sidecar connectivity and nonempty response only; no factual extraction accuracy or production parity claim."}))
|
|
'''
|
|
identity = json.loads(subprocess.check_output(["rtk", "proxy", "docker", "inspect", "jobjakt-dev-ai-service-1"], text=True))[0]
|
|
assert identity["Config"]["Labels"]["com.docker.compose.project"] == "jobjakt-dev"
|
|
assert identity["Image"] == "sha256:8a29cb90fcc2817b0d784826d55a172c943f5ad7e1b6105e690a2d79ee15fe87"
|
|
result = subprocess.run(["rtk", "proxy", "docker", "exec", "-i", "jobjakt-dev-ai-service-1", "python", "-"],
|
|
input=program, text=True, capture_output=True, timeout=500)
|
|
if result.returncode:
|
|
# Avoid forwarding exception bodies which might contain request data.
|
|
raise SystemExit("Local synthetic sidecar check failed; exit " + str(result.returncode))
|
|
record = json.loads(result.stdout)
|
|
assert record["status"] == "PASS" and len(record["checks"]) == 2
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
args.output.write_text(json.dumps(record, indent=2) + "\n", encoding="utf-8")
|
|
print(json.dumps(record))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|