From 782b30a86f3140622792a406f2f07cf7a822b15f Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Tue, 17 Nov 2026 20:24:21 -0800 Subject: [PATCH] fix(bundle): register writes a universe folder under its registry id bundle register refused any bundle holding an environment universe folder: the folder's environments and their files are named from the universe's id, and every one was checked as a local id, which a registry id never is, so each name was first hashed and then refused as "must start with '@local/'", with advice to shorten the name that couldn't help. A local id is still checked as one; a registry id takes the folder's names as they are. Co-Authored-By: Claude Opus 5.5 --- .../artifacts/environment_universe_folder.py | 13 ++++++++++--- .../artifact/environment_universe_folder_test.py | 12 ++++++++++++ tst/unit/bundle/register_test.py | 12 ++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/agent_env/artifact/artifacts/environment_universe_folder.py b/src/agent_env/artifact/artifacts/environment_universe_folder.py index 5a020819c..bc8a58dfc 100644 --- a/src/agent_env/artifact/artifacts/environment_universe_folder.py +++ b/src/agent_env/artifact/artifacts/environment_universe_folder.py @@ -18,7 +18,7 @@ from pathlib import Path from agent_env.artifact.artifacts.environment import EnvironmentArtifact -from agent_env.store.ids import derive_id, validate_local_id +from agent_env.store.ids import derive_id, is_local_id, validate_local_id # What a universe's metadata is called: the folder its files go in, and the segment of the ids they're written under. METADATA = "metadata" @@ -123,7 +123,7 @@ def read_folder(universe_id: str, files: Mapping[str, Path], try: for id in (env_id, file_id): if id is not None: - validate_local_id(id) + _check(id) except ValueError as e: problems.append(f"{folder}: can't name the artifacts written from it ({e}); give the universe a shorter " "name") @@ -144,13 +144,20 @@ def _child_id(derive: Callable[[str], str], name: str, *, environment: bool) -> id = derive(name) try: for derived in (id, EnvironmentArtifact.derived_file_id(id)) if environment else (id,): - validate_local_id(derived) + _check(derived) return id except ValueError: pass return derive(f"sha256__{hashlib.sha256(name.encode('utf-8')).hexdigest()[:16]}") +def _check(id: str) -> None: + """Raise ValueError when ``id`` is a local id an id can't be; a registry id, as ``bundle register`` writes a universe + under, takes the folder's names as they are.""" + if is_local_id(id): + validate_local_id(id) + + def _fold(name: str) -> str: """The caseless form names are compared in: casefold output isn't always NFC, so normalize both sides.""" return unicodedata.normalize("NFC", unicodedata.normalize("NFC", name).casefold()) diff --git a/tst/unit/artifact/environment_universe_folder_test.py b/tst/unit/artifact/environment_universe_folder_test.py index d74f3e4f0..df40e2085 100644 --- a/tst/unit/artifact/environment_universe_folder_test.py +++ b/tst/unit/artifact/environment_universe_folder_test.py @@ -53,3 +53,15 @@ def test_its_problems_name_paths_in_the_folder(): "gmail: holds one file, and has 2 ('a.json', 'b.json')", "slack: holds one file, and has 0", ] + + +def test_a_universe_registered_under_a_registry_id_names_its_environments_as_a_local_one_does(): + files, folders = _listing([environment_path(PurePosixPath(), name, "x.json") for name in ("gmail", "g__mail")]) + + read = read_folder("psi-ts-shelfway-laptop-elicitation-computer-u", files, folders) + + ids = {entry.name: (entry.environment_id, entry.file_id) for entry in read.environments} + assert ids["gmail"] == ("psi-ts-shelfway-laptop-elicitation-computer-u__gmail", + "psi-ts-shelfway-laptop-elicitation-computer-u__gmail__file") + digest = hashlib.sha256(b"g__mail").hexdigest()[:16] + assert ids["g__mail"][0] == f"psi-ts-shelfway-laptop-elicitation-computer-u__sha256__{digest}" diff --git a/tst/unit/bundle/register_test.py b/tst/unit/bundle/register_test.py index ab1c81fb1..5c5e8612a 100644 --- a/tst/unit/bundle/register_test.py +++ b/tst/unit/bundle/register_test.py @@ -116,6 +116,18 @@ def test_each_entry_takes_its_prefix_and_name_and_each_task_names_the_versions_i assert Artifact.get("triage-docs").version == 1 +def test_a_universe_folder_registers_its_environments_under_the_universe_s_registry_id(home): + universe = {"artifacts/world-u/artifact.toml": 'type = "environment_universe"\n', + "artifacts/world-u/gmail/gmail.zip": "mail\n", "artifacts/world-u/shelfway/shelfway.json": "{}\n", + "tasks/t.json": json.dumps([BOX, _load("world", "world-u")])} + + registered = register_bundle(layout(home / "triage", universe)) + + assert {done.write.id for done in registered.materialization.writes} == {"triage-world-u", "triage-t"} + environments = Artifact.get("triage-world-u").get_environment_artifacts() + assert sorted(env.id for env in environments) == ["triage-world-u__gmail", "triage-world-u__shelfway"] + + def test_registering_again_writes_nothing_and_an_edit_rewrites_only_what_it_reaches(home): root = layout(home / "triage", TRIAGE) register_bundle(root)