Option C Tools
Loading...
Searching...
No Matches
tests_core.test_git Namespace Reference

Classes

class  _FakeCompleted

Functions

bool _platform_can_symlink ()
 test_git_error_is_base_of_all_subclasses ()
 test_git_command_error_preserves_context ()
 test_redact_strips_http_creds ()
 test_redact_strips_https_creds ()
 test_redact_preserves_ssh_urls ()
 test_redact_handles_empty_string ()
 test_redact_handles_none_safely ()
 test_redact_multiline_output ()
 test_redact_preserves_non_url_content ()
 test_redact_argv_redacts_url_elements ()
 test_redact_argv_noop_for_plain_argv ()
 test_git_run_dbg_does_not_leak_token (tmp_path, monkeypatch, caplog)
 test_git_command_error_str_redacts_token_in_argv ()
 test_timeout_message_redacts_token (tmp_path, monkeypatch)
 test_git_run_rejects_non_list_argv (tmp_path)
 test_git_run_happy_path (tmp_path, monkeypatch)
 test_git_run_raises_git_not_found (tmp_path, monkeypatch)
 test_git_run_raises_timeout (tmp_path, monkeypatch)
 test_git_run_raises_on_nonzero_exit (tmp_path, monkeypatch)
 test_git_run_nocheck_returns_process (tmp_path, monkeypatch)
 test_git_run_redacts_stderr_on_error (tmp_path, monkeypatch)
 test_git_run_redacts_stdout_on_success (tmp_path, monkeypatch)
 test_is_git_repo_true_inside_repo (git_repo)
 test_is_git_repo_false_outside_repo (tmp_path)
 test_is_git_repo_false_when_git_missing (tmp_path, monkeypatch)
 test_is_git_repo_false_on_any_exception (tmp_path, monkeypatch)
 test_get_repo_root_returns_absolute_path (git_repo)
 test_get_repo_root_raises_not_a_repo (tmp_path)
 test_current_branch_returns_name (git_repo)
 test_is_detached_head_false_on_branch (git_repo)
 test_is_detached_head_true_after_checkout_sha (git_repo)
 test_has_uncommitted_changes_false_on_clean_repo (git_repo)
 test_has_uncommitted_changes_true_after_edit (git_repo)
 test_has_untracked_files_false_on_fresh_repo (git_repo)
 test_has_untracked_files_true_for_new_file (git_repo)
 test_git_changed_files_returns_absolute_paths (git_repo)
 test_git_changed_files_filters_by_extension (git_repo)
 test_git_changed_files_empty_on_clean_repo (git_repo)
 test_git_staged_files_only_returns_staged (git_repo)
 test_last_commit_sha_empty_on_fresh_repo (git_repo)
 test_last_commit_sha_full_and_short (git_repo)
 test_last_commit_message_empty_on_fresh_repo (git_repo)
 test_last_commit_message_returns_subject (git_repo)
 test_remote_urls_empty_on_fresh_repo (git_repo)
 test_remote_urls_redacts_http_creds (git_repo)
 test_is_within_project_root_true_for_child (tmp_path)
 test_is_within_project_root_true_for_self (tmp_path)
 test_is_within_project_root_false_for_sibling (tmp_path)
 test_is_within_project_root_handles_nonexistent_paths (tmp_path)
 test_is_within_project_root_false_for_symlink_escape (tmp_path)
 test_git_changed_files_filters_out_path_escapes (git_repo, tmp_path)
 test_legacy_shim_returns_empty_on_missing_git (tmp_path, monkeypatch)
 test_legacy_shim_returns_empty_on_not_a_repo (tmp_path, monkeypatch)
 test_legacy_shim_returns_empty_on_command_error (tmp_path, monkeypatch)
 test_legacy_shim_passes_py_extension_filter (tmp_path, monkeypatch)

Variables

bool _CAN_SYMLINK = _platform_can_symlink()
tuple _SYMLINK_SKIP_REASON
str _TOKEN_URL = "https://oauth2:ghp_SUPERSECRET@github.com/foo/bar.git"

Detailed Description

Purpose
-------
Validate the V4.0 Phase 4A Git integration foundation in
``oct.core.git``: exception hierarchy, subprocess discipline,
credential redaction, and the 11 read-only state query functions.

