Skip to content

Legacy license field improvements - #2960

Open
pramodjodhani wants to merge 22 commits into
release/M26.machampfrom
update/license-field-improvements
Open

Legacy license field improvements#2960
pramodjodhani wants to merge 22 commits into
release/M26.machampfrom
update/license-field-improvements

Conversation

@pramodjodhani

@pramodjodhani pramodjodhani commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

🎫 Ticket

SMTNC-1862

🗒️ Description

  1. If unified license key is set, the legacy license fields are made readonly and disabled.
  2. Warn user away from entering unified license key to the legacy license fields. Guide to the LW license manager.
  3. Fix bug where incorrect message is show when user tried to enter legacy license when already unified license key is set.

🎥 Artifacts

https://www.loom.com/share/94f08029f9fc4ac0a4a1f08915e1e778

✔️ Checklist

  • Ran npm run changelog to add changelog file(s). More info here
  • Code is covered by NEW wpunit or integration tests.
  • Code is covered by EXISTING wpunit or integration tests.
  • Are all the required tests passing?
  • Automated code review comments are addressed.
  • Have you added Artifacts?
  • Check the base branch for your PR.
  • Add your PR to the project board for the release.

1. If unified license key is set, the legacy license fields are made readonly and disabled.
2. Warn user away from entering unified license key to the legacy license fields. Guide to the LW license manager.
3. Fix bug where incorrect message is show when user tried to enter legacy license when already unified license key is set.
Comment thread src/Common/Libraries/Harbor.php Outdated
Comment on lines +303 to +305
return $this->is_product_licensed(
$this->get_harbor_product_slug( $tec_product_slug )
);

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.

This specific check could be risky, right? It just checks whether their Unified Key covers the Product Slug. Not whether it is active for their site.

If they choose specifically not to activate the Product License on their site via their Unified Key, then they should be able to enter a Legacy Key still.

lw_harbor_is_product_license_active() may be the correct underlying function to call here. $this->is_product_license() calls lw_harbor_is_feature_available() under the hood which is a different check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@d4mation I have made this change 07c8007 (this PR)

Questions:

  1. Are entitlements same as capabilities? Do we need to to rename the function?
  2. Do you think this function could be helpful for other plugins as well and can be added to Harbor's global functions?

@d4mation d4mation Jul 28, 2026

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.

Ah, good catch on this! I was working on LearnDash Core recently where I used lw_harbor_is_product_license_active() and it just happened to be the same slug as the Product in Portal+Licensing.

In this case, you need to be checking for Capabilities (plugins, services, etc.) that are provided via the Product. What you have done looks correct from a logic standpoint, but it will need to be a global function in Harbor to avoid calling the version frozen within Tribe Common. https://github.com/stellarwp/harbor/blob/main/docs/architecture/fat-leader-thin-instance.md

It might be a good idea to expose a few functions here:

  1. One to get all the Products from the License Repository
  2. One that does what you're doing and checking if a given Capability Slug is covered by the entered Unified Key, whether or not the Product is active for the domain
  3. One that does the same as above, but also checks whether the Product is active for the domain (exactly what you're doing)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@d4mation Sure, I'm on it. Do these names make sense to you:

lw_harbor_get_licensed_products()
lw_harbor_is_capability_licensed( string $capability_slug ): bool
function lw_harbor_is_capability_license_active( string $capability_slug ): bool

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.

I think we should follow some existing naming patterns:

  • lw_harbor_is_capability_license_available( string $slug ): bool
  • lw_harbor_is_capability_license_active( string $slug ): bool

But I otherwise prefer your simplification here :)

I am less sure about lw_harbor_get_licensed_products() though. Unless you think you need it, we should skip it for now. We would need to flatten it to an array of string slugs to make it make sense in a multi-Harbor environment because each version of Harbor would be expecting a different Strauss Prefix on whatever Object it would normally want to return.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

…bilities

`is_license_field_managed_by_harbor()` was checking tier entitlement
(`is_product_licensed()`), which only confirms a customer's tier
covers a product, not that it's actually licensed for this site. It
also didn't account for accounts holding license entries for multiple
sites, so a capability granted only to another site's entry could
incorrectly read as active here.

