Pace own positive-login regressions against shared runtime limits

This commit is contained in:
2026-11-16 11:59:43 +03:00
parent e5039231c3
commit 9535c07b40
3 changed files with 44 additions and 1 deletions
+4
View File
@@ -14,6 +14,10 @@ def run(args, *, output=None):
result = subprocess.run(args, cwd=ROOT, check=True, capture_output=True, text=True)
if output:
(ROOT / "evidence" / output).write_text(result.stdout)
if output.endswith(".json"):
record = json.loads(result.stdout)
if record.get("passed") is False:
raise RuntimeError("Security probe reported a failed invariant: " + output)
else:
print(result.stdout, end="")
return result.stdout
+39
View File
@@ -0,0 +1,39 @@
"""Own regression suite respects the real shared login budget; teacher client unchanged."""
import time
import pytest
from client import Client
_paced_logins = 0
@pytest.fixture(scope="session", autouse=True)
def honor_login_retry_after():
original = Client.call
def paced(
self, method, path, expected=200, body=None, actor=None, headers=None, raw=None, schema=None
):
global _paced_logins
if method != "POST" or path != "/api/v1/auth/sessions" or expected != 201:
return original(self, method, path, expected, body, actor, headers, raw, schema)
deadline = time.monotonic() + 90
while True:
response = original(self, method, path, [201, 429], body, actor, headers, raw, schema)
if response["status"] == 201:
return response
if time.monotonic() >= deadline:
pytest.fail("Shared login budget did not recover within test deadline")
_paced_logins += 1
time.sleep(min(10, max(1, float(response["headers"].get("Retry-After", "10")))))
Client.call = paced
yield
Client.call = original
def pytest_terminal_summary(terminalreporter):
terminalreporter.write_line(
f"Login pacing: {_paced_logins} retries honoring runtime Retry-After; teacher client unchanged."
)
+1 -1
View File
@@ -1,4 +1,4 @@
"""Black-box regressions derived from the contract and teacher review comments."""
"""Black-box regressions derived from the contract and attachment contract and edge cases."""
import hashlib
import os