package dialectsfcrm_test

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

// TestExternalDialectHasNoBackendOrGinDependency is the compiler/boundary proof for
// issue #1743 / #2015 PR-0: this out-of-tree gin-free dialect (the salesforce-v63
// composite/tree route partition) must not transitively depend on
// github.com/nexuscrm/backend or github.com/gin-gonic/gin.
// This is what makes "an external app pack authors a dialect against shared alone,
// with the transport framework owned by the backend binder" a compile fact rather
// than a convention.
//
// It is the own-file-scoped dep-budget / seal: it runs `go list -deps ./...` over
// THIS module's own dependency closure (resolved through this module's go.mod), so
// it stays valid under a workspace (go.work) and under GOWORK=off alike — CI runs
// it with GOWORK=off so the closure resolves through the module's own go.mod, not a
// workspace union.
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)
	}
	forbidden := []string{
		"github.com/nexuscrm/backend",
		"github.com/gin-gonic/gin",
	}
	for _, dep := range strings.Fields(string(out)) {
		for _, bad := range forbidden {
			if dep == bad || strings.HasPrefix(dep, bad+"/") {
				t.Errorf("external dialect transitively depends on forbidden package %q", dep)
			}
		}
	}
}