Add `is_capability_license_active()`, which checks the `capabilities`
list of `Product_Entry` rows that are both valid and `activated_here`,
matching the real shape of Harbor's licensing data (one entry per
bundle+tier, add-ons listed as capabilities rather than their own
product slug).
@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

SMTNC-1862

Comment thread src/Common/Libraries/Harbor.php Outdated
Comment thread src/Common/Integrations/Harbor/PUE.php
Comment thread src/Tribe/PUE/Checker.php Outdated
Comment thread composer.json Outdated
"stellarwp/container-contract": "^1.0.4",
"stellarwp/db": "^1.0.3",
"stellarwp/harbor": "^1.4",
"stellarwp/harbor": "dev-SMTNC-1895",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lets make sure we release new version of harbor before merging so we dont ship a dev version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This has been reverted back to ^1.4 since we dont need any new functions, we are now utilising the existing functions lw_harbor_is_feature_enabled 👍

Comment thread src/resources/postcss/utilities
Comment thread src/Common/Libraries/Harbor.php

@johnhooks johnhooks 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.

@pramodjodhani I approve. From my perspective this handles the juggling of unified and stellar license key correctly.

Though please get full approval from @dpanta94 before merging, he knows the ins and outs of tribe-common, I do not.

2. Restore submodule reference to src/resources/postcss/utilities
3. Added type hints to the PUE functions
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved license-key validation for products managed through Unified License Manager.
    • Prevented Unified license keys from being entered or saved in standalone legacy license fields.
    • Harbor-managed legacy license fields are now disabled to avoid conflicting license configurations.
    • Added clearer guidance and an error link when a Unified license key is entered in the wrong field.
    • Existing legacy license keys and validation behavior remain supported where applicable.
  • Documentation

    • Added a changelog notice explaining the updated license-key entry behavior.

Walkthrough

Harbor now detects unified license keys, manages legacy license fields, intercepts PUE validation and saving, and provides localized error messaging. The PUE checker supports pre-validation short-circuiting. Integration tests cover managed and unmanaged product behavior.

Changes

Harbor license handling

Layer / File(s) Summary
Unified-license model and pre-validation
src/Common/Libraries/Harbor.php, tests/integration/Tribe/Common/Libraries/Harbor_Test.php
Harbor detects trimmed unified keys, identifies managed fields from active capabilities, and returns a localized error when Harbor is unavailable.
Legacy PUE validation and field handling
src/Tribe/PUE/Checker.php, src/Common/Integrations/Harbor/PUE.php, tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
The PUE checker supports early responses. Harbor-managed products bypass remote validation, preserve stored keys, and disable legacy fields. Unmanaged unified keys are rejected.
Validation support and release note
tests/wpunit/_bootstrap.php, changelog/update-license-field-improvements
The test bootstrap prevents exit-triggered test termination. The changelog records the unified-key field warning.

Sequence Diagram(s)

sequenceDiagram
  participant Admin
  participant PUEChecker
  participant Harbor
  participant Options
  Admin->>PUEChecker: Submit a license key
  PUEChecker->>Harbor: Apply pre-validation filter
  Harbor-->>PUEChecker: Return a response or continue validation
  Harbor->>Options: Preserve or reject the submitted value
Loading

