Skip to content

fix(plugins): read serviceId in discovery - #670

Merged
uniqueg merged 6 commits into
devfrom
fix/665-verifications-service-id
Nov 4, 2026
Merged

uniqueg merged 6 commits into
devfrom
fix/665-verifications-service-id

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #665

Cloud Registry 1.0.0rc2 renames service_id to serviceId in GET /verifications (elixir-cloud-aai/cloud-registry#352). FOCA skipped every item, so an app such as proTES ended up with no backends. Discovery now reads serviceId, and service_id for older registries. An invalid serviceId doesn't fall back to service_id, so a malformed item can't stand in for a verification.

I compared the rest of the discovery code with the OpenAPI spec and docs of Cloud Registry dev (d3e4fd7) and the rename table of #353 and #355. GET /verifications is the only renamed field that FOCA reads: GET /services (id, url, type, environment) is unchanged. Further changes:

  • API types: group and artifact now ignore surrounding whitespace as well as case, as the registry's service_key() does. Verified services with such a spelling were dropped without a log entry.
  • Docs: a verification covers neither version nor environment, as the registry keeps it when owners or maintainers change them (unless the service becomes pending). A code comment said otherwise.
  • Docs: registries that require login for reads can't be used, as FOCA reads without a token. They count as unreachable.

No release notes change: docs/releases/ has no draft for 0.21.0, as the notes are added in the release-prep PR.

Verification

Failing first: with the test fakes serving serviceId, 18 tests of tests/plugins/test_plugin_backends.py failed, with Skipped 1 verifications without service identifier.

Against real registries (own containers, own network, port 18665). Services were registered and verified through the API, with real tokens of a static test issuer; FOCA's RegistryCache then read them, with the unverified TES and the verified WES as decoys. Scripts: work/elixir-on-cloud/projects/foca-665-cr-check/ (run.sh).

Registry                     FOCA             Result
Cloud Registry dev d3e4fd7   origin/dev       none discovered, "Skipped 2 verifications"
Cloud Registry dev d3e4fd7   this branch      verified TES only
Cloud Registry 1.0.0rc1      this branch      verified TES only (`service_id`)
dev, login-for-reads patch   this branch      none, registry answered 401

Locally (Python 3.12):

  • pytest -m "not mongodb": 3231 passed, 2 skipped
  • coverage of foca/plugins/backends: 100%
  • ruff check, ruff format --check, mypy, ast-grep scan, mkdocs build --strict: passed

Not run locally: tests marked mongodb (they need the fixed port 12345, and other agents work in parallel), integration tests. CI runs them.

CI: all checks passed on the pushed commit, including the MongoDB and integration tests that did not run locally (CI passed).

Declined review findings

  • Revocations stop applying when GET /verifications succeeds and GET /services then fails: the last good list stays in use for up to max_stale. It is confirmed, medium, and predates this PR. It isn't a mismatch with the registry's API, and changing what a partly failed read does to the cache is a design change, so it doesn't belong here. It is reported to the maintainer separately, with the unpaginated GET /services against the 16 MiB response limit.
  • The commit trailer names the wrong model: not correct, it follows this session's attribution.
  • test_verified_version uses a payload that the registry can't produce: it still can between the two reads, and other registries may keep the verified type, so the check and its test stay.
  • A unit test for 401: HttpError handling is already tested, and the real 401 ran against the registry (table above).

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Update registry discovery to support current and legacy verification identifiers while aligning API type matching and registry behavior documentation with Cloud Registry.

Bug Fixes:

  • Support the Cloud Registry’s renamed serviceId verification field while retaining compatibility with older service_id responses and rejecting malformed identifiers safely.

Enhancements:

  • Match API type group and artifact values using case-insensitive, whitespace-tolerant comparisons consistent with Cloud Registry behavior.
  • Clarify registry verification semantics and document that registries requiring authenticated reads are treated as unreachable.

Documentation:

  • Update discovery documentation for verification identifiers, version and environment semantics, and unauthenticated registry reads.

Tests:

  • Update backend discovery tests for the new verification field and add coverage for legacy identifiers, malformed identifier fallback behavior, and whitespace-tolerant API type matching.

uniqueg and others added 3 commits November 4, 2026 05:06
Cloud Registry 1.0.0rc2 renames `service_id` to `serviceId` in
`GET /verifications`, so discovery skipped every item and apps ended up
without backends. Read `serviceId`, and keep accepting `service_id` for
older registries. An invalid `serviceId` is not replaced by `service_id`.

Also state in the docs that registries requiring login for reads can't
be used, as they are read without a token.

Closes #665

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cloud Registry ignores surrounding whitespace in the group and artifact
of service types, so services verified with such a spelling were dropped
without a trace. Compare them the same way.

Correct the comment on the verified version, as the registry lists the
current version in both documents, and state in the docs that a
verification covers neither version nor environment. Registries that
require login count as unreachable, not as empty.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A new version that makes a service pending removes its verification, and
`_is_api` now follows `_same` in ignoring surrounding whitespace too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Discovery now handles the Cloud Registry’s serviceId rename while retaining compatibility with pre-1.0.0rc2 registries, rejects invalid identifiers safely, and aligns API type matching and documentation with registry semantics.

Sequence diagram for compatible registry verification discovery

sequenceDiagram
    participant Registry
    participant RegistryCache
    participant Discovery
    participant BackendSelection

    RegistryCache->>Registry: GET /verifications
    Registry-->>RegistryCache: verification items
    RegistryCache->>Discovery: _verifications(document)
    Discovery->>Discovery: Read serviceId
    alt serviceId is absent
        Discovery->>Discovery: Read service_id
    end
    alt identifier is invalid
        Discovery-->>RegistryCache: Skip and log item
    else identifier is valid
        Discovery-->>RegistryCache: verified service map
        RegistryCache->>Registry: GET /services
        Registry-->>RegistryCache: current service records
        RegistryCache->>BackendSelection: select_services(verified, services)
        BackendSelection->>BackendSelection: _is_api(api_type, api)
        BackendSelection->>BackendSelection: _version(verified_type)
    end
Loading

File-Level Changes

Change Details Files
Support both Cloud Registry verification identifier formats, with strict precedence for the new field.
  • Read serviceId for current registries and fall back to service_id for older versions.
  • Reject malformed or non-string serviceId values instead of using a fallback identifier.
  • Update discovery fakes and add coverage for both formats and invalid combinations.
foca/plugins/backends/registry.py
tests/plugins/test_plugin_backends.py
Align API type matching and discovery documentation with Cloud Registry behavior.
  • Ignore surrounding whitespace and case when comparing API type group and artifact.
  • Clarify that verifications do not cover current version or environment.
  • Document that registries requiring authentication for reads are unreachable to FOCA.
foca/plugins/backends/registry.py
foca/plugins/backends/__init__.py
docs/plugins.md
tests/plugins/test_plugin_backends.py

Possibly linked issues


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

@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #670   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           56        56           
  Lines         7230      7231    +1     
=========================================
+ Hits          7230      7231    +1     
Flag Coverage Δ
test_unit 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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
uniqueg marked this pull request as ready for review November 4, 2026 04:18

@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

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

## Individual Comments

### Comment 1
<location path="foca/plugins/backends/registry.py" line_range="144" />
<code_context>
+            else None
+        )
+        if not isinstance(service_id, str):
             skipped += 1
             continue
