Перенос исправления PR #99 (lab3): строки с U+0000 вместо 500

Expand-миграция 0005 (*_raw bytea для text, display_name, title), app/pgtext.py,
тест test_nul_in_text_roundtrip в регрессии lab3, раздел в REPORT.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 12:33:43 +03:00
co-authored by Claude Opus 5.5
parent 25d59bbcb2
commit 7844e7d4b8
5 changed files with 80 additions and 15 deletions
+29 -2
View File
@@ -249,15 +249,42 @@ def test_infrastructure_rules(_c: Client):
mounts = {m['Destination'] for m in cfg['Mounts']}
check(mounts <= {'/run/secrets/database_url', '/run/secrets/cache_url', '/run/secrets/s3_access_key_id',
'/run/secrets/s3_secret_access_key'}, f'api has unexpected mounts {mounts}') # lab4: + S3
check(sql('SELECT count(*) FROM schema_migrations') == '4', 'unexpected migration count') # lab4: + 0004_attachments
check(sql('SELECT count(*) FROM schema_migrations') == '5', 'unexpected migration count') # lab4: + 0004_attachments, 0005_nul_safe_text
with urllib.request.urlopen(os.environ.get('LB_STATS_URL', 'http://lb:8404/stats') + ';csv', timeout=2) as r:
text = r.read().decode()
check(',UP,' in text or ',UP ' in text, 'LB stats show no UP backend')
def test_nul_in_text_roundtrip(c: Client):
"""Замечание к PR #99: {"text":"abc\\u0000def"} давал 500. Строка с U+0000 сохраняется точно."""
alice, bob, _eve, _chat = c.bootstrap()
text = 'abc\u0000def'
chat = c.call('POST', '/api/v1/chats', 201, actor=alice,
body={'title': 'чат\u0000NUL', 'member_ids': [alice['id'], bob['id']]}, schema='Chat')['json']
check(chat['title'] == 'чат\u0000NUL', 'title with NUL changed in response')
got = c.call('GET', '/api/v1/chats/' + chat['id'], actor=bob, schema='Chat')['json']
check(got['title'] == 'чат\u0000NUL', 'title with NUL changed on read')
key = uuid.uuid4().hex
first = c.message(alice, chat, text, key=key)['json']
check(first['text'] == text, 'response text differs')
replay = c.message(alice, chat, text, key=key)['json']
check(replay == first, 'idempotent replay differs')
c.call('POST', '/api/v1/chats/' + chat['id'] + '/messages', 409, actor=alice,
body={'text': 'abc\ufffddef'}, headers={'Idempotency-Key': key}) # U+FFFD — другой текст
c.message(alice, chat, '\u0000') # только NUL — не пробел, допустим
history = c.call('GET', '/api/v1/chats/' + chat['id'] + '/messages', actor=bob,
schema='MessagePage')['json']['items']
check([m['text'] for m in history] == [text, '\u0000'], 'history lost NUL')
name = 'Имя\u0000Фамилия'
user = c.call('POST', '/api/v1/users', 201, body={'username': 'nul_' + uuid.uuid4().hex[:12],
'display_name': name, 'password': 'T3st-' + uuid.uuid4().hex}, schema='User')['json']
check(user['display_name'] == name, 'display_name with NUL changed')
TESTS = [test_session_across_replicas, test_same_key_concurrent_across_replicas,
test_same_key_concurrent_different_bodies, test_key_scope_and_format, test_replay_rechecks_session,
test_transient_failure_not_recorded, test_sigterm_drain, test_infrastructure_rules]
test_transient_failure_not_recorded, test_sigterm_drain, test_infrastructure_rules,
test_nul_in_text_roundtrip]
def main() -> int: