Skip to content

build: move to FOCA 0.21 - #369

Merged
uniqueg merged 5 commits into
devfrom
build/foca-0.21
Nov 5, 2026
Merged

uniqueg merged 5 commits into
devfrom
build/foca-0.21

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Closes #368

Summary

  • Pin foca>=0.21.0,<0.22, update uv.lock, and use the FOCA 0.21.0 base image by digest (the same as proTES PR 434).
  • Adapt 16 tests to FOCA's stricter request checks (FOCA #686): extra query parameters, invalid date-time and uri values, unpaired surrogates.
  • Document the stricter 400 responses in docs/api.md and docs/upgrading.md.
  • Drop format: uri and maxLength from serviceInfoUrl: otherwise FOCA returns and logs rejected addresses, which can hold secrets. The app's own checks handle them, with the same 2061 limit, and the test now covers all loggers and the response.

Invalid stored values

FOCA also checks the formats of responses, so one stored service with an invalid date-time or uri value makes GET /services return 500 for everyone. FOCA registers the format checks globally on the checker Connexion uses, so they can't be turned off per response; the only switch in the app is validate_responses for the whole API, which I left on.

refuse_old_format() already stops the app from starting on rc1 data, unless that data is migrated around it. As a safeguard, warn_invalid_formats() logs an error on startup naming such services, and docs/upgrading.md says what to do. It finds them but doesn't prevent the 500, and the list stays down until they are corrected or deleted.

Verification

Local, Python 3.13, chart dependencies built with helm dependency build deployment, checksum OK:

  • coverage run -m pytest: 2327 passed, 11 skipped, 100% coverage, including the chart tests.
  • ruff check, ruff format, mypy .: passed. mkdocs build --strict passed before the last two commits; CI covers it.

CI: see the checks of this PR.

Unrelated fixes

  • ci: give the test jobs 30 minutes: the mongomock entry takes about 19 minutes on dev and was cancelled at 93% by the 20-minute limit on this PR.

Declined review findings

  • POST /services still logs and returns a rejected url with whitespace, which may hold credentials: the field's format: uri comes from the GA4GH specification, so this is left in place and documented. The general fix belongs in FOCA.
  • Other POST /services fields can leak the same way through schema messages, e.g. maxLength: same reason.
  • App checks for surrogates and URLs that FOCA now pre-empts on the API path (_check_pending_update, for example) are kept as a second line, and because other paths use them.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Upgrade the registry to FOCA 0.21 and adapt validation, safeguards, documentation, and CI to its stricter API and response checks.

Bug Fixes:

  • Prevent rejected service-info addresses from being exposed in API responses or logs while preserving application-level validation.
  • Detect and report stored services with invalid URI or date-time values before FOCA response validation causes read failures.

Enhancements:

  • Upgrade the application to FOCA 0.21 with stricter request and response validation, including rejection of undeclared query parameters, invalid formats, and unpaired surrogates.
  • Preserve service URL length validation and document the updated API error behavior and migration considerations.

Build:

  • Upgrade the pinned FOCA dependency and container base image to version 0.21.0.

CI:

  • Increase test job timeout to accommodate the test suite.

Documentation:

  • Document FOCA 0.21 validation changes, potential invalid stored data, and required remediation steps.

Tests:

  • Update and extend API, logging, and stored-data validation coverage for FOCA 0.21 behavior.

Update the pin, lock and base image. Adapt tests and docs to FOCA's
stricter request checks. Drop the uri format of serviceInfoUrl, so that
rejected addresses, which can hold secrets, are neither logged nor
returned.

Closes #368

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v1.0.0-rc2 milestone Nov 5, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Moves the registry to FOCA 0.21.0, updating pinned runtime artifacts and adapting API behavior, tests, and documentation for stricter request and response validation. The change also prevents service-info validation errors from exposing sensitive addresses and warns operators about invalid stored service data that could make reads fail.

Sequence diagram for startup detection of invalid stored service data

sequenceDiagram
    participant App
    participant Registry
    participant Database
    participant Logger

    App->>Registry: warn_invalid_formats()
    Registry->>Database: find invalid URI and date-time fields
    Database-->>Registry: stored services
    alt invalid formats found
        Registry->>Logger: logger.error(service IDs)
    end
Loading

Sequence diagram for service-info address validation without leaking rejected values

sequenceDiagram
    participant Importer
    participant Validator
    participant Fetcher

    Importer->>Validator: service_url(address, schemes)
    alt address exceeds MAX_ADDRESS_LENGTH
        Validator-->>Importer: InvalidService
    else invalid scheme, query, fragment, or path
        Validator-->>Importer: InvalidService
    else valid service-info address
        Validator-->>Importer: service URL
        Importer->>Fetcher: fetch service URL
    end
Loading

File-Level Changes

Change Details Files
Upgrade the application and container runtime to FOCA 0.21.0 with locked dependency and deployment metadata updates.
  • Pin the Python dependency to the 0.21 release range.
  • Switch the FOCA base image to the 0.21.0 digest.
  • Refresh the lockfile and chart schema metadata.
