|
14 | 14 | import pytest |
15 | 15 |
|
16 | 16 | from src.opengradient.client.llm import LLM |
17 | | -from src.opengradient.client.tee_connection import TEEConnection |
18 | 17 | from src.opengradient.types import TEE_LLM, x402SettlementMode |
19 | 18 |
|
20 | 19 | # ── Fake HTTP transport ────────────────────────────────────────────── |
@@ -511,50 +510,6 @@ async def test_close_delegates_to_http_client(self, fake_http): |
511 | 510 | # FakeHTTPClient.aclose is a no-op; just verify it doesn't blow up. |
512 | 511 |
|
513 | 512 |
|
514 | | -# ── TEE resolution tests ───────────────────────────────────────────── |
515 | | - |
516 | | - |
517 | | -class TestResolveTeE: |
518 | | - def test_explicit_url_skips_registry(self): |
519 | | - endpoint, cert, tee_id, pay_addr = TEEConnection._resolve_tee("https://explicit.url", None) |
520 | | - |
521 | | - assert endpoint == "https://explicit.url" |
522 | | - assert cert is None |
523 | | - assert tee_id is None |
524 | | - assert pay_addr is None |
525 | | - |
526 | | - def test_missing_rpc_and_registry_raises(self): |
527 | | - with pytest.raises(ValueError): |
528 | | - TEEConnection._resolve_tee(None, None) |
529 | | - |
530 | | - def test_missing_registry_address_raises(self): |
531 | | - with pytest.raises(ValueError): |
532 | | - TEEConnection._resolve_tee(None, None) |
533 | | - |
534 | | - def test_registry_returns_none_raises(self): |
535 | | - mock_reg = MagicMock() |
536 | | - mock_reg.get_llm_tee.return_value = None |
537 | | - |
538 | | - with pytest.raises(ValueError, match="No active LLM proxy TEE"): |
539 | | - TEEConnection._resolve_tee(None, mock_reg) |
540 | | - |
541 | | - def test_registry_success(self): |
542 | | - mock_reg = MagicMock() |
543 | | - mock_tee = MagicMock() |
544 | | - mock_tee.endpoint = "https://registry.tee" |
545 | | - mock_tee.tls_cert_der = b"cert-bytes" |
546 | | - mock_tee.tee_id = "tee-42" |
547 | | - mock_tee.payment_address = "0xPay" |
548 | | - mock_reg.get_llm_tee.return_value = mock_tee |
549 | | - |
550 | | - endpoint, cert, tee_id, pay_addr = TEEConnection._resolve_tee(None, mock_reg) |
551 | | - |
552 | | - assert endpoint == "https://registry.tee" |
553 | | - assert cert == b"cert-bytes" |
554 | | - assert tee_id == "tee-42" |
555 | | - assert pay_addr == "0xPay" |
556 | | - |
557 | | - |
558 | 513 | # ── TEE retry tests (non-streaming) ────────────────────────────────── |
559 | 514 |
|
560 | 515 |
|
@@ -678,53 +633,6 @@ async def aread(self) -> bytes: |
678 | 633 | assert len(fake_http.post_calls) == 1 |
679 | 634 |
|
680 | 635 |
|
681 | | -# ── TEE reconnect tests ───────────────────────────────────────────── |
682 | | - |
683 | | - |
684 | | -@pytest.mark.asyncio |
685 | | -class TestReconnect: |
686 | | - async def test_replaces_http_client(self): |
687 | | - """After reconnect, the http client should be a new instance.""" |
688 | | - clients_created = [] |
689 | | - |
690 | | - def make_client(*args, **kwargs): |
691 | | - c = FakeHTTPClient() |
692 | | - clients_created.append(c) |
693 | | - return c |
694 | | - |
695 | | - with ( |
696 | | - patch(_PATCHES["x402_httpx"], side_effect=make_client), |
697 | | - patch(_PATCHES["x402_client"]), |
698 | | - patch(_PATCHES["signer"]), |
699 | | - patch(_PATCHES["register_exact"]), |
700 | | - patch(_PATCHES["register_upto"]), |
701 | | - ): |
702 | | - llm = _make_llm() |
703 | | - old_client = llm._tee.get().http_client |
704 | | - |
705 | | - await llm._tee.reconnect() |
706 | | - |
707 | | - assert llm._tee.get().http_client is not old_client |
708 | | - assert len(clients_created) == 2 # init + refresh |
709 | | - |
710 | | - async def test_closes_old_client(self, fake_http): |
711 | | - llm = _make_llm() |
712 | | - old_client = llm._tee.get().http_client |
713 | | - old_client.aclose = AsyncMock() |
714 | | - |
715 | | - await llm._tee.reconnect() |
716 | | - |
717 | | - old_client.aclose.assert_awaited_once() |
718 | | - |
719 | | - async def test_close_failure_is_swallowed(self, fake_http): |
720 | | - llm = _make_llm() |
721 | | - old_client = llm._tee.get().http_client |
722 | | - old_client.aclose = AsyncMock(side_effect=OSError("already closed")) |
723 | | - |
724 | | - # Should not raise |
725 | | - await llm._tee.reconnect() |
726 | | - |
727 | | - |
728 | 636 | # ── TEE cert rotation (crash + re-register) tests ──────────────────── |
729 | 637 |
|
730 | 638 |
|
|
0 commit comments