GHA-257 Jira fixture infrastructure — reusable setup/teardown scripts#136
GHA-257 Jira fixture infrastructure — reusable setup/teardown scripts#136nils-werner-sonarsource wants to merge 2 commits intomasterfrom
Conversation
Tests for jira_client.py, setup.py, and cleanup.py covering: - Jira connection with credential validation - Version and issue creation with correct fields - Idempotent cleanup that handles missing resources - JSON output format from setup - State file and inline argument parsing for cleanup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- jira_client.py: shared connection helper extracted from existing actions - setup.py: creates test version + 3 issues (Bug, Feature, Maintenance) linked via fixVersion, outputs JSON state for cleanup - cleanup.py: idempotent deletion of issues and versions, supports inline args or JSON state file from setup.py - README.md: usage guide with GitHub Actions workflow example - test-jira-fixtures.yml: CI workflow with unit tests + sandbox integration - Remove __init__.py to avoid shadowing the jira package Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
SummaryThis PR introduces reusable Jira fixture infrastructure for integration testing. It adds three Python scripts ( What reviewers should knowStart reading here:
Key design decisions to note:
Watch for:
|
|
| if args.state_file: | ||
| with open(args.state_file) as f: | ||
| state = json.load(f) | ||
| version_id = state.get('version_id', version_id) | ||
| issue_keys = state.get('issue_keys', issue_keys) |
There was a problem hiding this comment.
Unhandled FileNotFoundError breaks cleanup when setup.py fails mid-run.
If setup.py creates the Jira version but then fails during issue creation (API error, rate limit, etc.), set -euo pipefail in the workflow aborts the step before echo "$STATE" > /tmp/jira-fixtures.json executes. The state file is never written.
The cleanup step still runs (if: always()) and unconditionally passes --state-file /tmp/jira-fixtures.json. Line 60's open() raises FileNotFoundError — unhandled — so cleanup itself exits non-zero. The orphaned version and any partially-created issues are never cleaned up.
Fix here: catch FileNotFoundError and log a warning instead of crashing:
if args.state_file:
try:
with open(args.state_file) as f:
state = json.load(f)
version_id = state.get('version_id', version_id)
issue_keys = state.get('issue_keys', issue_keys)
except FileNotFoundError:
eprint(f"Warning: State file {args.state_file} not found. Nothing to clean up from state.")Note that this alone doesn't recover the orphaned version — setup.py would need to write partial state to a file as resources are created (rather than only emitting JSON to stdout at success) for a complete fix.
- Mark as noise
| python test-fixtures/jira/cleanup.py \ | ||
| --jira-url "https://sonarsource-sandbox-608.atlassian.net/" \ | ||
| --state-file /tmp/jira-fixtures.json |
There was a problem hiding this comment.
Cleanup unconditionally passes --state-file /tmp/jira-fixtures.json. When setup.py fails before writing that file, cleanup crashes with FileNotFoundError (see companion comment in cleanup.py). Guard the invocation:
if [ -f /tmp/jira-fixtures.json ]; then
python test-fixtures/jira/cleanup.py \
--jira-url "[link removed: sonarsource-sandbox-608.atlassian.net]" \
--state-file /tmp/jira-fixtures.json
else
echo "State file not found — setup failed before writing fixtures, nothing to clean up."
fiThis is the minimal patch; fixing cleanup.py to handle the missing file is still the right defence-in-depth change.
- Mark as noise
| """Configuration constants for Jira test fixtures.""" | ||
|
|
||
| SANDBOX_URL = "https://sonarsource-sandbox-608.atlassian.net/" | ||
| PROD_URL = "https://sonarsource.atlassian.net/" |
There was a problem hiding this comment.
PROD_URL is never imported anywhere — confirmed by grep. Neither is SANDBOX_URL; the actual sandbox URL is hardcoded in the workflow and README instead. Remove both unused URL constants. Leaving PROD_URL in a test-fixture config file creates risk: a future contributor copying a usage pattern could accidentally point cleanup at production Jira.
- Mark as noise



Summary
test-fixtures/jira/setup.pycreates a test version + 3 issues (Bug, Feature, Maintenance) linked via fixVersiontest-fixtures/jira/cleanup.pyidempotently deletes all created resourcestest-fixtures/jira/jira_client.pyextracts the shared Jira connection pattern used by all 6 Jira actionsTest plan
🤖 Generated with Claude Code