Skip to content

Commit a15ecb8

Browse files
authored
fail github actions when coverage threshold is not met (#35)
* add precision to coverage; get fail-under from toml; increase coverage
1 parent 1574b6a commit a15ecb8

File tree

5 files changed

+73
-5
lines changed

5 files changed

+73
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
7272
- name: Run tests with coverage
7373
run: |
74-
uv run pytest tests/ --cov=src --cov-report=xml --cov-report=html --cov-fail-under=56
74+
uv run pytest tests/ --cov=src --cov-report=xml --cov-report=html --cov-precision=2
7575
7676
- name: Upload coverage to Codecov
7777
uses: codecov/codecov-action@v5

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ repos:
5353
--cov=src,
5454
--cov-report=term-missing,
5555
--cov-report=html,
56-
--cov-fail-under=90,
5756
--cov-branch,
57+
--cov-precision=2,
5858
tests/
5959
]
6060

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ concurrency = ["thread", "multiprocessing"]
100100

101101
[tool.coverage.report]
102102
show_missing = true
103-
fail_under = 56
103+
fail_under = 90
104104
skip_covered = false
105105
skip_empty = false
106106

tests/bedrock_agentcore/identity/test_auth.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ async def test_async_func(param1, api_key=None):
257257
provider_name="test-provider", agent_identity_token="test-agent-token"
258258
)
259259

260-
def test_sync_function_decoration(self):
261-
"""Test decorator with sync function."""
260+
def test_sync_function_decoration_no_running_loop(self):
261+
"""Test decorator with sync function when no asyncio loop is running."""
262262
# Mock IdentityClient
263263
with patch("bedrock_agentcore.identity.auth.IdentityClient") as mock_identity_client_class:
264264
mock_client = Mock()
@@ -289,6 +289,44 @@ def test_sync_func(param1, my_key=None):
289289

290290
assert result == "param1=value1, key=test-api-key"
291291

292+
def test_sync_function_decoration_with_running_loop(self):
293+
"""Test decorator with sync function when asyncio loop is running."""
294+
# Mock IdentityClient
295+
with patch("bedrock_agentcore.identity.auth.IdentityClient") as mock_identity_client_class:
296+
mock_client = Mock()
297+
mock_identity_client_class.return_value = mock_client
298+
299+
# Mock _get_workload_access_token
300+
with patch(
301+
"bedrock_agentcore.identity.auth._get_workload_access_token", new_callable=AsyncMock
302+
) as mock_get_agent_token:
303+
mock_get_agent_token.return_value = "test-agent-token"
304+
305+
# Mock client.get_api_key
306+
mock_client.get_api_key = AsyncMock(return_value="test-api-key")
307+
308+
# Mock _get_region
309+
with patch("bedrock_agentcore.identity.auth._get_region", return_value="us-west-2"):
310+
311+
@requires_api_key(provider_name="test-provider")
312+
def test_sync_func(param1, api_key=None):
313+
return f"param1={param1}, key={api_key}"
314+
315+
# Mock asyncio.get_running_loop to succeed (loop is running)
316+
with patch("asyncio.get_running_loop"):
317+
with patch("concurrent.futures.ThreadPoolExecutor") as mock_executor_class:
318+
mock_executor = Mock()
319+
mock_executor_class.return_value.__enter__.return_value = mock_executor
320+
321+
mock_future = Mock()
322+
mock_future.result.return_value = "test-api-key"
323+
mock_executor.submit.return_value = mock_future
324+
325+
result = test_sync_func("value1")
326+
327+
assert result == "param1=value1, key=test-api-key"
328+
mock_executor.submit.assert_called_once()
329+
292330

293331
class TestSetUpLocalAuth:
294332
"""Test _set_up_local_auth function."""
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Tests for Bedrock AgentCore context functionality."""
2+
3+
import contextvars
4+
5+
from bedrock_agentcore.runtime.context import BedrockAgentCoreContext
6+
7+
8+
class TestBedrockAgentCoreContext:
9+
"""Test BedrockAgentCoreContext functionality."""
10+
11+
def test_set_and_get_workload_access_token(self):
12+
"""Test setting and getting workload access token."""
13+
token = "test-token-123"
14+
15+
BedrockAgentCoreContext.set_workload_access_token(token)
16+
result = BedrockAgentCoreContext.get_workload_access_token()
17+
18+
assert result == token
19+
20+
def test_get_workload_access_token_when_none_set(self):
21+
"""Test getting workload access token when none is set."""
22+
# Run this test in a completely fresh context to avoid interference from other tests
23+
ctx = contextvars.Context()
24+
25+
def test_in_new_context():
26+
result = BedrockAgentCoreContext.get_workload_access_token()
27+
return result
28+
29+
result = ctx.run(test_in_new_context)
30+
assert result is None

0 commit comments

Comments
 (0)