-        verified[item["service_id"]] = (item.get("url"), item.get("type"))
</code_context>
<issue_to_address>
**Blank identifiers hide malformed verifications**

When a registry returns an empty `serviceId` (including alongside a valid legacy `service_id`), `_verifications` accepts an empty string as a service identifier and stores the verification under `""`; ordinary services then fail the membership check in `select_services`, which logs only at debug level, so the malformed registry entry can leave a backend undiscovered without a warning.

Treat empty identifiers as invalid and include them in the skipped-verifications warning.
</issue_to_address>

Linked issues

#665 fix: read serviceId in backend discovery · 3 of 3 met

# Requirement Status Notes
1 Read serviceId and keep accepting service_id for registries before rc2. ✅ Met _verifications reads serviceId first and uses service_id only when that key is absent.
2 Check the rest of discovery against the registry's current API. ✅ Met The change also matches API-type group and artifact values with surrounding whitespace ignored; discovery continues to use the existing GET /services fields.
3 Update the docs. ✅ Met The docs describe both verification identifier spellings and clarify verification coverage and the behavior of registries requiring login.

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and the identifier and API-type matching changes determine which registry-listed services become request candidates. If they admit the wrong service, requests could be sent to an unintended endpoint; reverting stops future routing but cannot undo requests already sent.

Blocking findings: foca/plugins/backends/registry.py:144


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

Comment thread foca/plugins/backends/registry.py Resolved
uniqueg and others added 3 commits November 4, 2026 05:30
An empty identifier matches no service, so the item was dropped without
the warning that malformed items get.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit e5b2fb1 into dev Nov 4, 2026
56 checks passed
@uniqueg
uniqueg deleted the fix/665-verifications-service-id branch November 4, 2026 04:53
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.

fix: read serviceId in backend discovery

1 participant