Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion agent/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ dependencies = [
# Floors, not bare names: a bare requirement resolves to whatever the index
# offers on the day the image is built, and the lockfile hides that until
# somebody regenerates it. These are the releases the lock resolves today.
"daytona>=0.204.0",
# Daytona also has a ceiling: 2.0 moved every type out of the package root,
# so `from daytona import CreateSandboxFromSnapshotParams` and
# `import langchain_daytona` both raise ImportError on it. The ceiling is
# `<1`, not `<2`, because 1.0.1 is an old release nothing here was checked
# against; it keeps the resolver on the 0.x line.
"daytona>=0.232.0,<1",
"langchain-daytona>=0.0.7",
]

Expand Down
81 changes: 81 additions & 0 deletions agent/tests/test_daytona_sdk_contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Do we call the installed Daytona SDK the way it is actually shaped?

`coding/sandbox.py` and `scripts/probe_daytona.py` import from the `daytona`
package root and reach the raw sandbox's `process` and `git` APIs. The unit
tests in `test_sandbox.py` inject fakes, so they keep passing against an SDK
that no longer has those names. Daytona 2.0 is such an SDK: its package root
exports only the clients, and `from daytona import
CreateSandboxFromSnapshotParams` raises `ImportError`. So does
`import langchain_daytona`, in every release up to 0.0.9.

These tests read the real installed classes, offline. No client is built and no
sandbox is created.
"""

from __future__ import annotations

import inspect

from daytona import (
CreateSandboxFromSnapshotParams,
Daytona,
ExecuteResponse,
Sandbox,
)
from daytona._sync.git import Git
from daytona._sync.process import Process
from langchain_daytona import DaytonaSandbox


def parameters(method) -> dict[str, inspect.Parameter]:
return dict(inspect.signature(method).parameters)


def test_snapshot_params_accept_what_we_pass():
# `_default_create_sandbox` and the probe script build these four fields.
fields = set(CreateSandboxFromSnapshotParams.model_fields)
assert {"snapshot", "env_vars", "auto_stop_interval", "ttl_minutes"} <= fields


def test_create_takes_the_params_positionally():
names = list(parameters(Daytona.create))
assert names[1] == "params"


def test_process_exec_takes_a_timeout_and_returns_result_and_exit_code():
# `_run_on_box` prefers `process.exec` because session execute hangs on long
# commands, and reads `.result` and `.exit_code` from the response.
exec_params = parameters(Process.exec)
assert list(exec_params)[1] == "command"
assert "timeout" in exec_params
assert {"result", "exit_code"} <= set(ExecuteResponse.model_fields)


def test_git_methods_accept_the_keywords_we_pass():
calls = {
"clone": {"url", "path", "branch", "username", "password"},
"pull": {"path", "branch", "remote", "username", "password"},
"push": {"path", "branch", "remote", "set_upstream", "username", "password"},
"remote_add": {"path", "name", "url"},
"set_config": {"scope", "path"},
}
for name, keywords in calls.items():
accepted = set(parameters(getattr(Git, name)))
assert keywords <= accepted, f"Git.{name} lacks {keywords - accepted}"


def test_set_config_takes_key_and_value_positionally():
names = list(parameters(Git.set_config))
assert names[1:3] == ["key", "value"]


def test_sandbox_can_be_deleted_without_arguments():
for name, parameter in parameters(Sandbox.delete).items():
if name == "self":
continue
assert parameter.default is not inspect.Parameter.empty, name


def test_langchain_wrapper_takes_the_sandbox_by_keyword():
sandbox = parameters(DaytonaSandbox.__init__)["sandbox"]
assert sandbox.kind is inspect.Parameter.KEYWORD_ONLY
22 changes: 22 additions & 0 deletions agent/tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
#: `sandbox` and `manage_connections` arguments this repository passes.
COMPOSIO_SESSIONS_FLOOR = (0, 17, 0)

#: Daytona 2.0 moved every type out of the package root into version
#: namespaces (`daytona.v0`, `daytona.v2`). `from daytona import
#: CreateSandboxFromSnapshotParams` in `coding/sandbox.py` raises `ImportError`
#: there, and so does `import langchain_daytona` in every release up to 0.0.9.
#: `1.0.1` is an old, unrelated release. Below `1` keeps a re-resolve on 0.x.
DAYTONA_CEILING = (1,)

#: Floors that are not a matter of taste: the earliest release carrying an API
#: this repository actually calls.
REQUIRED_FLOORS = {"composio": COMPOSIO_SESSIONS_FLOOR}
Expand Down Expand Up @@ -223,6 +230,21 @@ def test_every_dependency_declares_a_lower_bound():
assert unbounded == []


def upper_bound(requirement: str) -> tuple[int, ...] | None:
"""The `<` ceiling in a requirement, as a comparable tuple, or `None`."""
match = re.search(r"<(?!=)\s*(\d+(?:\.\d+)*)", requirement)
return tuple(int(part) for part in match.group(1).split(".")) if match else None


def test_daytona_is_held_below_the_namespaced_sdk():
ceiling = upper_bound(declared_dependencies()["daytona"])

assert ceiling is not None and ceiling <= DAYTONA_CEILING, (
"daytona needs an upper bound: 2.0 removed the root imports this "
"repository and langchain-daytona use"
)


def test_pinned_apis_declare_a_floor_that_has_them():
declared = declared_dependencies()

Expand Down
Loading