Skip to content

fix(cli): don't set up plugin store in checks - #706

Merged
uniqueg merged 2 commits into
devfrom
fix/check-config-plugin-store
Nov 5, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/check-config-plugin-store

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Closes #705

Summary

disable_startup_writes() only switched off store setup through db.create_indexes_on_startup, so a gateway app without a db section still ran setup_store() under check-config (and sync-policies and export-spec, which use the same path). It now also sets a flag on the Foca instance that create_app() honours, with or without db. Normal startup and create-indexes don't change.

Findings on the issue's premise

Traced in the code, not on a running gateway:

  • Without db.dbs, PluginHost.from_config() keeps the store in memory, so the case in the issue touched the process's own memory rather than a database. The fix still meets the acceptance criteria, and the command no longer depends on that.
  • Loading plugins still runs their setup(config). FOCA passes it no store, and creating MongoStoreBackend doesn't write, so FOCA itself writes nothing there. What a plugin does on its own is its business; docs/cli.md says so.

Verification

Local, Python 3.12:

  • coverage run -m pytest -m 'not mongodb', without the integration test files: all passed. The one missed line of foca/foca.py (281, register_mongodb() in create_indexes()) is only reached by a test needing MongoDB, which CI runs.
  • ruff check, ruff format --check, mypy, ast-grep scan, mkdocs build --strict: passed.
  • The new test failed before the fix for the case without db, and also covers a db section with create_indexes_on_startup: true.

CI: see the checks of this PR.

Declined review findings

  • Keeping the state only in the configuration: there is no section to hold it without db.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Prevent read-only CLI checks from performing gateway plugin store setup while preserving normal startup and index-creation behavior.

Bug Fixes:

  • Prevent CLI configuration checks and related read-only commands from setting up the gateway plugin store, regardless of whether a database configuration is present.

Enhancements:

  • Clarify that plugin loading still runs plugin setup hooks while FOCA does not provide them with a store.

Documentation:

  • Update CLI documentation to describe the plugin store behavior during configuration checks.

Tests:

  • Add coverage for disabling gateway store setup with and without database configuration.

uniqueg and others added 2 commits November 5, 2026 08:01
disable_startup_writes() only turned off index creation through the db
section, so gateway apps without one still set up their plugin store.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also say in the docs that the setup() of plugins still runs.

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

sourcery-ai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR prevents check-config and related non-startup-write CLI paths from initializing gateway plugin stores by adding an explicit Foca startup-writes state honored by create_app(), while preserving normal startup and create-indexes behavior; documentation and regression tests cover both database-configured and database-free gateways.

Sequence diagram for disabling plugin store setup during CLI checks

sequenceDiagram
    participant CLI
    participant Foca
    participant App
    participant PluginHost

    CLI->>Foca: disable_startup_writes()
    Foca->>Foca: _startup_writes = False
    Foca->>Foca: db.create_indexes_on_startup = False
    CLI->>Foca: create_app()
    Foca->>App: create_app()
    App->>PluginHost: runtime.create_host()
    Note over App,PluginHost: Plugin store setup is skipped when _startup_writes is false
    PluginHost-->>App: host without initialized plugin store
Loading

File-Level Changes

Change Details Files
Prevent gateway plugin-store initialization when startup writes are disabled, including configurations without a database section.
  • Add an instance-level startup-writes flag enabled by default.
  • Make gateway app creation require that flag before setting up plugin stores, while preserving existing database index behavior during normal startup.
  • Have disable_startup_writes() clear the flag and continue disabling configured database startup indexes and policy synchronization.
foca/foca.py
Add regression coverage for both gateway configuration paths affected by the fix.
  • Verify plugin-store setup is skipped when startup writes are disabled with no database configuration.
  • Verify the same behavior when database configuration enables startup index creation, while retaining host warnings and cleanup.
tests/test_cli.py
Document that CLI checks load plugins without initializing their gateway store.
  • Clarify the behavior for gateway apps with and without a db section.
  • Explain that plugin setup hooks still run without a store supplied by FOCA.
docs/cli.md

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 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (32bcdba) to head (495d7fe).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #706   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           66        66           
  Lines         8597      8599    +2     
=========================================
+ Hits          8597      8599    +2     
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 5, 2026 07:20

@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/foca.py" line_range="236" />
<code_context>
         if self.gateway is not None:
-            create_indexes = self.conf.db is None or (
-                self.conf.db.create_indexes_on_startup
+            create_indexes = self._startup_writes and (
+                self.conf.db is None or self.conf.db.create_indexes_on_startup
             )
</code_context>
<issue_to_address>
**Check still initializes plugin store**

When a `create_app()` call and `disable_startup_writes()` run concurrently on the same `Foca` instance, with the app call reading the flag first, `create_app()` snapshots `_startup_writes` as `True`, then a concurrent `disable_startup_writes()` sets it to `False` and returns; the first call still reaches `host.setup_store()`, so the check initializes the plugin store.

Synchronize disabling with the check-and-setup sequence, or pass the write policy as a per-call option so disabling cannot race with an in-progress app creation.
</issue_to_address>

Linked issues

#705 fix: check-config writes to the plugin store · 3 of 3 met

# Requirement Status Notes
1 check-config writes nothing to the plugin store's backend, with and without a db section. ✅ Met disable_startup_writes() sets _startup_writes to false, and create_app() skips host.setup_store() when that flag is false.
2 A test covers the gateway case without a db section. ✅ Met test_no_store_of_gateway_without_writes is parameterized for both db=None and a configured db section.
3 Remove the exception from docs/cli.md. ✅ Met The documentation now says gateway plugin stores are not set up during checks, with or without a db section.

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: foca/foca.py:236


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

Comment thread foca/foca.py Resolved
@uniqueg
uniqueg merged commit a9efcd6 into dev Nov 5, 2026
83 checks passed
@uniqueg
uniqueg deleted the fix/check-config-plugin-store branch November 5, 2026 07:31
@uniqueg uniqueg added this to the v0.22.0 milestone Nov 9, 2026
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: check-config writes to the plugin store

1 participant