From e5e1561b641e86c0ce17b0195896d0230d84e1b2 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Wed, 18 Nov 2026 14:13:25 -0800 Subject: [PATCH 1/3] fix(bundle): bundle init names an installed agent registered under its alias by the alias bundle register writes an installed bundle's agent, env or artifact into a shared store under its alias (claude-code), and a task there names it so. bundle init then read it as one of the store's own and wrote it into the folder, where it shadows the installed one: the folder carried a frozen copy of agent-env's Claude Code. Now, when the registration ledger in the store says that version was written from the installed bundle that gives the alias, the import names the alias, floating, as it does an installed bundle's id. An entity stored under the alias any other way is still written into the folder. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/bundle/importer.py | 39 ++++++++++++++++++++++++++-- tst/unit/bundle/importer_test.py | 44 +++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/agent_env/bundle/importer.py b/src/agent_env/bundle/importer.py index 60666da21..a97f437f2 100644 --- a/src/agent_env/bundle/importer.py +++ b/src/agent_env/bundle/importer.py @@ -52,6 +52,7 @@ segment_problem, ) from agent_env.bundle.plan import STORE_GETTERS, check_bundle +from agent_env.bundle.register import REGISTRATIONS from agent_env.bundle.requires import Providers, Use, detected from agent_env.bundle.resolve import resolve_bundle, sync_context_paths from agent_env.config import get_config @@ -62,14 +63,18 @@ from agent_env.env.registry import get_env_registry from agent_env.eval import Eval from agent_env.plugins import ARTIFACTS, ENVS, TASK_STEPS +from agent_env.plugins._bundles import AGENT_ALIASES, ARTIFACT_ALIASES, ENV_ALIASES, InstalledAliases, installed_aliases +from agent_env.store import Filter from agent_env.store.base import NotFoundError from agent_env.store.ids import LOCAL_PREFIX, is_local_id +from agent_env.store.routing import configured_store from agent_env.store.image_store.oci_registry_credentials import names_registry from agent_env.store.image_store.registry_api import pin_digest from agent_env.task.task import Task from agent_env.task_step.registry import get_task_step_registry from agent_env.utils.paths import os_reason +_ALIAS_TABLES = {EntityKind.AGENT: AGENT_ALIASES, EntityKind.ENV: ENV_ALIASES, EntityKind.ARTIFACT: ARTIFACT_ALIASES} # How long a name taken from an id may be, in bytes; ids are capped far above it, and a longer name helps nobody. _MAX_NAME_BYTES = 200 _DOWNLOADS = 8 # objects downloaded at once @@ -152,6 +157,9 @@ def ref(self, entity: Any) -> str | dict: if (bundle := self.importer._installed_for(kind, entity.id)) is not None: self.importer.floating.append(Floating(self.folder, kind, entity.id, _from_bundle(bundle))) return entity.id + if (bundle := self.importer._registered_from(kind, entity)) is not None: + self.importer.floating.append(Floating(self.folder, kind, entity.id, _registered_from_bundle(bundle))) + return entity.id local = self.importer.local(kind, entity, self.folder) return local if local is not None else {kind.value: entity.id, "version": entity.version} @@ -207,6 +215,7 @@ def __init__(self, dest: Path | None, include_scopes: Collection[FieldScope] = ( self.jobs: list[ImageJob] = [] self.providers = Providers() self.installed: tuple[InstalledBundle, ...] | None = None + self.aliases: dict[str, InstalledAliases] = {} # the installed bundles' aliases, by aliases.toml table if self.dest is not None: _check_destination(self.dest) @@ -454,6 +463,9 @@ def _ref(self, site: RefSite, where: str, pins: Mapping[str, set[int]]) -> None: if isinstance(entity, str): self.problems.append(f"{where}: {entity}") return + if (bundle := self._registered_from(kind, entity)) is not None: + self._from_installed(site, where, bundle, _registered_from_bundle(bundle)) + return if isinstance(site.key, str) and (why := _not_taken(site, entity)) is not None: # The store holds the step as it is, though the step can't read what it names; a folder can't. site.rewrite(None) @@ -535,9 +547,27 @@ def _installed_for(self, kind: EntityKind, entity_id: str) -> InstalledBundle | self.installed = installed_bundles() return next((bundle for bundle in self.installed if entity_id.startswith(f"{bundle.id_root}/")), None) - def _from_installed(self, site: RefSite, where: str, bundle: InstalledBundle) -> None: + def _registered_from(self, kind: EntityKind, entity: Any) -> InstalledBundle | None: + """The installed bundle ``entity`` comes with when the store holds it under that bundle's alias for it and this + version is the one ``bundle register`` wrote from the bundle, as its ledger in the store records: a run writes + it from the bundle too. An entity stored under the alias by anything else is the store's own.""" + table = _ALIAS_TABLES.get(kind) + if table is None: + return None + if self.installed is None: + self.installed = installed_bundles() + if table not in self.aliases: + self.aliases[table] = installed_aliases(self.installed, table) + if (claim := self.aliases[table].target(entity.id)) is None: + return None + registered = configured_store(get_config().get_document_store()).find_one( + REGISTRATIONS, Filter.of(store=kind.value, id=entity.id, version=entity.version, status="done", + bundle=f"installed:{claim.bundle.id_root.removeprefix(LOCAL_PREFIX)}")) + return claim.bundle if registered is not None else None + + def _from_installed(self, site: RefSite, where: str, bundle: InstalledBundle, why: str | None = None) -> None: """An installed bundle's entity has no fixed version, so it isn't pinned, and a pin the store held is dropped.""" - why = _from_bundle(bundle) + why = why or _from_bundle(bundle) if site.version is not None and site.version_key is not None: why += f"; the stored pin to v{site.version} is dropped, as such an entity has no fixed version" _unpin(site) @@ -586,6 +616,11 @@ def _from_bundle(bundle: InstalledBundle) -> str: return f"it comes with the installed bundle {bundle.qualified}, which a run writes it from" +def _registered_from_bundle(bundle: InstalledBundle) -> str: + return (f"the store holds it under its alias as registered from the installed bundle {bundle.qualified}, which a run " + "writes it from") + + def _kind_of(entity: Any) -> EntityKind: if isinstance(entity, Env): return EntityKind.ENV diff --git a/tst/unit/bundle/importer_test.py b/tst/unit/bundle/importer_test.py index b592024da..7de256df6 100644 --- a/tst/unit/bundle/importer_test.py +++ b/tst/unit/bundle/importer_test.py @@ -18,7 +18,9 @@ from agent_env.bundle.importer import ImportedEval, import_eval, import_task from agent_env.bundle.installed import InstalledBundle from agent_env.bundle.materialize import materialize +from agent_env.bundle import register as register_module from agent_env.bundle.plan import plan_bundle +from agent_env.bundle.register import register_bundle from agent_env.bundle.requires import Provider from agent_env.bundle.resolve import resolve_bundle from agent_env.cli import cli @@ -33,7 +35,7 @@ from agent_env.store.routing import namespace_routing from agent_env.task import Task from agent_env.task_step.task_step import TaskStep -from tst.unit.bundle._support import context_image, fake_plugins +from tst.unit.bundle._support import context_image, fake_plugins, layout STEPS = [ {"id": "env", "type": "deploy_env", "env_id": "crm-env"}, @@ -745,3 +747,43 @@ def test_an_installed_bundles_entity_floats_unpinned_so_the_import_runs_it_from_ assert ("dropped" in imported.floating[0].why) == (pin is not None) and imported.pinned == () assert _steps(imported.root, "t")[0]["a2a_agent_version"] is None + + +AGENT_NAMED_BY_ALIAS = [{"id": "agent", "type": "deploy_agent", "env_ids": [], "a2a_agent_id": "claude-code"}] + + +@pytest.fixture +def registry(local_stores, tmp_path, monkeypatch, agents_published): + """A registry of bare ids, with ``register`` registering a bundle into it, outside git.""" + monkeypatch.setenv("HOME", str(tmp_path)) + monkeypatch.setattr(register_module, "_git", lambda root, *args: None) + return lambda name, steps: register_bundle(layout(tmp_path / name, {"tasks/t.json": json.dumps(steps)})) + + +def test_an_agent_registered_from_an_installed_bundle_under_its_alias_floats_by_the_alias(registry, tmp_path): + registry("triage", AGENT_NAMED_BY_ALIAS) + + imported = import_task("triage-t", tmp_path / "imported", include_scopes=[FieldScope.USER]) + + assert [(ref.where, ref.id) for ref in imported.floating] == [ + ("tasks/triage-t.json: step 'agent': a2a_agent_id", "claude-code")] + assert "registered from the installed bundle agentenv-framework" in imported.floating[0].why + assert "the stored pin to v1 is dropped" in imported.floating[0].why + assert imported.written == () and not (imported.root / "agents").exists() + step = _steps(imported.root, "triage-t")[0] + assert (step["a2a_agent_id"], step["a2a_agent_version"]) == ("claude-code", None) + + +@pytest.mark.parametrize("registered_first", [False, True]) +def test_an_agent_stored_under_an_installed_alias_by_anything_else_is_written_into_the_folder(registry, tmp_path, + registered_first): + if registered_first: + registry("triage", AGENT_NAMED_BY_ALIAS) + A2AAgent.put(id="claude-code", docker_image_artifact=context_image(tmp_path, "own-image")) + _task("own", AGENT_NAMED_BY_ALIAS) + + imported = import_task("own", tmp_path / "imported", include_scopes=[FieldScope.USER]) + + assert "claude-code" not in [ref.id for ref in imported.floating] + assert [(entity.folder, entity.id, entity.version) for entity in imported.written] == [ + ("agents/claude-code", "claude-code", 2 if registered_first else 1)] From 398a60b713fb92a3be0098050a81b9412534e1da Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Wed, 18 Nov 2026 15:14:20 -0800 Subject: [PATCH 2/3] fix(bundle): no folder takes an alias a step may float An export that floats an installed alias (claude-code) and writes a different version of that id into the folder named the folder after the alias, which a run reads before the alias, so the floating step took the folder's entity. A folder now never takes an alias the store holds a registered version of, whatever order the export runs in; other ids keep their names. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/bundle/importer.py | 44 ++++++++++++++++++++++++-------- tst/unit/bundle/importer_test.py | 19 +++++++++++++- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/agent_env/bundle/importer.py b/src/agent_env/bundle/importer.py index a97f437f2..d4379e0a5 100644 --- a/src/agent_env/bundle/importer.py +++ b/src/agent_env/bundle/importer.py @@ -63,7 +63,8 @@ from agent_env.env.registry import get_env_registry from agent_env.eval import Eval from agent_env.plugins import ARTIFACTS, ENVS, TASK_STEPS -from agent_env.plugins._bundles import AGENT_ALIASES, ARTIFACT_ALIASES, ENV_ALIASES, InstalledAliases, installed_aliases +from agent_env.plugins._bundles import (AGENT_ALIASES, ARTIFACT_ALIASES, ENV_ALIASES, BundleAlias, InstalledAliases, + installed_aliases) from agent_env.store import Filter from agent_env.store.base import NotFoundError from agent_env.store.ids import LOCAL_PREFIX, is_local_id @@ -75,6 +76,9 @@ from agent_env.utils.paths import os_reason _ALIAS_TABLES = {EntityKind.AGENT: AGENT_ALIASES, EntityKind.ENV: ENV_ALIASES, EntityKind.ARTIFACT: ARTIFACT_ALIASES} +# The kind of entity whose aliases a kind folder's names would shadow in a run. +_FOLDER_KINDS = {BundleKind.AGENT.value: EntityKind.AGENT, BundleKind.ENV.value: EntityKind.ENV, + BundleKind.ARTIFACT.value: EntityKind.ARTIFACT} # How long a name taken from an id may be, in bytes; ids are capped far above it, and a longer name helps nobody. _MAX_NAME_BYTES = 200 _DOWNLOADS = 8 # objects downloaded at once @@ -216,6 +220,7 @@ def __init__(self, dest: Path | None, include_scopes: Collection[FieldScope] = ( self.providers = Providers() self.installed: tuple[InstalledBundle, ...] | None = None self.aliases: dict[str, InstalledAliases] = {} # the installed bundles' aliases, by aliases.toml table + self.floatable: dict[EntityKind, set[str]] = {} # each kind's aliases a step may float (_floatable) if self.dest is not None: _check_destination(self.dest) @@ -552,18 +557,34 @@ def _registered_from(self, kind: EntityKind, entity: Any) -> InstalledBundle | N version is the one ``bundle register`` wrote from the bundle, as its ledger in the store records: a run writes it from the bundle too. An entity stored under the alias by anything else is the store's own.""" table = _ALIAS_TABLES.get(kind) - if table is None: + if table is None or (claim := self._aliases(table).target(entity.id)) is None: return None + return claim.bundle if self._registered(kind, claim, entity.version) else None + + def _registered(self, kind: EntityKind, claim: BundleAlias, version: int | None = None) -> bool: + """Whether the store's registration ledger has ``bundle register`` writing ``claim``'s alias, at ``version`` or + any, from the installed bundle that gives it.""" + fields = {"store": kind.value, "id": claim.alias, "status": "done", + "bundle": f"installed:{claim.bundle.id_root.removeprefix(LOCAL_PREFIX)}"} + if version is not None: + fields["version"] = version + return configured_store(get_config().get_document_store()).find_one(REGISTRATIONS, Filter.of(**fields)) is not None + + def _floatable(self, kind: EntityKind) -> set[str]: + """The aliases of ``kind``, folded, that a step may name floating: those the store holds a version of that + ``bundle register`` wrote from the installed bundle. No folder takes one, whatever order the export runs in.""" + if kind not in self.floatable: + aliases = self._aliases(_ALIAS_TABLES[kind]).aliases + self.floatable[kind] = {fold(alias) for alias, claim in aliases.items() if self._registered(kind, claim)} + return self.floatable[kind] + + def _aliases(self, table: str) -> InstalledAliases: + """The aliases the installed bundles give in ``table``.""" if self.installed is None: self.installed = installed_bundles() if table not in self.aliases: self.aliases[table] = installed_aliases(self.installed, table) - if (claim := self.aliases[table].target(entity.id)) is None: - return None - registered = configured_store(get_config().get_document_store()).find_one( - REGISTRATIONS, Filter.of(store=kind.value, id=entity.id, version=entity.version, status="done", - bundle=f"installed:{claim.bundle.id_root.removeprefix(LOCAL_PREFIX)}")) - return claim.bundle if registered is not None else None + return self.aliases[table] def _from_installed(self, site: RefSite, where: str, bundle: InstalledBundle, why: str | None = None) -> None: """An installed bundle's entity has no fixed version, so it isn't pinned, and a pin the store held is dropped.""" @@ -596,11 +617,14 @@ def _default_agents(self, step: dict, refs: tuple[EntityRef, ...], where: str) - "default")) def _name(self, kind: str, entity_id: str) -> str: - """A name in the ``kind`` folder: the id's last segment made valid, numbered when taken, caselessly.""" + """A name in the ``kind`` folder: the id's last segment made valid, numbered when taken, caselessly, or when a + step may name it as an installed alias, floating (``_floatable``), which a folder of that name would capture in + a run.""" names = _names_of(BundleKind(kind)) + aliases = self._floatable(_FOLDER_KINDS[kind]) if kind in _FOLDER_KINDS else set() base = _valid_name(entity_id.rsplit("/", 1)[-1]) or kind.removesuffix("s") name, n = base, 1 - while fold(name) in self.taken[names]: + while fold(name) in self.taken[names] or fold(name) in aliases: n += 1 name = f"{base}-{n}" self.taken[names].add(fold(name)) diff --git a/tst/unit/bundle/importer_test.py b/tst/unit/bundle/importer_test.py index 7de256df6..ed1930097 100644 --- a/tst/unit/bundle/importer_test.py +++ b/tst/unit/bundle/importer_test.py @@ -785,5 +785,22 @@ def test_an_agent_stored_under_an_installed_alias_by_anything_else_is_written_in imported = import_task("own", tmp_path / "imported", include_scopes=[FieldScope.USER]) assert "claude-code" not in [ref.id for ref in imported.floating] + name = "claude-code-2" if registered_first else "claude-code" assert [(entity.folder, entity.id, entity.version) for entity in imported.written] == [ - ("agents/claude-code", "claude-code", 2 if registered_first else 1)] + (f"agents/{name}", "claude-code", 2 if registered_first else 1)] + assert _steps(imported.root, "own")[0]["a2a_agent_id"] == name + + +def test_a_folder_never_takes_an_alias_a_step_floats_so_each_version_keeps_its_own(registry, tmp_path): + registry("triage", AGENT_NAMED_BY_ALIAS) + A2AAgent.put(id="claude-code", docker_image_artifact=context_image(tmp_path, "own-image")) + _task("both", [{**AGENT_NAMED_BY_ALIAS[0], "id": "own", "a2a_agent_version": 2}, + {**AGENT_NAMED_BY_ALIAS[0], "id": "registered", "a2a_agent_version": 1}]) + + imported = import_task("both", tmp_path / "imported", include_scopes=[FieldScope.USER]) + + steps = _steps(imported.root, "both") + assert [step["a2a_agent_id"] for step in steps] == ["claude-code-2", "claude-code"] + assert [(entity.folder, entity.version) for entity in imported.written] == [("agents/claude-code-2", 2)] + assert [(ref.where, ref.id) for ref in imported.floating if ref.id == "claude-code"] == [ + ("tasks/both.json: step 'registered': a2a_agent_id", "claude-code")] From ddfe91c0efd3426557456b564a048a00bb15e88b Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Wed, 18 Nov 2026 15:20:31 -0800 Subject: [PATCH 3/3] fix(bundle): reserve the aliases an export's steps name without reading a store The folder names an export keeps off installed aliases are now those its steps name, collected from the tasks before any folder is named, so an export that names none never reads the configured store's registration ledger: a local-only export no longer depends on a remote store being reachable. The ledger is read only for a step that names an alias, whose entity the export reads from that store anyway. An entity another entity names is written into the folder as before; only a step's reference floats. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/bundle/importer.py | 57 +++++++++++++++----------------- tst/unit/bundle/importer_test.py | 16 +++++++-- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/agent_env/bundle/importer.py b/src/agent_env/bundle/importer.py index d4379e0a5..602e03060 100644 --- a/src/agent_env/bundle/importer.py +++ b/src/agent_env/bundle/importer.py @@ -63,8 +63,7 @@ from agent_env.env.registry import get_env_registry from agent_env.eval import Eval from agent_env.plugins import ARTIFACTS, ENVS, TASK_STEPS -from agent_env.plugins._bundles import (AGENT_ALIASES, ARTIFACT_ALIASES, ENV_ALIASES, BundleAlias, InstalledAliases, - installed_aliases) +from agent_env.plugins._bundles import AGENT_ALIASES, ARTIFACT_ALIASES, ENV_ALIASES, InstalledAliases, installed_aliases from agent_env.store import Filter from agent_env.store.base import NotFoundError from agent_env.store.ids import LOCAL_PREFIX, is_local_id @@ -94,6 +93,7 @@ def import_task(task_id: str, dest: Path | str, *, version: int | None = None, digest its registry serves now when it gives none, with its build context beside it.""" importer = _Importer(Path(dest), include_scopes, progress, image_refs) task = Task.get(task_id, version) + importer.reserve_aliases([task]) importer.add_task(task) return importer.write(f"Imported from the store's task {task.id} v{task.version}.", {"task": task.id, "version": task.version}) @@ -106,7 +106,9 @@ def task_images(task_id: str, *, version: int | None = None, task with ``image_refs`` naming them there. Every image is listed, however it's stored, since each is then given a reference; raises BundleError when the import would fail on anything else it reads.""" importer = _Importer(None, include_scopes) - importer.add_task(Task.get(task_id, version)) + task = Task.get(task_id, version) + importer.reserve_aliases([task]) + importer.add_task(task) if importer.problems: raise BundleError(importer.problems) return tuple(importer.images_named.values()) @@ -119,7 +121,7 @@ def import_eval(eval_id: str, dest: Path | str, *, version: int | None = None, a bundle, leaving out their steps' scoped fields and writing ``image_refs`` as ``import_task`` does.""" importer = _Importer(Path(dest), include_scopes, progress, image_refs) stored = Eval.get(eval_id, version) - names, seen = [], set() + tasks, seen = [], set() for entry in stored.tasks: try: task = Task.get(entry.task_id, entry.task_version) @@ -132,7 +134,9 @@ def import_eval(eval_id: str, dest: Path | str, *, version: int | None = None, importer.duplicates.append(f"task {task.id} v{task.version}") continue seen.add((task.id, task.version)) - names.append(importer.add_task(task)) + tasks.append(task) + importer.reserve_aliases(tasks) + names = [importer.add_task(task) for task in tasks] if names: importer.add_eval(stored, names) return importer.write(f"Imported from the store's eval {stored.id} v{stored.version} and the tasks it names.", @@ -161,9 +165,6 @@ def ref(self, entity: Any) -> str | dict: if (bundle := self.importer._installed_for(kind, entity.id)) is not None: self.importer.floating.append(Floating(self.folder, kind, entity.id, _from_bundle(bundle))) return entity.id - if (bundle := self.importer._registered_from(kind, entity)) is not None: - self.importer.floating.append(Floating(self.folder, kind, entity.id, _registered_from_bundle(bundle))) - return entity.id local = self.importer.local(kind, entity, self.folder) return local if local is not None else {kind.value: entity.id, "version": entity.version} @@ -220,7 +221,7 @@ def __init__(self, dest: Path | None, include_scopes: Collection[FieldScope] = ( self.providers = Providers() self.installed: tuple[InstalledBundle, ...] | None = None self.aliases: dict[str, InstalledAliases] = {} # the installed bundles' aliases, by aliases.toml table - self.floatable: dict[EntityKind, set[str]] = {} # each kind's aliases a step may float (_floatable) + self.reserved: dict[EntityKind, set[str]] = {} # each kind's installed aliases a step names, folded if self.dest is not None: _check_destination(self.dest) @@ -559,24 +560,21 @@ def _registered_from(self, kind: EntityKind, entity: Any) -> InstalledBundle | N table = _ALIAS_TABLES.get(kind) if table is None or (claim := self._aliases(table).target(entity.id)) is None: return None - return claim.bundle if self._registered(kind, claim, entity.version) else None - - def _registered(self, kind: EntityKind, claim: BundleAlias, version: int | None = None) -> bool: - """Whether the store's registration ledger has ``bundle register`` writing ``claim``'s alias, at ``version`` or - any, from the installed bundle that gives it.""" - fields = {"store": kind.value, "id": claim.alias, "status": "done", - "bundle": f"installed:{claim.bundle.id_root.removeprefix(LOCAL_PREFIX)}"} - if version is not None: - fields["version"] = version - return configured_store(get_config().get_document_store()).find_one(REGISTRATIONS, Filter.of(**fields)) is not None - - def _floatable(self, kind: EntityKind) -> set[str]: - """The aliases of ``kind``, folded, that a step may name floating: those the store holds a version of that - ``bundle register`` wrote from the installed bundle. No folder takes one, whatever order the export runs in.""" - if kind not in self.floatable: - aliases = self._aliases(_ALIAS_TABLES[kind]).aliases - self.floatable[kind] = {fold(alias) for alias, claim in aliases.items() if self._registered(kind, claim)} - return self.floatable[kind] + registered = configured_store(get_config().get_document_store()).find_one(REGISTRATIONS, Filter.of( + store=kind.value, id=claim.alias, version=entity.version, status="done", + bundle=f"installed:{claim.bundle.id_root.removeprefix(LOCAL_PREFIX)}")) + return claim.bundle if registered is not None else None + + def reserve_aliases(self, tasks: Collection[Task]) -> None: + """Keep each installed alias a step of ``tasks`` names out of the folders' names, before any is given: such a + step may name it floating, and a folder of that name would capture it in a run. Reads no store.""" + registry = get_task_step_registry() + for task in tasks: + for step in task.to_dict()["steps"]: + for site in ref_sites(registry[step["type"]].entity_refs or (), step): + table = _ALIAS_TABLES.get(site.ref.kind) + if isinstance(site.value, str) and table is not None and self._aliases(table).target(site.value): + self.reserved.setdefault(site.ref.kind, set()).add(fold(site.value)) def _aliases(self, table: str) -> InstalledAliases: """The aliases the installed bundles give in ``table``.""" @@ -618,10 +616,9 @@ def _default_agents(self, step: dict, refs: tuple[EntityRef, ...], where: str) - def _name(self, kind: str, entity_id: str) -> str: """A name in the ``kind`` folder: the id's last segment made valid, numbered when taken, caselessly, or when a - step may name it as an installed alias, floating (``_floatable``), which a folder of that name would capture in - a run.""" + step of the export names it as an installed alias (``reserve_aliases``).""" names = _names_of(BundleKind(kind)) - aliases = self._floatable(_FOLDER_KINDS[kind]) if kind in _FOLDER_KINDS else set() + aliases = self.reserved.get(_FOLDER_KINDS[kind], set()) if kind in _FOLDER_KINDS else set() base = _valid_name(entity_id.rsplit("/", 1)[-1]) or kind.removesuffix("s") name, n = base, 1 while fold(name) in self.taken[names] or fold(name) in aliases: diff --git a/tst/unit/bundle/importer_test.py b/tst/unit/bundle/importer_test.py index ed1930097..3cdb043df 100644 --- a/tst/unit/bundle/importer_test.py +++ b/tst/unit/bundle/importer_test.py @@ -785,10 +785,9 @@ def test_an_agent_stored_under_an_installed_alias_by_anything_else_is_written_in imported = import_task("own", tmp_path / "imported", include_scopes=[FieldScope.USER]) assert "claude-code" not in [ref.id for ref in imported.floating] - name = "claude-code-2" if registered_first else "claude-code" assert [(entity.folder, entity.id, entity.version) for entity in imported.written] == [ - (f"agents/{name}", "claude-code", 2 if registered_first else 1)] - assert _steps(imported.root, "own")[0]["a2a_agent_id"] == name + ("agents/claude-code-2", "claude-code", 2 if registered_first else 1)] + assert _steps(imported.root, "own")[0]["a2a_agent_id"] == "claude-code-2" def test_a_folder_never_takes_an_alias_a_step_floats_so_each_version_keeps_its_own(registry, tmp_path): @@ -804,3 +803,14 @@ def test_a_folder_never_takes_an_alias_a_step_floats_so_each_version_keeps_its_o assert [(entity.folder, entity.version) for entity in imported.written] == [("agents/claude-code-2", 2)] assert [(ref.where, ref.id) for ref in imported.floating if ref.id == "claude-code"] == [ ("tasks/both.json: step 'registered': a2a_agent_id", "claude-code")] + + +def test_an_export_whose_steps_name_no_installed_alias_never_reads_the_registration_ledger(store, monkeypatch): + def unreachable(*args, **kwargs): + raise AssertionError("the registration ledger was read") + + monkeypatch.setattr(importer_module, "configured_store", unreachable) + + imported = import_task("triage", store / "triage", include_scopes=[FieldScope.USER]) + + assert [entity.folder for entity in imported.written] == ["envs/crm-env", "artifacts/crm-data", "agents/solver"]