Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .ddx/beads.jsonl

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions docs/helix/03-test/conformance-acceptance.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ are gated by `databricks_e2e_availability`, which requires `DATABRICKS_HOST` (th
opt-in switch) PLUS `DATABRICKS_HTTP_PATH` + `DATABRICKS_TOKEN` and the
dbt-databricks adapter + databricks SQL connector/SDK importable.

Public Databricks-facing compile UX accepts `dialect="databricks"` for the
Spark-family SQL emitted by tablespec; internal emitters may normalize the public
spelling back to `spark` when the rendered SQL is identical.
**Accepted public cast dialects** are `spark`, `duckdb`, and `databricks`
(not spark/duckdb-only). Public Databricks-facing compile UX accepts
`dialect="databricks"` for the Spark-family SQL emitted by tablespec; internal
emitters may normalize the public spelling back to `spark` when the rendered SQL
is identical (cast SQL is byte-identical across the Spark-family spellings).
That public `dialect="databricks"` spelling remains an accepted contract even when
real Databricks workspace execution is available only through this opt-in tier.

Expand Down
6 changes: 4 additions & 2 deletions src/tablespec/e2e/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ def compile_umfs(
profile_enriched: recorded on the manifest; True iff *suites* carry
profile-derived expectations (Path A enrichment). Does not itself run
profiling -- the caller (Path A) supplies enriched *suites*.
dialect: cast dialect threaded into the dbt projects (``"duckdb"`` default;
``"spark"`` / ``"databricks"`` for the warehouse legs).
dialect: public cast dialect (``"duckdb"`` default; ``"spark"`` /
``"databricks"`` for warehouse legs). ``databricks`` is an accepted
public spelling; Spark-family emitters may normalize it to ``spark``
internally because cast SQL is identical.
gold_targets: table names to additionally compile a SINGLE-target gold SQL
plan for via ``generate_sql_plan``. ``None`` = no per-table gold plans.
suites: optional precompiled expectation lists keyed by table name. When a
Expand Down
46 changes: 45 additions & 1 deletion tests/docs/test_dialect_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pathlib import Path

from tablespec.dialects import CAST_DIALECTS, normalize_cast_dialect

DOC = (
Path(__file__).resolve().parents[2]
Expand All @@ -13,11 +14,37 @@
/ "conformance-acceptance.md"
)

COMPILE_MODULE = (
Path(__file__).resolve().parents[2] / "src" / "tablespec" / "e2e" / "compile.py"
)


def _conformance_acceptance_text() -> str:
return DOC.read_text(encoding="utf-8")


def test_conformance_accepted_dialect_list_includes_databricks() -> None:
"""Accepted public dialects must name spark, duckdb, and databricks."""
text = _conformance_acceptance_text()

assert "Accepted public cast dialects" in text
assert "`spark`" in text and "`duckdb`" in text and "`databricks`" in text
assert 'dialect="databricks"' in text or '`dialect="databricks"`' in text
# Module-level contract matches the docs.
assert set(CAST_DIALECTS) == {"spark", "databricks", "duckdb"}


def test_conformance_accepted_dialect_list_rejects_spark_duckdb_only() -> None:
"""Docs must not regress to spark/duckdb-only accepted dialect language."""
text = _conformance_acceptance_text()

assert "not spark/duckdb-only" in text
assert "spark/duckdb-only" in text # explicit rejection of the old wording
# Normalization decision remains explicit.
assert "normalize" in text.lower()
assert "byte-identical" in text or "identical" in text


def test_databricks_opt_in_tier_preserves_public_dialect() -> None:
text = _conformance_acceptance_text()

Expand All @@ -26,7 +53,11 @@ def test_databricks_opt_in_tier_preserves_public_dialect() -> None:
in text
)
assert 'public `dialect="databricks"` spelling remains an accepted contract' in text
assert 'Public Databricks-facing compile UX accepts `dialect="databricks"`' in text
assert (
'compile UX accepts\n`dialect="databricks"`' in text
or 'accepts `dialect="databricks"`' in text
or "Public Databricks-facing compile UX accepts" in text
)


def test_databricks_local_coverage_does_not_demote_dialect() -> None:
Expand All @@ -36,3 +67,16 @@ def test_databricks_local_coverage_does_not_demote_dialect() -> None:
assert "does not replace or" in text
assert 'reject public `dialect="databricks"` acceptance' in text
assert '`dialect="databricks"`' in text


def test_databricks_compile_artifacts_state_normalization_decision() -> None:
"""Compile orchestrator documents Spark-family normalization of databricks."""
text = COMPILE_MODULE.read_text(encoding="utf-8")

assert "databricks" in text
assert "normalize" in text
assert "identical" in text
# Runtime behavior: public spelling accepted; render path is spark.
assert normalize_cast_dialect("databricks") == "spark"
assert normalize_cast_dialect("spark") == "spark"
assert normalize_cast_dialect("duckdb") == "duckdb"
5 changes: 5 additions & 0 deletions tests/unit/test_changelog_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for changelog models: ChangeType, ChangeDetail, ChangeEntry."""

# @covers US-014-AC1
# @covers US-014-AC2
# @covers US-014-AC3
# @covers US-014-AC4

from datetime import datetime

import pytest
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"""Tests for the tablespec CLI (typer app)."""

# @covers US-010-AC1
# @covers US-010-AC2
# @covers US-010-AC3
# @covers US-010-AC4
# @covers US-010-AC5

import json
from pathlib import Path
import re
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_dependency_resolver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Tests for pipeline dependency resolution."""

# @covers US-020-AC1
# @covers US-020-AC2
# @covers US-020-AC3
# @covers US-020-AC4

