Add unit tests for ExternalDatasetService (external knowledge API integration) #20577

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

Originally created by @SmartDever02 on GitHub (Nov 26, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

We need a dedicated unit test suite for ExternalDatasetService to cover external knowledge API integration paths.
Right now, most of our dataset-related tests focus on internal datasets and RAG pipelines, but the external dataset workflows (calling external knowledge APIs, handling responses, and error conditions) are not explicitly covered.
This makes it harder to safely change or extend external dataset logic (e.g., new providers, new API parameters, or different error handling) without risking regressions.

This issue proposes adding a new test suite for External dataset service:

  • ExternalDatasetService methods related to:
    • External knowledge API integration
    • Request building (headers, query/body, authentication)
    • Response handling and normalization
    • Error handling (HTTP errors, timeouts, invalid responses)
    • Configuration / provider settings usage

2. Additional context or comments

Suggested coverage (exact method names may vary depending on the implementation):

  • Successful external retrieval with valid configuration
  • Handling of different HTTP status codes (4xx, 5xx)
  • Timeout / network error behavior
  • Handling malformed or partial responses
  • Correct mapping of external API results into internal dataset / document structures
  • Respecting tenant / dataset configuration for external providers (API keys, base URLs, rate limits, etc.)
  • Logging or metrics hooks (if present) to ensure observability when external calls fail

The tests should follow the existing patterns used for DatasetService, DocumentService, SegmentService, HitTestingService, and reuse similar mocking strategies for:

  • HTTP client / requestor used by ExternalDatasetService
  • Database session (db.session)
  • Any helper services used for configuration or feature flags

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @SmartDever02 on GitHub (Nov 26, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. We need a dedicated unit test suite for `ExternalDatasetService` to cover external knowledge API integration paths. Right now, most of our dataset-related tests focus on internal datasets and RAG pipelines, but the external dataset workflows (calling external knowledge APIs, handling responses, and error conditions) are not explicitly covered. This makes it harder to safely change or extend external dataset logic (e.g., new providers, new API parameters, or different error handling) without risking regressions. This issue proposes adding a new test suite for **External dataset service**: - `ExternalDatasetService` methods related to: - External knowledge API integration - Request building (headers, query/body, authentication) - Response handling and normalization - Error handling (HTTP errors, timeouts, invalid responses) - Configuration / provider settings usage ### 2. Additional context or comments Suggested coverage (exact method names may vary depending on the implementation): - Successful external retrieval with valid configuration - Handling of different HTTP status codes (4xx, 5xx) - Timeout / network error behavior - Handling malformed or partial responses - Correct mapping of external API results into internal dataset / document structures - Respecting tenant / dataset configuration for external providers (API keys, base URLs, rate limits, etc.) - Logging or metrics hooks (if present) to ensure observability when external calls fail The tests should follow the existing patterns used for `DatasetService`, `DocumentService`, `SegmentService`, `HitTestingService`, and reuse similar mocking strategies for: - HTTP client / requestor used by `ExternalDatasetService` - Database session (`db.session`) - Any helper services used for configuration or feature flags ### 3. Can you help us with this feature? - [x] I am interested in contributing to this feature.
yindo added the 💪 enhancement label 2026-02-21 20:08:02 -05:00
yindo closed this issue 2026-02-21 20:08: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#20577