Skip to content

fix: address v0.21.0 pre-release findings - #694

Merged
uniqueg merged 8 commits into
devfrom
fix/021-prerelease-review
Nov 4, 2026
Merged

uniqueg merged 8 commits into
devfrom
fix/021-prerelease-review

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Closes #693

Summary

Fixes findings of the v0.21.0 pre-release review.

  • Migration guide: intro with the themes; unknown filters and handlers in log stop the app; the log of invalid responses; is_admin() with the required matcher prefix and resources without owners; one stored document fails a whole list, also for uri values; the foca-plugins cap, with the order FOCA tag, foca-plugins with <0.22 tested against 0.21, then proTES; foca-common 0.5.0 being unreleased, with apps free to stay on 0.4.0, plus PORT and the duplicates of protes.extraEnv; the audit claim narrowed to what it covers; the heading spacing.
  • Integration test: test_request_id_header checks the response header and a client's value through Gunicorn under both trust_incoming settings. The gateway example runs a second app (app-no-trust, port 8082, overlay no-trust.yaml) and sets true explicitly in its config, so the test doesn't depend on the default.
  • PORT docs: foca/gunicorn_config.py, docs/deployment.md and the guide's "App charts" now agree with the chart.
  • uv: image-constraints and test-lowest use one workflow-level UV_VERSION, 0.13.4, which test-lowest already used. The composite action of the chart install keeps its own pin, also 0.13.4, as release-chart.yml uses it too; a comment links the two.
  • reject_invalid_tokens: startup warns, once per function and specification, of functions on operations with optional authentication that the option doesn't reach.
  • CLI: docs/cli.md states that apps whose factory returns the Connexion app can't be targeted, and that the factory's own work runs before foca exits with 2.
  • Release workflow: only a comment changes, so that it also names the image requirements.

Not in this PR, left for the maintainer: the default of trust_incoming and docs/configuration/server.md:86-95, so the guide doesn't name that option yet; release prep; the dry run; #528; #625 and PR 691. The release checklist also doesn't get the foca-plugins step.

Verification

Locally on Python 3.12 with MongoDB 7.0.34:

  • coverage run -m pytest: 4244 passed, 3 skipped, 100% coverage. Run before the last review round; after it, tests/security/test_optional_tokens.py and tests/examples/test_gateway.py passed (48).
  • ruff check, ruff format --check, mypy, ast-grep scan, semgrep scan --config .semgrep --error, mkdocs build --strict: all clean.
  • pre-commit run --files <15 changed files>: passed.
  • tests/integration_gateway_tests.py against docker compose of the gateway example: 8 passed, before the last round, which tightened the test's assertions on generated identifiers. CI runs the final version.
  • scripts/compile-image-requirements.sh --check with uv 0.13.4: passed.
  • actionlint on ci.yml and release.yml: clean.

Not run locally: chart tests and chart install (no usable Helm), the petstore integration test, other Python versions, MongoDB 8.0, the release workflow.

CI on 816d968: all 29 checks passed, including the gateway integration tests with the final test on Python 3.13 and 3.15; Push image, Publish image and Trivy reported as skipped.

CI on db3ad81, the merged head: all 30 checks passed; the same three skipped.

Unrelated fixes

  • tests/security/test_auth.py: two assertions on caplog.text failed at random on debug records of PyMongo's background threads (one CI run on Python 3.12). They now look at FOCA's records only.

Declined review findings

  • Chart changes not on dev: wrong. charts/foca-common/templates/_deployment.tpl on dev sets PORT, and _helpers.tpl has foca-common.extraEnv.
  • - {None} fails mypy: mypy passed; the code was rewritten anyway when x-tokenInfoFunc was added.
  • Tests for security_schemes=None and unknown schemes: these aren't separate branches for coverage, and the existing _validates_optional_token has the same defensive shape.
  • One place for the uv version across the action and the workflow: the action is also used by release-chart.yml, where ci.yml's variable doesn't exist; changing that workflow is out of scope. The comment states the link.
  • Warning for BEARERINFO_FUNC: it's in the environment, not the specification; the docs say it gets no warning.
  • One warning per process rather than per specification: the docs and docstring state the scope instead.

Open questions

None.

🤖 Generated with Claude Code