Responsibilities
----------------
- Confirm the ``GitError`` hierarchy (G-A1).
- Confirm ``git_run`` enforces argv-only, timeout, text mode, utf-8
  with ``errors="replace"``, and translates subprocess failures to
  ``GitNotFoundError`` / ``GitTimeoutError`` / ``GitCommandError``
  (G-A2).
- Confirm every query function behaves correctly against a real git
  repo, raising the right error on missing repo / missing binary
  (G-A3).
- Confirm path-escape filtering in ``git_changed_files`` and
  ``git_staged_files`` (G-A3 + G-A4 defense-in-depth).
- Confirm ``_redact_git_url`` scrubs http(s) credentials while leaving
  SSH URLs intact (G-A5).
- Confirm ``_git_changed_files`` shim in the linter continues to
  return ``[]`` on all ``GitError`` subtypes (G-A7).

Diagnostics
-----------
Domain: CORE-TESTS
Levels:
    L2 — test lifecycle
    L3 — per-case setup
    L4 — fine-grained assertions

Contracts
---------
- Tests never write outside of ``tmp_path`` / pytest-managed temp dirs.
- Tests that require a real ``git`` binary are skipped via the
  ``git_repo`` fixture when git is missing.
- Symlink tests skip when the platform cannot create symlinks.

Function Documentation

◆ _platform_can_symlink()

bool tests_core.test_git._platform_can_symlink ( )
protected
Probe whether this process can create a real OS symlink.

Equivalent to the session-scoped ``can_symlink`` fixture in
``tests_core/conftest.py`` but evaluated at module import so the
result is usable in ``@pytest.mark.skipif`` decorators (which run
at collection time and cannot consume runtime fixtures). On
Windows without admin elevation or developer-mode this returns
``False``; on POSIX it returns ``True`` unless the filesystem
refuses the syscall (e.g. some FAT mounts).

Definition at line 54 of file test_git.py.

◆ test_current_branch_returns_name()

tests_core.test_git.test_current_branch_returns_name ( git_repo)

Definition at line 388 of file test_git.py.

◆ test_get_repo_root_raises_not_a_repo()

tests_core.test_git.test_get_repo_root_raises_not_a_repo ( tmp_path)

Definition at line 383 of file test_git.py.

◆ test_get_repo_root_returns_absolute_path()

tests_core.test_git.test_get_repo_root_returns_absolute_path ( git_repo)

Definition at line 379 of file test_git.py.

◆ test_git_changed_files_empty_on_clean_repo()

tests_core.test_git.test_git_changed_files_empty_on_clean_repo ( git_repo)

Definition at line 449 of file test_git.py.

◆ test_git_changed_files_filters_by_extension()

tests_core.test_git.test_git_changed_files_filters_by_extension ( git_repo)

Definition at line 441 of file test_git.py.

◆ test_git_changed_files_filters_out_path_escapes()

tests_core.test_git.test_git_changed_files_filters_out_path_escapes ( git_repo,
tmp_path )
``git_changed_files`` must filter symlinks that escape the repo.

Skipped on platforms without symlink capability — this is an
environmental constraint, not a defect in the tested behaviour.

Definition at line 555 of file test_git.py.

◆ test_git_changed_files_returns_absolute_paths()

tests_core.test_git.test_git_changed_files_returns_absolute_paths ( git_repo)

Definition at line 433 of file test_git.py.

◆ test_git_command_error_preserves_context()

tests_core.test_git.test_git_command_error_preserves_context ( )

Definition at line 120 of file test_git.py.

◆ test_git_command_error_str_redacts_token_in_argv()

tests_core.test_git.test_git_command_error_str_redacts_token_in_argv ( )

Definition at line 223 of file test_git.py.

◆ test_git_error_is_base_of_all_subclasses()

tests_core.test_git.test_git_error_is_base_of_all_subclasses ( )

Definition at line 113 of file test_git.py.

◆ test_git_run_dbg_does_not_leak_token()

tests_core.test_git.test_git_run_dbg_does_not_leak_token ( tmp_path,
monkeypatch,
caplog )
_dbg logs argv before the subprocess runs; it must be redacted.

Definition at line 203 of file test_git.py.

◆ test_git_run_happy_path()

tests_core.test_git.test_git_run_happy_path ( tmp_path,
monkeypatch )

Definition at line 267 of file test_git.py.

◆ test_git_run_nocheck_returns_process()

tests_core.test_git.test_git_run_nocheck_returns_process ( tmp_path,
monkeypatch )

