semantics

This commit is contained in:
2026-05-26 09:30:41 +03:00
parent 948584865c
commit d5cf5f0cf7
622 changed files with 7949 additions and 5628 deletions

View File

@@ -1,8 +1,8 @@
# [DEF:TestArchiveParser:Module]
# #region TestArchiveParser [C:2] [TYPE Module]
#
# @PURPOSE: Unit tests for MigrationArchiveParser ZIP extraction contract.
# @LAYER: Domain
# @RELATION: DEPENDS_ON -> [MigrationArchiveParserModule]
# @LAYER Domain
# @RELATION DEPENDS_ON -> [MigrationArchiveParserModule]
#
import os
import sys
@@ -19,8 +19,8 @@ if backend_dir not in sys.path:
from src.core.migration.archive_parser import MigrationArchiveParser
# [DEF:test_extract_objects_from_zip_collects_all_types:Function]
# @RELATION: BINDS_TO -> TestArchiveParser
# #region test_extract_objects_from_zip_collects_all_types [C:2] [TYPE Function]
# @RELATION BINDS_TO -> TestArchiveParser
# @PURPOSE: Verify archive parser collects dashboard/chart/dataset YAML objects into typed buckets.
# @TEST_CONTRACT: zip_archive_fixture -> typed dashboard/chart/dataset extraction buckets
# @TEST_SCENARIO: archive_with_supported_objects_extracts_all_types -> One YAML file per supported type lands in matching bucket.
@@ -74,5 +74,5 @@ def test_extract_objects_from_zip_collects_all_types():
raise AssertionError("dataset uuid mismatch")
# [/DEF:test_extract_objects_from_zip_collects_all_types:Function]
# [/DEF:TestArchiveParser:Module]
# #endregion test_extract_objects_from_zip_collects_all_types
# #endregion TestArchiveParser

View File

