Files
leocrm/test_report.md
T

106 lines
4.0 KiB
Markdown

# Test Report — T04 DMS Plugin Coverage Improvement
**Date**: 2026-06-29
**Task**: T04 — DMS Plugin Coverage Improvement
**Status**: ✅ COMPLETE
## Summary
- **Tests**: 106 total (27 existing + 38 error-path + 41 new coverage)
- **Passed**: 106
- **Failed**: 0
- **Coverage**: 97.90% (target: ≥80%)
- **Before**: 45.88%
- **After**: 97.90%
## Verification Command
```bash
cd /a0/usr/workdir/dev-projects/leocrm
python -m pytest tests/test_dms.py tests/test_dms_errors.py tests/test_dms_coverage.py -v --tb=short --cov=app/plugins/builtins/dms --cov-report=term-missing
```
## Coverage Report
```
Name Stmts Miss Branch BrPart Cover Missing
-----------------------------------------------------------------------------------
app/plugins/builtins/dms/__init__.py 2 0 0 0 100.00%
app/plugins/builtins/dms/models.py 26 0 0 0 100.00%
app/plugins/builtins/dms/plugin.py 5 0 0 0 100.00%
app/plugins/builtins/dms/routes.py 364 6 128 6 97.56%
app/plugins/builtins/dms/schemas.py 46 0 0 0 100.00%
-----------------------------------------------------------------------------------
TOTAL 443 6 128 6 97.90%
```
## Remaining Uncovered Lines (6 statements, 4 branches)
- Line 100: `_build_path` orphaned folder_id lookup
- Line 120→116: tree building branch (folder with parent not in map)
- Line 184→199: create_folder parent_id set but parent_folder is None
- Lines 279-282: `_is_descendant` loop traversal edge case
- Line 299: path building `cur is None` break
- Lines 639-640: `_stream()` generator body (coverage limitation with generators)
- Line 902→901: shared-with-me perm_map branch
## Files Changed
1. `tests/test_dms_coverage.py` — NEW: 41 tests covering folder tree, cascade delete, file upload edge cases, preview missing on disk, share multi-user/groups, search special chars, shared-with-me with data, bulk mixed IDs, tenant isolation
2. `pyproject.toml` — Added `concurrency = ["greenlet"]` to `[tool.coverage.run]` to fix async coverage tracking (was causing coverage to miss async function bodies)
## Key Fix: Coverage Concurrency Setting
The original coverage of 45.88% was misleadingly low because coverage.py was not tracking async function bodies with the default settings on Python 3.13. Adding `concurrency = ["greenlet"]` to `pyproject.toml` `[tool.coverage.run]` section fixed this, allowing proper tracking of async route handlers.
## Test Categories
### Folder Coverage (8 tests)
- Deeply nested tree with path verification
- Invalid parent_id in query params
- 3-level nested folder creation
- Rename + move in single request
- Move to root via parent_id=null
- Empty body update (no changes)
- Invalid folder_id in PATCH
- 3-level cascade delete with files in each folder
- Tenant isolation (cross-tenant folder access)
### File Coverage (12 tests)
- File too large (413) via mock patch
- Empty file upload
- Invalid folder_id in upload
- Invalid file_id in delete/restore/update/preview/edit-session
- Rename + move in single request
- Move to root via folder_id=null
- Empty body update (no changes)
- Preview file missing on disk (404 file_missing)
- Tenant isolation (cross-tenant file access)
### Share Coverage (8 tests)
- Share with multiple users
- Share with both users and groups
- Invalid group_id (400)
- Duplicate group share ignored
- Remove user share
- Remove share with no match (idempotent)
- Invalid group_id in remove (400)
- Remove both user and group shares
### Search Coverage (3 tests)
- Special characters in filename
- Partial name match
- Tenant isolation
### Shared-with-me Coverage (3 tests)
- Multiple shared files
- Excludes soft-deleted files
- Write access level display
### Bulk Coverage (5 tests)
- Bulk move with mixed valid/invalid IDs
- Bulk delete with mixed valid/invalid IDs
- Invalid target_folder_id (400)
- Bulk delete tenant isolation
- Bulk move tenant isolation