Definition at line 312 of file test_git.py.

◆ test_git_run_raises_git_not_found()

tests_core.test_git.test_git_run_raises_git_not_found ( tmp_path,
monkeypatch )

Definition at line 286 of file test_git.py.

◆ test_git_run_raises_on_nonzero_exit()

tests_core.test_git.test_git_run_raises_on_nonzero_exit ( tmp_path,
monkeypatch )

Definition at line 302 of file test_git.py.

◆ test_git_run_raises_timeout()

tests_core.test_git.test_git_run_raises_timeout ( tmp_path,
monkeypatch )

Definition at line 294 of file test_git.py.

◆ test_git_run_redacts_stderr_on_error()

tests_core.test_git.test_git_run_redacts_stderr_on_error ( tmp_path,
monkeypatch )

Definition at line 320 of file test_git.py.

◆ test_git_run_redacts_stdout_on_success()

tests_core.test_git.test_git_run_redacts_stdout_on_success ( tmp_path,
monkeypatch )

Definition at line 334 of file test_git.py.

◆ test_git_run_rejects_non_list_argv()

tests_core.test_git.test_git_run_rejects_non_list_argv ( tmp_path)

Definition at line 262 of file test_git.py.

◆ test_git_staged_files_only_returns_staged()

tests_core.test_git.test_git_staged_files_only_returns_staged ( git_repo)

Definition at line 455 of file test_git.py.

◆ test_has_uncommitted_changes_false_on_clean_repo()

tests_core.test_git.test_has_uncommitted_changes_false_on_clean_repo ( git_repo)

Definition at line 411 of file test_git.py.

◆ test_has_uncommitted_changes_true_after_edit()

tests_core.test_git.test_has_uncommitted_changes_true_after_edit ( git_repo)

Definition at line 417 of file test_git.py.

◆ test_has_untracked_files_false_on_fresh_repo()

tests_core.test_git.test_has_untracked_files_false_on_fresh_repo ( git_repo)

Definition at line 424 of file test_git.py.

◆ test_has_untracked_files_true_for_new_file()

tests_core.test_git.test_has_untracked_files_true_for_new_file ( git_repo)

Definition at line 428 of file test_git.py.

◆ test_is_detached_head_false_on_branch()

tests_core.test_git.test_is_detached_head_false_on_branch ( git_repo)

Definition at line 394 of file test_git.py.

◆ test_is_detached_head_true_after_checkout_sha()

tests_core.test_git.test_is_detached_head_true_after_checkout_sha ( git_repo)

Definition at line 400 of file test_git.py.

◆ test_is_git_repo_false_on_any_exception()

tests_core.test_git.test_is_git_repo_false_on_any_exception ( tmp_path,
monkeypatch )

Definition at line 367 of file test_git.py.

◆ test_is_git_repo_false_outside_repo()

tests_core.test_git.test_is_git_repo_false_outside_repo ( tmp_path)

Definition at line 356 of file test_git.py.

◆ test_is_git_repo_false_when_git_missing()

tests_core.test_git.test_is_git_repo_false_when_git_missing ( tmp_path,
monkeypatch )

Definition at line 360 of file test_git.py.

◆ test_is_git_repo_true_inside_repo()

tests_core.test_git.test_is_git_repo_true_inside_repo ( git_repo)

Definition at line 352 of file test_git.py.

◆ test_is_within_project_root_false_for_sibling()

tests_core.test_git.test_is_within_project_root_false_for_sibling ( tmp_path)

Definition at line 527 of file test_git.py.

◆ test_is_within_project_root_false_for_symlink_escape()

tests_core.test_git.test_is_within_project_root_false_for_symlink_escape ( tmp_path)
Symlinks pointing outside the project root must not be accepted.

Skipped on platforms without symlink capability — this is an
environmental constraint, not a defect in the tested behaviour.

Definition at line 539 of file test_git.py.

◆ test_is_within_project_root_handles_nonexistent_paths()

tests_core.test_git.test_is_within_project_root_handles_nonexistent_paths ( tmp_path)

Definition at line 532 of file test_git.py.

◆ test_is_within_project_root_true_for_child()

tests_core.test_git.test_is_within_project_root_true_for_child ( tmp_path)

Definition at line 516 of file test_git.py.

◆ test_is_within_project_root_true_for_self()

tests_core.test_git.test_is_within_project_root_true_for_self ( tmp_path)

