Files
wehub-resource-sync e0e362d700
SDK Tests / SDK CI (push) Blocked by required conditions
SDK Tests / changes (push) Successful in 2m29s
Real E2E Tests / changes (push) Successful in 2m29s
SDK Tests / Python SDK Tests (sandbox) (push) Waiting to run
SDK Tests / CLI Quality (push) Waiting to run
SDK Tests / CLI Tests (push) Waiting to run
SDK Tests / Python SDK Quality (code-interpreter) (push) Waiting to run
SDK Tests / Python SDK Quality (sandbox) (push) Waiting to run
SDK Tests / Python SDK Tests (code-interpreter) (push) Waiting to run
SDK Tests / JavaScript SDK Quality And Tests (code-interpreter) (push) Waiting to run
SDK Tests / JavaScript SDK Quality And Tests (sandbox) (push) Waiting to run
SDK Tests / Kotlin SDK Quality And Tests (sandbox) (push) Waiting to run
SDK Tests / Kotlin SDK Quality And Tests (code-interpreter) (push) Waiting to run
SDK Tests / C# SDK Quality And Tests (code-interpreter) (push) Waiting to run
SDK Tests / C# SDK Quality And Tests (sandbox) (push) Waiting to run
SDK Tests / Go SDK Quality And Tests (push) Waiting to run
Deploy Docs Pages / build (push) Has been cancelled
Deploy Docs Pages / deploy (push) Has been cancelled
Real E2E Tests / JavaScript E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Python E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Java E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / C# E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Go E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Real E2E CI (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:39:33 +08:00

166 lines
5.0 KiB
Python

# Copyright 2026 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from fastapi.testclient import TestClient
from opensandbox_server.api import devops
def test_diagnostics_logs_with_scope_returns_not_implemented(
client: TestClient,
auth_headers: dict,
monkeypatch,
) -> None:
class StubService:
@staticmethod
def get_sandbox_logs(
sandbox_id: str,
tail: int,
since: str | None = None,
container: str | None = None,
) -> str:
raise AssertionError("stable diagnostics requests must not call legacy logs")
monkeypatch.setattr(devops, "sandbox_service", StubService())
response = client.get(
"/v1/sandboxes/sbx-001/diagnostics/logs?scope=container",
headers=auth_headers,
)
assert response.status_code == 501
assert response.headers["content-type"].startswith("application/json")
assert response.json()["code"] == "DIAGNOSTICS_NOT_IMPLEMENTED"
def test_diagnostics_logs_without_scope_preserves_deprecated_plain_text(
client: TestClient,
auth_headers: dict,
monkeypatch,
) -> None:
class StubService:
@staticmethod
def get_sandbox_logs(
sandbox_id: str,
tail: int,
since: str | None = None,
container: str | None = None,
) -> str:
assert sandbox_id == "sbx-001"
assert tail == 25
assert since == "5m"
assert container is None
return "legacy logs"
monkeypatch.setattr(devops, "sandbox_service", StubService())
response = client.get(
"/v1/sandboxes/sbx-001/diagnostics/logs?tail=25&since=5m",
headers=auth_headers,
)
assert response.status_code == 200
assert response.headers["content-type"].startswith("text/plain")
assert response.headers["deprecation"] == "true"
assert response.text == "legacy logs"
def test_diagnostics_logs_forwards_container_query_to_service(
client: TestClient,
auth_headers: dict,
monkeypatch,
) -> None:
captured: dict = {}
class StubService:
@staticmethod
def get_sandbox_logs(
sandbox_id: str,
tail: int,
since: str | None = None,
container: str | None = None,
) -> str:
captured["container"] = container
return "sidecar logs"
monkeypatch.setattr(devops, "sandbox_service", StubService())
response = client.get(
"/v1/sandboxes/sbx-001/diagnostics/logs?container=egress",
headers=auth_headers,
)
assert response.status_code == 200
assert response.text == "sidecar logs"
assert captured == {"container": "egress"}
def test_diagnostics_events_with_scope_returns_not_implemented(
client: TestClient,
auth_headers: dict,
monkeypatch,
) -> None:
class StubService:
@staticmethod
def get_sandbox_events(sandbox_id: str, limit: int) -> str:
raise AssertionError("stable diagnostics requests must not call legacy events")
monkeypatch.setattr(devops, "sandbox_service", StubService())
response = client.get(
"/v1/sandboxes/sbx-001/diagnostics/events?scope=runtime",
headers=auth_headers,
)
assert response.status_code == 501
assert response.headers["content-type"].startswith("application/json")
assert response.json()["code"] == "DIAGNOSTICS_NOT_IMPLEMENTED"
def test_diagnostics_summary_redacts_unexpected_exception_details(
client: TestClient,
auth_headers: dict,
monkeypatch,
) -> None:
class StubService:
@staticmethod
def get_sandbox_inspect(sandbox_id: str) -> str:
raise RuntimeError("backend secret token")
@staticmethod
def get_sandbox_events(sandbox_id: str, limit: int) -> str:
return "events ok"
@staticmethod
def get_sandbox_logs(
sandbox_id: str,
tail: int,
since: str | None = None,
container: str | None = None,
) -> str:
return "logs ok"
monkeypatch.setattr(devops, "sandbox_service", StubService())
response = client.get(
"/v1/sandboxes/sbx-001/diagnostics/summary",
headers=auth_headers,
)
assert response.status_code == 200
assert "[error] Failed to collect inspect diagnostics." in response.text
assert "backend secret token" not in response.text
assert "events ok" in response.text
assert "logs ok" in response.text