uniqueg and others added 6 commits November 4, 2026 14:53
`reject_invalid_tokens` only applies to schemes naming FOCA's
`validate_token`, so functions wrapping it silently get no effect. Warn
at startup, once per function, for operations with optional
authentication.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The job is part of the gate, so a new uv could fail unrelated pull
requests. It now uses the version of `test-lowest` (0.13.4), from a
workflow-level variable; the requirements check passes with it. The
composite action of the chart install keeps its own pin, as it's also
used outside this workflow.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run the gateway example a second time with `trust_incoming: false`,
and test the response header and a client's value through Gunicorn
under both settings. Both are set explicitly, so that the test doesn't
depend on the default.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add fatal `log` sections, the log of invalid responses, `is_admin()`
and resources without owners, stored documents failing lists, the
foca-plugins cap and the chart, with `PORT` and duplicates of
`extraEnv`. Narrow the claim on the audit log and list the themes.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The chart sets `PORT` from foca-common 0.5.0. `foca` can't target apps
whose factory returns the Connexion app, and what such a factory does
runs before the command exits with 2. The comments on the release's
assets now also name the image requirements.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The warning now also covers `x-tokenInfoFunc`, and its remedy holds for
OAuth 2.0 schemes. In the guide, separate the changed log texts, narrow
the heading of the fatal `log` checks, and list what the library's
checks mean for charts with their own `extraEnv`. The integration test
checks the form of generated identifiers.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.21.0 milestone Nov 4, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR addresses v0.21.0 pre-release findings by documenting migration-impacting behavior, adding optional-token diagnostics and gateway request-ID coverage, aligning deployment/CI documentation and uv configuration, and clarifying release workflow expectations.

Sequence diagram for optional-token validator warnings

sequenceDiagram
    participant App as Application startup
    participant Resolver as InvalidTokenResolver
    participant Operation as Connexion operation
    participant Logger as foca.security.auth logger

    App->>Resolver: resolve(operation)
    Resolver->>Operation: _validates_optional_token(operation)
    alt Optional token validation is not handled by FOCA
        Resolver->>Operation: _other_token_validators(operation)
        Operation-->>Resolver: validator function names
        Resolver->>Logger: warning(function)
    else FOCA handles optional bearer validation
        Resolver-->>App: Resolution with _reject_invalid_token
    end
Loading

File-Level Changes

Change Details Files
Expanded the 0.21.0 migration guide to document configuration, validation, authentication, plugin, chart, audit-log, and invalid-response compatibility changes.
  • Added migration themes and actionable upgrade notes.
  • Documented strict logging configuration failures, stricter collection/URI validation, is_admin() behavior, plugin release ordering, chart environment changes, audit scope, and invalid-response logging.
docs/migration-0.21.md
Added explicit diagnostics for optional authentication validators that reject_invalid_tokens cannot wrap.
  • Detects alternate token and bearer validation functions on optionally authenticated operations.
  • Emits one warning per function and API-specification resolver while preserving existing wrapping behavior.
  • Added coverage for warning, deduplication, disabled-option, and non-applicable cases.
foca/security/auth.py
docs/authentication.md
tests/security/test_optional_tokens.py
Strengthened gateway request-ID integration coverage across trusted and untrusted configurations.
  • Runs a second gateway app with trust_incoming disabled.
  • Checks response identifiers, client-provided IDs, invalid-length replacement, format, and uniqueness through Gunicorn.
  • Updates readiness checks and local integration instructions.
examples/gateway/config.yaml
examples/gateway/docker-compose.yaml
examples/gateway/no-trust.yaml
examples/gateway/README.md
tests/integration_gateway_tests.py
docs/contributing/index.md
.github/workflows/ci.yml
Aligned deployment and chart documentation with PORT behavior and clarified CLI factory limitations.
  • Documents that foca-common 0.5.0 sets PORT to the chart service port.
  • Explains why CLI targeting cannot safely handle factories returning only a Connexion app and documents side effects before exit.
foca/gunicorn_config.py
docs/deployment.md
docs/cli.md
Centralized the uv version used by CI's image-constraint and lowest-dependency jobs.
  • Introduced a workflow-level UV_VERSION set to 0.13.4.
  • Applied it to uv setup and documented coordination with the chart-install action pin.
