b0edcb53a4
- Added execute_plugin() method to PluginManager that properly sets PluginState.EXECUTING before calling a plugin method - Transitions state back to ACTIVATED on success, or ERRORED on failure - Completes the lifecycle state machine defined in PluginState enum - Added BDD feature file features/plugin_executing_state.feature with scenarios covering state transitions - Added step definitions in features/steps/plugin_executing_state_steps.py ISSUES CLOSED: #5691
100 lines
5.2 KiB
Gherkin
100 lines
5.2 KiB
Gherkin
@mock_only
|
|
Feature: PluginState.EXECUTING lifecycle state
|
|
The PluginManager must set the EXECUTING state when a plugin method is
|
|
being invoked, completing the plugin lifecycle state machine as defined
|
|
in the specification.
|
|
|
|
Based on issue #5691.
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Happy path: execute_plugin transitions ACTIVATED -> EXECUTING -> ACTIVATED
|
|
# -----------------------------------------------------------------------
|
|
|
|
Scenario: execute_plugin transitions plugin to ACTIVATED after successful execution
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I activate the plugin "exec-plugin"
|
|
And I execute method "search" on plugin "exec-plugin" with valid args
|
|
Then the plugin "exec-plugin" state should be "activated"
|
|
|
|
Scenario: execute_plugin returns the method result
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I activate the plugin "exec-plugin"
|
|
And I execute method "search" on plugin "exec-plugin" with valid args
|
|
Then the execution result should be an empty list
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Error path: execute_plugin transitions ACTIVATED -> EXECUTING -> ERRORED
|
|
# -----------------------------------------------------------------------
|
|
|
|
Scenario: execute_plugin transitions plugin to ERRORED on method exception
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I activate the plugin "exec-plugin"
|
|
And I attempt to execute a failing method on plugin "exec-plugin"
|
|
Then the plugin "exec-plugin" state should be "errored"
|
|
And a PluginError should be raised
|
|
|
|
Scenario: execute_plugin wraps method exceptions in PluginError
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I activate the plugin "exec-plugin"
|
|
And I attempt to execute a failing method on plugin "exec-plugin"
|
|
Then a PluginError should be raised
|
|
And the plugin error message should contain "execution failed"
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Guard: execute_plugin requires ACTIVATED state
|
|
# -----------------------------------------------------------------------
|
|
|
|
Scenario: execute_plugin raises PluginError if plugin is not activated
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I attempt to execute method on non-activated plugin "exec-plugin"
|
|
Then a PluginError should be raised
|
|
|
|
Scenario: execute_plugin raises PluginError if plugin is in ERRORED state
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I activate the plugin "exec-plugin"
|
|
And I attempt to execute a failing method on plugin "exec-plugin"
|
|
And I attempt to execute method on non-activated plugin "exec-plugin"
|
|
Then a PluginError should be raised
|
|
|
|
# -----------------------------------------------------------------------
|
|
# Thread safety: EXECUTING state prevents concurrent deactivation
|
|
# -----------------------------------------------------------------------
|
|
|
|
Scenario: Cannot deactivate a plugin that is in EXECUTING state
|
|
Given a fresh PluginManager instance
|
|
And a PluginDescriptor for "exec-plugin" with module "cleveragents.domain.models.acms.stubs" and class "InMemoryTextBackend"
|
|
When I register the plugin descriptor
|
|
And I activate the plugin "exec-plugin"
|
|
And I manually set plugin "exec-plugin" state to "executing"
|
|
And I attempt to deactivate the plugin "exec-plugin"
|
|
Then a PluginError should be raised
|
|
|
|
# -----------------------------------------------------------------------
|
|
# PluginState enum includes EXECUTING
|
|
# -----------------------------------------------------------------------
|
|
|
|
Scenario: PluginState enum includes the EXECUTING value
|
|
Given the PluginState enum is available
|
|
Then it should have values "discovered", "activated", "executing", "deactivated", "errored"
|
|
|
|
# -----------------------------------------------------------------------
|
|
# execute_plugin raises PluginNotFoundError for unknown plugin
|
|
# -----------------------------------------------------------------------
|
|
|
|
Scenario: execute_plugin raises PluginNotFoundError for unknown plugin
|
|
Given a fresh PluginManager instance
|
|
And I attempt to execute method on unknown plugin "nonexistent-plugin"
|
|
Then a PluginNotFoundError should be raised
|