|
| 1 | +"""Regression test: gateway terms check must be gated on needs_inference, not needs_model_specs. |
| 2 | +
|
| 3 | +Commands like ``pipelex-agent validate bundle`` use ``needs_inference=False, needs_model_specs=True`` |
| 4 | +to load model specs for validation without actually calling inference APIs. These commands must |
| 5 | +NOT require gateway terms acceptance. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +from typing import TYPE_CHECKING |
| 11 | + |
| 12 | +import pytest |
| 13 | + |
| 14 | +from pipelex.pipelex import Pipelex |
| 15 | +from pipelex.system.pipelex_service.exceptions import GatewayTermsNotAcceptedError |
| 16 | +from pipelex.system.runtime import IntegrationMode |
| 17 | + |
| 18 | +if TYPE_CHECKING: |
| 19 | + from pytest_mock import MockerFixture |
| 20 | + |
| 21 | +PIPELEX_MODULE = "pipelex.pipelex" |
| 22 | + |
| 23 | + |
| 24 | +class TestGatewayTermsCheck: |
| 25 | + """Verify that the terms check in Pipelex.setup() respects needs_inference.""" |
| 26 | + |
| 27 | + @pytest.fixture |
| 28 | + def _gateway_enabled_terms_not_accepted(self, mocker: MockerFixture) -> None: |
| 29 | + """Configure mocks: gateway is enabled but terms have NOT been accepted.""" |
| 30 | + mocker.patch(f"{PIPELEX_MODULE}.is_pipelex_gateway_enabled", return_value=True) |
| 31 | + mocker.patch(f"{PIPELEX_MODULE}.load_pipelex_service_config_if_exists", return_value=None) |
| 32 | + |
| 33 | + @pytest.mark.usefixtures("_gateway_enabled_terms_not_accepted") |
| 34 | + def test_needs_inference_true_raises_when_terms_not_accepted( |
| 35 | + self, |
| 36 | + ) -> None: |
| 37 | + """With needs_inference=True and terms not accepted, setup must raise GatewayTermsNotAcceptedError.""" |
| 38 | + pipelex_instance = Pipelex.__new__(Pipelex) |
| 39 | + |
| 40 | + with pytest.raises(GatewayTermsNotAcceptedError): |
| 41 | + pipelex_instance.setup( |
| 42 | + integration_mode=IntegrationMode.CLI, |
| 43 | + needs_inference=True, |
| 44 | + needs_model_specs=True, |
| 45 | + ) |
| 46 | + |
| 47 | + @pytest.mark.usefixtures("_gateway_enabled_terms_not_accepted") |
| 48 | + def test_needs_inference_false_does_not_raise_when_terms_not_accepted( |
| 49 | + self, |
| 50 | + mocker: MockerFixture, |
| 51 | + ) -> None: |
| 52 | + """With needs_inference=False and needs_model_specs=True, setup must NOT raise GatewayTermsNotAcceptedError. |
| 53 | +
|
| 54 | + It may fail later (e.g., during remote config fetch), but the terms check itself must be skipped. |
| 55 | + """ |
| 56 | + # Mock the remote config fetch so we don't hit the network |
| 57 | + mock_remote_config = mocker.MagicMock() |
| 58 | + mock_remote_config.backend_model_specs = {} |
| 59 | + mocker.patch(f"{PIPELEX_MODULE}.RemoteConfigFetcher.fetch_remote_config", return_value=mock_remote_config) |
| 60 | + |
| 61 | + pipelex_instance = Pipelex.__new__(Pipelex) |
| 62 | + |
| 63 | + # setup() will fail somewhere after the gateway check (telemetry, models, etc.) |
| 64 | + # but it must NOT fail with GatewayTermsNotAcceptedError |
| 65 | + try: |
| 66 | + pipelex_instance.setup( |
| 67 | + integration_mode=IntegrationMode.CLI, |
| 68 | + needs_inference=False, |
| 69 | + needs_model_specs=True, |
| 70 | + ) |
| 71 | + except GatewayTermsNotAcceptedError: |
| 72 | + pytest.fail("setup() raised GatewayTermsNotAcceptedError even though needs_inference=False") |
| 73 | + except Exception: # noqa: S110 |
| 74 | + # Expected: setup() will fail later in the init chain (telemetry, models, etc.) |
| 75 | + # We only care that it did NOT fail with GatewayTermsNotAcceptedError |
| 76 | + pass |
0 commit comments