Skip to content

GHA-257 Jira fixture infrastructure — reusable setup/teardown scripts#136

Merged
nils-werner-sonarsource merged 11 commits intomasterfrom
nw/GHA-257
Apr 24, 2026
Merged

GHA-257 Jira fixture infrastructure — reusable setup/teardown scripts#136
nils-werner-sonarsource merged 11 commits intomasterfrom
nw/GHA-257

Conversation

@nils-werner-sonarsource
Copy link
Copy Markdown
Contributor

@nils-werner-sonarsource nils-werner-sonarsource commented Apr 19, 2026

Summary

  • Add reusable Python scripts for creating and cleaning up Jira sandbox state for integration tests
  • test-fixtures/jira/setup.py creates a test version + 3 issues (Bug, Feature, Maintenance) linked via fixVersion
  • test-fixtures/jira/cleanup.py idempotently deletes all created resources
  • test-fixtures/jira/jira_client.py extracts the shared Jira connection pattern used by all 6 Jira actions
  • CI workflow runs unit tests and a sandbox integration test with vault credentials

Test plan

  • 24 unit tests pass locally (96% coverage)
  • CI unit tests pass on ubuntu-latest with Python 3.10
  • CI integration test creates fixtures in Jira sandbox and cleans up

🤖 Generated with Claude Code

@hashicorp-vault-sonar-prod
Copy link
Copy Markdown

hashicorp-vault-sonar-prod Bot commented Apr 19, 2026

GHA-257

@sonar-review-alpha
Copy link
Copy Markdown

sonar-review-alpha Bot commented Apr 19, 2026

Summary

This PR adds reusable Python infrastructure for creating and cleaning up Jira test fixtures. The implementation consists of three layers:

Setup & Cleanup Scripts (setup.py, cleanup.py): Standalone executables that manage fixture lifecycle. setup.py creates a versioned test state (format: 99.<run_id>) with 3 issues, outputs JSON to both stdout and a state file (default /tmp/jira-fixtures.json). cleanup.py idempotently deletes resources by ID or from a state file, with graceful error handling for already-deleted resources.

Shared Infrastructure (jira_client.py, config.py): Extracted Jira connection pattern and configuration constants to support both scripts and future actions.

Testing & CI (24 unit tests, new workflow): Comprehensive mocking-based unit test suite (96% coverage) with a GitHub Actions workflow that runs tests on every change and validates fixtures against a sandbox Jira instance.

What reviewers should know

Start here: setup.py and cleanup.py are the entry points. Both are straightforward command-line tools designed for CI workflows. The helper functions are well-factored (create_test_version, delete_issues, etc.) and easy to follow.

Design details worth noting:

  • State file is written incrementally — once after version creation (before issues), then after each issue. This allows cleanup to recover partial state if issue creation fails midway.
  • Cleanup is intentionally lenient: any JIRAError or unexpected exception during deletion is logged as a warning and doesn't stop processing. This ensures cleanup never blocks a workflow.
  • --state-file flag on setup.py (review comment: uses default /tmp/jira-fixtures.json if not specified) provides flexibility for different CI contexts.

Test coverage is solid: Unit tests mock the Jira client and focus on argument parsing, state management, and error resilience. No external Jira calls in tests. The integration test in the workflow is marked continue-on-error: true with a TODO (GHA-258) — it will fail until sandbox permissions are configured, but won't block the workflow.

Workflow details: CI runs unit tests on every change, integration test validates real fixture creation/teardown in sandbox. Vault integration provides credentials. The workflow properly cleans up even on partial failure via if: always() guard.

Watch for: The integration test won't pass yet (permissions), but that's expected and documented with the TODO. Unit tests should pass consistently.


  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

sonar-review-alpha[bot]

This comment was marked as resolved.

sonar-review-alpha[bot]

This comment was marked as resolved.

sonar-review-alpha[bot]

This comment was marked as resolved.

sonar-review-alpha[bot]

This comment was marked as resolved.

nils-werner-sonarsource and others added 6 commits April 21, 2026 10:48
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>
…anup

- Add `continue-on-error: true` to the integration test job since the
  'Jira Tech User GitHub' permissions on SONARIAC in the sandbox are
  not yet configured
- Guard cleanup step with a file-existence check so it doesn't crash
  when setup failed before writing the state file
