feat(clients): runtime: Agent Engine reasoningEngines client, discovery-checked call table, typed deployment spec, demo routes
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check src/google/runtime/calls.cpp against Google's Discovery documents.
|
||||
|
||||
Fails (exit 1) when a declared call is absent, its HTTP method or path
|
||||
differs, or a request body field, query parameter or schema field we use is
|
||||
not in the discovery document. Python 3 stdlib only, no credentials needed.
|
||||
|
||||
python3 -I src/google/runtime/tools/check_discovery.py
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import urllib.request
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
CALLS = os.path.join(HERE, "..", "calls.cpp")
|
||||
URL = "https://aiplatform.googleapis.com/$discovery/rest?version=%s"
|
||||
PREFIX = {"v1": "GoogleCloudAiplatformV1", "v1beta1": "GoogleCloudAiplatformV1beta1"}
|
||||
|
||||
ROW = re.compile(r'^\s*\{(.*)\},?\s*$')
|
||||
STR = re.compile(r'"([^"]*)"')
|
||||
|
||||
|
||||
def block(text, begin, end):
|
||||
a = text.index(begin)
|
||||
b = text.index(end)
|
||||
rows = []
|
||||
for line in text[a:b].splitlines()[1:]:
|
||||
m = ROW.match(line)
|
||||
if m and '"' in line:
|
||||
rows.append(STR.findall(m.group(1)))
|
||||
return rows
|
||||
|
||||
|
||||
def fetch(version):
|
||||
with urllib.request.urlopen(URL % version, timeout=60) as r:
|
||||
return json.load(r)
|
||||
|
||||
|
||||
def methods(node, out):
|
||||
for m in node.get("methods", {}).values():
|
||||
out[m["id"]] = m
|
||||
for child in node.get("resources", {}).values():
|
||||
methods(child, out)
|
||||
|
||||
|
||||
def main():
|
||||
text = open(CALLS).read()
|
||||
calls = block(text, "// CALLS-BEGIN", "// CALLS-END")
|
||||
schemas = block(text, "// SCHEMAS-BEGIN", "// SCHEMAS-END")
|
||||
docs, index = {}, {}
|
||||
for v in ("v1", "v1beta1"):
|
||||
docs[v] = fetch(v)
|
||||
index[v] = {}
|
||||
methods(docs[v], index[v])
|
||||
bad = []
|
||||
for http, path, version, rpc, body, query in calls:
|
||||
m = index[version].get(rpc)
|
||||
if not m:
|
||||
bad.append("missing rpc " + rpc)
|
||||
continue
|
||||
if m["httpMethod"] != http:
|
||||
bad.append("%s: http %s != %s" % (rpc, http, m["httpMethod"]))
|
||||
if m["path"] != path:
|
||||
bad.append("%s: path %s != %s" % (rpc, path, m["path"]))
|
||||
params = m.get("parameters", {})
|
||||
for q in filter(None, query.split(",")):
|
||||
if q not in params or params[q].get("location") != "query":
|
||||
bad.append("%s: query param %s absent" % (rpc, q))
|
||||
fields = [f for f in body.split(",") if f]
|
||||
if fields:
|
||||
ref = m.get("request", {}).get("$ref")
|
||||
props = docs[version]["schemas"].get(ref, {}).get("properties", {})
|
||||
for f in fields:
|
||||
if f not in props:
|
||||
bad.append("%s: body field %s absent in %s" % (rpc, f, ref))
|
||||
for name, version, fields in schemas:
|
||||
props = docs[version]["schemas"].get(PREFIX[version] + name, {}).get("properties")
|
||||
if props is None:
|
||||
bad.append("missing schema %s %s" % (version, name))
|
||||
continue
|
||||
for f in fields.split(","):
|
||||
if f not in props:
|
||||
bad.append("schema %s.%s absent" % (name, f))
|
||||
revs = {v: docs[v].get("revision") for v in docs}
|
||||
if bad:
|
||||
print("DISCOVERY CHECK FAILED (revisions %s)" % revs)
|
||||
for b in bad:
|
||||
print(" " + b)
|
||||
return 1
|
||||
print("discovery ok: %d calls, %d schemas, revisions %s" % (len(calls), len(schemas), revs))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user