-
Notifications
You must be signed in to change notification settings - Fork 2
fix(#1): [$30 BOUNTY] [Python] Expand backend API contract edge-case #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,18 @@ | ||
| import pytest | ||
| from backend.api_contract import APIContract | ||
|
|
||
| @pytest.mark.parametrize("payload, expected_error", [ | ||
| ({"missing_field": "value"}, "Missing required field: 'required_field'"), | ||
| ({"required_field": None}, "Invalid value for field: 'required_field'") | ||
| ]) | ||
| def test_api_contract_negative_cases(payload, expected_error): | ||
| with pytest.raises(APIContract.Error) as exc_info: | ||
| APIContract.validate(payload) | ||
| assert str(exc_info.value) == expected_error | ||
|
|
||
| @pytest.mark.asyncio | ||
|
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Description: Check if pytest-asyncio is in project dependencies.
# Search for pytest-asyncio in common dependency files
rg -i 'pytest-asyncio' --type=toml --type=txt --type=py -g '*requirements*' -g '*pyproject.toml*' -g '*setup.py*' -g '*setup.cfg*'
# Also check in any poetry or pipenv files
fd -t f -e toml -e lock | xargs rg -l 'pytest-asyncio'Repository: jackjin1997/zeroeye Length of output: 47 🏁 Script executed: #!/bin/bash
# Step 1: Find and list all dependency-related files
echo "=== Finding dependency files ==="
fd -t f \( -name "pyproject.toml" -o -name "setup.py" -o -name "setup.cfg" -o -name "requirements*.txt" -o -name "poetry.lock" -o -name "Pipfile" \) | head -20
echo -e "\n=== Checking pyproject.toml if exists ==="
if [ -f "pyproject.toml" ]; then
cat pyproject.toml | grep -A 50 -i "dependencies\|pytest"
fi
echo -e "\n=== Checking setup.py if exists ==="
if [ -f "setup.py" ]; then
cat setup.py | grep -i "pytest"
fi
echo -e "\n=== Checking requirements files ==="
find . -maxdepth 2 -name "requirements*.txt" -exec echo "File: {}" \; -exec cat {} \;
echo -e "\n=== Direct search for pytest-asyncio ==="
rg "pytest-asyncio" . --max-count 5Repository: jackjin1997/zeroeye Length of output: 504 🏁 Script executed: #!/bin/bash
# List files in repository root to understand structure
echo "=== Repository root files ==="
git ls-files | head -30
echo -e "\n=== Looking for test configuration files ==="
find . -name "conftest.py" -o -name "pytest.ini" -o -name "tox.ini" | head -10
echo -e "\n=== Checking if test file exists ==="
cat tests/backend_api/test_api_contract.py | head -30
echo -e "\n=== Looking for any GitHub Actions workflows or CI files ==="
find . -name "*.yml" -o -name "*.yaml" | grep -E "(workflow|action|ci)" | head -10Repository: jackjin1997/zeroeye Length of output: 1886 🏁 Script executed: #!/bin/bash
echo "=== GitHub Actions workflow ==="
cat ".github/workflows/diagnostic-build-log.yml"
echo -e "\n=== Search all directories for requirements or dependency files ==="
find . -type f \( -name "requirements*.txt" -o -name "pyproject.toml" -o -name "setup.py" -o -name "setup.cfg" -o -name "Pipfile" -o -name "poetry.lock" \) 2>/dev/null
echo -e "\n=== Search for conftest.py files ==="
find . -name "conftest.py" 2>/dev/null
echo -e "\n=== Search for pytest.ini or pytest.cfg ==="
find . -name "pytest.ini" -o -name "pytest.cfg" -o -name ".pytest.ini" 2>/dev/null
echo -e "\n=== Check tests directory structure ==="
ls -la tests/ 2>/dev/null || echo "tests directory not found at root"
ls -la tests/backend_api/ 2>/dev/null || echo "tests/backend_api directory not found"Repository: jackjin1997/zeroeye Length of output: 2539 Add pytest-asyncio to project dependencies. The 🤖 Prompt for AI Agents |
||
| async def test_api_contract_async_wrapper(): | ||
| async def async_helper(): | ||
| return APIContract.validate({"required_field": "value"}) | ||
| result = await async_helper() | ||
| assert result == {"required_field": "value"} | ||
|
Comment on lines
+13
to
+18
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. The async test doesn't test meaningful async behavior. This test wraps a synchronous If
🔄 Alternative: Test error handling in async context `@pytest.mark.asyncio`
async def test_api_contract_async_wrapper():
- async def async_helper():
- return APIContract.validate({"required_field": "value"})
- result = await async_helper()
- assert result == {"required_field": "value"}
+ async def async_helper(payload):
+ try:
+ return APIContract.validate(payload)
+ except APIContract.Error as e:
+ raise # Ensure errors propagate correctly in async context
+
+ # Test successful validation
+ result = await async_helper({"required_field": "value"})
+ assert result == {"required_field": "value"}
+
+ # Test error propagation in async context
+ with pytest.raises(APIContract.Error):
+ await async_helper({"invalid": "payload"})🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: jackjin1997/zeroeye
Length of output: 45
🏁 Script executed:
Repository: jackjin1997/zeroeye
Length of output: 1393
🏁 Script executed:
Repository: jackjin1997/zeroeye
Length of output: 409
🏁 Script executed:
Repository: jackjin1997/zeroeye
Length of output: 147
🏁 Script executed:
Repository: jackjin1997/zeroeye
Length of output: 356
🏁 Script executed:
# Check the test file content to understand what it's trying to test cat tests/backend_api/test_api_contract.pyRepository: jackjin1997/zeroeye
Length of output: 784
🏁 Script executed:
Repository: jackjin1997/zeroeye
Length of output: 45
The import statement will fail:
backend.api_contractandAPIContractdo not exist.The backend directory is a Rust project with no Python modules. There is no
backend/__init__.py, nobackend/api_contract.py, and no Python API wrapper defined in the codebase. The test cannot run as written because the import will fail at runtime.🤖 Prompt for AI Agents