[PR #28955] feat: complete test script of plugin runtime #32251

Closed
opened 2026-02-21 20:51:02 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/28955

State: closed
Merged: Yes


feat: Add comprehensive test suite for plugin runtime

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

This PR introduces a comprehensive test suite for the plugin runtime functionality, covering all critical aspects of plugin execution, sandbox isolation, resource management, error handling, and communication patterns.

Fixes

Closes https://github.com/langgenius/dify/issues/28954

What's New

Added tests/unit_tests/core/plugin/test_plugin_runtime.py with 73 test cases organized into 9 test classes:

Core Functionality Tests

  • TestPluginRuntimeExecution (7 tests) - Plugin execution through daemon, request preparation, timeout handling
  • TestPluginRuntimeSandboxIsolation (4 tests) - HTTP-based isolation, authentication, permission checks
  • TestPluginRuntimeResourceLimits (4 tests) - Timeout enforcement, resource limit validation
  • TestPluginRuntimeErrorHandling (14 tests) - Comprehensive error scenarios (rate limits, auth, connection, etc.)
  • TestPluginRuntimeCommunication (7 tests) - Request/response patterns, streaming, model parsing

Integration Tests

  • TestPluginToolManagerIntegration (4 tests) - Tool invocation, credential validation
  • TestPluginInstallerIntegration (3 tests) - Plugin listing, uninstallation, fetching

Advanced Scenarios

  • TestPluginRuntimeAdvancedScenarios (6 tests) - Complex data structures, retry patterns, large chunks
  • TestPluginRuntimeSecurityAndValidation (5 tests) - API key validation, sensitive data handling
  • TestPluginRuntimePerformanceScenarios (4 tests) - High-volume streaming, memory efficiency
  • TestPluginToolManagerAdvanced (4 tests) - Complex parameters, OAuth credentials
  • TestPluginInstallerAdvanced (5 tests) - Package upload, README handling, pagination
  • TestPluginRuntimeEdgeCases (6 tests) - Malformed responses, invalid JSON, error edge cases

Key Features

1900 lines of well-documented test code
73 passing tests with 100% success rate
Comprehensive coverage of plugin execution, sandbox isolation, resource limits, error handling, and communication
Follows Arrange-Act-Assert pattern for clarity
Uses mocking to avoid external dependencies
Fast execution (~30 seconds for all tests)
Passes ruff lint with zero issues
Extensive docstrings and comments for maintainability

Testing Coverage

  • Plugin execution through HTTP daemon
  • Sandbox isolation and security boundaries
  • Resource limits (timeout, memory)
  • Error handling for 14+ error types
  • Streaming and non-streaming communication
  • Complex nested data structures
  • High-volume data processing (100+ chunks)
  • OAuth and API key authentication
  • Plugin package management
  • Edge cases and malformed data

Screenshots

N/A - This is a test suite addition with no UI changes.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Additional Notes

  • All tests follow the project's testing conventions as specified in AGENTS.md
  • Tests use proper type hints and avoid Any where possible
  • Mock configurations use the correct default plugin daemon URL (http://127.0.0.1:5002)
  • Plugin IDs follow the required format: organization/plugin_name/provider_name
  • Error handling tests validate proper exception types and error messages

Contribution by Gittensor, learn more at https://gittensor.io/

**Original Pull Request:** https://github.com/langgenius/dify/pull/28955 **State:** closed **Merged:** Yes --- # feat: Add comprehensive test suite for plugin runtime > [!IMPORTANT] > > 1. Make sure you have read our [contribution guidelines](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) > 1. Ensure there is an associated issue and you have been assigned to it > 1. Use the correct syntax to link this PR: `Fixes #<issue number>`. ## Summary This PR introduces a comprehensive test suite for the plugin runtime functionality, covering all critical aspects of plugin execution, sandbox isolation, resource management, error handling, and communication patterns. ### Fixes Closes https://github.com/langgenius/dify/issues/28954 ### What's New Added `tests/unit_tests/core/plugin/test_plugin_runtime.py` with **73 test cases** organized into 9 test classes: #### Core Functionality Tests - **TestPluginRuntimeExecution** (7 tests) - Plugin execution through daemon, request preparation, timeout handling - **TestPluginRuntimeSandboxIsolation** (4 tests) - HTTP-based isolation, authentication, permission checks - **TestPluginRuntimeResourceLimits** (4 tests) - Timeout enforcement, resource limit validation - **TestPluginRuntimeErrorHandling** (14 tests) - Comprehensive error scenarios (rate limits, auth, connection, etc.) - **TestPluginRuntimeCommunication** (7 tests) - Request/response patterns, streaming, model parsing #### Integration Tests - **TestPluginToolManagerIntegration** (4 tests) - Tool invocation, credential validation - **TestPluginInstallerIntegration** (3 tests) - Plugin listing, uninstallation, fetching #### Advanced Scenarios - **TestPluginRuntimeAdvancedScenarios** (6 tests) - Complex data structures, retry patterns, large chunks - **TestPluginRuntimeSecurityAndValidation** (5 tests) - API key validation, sensitive data handling - **TestPluginRuntimePerformanceScenarios** (4 tests) - High-volume streaming, memory efficiency - **TestPluginToolManagerAdvanced** (4 tests) - Complex parameters, OAuth credentials - **TestPluginInstallerAdvanced** (5 tests) - Package upload, README handling, pagination - **TestPluginRuntimeEdgeCases** (6 tests) - Malformed responses, invalid JSON, error edge cases ### Key Features ✅ **1900 lines** of well-documented test code ✅ **73 passing tests** with 100% success rate ✅ **Comprehensive coverage** of plugin execution, sandbox isolation, resource limits, error handling, and communication ✅ **Follows Arrange-Act-Assert pattern** for clarity ✅ **Uses mocking** to avoid external dependencies ✅ **Fast execution** (~30 seconds for all tests) ✅ **Passes ruff lint** with zero issues ✅ **Extensive docstrings and comments** for maintainability ### Testing Coverage - Plugin execution through HTTP daemon - Sandbox isolation and security boundaries - Resource limits (timeout, memory) - Error handling for 14+ error types - Streaming and non-streaming communication - Complex nested data structures - High-volume data processing (100+ chunks) - OAuth and API key authentication - Plugin package management - Edge cases and malformed data ## Screenshots N/A - This is a test suite addition with no UI changes. ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods ## Additional Notes - All tests follow the project's testing conventions as specified in `AGENTS.md` - Tests use proper type hints and avoid `Any` where possible - Mock configurations use the correct default plugin daemon URL (`http://127.0.0.1:5002`) - Plugin IDs follow the required format: `organization/plugin_name/provider_name` - Error handling tests validate proper exception types and error messages Contribution by Gittensor, learn more at https://gittensor.io/
yindo added the pull-request label 2026-02-21 20:51:02 -05:00
yindo closed this issue 2026-02-21 20:51:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32251