askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
test_install_order_after_upgrade.py · 3.6 KB · 93 lines
| 1 | """Reinstalling every package after an upgrade works in any order. |
| 2 | |
| 3 | app-nav owns the `attention_sources` schema. 2026.11v3 required `object_id`; the |
| 4 | current tree makes it optional, because a declared count has no provider |
| 5 | object. Packages that declare such a count write a row there at install. On a |
| 6 | box upgraded from 2026.11v3 whose app-nav has not been reinstalled yet, the |
| 7 | installed schema still demands `object_id`, and alphabetical order installs |
| 8 | app-nav last: seven packages answered 400 on the first pass and succeeded on a |
| 9 | second. An install must not fail on another package's stale schema. |
| 10 | """ |
| 11 | |
| 12 | from __future__ import annotations |
| 13 | |
| 14 | import io |
| 15 | import json |
| 16 | import subprocess |
| 17 | import tarfile |
| 18 | from pathlib import Path |
| 19 | |
| 20 | import pytest |
| 21 | |
| 22 | import object_package_baselines |
| 23 | import object_packages |
| 24 | import object_records |
| 25 | |
| 26 | ROOT = Path(__file__).resolve().parents[1] |
| 27 | PREVIOUS = "2026.11v3" |
| 28 | DECLARES_COUNTS = "app-finance" # one of the packages that declares a count |
| 29 | |
| 30 | |
| 31 | @pytest.fixture |
| 32 | def old_nav_box(tmp_path): |
| 33 | """A data dir whose app-nav is the previous release's.""" |
| 34 | archive = subprocess.run( |
| 35 | ["git", "archive", PREVIOUS, "packages/app-nav"], cwd=ROOT, capture_output=True) |
| 36 | if archive.returncode != 0: |
| 37 | pytest.skip(f"{PREVIOUS} is not in this checkout") |
| 38 | old = tmp_path / "old" |
| 39 | old.mkdir() |
| 40 | with tarfile.open(fileobj=io.BytesIO(archive.stdout)) as tar: |
| 41 | tar.extractall(old, filter="data") |
| 42 | data = tmp_path / "data" |
| 43 | result = object_packages.install_package( |
| 44 | "app-nav", root=old / "packages", base_dir=data, allow_replace=True, |
| 45 | object_roots=[data / "objects"]) |
| 46 | assert result["mode"] == "install" |
| 47 | schema = json.loads((data / "schemas" / "attention_sources.json").read_text()) |
| 48 | object_field = next(f for f in schema["fields"] if f["name"] == "object_id") |
| 49 | assert object_field.get("required") is True # the old box really is old |
| 50 | return data |
| 51 | |
| 52 | |
| 53 | def install(name, data): |
| 54 | return object_packages.install_package( |
| 55 | name, root=ROOT / "packages", base_dir=data, allow_replace=True, |
| 56 | object_roots=[data / "objects"]) |
| 57 | |
| 58 | |
| 59 | def test_a_package_installs_before_app_nav_is_refreshed(old_nav_box): |
| 60 | result = install(DECLARES_COUNTS, old_nav_box) |
| 61 | assert result["mode"] == "install" |
| 62 | assert any("attention" in w and "app-nav" in w for w in result["warnings"]) |
| 63 | |
| 64 | |
| 65 | def test_app_nav_then_registers_what_the_earlier_install_deferred(old_nav_box): |
| 66 | install(DECLARES_COUNTS, old_nav_box) |
| 67 | rows = {r["id"] for r in object_records.read_collection_records( |
| 68 | "attention_sources", base_dir=old_nav_box)} |
| 69 | declared = {e["id"] for e in object_package_baselines.load_baseline( |
| 70 | DECLARES_COUNTS, base_dir=old_nav_box)["attention"]} |
| 71 | assert declared and not (declared & rows) |
| 72 | |
| 73 | registered = install("app-nav", old_nav_box)["registered_for_others"] |
| 74 | rows = {r["id"] for r in object_records.read_collection_records( |
| 75 | "attention_sources", base_dir=old_nav_box)} |
| 76 | assert declared <= rows |
| 77 | assert any(item["package"] == DECLARES_COUNTS for item in registered) |
| 78 | |
| 79 | |
| 80 | def test_a_second_install_after_app_nav_needs_no_warning(old_nav_box): |
| 81 | install(DECLARES_COUNTS, old_nav_box) |
| 82 | install("app-nav", old_nav_box) |
| 83 | again = install(DECLARES_COUNTS, old_nav_box) |
| 84 | assert not [w for w in again["warnings"] if "attention" in w] |
| 85 | |
| 86 | |
| 87 | def test_a_real_validation_error_is_still_refused_when_the_schema_is_current(tmp_path): |
| 88 | data = tmp_path / "data" |
| 89 | install("app-nav", data) |
| 90 | with pytest.raises(Exception): |
| 91 | object_records.create_collection_record( |
| 92 | "attention_sources", {"id": "bad", "label": "x", "severity": "no-such-level"}, |
| 93 | base_dir=data, actor="package:test") |