feat(clients): registry: Agent Registry, Agent Gateway, Agent Identity from discovery call table

86-row call table checked against Google discovery documents, typed
services, local approval ledger, live read-only tests, /agent/registry demo.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 04:42:00 +02:00
co-authored by Claude Sonnet 5.5
parent 6d744a433f
commit cb70bb1116
55 changed files with 4629 additions and 3 deletions
@@ -0,0 +1,118 @@
#!/usr/bin/env python3
"""Verify the registry call table against Google's discovery documents.
Reads every row of the table in ../calls.cpp, fetches the discovery document
of its service and version (no credential needed), and fails when a row is
not backed by it: unknown rpc method id, different HTTP method or path,
query parameter the method does not list, request schema mismatch, or a
request field that the schema does not have.
python3 -I src/google/registry/tools/check_discovery.py [--cache DIR]
Standard library only. Exit status 0: every row verified.
"""
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")
ROW = re.compile(r'^\s*\{(".*")\},\s*$')
def rows():
out = []
for line in open(CALLS, encoding="utf-8"):
m = ROW.match(line)
if not m:
continue
cols = re.findall(r'"((?:[^"\\]|\\.)*)"', m.group(1))
if len(cols) != 9:
sys.exit("bad table row: " + line.strip())
out.append(dict(zip(
["id", "method", "path", "service", "version", "rpc", "request", "query", "fields"], cols)))
return out
def fetch(service, version, cache):
name = "%s_%s.json" % (service, version)
if cache:
path = os.path.join(cache, name)
if os.path.exists(path):
return json.load(open(path, encoding="utf-8"))
url = "https://%s.googleapis.com/$discovery/rest?version=%s" % (service, version)
with urllib.request.urlopen(url, timeout=60) as r:
data = r.read()
if cache:
os.makedirs(cache, exist_ok=True)
open(os.path.join(cache, name), "wb").write(data)
return json.loads(data)
def methods(doc):
found = {}
def walk(resources):
for r in resources.values():
for m in r.get("methods", {}).values():
found[m["id"]] = m
walk(r.get("resources", {}))
walk(doc.get("resources", {}))
return found
def main():
cache = None
if "--cache" in sys.argv:
cache = sys.argv[sys.argv.index("--cache") + 1]
table = rows()
if not table:
sys.exit("no rows found in calls.cpp")
docs, failures, ids = {}, [], set()
for row in table:
if row["id"] in ids:
failures.append("%s: duplicate id" % row["id"])
ids.add(row["id"])
key = (row["service"], row["version"])
if key not in docs:
doc = fetch(*key, cache)
docs[key] = (doc, methods(doc))
doc, found = docs[key]
m = found.get(row["rpc"])
if m is None:
failures.append("%s: rpc %s not in discovery" % (row["id"], row["rpc"]))
continue
if m["httpMethod"] != row["method"]:
failures.append("%s: method %s != discovery %s" % (row["id"], row["method"], m["httpMethod"]))
want = row["version"] + row["path"]
if m["path"] != want:
failures.append("%s: path %s != discovery %s" % (row["id"], want, m["path"]))
params = m.get("parameters", {})
queries = [] if row["query"] == "-" else row["query"].split(",")
listed = sorted(k for k, v in params.items() if v.get("location") == "query")
for q in queries:
if q not in listed:
failures.append("%s: query %s not listed" % (row["id"], q))
if sorted(queries) != listed:
failures.append("%s: query list differs from discovery %s" % (row["id"], listed))
req = m.get("request", {}).get("$ref", "-")
if req != row["request"]:
failures.append("%s: request %s != discovery %s" % (row["id"], row["request"], req))
if req != "-" and row["fields"] != "-":
props = doc["schemas"].get(req, {}).get("properties", {})
for f in row["fields"].split(","):
if f and f not in props:
failures.append("%s: field %s not in schema %s" % (row["id"], f, req))
print("checked %d calls across %d discovery documents" % (len(table), len(docs)))
for f in failures:
print("FAIL", f)
if failures:
sys.exit(1)
print("OK: every declared call, query parameter and request field is in discovery")
if __name__ == "__main__":
main()