Skip to content

Migrate tests to testcontainers and add CI workflows - #15

Merged
joao-pinheiro merged 1 commit into
masterfrom
development
Jun 2, 2026
Merged

joao-pinheiro merged 1 commit into
masterfrom
development

Conversation

@joao-pinheiro

@joao-pinheiro joao-pinheiro commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Replace tox-docker with testcontainers: PostgreSQL and ClickHouse containers are now managed from tests/conftest.py (session-scoped), so the suite runs via plain pytest with no env-var wiring. Drop the [docker:*] sections from tox.ini and swap tox-docker for testcontainers[postgres] in requirements-dev.txt.

Add a CI workflow (test matrix py3.10-3.14, lint, build, security, ci-success gate) replacing run-tests.yml, and rework sbom.yml to generate/scan/sign CycloneDX + SPDX SBOMs. Update README, CHANGELOG, and CLAUDE.md accordingly.

Summary by Sourcery

Migrate database integration tests to use session-scoped testcontainers and introduce a comprehensive GitHub Actions CI pipeline with enhanced SBOM generation, scanning, and signing.

New Features:

  • Add a GitHub Actions CI workflow covering testing across Python 3.10–3.14, linting, package builds, and security scanning with a ci-success gate.
  • Extend the SBOM workflow to generate both CycloneDX and SPDX SBOMs, scan them for vulnerabilities, sign them with Cosign, and upload signed artifacts to releases with optional Dependency-Track submission.

Enhancements:

  • Replace tox-docker–managed PostgreSQL and ClickHouse containers with session-scoped testcontainers fixtures in the test suite, allowing direct pytest runs without environment-variable wiring.

CI:

  • Add a multi-job CI workflow (test matrix, lint, build, security, and aggregate success job) for pushes and pull requests.
  • Rework the SBOM workflow trigger to run on published releases with appropriate permissions and artifact uploads.

Documentation:

  • Update README and CLAUDE developer guide with new test-running instructions based on testcontainers instead of tox-docker.

Tests:

  • Reconfigure PostgreSQL and ClickHouse test settings to derive connection parameters from testcontainers instead of environment variables and rely on automatic container lifecycle management.

Replace tox-docker with testcontainers: PostgreSQL and ClickHouse
containers are now managed from tests/conftest.py (session-scoped),
so the suite runs via plain pytest with no env-var wiring. Drop the
[docker:*] sections from tox.ini and swap tox-docker for
testcontainers[postgres] in requirements-dev.txt.

Add a CI workflow (test matrix py3.10-3.14, lint, build, security,
ci-success gate) replacing run-tests.yml, and rework sbom.yml to
generate/scan/sign CycloneDX + SPDX SBOMs. Update README, CHANGELOG,
and CLAUDE.md accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Replaces tox-docker–managed database containers with testcontainers-based pytest fixtures, introduces a new GitHub Actions CI pipeline (tests, lint, build, security, ci-success gate), and expands the SBOM workflow to generate, scan, sign, and publish CycloneDX/SPDX SBOMs while updating docs and changelog accordingly.

Sequence diagram for updated SBOM generation and scanning workflow

sequenceDiagram
  participant GA as GitHubActions_runner
  participant CycloneDX as cyclonedx-py
  participant Syft as syft
  participant Grype as grype
  participant Cosign as cosign
  participant DTrack as DependencyTrack
  participant Release as GitHubRelease

  GA->>CycloneDX: cyclonedx-py environment -o sbom-cyclonedx.json
  GA->>DTrack: curl POST /api/v1/bom (sbom-cyclonedx.json)
  GA->>Syft: syft . -o spdx-json > sbom-spdx.json
  GA->>Grype: grype sbom:sbom-cyclonedx.json --fail-on high
  GA->>Grype: grype sbom:sbom-spdx.json --fail-on high
  GA->>Cosign: cosign sign-blob sbom-cyclonedx.json
  GA->>Cosign: cosign sign-blob sbom-spdx.json
  GA->>Release: softprops/action-gh-release (upload SBOM files)
Loading

File-Level Changes

Change Details Files
Move PostgreSQL and ClickHouse test infrastructure from tox-docker/env-vars to session-scoped testcontainers fixtures so tests run under plain pytest.
  • Add reusable constants and session-scoped pg_container and ch_container fixtures using PostgresContainer and ClickHouseContainer
  • Wire pg_settings and ch_settings fixtures to container host/port and static credentials instead of environment variables
  • Simplify ch_conn fixture to always construct ClickHouseConnection from ch_settings and remove skip-on-failure logic
  • Remove docker-based testenv configuration and container definitions from tox.ini and rely on pytest + testcontainers for integration tests
  • Update README and CLAUDE usage docs to describe running tests with pytest and testcontainers without manual Docker env-var wiring
