shunsuke-sugita commented on code in PR #64879:
URL: https://github.com/apache/airflow/pull/64879#discussion_r3107898791
##########
providers/git/tests/unit/git/bundles/test_git.py:
##########
@@ -920,6 +932,103 @@ def
test_clone_bare_repo_invalid_repository_error_retry_fails(
# Verify Repo was called twice (failed attempt + failed retry)
assert mock_repo_class.call_count == 2
+ @mock.patch("airflow.providers.git.bundles.git.GitHook")
+ def test_fetch_submodules_uses_custom_environment_when_git_ssh_command_set(
+ self, mock_githook_class
+ ):
+ """Non-empty hook.env is passed to custom_environment; submodule runs
inside that context."""
+ expected_ssh_cmd = (
+ "ssh -i /path/key -o IdentitiesOnly=yes -o
UserKnownHostsFile=/path/known_hosts"
+ )
+ mock_hook = mock_githook_class.return_value
+ mock_hook.repo_url = "[email protected]:apache/airflow.git"
+ mock_hook.env = {"GIT_SSH_COMMAND": expected_ssh_cmd}
+
+ mock_git = mock.create_autospec(Git, instance=True)
+ ssh_ctx = mock.create_autospec(_GitCustomEnvContextManager,
instance=True)
+ mock_git.custom_environment.return_value = ssh_ctx
+ mock_repo = mock.MagicMock(spec=Repo)
+ mock_repo.git = mock_git
+
+ bundle = GitDagBundle(
+ name="test",
+ git_conn_id="git_default",
+ tracking_ref="main",
+ version="123456",
+ submodules=True,
+ )
+ bundle.repo = mock_repo
+
+ bundle._fetch_submodules()
+
+
mock_git.custom_environment.assert_called_once_with(GIT_SSH_COMMAND=expected_ssh_cmd)
+ ssh_ctx.__enter__.assert_called_once()
+ ssh_ctx.__exit__.assert_called_once()
+ mock_git.submodule.assert_has_calls(
+ [mock.call("sync", "--recursive"), mock.call("update", "--init",
"--recursive", "--jobs", "1")]
+ )
+
+ @mock.patch("airflow.providers.git.bundles.git.GitHook")
+ def test_fetch_submodules_forwards_full_hook_env_including_passphrase_vars(
+ self, mock_githook_class
+ ):
+ """SSH_ASKPASS / DISPLAY etc. must reach git subprocesses, not only
GIT_SSH_COMMAND."""
+ full_hook_env = {
+ "GIT_SSH_COMMAND": "ssh -i /path/key -o IdentitiesOnly=yes",
+ "SSH_ASKPASS": "/tmp/airflow-git-askpass.sh",
+ "SSH_ASKPASS_REQUIRE": "force",
+ "DISPLAY": ":0",
+ }
+ mock_hook = mock_githook_class.return_value
+ mock_hook.repo_url = "[email protected]:apache/airflow.git"
+ mock_hook.env = full_hook_env
+
+ mock_git = mock.create_autospec(Git, instance=True)
+ ssh_ctx = mock.create_autospec(_GitCustomEnvContextManager,
instance=True)
+ mock_git.custom_environment.return_value = ssh_ctx
+ mock_repo = mock.MagicMock(spec=Repo)
+ mock_repo.git = mock_git
+
+ bundle = GitDagBundle(
+ name="test",
+ git_conn_id="git_default",
+ tracking_ref="main",
+ version="123456",
+ submodules=True,
+ )
+ bundle.repo = mock_repo
+
+ bundle._fetch_submodules()
+
+ mock_git.custom_environment.assert_called_once_with(**full_hook_env)
+
+ @mock.patch("airflow.providers.git.bundles.git.GitHook")
+ def
test_fetch_submodules_skips_custom_environment_without_git_ssh_command(self,
mock_githook_class):
+ """When hook.env is empty, submodule update does not use
custom_environment."""
+ mock_hook = mock_githook_class.return_value
+ mock_hook.repo_url = "[email protected]:apache/airflow.git"
+ mock_hook.env = {}
Review Comment:
This has been fixed on my side. See:
[6d27243](https://github.com/apache/airflow/pull/64879/commits/6d272438c655ed4098d91ed44686d427c6ce0f78)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]