| name | debugging |
| description | Use when debugging test failures, runtime errors, or unexpected behavior in the GAC project. Covers pytest debugging, logging, and common patterns. |
| tags | ["debugging","troubleshooting","logs"] |
Debugging Workflows
When to Use
- Tests are failing and you need to understand why
- Runtime errors occur in CLI operation
- Provider responses are unexpected
- Need to trace code execution flow
Test Debugging
uv run -- pytest tests/test_cli.py -v
uv run -- pytest tests/test_cli.py -vv
uv run -- pytest tests/test_cli.py -s
uv run -- pytest tests/test_cli.py -x
uv run -- pytest tests/test_cli.py --pdb
uv run -- pytest tests/test_cli.py --tb=long
uv run -- pytest tests/test_cli.py --showlocals
Provider Test Debugging
uv run -- pytest tests/providers/test_openai.py::TestOpenAIProviderMocked::test_successful_api_call -vvv
uv run -- pytest tests/providers/test_openai.py -k "APIKey" -v
Note: The standard mocked test is test_successful_api_call (NOT test_successful_call).
CLI Debugging
gac --dry-run -v
gac --dry-run --message-only
gac --show-prompt --dry-run
GAC_LOG_LEVEL=DEBUG uv run python -m gac.cli --dry-run -v
uv run python -m gac.cli --log-level DEBUG --dry-run
Note: There is NO GAC_DEBUG env var. Use GAC_LOG_LEVEL=DEBUG or --log-level DEBUG.
Checking Configuration
uv run python -c "import os; print({k:v for k,v in os.environ.items() if k.startswith('GAC_')})"
uv run python -c "from gac.stats.store import STATS_FILE; print(STATS_FILE)"
uv run python -c "from gac.oauth.token_store import TOKEN_DIR; print(TOKEN_DIR)"
Stats Debugging (safe)
Always mock stats paths when debugging outside pytest:
from unittest.mock import patch
import tempfile
from pathlib import Path
with tempfile.TemporaryDirectory() as tmpdir:
with patch("gac.stats.store.STATS_FILE", Path(tmpdir) / "debug.json"):
from gac.stats import save_stats
save_stats({"model": "test"})
Using pdb
import pdb; pdb.set_trace()
if data.get("error"):
import pdb; pdb.set_trace()
Remove debug breakpoints before committing.
Logging in Code
Use logging, not print():
import logging
logger = logging.getLogger(__name__)
def parse_response(response: dict[str, Any]) -> str:
logger.debug("Received response keys: %s", list(response.keys()))
return response.get("message", {}).get("content", "")
Enable HTTP debugging for provider issues:
GAC_LOG_LEVEL=DEBUG uv run -- pytest tests/providers/test_openai.py -vv -s
Checklist
[ ] Using -v / -s / --pdb for test debugging?
[ ] Using GAC_LOG_LEVEL=DEBUG (not GAC_DEBUG)?
[ ] Mocking stats paths outside pytest?
[ ] Removing debug code before committing?
[ ] Provider test name is test_successful_api_call?