From 8e21ccdfc6f3ac542066e0af08de18e6965c85c0 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 16 Nov 2026 21:04:26 -0800 Subject: [PATCH 1/4] feat(env): an env store holds the env an alias names under the alias's id when its metadata says so A service resolves no alias, so for a task naming `chromium` to deploy chromium on the hub, the hub holds that env under the id `chromium`, which the store refused: it refuses to start any env under an installed alias's id, so a deployment recorded under the alias reloads the alias's env. The alias's own env reloads as the same env, so the store now lets it take the id when its metadata carries `released_alias_metadata(alias)`: the alias, its target's id without its namespace (an entity outside a local namespace may not name one) and the agent-env version. Any other env is refused the id as before. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 +++- src/agent_env/env/store.py | 36 +++++++++++++++++++++++++--- tst/unit/env/alias_get_test.py | 43 ++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 6 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e3f78a8bb..797e4ed1a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -275,7 +275,10 @@ Out-of-tree code plugs in either through `config.toml`, as a `module:Class` poin 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. + always reloads the alias's env; an env stored under such an id before keeps taking versions. It lets the alias's own + env take the id when its metadata says so (`released_alias_metadata(alias)`: the alias, its target's id without the + namespace, which an entity outside it may not name, and the agent-env version), which is how a service, resolving no + alias, holds `chromium` so a task naming it deploys that env there too. - `aliases.toml` gives artifacts aliases too (`[artifacts] "" = ["", ...]`; 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 diff --git a/src/agent_env/env/store.py b/src/agent_env/env/store.py index ccdf265f3..c03e0bdbd 100644 --- a/src/agent_env/env/store.py +++ b/src/agent_env/env/store.py @@ -7,11 +7,13 @@ import secrets import string from datetime import datetime, timedelta, timezone +from importlib.metadata import version as package_version from typing import TYPE_CHECKING, Any, Optional, Self, TypeVar from agent_env.plugins import _registration -from agent_env.plugins._bundles import ENV_ALIASES, installed_aliases +from agent_env.plugins._bundles import ENV_ALIASES, BundleAlias, installed_aliases from agent_env.store.base import ConcurrentModificationError, NotFoundError +from agent_env.store.ids import namespace_prefix, parse_namespace from agent_env.config import get_config from agent_env.store.document_store import ( AbsentOrNull, @@ -35,6 +37,32 @@ ENVS_COLLECTION = "envs" ENV_INSTANCES_COLLECTION = "env_instances" +#: The metadata key that marks an env as the env an installed alias names, stored under the alias's id: what a service, +#: which resolves no alias, holds so a task naming the alias deploys that env there too. +RELEASED_ALIAS = "released_alias" + + +def released_alias_metadata(alias: str) -> dict[str, Any]: + """The metadata that marks an env as the env the installed env alias ``alias`` names, which the store lets take the + alias's id: the alias, its target's id without its namespace, which an entity outside that namespace may not name, + and the agent-env version that released it. Raises ValueError for a name that isn't an installed env alias.""" + named = installed_aliases(table=ENV_ALIASES).target(alias) + if named is None: + raise ValueError(f"{alias!r} isn't an env alias an installed bundle gives") + return {RELEASED_ALIAS: {"alias": alias, "target": _unscoped(named.target_id), + "agent_env_version": package_version("agentenv-framework")}} + + +def _released_as(env: Env, named: BundleAlias) -> bool: + """Whether ``env``'s metadata marks it as the env the alias ``named`` names (``released_alias_metadata``).""" + mark = (env.metadata or {}).get(RELEASED_ALIAS) + return (isinstance(mark, dict) and mark.get("alias") == named.alias + and mark.get("target") == _unscoped(named.target_id)) + + +def _unscoped(entity_id: str) -> str: + namespace = parse_namespace(entity_id) + return entity_id.removeprefix(namespace_prefix(namespace)) if namespace else entity_id class EnvQuery(QueryBuilder["Env"]): @@ -101,8 +129,10 @@ 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: + # A deployment recorded under an alias reloads the alias's env, so no env of the store's own starts on its id + # but the alias's own, which a service holds there since it resolves no alias. + if (not existing and (named := installed_aliases(table=ENV_ALIASES).target(env.id)) is not None + and not _released_as(env, named)): 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) diff --git a/tst/unit/env/alias_get_test.py b/tst/unit/env/alias_get_test.py index 5dc1e1c53..2cb441f3c 100644 --- a/tst/unit/env/alias_get_test.py +++ b/tst/unit/env/alias_get_test.py @@ -9,6 +9,7 @@ from agent_env.env import store as env_store_module from agent_env.env.env import Env from agent_env.env.envs.mcp_server import MCPServerEnv +from agent_env.env.store import RELEASED_ALIAS, released_alias_metadata from agent_env.plugins._bundles import ALIASES_FILE, InstalledAliases, InstalledBundle, installed_aliases from agent_env.store.base import NotFoundError from agent_env.store.routing import namespace_routing @@ -37,10 +38,10 @@ def aliases(bundles, cli_routing): """``bundles``, with namespace routing on, as in the CLI.""" -def _put(env_id): +def _put(env_id, metadata=None): image = get_artifact_store().put_document(DockerImageArtifact( id=f"{env_id}/env_image", description="d", image_name="ghcr.io/acme/mail:1", tar_gz_s3_url="s3://b/x")) - return MCPServerEnv.put(id=env_id, docker_image_artifact=image, environment_name="mail") + return MCPServerEnv.put(id=env_id, docker_image_artifact=image, environment_name="mail", metadata=metadata) def _put_before_the_alias(monkeypatch, env_id): @@ -125,3 +126,41 @@ 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_the_aliass_own_released_env_is_stored_under_its_id_and_a_task_naming_it_there_deploys_it(bundles): + """A service resolves no alias, so it holds the env the alias names under the alias's id.""" + released = _put("mail", released_alias_metadata("mail")) + + env = Env.get("mail") + + assert (env.id, env.version, env.stored_id) == ("mail", 1, "mail") and released.version == 1 + assert env.metadata[RELEASED_ALIAS]["target"] == "agentenv-framework/mail-mcp/mail" + assert env.metadata[RELEASED_ALIAS]["alias"] == "mail" and env.metadata[RELEASED_ALIAS]["agent_env_version"] + + +def test_where_aliases_resolve_the_stores_released_env_is_the_one_a_task_naming_the_alias_deploys(aliases): + _put("mail", released_alias_metadata("mail")) + + env = Env.get("mail") + + assert (env.stored_id, env.metadata[RELEASED_ALIAS]["target"]) == ("mail", "agentenv-framework/mail-mcp/mail") + + +@pytest.mark.parametrize("mark", [ + {"alias": "mail", "target": "acme-kit/kit/a"}, + {"alias": "helper", "target": "agentenv-framework/mail-mcp/mail"}, + {"alias": "mail", "target": SHIPPED}, + {"target": "agentenv-framework/mail-mcp/mail"}, + "mail", +]) +def test_an_env_marked_as_another_aliass_or_another_envs_release_is_still_refused_the_aliass_id(bundles, mark): + with pytest.raises(ValueError, match="env id 'mail' is an alias of"): + _put("mail", {RELEASED_ALIAS: mark}) + + +def test_only_an_installed_env_alias_has_a_released_env(bundles): + with pytest.raises(ValueError, match="'helper' isn't an env alias an installed bundle gives"): + released_alias_metadata("helper") + with pytest.raises(ValueError, match="'nothing' isn't an env alias"): + released_alias_metadata("nothing") From 51c7651007b0de08fc2dfa2bf9586f0985df6d82 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 16 Nov 2026 21:49:00 -0800 Subject: [PATCH 2/4] docs(env): the alias's released env shadows the alias in its store, older alias deployments included Writing it shadows the alias as any store env of the alias's id does, since Env.get and the planner read the store first. A deployment recorded under the alias in that store before then, with routing on, reattaches to it from then on, or isn't found when it lacks that deployment's version: a one-time moment per store and alias, documented rather than handled. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 797e4ed1a..0ba6bc5fb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -278,7 +278,10 @@ Out-of-tree code plugs in either through `config.toml`, as a `module:Class` poin always reloads the alias's env; an env stored under such an id before keeps taking versions. It lets the alias's own env take the id when its metadata says so (`released_alias_metadata(alias)`: the alias, its target's id without the namespace, which an entity outside it may not name, and the agent-env version), which is how a service, resolving no - alias, holds `chromium` so a task naming it deploys that env there too. + alias, holds `chromium` so a task naming it deploys that env there too. That env then shadows the alias in that store, + as any store env of an alias's id does (`Env.get` and the planner read the store first), so a deployment recorded + under the alias there before it was written, with routing on, reattaches to it from then on, or isn't found when it + lacks that deployment's version. - `aliases.toml` gives artifacts aliases too (`[artifacts] "" = ["", ...]`; 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 From e3005ad76d6730bc2b899d538ddafafe2c113d88 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 16 Nov 2026 22:56:38 -0800 Subject: [PATCH 3/4] fix(env): each version of an alias's released env keeps its mark The store checked the mark only on an env's first version under an alias's id, so once the released env was written, any later version, marked or not, could become the latest and shadow the alias for every task naming it. A new version of an env whose latest version is marked must now carry the mark too. An env that held an alias's id before the alias existed carries none, and keeps taking versions as before. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 5 +++-- src/agent_env/env/store.py | 15 ++++++++++++--- tst/unit/env/alias_get_test.py | 12 ++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0ba6bc5fb..cfe4ea4e1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -277,8 +277,9 @@ Out-of-tree code plugs in either through `config.toml`, as a `module:Class` poin 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. It lets the alias's own env take the id when its metadata says so (`released_alias_metadata(alias)`: the alias, its target's id without the - namespace, which an entity outside it may not name, and the agent-env version), which is how a service, resolving no - alias, holds `chromium` so a task naming it deploys that env there too. That env then shadows the alias in that store, + namespace, which an entity outside it may not name, and the agent-env version), and refuses a later version of that + env without the mark, which is how a service, resolving no alias, holds `chromium` so a task naming it deploys that + env there too. That env then shadows the alias in that store, as any store env of an alias's id does (`Env.get` and the planner read the store first), so a deployment recorded under the alias there before it was written, with routing on, reattaches to it from then on, or isn't found when it lacks that deployment's version. diff --git a/src/agent_env/env/store.py b/src/agent_env/env/store.py index c03e0bdbd..72e5a9165 100644 --- a/src/agent_env/env/store.py +++ b/src/agent_env/env/store.py @@ -60,6 +60,11 @@ def _released_as(env: Env, named: BundleAlias) -> bool: and mark.get("target") == _unscoped(named.target_id)) +def _marked(document: dict) -> bool: + """Whether a stored env's ``document`` is marked as an alias's released env.""" + return isinstance((document.get("metadata") or {}).get(RELEASED_ALIAS), dict) + + def _unscoped(entity_id: str) -> str: namespace = parse_namespace(entity_id) return entity_id.removeprefix(namespace_prefix(namespace)) if namespace else entity_id @@ -130,9 +135,13 @@ 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 - # but the alias's own, which a service holds there since it resolves no alias. - if (not existing and (named := installed_aliases(table=ENV_ALIASES).target(env.id)) is not None - and not _released_as(env, named)): + # but the alias's own, which a service holds there since it resolves no alias, and keeps its mark after. + named = installed_aliases(table=ENV_ALIASES).target(env.id) if not existing or _marked(existing) else None + if named is not None and not _released_as(env, named): + if existing: + raise ValueError(f"env {env.id!r} is the released env of the alias {env.id!r}, which names " + f"{named.target_id}, so each of its versions carries that mark " + f"(released_alias_metadata({env.id!r})); put this one with it") 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) diff --git a/tst/unit/env/alias_get_test.py b/tst/unit/env/alias_get_test.py index 2cb441f3c..3136f21b2 100644 --- a/tst/unit/env/alias_get_test.py +++ b/tst/unit/env/alias_get_test.py @@ -147,6 +147,18 @@ def test_where_aliases_resolve_the_stores_released_env_is_the_one_a_task_naming_ assert (env.stored_id, env.metadata[RELEASED_ALIAS]["target"]) == ("mail", "agentenv-framework/mail-mcp/mail") +def test_each_version_of_the_aliass_released_env_keeps_its_mark(bundles): + _put("mail", released_alias_metadata("mail")) + + assert _put("mail", released_alias_metadata("mail")).version == 2 + with pytest.raises(ValueError, match=r"env 'mail' is the released env of the alias 'mail', which names " + rf"{SHIPPED}, so each of its versions carries that mark"): + _put("mail") + with pytest.raises(ValueError, match="is the released env of the alias 'mail'"): + _put("mail", {RELEASED_ALIAS: {"alias": "mail", "target": "acme-kit/kit/a"}}) + assert Env.get("mail").version == 2 + + @pytest.mark.parametrize("mark", [ {"alias": "mail", "target": "acme-kit/kit/a"}, {"alias": "helper", "target": "agentenv-framework/mail-mcp/mail"}, From dbe5e19f28b96777c5493b8c381698e483badfb7 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Tue, 17 Nov 2026 08:23:34 -0800 Subject: [PATCH 4/4] refactor(env): the env store refuses an alias's id only where aliases resolve, in place of the released-alias mark The store refuses an env under an installed alias's id so that a deployment recorded under the alias reloads the alias's env, and deployments are recorded under an alias only where aliases resolve, with namespace routing on. A service runs with routing off and resolves none, so there the refusal protected nothing. The refusal now applies only with routing on, and a service may hold an env under an alias's id, as the hub will hold `chromium`, with no mark: `released_alias_metadata`, `RELEASED_ALIAS` and the rule that each version keeps the mark are gone. The store's env of an id still wins over the alias wherever that store is read. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 17 +++++----- src/agent_env/env/store.py | 49 +++++------------------------ tst/unit/env/alias_get_test.py | 57 ++++++++-------------------------- 3 files changed, 27 insertions(+), 96 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index cfe4ea4e1..725a1e217 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -273,16 +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. It lets the alias's own - env take the id when its metadata says so (`released_alias_metadata(alias)`: the alias, its target's id without the - namespace, which an entity outside it may not name, and the agent-env version), and refuses a later version of that - env without the mark, which is how a service, resolving no alias, holds `chromium` so a task naming it deploys that - env there too. That env then shadows the alias in that store, - as any store env of an alias's id does (`Env.get` and the planner read the store first), so a deployment recorded - under the alias there before it was written, with routing on, reattaches to it from then on, or isn't found when it - lacks that deployment's version. + 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] "" = ["", ...]`; 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 diff --git a/src/agent_env/env/store.py b/src/agent_env/env/store.py index 72e5a9165..84ea4a216 100644 --- a/src/agent_env/env/store.py +++ b/src/agent_env/env/store.py @@ -7,13 +7,11 @@ import secrets import string from datetime import datetime, timedelta, timezone -from importlib.metadata import version as package_version from typing import TYPE_CHECKING, Any, Optional, Self, TypeVar from agent_env.plugins import _registration -from agent_env.plugins._bundles import ENV_ALIASES, BundleAlias, installed_aliases +from agent_env.plugins._bundles import ENV_ALIASES, installed_aliases from agent_env.store.base import ConcurrentModificationError, NotFoundError -from agent_env.store.ids import namespace_prefix, parse_namespace from agent_env.config import get_config from agent_env.store.document_store import ( AbsentOrNull, @@ -27,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 @@ -37,37 +36,6 @@ ENVS_COLLECTION = "envs" ENV_INSTANCES_COLLECTION = "env_instances" -#: The metadata key that marks an env as the env an installed alias names, stored under the alias's id: what a service, -#: which resolves no alias, holds so a task naming the alias deploys that env there too. -RELEASED_ALIAS = "released_alias" - - -def released_alias_metadata(alias: str) -> dict[str, Any]: - """The metadata that marks an env as the env the installed env alias ``alias`` names, which the store lets take the - alias's id: the alias, its target's id without its namespace, which an entity outside that namespace may not name, - and the agent-env version that released it. Raises ValueError for a name that isn't an installed env alias.""" - named = installed_aliases(table=ENV_ALIASES).target(alias) - if named is None: - raise ValueError(f"{alias!r} isn't an env alias an installed bundle gives") - return {RELEASED_ALIAS: {"alias": alias, "target": _unscoped(named.target_id), - "agent_env_version": package_version("agentenv-framework")}} - - -def _released_as(env: Env, named: BundleAlias) -> bool: - """Whether ``env``'s metadata marks it as the env the alias ``named`` names (``released_alias_metadata``).""" - mark = (env.metadata or {}).get(RELEASED_ALIAS) - return (isinstance(mark, dict) and mark.get("alias") == named.alias - and mark.get("target") == _unscoped(named.target_id)) - - -def _marked(document: dict) -> bool: - """Whether a stored env's ``document`` is marked as an alias's released env.""" - return isinstance((document.get("metadata") or {}).get(RELEASED_ALIAS), dict) - - -def _unscoped(entity_id: str) -> str: - namespace = parse_namespace(entity_id) - return entity_id.removeprefix(namespace_prefix(namespace)) if namespace else entity_id class EnvQuery(QueryBuilder["Env"]): @@ -134,14 +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 - # but the alias's own, which a service holds there since it resolves no alias, and keeps its mark after. - named = installed_aliases(table=ENV_ALIASES).target(env.id) if not existing or _marked(existing) else None - if named is not None and not _released_as(env, named): - if existing: - raise ValueError(f"env {env.id!r} is the released env of the alias {env.id!r}, which names " - f"{named.target_id}, so each of its versions carries that mark " - f"(released_alias_metadata({env.id!r})); put this one with it") + # 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) diff --git a/tst/unit/env/alias_get_test.py b/tst/unit/env/alias_get_test.py index 3136f21b2..dd486bc4c 100644 --- a/tst/unit/env/alias_get_test.py +++ b/tst/unit/env/alias_get_test.py @@ -9,7 +9,6 @@ from agent_env.env import store as env_store_module from agent_env.env.env import Env from agent_env.env.envs.mcp_server import MCPServerEnv -from agent_env.env.store import RELEASED_ALIAS, released_alias_metadata from agent_env.plugins._bundles import ALIASES_FILE, InstalledAliases, InstalledBundle, installed_aliases from agent_env.store.base import NotFoundError from agent_env.store.routing import namespace_routing @@ -38,10 +37,10 @@ def aliases(bundles, cli_routing): """``bundles``, with namespace routing on, as in the CLI.""" -def _put(env_id, metadata=None): +def _put(env_id): image = get_artifact_store().put_document(DockerImageArtifact( id=f"{env_id}/env_image", description="d", image_name="ghcr.io/acme/mail:1", tar_gz_s3_url="s3://b/x")) - return MCPServerEnv.put(id=env_id, docker_image_artifact=image, environment_name="mail", metadata=metadata) + return MCPServerEnv.put(id=env_id, docker_image_artifact=image, environment_name="mail") def _put_before_the_alias(monkeypatch, env_id): @@ -128,51 +127,21 @@ def test_an_env_the_store_held_under_an_aliass_id_before_keeps_taking_versions(a assert _put("mail").version == 2 -def test_the_aliass_own_released_env_is_stored_under_its_id_and_a_task_naming_it_there_deploys_it(bundles): - """A service resolves no alias, so it holds the env the alias names under the alias's id.""" - released = _put("mail", released_alias_metadata("mail")) +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.version, env.stored_id) == ("mail", 1, "mail") and released.version == 1 - assert env.metadata[RELEASED_ALIAS]["target"] == "agentenv-framework/mail-mcp/mail" - assert env.metadata[RELEASED_ALIAS]["alias"] == "mail" and env.metadata[RELEASED_ALIAS]["agent_env_version"] + assert (env.id, env.stored_id, env.version) == ("mail", "mail", held.version) -def test_where_aliases_resolve_the_stores_released_env_is_the_one_a_task_naming_the_alias_deploys(aliases): - _put("mail", released_alias_metadata("mail")) - - env = Env.get("mail") - - assert (env.stored_id, env.metadata[RELEASED_ALIAS]["target"]) == ("mail", "agentenv-framework/mail-mcp/mail") - +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) -def test_each_version_of_the_aliass_released_env_keeps_its_mark(bundles): - _put("mail", released_alias_metadata("mail")) + env = Env.get("mail") - assert _put("mail", released_alias_metadata("mail")).version == 2 - with pytest.raises(ValueError, match=r"env 'mail' is the released env of the alias 'mail', which names " - rf"{SHIPPED}, so each of its versions carries that mark"): - _put("mail") - with pytest.raises(ValueError, match="is the released env of the alias 'mail'"): - _put("mail", {RELEASED_ALIAS: {"alias": "mail", "target": "acme-kit/kit/a"}}) - assert Env.get("mail").version == 2 - - -@pytest.mark.parametrize("mark", [ - {"alias": "mail", "target": "acme-kit/kit/a"}, - {"alias": "helper", "target": "agentenv-framework/mail-mcp/mail"}, - {"alias": "mail", "target": SHIPPED}, - {"target": "agentenv-framework/mail-mcp/mail"}, - "mail", -]) -def test_an_env_marked_as_another_aliass_or_another_envs_release_is_still_refused_the_aliass_id(bundles, mark): - with pytest.raises(ValueError, match="env id 'mail' is an alias of"): - _put("mail", {RELEASED_ALIAS: mark}) - - -def test_only_an_installed_env_alias_has_a_released_env(bundles): - with pytest.raises(ValueError, match="'helper' isn't an env alias an installed bundle gives"): - released_alias_metadata("helper") - with pytest.raises(ValueError, match="'nothing' isn't an env alias"): - released_alias_metadata("nothing") + assert (env.stored_id, env.version) == ("mail", held.version)