Skip to content

test: add unit tests for generator logic - #51

Merged
BryanFRD merged 1 commit into
mainfrom
test/unit-tests
Apr 8, 2026
Merged

BryanFRD merged 1 commit into
mainfrom
test/unit-tests

Conversation

@BryanFRD

@BryanFRD BryanFRD commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds 28 unit tests across all generator modules:
    • types.rs (6 tests): config filename resolution
    • rng.rs (6 tests): determinism, range, message format
    • cli.rs (8 tests): arg parsing, defaults, error cases
    • tree.rs (8 tests): blob insertion, caching, repo builder
  • Adds tempfile as dev-dependency for tree tests

Closes #36

Copilot AI review requested due to automatic review settings April 8, 2026 12:15
@BryanFRD
BryanFRD merged commit cf8a69c into main Apr 8, 2026
3 checks passed
@BryanFRD
BryanFRD deleted the test/unit-tests branch April 8, 2026 12:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial Rust unit test coverage for the generator crate to validate core helper logic and reduce reliance on broken integration validation.

Changes:

  • Added unit tests for config filename resolution, RNG determinism/ranges/message formatting, CLI arg parsing, and git tree/repo builder behavior.
  • Introduced tempfile as a dev-dependency to support repository-in-temp-dir tests.
  • Updated Cargo.lock to reflect the new dev dependency and transitive crates.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
generator/src/types.rs Adds unit tests for resolve_config_filename defaults and overrides.
generator/src/rng.rs Adds unit tests for RNG determinism, ranges, and generated message/time shape.
generator/src/cli.rs Adds unit tests for flag parsing, defaults, and error cases.
generator/src/tree.rs Adds unit tests for tree insertion, caching invalidation, and commit chaining in a temp repo.
generator/Cargo.toml Adds tempfile under [dev-dependencies] for tests.
generator/Cargo.lock Locks tempfile and transitive dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread generator/src/tree.rs
let oid = builder.commit(&repo, None, "initial commit", &time).unwrap();

let commit = repo.find_commit(oid).unwrap();
assert_eq!(commit.message(), Some("initial commit"));

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git2::Commit::message() can include a trailing newline depending on libgit2 behavior, so asserting exact equality to Some("initial commit") can be brittle across versions/platforms. Consider asserting on commit.summary() == Some("initial commit") or comparing commit.message().unwrap().trim_end() instead.

Suggested change
assert_eq!(commit.message(), Some("initial commit"));
assert_eq!(commit.summary(), Some("initial commit"));

Copilot uses AI. Check for mistakes.
Comment thread generator/src/rng.rs
Comment on lines +87 to +88
let vals_a: Vec<usize> = (0..10).map(|_| a.usize(1000)).collect();
let vals_b: Vec<usize> = (0..10).map(|_| b.usize(1000)).collect();

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

different_seeds_differ is currently probabilistic because it compares values reduced modulo 1000; two different seeds could (rarely) produce the same 10-value sequence and make the test flaky. To make this deterministic, compare next_u64() outputs directly (the test module can access the private method) or increase robustness by checking that the underlying RNG state diverges.

Suggested change
let vals_a: Vec<usize> = (0..10).map(|_| a.usize(1000)).collect();
let vals_b: Vec<usize> = (0..10).map(|_| b.usize(1000)).collect();
let vals_a: Vec<u64> = (0..10).map(|_| a.next_u64()).collect();
let vals_b: Vec<u64> = (0..10).map(|_| b.next_u64()).collect();

Copilot uses AI. Check for mistakes.
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.

test: add unit tests for generator logic

2 participants