Files
OpenShell/e2e/python/test_sandbox_api.py
Alexander Watson 1d7909cb38 chore: add open-source compliance files and SPDX headers (#71)
Add Apache 2.0 licensing, SPDX copyright headers on all source files,
DCO enforcement, third-party notices, and CI enforcement.

- LICENSE: Apache License 2.0 full text
- DCO: Developer Certificate of Origin 1.1
- SPDX headers on all 176 source files (.rs, .py, .proto, .rego, .sh,
  .toml, .yaml, Dockerfiles)
- scripts/update_license_headers.py: header management with --check mode
- scripts/generate_third_party_notices.py: dependency license aggregation
- THIRD-PARTY-NOTICES: generated listing of all Rust and Python deps
- build/license.toml: mise tasks for license:check and license:update
- CI: license-headers job in checks.yml, DCO check workflow
- CONTRIBUTING.md: DCO sign-off requirement and license header docs
- Cargo.toml: license changed to Apache-2.0, repository URL updated
- pyproject.toml: license field added

Closes #58
2026-03-03 09:30:56 -08:00

55 lines
1.5 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Callable
from navigator import Sandbox, SandboxClient
def test_sandbox_api_crud_and_exec(
sandbox: Callable[..., Sandbox],
sandbox_client: SandboxClient,
) -> None:
class _FileOps:
def write(self, path: str, content: str) -> None:
from pathlib import Path
Path(path).write_text(content)
def read(self, path: str) -> str:
from pathlib import Path
return Path(path).read_text()
with sandbox(delete_on_exit=True) as sb:
assert sb.id
assert sb.sandbox.name.startswith("sandbox-")
fetched = sandbox_client.get(sb.id)
assert fetched.id == sb.id
ids = set(sandbox_client.list_ids(limit=100))
assert sb.id in ids
result = sb.exec(["python", "-c", "print('sandbox-ok')"])
assert result.exit_code == 0
assert "sandbox-ok" in result.stdout
file_ops = _FileOps()
create_file = sb.exec_python(
file_ops.write,
args=("/sandbox/exec-persistence.txt", "ok"),
)
assert create_file.exit_code == 0
verify_file = sb.exec_python(
file_ops.read, args=("/sandbox/exec-persistence.txt",)
)
assert verify_file.exit_code == 0
assert verify_file.stdout.strip() == "ok"