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.
danq9
signup: the person chooses the password and name on the confirm page
83c7aa6
2 weeks, 5 days ago
History
test_capability_surfacing.py · 4.7 KB · 107 lines
| 1 | """The capability layer, actually used. |
| 2 | |
| 3 | `capabilities` exists so a collection gains a comment thread, an |
| 4 | attachment list or record sharing by declaring a flag -- no per-app code, |
| 5 | no per-app table, one line in the detail renderer. It shipped with |
| 6 | `tasks` as its only user, and stayed that way: ONE collection out of 98, |
| 7 | which makes a uniform layer look like a feature of one app. |
| 8 | |
| 9 | This file is the layer being used, and every choice in it is a judgement |
| 10 | about where the widget earns its place -- not a sweep. Two kinds of |
| 11 | restraint matter as much as the additions: |
| 12 | |
| 13 | **Never beside a layer that already owns the job.** projects get |
| 14 | attachments and comments but NOT `shareable`, because project_access |
| 15 | already grants project sharing and two grant paths on one record is how |
| 16 | "who can see this" stops having an answer. contacts get attachments but |
| 17 | NOT comments, because `interactions` already records what was said to |
| 18 | this person and a second thread would split that history in half. |
| 19 | |
| 20 | **Never where the audience is different.** articles could take comments, |
| 21 | but public commentary is a different permission model than an internal |
| 22 | thread, and quietly mounting one where the other is meant is worse than |
| 23 | having neither. |
| 24 | """ |
| 25 | |
| 26 | import json |
| 27 | import pathlib |
| 28 | |
| 29 | import pytest |
| 30 | |
| 31 | PACKAGES = pathlib.Path(__file__).resolve().parents[1] / "packages" |
| 32 | |
| 33 | |
| 34 | def schema(package, collection): |
| 35 | return json.loads( |
| 36 | (PACKAGES / package / "schemas" / f"{collection}.json").read_text()) |
| 37 | |
| 38 | |
| 39 | EXPECTED = { |
| 40 | ("app-invoices", "invoices"): {"comments", "attachments"}, |
| 41 | ("app-orders", "orders"): {"comments", "attachments"}, |
| 42 | ("app-projects", "projects"): {"comments", "attachments"}, |
| 43 | ("app-finance", "fin_journals"): {"comments", "attachments"}, |
| 44 | ("app-notes", "notes"): {"attachments", "shareable"}, |
| 45 | ("app-contacts", "contacts"): {"attachments"}, |
| 46 | ("app-tasks", "tasks"): {"comments", "attachments", "shareable"}, |
| 47 | } |
| 48 | |
| 49 | |
| 50 | @pytest.mark.parametrize("package,collection", sorted(EXPECTED)) |
| 51 | def test_the_declared_capabilities_are_what_was_decided(package, collection): |
| 52 | caps = schema(package, collection).get("capabilities") or {} |
| 53 | assert {name for name, on in caps.items() if on} == EXPECTED[(package, collection)] |
| 54 | assert all(value is True for value in caps.values()), \ |
| 55 | "a capability is present-and-true or absent; false is a third state " \ |
| 56 | "the renderer does not read and nobody can see" |
| 57 | |
| 58 | |
| 59 | def test_projects_do_not_gain_a_second_sharing_path(): |
| 60 | """project_access already grants project sharing. Two grant paths on |
| 61 | one record is how an access question becomes unanswerable.""" |
| 62 | assert "shareable" not in (schema("app-projects", "projects") |
| 63 | .get("capabilities") or {}) |
| 64 | |
| 65 | |
| 66 | def test_contacts_do_not_gain_a_second_history(): |
| 67 | """`interactions` records what was said to this person; a comment |
| 68 | thread beside it splits that history in half.""" |
| 69 | assert "comments" not in (schema("app-contacts", "contacts") |
| 70 | .get("capabilities") or {}) |
| 71 | |
| 72 | |
| 73 | @pytest.mark.parametrize("package,collection", sorted(EXPECTED)) |
| 74 | def test_every_capability_collection_has_a_detail_page_to_mount_into( |
| 75 | package, collection): |
| 76 | """A flag on a collection with no generative detail view mounts |
| 77 | nowhere: `maybeMountCapabilities` runs from the detail block. A |
| 78 | capability that renders nowhere is worse than an absent one, because |
| 79 | the schema claims a behaviour the product does not have.""" |
| 80 | seeds = list((PACKAGES / package / "seed").glob("views.tsv")) |
| 81 | assert seeds, f"{package} ships no views seed" |
| 82 | text = seeds[0].read_text() |
| 83 | assert '"detail"' in text and collection in text, \ |
| 84 | f"{collection} declares capabilities but seeds no detail view" |
| 85 | |
| 86 | |
| 87 | @pytest.mark.parametrize("package,collection", sorted(EXPECTED)) |
| 88 | def test_the_schema_version_was_bumped_with_the_change(package, collection): |
| 89 | """Capabilities are an additive schema change and the version is how a |
| 90 | deployed box knows it changed at all.""" |
| 91 | assert int(schema(package, collection).get("version", 0)) >= 2 |
| 92 | |
| 93 | |
| 94 | def test_the_documented_set_is_the_implemented_set(): |
| 95 | """docs/capabilities.md is a contract: a fourth flag documented but |
| 96 | unmounted, or mounted but undocumented, is the drift this catches.""" |
| 97 | doc = (PACKAGES.parent / "docs" / "capabilities.md").read_text() |
| 98 | renderer = (PACKAGES / "app-views" / "objects" / "site" |
| 99 | / "view_render.py").read_text() |
| 100 | for flag in ("comments", "attachments", "shareable"): |
| 101 | assert f"`{flag}`" in doc, flag |
| 102 | assert f"caps.{flag}" in renderer, flag |
| 103 | |
| 104 | declared = {name for caps in |
| 105 | (schema(p, c).get("capabilities") or {} for p, c in EXPECTED) |
| 106 | for name in caps} |
| 107 | assert declared == {"comments", "attachments", "shareable"} |