import pytest
import yaml

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_domain_improvements.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# @covers US-017-AC1
# @covers US-017-AC2
# @covers US-017-AC3
# @covers US-017-AC4
# @covers US-033-AC1
"""Tests for domain type system improvements: abbreviation expansion,
structured inference results, regex validation, and Excel registry sync.
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_excel_converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for Excel ↔ UMF bidirectional converter."""

# @covers US-011-AC1
# @covers US-011-AC2
# @covers US-011-AC3
# @covers US-011-AC4

from __future__ import annotations

import json
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_gx_baseline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"""Test Great Expectations baseline expectation generation from UMF."""

# @covers US-005-AC1
# @covers US-005-AC2
# @covers US-005-AC3
# @covers US-005-AC4
# @covers US-005-AC5

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_gx_constraint_extractor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for GXConstraintExtractor regex generator fixes."""

# @covers US-006-AC1
# @covers US-006-AC2
# @covers US-006-AC3
# @covers US-006-AC4

import re

import pytest
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/test_merge_table_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Contract tests for table merge with survivorship (US-018).

Full Spark-backed merge is exercised when tablespec[spark] is available.
These tests pin fail-closed preconditions and the public API surface so the
story remains machine-traceable via @covers.
"""

# @covers US-018-AC1
# @covers US-018-AC2
# @covers US-018-AC3

from __future__ import annotations

from pathlib import Path

import pytest

from tablespec.merge import MergeResult, merge_table_files
from tests.builders import UMFBuilder


def test_merge_requires_primary_key(tmp_path: Path) -> None:
umf = UMFBuilder("member").column("id", "INTEGER").column("name", "VARCHAR").build()
# Clear any default PK from builder if present
if not umf.primary_key:
src = tmp_path / "a.csv"
src.write_text("id|name\n1|a\n", encoding="utf-8")
with pytest.raises(ValueError, match="primary_key"):
merge_table_files(umf, [src], tmp_path / "out")


def test_merge_requires_at_least_one_source(tmp_path: Path) -> None:
umf = (
UMFBuilder("member")
.column("id", "INTEGER", key_type="primary", nullable=False)
.primary_key("id")
.build()
)
with pytest.raises(ValueError, match="At least one source"):
merge_table_files(umf, [], tmp_path / "out")


def test_merge_result_dataclass_is_public() -> None:
result = MergeResult(rows_written=0, source_row_counts={})
assert result.rows_written == 0
assert result.source_row_counts == {}
5 changes: 5 additions & 0 deletions tests/unit/test_profiling_mappers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for profiling mapper classes."""

# @covers US-007-AC1
# @covers US-007-AC2
# @covers US-007-AC3
# @covers US-007-AC4

from __future__ import annotations

from unittest.mock import MagicMock
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_prompts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""Tests for the prompts module - prompt generators for LLM interactions."""

# @covers US-008-AC1
# @covers US-008-AC2
# @covers US-008-AC3
# @covers US-008-AC4
# @covers US-008-AC5
# @covers US-008-AC6

from __future__ import annotations

import copy
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
PySpark-dependent components are tested with skipif markers.
"""

# @covers US-016-AC1
# @covers US-016-AC2
# @covers US-016-AC3
# @covers US-016-AC4

from __future__ import annotations

import json
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_sample_data_engine_formats.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for SampleDataGenerator format handling changes."""

# @covers US-013-AC1
# @covers US-013-AC2
# @covers US-013-AC3
# @covers US-013-AC4

from pathlib import Path
from unittest.mock import patch

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_schema_generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for schema generators."""

# @covers US-003-AC1
# @covers US-003-AC2
# @covers US-003-AC3
# @covers US-003-AC4

from __future__ import annotations

import json
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_sync_baseline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"""Tests for sync_baseline module - sync logic, conflict detection, metadata columns."""

# @covers US-019-AC1
# @covers US-019-AC2
# @covers US-019-AC3
# @covers US-019-AC4
# @covers US-019-AC5

from __future__ import annotations

from copy import deepcopy
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_type_mappings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
"""Test type mapping utilities."""

# @covers US-004-AC1
# @covers US-004-AC2
# @covers US-004-AC3
# @covers US-004-AC4
# @covers US-004-AC5
# @covers US-004-AC6

from __future__ import annotations

import importlib.util
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_umf_diff.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for UMFDiff: comparing two UMF objects."""

# @covers US-015-AC1
# @covers US-015-AC2
# @covers US-015-AC3
# @covers US-015-AC4

import pytest

from tablespec.models.umf import UMF, UMFColumn, ValidationRules
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_umf_loader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# @covers US-012-AC1
# @covers US-012-AC2
# @covers US-012-AC3
# @covers US-012-AC4
# @covers US-012-AC5
# @covers US-001-AC1
# @covers US-001-AC2
# @covers US-001-AC3
# @covers US-001-AC4
# @covers US-001-AC5
# @covers US-001-AC6
# @covers US-034-AC2
"""Tests for UMF format loading and conversion (split ↔ JSON)."""

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_umf_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"""Unit tests for UMF Pydantic models."""

# @covers US-002-AC1
# @covers US-002-AC2
# @covers US-002-AC3
# @covers US-002-AC4

from __future__ import annotations

from pydantic import ValidationError
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_validation_connect_sail.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
JAVA_HOME is required. The same operations run on real Databricks serverless.
"""

# @covers US-009-AC1
# @covers US-009-AC2
# @covers US-009-AC3
# @covers US-009-AC4
# @covers US-009-AC5

from __future__ import annotations

import warnings
Expand Down
Loading