package soql_test

import (
	"os/exec"
	"strings"
	"testing"
)

// TestExternalDialectHasNoBackendOrGinDependency is the compiler/boundary proof
// that the SOQL dialect module is seal-clean: it must not transitively depend on
// github.com/nexuscrm/backend OR github.com/gin-gonic/gin. SOQL is an L1
// (Salesforce query LANGUAGE) concern that lives ABOVE the L0 contract, so it is
// now a compatibility adapter over the independently publishable, stdlib-only
// sfcrm/querycodec plus the legacy shared request types consumed by the
// transitional dialect. This makes the parser's single L1 owner a compile fact
// instead of leaving a second copy in the compatibility module. Run under
// GOWORK=off in CI so workspace replacements cannot mask a dependency leak.
func TestExternalDialectHasNoBackendOrGinDependency(t *testing.T) {
	out, err := exec.Command("go", "list", "-deps", "./...").CombinedOutput()
	if err != nil {
		t.Fatalf("go list -deps ./...: %v\n%s", err, out)
	}
	const codec = "github.com/pingcap-inc/nexuscrm-app-packs/sfcrm/querycodec"
	foundCodec := false
	forbidden := []string{"github.com/nexuscrm/backend", "github.com/gin-gonic/gin"}
	for _, dep := range strings.Fields(string(out)) {
		if dep == codec {
			foundCodec = true
		}
		for _, bad := range forbidden {
			if dep == bad || strings.HasPrefix(dep, bad+"/") {
				t.Errorf("external dialect transitively depends on forbidden package %q", dep)
			}
		}
	}
	if !foundCodec {
		t.Fatalf("compatibility module does not consume the single-owner codec %q", codec)
	}
}
