Lee-W commented on code in PR #74396:
URL: https://github.com/apache/airflow/pull/74396#discussion_r4241067926


##########
providers/common/ai/tests/unit/common/ai/mixins/test_usage_budget.py:
##########
@@ -0,0 +1,183 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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 __future__ import annotations
+
+import logging
+from decimal import Decimal
+from unittest import mock
+from unittest.mock import MagicMock
+
+import pytest
+from pydantic_ai.usage import RunUsage, UsageLimits
+
+from airflow.providers.common.ai.mixins.usage_budget import UsageBudgetMixin
+from airflow.providers.common.ai.utils.usage_budget import 
TaskStateStoreUsageBudget
+
+MIXIN_MODULE = "airflow.providers.common.ai.mixins.usage_budget"
+
+
+class _Host(UsageBudgetMixin):
+    def __init__(self, usage_limits=None):
+        self.usage_limits = usage_limits
+        self.log = logging.getLogger(__name__)
+        self.run_agent_sync = MagicMock()
+
+
+class TestBuildUsageBudget:
+    @mock.patch(f"{MIXIN_MODULE}.AIRFLOW_V_3_3_PLUS", True)
+    def test_builds_budget_from_task_state_store_and_max_tries(self):
+        context = {"task_state_store": MagicMock()}
+        ti = MagicMock(max_tries=3)
+
+        budget = _Host()._build_usage_budget(context, 
UsageLimits(request_limit=5), ti=ti)
+
+        assert isinstance(budget, TaskStateStoreUsageBudget)

Review Comment:
   The test now saves through the budget and asserts the record lands in 
`context["task_state_store"]` with `max_tries == 3`. It goes red when the store 
is wrong and when `max_tries` is off by one.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to