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,6 +1,6 @@
|
||||
# #region GitPackage [C:3] [TYPE Module] [SEMANTICS git, package, re-exports]
|
||||
# @BRIEF Package root for decomposed git routes. Re-exports all public symbols from submodules.
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
# @RELATION USES -> [GitRouter, GitDeps, GitHelpers, GitConfigRoutes, GitGiteaRoutes,
|
||||
# GitRepoRoutes, GitRepoOperationsRoutes, GitRepoLifecycleRoutes,
|
||||
# GitMergeRoutes, GitEnvironmentRoutes]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitConfigRoutes [C:2] [TYPE Module] [SEMANTICS git, config, routes, crud]
|
||||
# @BRIEF FastAPI endpoints for Git server configuration CRUD and connection testing.
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# #region GitDeps [C:1] [TYPE Module] [SEMANTICS git, deps, service-locator]
|
||||
# @BRIEF Shared dependency wiring for monkeypatch-safe git_service access and constants.
|
||||
# @LAYER API
|
||||
# @INVARIANT get_git_service() resolves from sys.modules at call time so test monkeypatching
|
||||
# @LAYER: API
|
||||
# @INVARIANT: get_git_service() resolves from sys.modules at call time so test monkeypatching
|
||||
# of git_routes.git_service (the __init__ attribute) takes effect across all submodules.
|
||||
|
||||
import sys
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitEnvironmentRoutes [C:2] [TYPE Module] [SEMANTICS git, environments, routes]
|
||||
# @BRIEF FastAPI endpoint for listing deployment environments.
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitGiteaRoutes [C:2] [TYPE Module] [SEMANTICS git, gitea, routes, repositories]
|
||||
# @BRIEF FastAPI endpoints for Gitea-specific repository operations.
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitHelpers [C:3] [TYPE Module] [SEMANTICS git, helpers, resolution, identity]
|
||||
# @BRIEF Shared helper functions for Git route modules.
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
# @RELATION USES -> [GitDeps]
|
||||
# @RELATION USES -> [SupersetClient]
|
||||
# @RELATION USES -> [UserDashboardPreference]
|
||||
@@ -11,9 +11,7 @@ from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.cot_logger import MarkerLogger
|
||||
|
||||
log = MarkerLogger("GitHelpers")
|
||||
from src.core.logger import logger
|
||||
from src.core.superset_client import SupersetClient
|
||||
from src.dependencies import get_config_manager
|
||||
from src.models.auth import User
|
||||
@@ -25,7 +23,7 @@ from ._deps import get_git_service, MAX_REPOSITORY_STATUS_BATCH
|
||||
|
||||
# #region _build_no_repo_status_payload [C:1] [TYPE Function]
|
||||
# @BRIEF Build a consistent status payload for dashboards without initialized repositories.
|
||||
# @POST Returns a stable payload compatible with frontend repository status parsing.
|
||||
# @POST: Returns a stable payload compatible with frontend repository status parsing.
|
||||
def _build_no_repo_status_payload() -> dict:
|
||||
return {
|
||||
"is_dirty": False,
|
||||
@@ -47,24 +45,24 @@ def _build_no_repo_status_payload() -> dict:
|
||||
|
||||
# #region _handle_unexpected_git_route_error [C:1] [TYPE Function]
|
||||
# @BRIEF Convert unexpected route-level exceptions to stable 500 API responses.
|
||||
# @PRE `error` is a non-HTTPException instance.
|
||||
# @POST Raises HTTPException(500) with route-specific context.
|
||||
# @PRE: `error` is a non-HTTPException instance.
|
||||
# @POST: Raises HTTPException(500) with route-specific context.
|
||||
def _handle_unexpected_git_route_error(route_name: str, error: Exception) -> None:
|
||||
log.explore(f"{route_name} failed: {error}", error=str(error))
|
||||
logger.error(f"[{route_name}][Coherence:Failed] {error}")
|
||||
raise HTTPException(status_code=500, detail=f"{route_name} failed: {str(error)}")
|
||||
# #endregion _handle_unexpected_git_route_error
|
||||
|
||||
|
||||
# #region _resolve_repository_status [C:2] [TYPE Function]
|
||||
# @BRIEF Resolve repository status for one dashboard with graceful NO_REPO semantics.
|
||||
# @PRE `dashboard_id` is a valid integer.
|
||||
# @POST Returns standard status payload or `NO_REPO` payload when repository path is absent.
|
||||
# @PRE: `dashboard_id` is a valid integer.
|
||||
# @POST: Returns standard status payload or `NO_REPO` payload when repository path is absent.
|
||||
def _resolve_repository_status(dashboard_id: int) -> dict:
|
||||
git_service = get_git_service()
|
||||
repo_path = git_service._get_repo_path(dashboard_id)
|
||||
if not os.path.exists(repo_path):
|
||||
log.reason(
|
||||
f"Repository is not initialized for dashboard {dashboard_id}"
|
||||
logger.debug(
|
||||
f"[get_repository_status][Action] Repository is not initialized for dashboard {dashboard_id}"
|
||||
)
|
||||
return _build_no_repo_status_payload()
|
||||
|
||||
@@ -72,8 +70,8 @@ def _resolve_repository_status(dashboard_id: int) -> dict:
|
||||
return git_service.get_status(dashboard_id)
|
||||
except HTTPException as e:
|
||||
if e.status_code == 404:
|
||||
log.reason(
|
||||
f"Repository is not initialized for dashboard {dashboard_id}"
|
||||
logger.debug(
|
||||
f"[get_repository_status][Action] Repository is not initialized for dashboard {dashboard_id}"
|
||||
)
|
||||
return _build_no_repo_status_payload()
|
||||
raise
|
||||
@@ -289,7 +287,11 @@ def _resolve_current_user_git_identity(
|
||||
.first()
|
||||
)
|
||||
except Exception as resolve_error:
|
||||
log.explore(f"Failed to load profile preference for user {user_id}: {resolve_error}", error=str(resolve_error))
|
||||
logger.warning(
|
||||
"[_resolve_current_user_git_identity][Action] Failed to load profile preference for user %s: %s",
|
||||
user_id,
|
||||
resolve_error,
|
||||
)
|
||||
return None
|
||||
|
||||
if not preference:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitMergeRoutes [C:3] [TYPE Module] [SEMANTICS git, merge, routes, conflicts]
|
||||
# @BRIEF FastAPI endpoints for merge operations (status, conflicts, resolve, abort, continue).
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitRepoLifecycleRoutes [C:3] [TYPE Module] [SEMANTICS git, lifecycle, sync, promote, deploy]
|
||||
# @BRIEF FastAPI endpoints for Git lifecycle operations (sync, promote, deploy).
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
import typing
|
||||
from typing import Optional
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitRepoOperationsRoutes [C:3] [TYPE Module] [SEMANTICS git, repository, operations, commit, push, pull, status]
|
||||
# @BRIEF FastAPI endpoints for Git repository operations (commit, push, pull, status, diff, history).
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -8,10 +8,7 @@ from fastapi import Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.database import get_db
|
||||
from src.core.cot_logger import MarkerLogger
|
||||
from src.core.logger import belief_scope
|
||||
|
||||
log = MarkerLogger("GitRepoOps")
|
||||
from src.core.logger import belief_scope, logger
|
||||
from src.dependencies import get_config_manager, get_current_user, has_permission
|
||||
from src.models.auth import User
|
||||
from src.models.git import GitRepository, GitServerConfig
|
||||
@@ -131,13 +128,23 @@ async def pull_changes(
|
||||
config_url = config_row.url
|
||||
config_provider = config_row.provider
|
||||
except Exception as diagnostics_error:
|
||||
log.explore(f"Failed to load repository binding diagnostics for dashboard {dashboard_id}: {diagnostics_error}", error=str(diagnostics_error))
|
||||
log.reason(
|
||||
f"Route diagnostics dashboard_ref={dashboard_ref} env_id={env_id} resolved_dashboard_id={dashboard_id} "
|
||||
f"binding_exists={bool(db_repo)} binding_local_path={(db_repo.local_path if db_repo else None)} "
|
||||
f"binding_remote_url={(db_repo.remote_url if db_repo else None)} "
|
||||
f"binding_config_id={(db_repo.config_id if db_repo else None)} "
|
||||
f"config_provider={config_provider} config_url={config_url}"
|
||||
logger.warning(
|
||||
"[pull_changes][Action] Failed to load repository binding diagnostics for dashboard %s: %s",
|
||||
dashboard_id,
|
||||
diagnostics_error,
|
||||
)
|
||||
logger.info(
|
||||
"[pull_changes][Action] Route diagnostics dashboard_ref=%s env_id=%s resolved_dashboard_id=%s "
|
||||
"binding_exists=%s binding_local_path=%s binding_remote_url=%s binding_config_id=%s config_provider=%s config_url=%s",
|
||||
dashboard_ref,
|
||||
env_id,
|
||||
dashboard_id,
|
||||
bool(db_repo),
|
||||
(db_repo.local_path if db_repo else None),
|
||||
(db_repo.remote_url if db_repo else None),
|
||||
(db_repo.config_id if db_repo else None),
|
||||
config_provider,
|
||||
config_url,
|
||||
)
|
||||
_apply_git_identity_from_profile(dashboard_id, db, current_user)
|
||||
_gs.pull_changes(dashboard_id)
|
||||
@@ -183,7 +190,11 @@ async def get_repository_status_batch(
|
||||
with belief_scope("get_repository_status_batch"):
|
||||
dashboard_ids = list(dict.fromkeys(request.dashboard_ids))
|
||||
if len(dashboard_ids) > MAX_REPOSITORY_STATUS_BATCH:
|
||||
log.explore(f"Batch size {len(dashboard_ids)} exceeds limit {MAX_REPOSITORY_STATUS_BATCH}. Truncating request.", error="Batch size exceeds limit")
|
||||
logger.warning(
|
||||
"[get_repository_status_batch][Action] Batch size %s exceeds limit %s. Truncating request.",
|
||||
len(dashboard_ids),
|
||||
MAX_REPOSITORY_STATUS_BATCH,
|
||||
)
|
||||
dashboard_ids = dashboard_ids[:MAX_REPOSITORY_STATUS_BATCH]
|
||||
|
||||
statuses = {}
|
||||
@@ -197,7 +208,9 @@ async def get_repository_status_batch(
|
||||
"sync_status": "ERROR",
|
||||
}
|
||||
except Exception as e:
|
||||
log.explore(f"Failed for dashboard {dashboard_id}: {e}", error=str(e))
|
||||
logger.error(
|
||||
f"[get_repository_status_batch][Coherence:Failed] Failed for dashboard {dashboard_id}: {e}"
|
||||
)
|
||||
statuses[str(dashboard_id)] = {
|
||||
**_build_no_repo_status_payload(),
|
||||
"sync_state": "ERROR",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitRepoRoutes [C:3] [TYPE Module] [SEMANTICS git, repository, routes, init, branches]
|
||||
# @BRIEF FastAPI endpoints for core Git repository operations (init, binding, branches, checkout).
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -8,10 +8,7 @@ from fastapi import Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from src.core.database import get_db
|
||||
from src.core.cot_logger import MarkerLogger
|
||||
from src.core.logger import belief_scope
|
||||
|
||||
log = MarkerLogger("GitRepoRoutes")
|
||||
from src.core.logger import belief_scope, logger
|
||||
from src.dependencies import get_config_manager, get_current_user, has_permission
|
||||
from src.models.auth import User
|
||||
from src.models.git import GitRepository, GitServerConfig
|
||||
@@ -64,7 +61,9 @@ async def init_repository(
|
||||
raise HTTPException(status_code=404, detail="Git configuration not found")
|
||||
|
||||
try:
|
||||
log.reason(f"Initializing repo for dashboard {dashboard_id}")
|
||||
logger.info(
|
||||
f"[init_repository][Action] Initializing repo for dashboard {dashboard_id}"
|
||||
)
|
||||
_gs.init_repo(
|
||||
dashboard_id,
|
||||
init_data.remote_url,
|
||||
@@ -95,10 +94,15 @@ async def init_repository(
|
||||
db_repo.current_branch = "dev"
|
||||
|
||||
db.commit()
|
||||
logger.info(
|
||||
f"[init_repository][Coherence:OK] Repository initialized for dashboard {dashboard_id}"
|
||||
)
|
||||
return {"status": "success", "message": "Repository initialized"}
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
log.explore("Failed to init repository", error=str(e))
|
||||
logger.error(
|
||||
f"[init_repository][Coherence:Failed] Failed to init repository: {e}"
|
||||
)
|
||||
if isinstance(e, HTTPException):
|
||||
raise
|
||||
_handle_unexpected_git_route_error("init_repository", e)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# #region GitRouter [C:1] [TYPE Module] [SEMANTICS git, routes, fastapi, router]
|
||||
# @BRIEF Shared APIRouter for all Git route modules.
|
||||
# @LAYER API
|
||||
# @LAYER: API
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
|
||||
Reference in New Issue
Block a user