Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

fix: serialize plan_slug as string and broaden PostHog enabled tests

Paulo Castellano0a9ca9a185f3
diff --git a/app/Jobs/PostHog/SyncUser.php b/app/Jobs/PostHog/SyncUser.php
index f25293330..aeed8ab8c 100644
--- a/app/Jobs/PostHog/SyncUser.php
+++ b/app/Jobs/PostHog/SyncUser.php
@@ -68,7 +68,7 @@ class SyncUser implements ShouldQueue
$postHog->groupIdentify('account', (string) $account->id, [
'name' => $account->name,
'plan' => $account->plan?->name,
- 'plan_slug' => $account->plan?->slug,
+ 'plan_slug' => $account->plan?->slug->value,
'has_active_subscription' => $account->hasActiveSubscription(),
'is_on_trial' => $account->isOnTrial(),
'workspaces_count' => $usage['workspaceCount'],
diff --git a/app/Jobs/PostHog/TrackBilling.php b/app/Jobs/PostHog/TrackBilling.php
index e1f8d033c..7c178ee67 100644
--- a/app/Jobs/PostHog/TrackBilling.php
+++ b/app/Jobs/PostHog/TrackBilling.php
@@ -59,7 +59,7 @@ class TrackBilling implements ShouldQueue
[
'stripe_status' => data_get($this->payload, 'data.object.status'),
'plan' => $account->plan?->name,
- 'plan_slug' => $account->plan?->slug,
+ 'plan_slug' => $account->plan?->slug->value,
'previous_plan' => $this->previousPlan,
],
$account,
diff --git a/tests/Unit/PostHogServiceTest.php b/tests/Unit/PostHogServiceTest.php
index babe0f93d..8e1280433 100644
--- a/tests/Unit/PostHogServiceTest.php
+++ b/tests/Unit/PostHogServiceTest.php
@@ -118,3 +118,52 @@ test('capture without account does not attach group properties', function () {
&& ! array_key_exists('plan', $properties);
});
});
+
+// ========================================
+// Self-hosted contract: enabled=false dominates regardless of api key
+// ========================================
+//
+// These cover the exact scenario the open-source gate exists to defend
+// against: a self-hosted install that inherited POSTHOG_API_KEY from an
+// example env file but did NOT explicitly opt in via POSTHOG_ENABLED.
+
+test('capture is a no-op when enabled is false even with an api key set', function () {
+ Queue::fake();
+ config(['services.posthog.enabled' => false, 'services.posthog.api_key' => 'phc_inherited_key']);
+
+ $service = new PostHogService;
+ $service->capture('user-123', 'test_event');
+
+ Queue::assertNothingPushed();
+});
+
+test('identify is a no-op when enabled is false even with an api key set', function () {
+ Queue::fake();
+ config(['services.posthog.enabled' => false, 'services.posthog.api_key' => 'phc_inherited_key']);
+
+ $service = new PostHogService;
+ $service->identify('user-123', ['$email' => '[email protected]']);
+
+ Queue::assertNothingPushed();
+});
+
+test('groupIdentify is a no-op when enabled is false even with an api key set', function () {
+ Queue::fake();
+ config(['services.posthog.enabled' => false, 'services.posthog.api_key' => 'phc_inherited_key']);
+
+ $service = new PostHogService;
+ $service->groupIdentify('account', 'acc-123', ['name' => 'Test']);
+
+ Queue::assertNothingPushed();
+});
+
+test('isEnabled requires both enabled and api key', function () {
+ config(['services.posthog.enabled' => true, 'services.posthog.api_key' => null]);
+ expect(PostHogService::isEnabled())->toBeFalse();
+
+ config(['services.posthog.enabled' => false, 'services.posthog.api_key' => 'phc_x']);
+ expect(PostHogService::isEnabled())->toBeFalse();
+
+ config(['services.posthog.enabled' => true, 'services.posthog.api_key' => 'phc_x']);
+ expect(PostHogService::isEnabled())->toBeTrue();
+});