semantics: complete DEF-to-region migration, fix regressions

- Convert legacy [DEF🆔Type] anchors to #region/#endregion across 329 files
- Reinstate _normalize_timestamp_value in sql_generator.py
- Fix MarkerLogger→logger migration in events.py (molecular CoT markers)
- Fix dataset_review orchestrator dependencies (_build_execution_snapshot)
- Fix config_manager stale-record deletion (moved to save path only)
- Add 77 missing [/DEF:] closers in 5 unbalanced test files
- Update assistant_chat.integration.test.js for #region format
- Apply molecular-cot-logging markers (REASON/REFLECT/EXPLORE) via logger.* methods
This commit is contained in:
2026-05-12 23:54:55 +03:00
parent fe8978f716
commit 306c5ae742
331 changed files with 9630 additions and 10312 deletions

View File

@@ -1,6 +1,6 @@
# #region AppDependencies [C:3] [TYPE Module] [SEMANTICS dependency, injection, singleton, factory, auth, jwt]
# @BRIEF Manages creation and provision of shared application dependencies, such as PluginLoader and TaskManager, to avoid circular imports.
# @LAYER Core
# @LAYER: Core
# @RELATION Used by main app and API routers to get access to shared instances.
# @RELATION CALLS -> [CleanReleaseRepository]
# @RELATION CALLS -> [ConfigManager]
@@ -39,13 +39,11 @@ from .services.clean_release.repository import CleanReleaseRepository
from .services.clean_release.facade import CleanReleaseFacade
from .services.reports.report_service import ReportsService
from .core.database import init_db, get_auth_db, get_db
from .core.cot_logger import MarkerLogger
from .core.logger import logger
from .core.auth.jwt import decode_token
from .core.auth.repository import AuthRepository
from .models.auth import User
log = MarkerLogger("Dependencies")
# Initialize singletons lazily to avoid import-time DB side effects during test collection.
# Use absolute path relative to this file to ensure plugins are found regardless of CWD
project_root = Path(__file__).parent.parent.parent
@@ -60,9 +58,8 @@ resource_service: Optional[ResourceService] = None
# #region get_config_manager [C:1] [TYPE Function]
# @BRIEF Dependency injector for ConfigManager.
# @PRE Global config_manager must be initialized.
# @POST Returns shared ConfigManager instance.
# @RETURN ConfigManager - The shared config manager instance.
# @PRE: Global config_manager must be initialized.
# @POST: Returns shared ConfigManager instance.
def get_config_manager() -> ConfigManager:
"""Dependency injector for ConfigManager."""
global config_manager
@@ -84,16 +81,15 @@ plugin_dir = Path(__file__).parent / "plugins"
# #region get_plugin_loader [C:1] [TYPE Function]
# @BRIEF Dependency injector for PluginLoader.
# @PRE Global plugin_loader must be initialized.
# @POST Returns shared PluginLoader instance.
# @RETURN PluginLoader - The shared plugin loader instance.
# @PRE: Global plugin_loader must be initialized.
# @POST: Returns shared PluginLoader instance.
def get_plugin_loader() -> PluginLoader:
"""Dependency injector for PluginLoader."""
global plugin_loader
if plugin_loader is None:
plugin_loader = PluginLoader(plugin_dir=str(plugin_dir))
log.reason(f"PluginLoader initialized with directory: {plugin_dir}")
log.reason(
logger.info(f"PluginLoader initialized with directory: {plugin_dir}")
logger.info(
f"Available plugins: {[config.name for config in plugin_loader.get_all_plugin_configs()]}"
)
return plugin_loader
@@ -104,15 +100,14 @@ def get_plugin_loader() -> PluginLoader:
# #region get_task_manager [C:1] [TYPE Function]
# @BRIEF Dependency injector for TaskManager.
# @PRE Global task_manager must be initialized.
# @POST Returns shared TaskManager instance.
# @RETURN TaskManager - The shared task manager instance.
# @PRE: Global task_manager must be initialized.
# @POST: Returns shared TaskManager instance.
def get_task_manager() -> TaskManager:
"""Dependency injector for TaskManager."""
global task_manager
if task_manager is None:
task_manager = TaskManager(get_plugin_loader())
log.reason("TaskManager initialized")
logger.info("TaskManager initialized")
return task_manager
@@ -121,15 +116,14 @@ def get_task_manager() -> TaskManager:
# #region get_scheduler_service [C:1] [TYPE Function]
# @BRIEF Dependency injector for SchedulerService.
# @PRE Global scheduler_service must be initialized.
# @POST Returns shared SchedulerService instance.
# @RETURN SchedulerService - The shared scheduler service instance.
# @PRE: Global scheduler_service must be initialized.
# @POST: Returns shared SchedulerService instance.
def get_scheduler_service() -> SchedulerService:
"""Dependency injector for SchedulerService."""
global scheduler_service
if scheduler_service is None:
scheduler_service = SchedulerService(get_task_manager(), get_config_manager())
log.reason("SchedulerService initialized")
logger.info("SchedulerService initialized")
return scheduler_service
@@ -138,15 +132,14 @@ def get_scheduler_service() -> SchedulerService:
# #region get_resource_service [C:1] [TYPE Function]
# @BRIEF Dependency injector for ResourceService.
# @PRE Global resource_service must be initialized.
# @POST Returns shared ResourceService instance.
# @RETURN ResourceService - The shared resource service instance.
# @PRE: Global resource_service must be initialized.
# @POST: Returns shared ResourceService instance.
def get_resource_service() -> ResourceService:
"""Dependency injector for ResourceService."""
global resource_service
if resource_service is None:
resource_service = ResourceService()
log.reason("ResourceService initialized")
logger.info("ResourceService initialized")
return resource_service
@@ -155,9 +148,8 @@ def get_resource_service() -> ResourceService:
# #region get_mapping_service [C:1] [TYPE Function]
# @BRIEF Dependency injector for MappingService.
# @PRE Global config_manager must be initialized.
# @POST Returns new MappingService instance.
# @RETURN MappingService - A new mapping service instance.
# @PRE: Global config_manager must be initialized.
# @POST: Returns new MappingService instance.
def get_mapping_service() -> MappingService:
"""Dependency injector for MappingService."""
return MappingService(get_config_manager())
@@ -171,7 +163,7 @@ _clean_release_repository = CleanReleaseRepository()
# #region get_clean_release_repository [C:1] [TYPE Function]
# @BRIEF Legacy compatibility shim for CleanReleaseRepository.
# @POST Returns a shared CleanReleaseRepository instance.
# @POST: Returns a shared CleanReleaseRepository instance.
def get_clean_release_repository() -> CleanReleaseRepository:
"""Legacy compatibility shim for CleanReleaseRepository."""
return _clean_release_repository
@@ -182,7 +174,7 @@ def get_clean_release_repository() -> CleanReleaseRepository:
# #region get_clean_release_facade [C:1] [TYPE Function]
# @BRIEF Dependency injector for CleanReleaseFacade.
# @POST Returns a facade instance with a fresh DB session.
# @POST: Returns a facade instance with a fresh DB session.
def get_clean_release_facade(db=Depends(get_db)) -> CleanReleaseFacade:
candidate_repo = CandidateRepository(db)
artifact_repo = ArtifactRepository(db)
@@ -211,21 +203,17 @@ def get_clean_release_facade(db=Depends(get_db)) -> CleanReleaseFacade:
# #endregion get_clean_release_facade
# #region oauth2_scheme [C:1] [TYPE Variable]
# @RELATION DEPENDS_ON -> OAuth2PasswordBearer
# @BRIEF OAuth2 password bearer scheme for token extraction.
# @RELATION DEPENDS_ON -> [OAuth2PasswordBearer]
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login")
# #endregion oauth2_scheme
# #region get_current_user [C:3] [TYPE Function]
# @RELATION CALLS -> AuthRepository
# @BRIEF Dependency for retrieving currently authenticated user from a JWT.
# @PRE JWT token provided in Authorization header.
# @POST Returns User object if token is valid.
# @RELATION CALLS -> [AuthRepository]
# @THROW: HTTPException 401 if token is invalid or user not found.
# @PARAM: token (str) - Extracted JWT token.
# @PARAM: db (Session) - Auth database session.
# @RETURN: User - The authenticated user.
# @PRE: JWT token provided in Authorization header.
# @POST: Returns User object if token is valid.
def get_current_user(token: str = Depends(oauth2_scheme), db=Depends(get_auth_db)):
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
@@ -252,14 +240,10 @@ def get_current_user(token: str = Depends(oauth2_scheme), db=Depends(get_auth_db
# #region has_permission [C:3] [TYPE Function]
# @RELATION CALLS -> AuthRepository
# @BRIEF Dependency for checking if the current user has a specific permission.
# @PRE User is authenticated.
# @POST Returns True if user has permission.
# @RELATION CALLS -> [AuthRepository]
# @THROW: HTTPException 403 if permission is denied.
# @PARAM: resource (str) - The resource identifier.
# @PARAM: action (str) - The action identifier (READ, EXECUTE, WRITE).
# @RETURN: User - The authenticated user if permission granted.
# @PRE: User is authenticated.
# @POST: Returns True if user has permission.
def has_permission(resource: str, action: str):
def permission_checker(current_user: User = Depends(get_current_user)):
# Union of all permissions across all roles