Skip to content

feat: add Rust closure fixtures to gix-testtools#2412

Merged
Byron merged 4 commits intomainfrom
copilot/add-execute-rust-closures-again
Feb 4, 2026
Merged

feat: add Rust closure fixtures to gix-testtools#2412
Byron merged 4 commits intomainfrom
copilot/add-execute-rust-closures-again

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

Adds ability to create fixtures using Rust closures instead of shell scripts, with manual version numbers for cache invalidation.

New API

  • rust_fixture_read_only(name, version, closure) - cached read-only fixture
  • rust_fixture_writable(name, version, mode, closure) - writable temp directory copy
  • *_standalone variants for fixtures/ instead of tests/fixtures/

Implementation

  • Version number (u32) replaces CRC-based script identity for cache invalidation
  • Archives prefixed with rust- (e.g., rust-my_fixture.tar.xz)
  • Reuses existing locking, archive extraction, and failure marker infrastructure

Example

let dir = gix_testtools::rust_fixture_read_only("my_fixture", 1, |dir| {
    std::fs::write(dir.join("file.txt"), "content")?;
    Ok(())
})?;

Increment version when closure behavior changes to force cache rebuild.

Original prompt

Add a way to execute Rust closures on a given directory in the gix-testtools crate, fully integrated into the existing ways of creating fixtures with scripts. The key here is to let the caller provide a version number (simple integer), that needs to be incremented manually to allow caching.
With it, it should be possible to make a fixture something like this:

let dir = gix_testtools::rust_fixture_read_only(1, |dir| { …create the fixture in Rust here })?;

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add execution of Rust closures in gix-testtools feat: add Rust closure fixtures to gix-testtools Feb 4, 2026
Copilot AI requested a review from Byron February 4, 2026 03:39
…to gix-testtools

Co-authored-by: Byron <63622+Byron@users.noreply.github.com>
Byron added 2 commits February 4, 2026 09:25
Reviewed-by: Claude <noreply@anthropic.com>
@Byron Byron force-pushed the copilot/add-execute-rust-closures-again branch from a0d9d91 to fff844b Compare February 4, 2026 08:26
@Byron Byron requested a review from Copilot February 4, 2026 08:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Rust-closure-driven fixture generation to gix-testtools, integrating with the existing cached fixture/archive system while switching cache invalidation to a caller-supplied version integer.

Changes:

  • Introduce rust_fixture_read_only* and rust_fixture_writable* APIs, with version: u32 used as the cache/archive identity.
  • Refactor fixture generation to reuse shared marker/failure/archive handling and centralize tar extension selection.
  • Add tests for Rust fixture caching, version invalidation, error propagation, and standalone fixture roots; move existing unit tests into a dedicated test module file.

Reviewed changes

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

File Description
tests/tools/src/lib.rs Adds new Rust fixture APIs; factors out common “run generator + marker/archive handling”; adds tar_extension() and externalizes unit tests module.
tests/tools/tests/rust_fixture.rs New integration tests validating Rust fixture behaviors (cache hit, version bump, writable mode, error propagation, standalone root).
tests/tools/src/tests.rs New internal unit test module extracted from lib.rs.
tests/tools/.gitignore Adds ignore rule for the standalone fixtures/ directory.

Comment on lines +106 to +113
let dir_str = dir.to_string_lossy();
assert!(
dir_str.contains("fixtures") && dir_str.contains("generated-do-not-edit"),
"Standalone fixture should be in fixtures/generated-do-not-edit directory, got: {dir_str}"
);
assert!(
!dir_str.contains("tests/fixtures"),
"Standalone fixture should NOT be in tests/fixtures directory, got: {dir_str}"
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

This path assertion is string-based and assumes / separators. On Windows, a wrong path like tests\\fixtures\\... would still satisfy the positive check and the negative "tests/fixtures" check would not catch it. Prefer checking path components via Path APIs (e.g., starts_with("fixtures") and !starts_with("tests")) to make the test platform-correct.

Suggested change
let dir_str = dir.to_string_lossy();
assert!(
dir_str.contains("fixtures") && dir_str.contains("generated-do-not-edit"),
"Standalone fixture should be in fixtures/generated-do-not-edit directory, got: {dir_str}"
);
assert!(
!dir_str.contains("tests/fixtures"),
"Standalone fixture should NOT be in tests/fixtures directory, got: {dir_str}"
let components: Vec<_> = dir.components().collect();
let has_fixtures = components.iter().any(|c| c.as_os_str() == "fixtures");
let has_generated = components
.iter()
.any(|c| c.as_os_str() == "generated-do-not-edit");
assert!(
has_fixtures && has_generated,
"Standalone fixture should be in fixtures/generated-do-not-edit directory, got: {}",
dir.display()
);
let has_tests_fixtures = components
.windows(2)
.any(|pair| pair[0].as_os_str() == "tests" && pair[1].as_os_str() == "fixtures");
assert!(
!has_tests_fixtures,
"Standalone fixture should NOT be in tests/fixtures directory, got: {}",
dir.display()

Copilot uses AI. Check for mistakes.
@@ -0,0 +1 @@
fixtures/
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

With the new integration-style rust fixture tests, running this crate’s tests will also generate tests/fixtures/generated-archives/*, which isn’t covered by this ignore entry and may leave untracked archives in the working tree. Consider narrowing the ignore to generated fixture outputs and/or adding an ignore entry for tests/fixtures/generated-archives/ (or a pattern matching *.tar/*.tar.xz) to keep local worktrees clean.

Copilot uses AI. Check for mistakes.
@Byron Byron marked this pull request as ready for review February 4, 2026 08:50
@Byron Byron enabled auto-merge February 4, 2026 08:53
@Byron Byron merged commit 675ce68 into main Feb 4, 2026
30 checks passed
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.

3 participants