package main

import (
	"context"
	"testing"
)

// The hook WIRING red-proof target: `guest-hook <vmid> post-start` must invoke the network
// reassert with the vmid; pre-start and unknown phases must NOT. (Companion red-proof: remove the
// PhasePostStart case from runGuestHook → the invoked assertion fails.)
func TestRunGuestHook_PostStartInvokesNetworkReassert(t *testing.T) {
	orig := postStartNetworkReassertFn
	t.Cleanup(func() { postStartNetworkReassertFn = orig })

	var gotVMIDs []string
	postStartNetworkReassertFn = func(_ context.Context, vmid string) {
		gotVMIDs = append(gotVMIDs, vmid)
	}

	runGuestHook([]string{"9201", "post-start"})
	if len(gotVMIDs) != 1 || gotVMIDs[0] != "9201" {
		t.Fatalf("post-start must invoke the network reassert with vmid 9201, got %v", gotVMIDs)
	}

	// pre-start must not touch the network reassert (it is the placeholder-heal phase; the heal
	// no-ops on a nonexistent config path and never blocks).
	runGuestHook([]string{"9201", "pre-start"})
	// unknown phases are ignored entirely.
	runGuestHook([]string{"9201", "pre-stop"})
	if len(gotVMIDs) != 1 {
		t.Fatalf("only post-start may invoke the network reassert, got %v", gotVMIDs)
	}
}
