fix(clients): later image reads show updated file contents#23510

open8
main
fix/issue-13138-preview-cache
opened4d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 2d ago
0 / 15 viewed15 files changedLine totals unavailable

scripts/seed-read-image-cache.py · Earlier revision 8c711e7f · right 48–48

Original diff
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+"""Seed stopped, isolated V2 visual state; or write a sequence image.
+
+Seed: --template <migrated isolated sqlite> --home <empty isolated home>.
+Write: --color red|green|blue [--atomic] [--path <sandbox PNG>].
+The three completed Read rows are preseeded. Expand them in order after each
+write; this exercises production signing/cache/rendering, not event ingestion.
+Never use this script with a running target server or the live T3 home.
+"""
+import argparse
+import json
+from pathlib import Path
+import sqlite3
+import struct
+import zlib
+
+p = argparse.ArgumentParser(description=__doc__)
+p.add_argument('--template', type=Path)
+p.add_argument('--home', type=Path)
+p.add_argument('--color', choices=['red', 'green', 'blue'])
+p.add_argument('--atomic', action='store_true')
+p.add_argument('--resource-path', default='/tmp/issue-13138-fixture/outside/square.png', help='Read resource used when seeding')
+p.add_argument('--path', type=Path, default=Path('/tmp/issue-13138-fixture/outside/square.png'))
+a = p.parse_args()
+if a.color:
+    rgb = {'red': (255, 0, 0), 'green': (0, 255, 0), 'blue': (0, 0, 255)}[a.color]
+    def chunk(tag, data):
+        return struct.pack('>I', len(data)) + tag + data + struct.pack('>I', zlib.crc32(tag + data) & 0xffffffff)
+    png = b'\x89PNG\r\n\x1a\n' + chunk(b'IHDR', struct.pack('>IIBBBBB', 100, 100, 8, 2, 0, 0, 0)) + chunk(b'IDAT', zlib.compress((b'\0' + bytes(rgb) * 100) * 100)) + chunk(b'IEND', b'')
+    a.path.parent.mkdir(parents=True, exist_ok=True)
+    target = a.path.with_suffix('.replacement.png') if a.atomic else a.path
+    target.write_bytes(png)
+    if a.atomic:
+        target.replace(a.path)
+    print(json.dumps({'color': a.color, 'atomic': a.atomic, 'inode': a.path.stat().st_ino, 'bytes': len(png)}))
+else:
+    assert a.home and a.template, '--home and --template required'
+    assert '.t3/userdata' not in str(a.home.resolve()), 'Use a disposable evidence home'
+    dest = a.home / 'userdata/statev2.sqlite'
+    assert not dest.exists(), 'Refusing to replace an existing database'
+    dest.parent.mkdir(parents=True, exist_ok=True)
+    src = sqlite3.connect(f'file:{a.template.resolve()}?mode=ro', uri=True)
+    db = sqlite3.connect(dest)
+    for (sql,) in src.execute("SELECT sql FROM sqlite_master WHERE sql IS NOT NULL AND type='table' AND name NOT LIKE 'sqlite_%'"):
+        db.execute(sql)
+    for row in src.execute('SELECT * FROM effect_sql_migrations'):
+        db.execute('INSERT INTO effect_sql_migrations VALUES (' + ','.join('?' for _ in row) + ')', row)
+    f = json.loads((Path(__file__).parent / 'fixtures/read-image-cache.json').read_text().replace('/tmp/issue-13138-fixture/outside/square.png', a.resource_path))

scripts/seed-read-image-cache.py · right 48–48

scripts/fixtures/read-cache-web-states.js · Earlier revision 8c711e7f · right 1

Original diff
@@ -0,0 +1,78 @@
+/* Static appearance fixture: production image view; bypasses asset hooks and signing. */