// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAZValueNetworkShapeTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AZ.ValueNetworkShape",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAZValueNetworkShapeTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchValueNetworkShapeBoundary Boundary;
	TestTrue(
		TEXT("The learned-search value-network shape boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchValueNetworkShapeBoundary(
			TEXT("learned-search-value-network-shape-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The learned-search value-network shape id must stay stable."),
		Boundary.BoundaryId,
		TEXT("learned-search-value-network-shape-boundary")
	);
	TestTrue(
		TEXT("The value-network shape boundary must preserve the flattened input reshape."),
		Boundary.ArchitectureSurfaceTags.Contains(TEXT("flattened input reshape"))
	);
	TestTrue(
		TEXT("The value-network shape boundary must preserve the 4096-2048-512 linear stack."),
		Boundary.ArchitectureSurfaceTags.Contains(TEXT("4096-2048-512 linear stack"))
	);
	TestTrue(
		TEXT("The value-network shape boundary must preserve xavier-normal weight init."),
		Boundary.InitializationSurfaceTags.Contains(TEXT("xavier-normal weight init"))
	);
	TestTrue(
		TEXT("The value-network shape boundary must preserve zero-bias init posture."),
		Boundary.InitializationSurfaceTags.Contains(TEXT("zero-bias init posture"))
	);
	TestTrue(
		TEXT("The value-network shape boundary must keep deployed model serving excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("deployed model serving ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistLearnedSearchPhase6RAZGeneratorSyncTest,
	"HyperTwist.FirstParty.LearnedSearch.Phase6R.AZ.GeneratorSync",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistLearnedSearchPhase6RAZGeneratorSyncTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingLearnedSearchGeneratorSyncBoundary Boundary;
	TestTrue(
		TEXT("The learned-search generator sync boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledLearnedSearchGeneratorSyncBoundary(
			TEXT("learned-search-generator-sync-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The learned-search generator sync id must stay stable."),
		Boundary.BoundaryId,
		TEXT("learned-search-generator-sync-boundary")
	);
	TestTrue(
		TEXT("The generator sync boundary must preserve tau-weighted generator refresh."),
		Boundary.SyncSurfaceTags.Contains(TEXT("tau-weighted generator refresh"))
	);
	TestTrue(
		TEXT("The generator sync boundary must preserve state-dict merge posture."),
		Boundary.SyncSurfaceTags.Contains(TEXT("state-dict merge posture"))
	);
	TestTrue(
		TEXT("The generator sync boundary must preserve device-aware parameter copy."),
		Boundary.ParameterSurfaceTags.Contains(TEXT("device-aware parameter copy"))
	);
	TestTrue(
		TEXT("The generator sync boundary must preserve generator return-on-device posture."),
		Boundary.ParameterSurfaceTags.Contains(TEXT("generator return-on-device posture"))
	);
	TestTrue(
		TEXT("The generator sync boundary must keep provider-backed model lifecycle ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("provider-backed model lifecycle ownership"))
	);
	TestTrue(
		TEXT("The generator sync boundary must preserve the benchmark-only training-service caveat."),
		Boundary.ProvenanceCaveats.Contains(TEXT("generator sync remains benchmark-only and non-authoritative for deployed training services"))
	);
	return true;
}

#endif
