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:
@@ -1,17 +1,16 @@
|
||||
# #region GitPluginModule [TYPE Module] [SEMANTICS git, plugin, dashboard, version_control, sync, deploy]
|
||||
#
|
||||
# @BRIEF Предоставляет плагин для версионирования и развертывания дашбордов Superset.
|
||||
# @LAYER Plugin
|
||||
# @INVARIANT Все операции с Git должны выполняться через GitService.
|
||||
# @RELATION INHERITS_FROM -> [src.core.plugin_base.PluginBase]
|
||||
# @RELATION USES -> [src.services.git_service.GitService]
|
||||
# @RELATION USES -> [src.core.superset_client.SupersetClient]
|
||||
# @RELATION USES -> [src.core.config_manager.ConfigManager]
|
||||
# @RELATION USES -> [TaskContext]
|
||||
#
|
||||
# @LAYER: Plugin
|
||||
# @RELATION INHERITS_FROM -> src.core.plugin_base.PluginBase
|
||||
# @RELATION USES -> src.services.git_service.GitService
|
||||
# @RELATION USES -> src.core.superset_client.SupersetClient
|
||||
# @RELATION USES -> src.core.config_manager.ConfigManager
|
||||
# @RELATION USES -> TaskContext
|
||||
#
|
||||
# @INVARIANT: Все операции с Git должны выполняться через GitService.
|
||||
# @CONSTRAINT: Плагин работает только с распакованными YAML-экспортами Superset.
|
||||
|
||||
# [SECTION: IMPORTS]
|
||||
import os
|
||||
import io
|
||||
import shutil
|
||||
@@ -21,27 +20,23 @@ from typing import Dict, Any, Optional
|
||||
from src.core.plugin_base import PluginBase
|
||||
from src.services.git_service import GitService
|
||||
from src.core.logger import logger as app_logger, belief_scope
|
||||
from src.core.cot_logger import MarkerLogger
|
||||
|
||||
log = MarkerLogger("GitPlugin")
|
||||
from src.core.config_manager import ConfigManager
|
||||
from src.core.superset_client import SupersetClient
|
||||
from src.core.task_manager.context import TaskContext
|
||||
from src.core.database import SessionLocal
|
||||
from src.core.mapping_service import IdMappingService
|
||||
# [/SECTION]
|
||||
|
||||
# #region GitPlugin [TYPE Class]
|
||||
# @BRIEF Реализация плагина Git Integration для управления версиями дашбордов.
|
||||
class GitPlugin(PluginBase):
|
||||
|
||||
# #region __init__ [TYPE Function]
|
||||
# @BRIEF Инициализирует плагин и его зависимости.
|
||||
# @PRE config.json exists or shared config_manager is available.
|
||||
# @POST Инициализированы git_service и config_manager.
|
||||
# [DEF:__init__:Function]
|
||||
# @PURPOSE: Инициализирует плагин и его зависимости.
|
||||
# @PRE: config.json exists or shared config_manager is available.
|
||||
# @POST: Инициализированы git_service и config_manager.
|
||||
def __init__(self):
|
||||
with belief_scope("GitPlugin.__init__"):
|
||||
log.reason("Initializing GitPlugin.")
|
||||
app_logger.info("Initializing GitPlugin.")
|
||||
self.git_service = GitService()
|
||||
|
||||
# Robust config path resolution:
|
||||
@@ -56,69 +51,69 @@ class GitPlugin(PluginBase):
|
||||
try:
|
||||
from src.dependencies import config_manager
|
||||
self.config_manager = config_manager
|
||||
log.reflect("GitPlugin initialized using shared config_manager.")
|
||||
app_logger.info("GitPlugin initialized using shared config_manager.")
|
||||
return
|
||||
except Exception:
|
||||
config_path = "config.json"
|
||||
|
||||
self.config_manager = ConfigManager(config_path)
|
||||
log.reflect(f"GitPlugin initialized with {config_path}")
|
||||
# #endregion __init__
|
||||
app_logger.info(f"GitPlugin initialized with {config_path}")
|
||||
# [/DEF:__init__:Function]
|
||||
|
||||
@property
|
||||
# #region id [TYPE Function]
|
||||
# @BRIEF Returns the plugin identifier.
|
||||
# @PRE GitPlugin is initialized.
|
||||
# @POST Returns 'git-integration'.
|
||||
# [DEF:id:Function]
|
||||
# @PURPOSE: Returns the plugin identifier.
|
||||
# @PRE: GitPlugin is initialized.
|
||||
# @POST: Returns 'git-integration'.
|
||||
def id(self) -> str:
|
||||
with belief_scope("GitPlugin.id"):
|
||||
return "git-integration"
|
||||
# #endregion id
|
||||
# [/DEF:id:Function]
|
||||
|
||||
@property
|
||||
# #region name [TYPE Function]
|
||||
# @BRIEF Returns the plugin name.
|
||||
# @PRE GitPlugin is initialized.
|
||||
# @POST Returns the human-readable name.
|
||||
# [DEF:name:Function]
|
||||
# @PURPOSE: Returns the plugin name.
|
||||
# @PRE: GitPlugin is initialized.
|
||||
# @POST: Returns the human-readable name.
|
||||
def name(self) -> str:
|
||||
with belief_scope("GitPlugin.name"):
|
||||
return "Git Integration"
|
||||
# #endregion name
|
||||
# [/DEF:name:Function]
|
||||
|
||||
@property
|
||||
# #region description [TYPE Function]
|
||||
# @BRIEF Returns the plugin description.
|
||||
# @PRE GitPlugin is initialized.
|
||||
# @POST Returns the plugin's purpose description.
|
||||
# [DEF:description:Function]
|
||||
# @PURPOSE: Returns the plugin description.
|
||||
# @PRE: GitPlugin is initialized.
|
||||
# @POST: Returns the plugin's purpose description.
|
||||
def description(self) -> str:
|
||||
with belief_scope("GitPlugin.description"):
|
||||
return "Version control for Superset dashboards"
|
||||
# #endregion description
|
||||
# [/DEF:description:Function]
|
||||
|
||||
@property
|
||||
# #region version [TYPE Function]
|
||||
# @BRIEF Returns the plugin version.
|
||||
# @PRE GitPlugin is initialized.
|
||||
# @POST Returns the version string.
|
||||
# [DEF:version:Function]
|
||||
# @PURPOSE: Returns the plugin version.
|
||||
# @PRE: GitPlugin is initialized.
|
||||
# @POST: Returns the version string.
|
||||
def version(self) -> str:
|
||||
with belief_scope("GitPlugin.version"):
|
||||
return "0.1.0"
|
||||
# #endregion version
|
||||
# [/DEF:version:Function]
|
||||
|
||||
@property
|
||||
# #region ui_route [TYPE Function]
|
||||
# @BRIEF Returns the frontend route for the git plugin.
|
||||
# @RETURN str - "/git"
|
||||
# [DEF:ui_route:Function]
|
||||
# @PURPOSE: Returns the frontend route for the git plugin.
|
||||
# @RETURN: str - "/git"
|
||||
def ui_route(self) -> str:
|
||||
with belief_scope("GitPlugin.ui_route"):
|
||||
return "/git"
|
||||
# #endregion ui_route
|
||||
# [/DEF:ui_route:Function]
|
||||
|
||||
# #region get_schema [TYPE Function]
|
||||
# @BRIEF Возвращает JSON-схему параметров для выполнения задач плагина.
|
||||
# @PRE GitPlugin is initialized.
|
||||
# @POST Returns a JSON schema dictionary.
|
||||
# @RETURN Dict[str, Any] - Схема параметров.
|
||||
# [DEF:get_schema:Function]
|
||||
# @PURPOSE: Возвращает JSON-схему параметров для выполнения задач плагина.
|
||||
# @PRE: GitPlugin is initialized.
|
||||
# @POST: Returns a JSON schema dictionary.
|
||||
# @RETURN: Dict[str, Any] - Схема параметров.
|
||||
def get_schema(self) -> Dict[str, Any]:
|
||||
with belief_scope("GitPlugin.get_schema"):
|
||||
return {
|
||||
@@ -131,15 +126,15 @@ class GitPlugin(PluginBase):
|
||||
},
|
||||
"required": ["operation", "dashboard_id"]
|
||||
}
|
||||
# #endregion get_schema
|
||||
# [/DEF:get_schema:Function]
|
||||
|
||||
# #region initialize [TYPE Function]
|
||||
# @BRIEF Выполняет начальную настройку плагина.
|
||||
# @PRE GitPlugin is initialized.
|
||||
# @POST Плагин готов к выполнению задач.
|
||||
# [DEF:initialize:Function]
|
||||
# @PURPOSE: Выполняет начальную настройку плагина.
|
||||
# @PRE: GitPlugin is initialized.
|
||||
# @POST: Плагин готов к выполнению задач.
|
||||
async def initialize(self):
|
||||
with belief_scope("GitPlugin.initialize"):
|
||||
log.reason("Initializing Git Integration Plugin logic")
|
||||
app_logger.info("[GitPlugin.initialize][Action] Initializing Git Integration Plugin logic.")
|
||||
|
||||
# [DEF:execute:Function]
|
||||
# @PURPOSE: Основной метод выполнения задач плагина с поддержкой TaskContext.
|
||||
@@ -250,15 +245,15 @@ class GitPlugin(PluginBase):
|
||||
# 5. Автоматический staging изменений (не коммит, чтобы юзер мог проверить diff)
|
||||
try:
|
||||
repo.git.add(A=True)
|
||||
log.reason("Changes staged in git")
|
||||
app_logger.info("[_handle_sync][Action] Changes staged in git")
|
||||
except Exception as ge:
|
||||
log.explore("Failed to stage changes", error=str(ge))
|
||||
app_logger.warning(f"[_handle_sync][Action] Failed to stage changes: {ge}")
|
||||
|
||||
log.reflect("Dashboard synced successfully", payload={"dashboard_id": dashboard_id})
|
||||
app_logger.info(f"[_handle_sync][Coherence:OK] Dashboard {dashboard_id} synced successfully.")
|
||||
return {"status": "success", "message": "Dashboard synced and flattened in local repository"}
|
||||
|
||||
except Exception as e:
|
||||
log.explore("Sync failed", error=str(e))
|
||||
app_logger.error(f"[_handle_sync][Coherence:Failed] Sync failed: {e}")
|
||||
raise
|
||||
# [/DEF:_handle_sync:Function]
|
||||
|
||||
@@ -320,16 +315,16 @@ class GitPlugin(PluginBase):
|
||||
f.write(zip_buffer.getvalue())
|
||||
|
||||
try:
|
||||
log.reason("Importing dashboard", payload={"environment": env.name})
|
||||
app_logger.info(f"[_handle_deploy][Action] Importing dashboard to {env.name}")
|
||||
result = client.import_dashboard(temp_zip_path)
|
||||
log.reflect("Deployment successful", payload={"dashboard_id": dashboard_id})
|
||||
app_logger.info(f"[_handle_deploy][Coherence:OK] Deployment successful for dashboard {dashboard_id}.")
|
||||
return {"status": "success", "message": f"Dashboard deployed to {env.name}", "details": result}
|
||||
finally:
|
||||
if temp_zip_path.exists():
|
||||
os.remove(temp_zip_path)
|
||||
|
||||
except Exception as e:
|
||||
log.explore("Deployment failed", error=str(e))
|
||||
app_logger.error(f"[_handle_deploy][Coherence:Failed] Deployment failed: {e}")
|
||||
raise
|
||||
# [/DEF:_handle_deploy:Function]
|
||||
|
||||
@@ -341,13 +336,13 @@ class GitPlugin(PluginBase):
|
||||
# @RETURN: Environment - Объект конфигурации окружения.
|
||||
def _get_env(self, env_id: Optional[str] = None):
|
||||
with belief_scope("GitPlugin._get_env"):
|
||||
log.reason("Fetching environment", payload={"env_id": env_id})
|
||||
app_logger.info(f"[_get_env][Entry] Fetching environment for ID: {env_id}")
|
||||
|
||||
# Priority 1: ConfigManager (config.json)
|
||||
if env_id:
|
||||
env = self.config_manager.get_environment(env_id)
|
||||
if env:
|
||||
log.reflect("Found environment by ID in ConfigManager", payload={"name": env.name})
|
||||
app_logger.info(f"[_get_env][Exit] Found environment by ID in ConfigManager: {env.name}")
|
||||
return env
|
||||
|
||||
# Priority 2: Database (DeploymentEnvironment)
|
||||
@@ -365,7 +360,7 @@ class GitPlugin(PluginBase):
|
||||
db_env = db.query(DeploymentEnvironment).first()
|
||||
|
||||
if db_env:
|
||||
log.reflect("Found environment in DB", payload={"name": db_env.name})
|
||||
app_logger.info(f"[_get_env][Exit] Found environment in DB: {db_env.name}")
|
||||
from src.core.config_models import Environment
|
||||
# Use token as password for SupersetClient
|
||||
return Environment(
|
||||
@@ -387,17 +382,17 @@ class GitPlugin(PluginBase):
|
||||
# but we have other envs, maybe it's one of them?
|
||||
env = next((e for e in envs if e.id == env_id), None)
|
||||
if env:
|
||||
log.reflect("Found environment in ConfigManager list", payload={"env_id": env_id})
|
||||
app_logger.info(f"[_get_env][Exit] Found environment {env_id} in ConfigManager list")
|
||||
return env
|
||||
|
||||
if not env_id:
|
||||
log.reflect("Using first environment from ConfigManager", payload={"name": envs[0].name})
|
||||
app_logger.info(f"[_get_env][Exit] Using first environment from ConfigManager: {envs[0].name}")
|
||||
return envs[0]
|
||||
|
||||
log.explore("No environments configured", payload={"env_id": env_id}, error="No Superset environments found in config or database")
|
||||
app_logger.error(f"[_get_env][Coherence:Failed] No environments configured (searched config.json and DB). env_id={env_id}")
|
||||
raise ValueError("No environments configured. Please add a Superset Environment in Settings.")
|
||||
# [/DEF:_get_env:Function]
|
||||
|
||||
# #endregion initialize
|
||||
# [/DEF:initialize:Function]
|
||||
# #endregion GitPlugin
|
||||
# #endregion GitPluginModule
|
||||
# #endregion GitPluginModule
|
||||
Reference in New Issue
Block a user