Fix durable logout and add grade-5 research
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Tmribob
2026-11-06 16:13:16 +03:00
parent ae730d5fdb
commit e73988a308
9 changed files with 324 additions and 25 deletions
+50 -3
View File
@@ -46,9 +46,13 @@ def wait_ready(expected: int, seconds: float) -> float:
deadline = started + seconds
last = None
while time.monotonic() < deadline:
last = common.request("GET", "/health/ready", timeout=5)
if last.status == expected:
return time.monotonic() - started
try:
last = common.request("GET", "/health/ready", timeout=5)
if last.status == expected:
return time.monotonic() - started
except OSError:
# The TCP listener may be replaced during `compose restart`.
pass
time.sleep(0.5)
raise AssertionError(
"readiness did not reach %s within %.0fs (last=%s %r)"
@@ -58,6 +62,49 @@ def wait_ready(expected: int, seconds: float) -> float:
@unittest.skipUnless(ENABLED, "set STUDENT_DOCKER_TESTS=1 to stop real containers")
class DependencyOutages(unittest.TestCase):
def test_logout_remains_revoked_after_cache_outage_and_api_restart(self) -> None:
"""A stale Valkey hit must never resurrect a PostgreSQL-revoked token."""
alice = common.actor("revoked")
chat = common.create_chat(alice.token, [alice.id], "Durable logout")
# Store the live session in Valkey before its simulated outage.
self.assertEqual(common.request("GET", "/api/v1/users/me", token=alice.token).status, 200)
try:
compose("stop", "valkey")
logout = common.request("DELETE", "/api/v1/auth/sessions/current", token=alice.token)
self.assertEqual(logout.status, 204, logout.json)
# Lose the local pending tombstone, then restore Valkey's old volume.
compose("restart", "api")
compose("start", "valkey")
wait_ready(200, 90)
common.expect_error(
self, common.request("GET", "/api/v1/users/me", token=alice.token), 401, "unauthorized"
)
common.expect_error(
self,
common.request("GET", "/api/v1/chats/" + chat["id"], token=alice.token),
401,
"unauthorized",
)
common.expect_error(
self,
common.request(
"POST",
"/api/v1/chats/" + chat["id"] + "/messages",
body={"text": "must not be accepted"},
token=alice.token,
),
401,
"unauthorized",
)
finally:
compose("start", "valkey", "postgres", "api")
try:
wait_ready(200, 90)
except AssertionError:
pass
def test_valkey_loss_degrades_then_postgres_loss_is_bounded(self) -> None:
alice = common.actor("degrade")
chat = common.create_chat(alice.token, [alice.id], "Устойчивость")