feat: исправила JSON-поля, пагинации и отчёт

This commit is contained in:
2026-10-29 12:58:37 +03:00
parent 59adbebe68
commit 55556f5b1c
30 changed files with 44640 additions and 40186 deletions
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""Reproduce teacher feedback through LB, including absence of side effects."""
import json
from pathlib import Path
import sys
import uuid
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT/'tests'))
sys.path.insert(0, str(ROOT/'scripts'))
from client import Client
from actions import base_url
from resilience import history
def main():
c = Client(base_url())
alice, bob, eve, chat = c.bootstrap()
path = '/api/v1/chats/'+chat['id']+'/messages'
results = []
def invalid(method, url, **kwargs):
response = c.call(method, url, 400, actor=alice, **kwargs)
assert response['json']['error']['code'] == 'invalid_request'
results.append({'method': method, 'path': url, 'status': 400})
bodies = [b'{"Text":"case-field"}', b'{"TEXT":"case-field"}',
b'{"text":"good","Text":"case-field"}',
b'{"\\u0054ext":"case-field"}',
b'{"text":"first","text":"second"}',
b'{"text":"first","te\\u0078t":"second"}']
before = history(c, bob, chat)
for body in bodies:
key = uuid.uuid4().hex
invalid('POST', path, raw=body,
headers={'Content-Type': 'application/json', 'Idempotency-Key': key})
assert history(c, bob, chat) == before, 'invalid request created a message'
# Invalid JSON must not reserve the key or store a 5xx/conflict result.
message = c.message(alice, chat, 'valid-'+key, key=key)['json']
assert c.message(alice, chat, 'valid-'+key, key=key)['json'] == message
before = history(c, bob, chat)
for endpoint in ('/api/v1/chats', path):
for query in ('limit=', 'cursor=', 'limit', 'cursor',
'limit=1&limit=2', 'cursor=&cursor=garbage'):
invalid('GET', endpoint+'?'+query)
for query in ('', '?limit=1', '?limit=100'):
c.call('GET', endpoint+query, actor=alice,
schema='ChatPage' if endpoint == '/api/v1/chats' else 'MessagePage')
invalid('POST', '/api/v1/chats', body={'Title': 'wrong case', 'member_ids': [alice['id']]})
c.call('POST', '/api/v1/users', 400,
body={'Username': 'review_'+uuid.uuid4().hex[:8], 'display_name': 'Review', 'password': 'long-password'})
report = {'pass': True, 'cases': results, 'exact_json_field_names': True,
'invalid_body_has_no_message_or_key_side_effect': True,
'empty_and_duplicate_pagination_rejected': True,
'absent_and_boundary_limits_accepted': True}
(ROOT/'evidence/review-regressions.json').write_text(json.dumps(report, indent=2)+'\n', encoding='utf-8')
print('PASS: exact JSON fields, pagination presence and no message/key side effects.')
if __name__ == '__main__':
main()
+4 -1
View File
@@ -15,7 +15,10 @@ def load(path):
def main():
research = load('evidence/research.json')
verification = load('evidence/verification.json')
resilience = load('evidence/resilience-summary.json')
# Render metrics from the detailed files cited by the report, not a potentially
# stale copy of the same numbers in the summary.
resilience = [load('evidence/'+run['label']+'.json')
for run in load('evidence/resilience-summary.json')]
assert verification['all_passed'] and research['cache_improvement_confirmed']
groups = research['groups']
rows = ['### Измеренные результаты', '',
+3
View File
@@ -21,6 +21,7 @@ def main():
('offline', ['scripts/check_contract.py']),
('smoke', ['tests/smoke.py', '--base-url', base_url()]),
('integration', ['student-tests/integration.py']),
('review-regressions', ['student-tests/review_regressions.py']),
('persistence', ['tests/resilience.py', '--mode', 'persistence', '--action-script', 'scripts/restart'+suffix, '--base-url', base_url()]),
('failover', ['tests/resilience.py', '--mode', 'failover', '--action-script', 'scripts/stop-one'+suffix, '--base-url', base_url()]),
('all-replica-failures', ['student-tests/resilience_load.py']),
@@ -50,6 +51,8 @@ def main():
result['containers'] = containers()
result['all_passed'] = True
(ROOT/'evidence'/'verification.json').write_text(json.dumps(result, indent=2)+'\n')
# Keep the report synchronized whenever a new verification replaces raw data.
subprocess.run([sys.executable, '-X', 'utf8', 'student-tests/summarize.py'], cwd=ROOT, check=True)
if __name__ == '__main__':