tests/conftest.py
tox.ini
README.md
CLAUDE.md
Replace legacy run-tests workflow with a full GitHub Actions CI pipeline covering test matrix, linting, build, security scanning, and a ci-success aggregation gate.
  • Add ci.yml workflow with matrix tests for Python 3.10–3.14 using pytest + coverage, lint job (flake8 and advisory black), build job (sdist + wheel), and security job (pip-audit and bandit)
  • Add ci-success job that depends on test, lint, build, and security jobs and fails if any upstream job failed or was cancelled
  • Remove obsolete run-tests.yml workflow
.github/workflows/ci.yml
.github/workflows/run-tests.yml
Expand SBOM generation to produce CycloneDX and SPDX artifacts, scan them for vulnerabilities, sign them, and publish them on releases with optional Dependency-Track upload.
  • Retarget sbom workflow trigger to published releases and add top-level permissions for contents and id-token
  • Install project + cyclonedx-bom, generate CycloneDX SBOM via cyclonedx-py, and optionally upload it to Dependency-Track using DTRACK_API_KEY
  • Install Syft and Grype to generate an SPDX SBOM and run vulnerability scans on both SBOM formats, failing on high-severity issues
  • Install Cosign and sign both SBOM artifacts, then upload SBOMs and signatures as release assets via action-gh-release
.github/workflows/sbom.yml
Document release 2.2.3 changes, including security fixes, dependency bumps, testcontainer-based testing, and CI/SBOM updates.
  • Add 2.2.3 section describing SQL injection fixes in JSON path handling and DTO codegen escaping/identifier validation
  • Note dependency upgrades for core packages and dev tooling
  • Describe migration from tox-docker to testcontainers and summarize new CI and SBOM workflows
CHANGELOG.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@joao-pinheiro
joao-pinheiro merged commit 67945b0 into master Jun 2, 2026
19 checks passed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The workflows reference actions/checkout@v6 and actions/setup-python@v6, but the latest published majors are @v4 and @v5 respectively; using non-existent major versions will cause the workflows to fail, so these should be pinned to existing majors.
  • In sbom.yml, generating the SBOM with cyclonedx-py environment after pip install . cyclonedx-bom will include tooling like cyclonedx-bom itself in the SBOM; if the intent is to describe just this project’s artifacts and dependencies, consider switching to a project-based invocation (or equivalent) that scopes to the package rather than the whole environment.
  • The SBOM workflow installs Syft and Grype via curl | sh on every run, which can be slow and brittle; using the official GitHub Actions (or caching the binaries) would make the job faster and more maintainable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The workflows reference `actions/checkout@v6` and `actions/setup-python@v6`, but the latest published majors are `@v4` and `@v5` respectively; using non-existent major versions will cause the workflows to fail, so these should be pinned to existing majors.
- In `sbom.yml`, generating the SBOM with `cyclonedx-py environment` after `pip install . cyclonedx-bom` will include tooling like `cyclonedx-bom` itself in the SBOM; if the intent is to describe just this project’s artifacts and dependencies, consider switching to a `project`-based invocation (or equivalent) that scopes to the package rather than the whole environment.
- The SBOM workflow installs Syft and Grype via `curl | sh` on every run, which can be slow and brittle; using the official GitHub Actions (or caching the binaries) would make the job faster and more maintainable.

## Individual Comments

### Comment 1
<location path=".github/workflows/sbom.yml" line_range="48-52" />
<code_context>
+            -F "projectVersion=${PROJECT_VERSION}" \
+            -F "bom=@sbom-cyclonedx.json"
+
+      - name: Install Syft
+        run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
+
+      - name: Install Grype
+        run: curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
+
+      - name: Install Cosign
</code_context>
<issue_to_address>
**🚨 issue (security):** Installing Syft/Grype via `curl | sh` without pinning versions or verifying integrity is a security and stability risk.

Both tools are installed via `curl ... | sh` from the `main` branch, which both breaks reproducibility and runs unauthenticated remote code. Please pin to a specific release (e.g., a tagged install script or versioned binary) and/or verify checksums before execution to reduce these risks.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +48 to +52
- name: Install Syft
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin

- name: Install Grype
run: curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚨 issue (security): Installing Syft/Grype via curl | sh without pinning versions or verifying integrity is a security and stability risk.

Both tools are installed via curl ... | sh from the main branch, which both breaks reproducibility and runs unauthenticated remote code. Please pin to a specific release (e.g., a tagged install script or versioned binary) and/or verify checksums before execution to reduce these risks.

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.

1 participant