- Make cleanup.py resilient to missing/invalid state file (FileNotFoundError,
  JSONDecodeError) instead of crashing
- Add unit test covering the missing-state-file case
- Remove unused SANDBOX_URL/PROD_URL constants from config.py

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nfigured

The 'Jira Tech User GitHub' account does not yet have Administrator access
on the SONARIAC project in the sandbox, so the integration test always fails
on PRs. Restrict it to workflow_dispatch and branch-* pushes so it doesn't
appear as a failing check on pull requests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tegration test on PRs

- setup.py: write partial state file (version only, empty issue_keys)
  immediately after version creation so cleanup can remove the version
  even when issue creation fails mid-run
- setup.py: final state written again after all issues are created
- workflow: pin vault-action-wrapper to SHA c154b4a (v3.4.0)
- workflow: restore integration test on PRs with continue-on-error: true
  (was accidentally excluded; now visible but non-blocking until sandbox
  permissions for SONARIAC are configured)
- tests: patch write_state in main tests; add test verifying partial state
  is written before issue creation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The GHA project is the correct sandbox project for this repository.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sonar-review-alpha[bot]

This comment was marked as resolved.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sonar-review-alpha[bot]

This comment was marked as resolved.

@sonarqube-agent
Copy link
Copy Markdown

sonarqube-agent Bot commented Apr 21, 2026

SonarQube Remediation Agent

SonarQube found 1 issue in this PR that the agent can fix for you. Est. time saved: ~5 min

1 issue found
  • 🟡 Remove the unused local variable "issues".setup.py:75
  • Run Remediation Agent
    Select the checkbox above to enable this action.

View Project in SonarCloud

💡 Got issues in your backlog? Let the agent fix them for you.

sonar-review-alpha[bot]

This comment was marked as resolved.

sonar-review-alpha[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@jonas-wielage-sonarsource jonas-wielage-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, please have a look at my comments before merging.

Comment thread test-fixtures/jira/cleanup.py
Comment thread test-fixtures/jira/jira_client.py
Comment thread test-fixtures/jira/jira_client.py
Comment thread test-fixtures/jira/test_cleanup.py
Comment thread .github/workflows/test-jira-fixtures.yml
Comment thread .github/workflows/test-jira-fixtures.yml Outdated
Comment thread .github/workflows/test-jira-fixtures.yml Outdated
Comment thread .github/workflows/test-jira-fixtures.yml
Copy link
Copy Markdown
Contributor

@jonas-wielage-sonarsource jonas-wielage-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already approved, I don't know why I need to do it again. Maybe related to the incident.

…x, coverage upload

- Add --state-file argument to setup.py (parity with cleanup.py, configurable path)
- Rename STATE_FILE to STATE_FILE_DEFAULT; write_state now takes path as argument
- Fix README example: remove shell redirection that overwrote the state file written by setup.py
- Update README cleanup example to guard on vault step success and state file existence
- Change ubuntu-latest runners to github-ubuntu-latest-s
- Add coverage XML report upload artifact in unit-tests job
- Add GHA-258 TODO comment on continue-on-error so it's tracked once sandbox permissions are granted
- Add test for --state-file argument and TestWriteState class using tempfile

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 23, 2026

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean follow-up commit that addresses all the critical bugs raised in the first review. The incremental state-writing approach is well-implemented and the tests verify it correctly.

Security hotspot tempfile.NamedTemporaryFile at test_setup.py:239 is Safe — Python's tempfile creates files with restricted permissions (0600), and the test cleans up via os.unlink in a finally block.

SonarQube Cloud status: The quality gate is failing — 1 new code issue needs to be resolved and the security hotspot needs to be reviewed in SonarQube Cloud. See the reviewer guide above for details. The code smell is almost certainly the # TODO GHA-258: comment at line 53 of the workflow — this is deliberate and tracked. Dismissing it in SonarQube Cloud and marking the hotspot as reviewed should clear the gate.

🗣️ Give feedback

@nils-werner-sonarsource nils-werner-sonarsource enabled auto-merge (squash) April 24, 2026 07:05
@nils-werner-sonarsource nils-werner-sonarsource merged commit 52b4b7c into master Apr 24, 2026
40 checks passed
@nils-werner-sonarsource nils-werner-sonarsource deleted the nw/GHA-257 branch April 24, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants