Exclude cache artifacts from builder source packages
Some checks failed
build / build (push) Failing after 2s

This commit is contained in:
robert
2026-06-07 19:54:03 -03:00
parent d7cb4b3f8f
commit aba68aaf2e
5 changed files with 158 additions and 26 deletions

View File

@@ -8,6 +8,7 @@ import unittest
from unittest.mock import patch
from agent_builder.config import Settings
from agent_builder.builder import _workspace_backend_with_grep_compat
from agent_builder.tools import (
_BUILDER_STATE_FILE,
_BUILDER_INTERNAL_PREFIX,
@@ -160,6 +161,44 @@ class TemplateInitTests(unittest.TestCase):
with tarfile.open(fileobj=io.BytesIO(bundle), mode="r:gz") as tf:
self.assertEqual(tf.getnames(), ["agent.py"])
def test_tarball_workspace_excludes_python_cache_artifacts(self) -> None:
prefix = "agents/demo-agent/"
s3 = _FakeS3({
prefix + "agent.py": b"print('ok')\n",
prefix + "__pycache__/agent.cpython-311.pyc": b"bytecode",
prefix + "helper.pyc": b"bytecode",
prefix + ".pytest_cache/v/cache/nodeids": b"[]",
prefix + "demo_agent.egg-info/PKG-INFO": b"metadata",
})
bundle = _tarball_workspace_dir(s3, "bucket", prefix)
with tarfile.open(fileobj=io.BytesIO(bundle), mode="r:gz") as tf:
self.assertEqual(tf.getnames(), ["agent.py"])
def test_tarball_workspace_skips_disappeared_files(self) -> None:
prefix = "agents/demo-agent/"
store = _FakeStaleStore(
objects={prefix + "agent.py": b"print('ok')\n"},
stale_keys={prefix + "generated.txt"},
)
bundle = _tarball_workspace_dir(store, prefix)
with tarfile.open(fileobj=io.BytesIO(bundle), mode="r:gz") as tf:
self.assertEqual(tf.getnames(), ["agent.py"])
def test_builder_workspace_backend_filters_cache_artifacts(self) -> None:
backend_cls = _workspace_backend_with_grep_compat(
_FakeDeepAgentsBackend,
object(),
)
self.assertEqual(
backend_cls._all_paths(),
["agents/demo-agent/agent.py"],
)
def test_render_skill_md_creates_valid_frontmatter(self) -> None:
text = _render_skill_md(
"market-research",
@@ -299,6 +338,10 @@ class TemplateInitTests(unittest.TestCase):
self.assertEqual(result["exit_code"], 0)
self.assertEqual(len(sandbox.calls), 1)
self.assertEqual(sandbox.calls[0]["workspace"], "bucket")
self.assertIn(
"export PYTHONDONTWRITEBYTECODE=1",
str(sandbox.calls[0]["script"]),
)
self.assertEqual(_FakeAsyncClient.posts, [])
def test_cp_deploy_tarball_posts_agent_dsl(self) -> None:
@@ -525,6 +568,36 @@ class _FakeS3:
raise AssertionError("batch DeleteObjects should not be used")
class _FakeStaleStore:
def __init__(self, objects: dict[str, bytes], stale_keys: set[str]) -> None:
self.objects = objects
self.stale_keys = stale_keys
def iter_keys(self, prefix: str) -> list[str]:
return sorted(
key
for key in [*self.objects, *self.stale_keys]
if key.startswith(prefix)
)
def get(self, key: str) -> bytes:
if key in self.stale_keys:
raise FileNotFoundError(key)
return self.objects[key]
class _FakeDeepAgentsBackend:
def __init__(self, workspace: object, **kwargs: object) -> None:
pass
def _all_paths(self) -> list[str]:
return [
"agents/demo-agent/agent.py",
"agents/demo-agent/__pycache__/agent.cpython-311.pyc",
"agents/demo-agent/.pytest_cache/v/cache/nodeids",
]
class _FakePaginator:
def __init__(self, objects: dict[str, bytes]) -> None:
self.objects = objects