ЛР 2: PostgreSQL, сессии, Redis и исследование
Skeleton contracts / contracts (pull_request) Failing after 30s
Skeleton contracts / contracts (pull_request) Failing after 30s
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""UI history must page backwards while the required API keeps ascending semantics."""
|
||||
import argparse
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from compose_helpers import sql
|
||||
from client import Client, check, run, shape
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--base-url", default="http://localhost:8080")
|
||||
args = parser.parse_args()
|
||||
client = Client(args.base_url)
|
||||
alice, bob, eve, chat = client.bootstrap()
|
||||
path = "/api/ui/chats/" + chat["id"] + "/messages"
|
||||
client.call("GET", path, 401)
|
||||
client.call("GET", path, 404, actor=eve)
|
||||
members_path = "/api/ui/chats/" + chat["id"] + "/members"
|
||||
client.call("GET", members_path, 401)
|
||||
client.call("GET", members_path, 404, actor=eve)
|
||||
members = json.loads(client.call("GET", members_path, actor=bob)["bytes"])["items"]
|
||||
check({user["id"] for user in members} == {alice["id"], bob["id"]}, "wrong UI member list")
|
||||
for member in members:
|
||||
shape(member, "User") # rejects any password/hash fields in this projection
|
||||
prefix = uuid.uuid4().hex[:20]
|
||||
# Equal timestamps exercise the UUID tie-breaker in both directions.
|
||||
sql(f"""
|
||||
INSERT INTO messages(id, chat_id, sender_id, text, created_at)
|
||||
SELECT ('{prefix}' || lpad(n::text, 12, '0'))::uuid,
|
||||
'{chat['id']}'::uuid, '{alice['id']}'::uuid, 'UI pagination ' || n,
|
||||
'2026-02-01T00:00:00Z'::timestamptz
|
||||
FROM generate_series(1, 75) fixture(n);
|
||||
""")
|
||||
check(int(sql(f"SELECT count(*) FROM messages WHERE chat_id = '{chat['id']}';")) == 75, "UI fixture mismatch")
|
||||
ascending = client.call("GET", "/api/v1/chats/" + chat["id"] + "/messages?limit=50", actor=alice, schema="MessagePage")["json"]
|
||||
recent = client.call("GET", path + "?limit=50", actor=bob, schema="MessagePage")["json"]
|
||||
older = client.call("GET", path + "?limit=50&cursor=" + recent["next_cursor"], actor=bob, schema="MessagePage")["json"]
|
||||
check([item["id"] for item in ascending["items"]] == sorted(item["id"] for item in ascending["items"]), "required history changed order")
|
||||
check([item["id"] for item in recent["items"]] == sorted((item["id"] for item in recent["items"]), reverse=True), "UI history is not newest first")
|
||||
all_items = recent["items"] + older["items"]
|
||||
check(len(all_items) == 75 and len({item["id"] for item in all_items}) == 75 and older["next_cursor"] is None,
|
||||
"UI pagination lost or repeated equal-time messages")
|
||||
client.call("GET", path + "?cursor=" + ascending["next_cursor"], 400, actor=alice)
|
||||
client.call("GET", "/api/v1/chats/" + chat["id"] + "/messages?cursor=" + recent["next_cursor"], 400, actor=alice)
|
||||
print("PASS: UI authentication, privacy, newest page, backwards pagination, cursor isolation; required API stays ascending")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(main)
|
||||
Reference in New Issue
Block a user