Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ keywords = [
requires-python = ">=3.12.2"
dependencies = [
"hio==0.6.14",
"keri>=1.2.13,<1.3",
"keri==1.2.14",
"mnemonic==0.21",
"multicommand>=1.0.0",
"falcon==4.0.2",
Expand Down
39 changes: 38 additions & 1 deletion src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
querying,
connecting,
grouping,
tocking,
)
from keri.app import delegating as kdelegating
from keri.app.grouping import Counselor
Expand Down Expand Up @@ -164,6 +165,32 @@ def readConfigFile(configDir: str, configFile: str, temp=False):
)


def keriTocks(cf):
Comment thread
iFergal marked this conversation as resolved.
"""Resolve KERIpy cadences while reserving the existing KERIA Agent keys.

Keep the config file intact so Agent can still read its legacy flat tocks.
Unknown keys and KERIpy values remain subject to KERIpy's validation.
"""
return tocking.resolveTocks(
cf.get().get("tocks") if cf is not None else None,
reserved=(
"signify",
"initer",
"querier",
"escrower",
"parser",
"witnesser",
"delegator",
"exchangeSender",
"granter",
"admitter",
"groupRequester",
"seeker",
"exchangecue",
),
)


def runAgency(config: KERIAServerConfig, temp=False):
"""Runs a KERIA Agency with the given Doers by calling Doist.do(). Useful for testing."""
set_log_level(config.logLevel, logger)
Expand Down Expand Up @@ -361,6 +388,7 @@ def create(self, caid, salt=None):
bran=self.bran,
ks=ks,
cf=agent_cf,
tocks=keriTocks(agent_cf),
temp=self.temp,
salt=salt,
)
Expand Down Expand Up @@ -441,8 +469,17 @@ def get(self, caid):

ks = keeping.Keeper(name=caid, base=self.base, temp=self.temp, reopen=True)

cf = configing.Configer(
name=caid, base=self.base, temp=self.temp, reopen=True, clear=False
)
agentHby = habbing.Habery(
name=caid, base=self.base, bran=self.bran, ks=ks, temp=self.temp
name=caid,
base=self.base,
bran=self.bran,
ks=ks,
temp=self.temp,
cf=cf,
tocks=keriTocks(cf),
)

agentHab = agentHby.habByName(f"agent-{caid}", ns="agent")
Expand Down
8 changes: 7 additions & 1 deletion src/keria/testing/testing_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,13 @@ def openKeria(salter=None, cf=None, temp=True):
)

agency = agenting.Agency(name="agency", bran=None, temp=True)
with habbing.openHby(name="keria", salt=salter.qb64, temp=temp, cf=cf) as hby:
with habbing.openHby(
name="keria",
salt=salter.qb64,
temp=temp,
cf=cf,
tocks=agenting.keriTocks(cf),
) as hby:
ims = eventing.messagize(serder, sigers=sigers)
parsing.Parser(kvy=hby.kvy).parseOne(ims=ims)

Expand Down
62 changes: 62 additions & 0 deletions tests/app/test_agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

from keria.app import agenting, aiding
from keria.core import longrunning, httping
from keria.db import basing as agencybasing
from keria.testing.testing_helper import SCRIPTS_DIR


Expand Down Expand Up @@ -192,6 +193,67 @@ def test_load_ends(helpers):
assert isinstance(end, agenting.ConfigResourceEnd)


def test_keri_tocks_preserves_agent_config(monkeypatch):
config = {"tocks": {"escrower": 1.0, "initer": 0.0, "receiptor": 0.25}}
with configing.openCF(temp=True) as cf:
cf.put(config)
monkeypatch.setenv("KERI_RECEIPTOR_TOCK", "0.125")
tocks = agenting.keriTocks(cf)
assert tocks["receiptor"] == 0.125
assert "escrower" not in tocks
assert "initer" not in tocks
assert cf.get() == config

cf.put({"tocks": {"escrower": 1.0, "receiptorTypo": 0.25}})
with pytest.raises(kering.ConfigurationError, match="receiptorTypo"):
agenting.keriTocks(cf)


def test_agency_reopens_legacy_tocks():
"""Reload an evicted Agent from disk and retain its legacy tock settings."""
caid = core.Signer().verfer.qb64
with dbing.openLMDB(cls=agencybasing.AgencyBaser, temp=True) as adb:
cf = agenting.readConfigFile(SCRIPTS_DIR, "legacy-tocks")
agency = agenting.Agency(name="agency", bran=None, cf=cf, adb=adb)
doist = doing.Doist()
doist.enter(doers=[agency])
# Provision the Agent and write its own config from the legacy fixture.
agent = agency.create(caid)
try:
assert agent.tocks["escrower"] == 1.0
assert agent.hby.tocks["receiptor"] == 0.25
persisted_config_path = agent.hby.cf.path
# Close the Agent's resources and evict it from the Agency cache,
# leaving its configuration and databases on disk for reopening.
agency.shut(agent)
assert caid not in agency.agents

# This cache miss is the reopen: Agency.get constructs a new Agent
# from its persisted config and databases, rather than returning
# the previously cached instance or provisioning it again.
agent = agency.get(caid)
assert agent.hby.cf.path == persisted_config_path
assert agent.hby.cf.get()["tocks"] == cf.get()["tocks"]
assert agent.tocks["escrower"] == 1.0
assert agent.hby.tocks["receiptor"] == 0.25
finally:
agency.shut(agent)
doist.exit()
for resource in (
agent.seeker,
agent.exnseeker,
agent.monitor.opr,
agent.notifier.noter,
agent.rep.mbx,
agent.rgy.reger,
agent.mgr.rb,
agent.hby,
agent.hby.cf,
):
resource.close(clear=True)
cf.close()


def test_load_tocks_config(helpers):
with helpers.openKeria() as (agency, agent, app, client):
agenting.loadEnds(app=app)
Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/keri/cf/legacy-tocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tocks": {
"initer": 0.0,
"escrower": 1.0,
"receiptor": 0.25
}
}
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.