fix(fnos): reuse content-addressed core runtime

This commit is contained in:
2026-08-12 17:33:05 +08:00
parent eec1227179
commit 1babec1b85
5 changed files with 63 additions and 12 deletions
+25 -2
View File
@@ -19,7 +19,7 @@ def _mock_app(tmp_path: Path) -> tuple[Path, Path, Path]:
app_root = tmp_path / "app"
runtime = app_root / "runtime"
(runtime / "wheels").mkdir(parents=True)
(runtime / "VERSION").write_text("0.4.3\n" + "a" * 64 + "\n")
(runtime / "VERSION").write_text("0.4.30001\n0.4.3\n" + "a" * 64 + "\n")
(runtime / "runtime-core.txt").write_text("# mocked offline core\n")
(runtime / "imagefind-0.4.3-py3-none-any.whl").write_bytes(b"mock wheel")
(runtime / "wheels" / "dependency.whl").write_bytes(b"mock dependency")
@@ -312,7 +312,7 @@ def test_runtime_bootstrap_atomically_replaces_existing_current(
assert result.returncode == 0, result.stderr
assert current.is_symlink()
assert current.resolve() == runtime_root / "core-0.4.3"
assert current.resolve() == runtime_root / "core-0.4.3-aaaaaaaaaaaaaaaa"
version = subprocess.run(
[str(current / "bin" / "python"), "-m", "imagefind.main", "--version"],
env=env,
@@ -332,6 +332,29 @@ def test_runtime_bootstrap_atomically_replaces_existing_current(
assert (previous[0] / "sentinel").read_text() == "preserve old runtime"
def test_runtime_bootstrap_reuses_content_id_across_package_builds_and_prunes_old_runtimes(tmp_path: Path):
app_root, args_file, password_file = _mock_app(tmp_path)
env = _environment(tmp_path, app_root, args_file, password_file)
runtime_root = tmp_path / "var" / "runtime"
runtime_root.mkdir(parents=True)
for name in ("core-0.3.14-old", "core-0.3.16-newer"):
old_runtime = runtime_root / name
old_runtime.mkdir()
(old_runtime / "sentinel").write_text(name)
first = _run("runtime_bootstrap", env)
target = runtime_root / "core-0.4.3-aaaaaaaaaaaaaaaa"
assert first.returncode == 0, first.stderr
assert target.is_dir()
assert len([path for path in runtime_root.glob("core-*") if path.is_dir()]) == 2
(app_root / "runtime" / "VERSION").write_text("0.4.30002\n0.4.3\n" + "a" * 64 + "\n")
second = _run("runtime_bootstrap", env)
assert second.returncode == 0, second.stderr
assert (runtime_root / "current").resolve() == target
assert len([path for path in runtime_root.glob("core-*") if path.is_dir()]) == 2
def test_config_callback_writes_validated_direct_access_atomically(tmp_path: Path):
data_root = tmp_path / "var"
env = {