Skip to content

Conversation

@fregataa
Copy link
Member

@fregataa fregataa commented Jan 27, 2026

resolves #8317 (BA-4092)

Changes

  • Add PurgeVFolderAction and PurgeVFolderActionResult classes
  • Add purge() method to VFolderService with status validation
  • Add purge_vfolder() method to VfolderRepository using execute_purger
  • Register purge_vfolder processor in VFolderProcessors
  • Update API handler to use processor instead of direct DB access

Test Coverage

Service Layer (VFolderService.purge())

Category Test Case Description
Normal test_purge_vfolder_success Successfully purges vfolder and returns PurgeVFolderActionResult
Edge test_purge_vfolder_not_found_propagates Propagates VFolderNotFound exception from repository
Edge test_purge_vfolder_invalid_status_propagates Propagates VFolderInvalidParameter exception from repository

Repository Layer (VfolderRepository.purge_vfolder())

Category Test Case Description
Normal test_purge_vfolder_success[delete_complete] Purges vfolder with DELETE_COMPLETE status, verifies deletion from DB
Normal test_purge_vfolder_success[delete_pending] Purges vfolder with DELETE_PENDING status, verifies deletion from DB
Edge test_purge_vfolder_not_found Raises VFolderNotFound when vfolder doesn't exist
Edge test_purge_vfolder_invalid_status[ready] Raises VFolderInvalidParameter for READY status
Edge test_purge_vfolder_invalid_status[performing] Raises VFolderInvalidParameter for PERFORMING status
Edge test_purge_vfolder_invalid_status[cloning] Raises VFolderInvalidParameter for CLONING status
Edge test_purge_vfolder_invalid_status[mounted] Raises VFolderInvalidParameter for MOUNTED status
Edge test_purge_vfolder_invalid_status[delete_ongoing] Raises VFolderInvalidParameter for DELETE_ONGOING status
Edge test_purge_vfolder_invalid_status[delete_error] Raises VFolderInvalidParameter for DELETE_ERROR status

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

@fregataa fregataa added this to the 26.2 milestone Jan 27, 2026
@fregataa fregataa self-assigned this Jan 27, 2026
@github-actions github-actions bot added size:M 30~100 LoC comp:manager Related to Manager component labels Jan 27, 2026
@fregataa fregataa force-pushed the refactor/BA-4092-vfolder-purge-action branch from 4e6287c to c78861d Compare January 27, 2026 03:07
@github-actions github-actions bot added size:L 100~500 LoC and removed size:M 30~100 LoC labels Jan 27, 2026
@fregataa fregataa marked this pull request as ready for review January 27, 2026 03:17
Copilot AI review requested due to automatic review settings January 27, 2026 03:17
@fregataa fregataa marked this pull request as draft January 27, 2026 03:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the VFolder purge API to follow the Action-Service-Repository pattern, replacing direct database access in the API handler with a properly layered implementation.

Changes:

  • Introduces PurgeVFolderAction and PurgeVFolderActionResult classes for the action layer
  • Adds purge() method to VFolderService that delegates to the repository
  • Implements purge_vfolder() in VfolderRepository with status validation using the Purger pattern
  • Registers purge_vfolder processor in VFolderProcessors
  • Updates API handler to use the processor instead of direct database operations

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ai/backend/manager/services/vfolder/actions/base.py Adds PurgeVFolderAction and PurgeVFolderActionResult action classes with appropriate permission types
src/ai/backend/manager/services/vfolder/services/vfolder.py Implements purge() method in VFolderService that delegates to repository
src/ai/backend/manager/services/vfolder/processors/vfolder.py Registers purge_vfolder processor with action monitors
src/ai/backend/manager/repositories/vfolder/repository.py Implements purge_vfolder() with status validation and execute_purger usage
src/ai/backend/manager/api/vfolder.py Refactors API handler to use processor, removes direct DB access and unused imports
tests/unit/manager/services/vfolder/test_vfolder_service.py Adds comprehensive service layer tests verifying delegation and exception propagation
tests/unit/manager/repositories/vfolder/test_vfolder_repository.py Adds comprehensive repository layer tests for various status scenarios
tests/unit/manager/services/vfolder/BUILD Adds BUILD file for test discovery
changes/8317.misc.md Documents the refactoring change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 430 to 431
if vfolder_data is None:
raise VFolderNotFound(extra_data=str(vfolder_uuid))
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This null check is unreachable because get_by_id on line 429 raises VFolderNotFound when the vfolder doesn't exist - it never returns None. The exception is already raised by get_by_id, so this check is redundant and can be removed.

