Repository navigation
feat(snapshot_env): hand a service that takes parts grants an object of its own to upload to #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
earakely-scale
wants to merge
17
commits into
edgararakelyan/store-begin-write
Choose a base branch
from
edgararakelyan/snapshot-parts-grant
base: edgararakelyan/store-begin-write
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ed59a6e
feat(snapshot_env): hand a service that takes parts grants an object …
earakely-scale b6aabc1
Merge remote-tracking branch 'origin/edgararakelyan/store-begin-write…
earakely-scale 6c052d2
fix(snapshot): an export cancelled midway leaves no write open and no…
earakely-scale 4cefaad
Merge remote-tracking branch 'origin/edgararakelyan/store-begin-write…
earakely-scale c53fc96
Merge remote-tracking branch 'origin/edgararakelyan/store-begin-write…
earakely-scale 53bcef6
refactor(snapshot_env): count a parts upload's parts with part_ranges
earakely-scale 32b9ddf
fix(local): services on a local compose stack trust the local transfe…
earakely-scale 4a2c4d5
Merge remote-tracking branch 'origin/edgararakelyan/store-begin-write…
earakely-scale aaa07cd
Merge branch 'edgararakelyan/snapshot-parts-grant' into edgararakelya…
earakely-scale 3178ff5
Merge remote-tracking branch 'origin/edgararakelyan/store-begin-write…
earakely-scale ab8ed05
Merge branch 'edgararakelyan/snapshot-parts-grant' into edgararakelya…
earakely-scale 797fa01
test(integration): close the grant server the compose fixture's tests…
earakely-scale f48eba4
test(integration): sort the grant_server import
earakely-scale db1469f
Merge remote-tracking branch 'origin/edgararakelyan/store-begin-write…
earakely-scale b307da3
Merge branch 'edgararakelyan/snapshot-parts-grant' into edgararakelya…
earakely-scale 0508b2e
fix(local): trusted compose services also carry the sandbox's host ma…
earakely-scale b18b88f
fix(local): a local compose mounts the trust files from a copy in its…
earakely-scale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """snapshot_env on the local backend, end to end, through a parts grant. | ||
|
|
||
| A MultiEnv's items server takes ``write_object``, so the snapshot hands it an object of its own on the local store; the | ||
| server uploads its bundle from its container, the snapshot registers that object as the server's export, and loading the | ||
| snapshot back restores the state it held. Requires a docker daemon; spins up a throwaway ``registry:2`` and skips if it | ||
| can't start. | ||
| """ | ||
|
|
||
| import io | ||
| import json | ||
| import logging | ||
| import uuid | ||
| import zipfile | ||
|
|
||
| import pytest | ||
| from agentenv_protocol import DataPart | ||
| from agentenv_protocol import client as protocol_v1 | ||
|
|
||
| from agent_env.artifact import EnvironmentUniverseArtifact | ||
| from agent_env.env import legacy_protocol | ||
| from agent_env.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.task_step.context import TaskStepContext | ||
| from agent_env.task_step.task_steps import snapshot_env as snapshot_mod | ||
| from agent_env.task_step.task_steps.snapshot_env import SnapshotEnvTaskStep | ||
| from tst.integration.env.envs.server_env_local_test import _put_items_image | ||
| from tst.integration.store.local_parallel_deploy_test import _docker, _seed_bootstrap_envs, local_stack # noqa: F401 (fixture) | ||
|
|
||
| pytestmark = [pytest.mark.integration, pytest.mark.int_test_slow] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_a_snapshot_of_a_server_that_takes_parts_registers_its_upload_and_loads_back(local_stack, caplog): | ||
| _seed_bootstrap_envs() | ||
| uid = uuid.uuid4().hex[:8] | ||
| items = MCPServerEnv.put(id=f"snap-items-{uid}", environment_name="items", | ||
| docker_image_artifact=_put_items_image(f"snap-items-{uid}")) | ||
| env = MultiEnv.put(id=f"snap-{uid}", mcp_server_envs=[items], name="suite") | ||
|
|
||
| deployed = await env.deploy(sandbox_type="local", ttl_seconds=900) | ||
| work_dir = env._sandbox.work_dir | ||
| try: | ||
| base_url = await legacy_protocol.v1_base_url(deployed, deployed.gateway_url, "items") | ||
| await protocol_v1.add_data(base_url, [DataPart(data={"items": ["snap-x", "snap-y"]})]) | ||
|
|
||
| step = SnapshotEnvTaskStep(id="snap", version=None, snapshot_id=f"snap-universe-{uid}") | ||
| with caplog.at_level(logging.INFO, logger=snapshot_mod.logger.name): | ||
| context = await step.execute(TaskStepContext(deployed_envs=[deployed])) | ||
|
|
||
| assert "items exported through parts" in caplog.text | ||
| universe = EnvironmentUniverseArtifact.get(context.metadata["env_snapshotted_universes"]["snap"]["id"]) | ||
| (bundle,) = universe.get_file_artifacts().values() | ||
| assert "/agentenv-snapshots/" in bundle.object_url and bundle.object_url.endswith("/items.zip") | ||
| assert (bundle.filename, bundle.content_type) == ("items.zip", "application/zip") | ||
| with zipfile.ZipFile(io.BytesIO(bundle.load())) as zf: | ||
| assert json.loads(zf.read("items.json")) == {"items": ["snap-x", "snap-y"]} | ||
|
|
||
| await protocol_v1.add_data(base_url, [DataPart(data={"items": ["after-the-snapshot"]})]) | ||
| await (await Env.from_instance_id(deployed.instance_id)).load_environment_universe_artifact(universe) | ||
| assert (await protocol_v1.get_data(base_url)).model_dump()["parts"][0]["data"] == {"items": ["snap-x", "snap-y"]} | ||
| finally: | ||
| _docker("compose", "--project-directory", str(work_dir), "down", "-v", "--remove-orphans") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.