From aaa894b27392a55980fff9db10ce0e3731ce9bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ertu=C4=9Frul=20Keyvan?= Date: Mon, 30 Nov 2026 01:28:28 +0300 Subject: [PATCH] fix(addons): run an add-on only on the module it was set up for A product add-on records the module it expects ("Expected module", e.g. panelica), but the executor never compared it with the service's own module: an add-on written for one module was sent to whatever module ran the service, where the same operation and parameter can mean something else. A mismatch now ends as Unsupported with a message naming both modules. An empty field keeps the current behaviour. --- app/Services/Addons/AddonExecutionService.php | 18 ++++++++++++++ lang/de/addons.php | 1 + lang/en/addons.php | 1 + lang/pl/addons.php | 1 + lang/tr/addons.php | 1 + lang/zh/addons.php | 1 + tests/Feature/AddonExecutorTest.php | 24 +++++++++++++++++++ 7 files changed, 47 insertions(+) diff --git a/app/Services/Addons/AddonExecutionService.php b/app/Services/Addons/AddonExecutionService.php index cf283811..a5cdc434 100644 --- a/app/Services/Addons/AddonExecutionService.php +++ b/app/Services/Addons/AddonExecutionService.php @@ -182,6 +182,24 @@ public function execute(ServiceAddonExecution $execution): bool return $this->finish($execution, AddonExecutionStatus::Failed, null, __('addons.executor.configuration_missing'), null, $attempt, $claimToken); } + // The add-on names the module it was written for. On a service + // run by another module the same operation and parameter can mean + // something else, so it is not sent there. + $expected = strtolower(trim((string) ($config['module'] ?? ''))); + $actual = strtolower(trim((string) ($service->server?->type ?? $service->product?->server_type ?? ''))); + + if ($expected !== '' && $expected !== $actual) { + return $this->finish( + $execution, + AddonExecutionStatus::Unsupported, + null, + __('addons.executor.module_mismatch', ['expected' => $expected, 'actual' => $actual !== '' ? $actual : '-']), + null, + $attempt, + $claimToken + ); + } + $this->assertNoSecrets($config); $problem = $this->validateCapabilities($module, $config); diff --git a/lang/de/addons.php b/lang/de/addons.php index 8e0cc4f8..be1ae552 100644 --- a/lang/de/addons.php +++ b/lang/de/addons.php @@ -4,6 +4,7 @@ 'executor' => [ 'service_or_addon_missing' => 'Der Dienst oder das Add-on existiert nicht mehr.', 'module_not_supported' => 'Das Dienstmodul unterstützt die technische Add-on-Ausführung nicht.', + 'module_mismatch' => 'Das Add-on ist für das Modul :expected eingerichtet, dieser Dienst läuft aber auf :actual.', 'configuration_missing' => 'Für dieses Add-on fehlt eine vollständige Ausführungskonfiguration.', 'validation_failed' => 'Das Modul hat die Add-on-Konfiguration abgelehnt.', 'operation_failed' => 'Das Modul konnte die Add-on-Operation nicht ausführen.', diff --git a/lang/en/addons.php b/lang/en/addons.php index 4e8c1ccf..591cd62b 100644 --- a/lang/en/addons.php +++ b/lang/en/addons.php @@ -4,6 +4,7 @@ 'executor' => [ 'service_or_addon_missing' => 'The service or add-on no longer exists.', 'module_not_supported' => 'The service module does not support technical add-on execution.', + 'module_mismatch' => 'The add-on is set up for the :expected module, but this service runs on :actual.', 'configuration_missing' => 'This add-on has no complete fulfillment configuration.', 'validation_failed' => 'The module rejected the add-on configuration.', 'operation_failed' => 'The module could not complete the add-on operation.', diff --git a/lang/pl/addons.php b/lang/pl/addons.php index f1782dd7..3c7914b6 100644 --- a/lang/pl/addons.php +++ b/lang/pl/addons.php @@ -4,6 +4,7 @@ 'executor' => [ 'service_or_addon_missing' => 'Usługa lub dodatek już nie istnieją.', 'module_not_supported' => 'Moduł usługi nie obsługuje technicznej realizacji dodatków.', + 'module_mismatch' => 'Dodatek jest skonfigurowany dla modułu :expected, a ta usługa działa na :actual.', 'configuration_missing' => 'Ten dodatek nie ma kompletnej konfiguracji realizacji.', 'validation_failed' => 'Moduł odrzucił konfigurację dodatku.', 'operation_failed' => 'Moduł nie mógł wykonać operacji dodatku.', diff --git a/lang/tr/addons.php b/lang/tr/addons.php index 4920ad58..31f7edf0 100644 --- a/lang/tr/addons.php +++ b/lang/tr/addons.php @@ -4,6 +4,7 @@ 'executor' => [ 'service_or_addon_missing' => 'Hizmet veya eklenti artık mevcut değil.', 'module_not_supported' => 'Hizmet modülü teknik eklenti uygulamasını desteklemiyor.', + 'module_mismatch' => 'Eklenti :expected modülü için ayarlanmış, ama bu hizmet :actual üzerinde çalışıyor.', 'configuration_missing' => 'Bu eklenti için tam bir uygulama yapılandırması yok.', 'validation_failed' => 'Modül eklenti yapılandırmasını reddetti.', 'operation_failed' => 'Modül eklenti işlemini tamamlayamadı.', diff --git a/lang/zh/addons.php b/lang/zh/addons.php index 466282a0..9cfa5639 100644 --- a/lang/zh/addons.php +++ b/lang/zh/addons.php @@ -4,6 +4,7 @@ 'executor' => [ 'service_or_addon_missing' => '服务或附加项已不存在。', 'module_not_supported' => '服务模块不支持附加项的技术执行。', + 'module_mismatch' => '该附加项是为 :expected 模块设置的,但此服务运行在 :actual 上。', 'configuration_missing' => '此附加项缺少完整的执行配置。', 'validation_failed' => '模块拒绝了附加项配置。', 'operation_failed' => '模块无法完成附加项操作。', diff --git a/tests/Feature/AddonExecutorTest.php b/tests/Feature/AddonExecutorTest.php index c6e85ac8..d131781c 100644 --- a/tests/Feature/AddonExecutorTest.php +++ b/tests/Feature/AddonExecutorTest.php @@ -155,6 +155,30 @@ function addonTestServiceAddon( expect($execution->fresh()->status)->toBe(AddonExecutionStatus::Unsupported); }); +it('does not run an add-on set up for another module', function () { + $service = addonTestService(); + $addon = addonTestServiceAddon($service, addonTestProductAddon(['fulfillment_module' => 'panelica'])); + $executor = app(AddonExecutionService::class); + + $execution = $executor->enqueueApply($addon); + $executor->execute($execution); + + expect($execution->fresh()->status)->toBe(AddonExecutionStatus::Unsupported) + ->and($execution->fresh()->result_message)->toContain('panelica') + ->and($service->fresh()->module_data['addon_test']['state']['storage_quota'] ?? null)->toBeNull(); +}); + +it('runs an add-on set up for the service module, whatever the case', function () { + $service = addonTestService(); + $addon = addonTestServiceAddon($service, addonTestProductAddon(['fulfillment_module' => 'Addon_Test'])); + $executor = app(AddonExecutionService::class); + + $execution = $executor->enqueueApply($addon); + $executor->execute($execution); + + expect($execution->fresh()->status)->toBe(AddonExecutionStatus::Completed); +}); + it('retries a transient module failure with a new attempt record', function () { $service = addonTestService(); $productAddon = addonTestProductAddon(['options' => ['simulate' => 'fail_once']]);