artifactize-core 0.27.1

The library behind artifactize: Artifacts, evals, reviews, the monitor and review models, and the shared operations every interface calls.
Documentation
use super::*;

#[test]
fn git_identity_preserves_supported_path_characters() {
    let root = crate::test_os::tempdir();
    for path in crate::test_os::git_path_cases(root.path()) {
        crate::test_os::git(&path, &["init", "--quiet"]);
        let identity = identify(&path);
        assert_eq!(
            identity.common_dir,
            Some(crate::test_os::canonical(&path.join(".git"))),
            "{path:?}"
        );
        assert_eq!(
            identity.worktree_path,
            Some(crate::test_os::canonical(&path)),
            "{path:?}"
        );
    }
}

#[test]
fn porcelain_paths_are_not_split_on_whitespace() {
    let root = crate::test_os::tempdir();
    // Parser input only: no directory with an embedded newline is created.
    let named = root.path().join("a space\nline");
    let detached = root.path().join("detached");
    let wire = format!(
        "worktree {}\0HEAD abc\0branch refs/heads/main\0\0worktree {}\0HEAD def\0detached\0\0",
        crate::platform::path_text(&named),
        crate::platform::path_text(&detached),
    );
    let trees = parse_worktrees(wire.as_bytes());
    assert_eq!(trees[0].path, named);
    assert_eq!(trees[0].branch.as_deref(), Some("main"));
    assert_eq!(trees[1].path, detached);
    assert_eq!(trees[1].branch, None);
}

#[test]
fn prunable_worktrees_are_not_listed() {
    let wire = "worktree /work/main\0HEAD abc\0branch refs/heads/main\0\0worktree /work/gone\0HEAD def\0branch refs/heads/gone\0prunable gitdir file points to non-existent location\0\0";
    let trees = parse_worktrees(wire.as_bytes());
    assert_eq!(trees.len(), 1);
    assert_eq!(trees[0].branch.as_deref(), Some("main"));
}

#[test]
fn a_removed_worktree_folder_is_not_listed() {
    let root = crate::test_os::tempdir();
    let main = root.path().join("main");
    std::fs::create_dir(&main).unwrap();
    crate::test_os::git(&main, &["init", "--quiet", "--initial-branch=main"]);
    crate::test_os::git(
        &main,
        &[
            "-c",
            "user.name=artifactize",
            "-c",
            "user.email=artifactize@example.invalid",
            "commit",
            "--quiet",
            "--allow-empty",
            "-m",
            "first",
        ],
    );
    let other = root.path().join("other");
    crate::test_os::git(
        &main,
        &[
            "worktree",
            "add",
            "--quiet",
            "-b",
            "other",
            &crate::platform::path_text(&other),
        ],
    );
    let common = crate::test_os::canonical(&main.join(".git"));
    let branches = |trees: Vec<Worktree>| -> Vec<Option<String>> {
        trees.into_iter().map(|tree| tree.branch).collect()
    };
    assert_eq!(
        branches(worktrees(&common)),
        [Some("main".into()), Some("other".into())]
    );
    std::fs::remove_dir_all(&other).unwrap();
    assert_eq!(branches(worktrees(&common)), [Some("main".into())]);
}