Suggested reviewers: d4mation, jonwaldstein

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 93.10% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary change to legacy license fields.
Description check ✅ Passed The description includes the ticket, change details, artifact, and checklist; only the project-board item remains unchecked.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update/license-field-improvements

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Common/Libraries/Harbor.php`:
- Around line 308-315: Update the legacy PUE methods filter_pre_get_option(),
filter_stellarwp_uplink_tec_license_get_key(), filter_pue_get_update_url(), and
filter_pre_http_request() to use the active-capability predicate,
is_license_field_managed_by_harbor(), instead of is_product_licensed(). Preserve
existing behavior for activated capabilities and add coverage for an entitled
but inactive capability.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a5032be1-c2d5-4431-8e57-dcceccc5cfdf

📥 Commits

Reviewing files that changed from the base of the PR and between ab48ac8 and 0b03b38.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • changelog/update-license-field-improvements
  • composer.json
  • src/Common/Integrations/Harbor/PUE.php
  • src/Common/Libraries/Harbor.php
  • src/Tribe/PUE/Checker.php
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • tests/integration/Tribe/Common/Libraries/Harbor_Test.php

Comment on lines +308 to +315
public function is_license_field_managed_by_harbor( string $tec_product_slug ): bool {
if ( ! lw_harbor_has_unified_license_key() ) {
return false;
}

return lw_harbor_is_capability_license_active(
$this->get_harbor_product_slug( $tec_product_slug )
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Use the active-capability check for all legacy PUE paths.

Line 313 correctly checks whether the capability is active on this site. However, PUE::filter_pre_get_option(), PUE::filter_stellarwp_uplink_tec_license_get_key(), PUE::filter_pue_get_update_url(), and PUE::filter_pre_http_request() still use is_product_licensed(), which checks feature availability.

If a customer is entitled to a capability but has not activated it on this site, the field remains editable but PUE still reads and uses the unified key. A saved legacy key cannot become effective.

Use the active-capability predicate for these legacy PUE paths. Add coverage with an entitled capability that is not activated on the current site.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Common/Libraries/Harbor.php` around lines 308 - 315, Update the legacy
PUE methods filter_pre_get_option(),
filter_stellarwp_uplink_tec_license_get_key(), filter_pue_get_update_url(), and
filter_pre_http_request() to use the active-capability predicate,
is_license_field_managed_by_harbor(), instead of is_product_licensed(). Preserve
existing behavior for activated capabilities and add coverage for an entitled
but inactive capability.

@pramodjodhani pramodjodhani Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dpanta94 I think this comment makes sense and should be implemented. But I want to confirm this with you, as its possible I might have not full context of why is_product_licensed was used in these places.

is_product_licensed internally calls lw_harbor_is_feature_available which only checks if the feature is available in the tier, not whether its active or not.

Comment thread src/Common/Libraries/Harbor.php Outdated
Comment thread tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
Comment thread tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php Outdated
Comment thread tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php Outdated
Comment thread tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
…d - update the error message to guide user accordingly

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/integration/Tribe/Common/Libraries/Harbor_Test.php (1)

208-214: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Update the expected manager label.

Line 213 expects LW License Manager, but Harbor::get_unified_license_key_entry_error_message() emits Unified License Manager. This test fails.

Proposed fix
-		$this->assertStringContainsString( 'LW License Manager', $message );
+		$this->assertStringContainsString( 'Unified License Manager', $message );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/Tribe/Common/Libraries/Harbor_Test.php` around lines 208 -
214, Update the expected manager label in
it_should_include_license_manager_link_in_unified_key_entry_error_message to
match the Unified License Manager text emitted by
Harbor::get_unified_license_key_entry_error_message, while preserving the
existing link and unified-license assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tests/integration/Tribe/Common/Libraries/Harbor_Test.php`:
- Around line 208-214: Update the expected manager label in
it_should_include_license_manager_link_in_unified_key_entry_error_message to
match the Unified License Manager text emitted by
Harbor::get_unified_license_key_entry_error_message, while preserving the
existing link and unified-license assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4453db09-ef06-47ce-a6c5-e1c7731fdd40

📥 Commits

Reviewing files that changed from the base of the PR and between 0b03b38 and ddce579.

📒 Files selected for processing (5)
  • src/Common/Integrations/Harbor/PUE.php
  • src/Common/Libraries/Harbor.php
  • src/Tribe/PUE/Checker.php
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • tests/integration/Tribe/Common/Libraries/Harbor_Test.php
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Tribe/PUE/Checker.php
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • src/Common/Integrations/Harbor/PUE.php

…w_harbor_is_feature_enabled instead of creating a new one called we created in harbod (lw_harbor_is_capability_license_active)
- spy that remote validation is skipped
- cover pre_validate paths via data provider

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (3)
tests/integration/Tribe/Common/Libraries/Harbor_Test.php (3)

130-130: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Exercise the registered PUE filter in the pass-through cases.

Line 130 and Line 158 call Harbor's callback directly. These tests do not verify that tec_common_pue_pre_validate_key is registered or has the correct priority. Use apply_filters() as in Line 100 for these integration tests. Keep direct callback calls in separate unit tests.

