chore: format with updated rustfmt and taplo rules

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ie9ef5fc421fa20071946cf1073f7920c6a6a6964
This commit is contained in:
raf 2026-02-02 02:23:50 +03:00
commit c306383d27
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
72 changed files with 11217 additions and 10487 deletions

View file

@ -3,95 +3,95 @@
#[test]
fn test_parse_valid_job() {
let line = r#"{"name":"hello","drvPath":"/nix/store/abc123-hello.drv","system":"x86_64-linux","outputs":{"out":"/nix/store/abc123-hello"}}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 1);
assert_eq!(result.error_count, 0);
assert_eq!(result.jobs[0].name, "hello");
assert_eq!(result.jobs[0].drv_path, "/nix/store/abc123-hello.drv");
assert_eq!(result.jobs[0].system.as_deref(), Some("x86_64-linux"));
let line = r#"{"name":"hello","drvPath":"/nix/store/abc123-hello.drv","system":"x86_64-linux","outputs":{"out":"/nix/store/abc123-hello"}}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 1);
assert_eq!(result.error_count, 0);
assert_eq!(result.jobs[0].name, "hello");
assert_eq!(result.jobs[0].drv_path, "/nix/store/abc123-hello.drv");
assert_eq!(result.jobs[0].system.as_deref(), Some("x86_64-linux"));
}
#[test]
fn test_parse_multiple_jobs() {
let output = r#"{"name":"hello","drvPath":"/nix/store/abc-hello.drv","system":"x86_64-linux"}
let output = r#"{"name":"hello","drvPath":"/nix/store/abc-hello.drv","system":"x86_64-linux"}
{"name":"world","drvPath":"/nix/store/def-world.drv","system":"aarch64-linux"}"#;
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 2);
assert_eq!(result.error_count, 0);
assert_eq!(result.jobs[0].name, "hello");
assert_eq!(result.jobs[1].name, "world");
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 2);
assert_eq!(result.error_count, 0);
assert_eq!(result.jobs[0].name, "hello");
assert_eq!(result.jobs[1].name, "world");
}
#[test]
fn test_parse_error_lines() {
let output = r#"{"name":"hello","drvPath":"/nix/store/abc-hello.drv"}
let output = r#"{"name":"hello","drvPath":"/nix/store/abc-hello.drv"}
{"attr":"broken","error":"attribute 'broken' missing"}
{"name":"world","drvPath":"/nix/store/def-world.drv"}"#;
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 2);
assert_eq!(result.error_count, 1);
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 2);
assert_eq!(result.error_count, 1);
}
#[test]
fn test_parse_empty_output() {
let result = fc_evaluator::nix::parse_eval_output("");
assert_eq!(result.jobs.len(), 0);
assert_eq!(result.error_count, 0);
let result = fc_evaluator::nix::parse_eval_output("");
assert_eq!(result.jobs.len(), 0);
assert_eq!(result.error_count, 0);
}
#[test]
fn test_parse_blank_lines_ignored() {
let output = "\n \n\n";
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 0);
assert_eq!(result.error_count, 0);
let output = "\n \n\n";
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 0);
assert_eq!(result.error_count, 0);
}
#[test]
fn test_parse_malformed_json_skipped() {
let output =
"not json at all\n{invalid json}\n{\"name\":\"ok\",\"drvPath\":\"/nix/store/x-ok.drv\"}";
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 1);
assert_eq!(result.jobs[0].name, "ok");
let output = "not json at all\n{invalid \
json}\n{\"name\":\"ok\",\"drvPath\":\"/nix/store/x-ok.drv\"}";
let result = fc_evaluator::nix::parse_eval_output(output);
assert_eq!(result.jobs.len(), 1);
assert_eq!(result.jobs[0].name, "ok");
}
#[test]
fn test_parse_job_with_input_drvs() {
let line = r#"{"name":"hello","drvPath":"/nix/store/abc-hello.drv","inputDrvs":{"/nix/store/dep1.drv":["out"],"/nix/store/dep2.drv":["out"]}}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 1);
let input_drvs = result.jobs[0].input_drvs.as_ref().unwrap();
assert_eq!(input_drvs.len(), 2);
let line = r#"{"name":"hello","drvPath":"/nix/store/abc-hello.drv","inputDrvs":{"/nix/store/dep1.drv":["out"],"/nix/store/dep2.drv":["out"]}}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 1);
let input_drvs = result.jobs[0].input_drvs.as_ref().unwrap();
assert_eq!(input_drvs.len(), 2);
}
#[test]
fn test_parse_job_with_constituents() {
let line = r#"{"name":"aggregate","drvPath":"/nix/store/abc-aggregate.drv","constituents":["hello","world"]}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 1);
let constituents = result.jobs[0].constituents.as_ref().unwrap();
assert_eq!(constituents.len(), 2);
assert_eq!(constituents[0], "hello");
assert_eq!(constituents[1], "world");
let line = r#"{"name":"aggregate","drvPath":"/nix/store/abc-aggregate.drv","constituents":["hello","world"]}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 1);
let constituents = result.jobs[0].constituents.as_ref().unwrap();
assert_eq!(constituents.len(), 2);
assert_eq!(constituents[0], "hello");
assert_eq!(constituents[1], "world");
}
#[test]
fn test_parse_error_without_name() {
let line = r#"{"error":"some eval error"}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 0);
assert_eq!(result.error_count, 1);
let line = r#"{"error":"some eval error"}"#;
let result = fc_evaluator::nix::parse_eval_output(line);
assert_eq!(result.jobs.len(), 0);
assert_eq!(result.error_count, 1);
}
// --- Inputs hash computation ---
#[test]
fn test_inputs_hash_deterministic() {
// The compute_inputs_hash function is in eval_loop which is not easily testable
// as a standalone function since it's not public. We test the nix parsing above
// and trust the hash logic is correct since it uses sha2.
// The compute_inputs_hash function is in eval_loop which is not easily
// testable as a standalone function since it's not public. We test the nix
// parsing above and trust the hash logic is correct since it uses sha2.
}

