@@ -534,5 +534,113 @@ def test_given_unresolved_additive_type_conflict_when_writing_then_file_is_not_r
534534 assert model_path .read_text (encoding = "utf-8" ) == original
535535
536536
537+ @pytest .mark .parametrize (
538+ "test_case" ,
539+ [
540+ ContractCommandIntegrationTestCase (
541+ description = "relative project directory preserves private macro scope" ,
542+ expected_exit_code = 1 ,
543+ )
544+ ],
545+ ids = lambda case : case .description ,
546+ )
547+ def test_given_relative_project_directory_when_diffing_contract_then_private_macro_is_visible (
548+ test_case : ContractCommandIntegrationTestCase ,
549+ tmp_path : Path ,
550+ monkeypatch : pytest .MonkeyPatch ,
551+ capsys : pytest .CaptureFixture [str ],
552+ ) -> None :
553+ project_dir : Path = tmp_path / "project"
554+ project_dir .mkdir ()
555+ _ = prepare_contract_project (project_dir )
556+ root_model_path : Path = project_dir / "models" / "orders.sql"
557+ root_model_path .unlink ()
558+ model_path : Path = project_dir / "models" / "orders" / "orders.sql"
559+ model_path .parent .mkdir ()
560+ _ = model_path .write_text (
561+ "MODEL (materialized table);\n SELECT @order_id() AS id, CAST('a' AS VARCHAR) AS name\n " ,
562+ encoding = "utf-8" ,
563+ )
564+ macro_path : Path = model_path .parent / "_sqlbuild" / "_macros" / "order_id.py"
565+ macro_path .parent .mkdir (parents = True )
566+ _ = macro_path .write_text (
567+ 'def order_id() -> str:\n return "CAST(1 AS INTEGER)"\n ' , encoding = "utf-8"
568+ )
569+ monkeypatch .chdir (tmp_path )
570+
571+ exit_code : int = main (
572+ [
573+ "--no-color" ,
574+ "--project-dir" ,
575+ project_dir .name ,
576+ "contract" ,
577+ "diff" ,
578+ "--from" ,
579+ "prod" ,
580+ "--select" ,
581+ "orders" ,
582+ ]
583+ )
584+
585+ captured : CaptureResult [str ] = capsys .readouterr ()
586+ assert exit_code == test_case .expected_exit_code
587+ assert "model:orders" in captured .out
588+ assert "inaccessible" not in captured .err
589+
590+
591+ @pytest .mark .parametrize (
592+ "test_case" ,
593+ [
594+ ContractCommandIntegrationTestCase (
595+ description = "indentless source column sequence receives physical types" ,
596+ expected_exit_code = 0 ,
597+ )
598+ ],
599+ ids = lambda case : case .description ,
600+ )
601+ def test_given_indentless_source_columns_when_generating_then_preserves_metadata_and_adds_types (
602+ test_case : ContractCommandIntegrationTestCase ,
603+ tmp_path : Path ,
604+ capsys : pytest .CaptureFixture [str ],
605+ ) -> None :
606+ _ = prepare_contract_project (tmp_path )
607+ source_path : Path = tmp_path / "sources" / "raw.yml"
608+ _ = source_path .write_text (
609+ """sources:
610+ - name: raw_orders
611+ schema: raw
612+ table: orders
613+ description: keep source
614+ columns:
615+ - name: id
616+ description: identifier
617+ """ ,
618+ encoding = "utf-8" ,
619+ )
620+
621+ exit_code : int = main (
622+ [
623+ "--no-color" ,
624+ "--project-dir" ,
625+ str (tmp_path ),
626+ "contract" ,
627+ "generate" ,
628+ "--from" ,
629+ "prod" ,
630+ "--select" ,
631+ "source:raw_orders" ,
632+ "--write" ,
633+ ]
634+ )
635+
636+ source_yaml : str = source_path .read_text (encoding = "utf-8" )
637+ assert exit_code == test_case .expected_exit_code
638+ assert "0 contract difference(s)" in capsys .readouterr ().out
639+ assert "description: keep source" in source_yaml
640+ assert "description: identifier" in source_yaml
641+ assert " - name: id\n type: 'BIGINT'" in source_yaml
642+ assert " - name: status\n type: 'VARCHAR'" in source_yaml
643+
644+
537645if __name__ == "__main__" :
538646 pytest .main ([__file__ , "-vv" ])
0 commit comments