pyproject.toml
uv.lock
Dockerfile
deployment/values.schema.json
docs/releases/1.0.0rc2.md
Adapt API validation and service import handling to FOCA 0.21's stricter request checks while preserving application-level safeguards.
  • Remove schema URI and length constraints from serviceInfoUrl to avoid exposing rejected values, then enforce the 2061-character limit in import logic.
  • Retain secondary application checks for URLs, strings, and service types after FOCA validation.
  • Update expected handling for extra query parameters, invalid date-time/URI values, and unpaired surrogate characters.
cloud_registry/api/additions.openapi.yaml
cloud_registry/ga4gh/registry/service_import.py
tests/test_app.py
tests/test_service_import.py
tests/test_service_types.py
tests/test_verification.py
Detect invalid stored service formats before FOCA response validation causes broad read failures.
  • Add startup diagnostics for stored invalid URI and date-time fields.
  • Register the diagnostic during application initialization.
  • Cover valid and invalid stored-service cases with tests.
cloud_registry/app.py
cloud_registry/ga4gh/registry/service.py
tests/ga4gh/registry/test_service.py
Document FOCA 0.21's externally visible validation and migration implications.
  • Document newly rejected query parameters, formats, and surrogate-containing JSON.
  • Explain that invalid stored values can make service reads return 500 and provide remediation guidance.
  • Update API timestamp behavior and release notes.
docs/api.md
docs/upgrading.md
docs/releases/1.0.0rc2.md

Possibly linked issues

  • Move to FOCA 0.21 #368: The PR implements the issue’s FOCA 0.21 dependency and image upgrade, test adaptations, and stricter-response documentation.

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

uniqueg and others added 2 commits November 5, 2026 14:40
FOCA checks formats of responses, so one such service makes
GET /services return 500. Name them on startup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check the length of serviceInfoUrl in the app, so that FOCA doesn't
quote rejected addresses. Cover the handlers behind FOCA's checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg marked this pull request as ready for review November 5, 2026 14:53

@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 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="cloud_registry/ga4gh/registry/service.py" line_range="767" />
<code_context>
+            UPDATED: True,
+        },
+    ):
+        organization = service.get("organization") or {}
+        uris = [
+            service.get("url"),
</code_context>
<issue_to_address>
**Worker fails to start**

When a stored service has a truthy non-object `organization` value, `warn_invalid_formats()` calls `.get()` on `organization`, raising `AttributeError` during `create_app()` and preventing the Gunicorn worker from starting.

Check that `organization` is an object before reading its URL, and mark the service invalid otherwise.
</issue_to_address>

### Comment 2
<location path="cloud_registry/ga4gh/registry/service.py" line_range="776" />
<code_context>
+        ]
+        dates = [service.get(field) for field in DATE_TIME_FIELDS]
+        if not all(is_uri(value) for value in uris if value is not None) or not all(
+            is_date_time(value) for value in dates if value is not None
+        ):
+            ids.append(f"'{service.get('id')}'")
</code_context>
<issue_to_address>
**Invalid services escape startup warning**

When a stored service has a non-string timestamp or an explicit null URI or timestamp field, `warn_invalid_formats()` skips explicit nulls and `is_date_time()` accepts non-strings, so invalid services are omitted from the startup warning; FOCA then rejects their responses and service reads return `500`.

Validate stored URIs and timestamps against the response schema, including explicit nulls and timestamp types, before deciding whether to name the service.
</issue_to_address>

Linked issues

#368 Move to FOCA 0.21 · 3 of 3 met

# Requirement Status Notes
1 Pin FOCA 0.21, update the lockfile, and use the 0.21.0 base image by digest. ✅ Met The dependency pin, lockfile, and Docker base image are updated.
2 Adapt tests for the stricter checks: extra query parameters, invalid date-time and URI values, and unpaired surrogates. ✅ Met Tests cover the changed validation cases and FOCA's error details.
3 Document the stricter 400 responses in the API documentation and upgrade notes. ✅ Met Both docs/api.md and docs/upgrading.md describe the stricter responses.

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and FOCA now includes some invalid URI values in 400 responses and logs, so a secret accidentally submitted in one of those fields could persist in logs even after the change is reverted. The service-info URL field is excluded from this validation, but other URI fields still have this exposure.

Blocking findings: cloud_registry/ga4gh/registry/service.py:767, cloud_registry/ga4gh/registry/service.py:776


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1d988ad) to head (a5b0110).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #369   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         3238      3259   +21     
=========================================
+ Hits          3238      3259   +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

uniqueg and others added 2 commits November 5, 2026 16:42
A non-object organization no longer stops the app from starting, and
null or non-string values are reported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The mongomock entry takes about 19 minutes on dev and hit the
20-minute limit at 93% on PR 369.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 8b69b3c into dev Nov 5, 2026
32 checks passed
@uniqueg
uniqueg deleted the build/foca-0.21 branch November 5, 2026 16:50
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.

Move to FOCA 0.21

1 participant