Merge pull request 'lib/introspect: use valueMeta to expose more information' (#5262) from update-service into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5262
This commit is contained in:
@@ -51,6 +51,8 @@ def get_priority(value: Any) -> int | None:
|
||||
"""Extract priority from a value, handling both dict and non-dict cases."""
|
||||
if isinstance(value, dict) and "__prio" in value:
|
||||
return value["__prio"]
|
||||
if isinstance(value, dict) and "__this" in value:
|
||||
return value["__this"]["prio"]
|
||||
return None
|
||||
|
||||
|
||||
@@ -110,7 +112,7 @@ def _determine_writeability_recursive(
|
||||
|
||||
for key, value in priorities.items():
|
||||
# Skip metadata keys
|
||||
if key == "__prio":
|
||||
if key in {"__this", "__list", "__prio"}:
|
||||
continue
|
||||
|
||||
path = (*current_path, key)
|
||||
|
||||
@@ -1,13 +1,49 @@
|
||||
from collections.abc import Callable
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
import pytest
|
||||
|
||||
from clan_lib.flake.flake import Flake
|
||||
from clan_lib.persist.inventory_store import InventoryStore
|
||||
from clan_lib.persist.write_rules import compute_write_map
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from clan_lib.nix_models.clan import Clan
|
||||
|
||||
|
||||
# Integration test
|
||||
@pytest.mark.with_core
|
||||
def test_write_integration(clan_flake: Callable[..., Flake]) -> None:
|
||||
clan_nix: Clan = {}
|
||||
flake = clan_flake(clan_nix)
|
||||
inventory_store = InventoryStore(flake)
|
||||
# downcast into a dict
|
||||
data_eval = cast("dict", inventory_store.read())
|
||||
prios = flake.select("clanInternals.inventoryClass.introspection")
|
||||
|
||||
res = compute_write_map(prios, data_eval, {})
|
||||
|
||||
# We should be able to write to these top-level keys
|
||||
assert ("machines",) in res["writeable"]
|
||||
assert ("instances",) in res["writeable"]
|
||||
assert ("meta",) in res["writeable"]
|
||||
|
||||
# Managed by nix
|
||||
assert ("assertions",) in res["non_writeable"]
|
||||
|
||||
|
||||
# New style __this.prio
|
||||
|
||||
|
||||
def test_write_simple() -> None:
|
||||
prios = {
|
||||
"foo": {
|
||||
"__prio": 100, # <- writeable: "foo"
|
||||
"bar": {"__prio": 1000}, # <- writeable: mkDefault "foo.bar"
|
||||
"__this": {
|
||||
"prio": 100, # <- writeable: "foo"
|
||||
},
|
||||
"bar": {"__this": {"prio": 1000}}, # <- writeable: mkDefault "foo.bar"
|
||||
},
|
||||
"foo.bar": {"__prio": 1000},
|
||||
"foo.bar": {"__this": {"prio": 1000}},
|
||||
}
|
||||
|
||||
default: dict = {"foo": {}}
|
||||
@@ -20,6 +56,9 @@ def test_write_simple() -> None:
|
||||
}
|
||||
|
||||
|
||||
# Compatibility test for old __prio style
|
||||
|
||||
|
||||
def test_write_inherited() -> None:
|
||||
prios = {
|
||||
"foo": {
|
||||
|
||||
Reference in New Issue
Block a user