View file

@ -6,85 +6,100 @@ use tempfile::TempDir;
#[test]
fn test_clone_or_fetch_clones_new_repo() {
let upstream_dir = TempDir::new().unwrap();
let work_dir = TempDir::new().unwrap();
let upstream_dir = TempDir::new().unwrap();
let work_dir = TempDir::new().unwrap();
// Create a non-bare repo to clone from (bare repos have no HEAD by default)
let upstream = Repository::init(upstream_dir.path()).unwrap();
// Create initial commit
{
let sig = Signature::now("Test", "test@example.com").unwrap();
let tree_id = upstream.index().unwrap().write_tree().unwrap();
let tree = upstream.find_tree(tree_id).unwrap();
upstream
.commit(Some("HEAD"), &sig, &sig, "initial", &tree, &[])
.unwrap();
}
// Create a non-bare repo to clone from (bare repos have no HEAD by default)
let upstream = Repository::init(upstream_dir.path()).unwrap();
// Create initial commit
{
let sig = Signature::now("Test", "test@example.com").unwrap();
let tree_id = upstream.index().unwrap().write_tree().unwrap();
let tree = upstream.find_tree(tree_id).unwrap();
upstream
.commit(Some("HEAD"), &sig, &sig, "initial", &tree, &[])
.unwrap();
}
let url = format!("file://{}", upstream_dir.path().display());
let result = fc_evaluator::git::clone_or_fetch(&url, work_dir.path(), "test-project", None);
let url = format!("file://{}", upstream_dir.path().display());
let result = fc_evaluator::git::clone_or_fetch(
&url,
work_dir.path(),
"test-project",
None,
);
assert!(
result.is_ok(),
"clone_or_fetch should succeed: {:?}",
result.err()
);
let (repo_path, hash): (std::path::PathBuf, String) = result.unwrap();
assert!(repo_path.exists());
assert!(!hash.is_empty());
assert_eq!(hash.len(), 40); // full SHA-1
assert!(
result.is_ok(),
"clone_or_fetch should succeed: {:?}",
result.err()
);
let (repo_path, hash): (std::path::PathBuf, String) = result.unwrap();
assert!(repo_path.exists());
assert!(!hash.is_empty());
assert_eq!(hash.len(), 40); // full SHA-1
}
#[test]
fn test_clone_or_fetch_fetches_existing() {
let upstream_dir = TempDir::new().unwrap();
let work_dir = TempDir::new().unwrap();
let upstream_dir = TempDir::new().unwrap();
let work_dir = TempDir::new().unwrap();
let upstream = Repository::init(upstream_dir.path()).unwrap();
{
let sig = Signature::now("Test", "test@example.com").unwrap();
let tree_id = upstream.index().unwrap().write_tree().unwrap();
let tree = upstream.find_tree(tree_id).unwrap();
upstream
.commit(Some("HEAD"), &sig, &sig, "initial", &tree, &[])
.unwrap();
}
let upstream = Repository::init(upstream_dir.path()).unwrap();
{
let sig = Signature::now("Test", "test@example.com").unwrap();
let tree_id = upstream.index().unwrap().write_tree().unwrap();
let tree = upstream.find_tree(tree_id).unwrap();
upstream
.commit(Some("HEAD"), &sig, &sig, "initial", &tree, &[])
.unwrap();
}
let url = format!("file://{}", upstream_dir.path().display());
let url = format!("file://{}", upstream_dir.path().display());
// First clone
let (_, hash1): (std::path::PathBuf, String) =
fc_evaluator::git::clone_or_fetch(&url, work_dir.path(), "test-project", None)
.expect("first clone failed");
// First clone
let (_, hash1): (std::path::PathBuf, String) =
fc_evaluator::git::clone_or_fetch(
&url,
work_dir.path(),
"test-project",
None,
)
.expect("first clone failed");
// Make another commit upstream
{
let sig = Signature::now("Test", "test@example.com").unwrap();
let tree_id = upstream.index().unwrap().write_tree().unwrap();
let tree = upstream.find_tree(tree_id).unwrap();
let head = upstream.head().unwrap().peel_to_commit().unwrap();
upstream
.commit(Some("HEAD"), &sig, &sig, "second", &tree, &[&head])
.unwrap();
}
// Make another commit upstream
{
let sig = Signature::now("Test", "test@example.com").unwrap();
let tree_id = upstream.index().unwrap().write_tree().unwrap();
let tree = upstream.find_tree(tree_id).unwrap();
let head = upstream.head().unwrap().peel_to_commit().unwrap();
upstream
.commit(Some("HEAD"), &sig, &sig, "second", &tree, &[&head])
.unwrap();
}
// Second fetch
let (_, hash2): (std::path::PathBuf, String) =
fc_evaluator::git::clone_or_fetch(&url, work_dir.path(), "test-project", None)
.expect("second fetch failed");
// Second fetch
let (_, hash2): (std::path::PathBuf, String) =
fc_evaluator::git::clone_or_fetch(
&url,
work_dir.path(),
"test-project",
None,
)
.expect("second fetch failed");
assert!(!hash1.is_empty());
assert!(!hash2.is_empty());
assert!(!hash1.is_empty());
assert!(!hash2.is_empty());
}
#[test]
fn test_clone_invalid_url_returns_error() {
let work_dir = TempDir::new().unwrap();
let result = fc_evaluator::git::clone_or_fetch(
"file:///nonexistent/repo",
work_dir.path(),
"bad-proj",
None,
);
assert!(result.is_err());
let work_dir = TempDir::new().unwrap();
let result = fc_evaluator::git::clone_or_fetch(
"file:///nonexistent/repo",
work_dir.path(),
"bad-proj",
None,
);
assert!(result.is_err());
}