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
10 changes: 7 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,13 @@ Out-of-tree code plugs in either through `config.toml`, as a `module:Class` poin
in a task's steps, so a MultiEnv's servers or a computer env's driver may name one, and writes the entry naming the
env's id, the entry pulled in from another bundle as well as the bundle's own. The env `Env.get` gives for an alias answers to the alias's
id, so a deployment records, and steps look it up by, the id the task names; its metadata writes go to the env the
alias names (`Env.stored_id`). An alias names its env only where namespace routing is on. An env store refuses to
create an env under an installed env alias's id (`EnvStore.put_document`), so a deployment recorded under an alias
always reloads the alias's env; an env stored under such an id before keeps taking versions.
alias names (`Env.stored_id`). An alias names its env only where namespace routing is on. There an env store refuses
to create an env under an installed env alias's id (`EnvStore.put_document`), so a deployment recorded under an alias
always reloads the alias's env; an env stored under such an id before keeps taking versions. A service, with routing
off, resolves no alias, so it may hold an env under an alias's id, as the hub holds `chromium` for the tasks that name
it. That env shadows the alias wherever that store is read, routing on or off (`Env.get` and the planner read the
store first), so a deployment recorded under the alias there before it was written reattaches to it from then on, or
isn't found when it lacks that deployment's version.
- `aliases.toml` gives artifacts aliases too (`[artifacts] "<folder>" = ["<alias>", ...]`; the `computers` bundle
names its base `ubuntu-24.04`), resolved by the planner wherever env aliases are, as a computer env's `computer` names
its base. `Artifact.get` reads no alias: the planner rewrites every alias an entry or a task names to its id. An alias may
Expand Down
8 changes: 6 additions & 2 deletions src/agent_env/env/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
VersionedEntityStoreCache,
)
from agent_env.store.query import QueryBuilder, to_document_query
from agent_env.store.routing import namespace_routing_enabled

if TYPE_CHECKING:
from agent_env.env.env import DeployedEnv, Env
Expand Down Expand Up @@ -101,8 +102,11 @@ def put_document(self, env: _E) -> _E:
)
if existing and existing.get("type") != env.type:
raise ValueError(f"Env id '{env.id}' already exists as type '{existing.get('type')}'; cannot put as type '{env.type}'.")
# A deployment recorded under an alias reloads the alias's env, so no env of the store's own starts on its id.
if not existing and (named := installed_aliases(table=ENV_ALIASES).target(env.id)) is not None:
# Where aliases resolve, with namespace routing on, a deployment recorded under an alias reloads its env, so no
# env of the store's own starts on its id there. A service resolves none, so it may hold one, as the hub holds
# `chromium`.
if (not existing and namespace_routing_enabled()
and (named := installed_aliases(table=ENV_ALIASES).target(env.id)) is not None):
raise ValueError(f"env id {env.id!r} is an alias of {named.target_id}, which comes with "
f"{named.declared_by}, and a task naming it deploys that env; give this env another id")
env.version = self._versioned_cache.for_store(store).put(env)
Expand Down
20 changes: 20 additions & 0 deletions tst/unit/env/alias_get_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,23 @@ def test_an_env_the_store_held_under_an_aliass_id_before_keeps_taking_versions(a
_put_before_the_alias(monkeypatch, "mail")

assert _put("mail").version == 2


def test_a_service_holds_an_env_under_an_installed_aliass_id_and_a_task_naming_it_there_deploys_it(bundles):
"""A service runs with namespace routing off and resolves no alias, so it holds the env a task names by it."""
held = _put("mail")

env = Env.get("mail")

assert (env.id, env.stored_id, env.version) == ("mail", "mail", held.version)


def test_where_aliases_resolve_the_env_a_service_holds_under_an_aliass_id_is_the_one_it_names(bundles):
"""The store's env of an id wins over an alias, so a CLI run against the service's store deploys the same env."""
held = _put("mail")
with namespace_routing():
_put(SHIPPED)

env = Env.get("mail")

assert (env.stored_id, env.version) == ("mail", held.version)
Loading