Repository navigation
Add initial Rust commit validator - #4
Conversation
ca081f4 to
987e2c8
Compare
yuval-block
left a comment
There was a problem hiding this comment.
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)
987e2c8 to
c0772c2
Compare
| ); | ||
| in | ||
| { | ||
| checks.default = validate-commits; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
checks should be small for now another PR that will expand this will happen for all fungi repo
see fungi-protocol/fungi#24
There was a problem hiding this comment.
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?
| [ "$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" |
There was a problem hiding this comment.
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).
4a20527 to
fff493a
Compare
|
@Mshehu5 to request review from someone |
| .collect() | ||
| } | ||
|
|
||
| fn add_revision(repo: &Repository, walk: &mut Revwalk<'_>, input: &str) -> Result<(), Error> { |
There was a problem hiding this comment.
non-blocking: could a test compare this with git rev-list on random histories?
yuval-block
left a comment
There was a problem hiding this comment.
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)
| ); | ||
| in | ||
| { | ||
| checks.default = validate-commits; |
There was a problem hiding this comment.
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?
| 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> { |
There was a problem hiding this comment.
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
fff493a to
7e32643
Compare
| return Ok(vec![CommitId(resolve(repo, revision)?.id())]); | ||
| } | ||
|
|
||
| let mut walk = repo.revwalk().map_err(Error::WalkHistory)?; |
There was a problem hiding this comment.
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
| 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() { |
There was a problem hiding this comment.
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
| walk.push(parent).map_err(Error::WalkHistory)?; | ||
| } | ||
| } else { | ||
| let spec = repo.revparse(input).map_err(Error::ParseRevision)?; |
There was a problem hiding this comment.
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
7e32643 to
b4612dc
Compare
b4612dc to
8237772
Compare
|
@Mshehu5
|
concernig first 2 will change test to follow yuvals comment of
for the repo parse issue: |
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