chore: migrate GRACE-Poly anchors to hierarchical dotted naming

Systematic rename of all semantic anchors (#region, [DEF], @RELATION)
across 1400+ files — backend Python, frontend Svelte/TS, specs, docs:
- Flat anchors become Namespace.Module.Entity
- @RELATION references updated to match new anchor paths
- Zero business logic changes
This commit is contained in:
root
2026-07-22 11:48:15 +03:00
parent 34393adf7e
commit 632b730fff
1438 changed files with 17031 additions and 16802 deletions

View File

@@ -1,8 +1,8 @@
# #region TestMigrationEngine [C:2] [TYPE Module]
# #region Test.MigrationEngine.TestMigrationEngine [C:2] [TYPE Module]
#
# @PURPOSE: Unit tests for MigrationEngine's cross-filter patching algorithms.
# @LAYER Domain
# @RELATION BINDS_TO -> [MigrationEngine]
# @RELATION BINDS_TO -> [Core.MigrationEngine]
#
import json
import os
@@ -23,8 +23,8 @@ from src.core.migration_engine import MigrationEngine
# --- Fixtures ---
# #region MockMappingService [C:2] [TYPE Class]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.MockMappingService [C:2] [TYPE Class]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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:
@@ -42,11 +42,11 @@ class MockMappingService:
return result
# #endregion MockMappingService
# #endregion Test.MigrationEngine.MockMappingService
# #region _write_dashboard_yaml [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.WriteDashboardYaml [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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 ---
# #endregion _write_dashboard_yaml
# #endregion Test.MigrationEngine.WriteDashboardYaml
# #region test_patch_dashboard_metadata_replaces_chart_ids [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestPatchDashboardMetadataReplacesChartIds [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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():
)
# #endregion test_patch_dashboard_metadata_replaces_chart_ids
# #endregion Test.MigrationEngine.TestPatchDashboardMetadataReplacesChartIds
# #region test_patch_dashboard_metadata_replaces_dataset_ids [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestPatchDashboardMetadataReplacesDatasetIds [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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():
)
# #endregion test_patch_dashboard_metadata_replaces_dataset_ids
# #endregion Test.MigrationEngine.TestPatchDashboardMetadataReplacesDatasetIds
# #region test_patch_dashboard_metadata_skips_when_no_metadata [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestPatchDashboardMetadataSkipsWhenNoMetadata [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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
# #endregion test_patch_dashboard_metadata_skips_when_no_metadata
# #endregion Test.MigrationEngine.TestPatchDashboardMetadataSkipsWhenNoMetadata
# #region test_patch_dashboard_metadata_handles_missing_targets [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestPatchDashboardMetadataHandlesMissingTargets [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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 ---
# #endregion test_patch_dashboard_metadata_handles_missing_targets
# #endregion Test.MigrationEngine.TestPatchDashboardMetadataHandlesMissingTargets
# #region test_extract_chart_uuids_from_archive [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestExtractChartUuidsFromArchive [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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 ---
# #endregion test_extract_chart_uuids_from_archive
# #endregion Test.MigrationEngine.TestExtractChartUuidsFromArchive
# #region test_transform_yaml_replaces_database_uuid [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestTransformYamlReplacesDatabaseUuid [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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"
# #endregion test_transform_yaml_replaces_database_uuid
# #endregion Test.MigrationEngine.TestTransformYamlReplacesDatabaseUuid
# #region test_transform_yaml_ignores_unmapped_uuid [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestTransformYamlIgnoresUnmappedUuid [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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 ---
# #endregion test_transform_yaml_ignores_unmapped_uuid
# #endregion Test.MigrationEngine.TestTransformYamlIgnoresUnmappedUuid
# #region test_transform_zip_end_to_end [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestTransformZipEndToEnd [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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,10 +328,10 @@ def test_transform_zip_end_to_end():
)
# #endregion test_transform_zip_end_to_end
# #endregion Test.MigrationEngine.TestTransformZipEndToEnd
# #region test_transform_zip_keeps_only_referenced_mapped_database [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformZipKeepsOnlyReferencedMappedDatabase [C:2] [TYPE Function]
# @BRIEF An exported archive must not import unused database resources or request their passwords.
# @TEST_EDGE unreferenced_database_with_password -> excluded from transformed archive.
def test_transform_zip_keeps_only_referenced_mapped_database():
@@ -398,11 +398,11 @@ def test_transform_zip_allows_empty_mapping_as_identity():
with zipfile.ZipFile(target) as zf:
dataset = yaml.safe_load(zf.read("datasets/orders.yaml"))
assert dataset["database_uuid"] == "source-db"
# #endregion test_transform_zip_keeps_only_referenced_mapped_database
# #endregion Test.MigrationEngine.TestTransformZipKeepsOnlyReferencedMappedDatabase
# #region test_transform_zip_invalid_path [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestTransformZipInvalidPath [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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."""
@@ -411,43 +411,43 @@ def test_transform_zip_invalid_path():
assert success is False
# #endregion test_transform_zip_invalid_path
# #endregion Test.MigrationEngine.TestTransformZipInvalidPath
# #region test_transform_yaml_nonexistent_file [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [TestMigrationEngine]
# #region Test.MigrationEngine.TestTransformYamlNonexistentFile [C:2] [TYPE Function]
# @RELATION BINDS_TO -> [Test.MigrationEngine.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."""
engine = MigrationEngine()
with pytest.raises(FileNotFoundError):
engine._transform_yaml(Path("non_existent.yaml"), {})
# #endregion test_transform_yaml_nonexistent_file
# #endregion Test.MigrationEngine.TestTransformYamlNonexistentFile
# ── [NEW] Additional coverage: init, edge cases, error paths ──
# #region test_init_belief_scope [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestInitBeliefScope [C:2] [TYPE Function]
# @BRIEF MigrationEngine.__init__ logs reason/reflect via belief_scope.
def test_init_belief_scope():
"""Engine init with mapping_service logs initialization."""
svc = MockMappingService({})
engine = MigrationEngine(svc)
assert engine.mapping_service is svc
# #endregion test_init_belief_scope
# #endregion Test.MigrationEngine.TestInitBeliefScope
# #region test_init_no_mapping_service [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestInitNoMappingService [C:2] [TYPE Function]
# @BRIEF MigrationEngine can be initialized without a mapping_service.
def test_init_no_mapping_service():
"""Engine init without arguments leaves mapping_service as None."""
engine = MigrationEngine()
assert engine.mapping_service is None
# #endregion test_init_no_mapping_service
# #endregion Test.MigrationEngine.TestInitNoMappingService
# #region test_transform_yaml_empty_data [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformYamlEmptyData [C:2] [TYPE Function]
# @BRIEF _transform_yaml with empty YAML (null data) returns early without error.
def test_transform_yaml_empty_data():
"""Empty YAML file does not raise."""
@@ -456,10 +456,10 @@ def test_transform_yaml_empty_data():
fp = Path(td) / "empty.yaml"
fp.write_text("~\n") # null in YAML
engine._transform_yaml(fp, {"src": "tgt"}) # should not raise
# #endregion test_transform_yaml_empty_data
# #endregion Test.MigrationEngine.TestTransformYamlEmptyData
# #region test_transform_yaml_no_matching_uuid [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformYamlNoMatchingUuid [C:2] [TYPE Function]
# @BRIEF _transform_yaml leaves file unchanged when uuid not in db_mapping.
def test_transform_yaml_no_matching_uuid():
"""Non-mapped database_uuid leaves YAML content unchanged."""
@@ -472,10 +472,10 @@ def test_transform_yaml_no_matching_uuid():
with open(fp) as f:
data = yaml.safe_load(f)
assert data["database_uuid"] == "uuid-alpha" # unchanged
# #endregion test_transform_yaml_no_matching_uuid
# #endregion Test.MigrationEngine.TestTransformYamlNoMatchingUuid
# #region test_transform_zip_extract_failure [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformZipExtractFailure [C:2] [TYPE Function]
# @BRIEF When the source ZIP is corrupted, transform_zip returns False.
def test_transform_zip_extract_failure():
"""Corrupt ZIP path returns False."""
@@ -485,10 +485,10 @@ def test_transform_zip_extract_failure():
bad_zip.write_text("this is not a zip file")
result = engine.transform_zip(str(bad_zip), str(Path(td) / "out.zip"), {})
assert result is False
# #endregion test_transform_zip_extract_failure
# #endregion Test.MigrationEngine.TestTransformZipExtractFailure
# #region test_transform_zip_strip_databases [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformZipStripDatabases [C:2] [TYPE Function]
# @BRIEF When strip_databases=True, the databases/ directory is excluded from output.
def test_transform_zip_strip_databases():
"""Databases directory is stripped when strip_databases=True."""
@@ -523,10 +523,10 @@ def test_transform_zip_strip_databases():
names = zf.namelist()
assert not any("databases" in n for n in names)
assert any("datasets" in n for n in names)
# #endregion test_transform_zip_strip_databases
# #endregion Test.MigrationEngine.TestTransformZipStripDatabases
# #region test_transform_zip_cross_filters_no_mapping_service [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformZipCrossFiltersNoMappingService [C:2] [TYPE Function]
# @BRIEF fix_cross_filters=True without mapping_service logs warning, doesn't crash.
def test_transform_zip_cross_filters_no_mapping_service():
"""Cross-filter fix requested but no mapping service — graceful skip."""
@@ -547,10 +547,10 @@ def test_transform_zip_cross_filters_no_mapping_service():
target_env_id="env-1", fix_cross_filters=True,
)
assert success is True
# #endregion test_transform_zip_cross_filters_no_mapping_service
# #endregion Test.MigrationEngine.TestTransformZipCrossFiltersNoMappingService
# #region test_extract_chart_uuids_malformed_yaml [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestExtractChartUuidsMalformedYaml [C:2] [TYPE Function]
# @BRIEF Malformed chart YAML files are skipped without crashing extraction.
def test_extract_chart_uuids_malformed_yaml():
"""Broken chart YAML files do not break the extraction loop."""
@@ -568,20 +568,20 @@ def test_extract_chart_uuids_malformed_yaml():
assert 1 in result
assert result[1] == "abc-123"
assert len(result) == 1 # only the valid one
# #endregion test_extract_chart_uuids_malformed_yaml
# #endregion Test.MigrationEngine.TestExtractChartUuidsMalformedYaml
# #region test_patch_dashboard_missing_file [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestPatchDashboardMissingFile [C:2] [TYPE Function]
# @BRIEF _patch_dashboard_metadata with non-existent file returns early.
def test_patch_dashboard_missing_file():
"""Non-existent dashboard YAML is silently skipped."""
engine = MigrationEngine(MockMappingService({}))
engine._patch_dashboard_metadata(Path("/nonexistent/dash.yaml"), "env-1", {})
# Should not raise
# #endregion test_patch_dashboard_missing_file
# #endregion Test.MigrationEngine.TestPatchDashboardMissingFile
# #region test_patch_dashboard_empty_json_metadata [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestPatchDashboardEmptyJsonMetadata [C:2] [TYPE Function]
# @BRIEF When json_metadata is empty string, patch returns early.
def test_patch_dashboard_empty_json_metadata():
"""Empty json_metadata string is handled gracefully."""
@@ -594,10 +594,10 @@ def test_patch_dashboard_empty_json_metadata():
with open(fp) as f:
data = yaml.safe_load(f)
assert data["json_metadata"] == "" # unchanged
# #endregion test_patch_dashboard_empty_json_metadata
# #endregion Test.MigrationEngine.TestPatchDashboardEmptyJsonMetadata
# #region test_patch_dashboard_no_target_ids [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestPatchDashboardNoTargetIds [C:2] [TYPE Function]
# @BRIEF When mapping_service returns no target IDs, patch returns early.
def test_patch_dashboard_no_target_ids():
"""No remote target IDs — metadata is left unchanged."""
@@ -612,10 +612,10 @@ def test_patch_dashboard_no_target_ids():
with open(fp) as f:
data = yaml.safe_load(f)
assert json.loads(data["json_metadata"]) == metadata # unchanged
# #endregion test_patch_dashboard_no_target_ids
# #endregion Test.MigrationEngine.TestPatchDashboardNoTargetIds
# #region test_patch_dashboard_no_source_match [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestPatchDashboardNoSourceMatch [C:2] [TYPE Function]
# @BRIEF When source IDs don't match any remote IDs, patch returns early.
def test_patch_dashboard_no_source_match():
"""Source IDs not found in remote mapping — metadata unchanged."""
@@ -630,10 +630,10 @@ def test_patch_dashboard_no_source_match():
with open(fp) as f:
data = yaml.safe_load(f)
assert data["json_metadata"] == metadata_json # unchanged
# #endregion test_patch_dashboard_no_source_match
# #endregion Test.MigrationEngine.TestPatchDashboardNoSourceMatch
# #region test_patch_dashboard_exception_handling [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestPatchDashboardExceptionHandling [C:2] [TYPE Function]
# @BRIEF Exception in _patch_dashboard_metadata is caught and logged, not raised.
def test_patch_dashboard_exception_handling():
"""Corrupt json_metadata that fails to parse — exception is caught, not raised."""
@@ -645,10 +645,10 @@ def test_patch_dashboard_exception_handling():
yaml.dump({"json_metadata": "{invalid json]"}, f)
# Should not raise
engine._patch_dashboard_metadata(fp, "env-1", {42: "uuid-42"})
# #endregion test_patch_dashboard_exception_handling
# #endregion Test.MigrationEngine.TestPatchDashboardExceptionHandling
# #region test_patch_dashboard_source_ids_not_in_remote [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestPatchDashboardSourceIdsNotInRemote [C:2] [TYPE Function]
# @BRIEF When target_ids exist but none match source_map UUIDs, patch returns early at line 237.
def test_patch_dashboard_source_ids_not_in_remote():
"""target_ids has entries, but none match source UUIDs → source_to_target empty → skip."""
@@ -668,10 +668,10 @@ def test_patch_dashboard_source_ids_not_in_remote():
with open(fp) as f:
data = yaml.safe_load(f)
assert json.loads(data["json_metadata"]) == metadata # unchanged
# #endregion test_patch_dashboard_source_ids_not_in_remote
# #endregion Test.MigrationEngine.TestPatchDashboardSourceIdsNotInRemote
# #region test_transform_zip_without_fix_cross_filters [C:2] [TYPE Function]
# #region Test.MigrationEngine.TestTransformZipWithoutFixCrossFilters [C:2] [TYPE Function]
# @BRIEF transform_zip works without fixing cross-filters (default).
def test_transform_zip_without_fix_cross_filters():
"""Default fix_cross_filters=False skips dashboard patching."""
@@ -694,6 +694,6 @@ def test_transform_zip_without_fix_cross_filters():
with open(Path(out_dir) / "datasets" / "ds.yaml") as f:
data = yaml.safe_load(f)
assert data["database_uuid"] == "new-uuid"
# #endregion test_transform_zip_without_fix_cross_filters
# #endregion Test.MigrationEngine.TestTransformZipWithoutFixCrossFilters
# #endregion TestMigrationEngine
# #endregion Test.MigrationEngine.TestMigrationEngine