3f95765cf2
* test: implement comprehensive test coverage for workspace module
Added extensive test coverage for the backend core workspace module:
- __init__.py: 100% coverage (workspace mode selection, uncommitted changes)
- display.py: 100% coverage (build summaries, conflict info display)
- models.py: 96% coverage (ParallelMergeTask, MergeLock, SpecNumberLock)
- git_utils.py: 93% coverage (file renames, path mapping, git operations)
- finalization.py: 86% coverage (workspace finalization workflows)
- setup.py: 61% coverage (env files, node_modules, spec copying)
Test Results:
- 367 tests passing, 1 skipped
- Overall coverage: 86% (899 statements)
- New test classes for all uncovered functions
* test: reorganize workspace tests to backend directory and improve coverage to 94%
- Move tests/test_workspace.py to apps/backend/tests/test_workspace.py for better co-location
- Add pytest.ini to apps/backend/ for backend-specific test configuration
- Improve coverage from 86% to 94% (+53 new tests)
- finalization.py: 86% → 97%
- git_utils.py: 93% → 99%
- models.py: 96% → 96%
- setup.py: 61% → 83%
- All 419 tests passing with proper long-running test markers
* test: fix test colocation - move workspace tests to module tests/ subfolder
Per test-team-implementer skill requirements, tests MUST be in tests/
subfolder within each module, not at the backend/tests level.
- Move test_workspace.py from apps/backend/tests/ to apps/backend/core/workspace/tests/
- Remove apps/backend/pytest.ini (no longer needed)
- Follow proper test colocation: module/tests/test_*.py pattern
This ensures tests are properly co-located with their source code for
better maintainability and clearer module associations.
* test: fix imports for co-located tests in workspace module
- Add sys.path fix to import parent workspace module
- Import WorktreeError for proper exception handling
- Copy conftest.py to tests/ subfolder for fixtures
- All 422 tests now passing from new location
Tests are now properly co-located at:
apps/backend/core/workspace/tests/test_workspace.py
* test: add finalization cd path tests and fix imports
Adds tests for finalization workspace cd path display when
get_existing_build_worktree returns None or a valid path.
Fixes sys.path manipulation for co-located tests in workspace
module tests/ subfolder.
Coverage improved from 97% to 99% for finalization.py.
Overall workspace coverage: 92% (420 tests passing).
* test: achieve 100% coverage for backend core workspace module
- Fixed 2 failing npx_fallback tests with correct Path.exists mocking
- Added pytest.ini with slow/integration marker registration
- Enhanced debug fallback test with proper import blocking
- Added setup_method to reset _git_hook_check_done global flag
- Added tests for hook installation edge cases (existing hook, exception handling)
- Added mock-based test for ValueError exception handler in _scan_specs_dir
- Renamed duplicate test classes to avoid F811 errors
Coverage Results:
- core/workspace/__init__.py: 100% (26 statements)
- core/workspace/display.py: 100% (109 statements)
- core/workspace/finalization.py: 100% (229 statements)
- core/workspace/git_utils.py: 100% (183 statements)
- core/workspace/models.py: 100% (147 statements)
- core/workspace/setup.py: 100% (205 statements)
- TOTAL: 100% (899 statements, 0 missed)
451 tests passed, 4 skipped (Windows-specific)
* fix: resolve CI failures - remove deleted test_discovery import
- Removed import of deleted analysis.test_discovery module from analysis/__init__.py
- Updated __all__ list to remove TestDiscovery export
- Added CodeQL exemption comment for intentionally unused merge imports in workspace conftest
Fixes: ModuleNotFoundError: No module named 'analysis.test_discovery'
* fix: remove TestDiscovery dependency and fix CodeQL warnings
- Removed TestDiscovery import from runners/github/services/review_tools.py
- Simplified run_tests() function to try common test commands instead of using TestDiscovery
- Fixed CodeQL unused import warnings in core/workspace/tests/conftest.py by using assignment
The TestDiscovery module was deleted as part of test colocation effort.
The run_tests() function now tries common test commands (pytest, npm test, etc.)
in order until one executes successfully.
Fixes: ModuleNotFoundError: No module named 'analysis.test_discovery'
Fixes: CodeQL unused import warnings for merge module imports
* fix: resolve remaining CI failures
- Delete root-level tests/test_discovery.py (tests deleted test_discovery module)
- Apply ruff formatting to runners/github/services/review_tools.py
Fixes CI errors:
- ModuleNotFoundError: No module named 'test_discovery' (root test import)
- Ruff formatting check failure in review_tools.py
* fix: resolve CodeQL warnings and test coverage issues
- Fixed chmod permissions (0o755 → 0o700) to avoid overly permissive file warnings
- Fixed pytest.raises unreachable code warnings by moving assertions inside with blocks
- Removed unused variables: git_add_line, temp_files_before, copied, warning_found, _merge_imports
- Fixed unused stdout/stderr in review_tools.py by using underscore discard pattern
Fixes CodeQL alerts:
- 3 High severity: Overly permissive file permissions
- 2 Warnings: Unreachable code
- 9 Notes: Unused variables
Improves test code quality and security posture.
* fix: resolve CodeQL failure and address PR review feedback
- Remove unused 'import sys' from workspace/__init__.py (NEW-004)
- Fix IndexError edge case in mock_run_agent_fn for empty side_effect (NEW-001)
- Fix fragile import from tests.test_fixtures with try/except fallback (NEW-003)
- Fix proc.returncode bug in review_tools.py - now checks for exit codes 126/127
Fixes CodeQL CI failure by removing unused sys import.
Also addresses Sentry bot bug report about test command fallback mechanism.
Related PR review findings:
- NEW-004: Unused 'import sys' removed
- NEW-001: Added guard for empty side_effect list
- NEW-002: Already fixed - call_count now properly synced
- NEW-003: Wrapped import in try/except with fallback definitions
* fix: remove private functions from __all__ and add SpecNumberLock exports
- Removed 11 private (_prefixed) functions from __all__ list
- Added SpecNumberLock and SpecNumberLockError to exports for consistency
- Private functions remain as module-level assignments for internal use
- Also removed unused 'import sys' that was causing CodeQL CI failure
This addresses PR review findings:
- de54cbbac404: 13 private functions exported in all
- 4d5a452082f4: SpecNumberLock not exported via init.py
- NEW-004: Unused import sys causing CodeQL failure
The __all__ list now only contains public API exports, maintaining
the underscore convention for private/internal functions.
* fix: resolve review_tools.py double execution and resource leak bugs
High: Remove double test execution (60s check + 300s rerun)
- Now runs tests once with 300s timeout instead of twice
- Previously skipped valid tests that took >60s to complete
- Reduces test execution time by ~50% for valid test frameworks
Medium: Fix resource leak in timeout exception handler
- Now kills the correct process (proc) when timeout occurs
- Added await proc.wait() to ensure process termination before continuing
- Previously killed wrong process (already-completed proc) when proc_full timed out
Fixes Sentry bot reports on resource management and test execution efficiency.
* refactor: split monolithic test file and trim conftest.py
This commit addresses all PR review findings related to code quality
and maintainability of the workspace test suite.
Major Changes:
- Split 8,499-line test_workspace.py into 8 focused test files:
* test_models.py (47 tests) - Workspace models and locks
* test_rebase.py (12 tests) - Rebase detection and operations
* test_merge.py (122 tests) - AI merge, code fences, 3way merge
* test_display.py (46 tests) - Display and UI functions
* test_setup.py (9 tests) - Workspace setup and configuration
* test_finalization.py (32 tests) - Finalization workflows
* test_git_utils.py (97 tests) - Git utilities and helpers
* test_workspace.py (89 tests) - Core workspace functionality
- Trimmed conftest.py from 1,376 lines to 251 lines:
* Removed ~27 unused fixtures (python_project, node_project, etc.)
* Removed dead module_mocks dictionary referencing non-existent tests
* Removed conditional reload logic for qa/review modules
* Kept only essential fixtures: temp_dir, temp_git_repo, spec_dir,
project_dir, make_commit, stage_files
* Added repo root to sys.path for robust test_fixtures import
- Standardized import styles across all test files:
* Changed bare `from workspace import` to `from core.workspace import`
* Removed duplicate imports and declarations
* Added missing model imports (MergeLock, SpecNumberLock) to
test_workspace.py
* Fixed encoding issues (added encoding="utf-8" to file operations)
Coverage: 99% (898 statements, 3 missing lines are defensive fallbacks)
Fixes:
- Resolved monolithic test file maintainability issue
- Fixed massive conftest.py bloat from copy-paste
- Removed unused fixtures and dead code
- Standardized import style consistency
- Fixed fragile import depending on pytest rootdir
* fix: ruff format review_tools.py logger.info call
* fix: add asyncio_mode to workspace pytest.ini
Adds asyncio_mode = auto to workspace/tests/pytest.ini to prevent
future configuration issues when async tests are added. This
addresses PR review feedback NCR-NEW-003.
The review mentioned several issues that were already addressed in
commit 89c6c08a4:
- Monolithic test file was split into 8 test files
- conftest.py was trimmed from 1,376 to 250 lines
- Import styles were standardized to from core.workspace.
- _POTENTIALLY_MOCKED_MODULES already contains only 4 SDK modules
* fix: address all 8 PR review findings from test split
Fixes all findings from the Auto Claude PR review:
MEDIUM (Blocking):
- NEW-001: Moved _original_module_state capture BEFORE pre-mocking
so cleanup doesn't restore MagicMock objects
- NEW-002: Added missing assertion in test_fresh_choice_discards_and_returns_false
- NEW-003: Completed truncated test_validate_merged_syntax_npx_fallback_with_mock
LOW:
- NEW-004: Added is_lock_file to __all__ exports
- NEW-005: Removed duplicate TEST_SPEC_NAME in test_rebase.py
- NEW-006: Removed stray section header in test_setup.py
- NEW-007: Updated docstrings to match actual content in 4 test files
- NEW-008: Removed redundant sys.path manipulation from individual test files
(conftest.py already handles this), kept import sys needed for platform checks
All tests pass: 450 passed, 4 skipped
---------
Co-authored-by: StillKnotKnown <stillknotknown@users.noreply.github.com>
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
"""
|
|
Analysis Module
|
|
===============
|
|
|
|
Code analysis and project scanning tools.
|
|
"""
|
|
|
|
# Import from analyzers subpackage (these are the modular analyzers)
|
|
|
|
from __future__ import annotations
|
|
|
|
from .analyzers import (
|
|
ProjectAnalyzer as ModularProjectAnalyzer,
|
|
)
|
|
from .analyzers import (
|
|
ServiceAnalyzer,
|
|
analyze_project,
|
|
analyze_service,
|
|
)
|
|
from .ci_discovery import CIDiscovery
|
|
|
|
# Import from analysis module root (these are other analysis tools)
|
|
from .project_analyzer import ProjectAnalyzer
|
|
from .risk_classifier import RiskClassifier
|
|
from .security_scanner import SecurityScanner
|
|
|
|
# TestDiscovery was removed - tests are now co-located in their respective modules
|
|
|
|
# insight_extractor is a module with functions, not a class, so don't import it here
|
|
# Import it directly when needed: from analysis import insight_extractor
|
|
|
|
__all__ = [
|
|
"ProjectAnalyzer",
|
|
"ModularProjectAnalyzer",
|
|
"ServiceAnalyzer",
|
|
"analyze_project",
|
|
"analyze_service",
|
|
"RiskClassifier",
|
|
"SecurityScanner",
|
|
"CIDiscovery",
|
|
# "TestDiscovery", # Removed - tests now co-located in their modules
|
|
]
|