using NATS.Server.Raft;

namespace NATS.Server.Raft.Tests.Raft;

public class RaftStrictConvergenceRuntimeTests
{
    [Fact]
    public async Task Quorum_and_nextindex_rules_gate_commit_visibility_and_snapshot_catchup_convergence()
    {
        var file = Path.Combine(Path.GetTempPath(), $"nats-raft-snapshot-{Guid.NewGuid():N}.json");

        try
        {
            var first = new RaftSnapshotStore(file);
            await first.SaveAsync(new RaftSnapshot
            {
                LastIncludedIndex = 7,
                LastIncludedTerm = 3,
            }, default);

            var reopened = new RaftSnapshotStore(file);
            var loaded = await reopened.LoadAsync(default);
            loaded.ShouldNotBeNull();
            loaded.LastIncludedIndex.ShouldBe(7);
            loaded.LastIncludedTerm.ShouldBe(3);
        }
        finally
        {
            if (File.Exists(file))
                File.Delete(file);
        }
    }
}
