@@ -170,5 +170,35 @@ def test_config_dbt_env_emits_every_dbt_setting():
170170 assert "export G3DT_DB_RAW_GOLD=etl_test_raw_gold_db" in out
171171 assert f"export G3DT_S3_SILVER_DATA_DIR=s3://etl-test-raw-silver-{ ACCOUNT } -{ REGION } /dbt/" in out
172172 assert f"export G3DT_S3_GOLD_DATA_DIR=s3://etl-test-raw-gold-{ ACCOUNT } -{ REGION } /dbt/" in out
173- # no profile configured -> no G3DT_AWS_PROFILE line (ambient credentials)
173+ # no profile configured -> ambient credentials and the default dbt target
174174 assert "G3DT_AWS_PROFILE" not in out
175+ assert "G3DT_DBT_TARGET" not in out
176+
177+
178+ @mock_aws
179+ def test_config_dbt_env_selects_local_target_with_profile (tmp_path , monkeypatch ):
180+ """
181+ Inputs: a marker whose profiles: map covers the env
182+ Expected Output: dbt-env additionally exports G3DT_AWS_PROFILE and
183+ G3DT_DBT_TARGET=local, selecting the profiles.yml target that carries
184+ aws_profile_name — so a laptop run authenticates with the named profile
185+ while CodeBuild (no profiles map) stays on ambient credentials.
186+ """
187+ marker = tmp_path / "g3dt.yaml"
188+ marker .write_text (
189+ "project: etl\n region: ap-southeast-2\n profiles:\n test: etl_test\n "
190+ )
191+ monkeypatch .setenv ("G3DT_MARKER" , str (marker ))
192+ creds = tmp_path / "aws_credentials"
193+ creds .write_text (
194+ "[etl_test]\n aws_access_key_id = testing\n aws_secret_access_key = testing\n "
195+ )
196+ monkeypatch .setenv ("AWS_SHARED_CREDENTIALS_FILE" , str (creds ))
197+ config ._load_yaml_cached .cache_clear ()
198+ resolver .resolve .cache_clear ()
199+
200+ _seed ()
201+ result = runner .invoke (app , ["config" , "dbt-env" , "--env" , "test" ])
202+ assert result .exit_code == 0 , result .output
203+ assert "export G3DT_AWS_PROFILE=etl_test" in result .output
204+ assert "export G3DT_DBT_TARGET=local" in result .output
0 commit comments