Skip to content

Commit 684a75d

Browse files
Defer OperatorObservabilityRepository binding to app
The v2 customization matrix documents Workflow\V2\Contracts\OperatorObservabilityRepository as a user-replaceable container binding for Waterline/history-export integrations. The service provider used singleton() to register the package default, which silently overwrote any implementation an application bound before the workflow provider registered (for example from an AppServiceProvider that loaded first in bootstrap/providers.php). Switch to singletonIf() so the package default only binds when no implementation has been registered. Applications retain full control whether they bind before or after the package provider. Add testOperatorObservabilityRepositoryBindingDefersToAppBinding to cover the pre-bound case: a custom implementation registered before WorkflowServiceProvider::register() must survive and resolve.
1 parent 8bda213 commit 684a75d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

src/Providers/WorkflowServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function register(): void
5252
{
5353
$this->mergeConfigFrom(__DIR__ . '/../config/workflows.php', 'workflows');
5454

55-
$this->app->singleton(
55+
$this->app->singletonIf(
5656
OperatorObservabilityRepository::class,
5757
DefaultOperatorObservabilityRepository::class,
5858
);

tests/Unit/Providers/WorkflowServiceProviderTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Workflow\Providers\WorkflowServiceProvider;
1818
use Workflow\Serializers\Serializer;
1919
use Workflow\States\WorkflowPendingStatus;
20+
use Workflow\V2\Contracts\OperatorObservabilityRepository;
2021
use Workflow\V2\Enums\RunStatus;
2122
use Workflow\V2\Enums\TaskStatus;
2223
use Workflow\V2\Enums\TaskType;
@@ -79,6 +80,23 @@ public function testProviderBootAllowsConfiguredInstanceModelWithExplicitRelatio
7980
$this->assertTrue(true);
8081
}
8182

83+
public function testOperatorObservabilityRepositoryBindingDefersToAppBinding(): void
84+
{
85+
// The customization matrix documents OperatorObservabilityRepository
86+
// as a user-replaceable container binding. When an application binds
87+
// its own implementation before the package service provider runs
88+
// (e.g. from an app service provider loaded earlier, or via test
89+
// setup), the package must not overwrite that binding.
90+
$custom = $this->createMock(OperatorObservabilityRepository::class);
91+
92+
$this->app->offsetUnset(OperatorObservabilityRepository::class);
93+
$this->app->singleton(OperatorObservabilityRepository::class, static fn () => $custom);
94+
95+
(new WorkflowServiceProvider($this->app))->register();
96+
97+
$this->assertSame($custom, $this->app->make(OperatorObservabilityRepository::class));
98+
}
99+
82100
public function testProviderMergesV2DefaultsIntoLegacyPublishedConfig(): void
83101
{
84102
config()->set('workflows', [

0 commit comments

Comments
 (0)