Skip to content
4 changes: 2 additions & 2 deletions .github/scripts/slow_test_durations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

Use a green ``main`` run: it has a ``junit-*`` artifact for every shard of the slow tier, the gateway tests, the unit
tier and the installer tier, which ``gh run download`` puts in a folder each. Each test's time counts toward its file,
or toward the test itself for a file the table names in ``split_by_test``; that list is kept as it is. A file the
or toward the test itself for a file the table names in ``split_by_test`` or ``split_in``, which are kept as they are. A file the
reports have no test of, such as one of a tier the run skipped, keeps the times the table had for it while it exists.
"""

Expand All @@ -30,7 +30,7 @@ def main() -> int:
args = parser.parse_args()

table = json.loads(args.table.read_text())
split = set(table.get("split_by_test", []))
split = set(table.get("split_by_test", [])) | set(table.get("split_in", {}))
seconds: dict[str, float] = defaultdict(float)
for report in args.reports:
for case in ET.parse(report).getroot().iter("testcase"):
Expand Down
30 changes: 8 additions & 22 deletions src/agent_env/env/envs/computer/utils/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,11 @@ def _built_disk(env: ComputerEnv, base: ComputerArtifact, arch: str, container:
progress: _Progress) -> dict:
"""The status of the disk form of ``arch`` once built from ``container``, its container's result, and pushed, or
reused, or the stage that failed and why. Its key is of the container's key, the base disk and the disk recipe;
the base disk is the base's own, the one published for it, or else one made on the builder from the base's
container and the boot recipe. Its build runs no program of ``arch``'s but that recipe's. Two composes of one disk
on this machine take turns, so the second reuses the first's: built again, its tag would move off the image the
first pinned, which a boot mounts by that name and Docker doesn't pull for a mount."""
the base disk is the base's own or the one published for it, whose EFI system partition and size the disk keeps,
or else the base's container and size, the disk then taking the recipe's own partition at that size, all a base
disk made from them would give it. Its build runs no program of ``arch``'s but that recipe's. Two composes of one
disk on this machine take turns, so the second reuses the first's: built again, its tag would move off the image
the first pinned, which a boot mounts by that name and Docker doesn't pull for a mount."""
pair, platform = f"disk/{arch}", f"linux/{arch}"
with (_attempting(env, "disk", arch) as attempt,
tempfile.TemporaryDirectory(prefix="agentenv-compose-") as work, contextlib.ExitStack() as opened):
Expand All @@ -718,15 +719,12 @@ def _built_disk(env: ComputerEnv, base: ComputerArtifact, arch: str, container:
tools = f"agentenv-disk-tools:{DISK_TOOLS_IMAGE.tag()}"
on.build((context / "tools" / "Dockerfile").read_text(), tools, on.platform, {},
context=f"{builder.CONTEXT}/tools")
dockerfile = (context / "Dockerfile").read_text()
if base_disk is None:
progress.at(pair, "making the base's disk")
base_disk = _made_base_disk(on, base, arch, f"{base_identity} {recipe}", tools, dockerfile)
progress.at(pair, "making the disk")
local = f"agentenv-computer:{key[7:23]}-disk-{arch}"
on.build(dockerfile, local, platform, {KEY_LABEL: key}, build_args={
on.build((context / "Dockerfile").read_text(), local, platform, {KEY_LABEL: key}, build_args={
"ROOTFS": container["image"], "ROOTFS_CONFIG": _encoded(_config(on, container["image"], arch)),
"ESP": base_disk, "TOOLS": tools})
"TOOLS": tools, **({"ESP": base_disk} if base_disk is not None
else {"SIZE_GB": str(base.forms.disk.min_disk_gb)})})
attempt.stage = "push"
progress.at(pair, "pushing the disk")
on.push(local, ref, store)
Expand All @@ -735,18 +733,6 @@ def _built_disk(env: ComputerEnv, base: ComputerArtifact, arch: str, container:
return attempt.result


def _made_base_disk(on: builder.Builder, base: ComputerArtifact, arch: str, made_from: str, tools: str,
dockerfile: str) -> str:
"""The base's disk for ``arch``, made on ``on`` from the base's container with the boot recipe's ``dockerfile`` at
the base's size, under a tag of ``made_from``, what it's made from."""
source, _ = _base(base, arch)
tag = f"agentenv-computer:{hashlib.sha256(made_from.encode()).hexdigest()[:16]}-base-disk-{arch}"
on.build(dockerfile, tag, f"linux/{arch}", {}, build_args={
"ROOTFS": source, "ROOTFS_CONFIG": _encoded(_config(on, source, arch)), "TOOLS": tools,
"SIZE_GB": str(base.forms.disk.min_disk_gb)})
return tag


@dataclass
class _Attempt:
"""How far a pair's build got, its stage and key, and, when it failed, its result (``_attempting``)."""
Expand Down
6 changes: 4 additions & 2 deletions tst/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def pytest_unconfigure(config):

@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(config, items):
"""With ``AGENTENV_TEST_SHARD=i/N``, run only the i-th of N groups of the selected tests (``tst/util/shards.py``).
Last, so it splits what ``-m`` and the other filters left."""
"""With ``AGENTENV_TEST_SHARD=i/N``, run only the i-th of N groups of the selected tests (``tst/util/shards.py``),
their files heaviest first. Last, so it splits what ``-m`` and the other filters left."""
value = os.environ.get(shards.ENV_VAR)
if not value:
return
Expand All @@ -71,6 +71,8 @@ def pytest_collection_modifyitems(config, items):
if deselected:
config.hook.pytest_deselected(items=deselected)
items[:] = [item for item in items if item.nodeid in keep]
position = {nodeid: n for n, nodeid in enumerate(shards.heaviest_first([item.nodeid for item in items], table))}
items.sort(key=lambda item: position[item.nodeid])


@pytest.fixture
Expand Down
39 changes: 34 additions & 5 deletions tst/integration/computer/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
from agent_env.env import Env
from agent_env.env.envs.mcp_server import MCPServerEnv
from agent_env.env.envs.multi_env import MultiEnv
from agent_env.env.envs.computer.utils import builder, inside
from agent_env.env.envs.computer.utils import builder, composer, inside
from agent_env.env.envs.computer.utils.composer import Composing
from agent_env.providers.sandbox_providers.host_images import host_platform
from agent_env.store.object_store.local.grant_server import grant_server
from agent_env.store.routing import namespace_routing
Expand Down Expand Up @@ -86,12 +87,21 @@ def base():

@pytest.fixture(scope="module")
def desktop(tmp_path_factory):
"""The shipped desktop example's computer env, composed for the module in stores of the module's own: an image for
each arch this machine's Docker builds, the native one probed by gate 3."""
"""The shipped desktop example's computer env, composed for the module in stores of the module's own as a run on
this machine composes it: the container of each arch this machine's Docker builds, the native one probed by gate 3.
A deploy of its disk form composes that first."""
bundle = find_bundle("desktop")
yield from _composed(tmp_path_factory.mktemp("desktop"), parse_bundle(bundle.root, id_root=bundle.id_root))


@pytest.fixture(scope="module")
def desktop_with_disk(tmp_path_factory):
"""``desktop`` with its disk forms composed too, for a test that boots its disk image itself."""
bundle = find_bundle("desktop")
yield from _composed(tmp_path_factory.mktemp("desktop"), parse_bundle(bundle.root, id_root=bundle.id_root),
disks=True)


@pytest.fixture(scope="module")
def cua_desktop(tmp_path_factory):
"""The cua-driver test bundle's desktop, the ubuntu-24.04 base with the cua-driver driver, composed as ``desktop``
Expand Down Expand Up @@ -158,7 +168,11 @@ def cdp_clients(tmp_path_factory) -> Path:
return folder


def _composed(root: Path, bundle, env_id: str | None = None):
def _composed(root: Path, bundle, env_id: str | None = None, disks: bool = False):
"""``bundle`` written and its computers composed as a run on this machine composes them, its containers alone,
unless ``disks``, which composes every form of each base too. A computer app among them is composed alone only
when it's ``env_id`` or with ``disks``: a fixture of a desktop deploys its apps on the desktop, never alone, and a
test that deploys one alone has its deploy compose it first."""
patch = pytest.MonkeyPatch()
patch.chdir(root)
patch.setenv("XDG_STATE_HOME", str(root / "state"))
Expand All @@ -169,16 +183,31 @@ def _composed(root: Path, bundle, env_id: str | None = None):
package_cache.seed()
with namespace_routing():
plan = plan_bundle(resolve_bundle(bundle), installed=installed_bundles)
alone = pytest.MonkeyPatch()
if not disks:
alone.setattr(composer, "compose", _no_app_alone_but(env_id))
try:
materialize(plan, build_here=frozenset(w.id for w in plan.writes if isinstance(w.source, BuiltImage)))
materialize(plan, build_here=frozenset(w.id for w in plan.writes if isinstance(w.source, BuiltImage)),
composing=Composing() if disks else Composing.for_run(None))
finally:
alone.undo()
package_cache.keep()
yield Env.get(env_id or f"{bundle.id_root}/desktop")
reset_artifact_store()
reset_config()
patch.undo()


def _no_app_alone_but(target: str | None):
"""``composer.compose``, but composing no computer app alone other than ``target``."""
compose = composer.compose

def composing(env, pairs=None, composing=Composing()):
return {} if env.type == "computer_app" and env.id != target else compose(env, pairs, composing)

return composing


#: How many characters of docker's stderr a failed call's error carries: the last, where docker says what failed.
DOCKER_ERROR_CHARS = 2000

Expand Down
6 changes: 6 additions & 0 deletions tst/integration/computer/disk_boot_failure_modal_vm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
pytestmark = [pytest.mark.integration, pytest.mark.int_test_slow, skip_without_remote_sandbox("modal_vm")]


@pytest.fixture(scope="module")
def desktop(desktop_with_disk):
"""The shipped desktop, its disk composed with it: these tests boot its disk image themselves."""
return desktop_with_disk


@pytest.fixture(scope="module")
def ghost(desktop, tmp_path_factory):
yield from ghost_disk(desktop.metadata["composed"]["disk"]["amd64"]["image"], tmp_path_factory.mktemp("ghost"))
Expand Down
6 changes: 6 additions & 0 deletions tst/integration/computer/launcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
BURST = 64


@pytest.fixture(scope="module")
def desktop(desktop_with_disk):
"""The shipped desktop, its disk composed with it: these tests boot its disk image themselves."""
return desktop_with_disk


@pytest.mark.asyncio
async def test_the_launcher_takes_a_burst_of_new_connections_and_a_reset_boots_its_disk_afresh_at_its_url(desktop):
image = _disk(desktop)
Expand Down
Loading
Loading