Skip to content

fix: site deregistration in both brand and governing site - #306

Draft
Kallyan01 wants to merge 1 commit into
mainfrom
fix/site-disconnect-event-propagation
Draft

fix: site deregistration in both brand and governing site#306
Kallyan01 wants to merge 1 commit into
mainfrom
fix/site-disconnect-event-propagation

Conversation

@Kallyan01

@Kallyan01 Kallyan01 commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

What

Makes disconnecting a governing/brand pair take effect on both sites instead of
only the one the action was performed on.

Why

A pairing lives in two options that never spoke to each other —
onesearch_shared_sites on the governing site, onesearch_parent_site_url on the
brand site — so either side could tear it down and leave the other believing the
pair was still connected.

Brand side (the reported bug). Disconnect Governing Site deleted the local
option and stopped there. The governing site kept listing the brand along with its
stored API key, indexable entities and indexed records.

Governing side. Deleting a brand row cleaned up the governing end properly, but
nothing told the brand. It kept showing the governing site URL under Governing
Site Connection
and kept serving its cached brand config for up to a week.

So the pairing was one-sided in both directions, just in opposite ways.

Related Issue(s):

How

A single symmetric endpoint, DELETE /onesearch/v1/connection, registered on both
site types behind the existing check_api_permissions guard.

AI Disclosure

Claude Code (Opus 5), used for diagnosis, implementation, and tests.

Testing Instructions

Needs two paired installs — e.g. npm run wp-env start (governing, :8888) and
npm run wp-env:child start (brand, :8890).

  1. On the governing site, add the brand site and let the health check pair the two.
    Confirm the brand appears under Brand Sites, and that the brand site shows the
    governing URL under Governing Site Connection.
  2. On the brand site, click Disconnect Governing Site and confirm. A success
    notice appears and the field clears.
  3. Reload the governing site's settings — the brand site is gone from the
    list. On main it would still be there.
  4. Re-pair the two sites.
  5. On the governing site, Delete the brand row and confirm.
  6. Reload the brand site's settings — the Governing Site URL is now empty and
    the disconnect button is disabled. On main it would still show the governing site.
  7. Failure path: re-pair, then stop the governing site (or point the brand's
    onesearch_parent_site_url at an unreachable host) and disconnect from the brand
    side. The brand still disconnects locally, but the notice is a warning saying
    the governing site could not be notified.

Checklist

  • I have read the Contribution Guidelines.
  • I have read the Development Guidelines.
  • I have added necessary tests to cover my changes.
  • I have updated the project documentation as needed.
  • My code has detailed inline documentation.
  • My code is tested to the best of my abilities.
  • My code passes all lints, tests, and checks.
Open WordPress Playground Preview

@Kallyan01 Kallyan01 self-assigned this Sep 4, 2026
Copilot AI balanced review requested due to automatic review settings September 4, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical concurrency flaw and unresolved remote-failure and retry-authentication issues can leave pairings inconsistent.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds symmetric deregistration between governing and brand sites through an authenticated REST endpoint.

Changes:

  • Propagates disconnects across paired sites.
  • Clears cached configuration and reports partial failures.
  • Adds PHP and React integration coverage.
File summaries
File Review
tests/phpunit/Integration/Modules/Settings/SettingsTest.php Tests removed-brand notifications.
tests/phpunit/Integration/Modules/Rest/Governing_Data_HandlerTest.php Tests disconnect request handling.
tests/phpunit/Integration/Modules/Rest/Governing_Data_Controller_GoverningSiteTest.php Tests governing-site endpoint behavior.
tests/phpunit/Integration/Modules/Rest/Governing_Data_Controller_BrandSiteTest.php Tests brand-site endpoint behavior.
tests/phpunit/Integration/Modules/Rest/Basic_Options_ControllerTest.php Tests local and remote disconnect outcomes.
tests/js/SiteSettings.test.tsx Tests success and warning notices.
inc/Modules/Settings/Settings.php Detects removed brand sites and initiates notifications.
inc/Modules/Rest/Governing_Data_Handler.php Moderate: Governing-side notifications discard transport errors and non-200 responses, leaving stale remote state while reporting success. Preserve failures for retry or expose their status.
inc/Modules/Rest/Governing_Data_Controller.php Critical: Concurrent deregistrations can overwrite each other and resurrect removed sites; serialize updates or use compare-and-swap retries. Moderate: Idempotent retries receive 403 because authentication state is already removed; retain authenticated tombstones or remove the guarantee and adjust retry handling/tests.
inc/Modules/Rest/Basic_Options_Controller.php Propagates brand-initiated disconnects and reports remote failures.
inc/Modules/Rest/Abstract_REST_Controller.php Resolves requesting-site URLs.
assets/src/components/SiteSettings.tsx Displays partial-failure warnings.
Review details
  • Files reviewed: 12/12 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

);
}

$shared_sites = Settings::get_shared_sites();
Comment on lines +177 to +179
// Already gone: nothing to do, but the caller got what it asked for.
if ( ! isset( $shared_sites[ $site_url ] ) ) {
return rest_ensure_response(
continue;
}

self::request_disconnect( $site_url, $api_key );
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.12977% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.47%. Comparing base (30af2f0) to head (214ed5c).

Files with missing lines Patch % Lines
inc/Modules/Rest/Governing_Data_Controller.php 90.24% 4 Missing ⚠️
inc/Modules/Rest/Governing_Data_Handler.php 94.11% 3 Missing ⚠️
inc/Modules/Settings/Settings.php 90.90% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #306      +/-   ##
============================================
+ Coverage     85.95%   86.47%   +0.51%     
- Complexity      613      646      +33     
============================================
  Files            22       22              
  Lines          2158     2284     +126     
============================================
+ Hits           1855     1975     +120     
- Misses          303      309       +6     
Flag Coverage Δ
unit 86.47% <93.12%> (+0.51%) ⬆️

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

Files with missing lines Coverage Δ
inc/Modules/Rest/Abstract_REST_Controller.php 95.58% <100.00%> (+5.11%) ⬆️
inc/Modules/Rest/Basic_Options_Controller.php 100.00% <100.00%> (ø)
inc/Modules/Settings/Settings.php 93.10% <90.90%> (-0.27%) ⬇️
inc/Modules/Rest/Governing_Data_Handler.php 96.31% <94.11%> (-0.68%) ⬇️
inc/Modules/Rest/Governing_Data_Controller.php 95.45% <90.24%> (-2.42%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Kallyan01
Kallyan01 marked this pull request as draft September 4, 2026 17:24
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.

3 participants