Keep prepared search readers warm and verify abrupt indexing recovery

This commit is contained in:
karl committed 2026-10-13 01:36:34 +02:00
1 parent 423a1ea57d
commit 6b78c8bb7f
17 files changed
+1011 -41

No files matched your search

+71
View File
@@ -45,9 +45,80 @@ class PackageTests(unittest.TestCase):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("notice")
(resources / "settings.json").write_text("private settings")
media = root / ".searchi/media-runtime"
media.mkdir(parents=True)
upstream = media / "pinned-windows.zip"
with zipfile.ZipFile(upstream, "w") as archive:
for staged, member in [("bin/ffmpeg.exe", "bin/ffmpeg.exe"), ("bin/ffprobe.exe", "bin/ffprobe.exe"), ("licenses/LICENSE.txt", "LICENSE.txt")]:
archive.writestr(member, (resources / "media-runtime" / staged).read_bytes())
manifest = root / "tools/media-runtime/manifest.json"
manifest.parent.mkdir(parents=True)
manifest.write_text(json.dumps({"platforms": {"windows-x86_64": {
"archive": upstream.name, "bytes": upstream.stat().st_size,
"sha256": hashlib.sha256(upstream.read_bytes()).hexdigest()}}}))
(resources / "media-runtime/manifest.json").write_bytes(manifest.read_bytes())
inventory(resources)
return root, resources, app, root / "archive.zip"
def test_valid_pe_media_mutation_and_notice_corruption_preserve_previous_archive(self):
for name in ["bin/ffmpeg.exe", "bin/ffprobe.exe", "licenses/LICENSE.txt", "manifest.json"]:
with self.subTest(name=name), tempfile.TemporaryDirectory() as directory:
root, resources, app, output = self.fixture(directory)
output.write_bytes(b"previous package")
path = resources / "media-runtime" / name
path.write_bytes(path.read_bytes() + b"tampered")
with self.assertRaisesRegex(ValueError, "differs from pinned"):
package(root, app, output)
self.assertEqual(output.read_bytes(), b"previous package")
self.assertEqual(list(output.parent.glob("*.partial")), [])
def test_pinned_archive_corruption_preserves_previous_package(self):
with tempfile.TemporaryDirectory() as directory:
root, _, app, output = self.fixture(directory)
output.write_bytes(b"previous package")
source = root / ".searchi/media-runtime/pinned-windows.zip"
source.write_bytes(source.read_bytes() + b"changed")
with self.assertRaisesRegex(ValueError, "provenance mismatch"):
package(root, app, output)
self.assertEqual(output.read_bytes(), b"previous package")
def test_media_change_during_archive_write_preserves_previous_package(self):
with tempfile.TemporaryDirectory() as directory:
root, resources, app, output = self.fixture(directory)
output.write_bytes(b"previous package")
original = zipfile.ZipFile.open
def mutate(archive, name, mode="r", *args, **kwargs):
if name == "media-runtime/bin/ffmpeg.exe" and mode == "w":
path = resources / name
path.write_bytes(path.read_bytes() + b"changed")
return original(archive, name, mode, *args, **kwargs)
with mock.patch.object(zipfile.ZipFile, "open", mutate), self.assertRaisesRegex(ValueError, "changed while packaging"):
package(root, app, output)
self.assertEqual(output.read_bytes(), b"previous package")
def test_duplicate_helper_and_link_notice_are_rejected_before_output(self):
for kind in ["duplicate", "link"]:
with self.subTest(kind=kind), tempfile.TemporaryDirectory() as directory:
root, resources, app, output = self.fixture(directory)
output.write_bytes(b"previous package")
upstream = root / ".searchi/media-runtime/pinned-windows.zip"
with zipfile.ZipFile(upstream, "a") as archive:
if kind == "duplicate":
archive.writestr("other/ffmpeg.exe", (resources / "media-runtime/bin/ffmpeg.exe").read_bytes())
else:
entry = zipfile.ZipInfo("COPYING.txt")
entry.create_system = 3
entry.external_attr = 0o120777 << 16
archive.writestr(entry, "somewhere")
manifest = root / "tools/media-runtime/manifest.json"
data = json.loads(manifest.read_text())
data["platforms"]["windows-x86_64"].update(bytes=upstream.stat().st_size, sha256=hashlib.sha256(upstream.read_bytes()).hexdigest())
manifest.write_text(json.dumps(data))
(resources / "media-runtime/manifest.json").write_bytes(manifest.read_bytes())
with self.assertRaisesRegex(ValueError, "Invalid or duplicate"):
package(root, app, output)
self.assertEqual(output.read_bytes(), b"previous package")
def test_complete_archive_excludes_settings_and_verifies_recorded_bytes(self):
with tempfile.TemporaryDirectory() as directory:
root, _, app, output = self.fixture(directory)