Skip to content

Commit 95d26f8

Browse files
committed
fix(native): keep the finished analysis session out of CompiledProject and gate on session proofs
1 parent 2b13748 commit 95d26f8

7 files changed

Lines changed: 10 additions & 56 deletions

File tree

‎src/sqlbuild/compiler/compile/_helpers/assembly/project.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ def assemble_compiled_project(
498498
),
499499
external_sql_reference_resolver=inputs.external_sql_reference_resolver,
500500
scope_index=scope_index,
501-
native_session=native_session,
502501
)
503502
return complete_semantic_diagnostics(
504503
project=project,

‎src/sqlbuild/rule_engine/_helpers/engine/custom_rules.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ def host_project(project: CompiledProject) -> CompiledProject:
277277
return replace(
278278
project,
279279
binding_catalog=None,
280-
native_session=None,
281280
sql_expansions={},
282281
loaded_macros={},
283282
loader_functions=(),

‎tests/e2e/src/sqlbuild/cli/commands/main/compile/test_native_analysis_seams.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def test_given_project_when_compiling_with_each_engine_then_native_seams_answer_
9393
len(planned_artifacts)
9494
]
9595
assert isinstance(preview_seams["complete_native_semantic_diagnostics"][0], CompiledProject)
96-
assert preview_seams["complete_native_semantic_diagnostics"][0].native_session is not None
9796
assert isinstance(preview_seams["evaluate_native_model_contracts"][0], ContractValidationResult)
9897
assert (native_run.returncode, preview_run.returncode) == (0, 0)
9998
assert report_without_engine(native_run) == report_without_engine(python_run)

‎tests/integration/src/sqlbuild/compiler/analysis_session/_test_types.py‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,5 @@ class StandalonePivotProofTestCase:
4848
description: str
4949
analysed_models: frozenset[str]
5050
expected_native_proofs: int
51-
expected_session_answers: list[bool]
51+
expected_session_proofs: int
5252
expected_proven_by_model: dict[str, bool | None]
53-
54-
55-
@dataclass(frozen=True)
56-
class HostPayloadTestCase:
57-
"""A natively analysed project that custom-rule hosts receive without its native session."""
58-
59-
description: str
60-
expected_models: tuple[str, ...]

‎tests/integration/src/sqlbuild/compiler/analysis_session/helpers.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,10 @@ def pivot_project_files() -> dict[str, str]:
307307

308308
@dataclass
309309
class NativePivotProofs:
310-
"""Every standalone native pivot proof assembly took, and whether a session answered it."""
310+
"""Every native pivot proof assembly took, and how many a finished session proved."""
311311

312312
proofs: list[DynamicColumnContractProof | None] = field(default_factory=list)
313-
session_answers: list[bool] = field(default_factory=list)
313+
session_proofs: int = 0
314314

315315

316316
def native_pivot_proofs(*, monkeypatch: pytest.MonkeyPatch) -> NativePivotProofs:
@@ -324,7 +324,8 @@ def native_pivot_proofs(*, monkeypatch: pytest.MonkeyPatch) -> NativePivotProofs
324324
def recorded(**keywords: Any) -> tuple[DynamicColumnContractProof | None, ...]:
325325
proofs: tuple[DynamicColumnContractProof | None, ...] = native_proofs(**keywords)
326326
recorded_proofs.proofs.extend(proofs)
327-
recorded_proofs.session_answers.extend([keywords["session"] is not None] * len(proofs))
327+
proven: int = sum(proof is not None for proof in proofs)
328+
recorded_proofs.session_proofs += proven * (keywords["session"] is not None)
328329
return proofs
329330

330331
python_proof: Callable[..., DynamicColumnContractProof | None] = (

‎tests/integration/src/sqlbuild/compiler/analysis_session/test_native_model_analysis.py‎

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import pickle
65
import random
76
from collections import Counter
87
from dataclasses import replace
@@ -23,12 +22,9 @@
2322
from sqlbuild.compiler.frontier.constants import COMPILER_ENGINE_ENV_VAR
2423
from sqlbuild.compiler.frontier.types import CompilerEngine
2524
from sqlbuild.compiler.sql_analysis.constants import ANALYSIS_RECORD_DIR_ENV_VAR
26-
from sqlbuild.rule_engine._helpers.engine.custom_rules import host_project
27-
from sqlbuild.rule_engine._helpers.host.custom_host_pool import host_payload_project
2825
from tests.integration.src.sqlbuild.compiler.analysis_session._test_types import (
2926
AnalysisFallbackTestCase,
3027
GeneratedAnalysisParityTestCase,
31-
HostPayloadTestCase,
3228
SessionFailureTestCase,
3329
StandalonePivotProofTestCase,
3430
)
@@ -204,7 +200,7 @@ def test_given_session_failure_after_deferrals_when_analysing_then_records_only_
204200
description="a selection that leaves the pivots out of model analysis",
205201
analysed_models=frozenset({"orders_list"}),
206202
expected_native_proofs=2,
207-
expected_session_answers=[True, True],
203+
expected_session_proofs=2,
208204
expected_proven_by_model={
209205
"orders_list": None,
210206
"status_amounts": True,
@@ -215,7 +211,7 @@ def test_given_session_failure_after_deferrals_when_analysing_then_records_only_
215211
description="no model analysis, so the proofs run without a session",
216212
analysed_models=frozenset(),
217213
expected_native_proofs=2,
218-
expected_session_answers=[False, False],
214+
expected_session_proofs=0,
219215
expected_proven_by_model={
220216
"orders_list": None,
221217
"status_amounts": True,
@@ -243,50 +239,18 @@ def test_given_unanalysed_pivot_model_when_assembling_then_native_proves_it_with
243239
assert (
244240
all(proof is not None for proof in recorded.proofs),
245241
len(recorded.proofs),
246-
recorded.session_answers,
242+
recorded.session_proofs,
247243
{
248244
model.name: getattr(model.dynamic_column_contract, "output_proven", None)
249245
for model in project.models
250246
},
251247
) == (
252248
True,
253249
test_case.expected_native_proofs,
254-
test_case.expected_session_answers,
250+
test_case.expected_session_proofs,
255251
test_case.expected_proven_by_model,
256252
)
257253

258254

259-
@pytest.mark.parametrize(
260-
"test_case",
261-
[
262-
HostPayloadTestCase(
263-
description="a pivot project analysed in one native session",
264-
expected_models=("orders_list", "status_amounts", "status_passthrough"),
265-
)
266-
],
267-
ids=lambda case: case.description,
268-
)
269-
def test_given_native_session_when_publishing_rule_host_payload_then_session_is_dropped(
270-
test_case: HostPayloadTestCase, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
271-
) -> None:
272-
inputs: CompileProjectInputs = compile_inputs(
273-
project_dir=tmp_path / "project", files=pivot_project_files()
274-
)
275-
monkeypatch.setenv(COMPILER_ENGINE_ENV_VAR, CompilerEngine.NATIVE_PREVIEW.value)
276-
project: CompiledProject = assemble_compiled_project(
277-
inputs=inputs, inference_profile=ExpressionInferenceProfile(sql_analysis_dialect="duckdb")
278-
)
279-
280-
payload: CompiledProject = pickle.loads(
281-
pickle.dumps(host_payload_project(host_project(project)))
282-
)
283-
284-
assert project.native_session is not None
285-
assert (payload.native_session, tuple(sorted(model.name for model in payload.models))) == (
286-
None,
287-
test_case.expected_models,
288-
)
289-
290-
291255
if __name__ == "__main__":
292256
pytest.main([__file__, "-vv"])

‎tests/integration/src/sqlbuild/rule_engine/host_payload/test_host_payload_facts.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"SELECT 1\n"
101101
),
102102
},
103-
expected_unpopulated_trimmed_fields=frozenset({"native_session"}),
103+
expected_unpopulated_trimmed_fields=frozenset(),
104104
),
105105
),
106106
ids=lambda case: case.description,

0 commit comments

Comments
 (0)