package controlplane

import (
	"os"
	"strings"
	"testing"
)

func TestSourcePackOpsFormulaViewHelpersStayOutOfInstallOrchestrationFile(t *testing.T) {
	opsSrc := readControlplaneSourceForStructureTest(t, "source_pack_ops.go")
	formulaViewsSrc := readControlplaneSourceForStructureTest(t, "source_pack_ops_formula_views.go")

	for _, symbol := range []string{
		"func materializeSourceBackedPackDerived(",
		"func verifySourceBackedDerivedArtifacts(",
		"func verifySourceBackedDerivedArtifactsWithCompileProof(",
		"func formulaViewCompileProofForRunner(",
		"func formulaViewCompileProofForDB(",
		"type formulaStorageRow struct",
		"func queryFormulaStorageRows(",
		"func verifyActiveFormulaViewsUsable(",
		"func formulaViewExists(",
		"func verifyFormulaViewUsable(",
	} {
		if strings.Contains(opsSrc, symbol) {
			t.Fatalf("source_pack_ops.go still owns formula-view derived artifact helper %q", symbol)
		}
		if !strings.Contains(formulaViewsSrc, symbol) {
			t.Fatalf("source_pack_ops_formula_views.go is missing formula-view derived artifact helper %q", symbol)
		}
	}
}

func readControlplaneSourceForStructureTest(t *testing.T, filename string) string {
	t.Helper()

	raw, err := os.ReadFile(filename)
	if err != nil {
		t.Fatalf("read %s: %v", filename, err)
	}
	return string(raw)
}
