package reconcile

import (
	"context"
	"testing"

	"gitea.dooplex.hu/admin/felhom-agent/internal/proxmox"
)

// LastResult (v0.90.0, R-28 fast-tick source): false until the first successful pass, then it
// mirrors the pass Result. The fast-tick reads Planned − Pending > 0 off it.
func TestEngine_LastResult(t *testing.T) {
	api := &fakeAPI{
		lxc: []proxmox.Guest{{VMID: 100, Status: "running"}},
		cfg: map[int]proxmox.GuestConfig{100: {Cores: 2}},
	}
	e, _, _ := newEngine(t, api, EmptyProvider{})

	if _, ok := e.LastResult(); ok {
		t.Fatal("LastResult ok=true before any pass, want false")
	}

	e.reconcileOnce(context.Background())

	res, ok := e.LastResult()
	if !ok {
		t.Fatal("LastResult not recorded after a reconcile pass")
	}
	if res.Planned != 0 || res.Pending != 0 {
		t.Errorf("converged pass recorded drift: %+v", res)
	}
}
