package controlplane

import (
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"testing"
)

func TestL0OracleAssemblyStaysOutOfVerifyL0Root(t *testing.T) {
	rootSrc := readControlplaneSourceForL0StructureTest(t, "verify_l0.go")
	oracleSrc := readControlplaneSourceForL0StructureTest(t, "verify_l0_oracle.go")

	for _, symbol := range []string{
		"func buildL0Oracle(",
		"func injectStandardSystemFieldsForL0Oracle(",
	} {
		if strings.Contains(rootSrc, symbol) {
			t.Fatalf("verify_l0.go still owns L0 oracle assembly symbol %q", symbol)
		}
		if !strings.Contains(oracleSrc, symbol) {
			t.Fatalf("verify_l0_oracle.go is missing L0 oracle assembly symbol %q", symbol)
		}
	}
}

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

	_, currentFile, _, ok := runtime.Caller(0)
	if !ok {
		t.Fatal("locate current test file")
	}
	raw, err := os.ReadFile(filepath.Join(filepath.Dir(currentFile), filename))
	if err != nil {
		t.Fatalf("read %s: %v", filename, err)
	}
	return string(raw)
}
