Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import hashlib
import re
from datetime import UTC, datetime, timedelta
from typing import Any

import config
import didkey
Expand Down Expand Up @@ -488,7 +489,7 @@ def openapi_document(base: str, version: str, max_body_bytes: int, max_wait: flo
publishing the path of a token-gated endpoint that answers 404 rather than 401 would
undo the reason it answers 404.
"""
return {
doc = {
"openapi": "3.1.0",
"info": {
"title": "technocore-chat",
Expand Down Expand Up @@ -1322,6 +1323,14 @@ def openapi_document(base: str, version: str, max_body_bytes: int, max_wait: flo
},
},
}
# `/r/events` is read by the `/r/{room}` handler, so it takes that lane's query
# parameters. Derived rather than copied: a parameter added to the room read is
# published on both the day it lands, and the description here cannot promise a
# `since` the operation does not declare.
room_query = [p for p in doc["paths"]["/r/{room}"]["get"]["parameters"] if p["in"] == "query"]
events_read: dict[str, Any] = doc["paths"]["/r/events"]["get"]
events_read["parameters"] = room_query
return doc


def agent_manifest(
Expand Down
25 changes: 25 additions & 0 deletions tests/http/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,31 @@ def test_every_negotiable_response_publishes_the_switch_that_negotiates_it(clien
)


def test_the_discovery_lane_publishes_the_parameters_it_reads(client):
"""`/r/events` is served by the `/r/{room}` handler, and its own description says
`since`, `format` and `wait` all apply. It published `format` alone, so a client
generated from the contract could not pass the cursor the operation promises, and the
long-poll the manual tells a reader to use was undiscoverable. Derived from the room
read lane now, so the two cannot drift apart again.
"""
doc = client.get("/openapi.json").json()
events = doc["paths"]["/r/events"]["get"]
room = doc["paths"]["/r/{room}"]["get"]

published = [p["name"] for p in events["parameters"] if p["in"] == "query"]
assert published == [p["name"] for p in room["parameters"] if p["in"] == "query"]
assert {"since", "limit", "wait", "format"} <= set(published)

# And they are the ones the server honours on that path, not just names in a document.
client.get("/r/one-event-room/say/bot/hello")
full = client.get("/r/events?format=json").json()
assert full["count"] >= 1
assert client.get("/r/events?format=json&limit=1").json()["count"] == 1
head = client.get(f"/r/events?format=json&since={full['last_seq']}").json()
assert head["count"] == 0
assert head["last_seq"] == full["last_seq"]


def test_a_published_ceiling_is_a_number_json_can_carry(client, monkeypatch):
"""`float()` accepts `inf` and `nan` where the `int()` beside it raises, and this setting's
value is published. A non-finite ceiling reaches /openapi.json and
Expand Down
Loading