Also applies to: 158-158

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/Tribe/Common/Libraries/Harbor_Test.php` at line 130, Update
the pass-through integration tests around
Harbor::filter_tec_common_pue_pre_validate_key, including the cases at lines 130
and 158, to invoke the registered tec_common_pue_pre_validate_key filter via
apply_filters() with the same arguments. Preserve direct callback invocation
only in separate unit tests.

100-111: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert the License Manager link destination.

Line 100 through Line 111 checks the label, and Line 212 checks only that an anchor exists. A wrong or stale href would still pass. Assert that both messages contain the configured Unified License Manager URL, such as tribe( Harbor::class )->get_portal_url().

Also applies to: 208-213

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/Tribe/Common/Libraries/Harbor_Test.php` around lines 100 -
111, Update the assertions in the test cases around the unified license key
message, including the block using apply_filters and the anchor check near the
second occurrence, to verify each message contains the configured Unified
License Manager URL from tribe( Harbor::class )->get_portal_url(). Preserve the
existing label and anchor assertions while adding the destination assertion.

90-104: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Restore the Harbor action state in finally blocks.

The test restores $wp_actions['lw_harbor/loaded'] only after the callback returns. If apply_filters() or a callback throws, later tests can inherit modified global state. The first two blocks also do not explicitly unset the key when it was absent before the test. Wrap each setup and filter call in try/finally, and restore both the prior value and key presence.

Also applies to: 120-134, 148-164

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/Tribe/Common/Libraries/Harbor_Test.php` around lines 90 -
104, Update each affected test block around apply_filters(), including the
blocks near the visible Tribe__PUE__Checker setup and the additional referenced
blocks, to wrap setup, invocation, and restoration in try/finally. Preserve
whether $wp_actions['lw_harbor/loaded'] originally existed: restore its saved
value when present, otherwise explicitly unset the key in the finally block,
even when the filter or callback throws.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/integration/Tribe/Common/Libraries/Harbor_Test.php`:
- Line 130: Update the pass-through integration tests around
Harbor::filter_tec_common_pue_pre_validate_key, including the cases at lines 130
and 158, to invoke the registered tec_common_pue_pre_validate_key filter via
apply_filters() with the same arguments. Preserve direct callback invocation
only in separate unit tests.
- Around line 100-111: Update the assertions in the test cases around the
unified license key message, including the block using apply_filters and the
anchor check near the second occurrence, to verify each message contains the
configured Unified License Manager URL from tribe( Harbor::class
)->get_portal_url(). Preserve the existing label and anchor assertions while
adding the destination assertion.
- Around line 90-104: Update each affected test block around apply_filters(),
including the blocks near the visible Tribe__PUE__Checker setup and the
additional referenced blocks, to wrap setup, invocation, and restoration in
try/finally. Preserve whether $wp_actions['lw_harbor/loaded'] originally
existed: restore its saved value when present, otherwise explicitly unset the
key in the finally block, even when the filter or callback throws.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 834aee82-c5c2-4097-80ca-679c24acc3c1

📥 Commits

Reviewing files that changed from the base of the PR and between f6e1239 and 90489d5.

📒 Files selected for processing (3)
  • src/Common/Libraries/Harbor.php
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • tests/integration/Tribe/Common/Libraries/Harbor_Test.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • src/Common/Libraries/Harbor.php

@pramodjodhani

Copy link
Copy Markdown
Contributor Author

@dpanta94 This is ready for review again.

There is a test failing, I checked it and found that the test script is crashing because the control goes to the exit statement here: https://github.com/the-events-calendar/the-events-calendar/blob/31784e78fbb240feca0cbfb506e7426de9c594b9/src/Events/Admin/Onboarding/Controller.php#L237

I confirmed this by commenting out the tribe_exit() function and then the test script was working fine except some failures unrelated to this PR (It_should_return_the_current_theme_object, It_should_correctly_identify_an_active_theme)

How do you think we should approach this solution? Maybe we should stub tribe_exit so it doesn't crash the whole script.

