Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

Environments: a one-file ZIP or TAR imports its file (#435)

Jasper9e96b7a99dee
diff --git a/runner/environments.py b/runner/environments.py
index 7766cc51..72ce63ad 100644
--- a/runner/environments.py
+++ b/runner/environments.py
@@ -351,6 +351,8 @@ def _strip_common_root(names: list[str]) -> str:
firsts = {n.split("/", 1)[0] for n in names if n.strip("/")}
if len(firsts) == 1:
root = next(iter(firsts))
+ if not any(n.startswith(root + "/") and n[len(root) + 1:].strip("/") for n in names):
+ return ""
if all(n == root or n == root + "/" or n.startswith(root + "/") for n in names if n.strip("/")):
return root + "/"
return ""
diff --git a/runner/tests/test_environments.py b/runner/tests/test_environments.py
index 39afce6f..3316b0a3 100644
--- a/runner/tests/test_environments.py
+++ b/runner/tests/test_environments.py
@@ -80,6 +80,35 @@ def test_import_strips_one_wrapping_directory_and_drops_escapes_and_links(store,
assert {e["path"] for e in E.tree("henv_z") if not e["dir"]} == {"a.txt", "d/b.txt"}
[email protected]("archive_format", ["zip", "tar"])
[email protected]("wrapper, directory_entry", [("", False), ("project/", False), ("project/", True)])
+def test_import_keeps_a_single_file_with_or_without_a_wrapping_directory(
+ store, tmp_path, archive_format, wrapper, directory_entry,
+):
+ data = b"a single file\n"
+ p = tmp_path / ("single." + archive_format)
+ if archive_format == "zip":
+ with zipfile.ZipFile(p, "w") as zf:
+ if directory_entry:
+ zf.writestr(wrapper, b"")
+ zf.writestr(wrapper + "new.txt", data)
+ else:
+ with tarfile.open(p, "w") as tf:
+ if directory_entry:
+ directory = tarfile.TarInfo(wrapper)
+ directory.type = tarfile.DIRTYPE
+ tf.addfile(directory)
+ member = tarfile.TarInfo(wrapper + "new.txt")
+ member.size = len(data)
+ tf.addfile(member, io.BytesIO(data))
+
+ out = E.import_archive("henv_single", str(p))
+ assert out["written"] == 1 and out["skipped"] == 0
+ assert E.source_stat("henv_single") == {"count": 1, "bytes": len(data)}
+ assert E.read_file("henv_single", "new.txt")[0] == data
+ assert {e["path"] for e in E.tree("henv_single")} == {"new.txt"}
+
+
def _wait(env_id, n, timeout=240):
for _ in range(timeout * 4):
rec = E.build_record(env_id, n)