Skip to content

Add initial Rust commit validator - #4

Merged
Mshehu5 merged 4 commits into
mainfrom
commit-validation
Nov 6, 2026
Merged

Mshehu5 merged 4 commits into
mainfrom
commit-validation

Conversation

@Mshehu5

@Mshehu5 Mshehu5 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

This PR sets up the Rust project and implements the first commit-validation MVP. The CLI accepts a Git revision range, runs nix flake check on each commit in order, and stops on the first failure. tests for the main validation flow and minimum CI.

replaces #1 to suppport stacked PR old comments and be found there

@yuval-block yuval-block left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

only skimmed the rust code so far, it looks good but i will post a complete review of that

i think it makes sense to use the fungi validate-commits shell script on this repo from the very first commit, so basically the 2nd commit that adds the MVP implementation should also initialize the flake with crane based checks, and CI should be added immediately after

then eventually the validate commits program can start validating itself (and we can think about how to handle that cleanly using nix, e.g. running the version in main to validate PRs to the repo, then rerunning with the updated version in the merge queue, perhaps)

Comment thread nix/treefmt.nix Resolved

@bc1cindy bc1cindy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good!

Comment thread Cargo.toml Resolved
Comment thread Cargo.toml Resolved
Comment thread .github/workflows/ci.yml Resolved
Comment thread nix/package.nix Outdated
);
in
{
checks.default = validate-commits;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could we add crane checks here, like clippy and doc, as in fungi's nix/checks/?

the 2nd commit that adds the MVP implementation should also initialize the flake with crane based checks

#4 (review)

@Mshehu5 Mshehu5 Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

checks should be small for now another PR that will expand this will happen for all fungi repo
see fungi-protocol/fungi#24

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

at least minimal tests like nextest & coverage should be copied over, even if not everything is fully extracted

are you going to create a repo for the reusable flake parts?

Comment thread src/lib.rs Resolved
Comment thread tests/cli.rs
[ "$1" = flake ] && [ "$2" = check ] || exit 91
[ "$3" = --no-update-lock-file ] || exit 92
[ "$4" = --print-build-logs ] || exit 93
printf '%s\n' "$5" >> "$TEST_NIX_LOG"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fake nix harness records only the final argument string (line 59) and never asserts the spawned process's working directory, so the contract documented at lines 184-187 - a relative git+file:./ reference resolved against the repository root the CLI sets as working directory - is unverified.
Deleting .current_dir(&repository.root) from src/nix.rs leaves all 6 tests passing, while real Nix would then resolve ./ against the caller's CWD (demonstrated: a CLI launched from a subdirectory runs the fake in that subdirectory).

@Mshehu5
Mshehu5 force-pushed the commit-validation branch 2 times, most recently from 4a20527 to fff493a Compare October 15, 2026 19:10
@arminsabouri

Copy link
Copy Markdown

@Mshehu5 to request review from someone

@Mshehu5
Mshehu5 requested a review from yuval-block October 19, 2026 13:23

@bc1cindy bc1cindy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK fff493a

Comment thread src/history.rs
.collect()
}

fn add_revision(repo: &Repository, walk: &mut Revwalk<'_>, input: &str) -> Result<(), Error> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

non-blocking: could a test compare this with git rev-list on random histories?

@yuval-block yuval-block left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i didn't scrutinize the fixture very closely, seems like that is nice and simple for now but may be better served by actual test flakes in subdirectories when the nix derivation building uses a more programmatic approach down the line

this seems perfectly adequate for now, i think we should merge and focus on the diff injection since that will be the highest impact (cargo mutants takes a long time to run on the entire project)

Comment thread nix/package.nix Outdated
);
in
{
checks.default = validate-commits;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

at least minimal tests like nextest & coverage should be copied over, even if not everything is fully extracted

are you going to create a repo for the reusable flake parts?

Comment thread nix/treefmt.nix Resolved
Comment thread src/nix.rs
use crate::{CommitId, Error, Repository};

// Run the commit's flake checks and preserve Nix's output validation.
pub(super) fn check_flake(repository: &Repository, commit: &CommitId) -> Result<(), Error> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for now this is fine but we almost certainly want to use nix flake check --no-build and then nix build --no-link for the individual checks, probably using nix-eval-jobs... anyway the point is more, keep this as minimal as it currently is for just a pass/fail determination, but if you find yourself parsing log output or anything like that then reach for a more robust API

@Mshehu5 Mshehu5 mentioned this pull request Nov 5, 2026
Comment thread src/history.rs
return Ok(vec![CommitId(resolve(repo, revision)?.id())]);
}

let mut walk = repo.revwalk().map_err(Error::WalkHistory)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shallow linked worktrees fail history resolution

resolve_commits uses libgit2's revwalk, which fails with object not found on a missing parent in a linked worktree of a shallow clone; git rev-list HEAD lists the commits and the main worktree validates them, so plain revisions and --all fail.

oak · automated · 7e32643

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see #5 it deals with shallow

Comment thread src/nix.rs
pub(super) fn check_flake(repository: &Repository, commit: &CommitId) -> Result<(), Error> {
// Nix resolves this against the repository root and encodes the path.
let mut reference = format!("git+file:./?rev={commit}");
if repository.git_repo.is_shallow() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shallow linked worktrees omit Nix shallow=1

The Nix URL omits &shallow=1 in a linked worktree even though git rev-parse --is-shallow-repository is true, so nix flake check fails to fetch the missing object; the same commit succeeds with &shallow=1.

oak · automated · 7e32643

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see #5 it deals with shallow

Comment thread src/history.rs
walk.push(parent).map_err(Error::WalkHistory)?;
}
} else {
let spec = repo.revparse(input).map_err(Error::ParseRevision)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Valid ^-N revision is rejected

repo.revparse is used for revisions that are not leading-^, ^!, or ^@, but libgit2 does not implement git's rev^-N shorthand; main^-1 is rejected even though git rev-list main^-1 accepts it. The leading-^ path also passes the remaining suffix to revparse_single, so main ^main^@ fails too.

oak · automated · 7e32643

Comment thread tests/cli.rs Resolved
@oakagent

oakagent commented Nov 6, 2026 •

Copy link
Copy Markdown

@Mshehu5 8237772 is clean; the ACK waits on the description:

  • Not mentioned: The CLI also accepts multiple revisions, exclusions, and --all. (src/main.rs:8)

oak · automated

@Mshehu5

Mshehu5 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@Mshehu5 8237772 is clean; the ACK waits on three open points and the description:

Three open points:

  • tests/cli.rs:59 oakagent: "The fake nix harness records only the final argument string (line 59) and never asserts the spawned process's working directory, so the contract documented..." (no reply yet)
  • src/history.rs:42 bc1cindy: "non-blocking: could a test compare this with git rev-list on random histories?" (no reply yet)
  • src/history.rs:59 oakagent: "repo.revparse is used for revisions that are not leading-^, ^!, or ^@, but libgit2 does not implement git's rev^-N shorthand; main^-1 is rejected..." (no reply yet)

The description:

  • Not mentioned: The CLI also accepts multiple revisions, exclusions, and --all. (src/main.rs:8)

oak · automated

concernig first 2 will change test to follow yuvals comment of

but may be better served by actual test flakes in subdirectories when the nix derivation building uses a more programmatic approach down the line

#4 (review)

for the repo parse issue:
Our current CI uses $BASE_SHA..HEAD, so these cases don’t affect that workflow. I will address in a follow up issue these are none blocking will merge for now

@Mshehu5
Mshehu5 merged commit 68030ea into main Nov 6, 2026
1 check 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.

5 participants