// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAXNodeIdentityTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AX.NodeIdentity",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAXNodeIdentityTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchNodeIdentityContract Contract;
	TestTrue(
		TEXT("The learned-search node identity contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchNodeIdentityContract(
			TEXT("learned-search-node-identity-contract"),
			Contract
		)
	);
	TestEqual(
		TEXT("The learned-search node identity id must stay stable."),
		Contract.ContractId,
		TEXT("learned-search-node-identity-contract")
	);
	TestEqual(
		TEXT("The learned-search node identity contract must remain first-party."),
		Contract.SourceAttribution.SourceMode,
		EHyperTwistTrainingSourceMode::FirstParty
	);
	TestTrue(
		TEXT("The node identity contract must preserve flattened-byte node hashing."),
		Contract.IdentitySurfaceTags.Contains(TEXT("flattened-byte node hash"))
	);
	TestTrue(
		TEXT("The node identity contract must preserve shallower-depth replacement policy."),
		Contract.IdentitySurfaceTags.Contains(TEXT("shallower-depth replacement policy"))
	);
	TestTrue(
		TEXT("The node identity contract must preserve parent-linked lineage."),
		Contract.LineageSurfaceTags.Contains(TEXT("parent-linked lineage"))
	);
	TestTrue(
		TEXT("The node identity contract must keep canonical replay ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("canonical replay ledger ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAXStateExpansionTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AX.StateExpansion",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAXStateExpansionTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchStateExpansionBoundary Boundary;
	TestTrue(
		TEXT("The learned-search state-expansion boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchStateExpansionBoundary(
			TEXT("learned-search-state-expansion-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The state-expansion boundary id must stay stable."),
		Boundary.BoundaryId,
		TEXT("learned-search-state-expansion-boundary")
	);
	TestTrue(
		TEXT("The state-expansion boundary must preserve 12-way successor expansion."),
		Boundary.ExpansionSurfaceTags.Contains(TEXT("12-way successor expansion"))
	);
	TestTrue(
		TEXT("The state-expansion boundary must preserve vectorized reward scan."),
		Boundary.ExpansionSurfaceTags.Contains(TEXT("vectorized reward scan"))
	);
	TestTrue(
		TEXT("The state-expansion boundary must preserve solved-state goal tagging."),
		Boundary.GoalSurfaceTags.Contains(TEXT("solved-state goal tagging"))
	);
	TestTrue(
		TEXT("The state-expansion boundary must keep committed-face reconstruction ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("committed-face reconstruction ownership"))
	);
	TestTrue(
		TEXT("The state-expansion boundary must preserve the benchmark-only reconstruction caveat."),
		Boundary.ProvenanceCaveats.Contains(TEXT("state expansion remains benchmark-only and non-authoritative for live reconstruction"))
	);
	return true;
}

#endif