Comment thread src/Common/Libraries/Harbor.php

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/wpunit/_bootstrap.php`:
- Line 14: Remove the suite-wide `tribe_exit` filter from the bootstrap. In the
specific test that needs to intercept `tribe_exit()`, scope the filter to that
test or replace it with an exception-based handler that stops execution at the
exit boundary, while preserving normal termination behavior for all other tests.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: be3f1bb0-94f7-4c53-9d0e-2b43badfca5f

📥 Commits

Reviewing files that changed from the base of the PR and between 90489d5 and 6298ee3.

📒 Files selected for processing (3)
  • src/Common/Libraries/Harbor.php
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • tests/wpunit/_bootstrap.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/integration/Tribe/Common/Integrations/Harbor/PUE_Test.php
  • src/Common/Libraries/Harbor.php

Comment thread tests/wpunit/_bootstrap.php Outdated
* function in src/Events/Admin/Onboarding/Controller.php) could kill the PHP process and
* silently abandon every remaining test in the suite.
*/
tests_add_filter( 'tribe_exit', static fn() => '__return_true' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Review all exit-related tests and filters.
rg -n -C 4 'tribe_exit|tests_add_filter|remove_filter' tests src

Repository: the-events-calendar/tribe-common

Length of output: 44020


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- tribe_exit call sites in WPUnit tests ---'
rg -n -C 5 'tribe_exit|maybe_redirect_to_guided_setup_on_activation|Onboarding' tests/wpunit src/Events tests/_bootstrap.php tests/wpunit/_bootstrap.php 2>/dev/null || true

printf '%s\n' '--- bootstrap and exit wrapper ---'
cat -n tests/wpunit/_bootstrap.php
sed -n '120,150p' src/functions/utils.php

printf '%s\n' '--- test bootstrap/filter helpers ---'
rg -n -C 5 'function tests_add_filter|tests_add_filter|setUpBeforeClass|tearDownAfterClass' tests src --glob '*.php'

Repository: the-events-calendar/tribe-common

Length of output: 21303


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- WPUnit configuration and process isolation ---'
fd -i 'codeception|phpunit|bootstrap|config' . -t f | head -200
rg -n -C 4 'wpunit|processIsolation|process-isolation|bootstrap|tests_add_filter' . \
  --glob '!vendor/**' --glob '!node_modules/**' --glob '!*.lock' | head -400

printf '%s\n' '--- All tracked tribe_exit call sites ---'
rg -n -C 3 'tribe_exit\s*\(' . \
  --glob '*.php' --glob '!vendor/**' --glob '!node_modules/**'

printf '%s\n' '--- Onboarding-related tracked files ---'
fd -i 'onboard|guided|activation' . -t f

Repository: the-events-calendar/tribe-common

Length of output: 36430


Avoid a suite-wide tribe_exit() no-op.

This filter applies to the complete WPUnit process. Every tribe_exit() call invokes __return_true instead of terminating. Code after redirects or other exit paths can therefore run and hide regressions. Scope the filter to the test that requires it, or use an exception-based handler that preserves the exit boundary.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/wpunit/_bootstrap.php` at line 14, Remove the suite-wide `tribe_exit`
filter from the bootstrap. In the specific test that needs to intercept
`tribe_exit()`, scope the filter to that test or replace it with an
exception-based handler that stops execution at the exit boundary, while
preserving normal termination behavior for all other tests.

@pramodjodhani
pramodjodhani requested a review from dpanta94 August 11, 2026 10:26
@pramodjodhani

Copy link
Copy Markdown
Contributor Author

@dpanta94 because tribe_exit function silently exits the script, its hard to debug when the exit happens. I think it makes sense to disable it throughout the test suite. But let me know if you think otherwise.

@dpanta94

Copy link
Copy Markdown
Member

@pramodjodhani yes i do think otherwise. In tests environment we need to have control, mocking fully a function may mean that in the future we lose something we should catch.

Do you want to take a look here ? Im suspecting cherry picking that commit would fix the suite.

@pramodjodhani

Copy link
Copy Markdown
Contributor Author

@dpanta94 Fair enough. I have added that commit and removed my code from bootstrap.php.

Everything seems to be in good shape now. Can you please confirm?

@dpanta94
dpanta94 changed the base branch from main to release/M26.machamp August 11, 2026 13:03
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.

4 participants