package boundary_test

import (
	"testing"
)

// L0-E CreateTree carve, PR-3 (anti-regrowth seal).
//
// PR-1 added the neutral nested tree-create IR (contract.TreeNode) and the
// engine path CreateTreeNodes/insertTreeNodeIR on a SEPARATE TreeNodeWriter
// interface; PR-2 flipped the SF dialect to decode its Composite-Tree wire
// grammar into []TreeNode and call CreateTreeNodes; PR-3 removed the old
// []Record/[]map tree path (Records.CreateTree, ContractService.CreateTree,
// PersistenceService.CreateTree, insertTreeNode, appendTreeObjectNames,
// groupMembershipClosureObjectNamesFromTree). After PR-3 the SF Composite-Tree
// wire grammar is parsed ENTIRELY in the dialect; the L0 records engine only
// ever sees the fully structured contract.TreeNode.
//
// These markers were the two wire-grammar accesses that lived ONLY in the
// deleted SF-shaped parse (insertTreeNode / appendTreeObjectNames):
//
//   - the intra-batch alias marker: the lowercase `referenceId` wire key, pulled
//     out of each node's `attributes` sub-map (`attr["referenceId"]`) and echoed
//     back in the SObject result. The neutral engine reads the exported struct
//     field contract.TreeNode.ReferenceID (capitalized) instead and never touches
//     the lowercase wire key, so a case-sensitive scan for `referenceId` is a
//     precise regrowth signal.
//   - the nested-relationship marker: the `"records"` wire key, the named
//     sub-object the SF grammar wraps each child collection in
//     (`m["records"].([]interface{})`). The neutral engine reads the structured
//     contract.TreeNode.Children map instead and never indexes a `"records"` key.
//
// If either reappears in nexuscrm-records production Go, the SF Composite-Tree
// wire decode has leaked back below the dialect boundary into the app-blind L0
// engine — exactly the regression this carve removed.
var createTreeSFWireGrammarMarkers = []string{
	"referenceId",
	`"records"`,
}

func TestL0ECreateTreeSFWireGrammarSealedFromRecordsEngine(t *testing.T) {
	root := repoRoot(t)
	got := countMarkersByFile(t, root, []string{"nexuscrm-records"}, createTreeSFWireGrammarMarkers)
	if len(got) != 0 {
		t.Fatalf("SF Composite-Tree wire-grammar markers reappeared in nexuscrm-records production Go: %s\n"+
			"markers %v are the intra-batch alias (referenceId) and nested-relationship (\"records\") wire accesses that\n"+
			"must live only in the SF dialect after the L0-E CreateTree carve. The L0 records engine consumes the\n"+
			"structured contract.TreeNode (ReferenceID field / Children map), not the SF wire grammar. If this is an\n"+
			"intentional boundary change, it belongs in a migration PR, not a records-engine edit.",
			formatCountMap(got), createTreeSFWireGrammarMarkers)
	}
}
