Add unit tests for document service status management #20617

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

Originally created by @SmartDever02 on GitHub (Nov 27, 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 comprehensive unit test coverage for the Document service status management methods that are not yet covered by existing test suites.

Currently, we have test coverage for document creation, retrieval, update, and deletion operations. However, the document status management functionality remains untested, including document indexing control (pause/resume), error recovery operations, retry mechanisms, batch status updates, and document renaming.

This makes it difficult to safely refactor or extend status management functionality (e.g., indexing pause/resume logic, error recovery workflows, batch operations, document renaming) without risking regressions that could affect document processing workflows and user experience.

The Document service status management provides critical functionality for:

  • Controlling document indexing processes (pause/resume)
  • Recovering documents from error or paused states
  • Retrying failed document indexing operations
  • Batch updating document statuses (enable/disable/archive/unarchive)
  • Renaming documents for better organization

This issue proposes adding a comprehensive test suite for the following methods:

1. pause_document

  • Pause document indexing process
  • Update document status to paused
  • Handle documents in various states
  • Validate document existence
  • Permission validation

2. recover_document

  • Recover documents from paused state
  • Recover documents from error state
  • Restart indexing process
  • Handle invalid recovery attempts
  • Status transition validation

3. retry_document

  • Retry failed document indexing
  • Reset document error state
  • Trigger re-indexing task
  • Handle documents not in error state
  • Validate retry conditions

4. batch_update_document_status

  • Batch enable documents
  • Batch disable documents
  • Batch archive documents
  • Batch unarchive documents
  • Handle mixed status updates
  • Validate batch operation permissions
  • Handle empty document lists

5. rename_document

  • Rename document successfully
  • Validate new name format
  • Handle duplicate names
  • Permission validation
  • Update document metadata

2. Additional context or comments

The test suite should follow the existing patterns used for other service test files, including:

  • Comprehensive test coverage for all methods
  • Proper mocking of dependencies (database, task queues, indexing services)
  • Error condition testing
  • Edge case handling
  • Detailed documentation and comments
  • Test data factories for reusable mock objects

The tests should be organized into a single file:

  • document_service_status.py - Branch: feat/test-document-service-status

Key testing scenarios to cover:

  • Document status transitions (indexing → paused → indexing)
  • Error state recovery and retry mechanisms
  • Batch operations with various document states
  • Permission validation for status changes
  • Task queue integration for indexing operations
  • Edge cases (empty lists, invalid states, missing documents)
  • Concurrent status update handling

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @SmartDever02 on GitHub (Nov 27, 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 comprehensive unit test coverage for the Document service status management methods that are not yet covered by existing test suites. Currently, we have test coverage for document creation, retrieval, update, and deletion operations. However, the document status management functionality remains untested, including document indexing control (pause/resume), error recovery operations, retry mechanisms, batch status updates, and document renaming. This makes it difficult to safely refactor or extend status management functionality (e.g., indexing pause/resume logic, error recovery workflows, batch operations, document renaming) without risking regressions that could affect document processing workflows and user experience. The Document service status management provides critical functionality for: - Controlling document indexing processes (pause/resume) - Recovering documents from error or paused states - Retrying failed document indexing operations - Batch updating document statuses (enable/disable/archive/unarchive) - Renaming documents for better organization This issue proposes adding a comprehensive test suite for the following methods: **1. pause_document** - Pause document indexing process - Update document status to paused - Handle documents in various states - Validate document existence - Permission validation **2. recover_document** - Recover documents from paused state - Recover documents from error state - Restart indexing process - Handle invalid recovery attempts - Status transition validation **3. retry_document** - Retry failed document indexing - Reset document error state - Trigger re-indexing task - Handle documents not in error state - Validate retry conditions **4. batch_update_document_status** - Batch enable documents - Batch disable documents - Batch archive documents - Batch unarchive documents - Handle mixed status updates - Validate batch operation permissions - Handle empty document lists **5. rename_document** - Rename document successfully - Validate new name format - Handle duplicate names - Permission validation - Update document metadata ### 2. Additional context or comments The test suite should follow the existing patterns used for other service test files, including: - Comprehensive test coverage for all methods - Proper mocking of dependencies (database, task queues, indexing services) - Error condition testing - Edge case handling - Detailed documentation and comments - Test data factories for reusable mock objects The tests should be organized into a single file: - `document_service_status.py` - Branch: `feat/test-document-service-status` Key testing scenarios to cover: - Document status transitions (indexing → paused → indexing) - Error state recovery and retry mechanisms - Batch operations with various document states - Permission validation for status changes - Task queue integration for indexing operations - Edge cases (empty lists, invalid states, missing documents) - Concurrent status update handling ### 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:11 -05:00
yindo closed this issue 2026-02-21 20:08:11 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20617