// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAYFrontierScoringTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AY.FrontierScoring",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAYFrontierScoringTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchFrontierScoringBoundary Boundary;
	TestTrue(
		TEXT("The learned-search frontier scoring boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchFrontierScoringBoundary(
			TEXT("learned-search-frontier-scoring-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The learned-search frontier scoring boundary id must stay stable."),
		Boundary.BoundaryId,
		TEXT("learned-search-frontier-scoring-boundary")
	);
	TestTrue(
		TEXT("The frontier scoring boundary must preserve weighted f-score depth penalty."),
		Boundary.FrontierSurfaceTags.Contains(TEXT("weighted f-score depth penalty"))
	);
	TestTrue(
		TEXT("The frontier scoring boundary must preserve the batched frontier pop window."),
		Boundary.FrontierSurfaceTags.Contains(TEXT("batched frontier pop window"))
	);
	TestTrue(
		TEXT("The frontier scoring boundary must preserve one-hot categorical heuristic input."),
		Boundary.EvaluationSurfaceTags.Contains(TEXT("one-hot categorical heuristic input"))
	);
	TestTrue(
		TEXT("The frontier scoring boundary must preserve torch no-grad evaluation posture."),
		Boundary.EvaluationSurfaceTags.Contains(TEXT("torch no-grad evaluation posture"))
	);
	TestTrue(
		TEXT("The frontier scoring boundary must keep deployed model serving excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("deployed model serving ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAYSolutionUnwindTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AY.SolutionUnwind",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAYSolutionUnwindTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchSolutionUnwindBoundary Boundary;
	TestTrue(
		TEXT("The learned-search solution unwind boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchSolutionUnwindBoundary(
			TEXT("learned-search-solution-unwind-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The learned-search solution unwind boundary id must stay stable."),
		Boundary.BoundaryId,
		TEXT("learned-search-solution-unwind-boundary")
	);
	TestTrue(
		TEXT("The solution unwind boundary must preserve goal-index to parent-chain unwind."),
		Boundary.RecoverySurfaceTags.Contains(TEXT("goal-index to parent-chain unwind"))
	);
	TestTrue(
		TEXT("The solution unwind boundary must preserve clear-seq normalization posture."),
		Boundary.RecoverySurfaceTags.Contains(TEXT("clear-seq normalization posture"))
	);
	TestTrue(
		TEXT("The solution unwind boundary must preserve time-bounded search mode."),
		Boundary.TerminationSurfaceTags.Contains(TEXT("time-bounded search mode"))
	);
	TestTrue(
		TEXT("The solution unwind boundary must preserve iteration and generated-node reporting."),
		Boundary.TerminationSurfaceTags.Contains(TEXT("iteration and generated-node reporting"))
	);
	TestTrue(
		TEXT("The solution unwind boundary must keep canonical replay ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("canonical replay ledger ownership"))
	);
	TestTrue(
		TEXT("The solution unwind boundary must preserve the benchmark-only replay caveat."),
		Boundary.ProvenanceCaveats.Contains(TEXT("solution unwind remains benchmark-only and non-authoritative for canonical replay"))
	);
	return true;
}

#endif