Definition at line 523 of file test_git.py.

◆ test_last_commit_message_empty_on_fresh_repo()

tests_core.test_git.test_last_commit_message_empty_on_fresh_repo ( git_repo)

Definition at line 482 of file test_git.py.

◆ test_last_commit_message_returns_subject()

tests_core.test_git.test_last_commit_message_returns_subject ( git_repo)

Definition at line 486 of file test_git.py.

◆ test_last_commit_sha_empty_on_fresh_repo()

tests_core.test_git.test_last_commit_sha_empty_on_fresh_repo ( git_repo)

Definition at line 468 of file test_git.py.

◆ test_last_commit_sha_full_and_short()

tests_core.test_git.test_last_commit_sha_full_and_short ( git_repo)

Definition at line 472 of file test_git.py.

◆ test_legacy_shim_passes_py_extension_filter()

tests_core.test_git.test_legacy_shim_passes_py_extension_filter ( tmp_path,
monkeypatch )

Definition at line 609 of file test_git.py.

◆ test_legacy_shim_returns_empty_on_command_error()

tests_core.test_git.test_legacy_shim_returns_empty_on_command_error ( tmp_path,
monkeypatch )

Definition at line 596 of file test_git.py.

◆ test_legacy_shim_returns_empty_on_missing_git()

tests_core.test_git.test_legacy_shim_returns_empty_on_missing_git ( tmp_path,
monkeypatch )

Definition at line 574 of file test_git.py.

◆ test_legacy_shim_returns_empty_on_not_a_repo()

tests_core.test_git.test_legacy_shim_returns_empty_on_not_a_repo ( tmp_path,
monkeypatch )

Definition at line 585 of file test_git.py.

◆ test_redact_argv_noop_for_plain_argv()

tests_core.test_git.test_redact_argv_noop_for_plain_argv ( )

Definition at line 198 of file test_git.py.

◆ test_redact_argv_redacts_url_elements()

tests_core.test_git.test_redact_argv_redacts_url_elements ( )

Definition at line 190 of file test_git.py.

◆ test_redact_handles_empty_string()

tests_core.test_git.test_redact_handles_empty_string ( )

Definition at line 156 of file test_git.py.

◆ test_redact_handles_none_safely()

tests_core.test_git.test_redact_handles_none_safely ( )

Definition at line 160 of file test_git.py.

◆ test_redact_multiline_output()

tests_core.test_git.test_redact_multiline_output ( )

Definition at line 166 of file test_git.py.

◆ test_redact_preserves_non_url_content()

tests_core.test_git.test_redact_preserves_non_url_content ( )

Definition at line 176 of file test_git.py.

◆ test_redact_preserves_ssh_urls()

tests_core.test_git.test_redact_preserves_ssh_urls ( )

Definition at line 151 of file test_git.py.

◆ test_redact_strips_http_creds()

tests_core.test_git.test_redact_strips_http_creds ( )

Definition at line 138 of file test_git.py.

◆ test_redact_strips_https_creds()

tests_core.test_git.test_redact_strips_https_creds ( )

Definition at line 144 of file test_git.py.

◆ test_remote_urls_empty_on_fresh_repo()

tests_core.test_git.test_remote_urls_empty_on_fresh_repo ( git_repo)

Definition at line 492 of file test_git.py.

◆ test_remote_urls_redacts_http_creds()

tests_core.test_git.test_remote_urls_redacts_http_creds ( git_repo)

Definition at line 496 of file test_git.py.

◆ test_timeout_message_redacts_token()

tests_core.test_git.test_timeout_message_redacts_token ( tmp_path,
monkeypatch )

Definition at line 237 of file test_git.py.

Variable Documentation

◆ _CAN_SYMLINK

bool tests_core.test_git._CAN_SYMLINK = _platform_can_symlink()
protected

Definition at line 76 of file test_git.py.

◆ _SYMLINK_SKIP_REASON

tuple tests_core.test_git._SYMLINK_SKIP_REASON
protected
Initial value:
1= (
2 "Platform cannot create symlinks without elevation "
3 "(Windows non-admin / non-developer-mode, or FS refuses the syscall)."
4)

Definition at line 77 of file test_git.py.

◆ _TOKEN_URL

str tests_core.test_git._TOKEN_URL = "https://oauth2:ghp_SUPERSECRET@github.com/foo/bar.git"
protected

Definition at line 187 of file test_git.py.