-
Notifications
You must be signed in to change notification settings - Fork 1
Reorganize tests into component-based structure #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4c5a9ea
6ba5aad
1b9d98f
60e2b84
ca63d4c
29acdd2
1a51639
195542e
021501b
7852052
4bcc324
c11b082
26c2bf9
6dec921
f7b4ff2
7059ec1
3d451fa
d17897a
b4ad42a
ee07f66
49a4161
7904614
027ce10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
name: Component Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
components: | ||
description: "Comma-separated components to run (auth,cli,client,fuzz_engine,safety[safety_system],transport)" | ||
required: false | ||
default: "" | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
actions: read | ||
|
||
jobs: | ||
component-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install . | ||
pip install pytest pytest-cov pytest-asyncio | ||
|
||
- name: Determine changed components | ||
id: changes | ||
run: | | ||
# If manual input is provided, use that. Otherwise, run all components. | ||
INPUTS="${{ github.event.inputs.components }}" | ||
if [ -n "$INPUTS" ]; then | ||
AUTH_CHANGES=false | ||
CLI_CHANGES=false | ||
CLIENT_CHANGES=false | ||
FUZZ_ENGINE_CHANGES=false | ||
SAFETY_CHANGES=false | ||
TRANSPORT_CHANGES=false | ||
IFS=',' read -ra TOKENS <<< "$INPUTS" | ||
for t in "${TOKENS[@]}"; do | ||
t="${t//[[:space:]]/}" | ||
case "$t" in | ||
auth) AUTH_CHANGES=true ;; | ||
cli) CLI_CHANGES=true ;; | ||
client) CLIENT_CHANGES=true ;; | ||
fuzz_engine) FUZZ_ENGINE_CHANGES=true ;; | ||
safety|safety_system) SAFETY_CHANGES=true ;; | ||
transport) TRANSPORT_CHANGES=true ;; | ||
esac | ||
done | ||
else | ||
# Default to running all components on manual trigger | ||
AUTH_CHANGES=true | ||
CLI_CHANGES=true | ||
CLIENT_CHANGES=true | ||
FUZZ_ENGINE_CHANGES=true | ||
SAFETY_CHANGES=true | ||
TRANSPORT_CHANGES=true | ||
fi | ||
|
||
echo "auth=$AUTH_CHANGES" >> $GITHUB_OUTPUT | ||
echo "cli=$CLI_CHANGES" >> $GITHUB_OUTPUT | ||
echo "client=$CLIENT_CHANGES" >> $GITHUB_OUTPUT | ||
echo "fuzz_engine=$FUZZ_ENGINE_CHANGES" >> $GITHUB_OUTPUT | ||
echo "safety=$SAFETY_CHANGES" >> $GITHUB_OUTPUT | ||
echo "transport=$TRANSPORT_CHANGES" >> $GITHUB_OUTPUT | ||
|
||
- name: Run auth tests | ||
if: steps.changes.outputs.auth == 'true' | ||
run: pytest -vv tests/unit/auth --cov=mcp_fuzzer.auth --cov-report=xml:coverage.auth.xml | ||
|
||
- name: Run CLI tests | ||
if: steps.changes.outputs.cli == 'true' | ||
run: pytest -vv tests/unit/cli --cov=mcp_fuzzer.cli --cov-report=xml:coverage.cli.xml | ||
|
||
- name: Run client tests | ||
if: steps.changes.outputs.client == 'true' | ||
run: pytest -vv tests/unit/client --cov=mcp_fuzzer.client --cov-report=xml:coverage.client.xml | ||
|
||
- name: Run fuzz engine tests | ||
if: steps.changes.outputs.fuzz_engine == 'true' | ||
run: pytest -vv tests/unit/fuzz_engine --cov=mcp_fuzzer.fuzz_engine --cov-report=xml:coverage.fuzz_engine.xml | ||
|
||
- name: Run safety system tests | ||
if: steps.changes.outputs.safety == 'true' | ||
run: pytest -vv tests/unit/safety_system --cov=mcp_fuzzer.safety_system --cov-report=xml:coverage.safety_system.xml | ||
|
||
- name: Run transport tests | ||
if: steps.changes.outputs.transport == 'true' | ||
run: pytest -vv tests/unit/transport --cov=mcp_fuzzer.transport --cov-report=xml:coverage.transport.xml | ||
|
||
- name: Run integration tests | ||
if: ${{ steps.changes.outputs.auth == 'true' || steps.changes.outputs.cli == 'true' || steps.changes.outputs.client == 'true' || steps.changes.outputs.fuzz_engine == 'true' || steps.changes.outputs.safety == 'true' || steps.changes.outputs.transport == 'true' }} | ||
run: | | ||
pytest -vv tests/integration --cov=mcp_fuzzer --cov-report=xml:coverage.integration.xml | ||
|
||
- name: Check for coverage files | ||
id: coverage_check | ||
run: | | ||
if ls coverage.*.xml 1> /dev/null 2>&1; then | ||
echo "has_coverage=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "has_coverage=false" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
- name: Check Codecov token | ||
id: codecov_token | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | ||
run: | | ||
if [ -n "$CODECOV_TOKEN" ]; then | ||
echo "has_token=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "has_token=false" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
- name: Upload coverage to Codecov | ||
if: ${{ (steps.changes.outputs.auth == 'true' || steps.changes.outputs.cli == 'true' || steps.changes.outputs.client == 'true' || steps.changes.outputs.fuzz_engine == 'true' || steps.changes.outputs.safety == 'true' || steps.changes.outputs.transport == 'true') && steps.coverage_check.outputs.has_coverage == 'true' && steps.codecov_token.outputs.has_token == 'true' }} | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: coverage.*.xml | ||
fail_ci_if_error: true |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -169,9 +169,8 @@ async def execute_batch( | |||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
async def _bounded_execute_and_track(op, args, kwargs): | ||||||||||||||||||||||||||||||||||||||||
# Acquire semaphore before execution and release after | ||||||||||||||||||||||||||||||||||||||||
async with self._semaphore: | ||||||||||||||||||||||||||||||||||||||||
return await self._execute_and_track(op, args, kwargs) | ||||||||||||||||||||||||||||||||||||||||
# Concurrency is enforced inside execute(); avoid double-acquire deadlock | ||||||||||||||||||||||||||||||||||||||||
return await self._execute_and_track(op, args, kwargs) | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# Create bounded tasks that respect the semaphore limit | ||||||||||||||||||||||||||||||||||||||||
tasks = [] | ||||||||||||||||||||||||||||||||||||||||
|
@@ -242,3 +241,12 @@ async def shutdown(self, timeout: float = 5.0) -> None: | |||||||||||||||||||||||||||||||||||||||
"Shutdown timed out with %d tasks still running", | ||||||||||||||||||||||||||||||||||||||||
len(self._running_tasks), | ||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||
# Proactively cancel outstanding tasks and wait for them to finish | ||||||||||||||||||||||||||||||||||||||||
for task in list(self._running_tasks): | ||||||||||||||||||||||||||||||||||||||||
task.cancel() | ||||||||||||||||||||||||||||||||||||||||
await asyncio.gather(*self._running_tasks, return_exceptions=True) | ||||||||||||||||||||||||||||||||||||||||
finally: | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+244
to
+248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Cancel-then-await can hang indefinitely; bound the second wait. If tasks ignore cancellation or are stuck in uninterruptible awaits, the unconditional gather() can block shutdown forever. Apply this diff to add a bounded “grace” wait and log if tasks remain: for task in list(self._running_tasks):
task.cancel()
- await asyncio.gather(*self._running_tasks, return_exceptions=True)
+ try:
+ await asyncio.wait_for(
+ asyncio.gather(*self._running_tasks, return_exceptions=True),
+ timeout=min(2.0, timeout),
+ )
+ except asyncio.TimeoutError:
+ self._logger.error(
+ "Forced shutdown still timed out; %d tasks may still be running",
+ sum(1 for t in self._running_tasks if not t.done()),
+ ) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
# Ensure the set is cleaned up | ||||||||||||||||||||||||||||||||||||||||
self._running_tasks = { | ||||||||||||||||||||||||||||||||||||||||
t for t in self._running_tasks if not t.cancelled() and not t.done() | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+249
to
+252
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rebinding _running_tasks breaks done callbacks; mutate in place instead. add_done_callback(self._running_tasks.discard) captures the old set object. Reassigning self._running_tasks creates a new set, so callbacks remove from the stale set, leaking entries in the current set. Apply this diff to preserve the set identity and safely remove completed/cancelled tasks: - # Ensure the set is cleaned up
- self._running_tasks = {
- t for t in self._running_tasks if not t.cancelled() and not t.done()
- }
+ # Ensure the set is cleaned up without rebinding (callbacks rely on identity)
+ to_remove = {t for t in tuple(self._running_tasks) if t.done() or t.cancelled()}
+ self._running_tasks.difference_update(to_remove) 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
Uh oh!
There was an error while loading. Please reload this page.