@@ -1,8 +1,8 @@
# [DEF:TestDryRunOrchestrator:Module]
# #region TestDryRunOrchestrator [C:2] [TYPE Module]
#
# @PURPOSE: Unit tests for MigrationDryRunService diff and risk computation contracts.
# @LAYER: Domain
# @RELATION: DEPENDS_ON -> [MigrationDryRunOrchestratorModule]
# @LAYER Domain
# @RELATION DEPENDS_ON -> [MigrationDryRunOrchestratorModule]
#
import json
import sys
@@ -22,8 +22,8 @@ from src.models.dashboard import DashboardSelection
from src.models.mapping import Base
# [DEF:_load_fixture:Function]
# @RELATION: BINDS_TO -> [TestDryRunOrchestrator]
# #region _load_fixture [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestDryRunOrchestrator]
# @PURPOSE: Load canonical migration dry-run fixture payload used by deterministic orchestration assertions.
def _load_fixture() -> dict:
fixture_path = (
@@ -32,11 +32,11 @@ def _load_fixture() -> dict:
return json.loads(fixture_path.read_text())
# [/DEF:_load_fixture:Function]
# #endregion _load_fixture
# [DEF:_make_session:Function]
# @RELATION: BINDS_TO -> [TestDryRunOrchestrator]
# #region _make_session [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestDryRunOrchestrator]
# @PURPOSE: Build isolated in-memory SQLAlchemy session for dry-run service tests.
def _make_session():
engine = create_engine(
@@ -49,11 +49,11 @@ def _make_session():
return Session()
# [/DEF:_make_session:Function]
# #endregion _make_session
# [DEF:test_migration_dry_run_service_builds_diff_and_risk:Function]
# @RELATION: BINDS_TO -> [TestDryRunOrchestrator]
# #region test_migration_dry_run_service_builds_diff_and_risk [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestDryRunOrchestrator]
# @PURPOSE: Verify dry-run orchestration returns stable diff summary and required risk codes.
# @TEST_SCENARIO: dry_run_builds_diff_and_risk -> Stable diff summary and required risk codes are returned.
# @TEST_EDGE: missing_field -> Missing target datasource remains visible in risk items.
@@ -130,5 +130,5 @@ def test_migration_dry_run_service_builds_diff_and_risk():
raise AssertionError("breaking_reference risk is not detected")
# [/DEF:test_migration_dry_run_service_builds_diff_and_risk:Function]
# [/DEF:TestDryRunOrchestrator:Module]
# #endregion test_migration_dry_run_service_builds_diff_and_risk
# #endregion TestDryRunOrchestrator

View File

@@ -13,8 +13,7 @@ from src.core.superset_client import SupersetClient
from src.services.git_service import GitService
# [DEF:test_git_service_get_repo_path_guard:Function]
# @RELATION: BINDS_TO -> UnknownModule
# #region test_git_service_get_repo_path_guard [C:2] [TYPE Function]
def test_git_service_get_repo_path_guard():
"""Verify that _get_repo_path raises ValueError if dashboard_id is None."""
service = GitService(base_path="test_repos")
@@ -22,10 +21,9 @@ def test_git_service_get_repo_path_guard():
service._get_repo_path(None)
# [/DEF:test_git_service_get_repo_path_guard:Function]
# #endregion test_git_service_get_repo_path_guard
# [DEF:test_git_service_get_repo_path_recreates_base_dir:Function]
# @RELATION: BINDS_TO -> UnknownModule
# #region test_git_service_get_repo_path_recreates_base_dir [C:2] [TYPE Function]
def test_git_service_get_repo_path_recreates_base_dir():
"""Verify _get_repo_path recreates missing base directory before returning repo path."""
service = GitService(base_path="test_repos_runtime_recreate")
@@ -36,10 +34,9 @@ def test_git_service_get_repo_path_recreates_base_dir():
assert Path(service.base_path).is_dir()
assert repo_path == str(Path(service.base_path) / "42")
# [/DEF:test_git_service_get_repo_path_recreates_base_dir:Function]
# #endregion test_git_service_get_repo_path_recreates_base_dir
# [DEF:test_superset_client_import_dashboard_guard:Function]
# @RELATION: BINDS_TO -> UnknownModule
# #region test_superset_client_import_dashboard_guard [C:2] [TYPE Function]
def test_superset_client_import_dashboard_guard():
"""Verify that import_dashboard raises ValueError if file_name is None."""
mock_env = Environment(
@@ -54,10 +51,9 @@ def test_superset_client_import_dashboard_guard():
client.import_dashboard(None)
# [/DEF:test_superset_client_import_dashboard_guard:Function]
# #endregion test_superset_client_import_dashboard_guard
# [DEF:test_git_service_init_repo_reclones_when_path_is_not_a_git_repo:Function]
# @RELATION: BINDS_TO -> UnknownModule
# #region test_git_service_init_repo_reclones_when_path_is_not_a_git_repo [C:2] [TYPE Function]
def test_git_service_init_repo_reclones_when_path_is_not_a_git_repo():
"""Verify init_repo reclones when target path exists but is not a valid Git repository."""
service = GitService(base_path="test_repos_invalid_repo")
@@ -77,10 +73,9 @@ def test_git_service_init_repo_reclones_when_path_is_not_a_git_repo():
assert not target_path.exists()
# [/DEF:test_git_service_init_repo_reclones_when_path_is_not_a_git_repo:Function]
# #endregion test_git_service_init_repo_reclones_when_path_is_not_a_git_repo
# [DEF:test_git_service_ensure_gitflow_branches_creates_and_pushes_missing_defaults:Function]
# @RELATION: BINDS_TO -> UnknownModule
# #region test_git_service_ensure_gitflow_branches_creates_and_pushes_missing_defaults [C:2] [TYPE Function]
def test_git_service_ensure_gitflow_branches_creates_and_pushes_missing_defaults():
"""Verify _ensure_gitflow_branches creates dev/preprod locally and pushes them to origin."""
service = GitService(base_path="test_repos_gitflow_defaults")
@@ -135,10 +130,9 @@ def test_git_service_ensure_gitflow_branches_creates_and_pushes_missing_defaults
assert "preprod:preprod" in repo.origin.pushed
# [/DEF:test_git_service_ensure_gitflow_branches_creates_and_pushes_missing_defaults:Function]
# #endregion test_git_service_ensure_gitflow_branches_creates_and_pushes_missing_defaults
# [DEF:test_git_service_configure_identity_updates_repo_local_config:Function]
# @RELATION: BINDS_TO -> UnknownModule
# #region test_git_service_configure_identity_updates_repo_local_config [C:2] [TYPE Function]
def test_git_service_configure_identity_updates_repo_local_config():
"""Verify configure_identity writes repository-local user.name/user.email."""
service = GitService(base_path="test_repos_identity")
@@ -154,4 +148,4 @@ def test_git_service_configure_identity_updates_repo_local_config():
fake_repo.config_writer.assert_called_once_with(config_level="repository")
config_writer.set_value.assert_any_call("user", "name", "user_1")
config_writer.set_value.assert_any_call("user", "email", "user1@mail.ru")
# [/DEF:test_git_service_configure_identity_updates_repo_local_config:Function]
# #endregion test_git_service_configure_identity_updates_repo_local_config

View File

@@ -1,8 +1,8 @@
# [DEF:TestGitServiceGiteaPr:Module]
# @RELATION: BELONGS_TO -> SrcRoot
# #region TestGitServiceGiteaPr [C:2] [TYPE Module]
# @RELATION BINDS_TO -> SrcRoot
# @SEMANTICS: tests, git, gitea, pull_request, fallback
# @PURPOSE: Validate Gitea PR creation fallback behavior when configured server URL is stale.
# @LAYER: Domain
# @LAYER Domain
# @INVARIANT: A 404 from primary Gitea URL retries once against remote-url host when different.
import asyncio
@@ -17,8 +17,8 @@ sys.path.insert(0, str(Path(__file__).parent.parent.parent))
from src.services.git_service import GitService
# [DEF:test_derive_server_url_from_remote_strips_credentials:Function]
# @RELATION: BINDS_TO -> TestGitServiceGiteaPr
# #region test_derive_server_url_from_remote_strips_credentials [C:2] [TYPE Function]
# @RELATION BINDS_TO -> TestGitServiceGiteaPr
# @PURPOSE: Ensure helper returns host base URL and removes embedded credentials.
# @PRE: remote_url is an https URL with username/token.
# @POST: Result is scheme+host only.
@@ -28,11 +28,11 @@ def test_derive_server_url_from_remote_strips_credentials():
"https://oauth2:token@giteabusya.bebesh.ru/busya/covid-vaccine-dashboard.git"
)
assert derived == "https://giteabusya.bebesh.ru"
# [/DEF:test_derive_server_url_from_remote_strips_credentials:Function]
# #endregion test_derive_server_url_from_remote_strips_credentials
# [DEF:test_create_gitea_pull_request_retries_with_remote_host_on_404:Function]
# @RELATION: BINDS_TO -> TestGitServiceGiteaPr
# #region test_create_gitea_pull_request_retries_with_remote_host_on_404 [C:2] [TYPE Function]
# @RELATION BINDS_TO -> TestGitServiceGiteaPr
# @PURPOSE: Verify create_gitea_pull_request retries with remote URL host after primary 404.
# @PRE: primary server_url differs from remote_url host.
# @POST: Method returns success payload from fallback request.
@@ -64,11 +64,11 @@ def test_create_gitea_pull_request_retries_with_remote_host_on_404(monkeypatch):
assert len(calls) == 2
assert calls[0][1] == "https://gitea.bebesh.ru"
assert calls[1][1] == "https://giteabusya.bebesh.ru"
# [/DEF:test_create_gitea_pull_request_retries_with_remote_host_on_404:Function]
# #endregion test_create_gitea_pull_request_retries_with_remote_host_on_404
# [DEF:test_create_gitea_pull_request_returns_branch_error_when_target_missing:Function]
# @RELATION: BINDS_TO -> TestGitServiceGiteaPr
# #region test_create_gitea_pull_request_returns_branch_error_when_target_missing [C:2] [TYPE Function]
# @RELATION BINDS_TO -> TestGitServiceGiteaPr
# @PURPOSE: Ensure Gitea 404 on PR creation is mapped to actionable target-branch validation error.
# @PRE: PR create call returns 404 and target branch is absent.
# @POST: Service raises HTTPException 400 with explicit missing target branch message.
@@ -101,6 +101,6 @@ def test_create_gitea_pull_request_returns_branch_error_when_target_missing(monk
assert exc_info.value.status_code == 400
assert "target branch 'preprod'" in str(exc_info.value.detail)
# [/DEF:test_create_gitea_pull_request_returns_branch_error_when_target_missing:Function]
# #endregion test_create_gitea_pull_request_returns_branch_error_when_target_missing
# [/DEF:TestGitServiceGiteaPr:Module]
# #endregion TestGitServiceGiteaPr

View File

@@ -1,8 +1,8 @@
# [DEF:TestMappingService:Module]
# #region TestMappingService [C:2] [TYPE Module]
#
# @PURPOSE: Unit tests for the IdMappingService matching UUIDs to integer IDs.
# @LAYER: Domain
# @RELATION: VERIFIES ->[src.core.mapping_service.IdMappingService]
# @LAYER Domain
# @RELATION BINDS_TO ->[IdMappingService]
#
import sys
from datetime import UTC, datetime
@@ -40,8 +40,8 @@ class MockSupersetClient:
return self.resources.get(endpoint, [])
# [DEF:test_sync_environment_upserts_correctly:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_sync_environment_upserts_correctly [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_sync_environment_upserts_correctly(db_session):
service = IdMappingService(db_session)
mock_client = MockSupersetClient(
@@ -67,11 +67,11 @@ def test_sync_environment_upserts_correctly(db_session):
assert mapping.resource_name == "Test Chart"
# [/DEF:test_sync_environment_upserts_correctly:Function]
# #endregion test_sync_environment_upserts_correctly
# [DEF:test_get_remote_id_returns_integer:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_get_remote_id_returns_integer [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_get_remote_id_returns_integer(db_session):
service = IdMappingService(db_session)
mapping = ResourceMapping(
@@ -89,11 +89,11 @@ def test_get_remote_id_returns_integer(db_session):
assert result == 99
# [/DEF:test_get_remote_id_returns_integer:Function]
# #endregion test_get_remote_id_returns_integer
# [DEF:test_get_remote_ids_batch_returns_dict:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_get_remote_ids_batch_returns_dict [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_get_remote_ids_batch_returns_dict(db_session):
service = IdMappingService(db_session)
m1 = ResourceMapping(
@@ -121,11 +121,11 @@ def test_get_remote_ids_batch_returns_dict(db_session):
assert "uuid-missing" not in result
# [/DEF:test_get_remote_ids_batch_returns_dict:Function]
# #endregion test_get_remote_ids_batch_returns_dict
# [DEF:test_sync_environment_updates_existing_mapping:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_sync_environment_updates_existing_mapping [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_sync_environment_updates_existing_mapping(db_session):
"""Verify that sync_environment updates an existing mapping (upsert UPDATE path)."""
from src.models.mapping import ResourceMapping
@@ -168,11 +168,11 @@ def test_sync_environment_updates_existing_mapping(db_session):
assert count == 1
# [/DEF:test_sync_environment_updates_existing_mapping:Function]
# #endregion test_sync_environment_updates_existing_mapping
# [DEF:test_sync_environment_skips_resources_without_uuid:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_sync_environment_skips_resources_without_uuid [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_sync_environment_skips_resources_without_uuid(db_session):
"""Resources missing uuid or having id=None should be silently skipped."""
service = IdMappingService(db_session)
@@ -200,11 +200,11 @@ def test_sync_environment_skips_resources_without_uuid(db_session):
assert count == 0
# [/DEF:test_sync_environment_skips_resources_without_uuid:Function]
# #endregion test_sync_environment_skips_resources_without_uuid
# [DEF:test_sync_environment_handles_api_error_gracefully:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_sync_environment_handles_api_error_gracefully [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_sync_environment_handles_api_error_gracefully(db_session):
"""If one resource type fails, others should still sync."""
@@ -225,11 +225,11 @@ def test_sync_environment_handles_api_error_gracefully(db_session):
assert mapping.resource_type == ResourceType.DATASET
# [/DEF:test_sync_environment_handles_api_error_gracefully:Function]
# #endregion test_sync_environment_handles_api_error_gracefully
# [DEF:test_get_remote_id_returns_none_for_missing:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_get_remote_id_returns_none_for_missing [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_get_remote_id_returns_none_for_missing(db_session):
"""get_remote_id should return None when no mapping exists."""
service = IdMappingService(db_session)
@@ -237,11 +237,11 @@ def test_get_remote_id_returns_none_for_missing(db_session):
assert result is None
# [/DEF:test_get_remote_id_returns_none_for_missing:Function]
# #endregion test_get_remote_id_returns_none_for_missing
# [DEF:test_get_remote_ids_batch_returns_empty_for_empty_input:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_get_remote_ids_batch_returns_empty_for_empty_input [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_get_remote_ids_batch_returns_empty_for_empty_input(db_session):
"""get_remote_ids_batch should return {} for an empty list of UUIDs."""
service = IdMappingService(db_session)
@@ -249,11 +249,11 @@ def test_get_remote_ids_batch_returns_empty_for_empty_input(db_session):
assert result == {}
# [/DEF:test_get_remote_ids_batch_returns_empty_for_empty_input:Function]
# #endregion test_get_remote_ids_batch_returns_empty_for_empty_input
# [DEF:test_mapping_service_alignment_with_test_data:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_mapping_service_alignment_with_test_data [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_mapping_service_alignment_with_test_data(db_session):
"""**@TEST_DATA**: Verifies that the service aligns with the resource_mapping_record contract."""
# Contract: {'environment_id': 'prod-env-1', 'resource_type': 'chart', 'uuid': '123e4567-e89b-12d3-a456-426614174000', 'remote_integer_id': '42'}
@@ -278,11 +278,11 @@ def test_mapping_service_alignment_with_test_data(db_session):
assert result == 42
# [/DEF:test_mapping_service_alignment_with_test_data:Function]
# #endregion test_mapping_service_alignment_with_test_data
# [DEF:test_sync_environment_requires_existing_env:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_sync_environment_requires_existing_env [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_sync_environment_requires_existing_env(db_session):
"""**@PRE**: Verify behavior when environment_id is invalid/missing in DB.
Note: The current implementation doesn't strictly check for environment existencia in the DB
@@ -301,11 +301,11 @@ def test_sync_environment_requires_existing_env(db_session):
assert db_session.query(ResourceMapping).count() == 0
# [/DEF:test_sync_environment_requires_existing_env:Function]
# #endregion test_sync_environment_requires_existing_env
# [DEF:test_sync_environment_deletes_stale_mappings:Function]
# @RELATION: BINDS_TO ->[TestMappingService]
# #region test_sync_environment_deletes_stale_mappings [C:2] [TYPE Function]
# @RELATION BINDS_TO ->[TestMappingService]
def test_sync_environment_deletes_stale_mappings(db_session):
"""Verify that mappings for resources deleted from the remote environment
are removed from the local DB on the next sync cycle."""
@@ -340,5 +340,5 @@ def test_sync_environment_deletes_stale_mappings(db_session):
assert remaining[0].uuid == "aaa"
# [/DEF:test_sync_environment_deletes_stale_mappings:Function]
# [/DEF:TestMappingService:Module]
# #endregion test_sync_environment_deletes_stale_mappings
# #endregion TestMappingService

View File

@@ -1,8 +1,8 @@
# [DEF:TestMigrationEngine:Module]
# #region TestMigrationEngine [C:2] [TYPE Module]
#
# @PURPOSE: Unit tests for MigrationEngine's cross-filter patching algorithms.
# @LAYER: Domain
# @RELATION: VERIFIES -> [src.core.migration_engine:Module]
# @LAYER Domain
# @RELATION BINDS_TO -> [MigrationEngine]
#
import json
import os
@@ -23,8 +23,8 @@ from src.core.migration_engine import MigrationEngine
# --- Fixtures ---
# [DEF:MockMappingService:Class]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region MockMappingService [C:2] [TYPE Class]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Deterministic mapping service double for native filter ID remapping scenarios.
# @INVARIANT: Returns mappings only for requested UUID keys present in seeded map.
class MockMappingService:
@@ -38,15 +38,15 @@ class MockMappingService:
result = {}
for uuid in uuids:
if uuid in self.mappings:
result[uuid] = self.mappings[uuid]
result[EXT:Python:uuid] = self.mappings[EXT:Python:uuid]
return result
# [/DEF:MockMappingService:Class]
# #endregion MockMappingService
# [DEF:_write_dashboard_yaml:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region _write_dashboard_yaml [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Serialize dashboard metadata into YAML fixture with json_metadata payload for patch tests.
def _write_dashboard_yaml(dir_path: Path, metadata: dict) -> Path:
"""Helper: writes a dashboard YAML file with json_metadata."""
@@ -58,11 +58,11 @@ def _write_dashboard_yaml(dir_path: Path, metadata: dict) -> Path:
# --- _patch_dashboard_metadata tests ---
# [/DEF:_write_dashboard_yaml:Function]
# #endregion _write_dashboard_yaml
# [DEF:test_patch_dashboard_metadata_replaces_chart_ids:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_patch_dashboard_metadata_replaces_chart_ids [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Verify native filter target chartId values are remapped via mapping service results.
def test_patch_dashboard_metadata_replaces_chart_ids():
"""Verifies that chartId values are replaced using the mapping service."""
@@ -85,11 +85,11 @@ def test_patch_dashboard_metadata_replaces_chart_ids():
)
# [/DEF:test_patch_dashboard_metadata_replaces_chart_ids:Function]
# #endregion test_patch_dashboard_metadata_replaces_chart_ids
# [DEF:test_patch_dashboard_metadata_replaces_dataset_ids:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_patch_dashboard_metadata_replaces_dataset_ids [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Verify native filter target datasetId values are remapped via mapping service results.
def test_patch_dashboard_metadata_replaces_dataset_ids():
"""Verifies that datasetId values are replaced using the mapping service."""
@@ -113,11 +113,11 @@ def test_patch_dashboard_metadata_replaces_dataset_ids():
)
# [/DEF:test_patch_dashboard_metadata_replaces_dataset_ids:Function]
# #endregion test_patch_dashboard_metadata_replaces_dataset_ids
# [DEF:test_patch_dashboard_metadata_skips_when_no_metadata:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_patch_dashboard_metadata_skips_when_no_metadata [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Ensure dashboard files without json_metadata are left unchanged by metadata patching.
def test_patch_dashboard_metadata_skips_when_no_metadata():
"""Verifies early return when json_metadata key is absent."""
@@ -136,11 +136,11 @@ def test_patch_dashboard_metadata_skips_when_no_metadata():
assert "json_metadata" not in data
# [/DEF:test_patch_dashboard_metadata_skips_when_no_metadata:Function]
# #endregion test_patch_dashboard_metadata_skips_when_no_metadata
# [DEF:test_patch_dashboard_metadata_handles_missing_targets:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_patch_dashboard_metadata_handles_missing_targets [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Verify patching updates mapped targets while preserving unmapped native filter IDs.
def test_patch_dashboard_metadata_handles_missing_targets():
"""When some source IDs have no target mapping, patches what it can and leaves the rest."""
@@ -170,11 +170,11 @@ def test_patch_dashboard_metadata_handles_missing_targets():
# --- _extract_chart_uuids_from_archive tests ---
# [/DEF:test_patch_dashboard_metadata_handles_missing_targets:Function]
# #endregion test_patch_dashboard_metadata_handles_missing_targets
# [DEF:test_extract_chart_uuids_from_archive:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_extract_chart_uuids_from_archive [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Verify chart archive scan returns complete local chart id-to-uuid mapping.
def test_extract_chart_uuids_from_archive():
"""Verifies that chart YAML files are parsed for id->uuid mappings."""
@@ -199,11 +199,11 @@ def test_extract_chart_uuids_from_archive():
# --- _transform_yaml tests ---
# [/DEF:test_extract_chart_uuids_from_archive:Function]
# #endregion test_extract_chart_uuids_from_archive
# [DEF:test_transform_yaml_replaces_database_uuid:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_transform_yaml_replaces_database_uuid [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Ensure dataset YAML database_uuid fields are replaced when source UUID mapping exists.
def test_transform_yaml_replaces_database_uuid():
"""Verifies that database_uuid in a dataset YAML is replaced."""
@@ -222,11 +222,11 @@ def test_transform_yaml_replaces_database_uuid():
assert data["table_name"] == "my_table"
# [/DEF:test_transform_yaml_replaces_database_uuid:Function]
# #endregion test_transform_yaml_replaces_database_uuid
# [DEF:test_transform_yaml_ignores_unmapped_uuid:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_transform_yaml_ignores_unmapped_uuid [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Ensure transform_yaml leaves dataset files untouched when database_uuid is not mapped.
def test_transform_yaml_ignores_unmapped_uuid():
"""Verifies no changes when UUID is not in the mapping."""
@@ -247,11 +247,11 @@ def test_transform_yaml_ignores_unmapped_uuid():
# --- [NEW] transform_zip E2E tests ---
# [/DEF:test_transform_yaml_ignores_unmapped_uuid:Function]
# #endregion test_transform_yaml_ignores_unmapped_uuid
# [DEF:test_transform_zip_end_to_end:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_transform_zip_end_to_end [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Validate full ZIP transform pipeline remaps datasets and dashboard cross-filter chart IDs.
def test_transform_zip_end_to_end():
"""Verifies full orchestration: extraction, transformation, patching, and re-packaging."""
@@ -328,11 +328,11 @@ def test_transform_zip_end_to_end():
)
# [/DEF:test_transform_zip_end_to_end:Function]
# #endregion test_transform_zip_end_to_end
# [DEF:test_transform_zip_invalid_path:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_transform_zip_invalid_path [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Verify transform_zip returns False when source archive path does not exist.
def test_transform_zip_invalid_path():
"""@PRE: Verify behavior (False) on invalid ZIP path."""
@@ -341,11 +341,11 @@ def test_transform_zip_invalid_path():
assert success is False
# [/DEF:test_transform_zip_invalid_path:Function]
# #endregion test_transform_zip_invalid_path
# [DEF:test_transform_yaml_nonexistent_file:Function]
# @RELATION: BINDS_TO -> [TestMigrationEngine:Module]
# #region test_transform_yaml_nonexistent_file [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# @PURPOSE: Verify transform_yaml raises FileNotFoundError for missing YAML source files.
def test_transform_yaml_nonexistent_file():
"""@PRE: Verify behavior on non-existent YAML file."""
@@ -356,5 +356,5 @@ def test_transform_yaml_nonexistent_file():
engine._transform_yaml(Path("non_existent.yaml"), {})
# [/DEF:test_transform_yaml_nonexistent_file:Function]
# [/DEF:TestMigrationEngine:Module]
# #endregion test_transform_yaml_nonexistent_file
# #endregion TestMigrationEngine