Secure, Fast, and Extensible Sandbox runtime for AI agents.
fix(console): run BFF platform tests under unittest in CI
刘祺祥fde59d42f4c2
diff --git a/console/bff/tests/test_k8s_event_filter.py b/console/bff/tests/test_k8s_event_filter.pyindex 194747eb0..60f195e7a 100644--- a/console/bff/tests/test_k8s_event_filter.py+++ b/console/bff/tests/test_k8s_event_filter.py@@ -12,22 +12,29 @@# See the License for the specific language governing permissions and# limitations under the License.+import unittestfrom types import SimpleNamespacefrom app.k8s_resources import _event_matches_sandbox, pod_name_candidates_for_sandbox-def test_pod_name_candidates_include_batch_suffix():- assert pod_name_candidates_for_sandbox("abc") == ["abc-0", "abc"]+class K8sEventFilterTests(unittest.TestCase):+ def test_pod_name_candidates_include_batch_suffix(self):+ self.assertEqual(pod_name_candidates_for_sandbox("abc"), ["abc-0", "abc"])+ def test_event_matches_pooled_pod_name(self):+ ev = SimpleNamespace(+ involved_object=SimpleNamespace(kind="Pod", name="abc-0"),+ )+ names = set(pod_name_candidates_for_sandbox("abc"))+ self.assertTrue(_event_matches_sandbox(ev, names))+ self.assertFalse(+ _event_matches_sandbox(+ SimpleNamespace(involved_object=SimpleNamespace(kind="Pod", name="other-0")),+ names,+ )+ )-def test_event_matches_pooled_pod_name():- ev = SimpleNamespace(- involved_object=SimpleNamespace(kind="Pod", name="abc-0"),- )- names = set(pod_name_candidates_for_sandbox("abc"))- assert _event_matches_sandbox(ev, names)- assert not _event_matches_sandbox(- SimpleNamespace(involved_object=SimpleNamespace(kind="Pod", name="other-0")),- names,- )++if __name__ == "__main__":+ unittest.main()diff --git a/console/bff/tests/test_query_params.py b/console/bff/tests/test_query_params.pyindex 26fc69f21..09212f5c3 100644--- a/console/bff/tests/test_query_params.py+++ b/console/bff/tests/test_query_params.py@@ -12,27 +12,39 @@# See the License for the specific language governing permissions and# limitations under the License.-import pytest+import unittest+from fastapi import HTTPExceptionfrom app.query_params import parse_archive_max_bytes, parse_query_int-def test_parse_query_int_defaults_and_clamps():- assert parse_query_int(None, field="limit", default=100, maximum=500) == 100- assert parse_query_int("", field="limit", default=100, maximum=500) == 100- assert parse_query_int("0", field="limit", default=100, minimum=1, maximum=500) == 1- assert parse_query_int("9999", field="limit", default=100, maximum=500) == 500+class ParseQueryIntTests(unittest.TestCase):+ def test_defaults_and_clamps(self):+ self.assertEqual(parse_query_int(None, field="limit", default=100, maximum=500), 100)+ self.assertEqual(parse_query_int("", field="limit", default=100, maximum=500), 100)+ self.assertEqual(+ parse_query_int("0", field="limit", default=100, minimum=1, maximum=500),+ 1,+ )+ self.assertEqual(+ parse_query_int("9999", field="limit", default=100, maximum=500),+ 500,+ )++ def test_rejects_garbage(self):+ with self.assertRaises(HTTPException) as ctx:+ parse_query_int("abc", field="limit", default=100, maximum=500)+ self.assertEqual(ctx.exception.detail["code"], "INVALID_QUERY")-def test_parse_query_int_rejects_garbage():- with pytest.raises(HTTPException) as exc:- parse_query_int("abc", field="limit", default=100, maximum=500)- assert exc.value.detail["code"] == "INVALID_QUERY"+class ParseArchiveMaxBytesTests(unittest.TestCase):+ def test_clamps_to_cap(self):+ self.assertEqual(parse_archive_max_bytes(None, cap=512_288), 512_288)+ self.assertEqual(parse_archive_max_bytes("9999999", cap=512_288), 512_288)+ self.assertEqual(parse_archive_max_bytes("0", cap=512_288), 1)+ self.assertEqual(parse_archive_max_bytes("-5", cap=512_288), 1)-def test_parse_archive_max_bytes_clamps_to_cap():- assert parse_archive_max_bytes(None, cap=512_288) == 512_288- assert parse_archive_max_bytes("9999999", cap=512_288) == 512_288- assert parse_archive_max_bytes("0", cap=512_288) == 1- assert parse_archive_max_bytes("-5", cap=512_288) == 1+if __name__ == "__main__":+ unittest.main()