Ship a disk example pack so last-wins, patches and create-with-a-mod are tested for real.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leonid Pershin
2026-08-20 01:06:12 +03:00
co-authored by Cursor
parent edd3d35c79
commit 505b1429ab
20 changed files with 405 additions and 14 deletions
@@ -0,0 +1,97 @@
namespace HSchool.Content.Tests;
/// <summary>
/// The shipped <c>mods/example</c> folder, copied next to vanilla core. Last-wins, patches and a
/// placeable room have to work from disk — in-memory documents already have their own tests.
/// </summary>
public class ExamplePackTests
{
private const string ExamplePackId = "example";
private readonly CatalogLoader _loader = new();
[Fact]
public void DuplicateChair_LastWinsAndWarns()
{
var log = new RecordingLog();
var catalog = LoadCoreAndExample(log);
Assert.Equal(["Sit", "Chat"], catalog.Things["Chair"].Actions);
Assert.Contains(
log.Warnings,
warning => warning.Contains("Chair", StringComparison.Ordinal)
&& warning.Contains(ExamplePackId, StringComparison.Ordinal));
}
[Fact]
public void PatchAddsASlot_OnlyWhenThePackIsLoaded()
{
var vanilla = LoadCore();
Assert.DoesNotContain(vanilla.Rooms["PrincipalsOffice"].Slots, slot => slot.Key == "exampleLocker");
var withPack = LoadCoreAndExample();
Assert.Contains(withPack.Rooms["PrincipalsOffice"].Slots, slot => slot.Key == "exampleLocker" && slot.Thing == "Locker");
}
[Fact]
public void PackTypes_LoadWithLocalizedLabels()
{
var catalog = LoadCoreAndExample();
Assert.True(catalog.Traits.ContainsKey("ExampleEarlyRiser"));
Assert.True(catalog.Traits.ContainsKey("ExampleNightOwl"));
Assert.True(catalog.NameSets.ContainsKey("ExampleNames"));
Assert.True(catalog.Rooms.ContainsKey("ExampleStore"));
Assert.Equal("Кладовая", catalog.Label("ru", catalog.Rooms["ExampleStore"]));
Assert.Equal("Storeroom", catalog.Label("en", catalog.Rooms["ExampleStore"]));
Assert.Equal("Примерные имена", catalog.Label("ru", catalog.NameSets["ExampleNames"]));
Assert.Equal(["RussianLanguage"], catalog.NameSets["ExampleNames"].Spoken.ToArray());
Assert.True(catalog.Rooms.ContainsKey("PrincipalsOffice"));
Assert.Equal("Кабинет директора", catalog.Label("ru", catalog.Rooms["PrincipalsOffice"]));
}
[Fact]
public void MapUsingThePackRoom_PassesValidation()
{
var catalog = LoadCoreAndExample();
var map = new MapLayout
{
Territory = new TerritoryNode { Id = "yard", Def = "SchoolYard" },
Buildings = [new BuildingNode { Id = "main", Def = "MainBuilding" }],
Floors = [new FloorNode { Id = "floor-1", Def = "StandardFloor", Building = "main" }],
Rooms =
[
new RoomNode { Id = "store", Def = "ExampleStore", Building = "main", Floor = "floor-1" },
],
Links = [new MapLink { A = "yard", B = "store" }],
};
MapValidator.Validate(map, catalog);
var defaults = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId, ExamplePackId], Documents());
Assert.NotNull(defaults);
Assert.Equal("SchoolYard", defaults.Territory?.Def);
}
private DefCatalog LoadCore() =>
_loader.Load(
[CatalogLoader.CorePackId],
PackDocuments.FromDirectory(CatalogLoader.CorePackId, CoreRoot()));
private DefCatalog LoadCoreAndExample(IContentLog? log = null) =>
_loader.Load([CatalogLoader.CorePackId, ExamplePackId], Documents(), log);
private static IReadOnlyList<ContentDocument> Documents()
{
var example = ExampleRoot();
Assert.True(Directory.Exists(example), $"Example pack was not copied to {example}.");
return
[
.. PackDocuments.FromDirectory(CatalogLoader.CorePackId, CoreRoot()),
.. PackDocuments.FromDirectory(ExamplePackId, example),
];
}
private static string CoreRoot() => Path.Combine(AppContext.BaseDirectory, "vanilla");
private static string ExampleRoot() => Path.Combine(AppContext.BaseDirectory, "example");
}
@@ -25,6 +25,10 @@
<Link>vanilla\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\src\HSchool.Server\mods\example\**\*">
<Link>example\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>