chore: checkpoint current workspace changes

This commit is contained in:
2026-04-11 22:14:02 +08:00
parent 3e55f8c204
commit 8848cfd958
227 changed files with 34027 additions and 6711 deletions

View File

@@ -4,6 +4,7 @@
#include <XCEngine/Core/Asset/ProjectAssetIndex.h>
#include <XCEngine/Core/Asset/ResourceManager.h>
#include <XCEngine/Core/IO/IResourceLoader.h>
#include <XCEngine/Resources/Material/MaterialLoader.h>
#include <XCEngine/Resources/Mesh/Mesh.h>
#include <algorithm>
@@ -350,12 +351,12 @@ TEST(AssetImportService_Test, RebuildLibraryCacheKeepsStableAssetRefs) {
ASSERT_TRUE(firstAssetRef.IsValid());
const fs::path libraryRoot(importService.GetLibraryRoot().CStr());
EXPECT_TRUE(fs::exists(libraryRoot / "SourceAssetDB" / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "ArtifactDB" / "artifacts.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "artifacts.db"));
EXPECT_TRUE(importService.RebuildLibraryCache());
EXPECT_TRUE(fs::exists(libraryRoot / "SourceAssetDB" / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "ArtifactDB" / "artifacts.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "artifacts.db"));
AssetRef secondAssetRef;
ASSERT_TRUE(importService.TryGetAssetRef("Assets/runtime.material", ResourceType::Material, secondAssetRef));
@@ -368,6 +369,61 @@ TEST(AssetImportService_Test, RebuildLibraryCacheKeepsStableAssetRefs) {
fs::remove_all(projectRoot);
}
TEST(AssetImportService_Test, EnsureArtifactExposesContainerEntryRuntimeLoadPath) {
namespace fs = std::filesystem;
AssetImportService importService;
importService.Initialize();
const fs::path projectRoot = fs::temp_directory_path() / "xc_asset_import_service_entry_runtime_path_test";
const fs::path assetsDir = projectRoot / "Assets";
const fs::path materialPath = assetsDir / "runtime.material";
fs::remove_all(projectRoot);
fs::create_directories(assetsDir);
{
std::ofstream materialFile(materialPath);
ASSERT_TRUE(materialFile.is_open());
materialFile << "{\n";
materialFile << " \"renderQueue\": \"geometry\"\n";
materialFile << "}\n";
}
importService.SetProjectRoot(projectRoot.string().c_str());
AssetImportService::ImportedAsset importedAsset;
ASSERT_TRUE(importService.EnsureArtifact("Assets/runtime.material", ResourceType::Material, importedAsset));
ASSERT_TRUE(importedAsset.exists);
ASSERT_TRUE(importedAsset.artifactReady);
EXPECT_EQ(importedAsset.artifactStorageKind, ArtifactStorageKind::SingleFileContainer);
EXPECT_EQ(importedAsset.mainEntryName, "main");
EXPECT_FALSE(importedAsset.artifactMainPath.Empty());
EXPECT_FALSE(importedAsset.artifactMainEntryPath.Empty());
EXPECT_EQ(importedAsset.runtimeLoadPath, importedAsset.artifactMainEntryPath);
EXPECT_NE(importedAsset.artifactMainEntryPath, importedAsset.artifactMainPath);
EXPECT_NE(std::string(importedAsset.runtimeLoadPath.CStr()).find("@entry=main"), std::string::npos);
{
const fs::path artifactDbPath = fs::path(importService.GetLibraryRoot().CStr()) / "artifacts.db";
std::ifstream artifactDbInput(artifactDbPath, std::ios::binary);
ASSERT_TRUE(artifactDbInput.is_open());
std::stringstream artifactDbBuffer;
artifactDbBuffer << artifactDbInput.rdbuf();
const std::string artifactDbText = artifactDbBuffer.str();
EXPECT_NE(artifactDbText.find("# schema=2"), std::string::npos);
EXPECT_NE(artifactDbText.find("storageKind\tmainEntryName"), std::string::npos);
}
MaterialLoader loader;
LoadResult loadResult = loader.Load(importedAsset.runtimeLoadPath);
ASSERT_TRUE(loadResult);
ASSERT_NE(loadResult.resource, nullptr);
delete loadResult.resource;
importService.Shutdown();
fs::remove_all(projectRoot);
}
TEST(ResourceManager_Test, RebuildProjectAssetCacheRefreshesLookupState) {
namespace fs = std::filesystem;
@@ -395,10 +451,10 @@ TEST(ResourceManager_Test, RebuildProjectAssetCacheRefreshesLookupState) {
ASSERT_TRUE(firstAssetRef.IsValid());
const fs::path libraryRoot(manager.GetProjectLibraryRoot().CStr());
EXPECT_TRUE(fs::exists(libraryRoot / "SourceAssetDB" / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "assets.db"));
EXPECT_TRUE(manager.RebuildProjectAssetCache());
EXPECT_TRUE(fs::exists(libraryRoot / "SourceAssetDB" / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "assets.db"));
AssetRef secondAssetRef;
ASSERT_TRUE(manager.TryGetAssetRef("Assets/runtime.material", ResourceType::Material, secondAssetRef));
@@ -410,6 +466,45 @@ TEST(ResourceManager_Test, RebuildProjectAssetCacheRefreshesLookupState) {
fs::remove_all(projectRoot);
}
TEST(ResourceManager_Test, AssetImportServiceMigratesLegacyLibraryDatabasePathsToLibraryRoot) {
namespace fs = std::filesystem;
AssetImportService importService;
importService.Initialize();
const fs::path projectRoot = fs::temp_directory_path() / "xc_library_db_path_migration_test";
const fs::path assetsDir = projectRoot / "Assets";
const fs::path legacySourceDbPath = projectRoot / "Library" / "SourceAssetDB" / "assets.db";
const fs::path legacyArtifactDbPath = projectRoot / "Library" / "ArtifactDB" / "artifacts.db";
fs::remove_all(projectRoot);
fs::create_directories(assetsDir);
fs::create_directories(legacySourceDbPath.parent_path());
fs::create_directories(legacyArtifactDbPath.parent_path());
{
std::ofstream sourceDbFile(legacySourceDbPath);
ASSERT_TRUE(sourceDbFile.is_open());
sourceDbFile << "# legacy source database\n";
}
{
std::ofstream artifactDbFile(legacyArtifactDbPath);
ASSERT_TRUE(artifactDbFile.is_open());
artifactDbFile << "# legacy artifact database\n";
}
importService.SetProjectRoot(projectRoot.string().c_str());
const fs::path libraryRoot(importService.GetLibraryRoot().CStr());
EXPECT_TRUE(fs::exists(libraryRoot / "assets.db"));
EXPECT_TRUE(fs::exists(libraryRoot / "artifacts.db"));
EXPECT_FALSE(fs::exists(legacySourceDbPath));
EXPECT_FALSE(fs::exists(legacyArtifactDbPath));
importService.Shutdown();
fs::remove_all(projectRoot);
}
TEST(ResourceManager_Test, SetResourceRootBootstrapsProjectAssetCache) {
namespace fs = std::filesystem;