package controlplane

import (
	"go/ast"
	"testing"
)

func TestVerifyImplRunsConnectedDeliverySchemaOnlyForDeepVerify(t *testing.T) {
	verifyImpl := parseControlplaneFuncDecl(t, "verify.go", "verifyImpl")
	found := false
	ast.Inspect(verifyImpl.Body, func(node ast.Node) bool {
		ifStmt, ok := node.(*ast.IfStmt)
		if !ok {
			return true
		}
		deep, ok := ifStmt.Cond.(*ast.Ident)
		if !ok || deep.Name != "deep" {
			return true
		}
		ast.Inspect(ifStmt.Body, func(child ast.Node) bool {
			call, ok := child.(*ast.CallExpr)
			if !ok {
				return true
			}
			selector, ok := call.Fun.(*ast.SelectorExpr)
			if ok && selector.Sel.Name == "VerifyConnectedDeliverySchema" {
				found = true
			}
			return true
		})
		return true
	})
	if !found {
		t.Fatal("verifyImpl must run connected-delivery exact convergence only inside the operator deep-verify branch")
	}
}
