rn-forge-web 0.3.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rn-forge-web might be problematic. Click here for more details.

@@ -0,0 +1,1890 @@
1
+ """HTTP conformance cases consumed by framework-specific test drivers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Collection
6
+ from http import HTTPStatus
7
+ from typing import Final
8
+
9
+ from rn_forge.web.auth import CSRF_FAILED_DETAIL
10
+ from rn_forge.web.conformance.types import (
11
+ REDACTED,
12
+ ConformanceArea,
13
+ ConformanceCapability,
14
+ ConformanceCase,
15
+ RequestSpec,
16
+ )
17
+ from rn_forge.web.merge_patch import MERGE_PATCH_MEDIA_TYPE
18
+ from rn_forge.web.pagination import encode_cursor
19
+ from rn_forge.web.problem import (
20
+ BAD_REQUEST,
21
+ BLANK_TYPE,
22
+ CONFLICT,
23
+ CONTENT_TOO_LARGE,
24
+ CSRF_FAILED,
25
+ FORBIDDEN,
26
+ GENERIC_SERVER_DETAIL,
27
+ INTERNAL_ERROR,
28
+ NOT_FOUND,
29
+ NULL_FIELD_DETAIL,
30
+ PRECONDITION_FAILED,
31
+ PRECONDITION_REQUIRED,
32
+ SERVICE_UNAVAILABLE,
33
+ TOO_MANY_REQUESTS,
34
+ UNAUTHORIZED,
35
+ UNSUPPORTED_MEDIA_TYPE,
36
+ VALIDATION_ERROR,
37
+ ProblemType,
38
+ )
39
+ from rn_forge.web.tracing import EXPOSED_HEADERS
40
+
41
+ __all__ = ["CASES", "case_by_id", "cases_for", "cases_provided_by"]
42
+
43
+ _JSON: Final = {"Content-Type": "application/json"}
44
+ _PROBLEM: Final = {"Content-Type": "application/problem+json"}
45
+ _LINKSET: Final = {"Content-Type": "application/linkset+json"}
46
+
47
+ _TRACEPARENT: Final = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
48
+ """A well-formed W3C traceparent, from the standard's own example."""
49
+
50
+ _SESSION_PATH: Final = "/conformance/session"
51
+ _ORDER_ID_DESC: Final = "id desc"
52
+ _MERGE: Final = {"Content-Type": MERGE_PATCH_MEDIA_TYPE}
53
+ _DOCUMENT_PATH: Final = "/conformance/documents/1"
54
+ _PROFILE_PATH: Final = "/conformance/profiles/1"
55
+ _PROFILE_ADA: Final = {
56
+ "id": "1",
57
+ "displayName": "Ada",
58
+ "address": {"city": "London", "postcode": "N1"},
59
+ "phones": [{"kind": "home", "number": "1"}, {"kind": "work", "number": "2"}],
60
+ "settings": {"theme": "dark"},
61
+ }
62
+ _ITEMS_PATH: Final = "/conformance/items"
63
+ _PEOPLE_PATH: Final = "/conformance/people"
64
+ _ORDER_TEAM_SCORE_DESC: Final = "team,score desc"
65
+ _ITEM_PATH: Final = "/conformance/items/1"
66
+ _ITEM_ETAG: Final = 'W/"1:7"'
67
+ _CHARGES_PATH: Final = "/conformance/charges"
68
+ _READYZ_PATH: Final = "/conformance/readyz"
69
+ _ECHO_PATH: Final = "/conformance/echo"
70
+ _CSV_TYPE: Final = "text/csv"
71
+ _CSV_TYPE_PATTERN: Final = r"text/csv(; charset=utf-8)?"
72
+ _ORDERS_CSV: Final = "id,name\r\n1,widget\r\n"
73
+ _FIRST_CALL_ID: Final = "idempotency.first-call-executes"
74
+ _BOOKS_GET: Final = "/conformance/books:batchGet"
75
+ _BOOKS_UPDATE: Final = "/conformance/books:batchUpdate"
76
+ _STALE_BOOK: Final = "Precondition failed: expected version 1, got 9"
77
+
78
+
79
+ def _problem_body(
80
+ row: ProblemType, detail: str, **extensions: object
81
+ ) -> dict[str, object]:
82
+ """The problem body a driver must produce, already in redacted form.
83
+
84
+ Every case here uses ``about:blank`` (no ``type_base`` configured), so per
85
+ RFC 9457 §4.2.1 the title is the HTTP status phrase, not *row*'s
86
+ kit-specific title.
87
+ """
88
+ return {
89
+ "type": BLANK_TYPE,
90
+ "title": HTTPStatus(row.status).phrase,
91
+ "status": row.status,
92
+ "detail": detail,
93
+ "instance": REDACTED,
94
+ "traceId": REDACTED,
95
+ **extensions,
96
+ }
97
+
98
+
99
+ def _document(**changes: object) -> dict[str, object]:
100
+ """The fixture document, as `GET /conformance/documents/1` serves it fresh."""
101
+ return {
102
+ "id": "1",
103
+ "name": "widget",
104
+ "note": "fragile",
105
+ "tags": ["a", "b"],
106
+ "settings": {"color": "red", "size": "L"},
107
+ **changes,
108
+ }
109
+
110
+
111
+ PAGE_1_NEXT_TOKEN: Final = encode_cursor((), "2")
112
+ ORDERED_PAGE_1_NEXT_TOKEN: Final = encode_cursor(("2",), "2", _ORDER_ID_DESC)
113
+ """The token page one must return.
114
+
115
+ Asserted **exactly**, not redacted. A token is opaque to a *client*; between
116
+ two servers running the same codec over the same keyset it is deterministic,
117
+ and two stacks that emit different tokens for the same page have diverged in a
118
+ way no client-visible field would show.
119
+ """
120
+
121
+ COMPOSITE_PAGE_1_TOKEN: Final = encode_cursor(("a", 10), "1", _ORDER_TEAM_SCORE_DESC)
122
+ COMPOSITE_PAGE_2_TOKEN: Final = encode_cursor(("b", 5), "4", _ORDER_TEAM_SCORE_DESC)
123
+ COMPOSITE_NULL_TOKEN: Final = encode_cursor(("a", None), "3", _ORDER_TEAM_SCORE_DESC)
124
+
125
+ _PEOPLE: Final = {
126
+ 1: ("a", 10),
127
+ 2: ("b", None),
128
+ 3: ("a", None),
129
+ 4: ("b", 5),
130
+ 5: ("a", 10),
131
+ }
132
+
133
+
134
+ def _people(*ids: int) -> list[dict[str, object]]:
135
+ """The ``/conformance/people`` items with these ids, in this order."""
136
+ return [{"id": str(i), "team": _PEOPLE[i][0], "score": _PEOPLE[i][1]} for i in ids]
137
+
138
+
139
+ _NOTES_PATH: Final = "/conformance/notes"
140
+ _NOTE_1: Final = "/conformance/notes/1"
141
+ _NOTE_2: Final = "/conformance/notes/2"
142
+ _NOTE_3: Final = "/conformance/notes/3"
143
+
144
+
145
+ def _note(id: str, text: str, delete_time: str | None = None) -> dict[str, object]:
146
+ return {"id": id, "text": text, "deleteTime": delete_time}
147
+
148
+
149
+ CASES: Final[tuple[ConformanceCase, ...]] = (
150
+ # --- Problem bodies (problem.py) -------------------------------
151
+ ConformanceCase(
152
+ id="problem.unregistered-is-500-without-detail",
153
+ area="problem",
154
+ description=(
155
+ "An exception with no registry row falls back to internal-error, and "
156
+ "its detail is the generic string — str(exc) at 5xx leaks internals."
157
+ ),
158
+ request=RequestSpec("GET", "/conformance/boom"),
159
+ expect_status=500,
160
+ expect_headers=_PROBLEM,
161
+ expect_body=_problem_body(INTERNAL_ERROR, GENERIC_SERVER_DETAIL),
162
+ ),
163
+ ConformanceCase(
164
+ id="problem.registered-domain-conflict-is-409",
165
+ area="problem",
166
+ description="A registered DomainConflict resolves to conflict/409 with str(exc) as the detail.",
167
+ request=RequestSpec("GET", "/conformance/conflict"),
168
+ expect_status=409,
169
+ expect_headers=_PROBLEM,
170
+ expect_body=_problem_body(CONFLICT, "Order already dispatched"),
171
+ ),
172
+ ConformanceCase(
173
+ id="problem.framework-404-is-a-problem-body",
174
+ area="problem",
175
+ description=(
176
+ "A 404 raised by the framework's own routing, not by application code, "
177
+ "still comes back as problem+json rather than the framework's default page."
178
+ ),
179
+ request=RequestSpec("GET", "/conformance/missing"),
180
+ expect_status=404,
181
+ expect_headers=_PROBLEM,
182
+ expect_body=_problem_body(NOT_FOUND, "Not Found"),
183
+ ),
184
+ ConformanceCase(
185
+ id="problem.validation-errors-are-rfc6901-pointers",
186
+ area="problem",
187
+ description=(
188
+ "The single most drift-prone case: DRF's {field: [msg]} and pydantic's "
189
+ "loc/msg list must normalize to the identical pointer list."
190
+ ),
191
+ request=RequestSpec("POST", "/conformance/validate", headers=_JSON, body={}),
192
+ expect_status=422,
193
+ expect_headers=_PROBLEM,
194
+ expect_body=_problem_body(
195
+ VALIDATION_ERROR,
196
+ "Validation Error",
197
+ errors=[{"pointer": "/name", "detail": "This field is required."}],
198
+ ),
199
+ ),
200
+ # --- Concurrency (concurrency.py) ------------------------------
201
+ ConformanceCase(
202
+ id="concurrency.absent-if-match-on-required-route-is-428",
203
+ area="concurrency",
204
+ description="RFC 6585 §3: the route demands a precondition and none was sent.",
205
+ request=RequestSpec("PATCH", _ITEM_PATH, headers=_JSON, body={}),
206
+ expect_status=428,
207
+ expect_headers=_PROBLEM,
208
+ expect_body=_problem_body(
209
+ PRECONDITION_REQUIRED, "This endpoint requires an If-Match precondition"
210
+ ),
211
+ ),
212
+ ConformanceCase(
213
+ id="concurrency.stale-if-match-is-412-not-409",
214
+ area="concurrency",
215
+ description=(
216
+ "RFC 9110 §15.5.13: the precondition evaluated to false. 412, not 409."
217
+ ),
218
+ request=RequestSpec(
219
+ "PATCH",
220
+ _ITEM_PATH,
221
+ headers={**_JSON, "If-Match": 'W/"1:6"'},
222
+ body={},
223
+ ),
224
+ expect_status=412,
225
+ expect_headers=_PROBLEM,
226
+ expect_body=_problem_body(
227
+ PRECONDITION_FAILED, "Precondition failed: expected version 7, got 6"
228
+ ),
229
+ ),
230
+ ConformanceCase(
231
+ id="concurrency.star-if-match-passes",
232
+ area="concurrency",
233
+ description="RFC 9110 §13.1.1: `*` matches any current representation.",
234
+ request=RequestSpec(
235
+ "PATCH",
236
+ _ITEM_PATH,
237
+ headers={**_JSON, "If-Match": "*"},
238
+ body={},
239
+ ),
240
+ expect_status=200,
241
+ expect_headers=_JSON,
242
+ expect_body={"id": "1", "version": 7},
243
+ ),
244
+ ConformanceCase(
245
+ id="concurrency.malformed-if-match-is-400",
246
+ area="concurrency",
247
+ description="An unparseable validator is a 400, never a crash and never a 412.",
248
+ request=RequestSpec(
249
+ "PATCH",
250
+ _ITEM_PATH,
251
+ headers={**_JSON, "If-Match": "not-an-etag"},
252
+ body={},
253
+ ),
254
+ expect_status=400,
255
+ expect_headers=_PROBLEM,
256
+ expect_body=_problem_body(
257
+ BAD_REQUEST, "Malformed If-Match validator: not-an-etag"
258
+ ),
259
+ ),
260
+ ConformanceCase(
261
+ id="concurrency.if-none-match-matches-is-304",
262
+ area="concurrency",
263
+ description=(
264
+ "RFC 9110 §13.1.2, §15.4.5: a GET whose If-None-Match weakly matches "
265
+ "the current ETag gets 304, no body, ETag repeated."
266
+ ),
267
+ request=RequestSpec("GET", _ITEM_PATH, headers={"If-None-Match": _ITEM_ETAG}),
268
+ expect_status=304,
269
+ expect_headers={"ETag": _ITEM_ETAG},
270
+ expect_body={},
271
+ ),
272
+ ConformanceCase(
273
+ id="concurrency.if-none-match-mismatch-is-200",
274
+ area="concurrency",
275
+ description="A stale If-None-Match is an ordinary 200 with the current ETag.",
276
+ request=RequestSpec("GET", _ITEM_PATH, headers={"If-None-Match": 'W/"1:1"'}),
277
+ expect_status=200,
278
+ expect_headers={**_JSON, "ETag": _ITEM_ETAG},
279
+ expect_body={"id": "1", "version": 7},
280
+ ),
281
+ # --- Pagination (pagination.py) --------------------------------------
282
+ ConformanceCase(
283
+ id="pagination.first-page-carries-a-next-token",
284
+ area="pagination",
285
+ description="The AIP-158 envelope: items + nextPageToken, and totalSize absent by default.",
286
+ request=RequestSpec("GET", _ITEMS_PATH, query={"pageSize": "2"}),
287
+ expect_status=200,
288
+ expect_headers=_JSON,
289
+ expect_body={
290
+ "items": [{"id": "1"}, {"id": "2"}],
291
+ "nextPageToken": PAGE_1_NEXT_TOKEN,
292
+ },
293
+ ),
294
+ ConformanceCase(
295
+ id="pagination.last-page-has-a-null-next-token",
296
+ area="pagination",
297
+ description=(
298
+ "nextPageToken is present and null on the last page rather than omitted, "
299
+ "so a generated client's type does not change shape between pages."
300
+ ),
301
+ request=RequestSpec(
302
+ "GET",
303
+ _ITEMS_PATH,
304
+ query={"pageSize": "2", "pageToken": PAGE_1_NEXT_TOKEN},
305
+ ),
306
+ expect_status=200,
307
+ expect_headers=_JSON,
308
+ expect_body={"items": [{"id": "3"}], "nextPageToken": None},
309
+ ),
310
+ ConformanceCase(
311
+ id="pagination.oversized-page-size-is-clamped-not-rejected",
312
+ area="pagination",
313
+ description=(
314
+ "AIP-158: coerce down to the maximum. A FastAPI Query(le=...) would 422 here, "
315
+ "and that is the divergence this case exists to catch."
316
+ ),
317
+ request=RequestSpec("GET", _ITEMS_PATH, query={"pageSize": "1000"}),
318
+ expect_status=200,
319
+ expect_headers=_JSON,
320
+ expect_body={
321
+ "items": [{"id": "1"}, {"id": "2"}],
322
+ "nextPageToken": PAGE_1_NEXT_TOKEN,
323
+ },
324
+ ),
325
+ ConformanceCase(
326
+ id="pagination.tampered-page-token-is-400",
327
+ area="pagination",
328
+ description="A malformed opaque token is InvalidCursor → 400, never a 500.",
329
+ request=RequestSpec(
330
+ "GET", _ITEMS_PATH, query={"pageToken": "!!!not-base64!!!"}
331
+ ),
332
+ expect_status=400,
333
+ expect_headers=_PROBLEM,
334
+ expect_body=_problem_body(BAD_REQUEST, "Malformed page token"),
335
+ ),
336
+ ConformanceCase(
337
+ id="pagination.order-by-descending-binds-the-token",
338
+ area="pagination",
339
+ description=(
340
+ "AIP-132: orderBy reorders the list, and the next token carries that "
341
+ "order so it cannot be replayed under another."
342
+ ),
343
+ request=RequestSpec(
344
+ "GET",
345
+ _ITEMS_PATH,
346
+ query={"pageSize": "2", "orderBy": _ORDER_ID_DESC},
347
+ ),
348
+ expect_status=200,
349
+ expect_headers=_JSON,
350
+ expect_body={
351
+ "items": [{"id": "3"}, {"id": "2"}],
352
+ "nextPageToken": ORDERED_PAGE_1_NEXT_TOKEN,
353
+ },
354
+ ),
355
+ ConformanceCase(
356
+ id="pagination.order-by-unlisted-field-is-400",
357
+ area="pagination",
358
+ description="An orderBy field the endpoint does not list is a 400, never silently ignored.",
359
+ request=RequestSpec("GET", _ITEMS_PATH, query={"orderBy": "secret"}),
360
+ expect_status=400,
361
+ expect_headers=_PROBLEM,
362
+ expect_body=_problem_body(BAD_REQUEST, "Cannot order by 'secret'; allowed: id"),
363
+ ),
364
+ ConformanceCase(
365
+ id="pagination.order-by-several-fields-sorts-by-each-in-turn",
366
+ area="pagination",
367
+ description=(
368
+ "AIP-132: orderBy is a comma-separated list; each term breaks the "
369
+ "ties of the one before, with its own direction."
370
+ ),
371
+ request=RequestSpec(
372
+ "GET",
373
+ _PEOPLE_PATH,
374
+ query={"orderBy": _ORDER_TEAM_SCORE_DESC, "pageSize": "5"},
375
+ ),
376
+ expect_status=200,
377
+ expect_headers=_JSON,
378
+ expect_body={"items": _people(5, 1, 3, 4, 2), "nextPageToken": None},
379
+ ),
380
+ ConformanceCase(
381
+ id="pagination.nulls-sort-last-ascending",
382
+ area="pagination",
383
+ description="Rows whose value is null come after those that have one, ascending.",
384
+ request=RequestSpec("GET", _PEOPLE_PATH, query={"orderBy": "score"}),
385
+ expect_status=200,
386
+ expect_headers=_JSON,
387
+ expect_body={"items": _people(4, 1, 5, 2, 3), "nextPageToken": None},
388
+ ),
389
+ ConformanceCase(
390
+ id="pagination.nulls-sort-last-descending",
391
+ area="pagination",
392
+ description="Rows whose value is null come after those that have one, descending too.",
393
+ request=RequestSpec("GET", _PEOPLE_PATH, query={"orderBy": "score desc"}),
394
+ expect_status=200,
395
+ expect_headers=_JSON,
396
+ expect_body={"items": _people(5, 1, 4, 3, 2), "nextPageToken": None},
397
+ ),
398
+ ConformanceCase(
399
+ id="pagination.first-page-carries-a-composite-token",
400
+ area="pagination",
401
+ description=(
402
+ "The token holds one sort value per orderBy term, so the next page "
403
+ "can resume from the whole order."
404
+ ),
405
+ request=RequestSpec(
406
+ "GET",
407
+ _PEOPLE_PATH,
408
+ query={"orderBy": _ORDER_TEAM_SCORE_DESC, "pageSize": "2"},
409
+ ),
410
+ expect_status=200,
411
+ expect_headers=_JSON,
412
+ expect_body={"items": _people(5, 1), "nextPageToken": COMPOSITE_PAGE_1_TOKEN},
413
+ ),
414
+ ConformanceCase(
415
+ id="pagination.composite-token-resumes-within-a-tie",
416
+ area="pagination",
417
+ description="Rows tied on every term but the key are neither skipped nor repeated.",
418
+ request=RequestSpec(
419
+ "GET",
420
+ _PEOPLE_PATH,
421
+ query={
422
+ "orderBy": _ORDER_TEAM_SCORE_DESC,
423
+ "pageSize": "2",
424
+ "pageToken": COMPOSITE_PAGE_1_TOKEN,
425
+ },
426
+ ),
427
+ expect_status=200,
428
+ expect_headers=_JSON,
429
+ expect_body={"items": _people(3, 4), "nextPageToken": COMPOSITE_PAGE_2_TOKEN},
430
+ ),
431
+ ConformanceCase(
432
+ id="pagination.composite-token-resumes-after-a-null",
433
+ area="pagination",
434
+ description="A token whose last value is null resumes among the rows that are null there.",
435
+ request=RequestSpec(
436
+ "GET",
437
+ _PEOPLE_PATH,
438
+ query={
439
+ "orderBy": _ORDER_TEAM_SCORE_DESC,
440
+ "pageSize": "3",
441
+ "pageToken": COMPOSITE_NULL_TOKEN,
442
+ },
443
+ ),
444
+ expect_status=200,
445
+ expect_headers=_JSON,
446
+ expect_body={"items": _people(4, 2), "nextPageToken": None},
447
+ ),
448
+ ConformanceCase(
449
+ id="pagination.repeated-order-by-field-is-400",
450
+ area="pagination",
451
+ description="A field named twice in orderBy is a 400, never silently ignored.",
452
+ request=RequestSpec("GET", _PEOPLE_PATH, query={"orderBy": "team,team desc"}),
453
+ expect_status=400,
454
+ expect_headers=_PROBLEM,
455
+ expect_body=_problem_body(BAD_REQUEST, "orderBy names 'team' more than once"),
456
+ ),
457
+ ConformanceCase(
458
+ id="pagination.token-with-the-wrong-number-of-values-is-400",
459
+ area="pagination",
460
+ description="A token with fewer values than orderBy has terms is rejected as malformed.",
461
+ request=RequestSpec(
462
+ "GET",
463
+ _PEOPLE_PATH,
464
+ query={
465
+ "orderBy": _ORDER_TEAM_SCORE_DESC,
466
+ "pageToken": encode_cursor(("a",), "1", _ORDER_TEAM_SCORE_DESC),
467
+ },
468
+ ),
469
+ expect_status=400,
470
+ expect_headers=_PROBLEM,
471
+ expect_body=_problem_body(BAD_REQUEST, "Malformed page token"),
472
+ ),
473
+ ConformanceCase(
474
+ id="pagination.token-under-a-different-order-by-is-400",
475
+ area="pagination",
476
+ description="A token issued for the default order is rejected once orderBy changes.",
477
+ request=RequestSpec(
478
+ "GET",
479
+ _ITEMS_PATH,
480
+ query={"orderBy": _ORDER_ID_DESC, "pageToken": PAGE_1_NEXT_TOKEN},
481
+ ),
482
+ expect_status=400,
483
+ expect_headers=_PROBLEM,
484
+ expect_body=_problem_body(BAD_REQUEST, "pageToken does not match orderBy"),
485
+ ),
486
+ # --- Idempotency (idempotency.py) ------------------------------------
487
+ ConformanceCase(
488
+ id=_FIRST_CALL_ID,
489
+ area="idempotency",
490
+ description="First sight of a key: the handler runs and its response is stored.",
491
+ request=RequestSpec(
492
+ "POST",
493
+ _CHARGES_PATH,
494
+ headers={**_JSON, "Idempotency-Key": "k-1"},
495
+ body={"amount": 100},
496
+ ),
497
+ expect_status=201,
498
+ expect_headers=_JSON,
499
+ expect_body={"charged": 100, "replayed": False},
500
+ ),
501
+ ConformanceCase(
502
+ id="idempotency.replay-returns-the-stored-response",
503
+ area="idempotency",
504
+ description=(
505
+ "The same key and the same body replays the stored response, "
506
+ "including its original status."
507
+ ),
508
+ depends_on=(_FIRST_CALL_ID,),
509
+ request=RequestSpec(
510
+ "POST",
511
+ _CHARGES_PATH,
512
+ headers={**_JSON, "Idempotency-Key": "k-1"},
513
+ body={"amount": 100},
514
+ ),
515
+ expect_status=201,
516
+ expect_headers=_JSON,
517
+ expect_body={"charged": 100, "replayed": True},
518
+ ),
519
+ ConformanceCase(
520
+ id="idempotency.same-key-different-body-is-422",
521
+ area="idempotency",
522
+ description=(
523
+ "Body hashing is the whole point of the module: a replayed key with a "
524
+ "different body is a detectable client bug, not a silently-wrong replay. "
525
+ "422 per draft-ietf-httpapi-idempotency-key-header §2.7."
526
+ ),
527
+ depends_on=(_FIRST_CALL_ID,),
528
+ request=RequestSpec(
529
+ "POST",
530
+ _CHARGES_PATH,
531
+ headers={**_JSON, "Idempotency-Key": "k-1"},
532
+ body={"amount": 999},
533
+ ),
534
+ expect_status=422,
535
+ expect_headers=_PROBLEM,
536
+ expect_body=_problem_body(
537
+ VALIDATION_ERROR,
538
+ "Idempotency key k-1 was replayed with a different request body",
539
+ ),
540
+ ),
541
+ # --- Health (health.py) ------------------------------------------------
542
+ ConformanceCase(
543
+ id="health.all-pass-is-200",
544
+ area="health",
545
+ description="Every check passes; the aggregate is pass and the status is 200.",
546
+ request=RequestSpec("GET", _READYZ_PATH),
547
+ expect_status=200,
548
+ expect_headers=_JSON,
549
+ expect_body={
550
+ "status": "pass",
551
+ "checks": {
552
+ "db": {
553
+ "status": "pass",
554
+ "reason": None,
555
+ "remediation": None,
556
+ "details": {},
557
+ },
558
+ "queue": {
559
+ "status": "pass",
560
+ "reason": None,
561
+ "remediation": None,
562
+ "details": {},
563
+ },
564
+ },
565
+ },
566
+ ),
567
+ ConformanceCase(
568
+ id="health.required-failure-is-503",
569
+ area="health",
570
+ description="A failing check named in `required` takes the endpoint to 503.",
571
+ request=RequestSpec("GET", _READYZ_PATH, query={"fail": "db"}),
572
+ expect_status=503,
573
+ # Not problem+json: a readiness report is the endpoint's normal
574
+ # representation, and the 503 is its verdict rather than an error.
575
+ expect_headers=_JSON,
576
+ expect_body={
577
+ "status": "fail",
578
+ "checks": {
579
+ "db": {
580
+ "status": "fail",
581
+ "reason": "unreachable",
582
+ "remediation": None,
583
+ "details": {},
584
+ },
585
+ "queue": {
586
+ "status": "pass",
587
+ "reason": None,
588
+ "remediation": None,
589
+ "details": {},
590
+ },
591
+ },
592
+ },
593
+ ),
594
+ ConformanceCase(
595
+ id="health.optional-failure-is-200-degraded",
596
+ area="health",
597
+ description=(
598
+ "A failing check outside `required` degrades the aggregate status but "
599
+ "leaves the HTTP status at 200 — the load balancer keeps sending traffic."
600
+ ),
601
+ request=RequestSpec("GET", _READYZ_PATH, query={"fail": "queue"}),
602
+ expect_status=200,
603
+ expect_headers=_JSON,
604
+ expect_body={
605
+ "status": "fail",
606
+ "checks": {
607
+ "db": {
608
+ "status": "pass",
609
+ "reason": None,
610
+ "remediation": None,
611
+ "details": {},
612
+ },
613
+ "queue": {
614
+ "status": "fail",
615
+ "reason": "unreachable",
616
+ "remediation": None,
617
+ "details": {},
618
+ },
619
+ },
620
+ },
621
+ ),
622
+ ConformanceCase(
623
+ id="problem.content-too-large-is-413",
624
+ area="problem",
625
+ description="RFC 9110 §15.5.14. A body over the configured limit is 413.",
626
+ request=RequestSpec("POST", "/conformance/validate", body={"name": "x" * 250}),
627
+ expect_status=413,
628
+ expect_headers=_PROBLEM,
629
+ expect_body=_problem_body(
630
+ CONTENT_TOO_LARGE, "Request body exceeds the configured limit"
631
+ ),
632
+ ),
633
+ ConformanceCase(
634
+ id="problem.too-many-requests-carries-retry-after",
635
+ area="problem",
636
+ description="RFC 6585 §4. A 429 carries `Retry-After` in seconds.",
637
+ request=RequestSpec("GET", "/conformance/throttled"),
638
+ expect_status=429,
639
+ expect_headers={**_PROBLEM, "Retry-After": "30"},
640
+ expect_body=_problem_body(TOO_MANY_REQUESTS, "Too many requests"),
641
+ ),
642
+ ConformanceCase(
643
+ id="problem.service-unavailable-carries-retry-after",
644
+ area="problem",
645
+ description="RFC 9110 §15.6.4. A 503 problem carries `Retry-After` in seconds.",
646
+ request=RequestSpec("GET", "/conformance/unavailable"),
647
+ expect_status=503,
648
+ expect_headers={**_PROBLEM, "Retry-After": "5"},
649
+ expect_body=_problem_body(SERVICE_UNAVAILABLE, GENERIC_SERVER_DETAIL),
650
+ ),
651
+ ConformanceCase(
652
+ id="health.liveness-is-200",
653
+ area="health",
654
+ description="Liveness touches no dependency and always answers 200.",
655
+ request=RequestSpec("GET", "/conformance/livez"),
656
+ expect_status=200,
657
+ expect_headers=_JSON,
658
+ expect_body={"status": "pass"},
659
+ ),
660
+ # --- Auth (auth.py) -------------------------------------------------
661
+ ConformanceCase(
662
+ id="auth.no-credentials-is-401-with-a-challenge",
663
+ area="auth",
664
+ description=(
665
+ "RFC 6750 §3. DRF's stock behaviour does not match this and must be "
666
+ "overridden rather than inherited."
667
+ ),
668
+ request=RequestSpec("GET", "/conformance/private"),
669
+ expect_status=401,
670
+ expect_headers={
671
+ **_PROBLEM,
672
+ "WWW-Authenticate": 'Bearer realm="conformance"',
673
+ },
674
+ expect_body=_problem_body(UNAUTHORIZED, "Authentication failed."),
675
+ ),
676
+ ConformanceCase(
677
+ id="auth.insufficient-scope-is-403-without-a-challenge",
678
+ area="auth",
679
+ description=(
680
+ "Valid credentials lacking the scope is 403 and carries NO challenge — "
681
+ "a challenge here would tell a browser to re-prompt for credentials "
682
+ "that were already correct."
683
+ ),
684
+ request=RequestSpec(
685
+ "GET", "/conformance/private", headers={"Authorization": "Bearer no-scopes"}
686
+ ),
687
+ expect_status=403,
688
+ expect_headers=_PROBLEM,
689
+ expect_absent_headers=frozenset({"WWW-Authenticate"}),
690
+ expect_body=_problem_body(
691
+ FORBIDDEN, "The authenticated principal lacks the required access"
692
+ ),
693
+ ),
694
+ ConformanceCase(
695
+ id="auth.session-only-401-has-no-challenge",
696
+ area="auth",
697
+ description=(
698
+ "RFC 9110 §15.5.2 deviation. A session-only route has no registered "
699
+ "scheme to challenge with, so its 401 carries no WWW-Authenticate."
700
+ ),
701
+ request=RequestSpec("GET", _SESSION_PATH),
702
+ requires=frozenset({"session-routes"}),
703
+ expect_status=401,
704
+ expect_headers=_PROBLEM,
705
+ expect_absent_headers=frozenset({"WWW-Authenticate"}),
706
+ expect_body=_problem_body(UNAUTHORIZED, "Authentication failed."),
707
+ ),
708
+ ConformanceCase(
709
+ id="auth.csrf-rejection-is-403-csrf-failed",
710
+ area="auth",
711
+ description=(
712
+ "An unsafe request from a foreign origin is a 403 csrf-failed problem, "
713
+ "not a permission denial. The detail is generic and never names the "
714
+ "check that failed; with a type_base the type member is csrf-failed."
715
+ ),
716
+ request=RequestSpec(
717
+ "POST",
718
+ _SESSION_PATH,
719
+ headers={**_JSON, "Origin": "https://evil.example"},
720
+ body={},
721
+ ),
722
+ requires=frozenset({"session-routes", "csrf"}),
723
+ expect_status=403,
724
+ expect_headers=_PROBLEM,
725
+ expect_absent_headers=frozenset({"WWW-Authenticate"}),
726
+ expect_body=_problem_body(CSRF_FAILED, CSRF_FAILED_DETAIL),
727
+ ),
728
+ # --- Casing (api-conventions.md) ------------------------------------------
729
+ ConformanceCase(
730
+ id="casing.response-bodies-are-camel-case",
731
+ area="casing",
732
+ description=(
733
+ "Asserted structurally by the driver rather than per case: every key in "
734
+ "every response body above, at every depth, matches ^[a-z][a-zA-Z0-9]*$ "
735
+ "or is an RFC 9457 core member. RFC 9457's own members are single "
736
+ "lowercase words and are unaffected."
737
+ ),
738
+ request=RequestSpec("GET", _ITEMS_PATH, query={"pageSize": "2"}),
739
+ expect_status=200,
740
+ expect_headers=_JSON,
741
+ expect_body={
742
+ "items": [{"id": "1"}, {"id": "2"}],
743
+ "nextPageToken": PAGE_1_NEXT_TOKEN,
744
+ },
745
+ ),
746
+ # --- Tracing (tracing.py, asgi.py) -----------------------------------
747
+ ConformanceCase(
748
+ id="tracing.inbound-traceparent-continues-the-trace",
749
+ area="tracing",
750
+ description=(
751
+ "A caller-supplied W3C traceparent continues that trace: the "
752
+ "response's traceresponse carries the same trace id with a new "
753
+ "span id."
754
+ ),
755
+ request=RequestSpec(
756
+ "GET",
757
+ _ECHO_PATH,
758
+ headers={
759
+ "traceparent": _TRACEPARENT,
760
+ },
761
+ ),
762
+ expect_status=200,
763
+ expect_headers=_JSON,
764
+ expect_header_patterns={
765
+ "traceresponse": r"00-4bf92f3577b34da6a3ce929d0e0e4736-[0-9a-f]{16}-[0-9a-f]{2}",
766
+ },
767
+ expect_body={},
768
+ ),
769
+ ConformanceCase(
770
+ id="tracing.malformed-traceparent-starts-a-new-trace",
771
+ area="tracing",
772
+ description=(
773
+ "A malformed traceparent is never an error: the server discards "
774
+ "it and starts a new trace."
775
+ ),
776
+ request=RequestSpec("GET", _ECHO_PATH, headers={"traceparent": "garbage"}),
777
+ expect_status=200,
778
+ expect_headers=_JSON,
779
+ expect_header_patterns={
780
+ "traceresponse": r"00-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}",
781
+ },
782
+ expect_body={},
783
+ ),
784
+ ConformanceCase(
785
+ id="tracing.problem-body-carries-the-trace-id",
786
+ area="tracing",
787
+ description=(
788
+ "The current trace id reaches the problem body as the traceId "
789
+ "extension, which is what makes a user-reported error findable in "
790
+ "the trace backend and the logs."
791
+ ),
792
+ request=RequestSpec(
793
+ "GET", "/conformance/boom", headers={"traceparent": _TRACEPARENT}
794
+ ),
795
+ expect_status=500,
796
+ expect_headers=_PROBLEM,
797
+ expect_header_patterns={
798
+ "traceresponse": r"00-4bf92f3577b34da6a3ce929d0e0e4736-[0-9a-f]{16}-[0-9a-f]{2}",
799
+ },
800
+ expect_body=_problem_body(INTERNAL_ERROR, GENERIC_SERVER_DETAIL),
801
+ ),
802
+ ConformanceCase(
803
+ id="tracing.house-header-is-not-echoed",
804
+ area="tracing",
805
+ description="X-Correlation-ID is a removed house header: not read, and never sent back.",
806
+ request=RequestSpec("GET", _ECHO_PATH, headers={"X-Correlation-ID": "abc123"}),
807
+ expect_status=200,
808
+ expect_headers=_JSON,
809
+ expect_absent_headers=frozenset({"X-Correlation-ID"}),
810
+ expect_body={},
811
+ ),
812
+ # --- Deprecation (deprecation.py) -----------------------------------
813
+ ConformanceCase(
814
+ id="deprecation.endpoint-carries-rfc9745-headers",
815
+ area="deprecation",
816
+ description=(
817
+ "RFC 9745's Deprecation (a structured-field date) and RFC 8594's "
818
+ "Sunset (an HTTP-date), plus a Link rel=deprecation."
819
+ ),
820
+ request=RequestSpec("GET", "/conformance/legacy"),
821
+ expect_status=200,
822
+ expect_headers={
823
+ **_JSON,
824
+ "Deprecation": "@1767225600",
825
+ "Sunset": "Wed, 01 Jul 2026 00:00:00 GMT",
826
+ "Link": '<https://example.com/deprecated>; rel="deprecation"',
827
+ },
828
+ expect_body={"legacy": True},
829
+ ),
830
+ # --- Discovery (openapi.py) ------------------------------------------
831
+ ConformanceCase(
832
+ id="discovery.api-catalog-is-an-rfc9264-linkset",
833
+ area="discovery",
834
+ description=(
835
+ "RFC 9727's /.well-known/api-catalog: an RFC 9264 linkset naming the "
836
+ "OpenAPI document, the docs UI, and the readiness path."
837
+ ),
838
+ request=RequestSpec("GET", "/.well-known/api-catalog"),
839
+ expect_status=200,
840
+ expect_headers=_LINKSET,
841
+ expect_body={
842
+ "linkset": [
843
+ {
844
+ "anchor": "/",
845
+ "service-desc": [{"href": "/openapi.json"}],
846
+ "service-doc": [{"href": "/docs"}],
847
+ "status": [{"href": "/readyz"}],
848
+ }
849
+ ]
850
+ },
851
+ ),
852
+ # --- Security headers (security.py) -----------------------------------
853
+ ConformanceCase(
854
+ id="security.owasp-headers-are-present",
855
+ area="security",
856
+ description="The OWASP REST Security Cheat Sheet response headers, on every response.",
857
+ request=RequestSpec("GET", _ECHO_PATH),
858
+ expect_status=200,
859
+ expect_headers={
860
+ **_JSON,
861
+ "Cache-Control": "no-store",
862
+ "Content-Security-Policy": "frame-ancestors 'none'",
863
+ "X-Content-Type-Options": "nosniff",
864
+ "X-Frame-Options": "DENY",
865
+ "Referrer-Policy": "no-referrer",
866
+ },
867
+ expect_body={},
868
+ ),
869
+ # --- CORS (tracing.py: EXPOSED_HEADERS) --------------------------------
870
+ ConformanceCase(
871
+ id="cors.exposed-headers-are-comma-joined",
872
+ area="cors",
873
+ description=(
874
+ "A CORS response exposes the kit's own headers to a browser, in "
875
+ "configured order. traceresponse is exposed by the OpenTelemetry "
876
+ "response propagator itself, not by this list."
877
+ ),
878
+ request=RequestSpec(
879
+ "GET", _ECHO_PATH, headers={"Origin": "https://example.com"}
880
+ ),
881
+ expect_status=200,
882
+ expect_headers={
883
+ **_JSON,
884
+ "Access-Control-Allow-Origin": "https://example.com",
885
+ "Access-Control-Expose-Headers": ", ".join(
886
+ (*EXPOSED_HEADERS, "traceresponse")
887
+ ),
888
+ },
889
+ expect_body={},
890
+ ),
891
+ ConformanceCase(
892
+ id="cors.export-exposes-content-disposition",
893
+ area="cors",
894
+ description=(
895
+ "A cross-origin CSV export exposes Content-Disposition, so a "
896
+ "browser client can read the file name."
897
+ ),
898
+ request=RequestSpec(
899
+ "GET",
900
+ "/conformance/orders",
901
+ headers={"Accept": _CSV_TYPE, "Origin": "https://example.com"},
902
+ ),
903
+ expect_status=200,
904
+ expect_headers={"Access-Control-Allow-Origin": "https://example.com"},
905
+ expect_header_patterns={
906
+ "Content-Type": _CSV_TYPE_PATTERN,
907
+ "Access-Control-Expose-Headers": r"(.+, )?Content-Disposition(, .+)?",
908
+ },
909
+ expect_text=_ORDERS_CSV,
910
+ ),
911
+ # --- Tabular transfer and bulk operations (transfer.py) ----------------
912
+ ConformanceCase(
913
+ id="transfer.export-is-negotiated-from-accept",
914
+ area="transfer",
915
+ description=(
916
+ "RFC 9110 §12: a list asked for as text/csv is answered as CSV, "
917
+ "as an attachment (RFC 6266)."
918
+ ),
919
+ request=RequestSpec(
920
+ "GET", "/conformance/orders", headers={"Accept": _CSV_TYPE}
921
+ ),
922
+ expect_status=200,
923
+ expect_header_patterns={"Content-Type": _CSV_TYPE_PATTERN},
924
+ expect_headers={
925
+ "Content-Disposition": (
926
+ "attachment; filename=\"orders.csv\"; filename*=UTF-8''orders.csv"
927
+ ),
928
+ },
929
+ expect_text=_ORDERS_CSV,
930
+ ),
931
+ ConformanceCase(
932
+ id="transfer.export-format-param-is-the-fallback",
933
+ area="transfer",
934
+ description="?format=csv selects CSV for a plain link that cannot send Accept.",
935
+ request=RequestSpec("GET", "/conformance/orders", query={"format": "csv"}),
936
+ expect_status=200,
937
+ expect_header_patterns={"Content-Type": _CSV_TYPE_PATTERN},
938
+ expect_headers={
939
+ "Content-Disposition": (
940
+ "attachment; filename=\"orders.csv\"; filename*=UTF-8''orders.csv"
941
+ ),
942
+ },
943
+ expect_text=_ORDERS_CSV,
944
+ ),
945
+ ConformanceCase(
946
+ id="transfer.export-filename-carries-rfc8187-encoding",
947
+ area="transfer",
948
+ description=(
949
+ "A non-ASCII filename gets an ASCII fallback in filename= and the "
950
+ "percent-encoded UTF-8 in filename*= (RFC 8187)."
951
+ ),
952
+ request=RequestSpec(
953
+ "GET", "/conformance/orders/named", headers={"Accept": _CSV_TYPE}
954
+ ),
955
+ expect_status=200,
956
+ expect_header_patterns={"Content-Type": _CSV_TYPE_PATTERN},
957
+ expect_headers={
958
+ "Content-Disposition": (
959
+ 'attachment; filename="Ord_rs 2026.csv"; '
960
+ "filename*=UTF-8''Ord%C3%A9rs%202026.csv"
961
+ ),
962
+ },
963
+ expect_text=_ORDERS_CSV,
964
+ ),
965
+ ConformanceCase(
966
+ id="transfer.export-over-the-cap-is-422",
967
+ area="transfer",
968
+ description="An export above the configured cap is a 422 problem naming the cap.",
969
+ request=RequestSpec(
970
+ "GET", "/conformance/orders/over-cap", headers={"Accept": _CSV_TYPE}
971
+ ),
972
+ expect_status=422,
973
+ expect_headers=_PROBLEM,
974
+ expect_body=_problem_body(
975
+ VALIDATION_ERROR,
976
+ "The export exceeds the limit of 1 rows; narrow the filter.",
977
+ ),
978
+ ),
979
+ ConformanceCase(
980
+ id="transfer.import-report-counts-and-validate-only",
981
+ area="transfer",
982
+ description=(
983
+ "AIP-136/AIP-163: a multipart upload with validateOnly=true is 200 "
984
+ "with the counts it would produce."
985
+ ),
986
+ request=RequestSpec(
987
+ "POST",
988
+ "/conformance/orders:import",
989
+ headers={"Content-Type": "multipart/form-data"},
990
+ query={"validateOnly": "true"},
991
+ body={"file": "id,name,Quantity\n2,gadget,3\n"},
992
+ ),
993
+ expect_status=200,
994
+ expect_headers=_JSON,
995
+ expect_body={"created": 1, "updated": 0, "skipped": 0, "validateOnly": True},
996
+ ),
997
+ ConformanceCase(
998
+ id="transfer.import-row-errors-are-422-pointers",
999
+ area="transfer",
1000
+ description=(
1001
+ "Any row error fails the whole import as a 422 whose errors[].pointer "
1002
+ "is /rows/<row>/<column>."
1003
+ ),
1004
+ request=RequestSpec(
1005
+ "POST",
1006
+ "/conformance/orders:import",
1007
+ headers={"Content-Type": "multipart/form-data"},
1008
+ body={"file": "id,name,Quantity\n2,gadget,three\n"},
1009
+ ),
1010
+ expect_status=422,
1011
+ expect_headers=_PROBLEM,
1012
+ expect_body=_problem_body(
1013
+ VALIDATION_ERROR,
1014
+ "One or more rows are invalid.",
1015
+ errors=[{"pointer": "/rows/0/Quantity", "detail": "Enter a whole number."}],
1016
+ ),
1017
+ ),
1018
+ ConformanceCase(
1019
+ id="transfer.batch-create-item-failure-is-422-pointer",
1020
+ area="transfer",
1021
+ description=(
1022
+ "AIP-233: one invalid item fails the whole batch; the pointer names "
1023
+ "the item in the requests array."
1024
+ ),
1025
+ request=RequestSpec(
1026
+ "POST",
1027
+ "/conformance/orders:batchCreate",
1028
+ headers=_JSON,
1029
+ body={"requests": [{"name": "ok"}, {}]},
1030
+ ),
1031
+ expect_status=422,
1032
+ expect_headers=_PROBLEM,
1033
+ expect_body=_problem_body(
1034
+ VALIDATION_ERROR,
1035
+ "One or more rows are invalid.",
1036
+ errors=[
1037
+ {"pointer": "/requests/1/name", "detail": "This field is required."}
1038
+ ],
1039
+ ),
1040
+ ),
1041
+ ConformanceCase(
1042
+ id="transfer.failed-batch-create-persists-nothing",
1043
+ area="transfer",
1044
+ description="All or nothing: after the failed batch, the collection still has one order.",
1045
+ request=RequestSpec("GET", "/conformance/orders/count"),
1046
+ depends_on=("transfer.batch-create-item-failure-is-422-pointer",),
1047
+ expect_status=200,
1048
+ expect_headers=_JSON,
1049
+ expect_body={"count": 1},
1050
+ ),
1051
+ ConformanceCase(
1052
+ id="transfer.batch-create-returns-the-created-resources",
1053
+ area="transfer",
1054
+ description="AIP-233: a successful batch is 200 with the created resources under the plural name.",
1055
+ request=RequestSpec(
1056
+ "POST",
1057
+ "/conformance/orders:batchCreate",
1058
+ headers=_JSON,
1059
+ body={"requests": [{"name": "gadget"}]},
1060
+ ),
1061
+ expect_status=200,
1062
+ expect_headers=_JSON,
1063
+ expect_body={"orders": [{"id": "2", "name": "gadget"}]},
1064
+ ),
1065
+ ConformanceCase(
1066
+ id="transfer.batch-delete-with-unknown-id-is-404",
1067
+ area="transfer",
1068
+ description="AIP-235: one id that does not exist fails the whole batch.",
1069
+ request=RequestSpec(
1070
+ "POST",
1071
+ "/conformance/orders:batchDelete",
1072
+ headers=_JSON,
1073
+ body={"ids": ["1", "missing"]},
1074
+ ),
1075
+ expect_status=404,
1076
+ expect_headers=_PROBLEM,
1077
+ expect_body=_problem_body(NOT_FOUND, "Order missing not found"),
1078
+ ),
1079
+ ConformanceCase(
1080
+ id="transfer.failed-batch-delete-deletes-nothing",
1081
+ area="transfer",
1082
+ description="All or nothing: the order named alongside the unknown id is still there.",
1083
+ request=RequestSpec("GET", "/conformance/orders/1"),
1084
+ depends_on=("transfer.batch-delete-with-unknown-id-is-404",),
1085
+ expect_status=200,
1086
+ expect_headers=_JSON,
1087
+ expect_body={"id": "1", "name": "widget"},
1088
+ ),
1089
+ ConformanceCase(
1090
+ id="transfer.batch-delete-is-204",
1091
+ area="transfer",
1092
+ description="AIP-235: a successful batch delete is 204 with no body.",
1093
+ request=RequestSpec(
1094
+ "POST",
1095
+ "/conformance/orders:batchDelete",
1096
+ headers=_JSON,
1097
+ body={"ids": ["1"]},
1098
+ ),
1099
+ expect_status=204,
1100
+ expect_body={},
1101
+ ),
1102
+ ConformanceCase(
1103
+ id="transfer.import-template-is-the-import-columns",
1104
+ area="transfer",
1105
+ description=(
1106
+ "AIP-136: the import template is a CSV attachment whose only row is "
1107
+ "the import model's column names."
1108
+ ),
1109
+ request=RequestSpec(
1110
+ "GET", "/conformance/orders:importTemplate", headers={"Accept": _CSV_TYPE}
1111
+ ),
1112
+ expect_status=200,
1113
+ expect_header_patterns={"Content-Type": _CSV_TYPE_PATTERN},
1114
+ expect_headers={
1115
+ "Content-Disposition": (
1116
+ 'attachment; filename="import-template.csv"; '
1117
+ "filename*=UTF-8''import-template.csv"
1118
+ ),
1119
+ },
1120
+ expect_text="id,name,Quantity\r\n",
1121
+ ),
1122
+ ConformanceCase(
1123
+ id="transfer.import-template-prefill-adds-the-rows",
1124
+ area="transfer",
1125
+ description="?prefill=true adds the current rows under the header row.",
1126
+ request=RequestSpec(
1127
+ "GET",
1128
+ "/conformance/orders:importTemplate",
1129
+ headers={"Accept": _CSV_TYPE},
1130
+ query={"prefill": "true"},
1131
+ ),
1132
+ expect_status=200,
1133
+ expect_header_patterns={"Content-Type": _CSV_TYPE_PATTERN},
1134
+ expect_text="id,name,Quantity\r\n1,widget,0\r\n",
1135
+ ),
1136
+ ConformanceCase(
1137
+ id="transfer.import-without-a-file-is-422",
1138
+ area="transfer",
1139
+ description="A multipart import with no file part is a 422 naming /file.",
1140
+ request=RequestSpec(
1141
+ "POST",
1142
+ "/conformance/orders:import",
1143
+ headers={"Content-Type": "multipart/form-data"},
1144
+ body={},
1145
+ ),
1146
+ expect_status=422,
1147
+ expect_headers=_PROBLEM,
1148
+ expect_body=_problem_body(
1149
+ VALIDATION_ERROR,
1150
+ "Validation Error",
1151
+ errors=[{"pointer": "/file", "detail": "This field is required."}],
1152
+ ),
1153
+ ),
1154
+ ConformanceCase(
1155
+ id="transfer.import-over-the-cap-is-422",
1156
+ area="transfer",
1157
+ description="An import with more data rows than the cap is a 422 naming the cap.",
1158
+ request=RequestSpec(
1159
+ "POST",
1160
+ "/conformance/capped:import",
1161
+ headers={"Content-Type": "multipart/form-data"},
1162
+ body={"file": "id,name,Quantity\n2,a,3\n3,b,4\n"},
1163
+ ),
1164
+ expect_status=422,
1165
+ expect_headers=_PROBLEM,
1166
+ expect_body=_problem_body(
1167
+ VALIDATION_ERROR, "The import exceeds the limit of 1 rows."
1168
+ ),
1169
+ ),
1170
+ ConformanceCase(
1171
+ id="transfer.batch-create-with-an-empty-list-is-422",
1172
+ area="transfer",
1173
+ description="AIP-233: an empty requests list is a 422 naming /requests.",
1174
+ request=RequestSpec(
1175
+ "POST",
1176
+ "/conformance/orders:batchCreate",
1177
+ headers=_JSON,
1178
+ body={"requests": []},
1179
+ ),
1180
+ expect_status=422,
1181
+ expect_headers=_PROBLEM,
1182
+ expect_body=_problem_body(
1183
+ VALIDATION_ERROR,
1184
+ "Validation Error",
1185
+ errors=[
1186
+ {"pointer": "/requests", "detail": "A non-empty list is required."}
1187
+ ],
1188
+ ),
1189
+ ),
1190
+ ConformanceCase(
1191
+ id="transfer.batch-create-over-the-cap-is-422",
1192
+ area="transfer",
1193
+ description="A batch with more items than the cap is a 422 naming the cap.",
1194
+ request=RequestSpec(
1195
+ "POST",
1196
+ "/conformance/capped:batchCreate",
1197
+ headers=_JSON,
1198
+ body={"requests": [{"name": "a"}, {"name": "b"}]},
1199
+ ),
1200
+ expect_status=422,
1201
+ expect_headers=_PROBLEM,
1202
+ expect_body=_problem_body(
1203
+ VALIDATION_ERROR, "The batch exceeds the limit of 1 rows."
1204
+ ),
1205
+ ),
1206
+ ConformanceCase(
1207
+ id="transfer.batch-create-denied-item-is-403-pointer",
1208
+ area="transfer",
1209
+ description=(
1210
+ "One item the principal may not create fails the whole batch as a "
1211
+ "403 whose pointer names the item."
1212
+ ),
1213
+ request=RequestSpec(
1214
+ "POST",
1215
+ "/conformance/orders:batchCreate",
1216
+ headers=_JSON,
1217
+ body={"requests": [{"name": "ok"}, {"name": "forbidden"}]},
1218
+ ),
1219
+ expect_status=403,
1220
+ expect_headers=_PROBLEM,
1221
+ expect_body=_problem_body(
1222
+ FORBIDDEN,
1223
+ "Forbidden",
1224
+ errors=[
1225
+ {"pointer": "/requests/1", "detail": "You may not create this order."}
1226
+ ],
1227
+ ),
1228
+ ),
1229
+ ConformanceCase(
1230
+ id="transfer.denied-batch-create-persists-nothing",
1231
+ area="transfer",
1232
+ description="All or nothing: after the denied batch, the collection still has one order.",
1233
+ request=RequestSpec("GET", "/conformance/orders/count"),
1234
+ depends_on=("transfer.batch-create-denied-item-is-403-pointer",),
1235
+ expect_status=200,
1236
+ expect_headers=_JSON,
1237
+ expect_body={"count": 1},
1238
+ ),
1239
+ ConformanceCase(
1240
+ id="transfer.batch-get-returns-resources-in-request-order",
1241
+ area="transfer",
1242
+ description="AIP-231: :batchGet answers 200 with the resources under the plural name, in request order.",
1243
+ request=RequestSpec("GET", _BOOKS_GET, query={"ids": ("3", "1")}),
1244
+ expect_status=200,
1245
+ expect_headers=_JSON,
1246
+ expect_body={
1247
+ "books": [{"id": "3", "name": "gamma"}, {"id": "1", "name": "alpha"}]
1248
+ },
1249
+ ),
1250
+ ConformanceCase(
1251
+ id="transfer.batch-get-with-an-unknown-id-is-404",
1252
+ area="transfer",
1253
+ description="AIP-231: one id that does not exist fails the whole batch.",
1254
+ request=RequestSpec("GET", _BOOKS_GET, query={"ids": ("1", "999")}),
1255
+ expect_status=404,
1256
+ expect_headers=_PROBLEM,
1257
+ expect_body=_problem_body(NOT_FOUND, "Book 999 not found"),
1258
+ ),
1259
+ ConformanceCase(
1260
+ id="transfer.batch-get-without-ids-is-400",
1261
+ area="transfer",
1262
+ description="A :batchGet with no ids parameter is a 400, as a query-parameter fault is.",
1263
+ request=RequestSpec("GET", _BOOKS_GET),
1264
+ expect_status=400,
1265
+ expect_headers=_PROBLEM,
1266
+ expect_body=_problem_body(
1267
+ BAD_REQUEST, "A non-empty ids parameter is required."
1268
+ ),
1269
+ ),
1270
+ ConformanceCase(
1271
+ id="transfer.batch-get-over-the-cap-is-400",
1272
+ area="transfer",
1273
+ description="A :batchGet naming more ids than the cap is a 400 naming the cap.",
1274
+ request=RequestSpec(
1275
+ "GET", "/conformance/capped-books:batchGet", query={"ids": ("1", "2")}
1276
+ ),
1277
+ expect_status=400,
1278
+ expect_headers=_PROBLEM,
1279
+ expect_body=_problem_body(
1280
+ BAD_REQUEST, "The batch exceeds the limit of 1 rows."
1281
+ ),
1282
+ ),
1283
+ ConformanceCase(
1284
+ id="transfer.batch-update-applies-each-merge-patch",
1285
+ area="transfer",
1286
+ description="AIP-234 with RFC 7396 items: each patch is merged and the updated resources are returned in request order.",
1287
+ request=RequestSpec(
1288
+ "POST",
1289
+ _BOOKS_UPDATE,
1290
+ headers=_JSON,
1291
+ body={
1292
+ "requests": [
1293
+ {"id": "2", "patch": {"name": "beta2"}, "ifMatch": 'W/"2:1"'}
1294
+ ]
1295
+ },
1296
+ ),
1297
+ expect_status=200,
1298
+ expect_headers=_JSON,
1299
+ expect_body={"books": [{"id": "2", "name": "beta2"}]},
1300
+ ),
1301
+ ConformanceCase(
1302
+ id="transfer.batch-update-stale-if-match-is-412-pointer",
1303
+ area="transfer",
1304
+ description="An item whose ifMatch is stale fails the whole batch as a 412 whose pointer names the item.",
1305
+ request=RequestSpec(
1306
+ "POST",
1307
+ _BOOKS_UPDATE,
1308
+ headers=_JSON,
1309
+ body={
1310
+ "requests": [
1311
+ {"id": "1", "patch": {"name": "x"}},
1312
+ {"id": "3", "patch": {"name": "y"}, "ifMatch": 'W/"3:9"'},
1313
+ ]
1314
+ },
1315
+ ),
1316
+ expect_status=412,
1317
+ expect_headers=_PROBLEM,
1318
+ expect_body=_problem_body(
1319
+ PRECONDITION_FAILED,
1320
+ _STALE_BOOK,
1321
+ errors=[{"pointer": "/requests/1/ifMatch", "detail": _STALE_BOOK}],
1322
+ ),
1323
+ ),
1324
+ ConformanceCase(
1325
+ id="transfer.failed-batch-update-changes-nothing",
1326
+ area="transfer",
1327
+ description="All or nothing: after the failed batch, the first item is still unchanged.",
1328
+ request=RequestSpec("GET", _BOOKS_GET, query={"ids": ("1", "3")}),
1329
+ depends_on=("transfer.batch-update-stale-if-match-is-412-pointer",),
1330
+ expect_status=200,
1331
+ expect_headers=_JSON,
1332
+ expect_body={
1333
+ "books": [{"id": "1", "name": "alpha"}, {"id": "3", "name": "gamma"}]
1334
+ },
1335
+ ),
1336
+ ConformanceCase(
1337
+ id="transfer.batch-update-item-validation-is-422-pointer",
1338
+ area="transfer",
1339
+ description="An item whose merged document is invalid fails the whole batch; the pointer names the member in the patch.",
1340
+ request=RequestSpec(
1341
+ "POST",
1342
+ _BOOKS_UPDATE,
1343
+ headers=_JSON,
1344
+ body={"requests": [{"id": "1", "patch": {"name": None}}]},
1345
+ ),
1346
+ expect_status=422,
1347
+ expect_headers=_PROBLEM,
1348
+ expect_body=_problem_body(
1349
+ VALIDATION_ERROR,
1350
+ "One or more rows are invalid.",
1351
+ errors=[{"pointer": "/requests/0/patch/name", "detail": NULL_FIELD_DETAIL}],
1352
+ ),
1353
+ ),
1354
+ ConformanceCase(
1355
+ id="transfer.batch-update-with-an-unknown-id-is-404",
1356
+ area="transfer",
1357
+ description="One id that does not exist fails the whole batch.",
1358
+ request=RequestSpec(
1359
+ "POST",
1360
+ _BOOKS_UPDATE,
1361
+ headers=_JSON,
1362
+ body={"requests": [{"id": "999", "patch": {}}]},
1363
+ ),
1364
+ expect_status=404,
1365
+ expect_headers=_PROBLEM,
1366
+ expect_body=_problem_body(NOT_FOUND, "Book 999 not found"),
1367
+ ),
1368
+ ConformanceCase(
1369
+ id="transfer.batch-update-with-a-duplicate-id-is-422",
1370
+ area="transfer",
1371
+ description="An id named twice is a 422 pointing at the later item.",
1372
+ request=RequestSpec(
1373
+ "POST",
1374
+ _BOOKS_UPDATE,
1375
+ headers=_JSON,
1376
+ body={"requests": [{"id": "1", "patch": {}}, {"id": "1", "patch": {}}]},
1377
+ ),
1378
+ expect_status=422,
1379
+ expect_headers=_PROBLEM,
1380
+ expect_body=_problem_body(
1381
+ VALIDATION_ERROR,
1382
+ "One or more rows are invalid.",
1383
+ errors=[{"pointer": "/requests/1/id", "detail": "Duplicate id in batch."}],
1384
+ ),
1385
+ ),
1386
+ ConformanceCase(
1387
+ id="transfer.batch-update-with-an-empty-list-is-422",
1388
+ area="transfer",
1389
+ description="An empty requests list is a 422 naming /requests.",
1390
+ request=RequestSpec(
1391
+ "POST", _BOOKS_UPDATE, headers=_JSON, body={"requests": []}
1392
+ ),
1393
+ expect_status=422,
1394
+ expect_headers=_PROBLEM,
1395
+ expect_body=_problem_body(
1396
+ VALIDATION_ERROR,
1397
+ "Validation Error",
1398
+ errors=[
1399
+ {"pointer": "/requests", "detail": "A non-empty list is required."}
1400
+ ],
1401
+ ),
1402
+ ),
1403
+ # --- Timestamps (api-conventions.md §18) -----------------------------
1404
+ ConformanceCase(
1405
+ id="timestamps.rfc-3339-utc-with-z",
1406
+ area="timestamps",
1407
+ description=(
1408
+ "AIP-142: an instant is an RFC 3339 string in UTC with a Z suffix, "
1409
+ "not an offset and not a zone name."
1410
+ ),
1411
+ request=RequestSpec("GET", "/conformance/stamped"),
1412
+ expect_status=200,
1413
+ expect_headers=_JSON,
1414
+ expect_body={"id": "1", "createTime": "2026-09-23T14:05:00Z"},
1415
+ ),
1416
+ # --- Long-running operations (operations.py) -------------------------
1417
+ ConformanceCase(
1418
+ id="operations.start-is-202-with-location",
1419
+ area="operations",
1420
+ description=(
1421
+ "AIP-151: the call answers 202, names the operation in Location, and "
1422
+ "returns it unfinished."
1423
+ ),
1424
+ request=RequestSpec("POST", "/conformance/exports", headers=_JSON, body={}),
1425
+ expect_status=202,
1426
+ expect_headers={**_JSON, "Location": "/conformance/operations/1"},
1427
+ expect_body={"name": "operations/1", "done": False},
1428
+ ),
1429
+ ConformanceCase(
1430
+ id="operations.finished-carries-its-response",
1431
+ area="operations",
1432
+ description="A finished operation has done=true and a response, and no error.",
1433
+ request=RequestSpec("GET", "/conformance/operations/1"),
1434
+ expect_status=200,
1435
+ expect_headers=_JSON,
1436
+ expect_body={
1437
+ "name": "operations/1",
1438
+ "done": True,
1439
+ "response": {"id": "1"},
1440
+ },
1441
+ ),
1442
+ ConformanceCase(
1443
+ id="operations.failed-carries-a-problem",
1444
+ area="operations",
1445
+ description=(
1446
+ "A failed operation has done=true and an RFC 9457 problem as its error, "
1447
+ "never google.rpc.Status."
1448
+ ),
1449
+ request=RequestSpec("GET", "/conformance/operations/2"),
1450
+ expect_status=200,
1451
+ expect_headers=_JSON,
1452
+ expect_body={
1453
+ "name": "operations/2",
1454
+ "done": True,
1455
+ "error": {
1456
+ "type": BLANK_TYPE,
1457
+ "title": "Conflict",
1458
+ "status": 409,
1459
+ "detail": "Order already dispatched",
1460
+ "instance": REDACTED,
1461
+ },
1462
+ },
1463
+ ),
1464
+ # --- Merge patch (merge_patch.py) ------------------------------
1465
+ ConformanceCase(
1466
+ id="patch.nested-merge-keeps-absent-members",
1467
+ area="patch",
1468
+ description=(
1469
+ "RFC 7396 §2: objects merge recursively, so a member the patch does "
1470
+ "not name keeps its value."
1471
+ ),
1472
+ request=RequestSpec(
1473
+ "PATCH",
1474
+ _DOCUMENT_PATH,
1475
+ headers=_MERGE,
1476
+ body={"settings": {"color": "blue"}},
1477
+ ),
1478
+ expect_status=200,
1479
+ expect_headers={**_JSON, "ETag": 'W/"1:2"'},
1480
+ expect_body=_document(settings={"color": "blue", "size": "L"}),
1481
+ ),
1482
+ ConformanceCase(
1483
+ id="patch.null-inside-a-json-value-removes-the-member",
1484
+ area="patch",
1485
+ description=("RFC 7396 §2: below the top level, null removes the member."),
1486
+ request=RequestSpec(
1487
+ "PATCH", _DOCUMENT_PATH, headers=_MERGE, body={"settings": {"size": None}}
1488
+ ),
1489
+ expect_status=200,
1490
+ expect_headers=_JSON,
1491
+ expect_body=_document(settings={"color": "red"}),
1492
+ ),
1493
+ ConformanceCase(
1494
+ id="patch.null-sets-a-nullable-field-to-null",
1495
+ area="patch",
1496
+ description=("At the top level a null names a field and stores null in it."),
1497
+ request=RequestSpec(
1498
+ "PATCH", _DOCUMENT_PATH, headers=_MERGE, body={"note": None}
1499
+ ),
1500
+ expect_status=200,
1501
+ expect_headers=_JSON,
1502
+ expect_body=_document(note=None),
1503
+ ),
1504
+ ConformanceCase(
1505
+ id="patch.array-is-replaced-whole",
1506
+ area="patch",
1507
+ description=("RFC 7396 §2: an array is a value, so it replaces the target's."),
1508
+ request=RequestSpec(
1509
+ "PATCH", _DOCUMENT_PATH, headers=_MERGE, body={"tags": ["c"]}
1510
+ ),
1511
+ expect_status=200,
1512
+ expect_headers=_JSON,
1513
+ expect_body=_document(tags=["c"]),
1514
+ ),
1515
+ ConformanceCase(
1516
+ id="patch.read-only-members-are-ignored",
1517
+ area="patch",
1518
+ description=(
1519
+ "A server-owned member in the patch changes nothing; the rest applies."
1520
+ ),
1521
+ request=RequestSpec(
1522
+ "PATCH", _DOCUMENT_PATH, headers=_MERGE, body={"id": "99", "name": "gadget"}
1523
+ ),
1524
+ expect_status=200,
1525
+ expect_headers=_JSON,
1526
+ expect_body=_document(name="gadget"),
1527
+ ),
1528
+ ConformanceCase(
1529
+ id="patch.null-on-a-non-nullable-field-is-422",
1530
+ area="patch",
1531
+ description="A null on a required field fails validation, naming the field.",
1532
+ request=RequestSpec(
1533
+ "PATCH", _DOCUMENT_PATH, headers=_MERGE, body={"name": None}
1534
+ ),
1535
+ expect_status=422,
1536
+ expect_headers=_PROBLEM,
1537
+ expect_body=_problem_body(
1538
+ VALIDATION_ERROR,
1539
+ "Validation Error",
1540
+ errors=[{"pointer": "/name", "detail": NULL_FIELD_DETAIL}],
1541
+ ),
1542
+ ),
1543
+ ConformanceCase(
1544
+ id="patch.non-object-body-is-422",
1545
+ area="patch",
1546
+ description="RFC 7396 lets a non-object replace the target; pykit refuses it.",
1547
+ request=RequestSpec("PATCH", _DOCUMENT_PATH, headers=_MERGE, body=["name"]),
1548
+ expect_status=422,
1549
+ expect_headers=_PROBLEM,
1550
+ expect_body=_problem_body(
1551
+ VALIDATION_ERROR, "A merge patch must be a JSON object."
1552
+ ),
1553
+ ),
1554
+ ConformanceCase(
1555
+ id="patch.json-content-type-is-415",
1556
+ area="patch",
1557
+ description=(
1558
+ "RFC 5789 §2.2: a patch format the server does not support is 415, "
1559
+ "and Accept-Patch names the one it does."
1560
+ ),
1561
+ request=RequestSpec(
1562
+ "PATCH", _DOCUMENT_PATH, headers=_JSON, body={"name": "gadget"}
1563
+ ),
1564
+ expect_status=415,
1565
+ expect_headers={**_PROBLEM, "Accept-Patch": MERGE_PATCH_MEDIA_TYPE},
1566
+ expect_body=_problem_body(
1567
+ UNSUPPORTED_MEDIA_TYPE,
1568
+ "Use Content-Type: application/merge-patch+json for PATCH",
1569
+ ),
1570
+ ),
1571
+ ConformanceCase(
1572
+ id="patch.stale-if-match-is-412",
1573
+ area="patch",
1574
+ description="The precondition is checked before the patch is applied.",
1575
+ request=RequestSpec(
1576
+ "PATCH",
1577
+ _DOCUMENT_PATH,
1578
+ headers={**_MERGE, "If-Match": 'W/"1:9"'},
1579
+ body={"name": "gadget"},
1580
+ ),
1581
+ expect_status=412,
1582
+ expect_headers=_PROBLEM,
1583
+ expect_body=_problem_body(
1584
+ PRECONDITION_FAILED, "Precondition failed: expected version 1, got 9"
1585
+ ),
1586
+ ),
1587
+ ConformanceCase(
1588
+ id="patch.failed-precondition-changes-nothing",
1589
+ area="patch",
1590
+ description="After the 412, the document is still the original.",
1591
+ request=RequestSpec("GET", _DOCUMENT_PATH),
1592
+ expect_status=200,
1593
+ expect_headers=_JSON,
1594
+ expect_body=_document(),
1595
+ depends_on=("patch.stale-if-match-is-412",),
1596
+ ),
1597
+ ConformanceCase(
1598
+ id="read-mask.get-returns-only-the-masked-fields",
1599
+ area="read-mask",
1600
+ description="AIP-157: readMask names top-level fields, and only those are returned.",
1601
+ request=RequestSpec(
1602
+ "GET", _PROFILE_PATH, query={"readMask": "displayName,settings"}
1603
+ ),
1604
+ expect_status=200,
1605
+ expect_headers=_JSON,
1606
+ expect_body={"displayName": "Ada", "settings": {"theme": "dark"}},
1607
+ ),
1608
+ ConformanceCase(
1609
+ id="read-mask.nested-path-selects-a-sub-field",
1610
+ area="read-mask",
1611
+ description="A dotted path selects one field of a declared object.",
1612
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "address.city"}),
1613
+ expect_status=200,
1614
+ expect_headers=_JSON,
1615
+ expect_body={"address": {"city": "London"}},
1616
+ ),
1617
+ ConformanceCase(
1618
+ id="read-mask.path-through-a-list-applies-to-each-element",
1619
+ area="read-mask",
1620
+ description="A path through a list of objects applies to every element.",
1621
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "phones.number"}),
1622
+ expect_status=200,
1623
+ expect_headers=_JSON,
1624
+ expect_body={"phones": [{"number": "1"}, {"number": "2"}]},
1625
+ ),
1626
+ ConformanceCase(
1627
+ id="read-mask.overlapping-paths-merge",
1628
+ area="read-mask",
1629
+ description="A path and one of its sub-paths merge to the whole object.",
1630
+ request=RequestSpec(
1631
+ "GET", _PROFILE_PATH, query={"readMask": "address,address.city"}
1632
+ ),
1633
+ expect_status=200,
1634
+ expect_headers=_JSON,
1635
+ expect_body={"address": {"city": "London", "postcode": "N1"}},
1636
+ ),
1637
+ ConformanceCase(
1638
+ id="read-mask.star-is-the-whole-resource",
1639
+ area="read-mask",
1640
+ description="A readMask of * returns the whole resource.",
1641
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "*"}),
1642
+ expect_status=200,
1643
+ expect_headers=_JSON,
1644
+ expect_body=_PROFILE_ADA,
1645
+ ),
1646
+ ConformanceCase(
1647
+ id="read-mask.list-masks-each-item",
1648
+ area="read-mask",
1649
+ description="On a collection the mask applies to each item, and the page members stay.",
1650
+ request=RequestSpec(
1651
+ "GET", "/conformance/profiles", query={"readMask": "id,displayName"}
1652
+ ),
1653
+ expect_status=200,
1654
+ expect_headers=_JSON,
1655
+ expect_body={
1656
+ "items": [
1657
+ {"id": "1", "displayName": "Ada"},
1658
+ {"id": "2", "displayName": "Grace"},
1659
+ ],
1660
+ "nextPageToken": None,
1661
+ },
1662
+ ),
1663
+ ConformanceCase(
1664
+ id="read-mask.unknown-path-is-400",
1665
+ area="read-mask",
1666
+ description="A path that names no declared field is a 400, never ignored.",
1667
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "nickname"}),
1668
+ expect_status=400,
1669
+ expect_headers=_PROBLEM,
1670
+ expect_body=_problem_body(BAD_REQUEST, "Unknown readMask path 'nickname'"),
1671
+ ),
1672
+ ConformanceCase(
1673
+ id="read-mask.path-inside-a-free-form-field-is-400",
1674
+ area="read-mask",
1675
+ description="A free-form JSON field is a leaf: a path inside it names nothing declared.",
1676
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "settings.theme"}),
1677
+ expect_status=400,
1678
+ expect_headers=_PROBLEM,
1679
+ expect_body=_problem_body(
1680
+ BAD_REQUEST, "Unknown readMask path 'settings.theme'"
1681
+ ),
1682
+ ),
1683
+ ConformanceCase(
1684
+ id="read-mask.star-with-other-paths-is-400",
1685
+ area="read-mask",
1686
+ description="* selects everything, so combining it with a path is a 400.",
1687
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "*,displayName"}),
1688
+ expect_status=400,
1689
+ expect_headers=_PROBLEM,
1690
+ expect_body=_problem_body(
1691
+ BAD_REQUEST, "readMask '*' cannot be combined with other paths"
1692
+ ),
1693
+ ),
1694
+ ConformanceCase(
1695
+ id="read-mask.masked-read-keeps-the-etag",
1696
+ area="read-mask",
1697
+ description="A masked read carries the resource's ETag, so a client can follow with If-Match.",
1698
+ request=RequestSpec("GET", _PROFILE_PATH, query={"readMask": "displayName"}),
1699
+ expect_status=200,
1700
+ expect_headers={**_JSON, "ETag": 'W/"1:1"'},
1701
+ expect_body={"displayName": "Ada"},
1702
+ ),
1703
+ ConformanceCase(
1704
+ id="read-mask.batch-get-masks-each-item",
1705
+ area="read-mask",
1706
+ description="A :batchGet applies the mask to each resource.",
1707
+ request=RequestSpec("GET", _BOOKS_GET, query={"ids": "1", "readMask": "name"}),
1708
+ expect_status=200,
1709
+ expect_headers=_JSON,
1710
+ expect_body={"books": [{"name": "alpha"}]},
1711
+ ),
1712
+ ConformanceCase(
1713
+ id="soft-delete.delete-returns-the-resource-with-its-delete-time",
1714
+ area="soft-delete",
1715
+ description="AIP-164: DELETE soft-deletes and answers 200 with the resource, its deleteTime and the new ETag.",
1716
+ request=RequestSpec("DELETE", _NOTE_1),
1717
+ expect_status=200,
1718
+ expect_headers={**_JSON, "ETag": 'W/"1:2"'},
1719
+ expect_body=_note("1", "first", "2026-01-02T00:00:00Z"),
1720
+ ),
1721
+ ConformanceCase(
1722
+ id="soft-delete.list-omits-deleted-resources",
1723
+ area="soft-delete",
1724
+ description="A list leaves out soft-deleted resources.",
1725
+ request=RequestSpec("GET", _NOTES_PATH),
1726
+ expect_status=200,
1727
+ expect_headers=_JSON,
1728
+ expect_body={
1729
+ "items": [_note("1", "first"), _note("3", "third")],
1730
+ "nextPageToken": None,
1731
+ },
1732
+ ),
1733
+ ConformanceCase(
1734
+ id="soft-delete.show-deleted-lists-them",
1735
+ area="soft-delete",
1736
+ description="showDeleted=true brings soft-deleted resources back into a list.",
1737
+ request=RequestSpec("GET", _NOTES_PATH, query={"showDeleted": "true"}),
1738
+ expect_status=200,
1739
+ expect_headers=_JSON,
1740
+ expect_body={
1741
+ "items": [
1742
+ _note("1", "first"),
1743
+ _note("2", "second", "2026-01-01T00:00:00Z"),
1744
+ _note("3", "third"),
1745
+ ],
1746
+ "nextPageToken": None,
1747
+ },
1748
+ ),
1749
+ ConformanceCase(
1750
+ id="soft-delete.get-returns-a-deleted-resource",
1751
+ area="soft-delete",
1752
+ description="AIP-164: a get returns the soft-deleted resource, with its deleteTime.",
1753
+ request=RequestSpec("GET", _NOTE_2),
1754
+ expect_status=200,
1755
+ expect_headers=_JSON,
1756
+ expect_body=_note("2", "second", "2026-01-01T00:00:00Z"),
1757
+ ),
1758
+ ConformanceCase(
1759
+ id="soft-delete.delete-of-a-deleted-resource-is-404",
1760
+ area="soft-delete",
1761
+ description="A DELETE on an already soft-deleted resource is not found.",
1762
+ request=RequestSpec("DELETE", _NOTE_2),
1763
+ expect_status=404,
1764
+ expect_headers=_PROBLEM,
1765
+ expect_body=_problem_body(NOT_FOUND, "Note 2 not found"),
1766
+ ),
1767
+ ConformanceCase(
1768
+ id="soft-delete.undelete-restores-the-resource",
1769
+ area="soft-delete",
1770
+ description="AIP-164: :undelete answers 200 with the live resource and the new ETag.",
1771
+ request=RequestSpec("POST", "/conformance/notes/2:undelete"),
1772
+ expect_status=200,
1773
+ expect_headers={**_JSON, "ETag": 'W/"2:3"'},
1774
+ expect_body=_note("2", "second"),
1775
+ ),
1776
+ ConformanceCase(
1777
+ id="soft-delete.undeleted-resource-is-listed-again",
1778
+ area="soft-delete",
1779
+ description="An undeleted resource is back in the default list.",
1780
+ request=RequestSpec("GET", _NOTES_PATH),
1781
+ depends_on=("soft-delete.undelete-restores-the-resource",),
1782
+ expect_status=200,
1783
+ expect_headers=_JSON,
1784
+ expect_body={
1785
+ "items": [
1786
+ _note("1", "first"),
1787
+ _note("2", "second"),
1788
+ _note("3", "third"),
1789
+ ],
1790
+ "nextPageToken": None,
1791
+ },
1792
+ ),
1793
+ ConformanceCase(
1794
+ id="soft-delete.undelete-of-a-live-resource-is-409",
1795
+ area="soft-delete",
1796
+ description="Undeleting a resource that is not deleted conflicts.",
1797
+ request=RequestSpec("POST", "/conformance/notes/1:undelete"),
1798
+ expect_status=409,
1799
+ expect_headers=_PROBLEM,
1800
+ expect_body=_problem_body(CONFLICT, "Note 1 is not deleted"),
1801
+ ),
1802
+ ConformanceCase(
1803
+ id="soft-delete.write-to-a-deleted-resource-is-409",
1804
+ area="soft-delete",
1805
+ description="A PATCH on a soft-deleted resource conflicts.",
1806
+ request=RequestSpec("PATCH", _NOTE_2, headers=_MERGE, body={"text": "x"}),
1807
+ expect_status=409,
1808
+ expect_headers=_PROBLEM,
1809
+ expect_body=_problem_body(CONFLICT, "Note 2 is deleted"),
1810
+ ),
1811
+ ConformanceCase(
1812
+ id="soft-delete.stale-if-match-is-412",
1813
+ area="soft-delete",
1814
+ description="DELETE honours If-Match; a stale validator is a 412.",
1815
+ request=RequestSpec("DELETE", _NOTE_1, headers={"If-Match": 'W/"1:9"'}),
1816
+ expect_status=412,
1817
+ expect_headers=_PROBLEM,
1818
+ expect_body=_problem_body(
1819
+ PRECONDITION_FAILED, "Precondition failed: expected version 1, got 9"
1820
+ ),
1821
+ ),
1822
+ ConformanceCase(
1823
+ id="soft-delete.failed-precondition-deletes-nothing",
1824
+ area="soft-delete",
1825
+ description="A failed precondition leaves the resource live.",
1826
+ request=RequestSpec("GET", _NOTE_1),
1827
+ depends_on=("soft-delete.stale-if-match-is-412",),
1828
+ expect_status=200,
1829
+ expect_headers=_JSON,
1830
+ expect_body=_note("1", "first"),
1831
+ ),
1832
+ ConformanceCase(
1833
+ id="soft-delete.batch-delete-soft-deletes",
1834
+ area="soft-delete",
1835
+ description="AIP-235 over AIP-164: a batch delete soft-deletes and answers 204.",
1836
+ request=RequestSpec(
1837
+ "POST", "/conformance/notes:batchDelete", headers=_JSON, body={"ids": ["3"]}
1838
+ ),
1839
+ expect_status=204,
1840
+ expect_body={},
1841
+ ),
1842
+ ConformanceCase(
1843
+ id="soft-delete.batch-deleted-resource-is-still-readable",
1844
+ area="soft-delete",
1845
+ description="A resource soft-deleted in a batch is still returned by a get.",
1846
+ request=RequestSpec("GET", _NOTE_3),
1847
+ depends_on=("soft-delete.batch-delete-soft-deletes",),
1848
+ expect_status=200,
1849
+ expect_headers=_JSON,
1850
+ expect_body=_note("3", "third", "2026-01-02T00:00:00Z"),
1851
+ ),
1852
+ )
1853
+
1854
+
1855
+ def cases_for(area: ConformanceArea) -> tuple[ConformanceCase, ...]:
1856
+ """Return every case in *area*, in table order."""
1857
+ return tuple(case for case in CASES if case.area == area)
1858
+
1859
+
1860
+ def case_by_id(case_id: str) -> ConformanceCase:
1861
+ """Return the case with *case_id*, for resolving ``depends_on``.
1862
+
1863
+ Raises:
1864
+ KeyError: No case has that id.
1865
+ """
1866
+ for case in CASES:
1867
+ if case.id == case_id:
1868
+ return case
1869
+ raise KeyError(case_id)
1870
+
1871
+
1872
+ def cases_provided_by(
1873
+ provides: Collection[ConformanceCapability] = (),
1874
+ ) -> tuple[ConformanceCase, ...]:
1875
+ """Return every case whose required capabilities a binding provides.
1876
+
1877
+ A case with no ``requires`` is always returned. A driver parametrizes over
1878
+ this instead of :data:`CASES`, passing the capabilities its fixture
1879
+ application serves.
1880
+
1881
+ Args:
1882
+ provides: The capabilities the binding provides.
1883
+
1884
+ Example::
1885
+
1886
+ @pytest.mark.parametrize("case", cases_provided_by({"session-routes"}))
1887
+ def test_conforms(case): ...
1888
+ """
1889
+ available = frozenset(provides)
1890
+ return tuple(case for case in CASES if case.requires <= available)