Repository: gitbutlerapp/gitbutler
File: crates/but-graph/tests/graph/init/with_workspace.rs (Rust)

Code before:
    │   └── →:2: (main →:1:)
    └── ►:5[0]:origin/A →:4:
        └── 🟣b627ca7 (0x0|1000)
            └── →:4: (A →:5:)
    ");

    insta::assert_snapshot!(graph_workspace(&graph.into_workspace()?), @r"
    📕🏘️:0:gitbutler/workspace[🌳] <> ✓refs/remotes/origin/main on fafd9d0
    ├── ≡:6:B-on-A on fafd9d0
    │   ├── :6:B-on-A
    │   │   └── ·aff8449 (🏘️)
    │   └── :4:A <> origin/A →:5:⇣1
    │       ├── 🟣b627ca7
    │       └── ❄️e255adc (🏘️)
    └── ≡📙:3:C-on-A on fafd9d0 {1}
        ├── 📙:3:C-on-A
        │   └── ·4f1bb32 (🏘️)
        └── :4:A <> origin/A →:5:⇣1
            ├── 🟣b627ca7
            └── ❄️e255adc (🏘️)
    ");
    Ok(())
}

#[test]
fn shared_commits_can_be_in_multiple_stacks_without_local_remote_overlap() -> anyhow::Result<()> {
    let (repo, mut meta) =
        read_only_in_memory_scenario("ws/multiple-stacks-with-shared-segment-and-remote")?;

    add_stack_with_segments(&mut meta, 1, "C-on-A", StackState::InWorkspace, &[]);
    let ws = Graph::from_head(&repo, &*meta, standard_options())?
        .validated()?
        .into_workspace()?;

    for stack in &ws.stacks {
        for segment in &stack.segments {
            let local_commit_ids: HashSet<_> =
                segment.commits.iter().map(|commit| commit.id).collect();
            let overlap: Vec<_> = segment
                .commits_on_remote
                .iter()
                .map(|commit| commit.id)
                .filter(|id| local_commit_ids.contains(id))
                .collect();
            assert!(
                overlap.is_empty(),
                "segment {:?} must not list the same commit as local and remote: {:?}",
                segment.ref_name(),
                overlap
            );
        }

Review comment (refactor):
I'd remove this test as this point is more obvious when looking at the test that was originally using the fixture. If there is something special here, I think it should be added to the existing test.

```Rust
    let (repo, mut meta) =
        read_only_in_memory_scenario("ws/multiple-stacks-with-shared-segment-and-remote")?;
    insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
    *   e982e8a (HEAD -> gitbutler/workspace) GitButler Workspace Commit
    |\  
    | * aff8449 (B-on-A) B-on-A
    * | 4f1bb32 (C-on-A) C-on-A
    |/  
    | * b627ca7 (origin/A) A-on-remote
    |/  
    * e255adc (A) A
    * fafd9d0 (origin/main, main) init
    ");

    add_stack_with_segments(&mut meta, 1, "C-on-A", StackState::InWorkspace, &[]);

    let graph = Graph::from_head(&repo, &*meta, standard_options())?.validated()?;
    insta::assert_snapshot!(graph_tree(&graph), @r"

    ├── 👉📕►►►:0[0]:gitbutler/workspace[🌳]
    │   └── ·e982e8a (⌂|🏘|0001)
    │       ├── 📙►:3[1]:C-on-A
    │       │   └── ·4f1bb32 (⌂|🏘|0001)
    │       │       └── ►:4[2]:A <> origin/A →:5:
    │       │           └── ·e255adc (⌂|🏘|1101)
    │       │               └── ►:2[3]:main <> origin/main →:1:
    │       │                   └── ·fafd9d0 (⌂|🏘|✓|1111)
    │       └── ►:6[1]:B-on-A
    │           └── ·aff8449 (⌂|🏘|0001)
    │               └── →:4: (A →:5:)
    ├── ►:1[0]:origin/main →:2:
    │   └── →:2: (main →:1:)
    └── ►:5[0]:origin/A →:4:
        └── 🟣b627ca7 (0x0|1000)
            └── →:4: (A →:5:)
    ");

    insta::assert_snapshot!(graph_workspace(&graph.into_workspace()?), @r"
    📕🏘️:0:gitbutler/workspace[🌳] <> ✓refs/remotes/origin/main on fafd9d0
    ├── ≡:6:B-on-A on fafd9d0
    │   ├── :6:B-on-A
    │   │   └── ·aff8449 (🏘️)
    │   └── :4:A <> origin/A →:5:⇣1
    │       ├── 🟣b627ca7
    │       └── ❄️e255adc (🏘️)
    └── ≡📙:3:C-on-A on fafd9d0 {1}
        ├── 📙:3:C-on-A
        │   └── ·4f1bb32 (🏘️)
        └── :4:A <> origin/A →:5:⇣1
            ├── 🟣b627ca7
            └── ❄️e255adc (🏘️)
    ");
```

Code after:
        └── 🟣b627ca7 (0x0|1000)
            └── →:4: (A →:5:)
    ");

    insta::assert_snapshot!(graph_workspace(&graph.into_workspace()?), @r"
    📕🏘️:0:gitbutler/workspace[🌳] <> ✓refs/remotes/origin/main on fafd9d0
    ├── ≡:6:B-on-A on fafd9d0
    │   ├── :6:B-on-A
    │   │   └── ·aff8449 (🏘️)
    │   └── :4:A <> origin/A →:5:⇣1
    │       ├── 🟣b627ca7
    │       └── ❄️e255adc (🏘️)
    └── ≡📙:3:C-on-A on fafd9d0 {1}
        ├── 📙:3:C-on-A
        │   └── ·4f1bb32 (🏘️)
        └── :4:A <> origin/A →:5:⇣1
            ├── 🟣b627ca7
            └── ❄️e255adc (🏘️)
    ");
    Ok(())
}

#[test]
fn a_stack_segment_can_be_a_segment_elsewhere_and_stack_order() -> anyhow::Result<()> {
    let (repo, mut meta) = read_only_in_memory_scenario(
        "ws/two-branches-one-advanced-two-parent-ws-commit-diverged-ttb",
    )?;
    insta::assert_snapshot!(visualize_commit_graph_all(&repo)?, @r"
    *   873d056 (HEAD -> gitbutler/workspace) GitButler Workspace Commit
    |\  
    * | cbc6713 (advanced-lane) change
    |/  
    * fafd9d0 (main, lane) init
    * da83717 (origin/main) disjoint remote target
    ");

    let lanes = ["advanced-lane", "lane"];
    for (idx, name) in lanes.into_iter().enumerate() {
        add_stack_with_segments(&mut meta, idx, name, StackState::InWorkspace, &[]);
    }

    let graph = Graph::from_head(&repo, &*meta, standard_options())?.validated()?;
    insta::assert_snapshot!(graph_tree(&graph), @"

    ├── 👉📕►►►:0[0]:gitbutler/workspace[🌳]
    │   └── ·873d056 (⌂|🏘|1)
    │       ├── 📙►:2[1]:advanced-lane
    │       │   └── ·cbc6713 (⌂|🏘|1)
    │       │       └── ►:3[2]:anon:
    │       │           └── ·fafd9d0 (⌂|🏘|1) ►main
    │       └── 📙►:4[1]:lane