Skip to content

Test/integration tests#7

Merged
fadyphil merged 5 commits into
mainfrom
test/integration-tests
Jun 25, 2026
Merged

Test/integration tests#7
fadyphil merged 5 commits into
mainfrom
test/integration-tests

Conversation

@fadyphil

Copy link
Copy Markdown
Owner

Description

This PR transitions git-rs from manual terminal verification to a fully automated, bulletproof testing and continuous integration pipeline.

To achieve true test isolation and parallel execution, a massive architectural refactor was performed to eradicate implicit global state (the OS Current Working Directory) from the core library, replacing it with explicit Dependency Injection. Furthermore, a comprehensive suite of white-box unit tests and black-box integration tests has been added, guarded by a new GitHub Actions CI/CD pipeline.

Key Changes:

  • Architectural Refactor (Dependency Injection): The core engine (object, refs, tree, commit, config) no longer relies on hardcoded relative paths (e.g., .git/). All filesystem-touching functions now require a repo_dir: &Path parameter. main.rs acts as a strict application boundary, capturing std::env::current_dir() exactly once and injecting it down the call chain.
  • Unit Testing: Introduced 20+ parallel-safe unit tests across all core modules using the Arrange-Act-Assert (AAA) pattern and the tempfile crate. Coverage includes pure math verification, SHA-1 known-value constants, corrupt Zlib stream rejection, tree sorting proofs, and DAG parent-linking logic.
  • Integration Testing: Added an end-to-end black-box test using assert_cmd that spawns the compiled binary, executes a full Git workflow (init -> hash-object -> write-tree -> commit), and mathematically verifies the resulting 40-character hex hashes and ref updates.
  • CI/CD Pipeline: Configured .github/workflows/ci.yml to automatically run cargo fmt, cargo clippy -- -D warnings, and cargo test on all pushes and PRs. Integrated Swatinem/rust-cache for fast execution.
  • Documentation: Added a dynamic CI status badge to README.md and updated CONTRIBUTING.md with local testing requirements.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactor (memory/safety optimization)
  • Documentation update
  • Testing & CI/CD Infrastructure

Checklist

  • My code follows the style guidelines of this project
  • I have run cargo fmt
  • I have run cargo clippy --all-targets --all-features -- -D warnings and fixed all warnings
  • I have added/updated documentation if necessary

fadyphil added 5 commits June 25, 2026 14:28
The core engine (object, refs, tree, commit) previously relied on the OS's global Current Working Directory (CWD) by utilizing hardcoded relative paths (e.g., '.git/objects/'). This implicit coupling to the execution environment rendered the library impure, tightly bound to the terminal state, and inherently thread-unsafe for parallel testing.

Transitioned the entire core architecture to explicit Dependency Injection. All filesystem-touching functions now require a `repo_dir: &Path` parameter. `main.rs` has been elevated to a strict 'application boundary' that captures `std::env::current_dir()` exactly once and injects it down the call chain.

Architectural Impact:
- Eradicated all hidden environmental dependencies and hardcoded '.git/' literals from the library layer.
- Transformed the engine from an environment-dependent script into a pure, isolated library capable of manipulating any repository programmatically.
- Eliminated global state mutation, establishing a thread-safe foundation that enables parallel, race-condition-free unit testing.
… engine

Introduced a robust suite of unit tests across all core library modules (object, refs, tree, commit) utilizing the Arrange-Act-Assert (AAA) pattern. Leveraged the `tempfile` crate to provide isolated, ephemeral filesystems for every test case, ensuring zero side-effects and complete isolation between test runs.

Architectural Impact:
Because the recent Dependency Injection refactor eradicated implicit reliance on the OS's global Current Working Directory (CWD), these tests no longer require global state mutation (e.g., `env::set_current_dir()`) or serial execution (`--test-threads=1`). The test suite is now inherently thread-safe and executes in parallel, drastically reducing execution time.

White-Box Coverage Highlights:
- object.rs: Verified pure formatting math, SHA-1 known-value constants, and intentionally fed corrupt Zlib streams to prove the safety nets catch missing null separators and size mismatches.
- tree.rs: Mathematically proved the alphabetical sorting algorithm and verified that `.git` directories are correctly ignored during recursive walks.
- commit.rs: Validated DAG parent-linking logic and verified the graceful fallback to 'unknown_user' when `.git/config` is missing or malformed.
- refs.rs: Tested pointer resolution, branch updates, and the explicit rejection of Detached HEAD states.
Transitioned the project from manual terminal verification to a robust, automated Continuous Integration (CI) pipeline using GitHub Actions. The pipeline triggers on all pushes and pull requests targeting the main branches.

Pipeline Guardrails:
- Enforces strict code formatting via `cargo fmt --check`.
- Mandates zero compiler and Clippy warnings using `-D warnings`, ensuring idiomatic Rust standards are mathematically enforced.
- Executes the full suite of parallel-safe unit tests and black-box integration tests via `cargo test --all`.

Infrastructure Optimizations:
- Integrated `dtolnay/rust-toolchain` for reliable, cross-platform Rust environment provisioning.
- Integrated `Swatinem/rust-cache` to cache the `target/` directory between workflow runs, drastically reducing CI execution time from minutes to seconds.

Updated README.md with a dynamic CI status badge and expanded CONTRIBUTING.md to document the new local testing requirements for PR approval.
@fadyphil fadyphil merged commit f161d60 into main Jun 25, 2026
1 check passed
@fadyphil fadyphil deleted the test/integration-tests branch June 25, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant