Spaces:
Sleeping
Sleeping
Download src/tests/runtime/test_container_live.py from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/tests/runtime/test_container_live.py
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/src/tests/runtime/test_container_live.py
-
curl -L -o test_container_live.py https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/src/tests/runtime/test_container_live.py
2.41 kB
| """Opt-in real isolation acceptance. No host javac/java fallback.""" | |
| import os | |
| import shutil | |
| import unittest | |
| import uuid | |
| from src.adapters.sandbox.docker import DockerSandbox | |
| from src.modules.execution.contracts import SandboxConfig | |
| from src.modules.skill.domain.models import digest | |
| from src.tests.runtime.fixtures import workspace | |
| SOURCE = '''package demo; | |
| import com.sun.net.httpserver.HttpServer; | |
| import java.net.InetSocketAddress; | |
| import java.nio.charset.StandardCharsets; | |
| public class App { | |
| public static void main(String[] args) throws Exception { | |
| var server = HttpServer.create(new InetSocketAddress("127.0.0.1",8080),0); | |
| server.createContext("/health", exchange -> { | |
| byte[] body = "{\\"status\\":\\"ok\\"}".getBytes(StandardCharsets.UTF_8); | |
| exchange.getResponseHeaders().add("Content-Type","application/json"); | |
| exchange.sendResponseHeaders(200,body.length); | |
| try(var stream=exchange.getResponseBody()){stream.write(body);} | |
| }); | |
| server.start(); | |
| } | |
| }''' | |
| class LiveContainerTests(unittest.TestCase): | |
| def test_real_java_build_http_test_preview_and_cleanup(self): | |
| config = SandboxConfig(image=os.environ['ZKCODING_TEST_IMAGE'], skill_ids=['erp-java-development'], | |
| api_contract='GET /health -> {"status":"ok"}', | |
| tests=[{'path': '/health', 'status': 200, 'expected_json': {'status': 'ok'}}], | |
| health={'path': '/health', 'status': 200, 'expected_json': {'status': 'ok'}}) | |
| with workspace() as folder: | |
| sandbox = DockerSandbox(folder, config) | |
| run_id = 'run-' + uuid.uuid4().hex | |
| files = {'src/main/java/demo/App.java': SOURCE} | |
| try: | |
| candidate = sandbox.build(run_id, {'files': files, 'source_digest': digest(files)}, lambda: False) | |
| test = sandbox.probe(run_id, candidate, 'test', lambda: False) | |
| preview = sandbox.probe(run_id, candidate, 'preview', lambda: False) | |
| self.assertTrue(test['passed']) | |
| self.assertTrue(preview['passed']) | |
| self.assertEqual(test['classes_digest'], preview['classes_digest']) | |
| finally: | |
| self.assertTrue(sandbox.cleanup(run_id)) | |