883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
51 lines
3.1 KiB
Python
51 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Bulk publication boundaries and native request splitter, without client access."""
|
|
import hashlib,json,subprocess,sys,tempfile,unittest
|
|
from pathlib import Path
|
|
ROOT=Path(__file__).resolve().parents[1];sys.path.insert(0,str(ROOT/'ops'))
|
|
from item_sparse_compat import package_payloads,package_pages
|
|
from item_hotfix_report import summarize
|
|
|
|
def rows(count,size=1):
|
|
raw=b'\x01'*size;digest=hashlib.sha256(raw).hexdigest()
|
|
return [dict(table_name='ItemSparse',table_hash='0x919be54e',id=i+1,wire_hex=raw.hex(),sha256=digest)for i in range(count)]
|
|
|
|
class Paging(unittest.TestCase):
|
|
def test_legacy_single_push_identity_preserved(self):
|
|
value=rows(3);root,_=package_payloads(value);pages=package_pages(value)
|
|
self.assertEqual(pages,[dict(push_id=root,first=0,count=3,wire_bytes=74)])
|
|
def test_row_count_split_and_deterministic_coverage(self):
|
|
value=rows(4097);root,header=package_payloads(value);pages=package_pages(value)
|
|
self.assertEqual([r['count']for r in pages],[4096,1]);self.assertEqual(pages[1]['first'],4096)
|
|
self.assertEqual(len({r['push_id']for r in pages}),2)
|
|
self.assertIn('inline constexpr Push Pushes[]',header)
|
|
self.assertEqual((root,header),package_payloads(value))
|
|
self.assertNotIn(root,[p['push_id']for p in pages])
|
|
def test_bytes_split_before_codec_limit(self):
|
|
value=rows(30,65535);pages=package_pages(value)
|
|
self.assertEqual(sum(p['count']for p in pages),30)
|
|
self.assertTrue(all(p['wire_bytes']<=1048576 for p in pages))
|
|
self.assertEqual(pages[0]['count'],15)
|
|
def test_acceptance_rejects_wrong_push_and_page_directory(self):
|
|
value=rows(4097);root,_=package_payloads(value);pages=package_pages(value)
|
|
package=dict(push_id=root,rows=value,pushes=pages)
|
|
def line(push,ident):return f'10/18 12:34:56.789 {push} Table ItemSparse RecID {ident} VALIDATION_RESULT_VALID\n'
|
|
partial=summarize(line(pages[1]['push_id'],1),package)
|
|
self.assertEqual(partial['validation_rows'],[])
|
|
good=''.join(line(page['push_id'],row['id'])for page in pages for row in value[page['first']:page['first']+page['count']])
|
|
self.assertTrue(summarize(good,package)['all_expected_validated'])
|
|
with self.assertRaises(ValueError):summarize(good,dict(package,pushes=list(reversed(pages))))
|
|
def test_tombstones_retain_page_ownership(self):
|
|
active=json.loads((ROOT/'docs/evidence/data/item-sparse-compat/package.json').read_text())
|
|
tombstone=next(r for r in active['rows']if r.get('record_status')=='removed')
|
|
value=rows(4096)+[tombstone];pages=package_pages(value)
|
|
self.assertEqual(len(pages),2);self.assertEqual(pages[1]['count'],1)
|
|
package_payloads(value)
|
|
def test_native_request_partition_contract(self):
|
|
with tempfile.TemporaryDirectory()as tmp:
|
|
binary=Path(tmp)/'split'
|
|
subprocess.run(['cc','-std=c11','-Wall','-Wextra','-Werror','-fsanitize=undefined','-I'+str(ROOT/'native'),str(ROOT/'tests/hotfix_request_split_test.c'),'-o',str(binary)],check=True)
|
|
subprocess.run([str(binary)],check=True)
|
|
|
|
if __name__=='__main__':unittest.main()
|