.github/workflows/ci.yml
Clarified release asset comments to include image requirements.
  • Updated the release workflow explanation without changing execution behavior.
.github/workflows/release.yml

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 (4ea3377) to head (db3ad81).
⚠️ Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #694   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           65        65           
  Lines         8511      8523   +12     
=========================================
+ Hits          8511      8523   +12     
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 14:26

@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/security/auth.py" line_range="371-372" />
<code_context>
         """
         resolution = self.resolver.resolve(operation)
         if not _validates_optional_token(operation):
+            self._warn_other_validators(operation)
             return resolution
         return Resolution(
</code_context>
<issue_to_address>
**Other validators receive no warning**

When an optional operation has a FOCA bearer scheme and another scheme with a validator function, `_validates_optional_token(operation)` returns true, so `resolve()` skips `_warn_other_validators()` and the other validator receives no warning despite the documented warning contract.

Check for uncovered validator functions before treating the operation as covered by the FOCA bearer validator.

Also at `docs/authentication.md:92-94`.
</issue_to_address>

Linked issues

#693 fix: address v0.21.0 pre-release review findings · 14 of 14 met

# Requirement Status Notes
1 Add an intro listing the migration themes and the missing blank line before ## Audit log. ✅ Met The intro lists the themes, and the Audit log section is separated by a blank line.
2 Document that invalid log sections now stop the app rather than falling back with a warning. ✅ Met The guide explains which unknown filters and handlers fail validation and gives an example fix.
3 Document the changed log text for invalid responses. ✅ Met The guide describes the filtered Connexion message and the replacement FOCA error log.
4 Document that foca-common 0.5.0 is unreleased, apps may stay on 0.4.0, it sets and reserves PORT, and charts that add extraEnv themselves render duplicates. ✅ Met These details are covered in the App charts section, including the proTES example.
5 Document when is_admin() is False for custom models and that admins can reach resources without owners through ownership_server. ✅ Met The guide covers the required matcher prefix and the ownerless-resource operations.
6 Document that one stored document can fail a whole list, including for uri values. ✅ Met The stricter request checks section gives a uri example and explains that the list can return 500.
7 Document the foca-plugins version cap and the order: FOCA tag, foca-plugins with <0.22 tested against 0.21, then proTES. ✅ Met The guide describes the cap, the tested <0.22 sequence, and identifies proTES as an affected app.
8 Narrow the audit-log claim to exclude configured rules, foca sync-policies, and policies_force. ✅ Met The guide states that these changes leave no audit event.
9 Add an integration test for X-Request-ID and a client-supplied value under both trust_incoming settings. ✅ Met The parametrized test checks both app instances, including generated IDs and client-supplied IDs.
10 Make foca/gunicorn_config.py, docs/deployment.md, and the migration guide’s App charts section agree with the chart on PORT. ✅ Met The comment and both documentation sections describe the chart setting PORT to the Service port.
11 Document that apps whose factory returns the Connexion app cannot be targeted by the CLI, and that the factory’s writes happen before foca exits with 2. ✅ Met The CLI guide states both limitations and gives the required app change.
12 Update the release-step comments to mention the image requirements as well as distributions. ✅ Met The release workflow comment now names both distributions and image requirements.
13 Warn at startup when reject_invalid_tokens cannot apply to optional-token validator functions. ✅ Met The resolver warns for other x-bearerInfoFunc and x-tokenInfoFunc functions, once per function per resolver/specification.
14 Pin uv for image-constraints in one shared place with test-lowest. ✅ Met Both jobs use the workflow-level UV_VERSION value of 0.13.4.

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: foca/security/auth.py:372


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

Comment thread foca/security/auth.py Resolved
uniqueg and others added 2 commits November 4, 2026 15:38
Debug records of PyMongo's background threads, left by earlier tests,
could land in `caplog.text` and fail these tests at random. Only look
at FOCA's records.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Operations with both FOCA's and another function do get the option, and
no warning.

Refs #693

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 3e4f57c into dev Nov 4, 2026
58 checks passed
@uniqueg
uniqueg deleted the fix/021-prerelease-review branch November 4, 2026 14: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.

fix: address v0.21.0 pre-release review findings

1 participant