Suggested change
if vfolder_data is None:
raise VFolderNotFound(extra_data=str(vfolder_uuid))

Copilot uses AI. Check for mistakes.
@fregataa fregataa marked this pull request as ready for review January 27, 2026 03:43
@fregataa fregataa requested a review from jopemachine January 27, 2026 04:57
)
)
except VFolderInvalidParameter as e:
raise InvalidAPIParameters(str(e))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious, why do we need to convert VFolderInvalidParameter to InvalidAPIParameters?

Copy link
Member Author

@fregataa fregataa Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that we keep InvalidAPIParameters for error message compatibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error message could be updated.
Both errors are same HTTP response code, so I think we don't this need this conversion

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check it once. @fregataa

@fregataa fregataa requested a review from jopemachine January 27, 2026 06:27
)
)
except VFolderInvalidParameter as e:
raise InvalidAPIParameters(str(e))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check it once. @fregataa

Comment on lines 646 to 653
vfolder_id = uuid.uuid4()
await self._create_vfolder_in_db(
db_with_cleanup,
vfolder_id=vfolder_id,
domain_name=test_domain_name,
user_id=test_user,
status=status,
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put anything related to this situation in the fixture.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has to use a parameterized input (status). Is there any example to setup fixtures with parameters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this part

…itory pattern

- Add PurgeVFolderAction and PurgeVFolderActionResult classes
- Add purge() method to VFolderService with status validation
- Add purge_vfolder() method to VfolderRepository using execute_purger
- Register purge_vfolder processor in VFolderProcessors
- Update API handler to use processor instead of direct DB access
…tory

Move VFolderNotFound and VFolderInvalidParameter validation from
VFolderService.purge() to VfolderRepository.purge_vfolder() for
cleaner separation of concerns.

- Repository now validates vfolder existence and purgable status
- Service layer simplified to delegate to repository
- Added unit tests for both service and repository layers
Add test_purge_vfolder_invalid_status to verify VFolderInvalidParameter
is raised when attempting to purge vfolders with non-purgable status
(READY, PERFORMING, CLONING, MOUNTED, DELETE_ONGOING, DELETE_ERROR).
Clarify why get_by_id() is called before execute_purger() - it's needed
to validate vfolder status since execute_purger() only deletes by PK
without checking status.
- Remove @pytest.mark.asyncio decorators (auto-detected by pytest)
- Move all imports to top of file
- Convert _create_vfolder_data helper to sample_vfolder_data fixture
- Merge purgable/non_purgable fixtures into single vfolder_in_db
- Use indirect parametrization to pass status to fixture
- Return only vfolder_id from fixture (status not needed)
…atus

- Replace VFolderInvalidParameter with VFolderFilterStatusFailed in
  repository purge_vfolder() for consistency with existing error types
- Remove try-except in API handler since VFolderFilterStatusFailed
  already inherits from HTTPBadRequest
- Update tests accordingly
@fregataa fregataa force-pushed the refactor/BA-4092-vfolder-purge-action branch from 269c3ca to a1a1529 Compare January 27, 2026 09:13
@fregataa fregataa requested a review from HyeockJinKim January 27, 2026 09:15
@HyeockJinKim HyeockJinKim added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit 3bd942d Jan 27, 2026
33 checks passed
@HyeockJinKim HyeockJinKim deleted the refactor/BA-4092-vfolder-purge-action branch January 27, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor VFolder Purge action

4 participants