// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAWSequencePolicyTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AW.SequencePolicy",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAWSequencePolicyTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchSequencePolicyContract Contract;
	TestTrue(
		TEXT("The learned-search sequence policy contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchSequencePolicyContract(
			TEXT("learned-search-sequence-policy-contract"),
			Contract
		)
	);
	TestEqual(
		TEXT("The learned-search sequence policy id must stay stable."),
		Contract.ContractId,
		TEXT("learned-search-sequence-policy-contract")
	);
	TestEqual(
		TEXT("The learned-search sequence policy must remain first-party."),
		Contract.SourceAttribution.SourceMode,
		EHyperTwistTrainingSourceMode::FirstParty
	);
	TestTrue(
		TEXT("The sequence policy must preserve inverse-pair suppression."),
		Contract.SequenceSurfaceTags.Contains(TEXT("inverse-pair suppression"))
	);
	TestTrue(
		TEXT("The sequence policy must preserve triple-repeat suppression."),
		Contract.SequenceSurfaceTags.Contains(TEXT("triple-repeat suppression"))
	);
	TestTrue(
		TEXT("The sequence policy must preserve optional solved-state inclusion."),
		Contract.SamplingSurfaceTags.Contains(TEXT("optional solved-state inclusion"))
	);
	TestTrue(
		TEXT("The sequence policy must preserve learn-first-close weighting."),
		Contract.WeightingSurfaceTags.Contains(TEXT("learn-first-close weighting"))
	);
	TestTrue(
		TEXT("The sequence policy must keep live replay notation ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("live replay notation ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAWSearchBudgetTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AW.SearchBudget",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAWSearchBudgetTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchSearchBudgetBoundary Boundary;
	TestTrue(
		TEXT("The learned-search search-budget boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchSearchBudgetBoundary(
			TEXT("learned-search-search-budget-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The search-budget boundary id must stay stable."),
		Boundary.BoundaryId,
		TEXT("learned-search-search-budget-boundary")
	);
	TestTrue(
		TEXT("The search-budget boundary must preserve weighted frontier ranking."),
		Boundary.BudgetSurfaceTags.Contains(TEXT("weighted frontier ranking"))
	);
	TestTrue(
		TEXT("The search-budget boundary must preserve iteration-cap search mode."),
		Boundary.BudgetSurfaceTags.Contains(TEXT("iteration-cap search mode"))
	);
	TestTrue(
		TEXT("The search-budget boundary must preserve benchmark checkpoint clone posture."),
		Boundary.FrontierSurfaceTags.Contains(TEXT("benchmark checkpoint clone posture"))
	);
	TestTrue(
		TEXT("The search-budget boundary must keep correctness/performance oracle ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("correctness/performance oracle ownership"))
	);
	TestTrue(
		TEXT("The search-budget boundary must preserve the benchmark-only live solve UX caveat."),
		Boundary.ProvenanceCaveats.Contains(TEXT("frontier budgets remain benchmark-only and non-authoritative for live solve UX"))
	);
	return true;
}

#endif
