|
10 | 10 | import pytest |
11 | 11 |
|
12 | 12 | from sqlbuild.cli.commands.main.entrypoint.entry import main |
| 13 | +from sqlbuild.compiler.frontier.constants import COMPILER_ENGINE_ENV_VAR |
13 | 14 | from tests.integration.src.sqlbuild.cli.commands.main._test_types import ( |
| 15 | + FixSessionTestCase, |
14 | 16 | FormatCompileIntegrationTestCase, |
15 | 17 | SemanticFixTestCase, |
16 | 18 | UnusedOutputDifferentialCase, |
17 | 19 | ) |
18 | 20 | from tests.integration.src.sqlbuild.cli.commands.main.helpers import ( |
19 | 21 | built_model_rows, |
| 22 | + record_fix_sessions, |
20 | 23 | rule_fix_statuses, |
21 | 24 | ) |
22 | 25 |
|
|
31 | 34 | ) |
32 | 35 |
|
33 | 36 |
|
| 37 | +@pytest.mark.parametrize( |
| 38 | + "test_case", |
| 39 | + [ |
| 40 | + FixSessionTestCase( |
| 41 | + description="preview fix passes drop the session of the unfixed files", |
| 42 | + engine="native-preview", |
| 43 | + expected_original_sessions=(True,), |
| 44 | + expected_fix_pass_sessions=frozenset({False}), |
| 45 | + ), |
| 46 | + ], |
| 47 | + ids=lambda case: case.description, |
| 48 | +) |
| 49 | +def test_given_retained_native_session_when_fixing_then_fix_passes_never_reuse_it( |
| 50 | + test_case: FixSessionTestCase, |
| 51 | + tmp_path: Path, |
| 52 | + capsys: pytest.CaptureFixture[str], |
| 53 | + monkeypatch: pytest.MonkeyPatch, |
| 54 | +) -> None: |
| 55 | + (tmp_path / "sqlbuild_project.toml").write_text('name = "orders"\nadapter = "duckdb"\n') |
| 56 | + model: Path = tmp_path / "models" / "orders.sql" |
| 57 | + model.parent.mkdir() |
| 58 | + model.write_text( |
| 59 | + 'MODEL (description "Orders");\nSELECT 1 AS order_id UNION SELECT 2 AS order_id\n' |
| 60 | + ) |
| 61 | + monkeypatch.setenv(COMPILER_ENGINE_ENV_VAR, test_case.engine) |
| 62 | + original, passes = record_fix_sessions(monkeypatch) |
| 63 | + |
| 64 | + exit_code: int = main(["--project-dir", str(tmp_path), "format", "--fix", "--json"]) |
| 65 | + |
| 66 | + capsys.readouterr() |
| 67 | + assert exit_code == 0 |
| 68 | + assert tuple(original) == test_case.expected_original_sessions |
| 69 | + assert frozenset(passes) == test_case.expected_fix_pass_sessions |
| 70 | + |
| 71 | + |
34 | 72 | @pytest.mark.parametrize( |
35 | 73 | "test_case", |
36 | 74 | [FormatCompileIntegrationTestCase("bare union", "UNION DISTINCT")], |
|
0 commit comments