diff --git a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs index 18cf51de5..42be988fa 100644 --- a/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs +++ b/tests/Aetheria.Shared.Tests/RestoredHullsTests.cs @@ -13,6 +13,7 @@ using GameCult.Caching.MessagePack; using Xunit; using static CultMath.math; using float3 = CultMath.float3; +using Random = CultMath.Random; // Cut 1 (docs/locomotion-cut.md, "Restore the legacy thruster ship hulls to the live catalog"). Verifies the // content restore-hulls landed, against the real shipped catalog, read-only: the hulls exist with the expected @@ -56,12 +57,9 @@ public sealed class RestoredHullsTests private static CultCache OpenCatalog() => OpenReadOnlyRealCatalog(Path.Combine(FindRepoRoot(), "GameData", "Aetheria.cc")); - // Same registry-scoping problem FireControlCut7Tests.OpenReadOnlyRealCatalog solves for a catalog-only open: - // AetheriaStores.Open's `new CultCache()` uses the shared, AppDomain-scanning registry, which also picks up - // this test assembly's own [CultDocument] fixture types and then demands a record for each -- so this test, - // which also needs a writable scratch run store (RunSave.Commit's SavedGame/SavedZone), builds the same - // catalog+run composition AetheriaStores.Open does, but against a registry scoped to the shipped assembly. - private static CultCache OpenRealCatalogWithScratchRun(string catalogPath, string runPath) + // ZoneGenerator.GenerateZone writes OrbitData/BodyData (run-store types, AetheriaStores.RunTypes), so a + // catalog-only cache has no home for them. A scratch run file, deleted after the seed that used it. + private static CultCache OpenReadOnlyRealCatalogWithScratchRun(string catalogPath, string runPath) { var registry = CultDocumentRegistry.ForTypes(typeof(ItemData).Assembly.GetTypes() .Where(t => t is { IsAbstract: false, IsInterface: false }) @@ -72,6 +70,36 @@ public sealed class RestoredHullsTests return cache; } + // Headless asset-reference rule: every hull's Prefab, every ThrusterData.ParticlesPrefab, and every + // non-empty Schematic names a GUID that actually exists under Assets/ (a .meta file carries it). Unity's + // EngineAssetCheck enforces this too, but only in-editor; this is the same check run headless against the + // shipped catalog, so a fabricated or dropped GUID fails a build that never opens Unity. Soul's own probe + // (commit message, this cut's fix batch) found Djinni.Prefab fabricated and all five restored thrusters' + // ParticlesPrefab null; this test is that probe, committed so it can be rerun and mutated. + [Fact] + public void EveryAssetReferenceResolvesToAMetaGuid() + { + var assetGuids = new HashSet(Directory.EnumerateFiles(Path.Combine(FindRepoRoot(), "Assets"), "*.meta", SearchOption.AllDirectories) + .Select(f => File.ReadLines(f).FirstOrDefault(l => l.StartsWith("guid: "))?.Substring("guid: ".Length).Trim()) + .Where(g => g != null)); + + using var cache = OpenCatalog(); + var missing = new List(); + foreach (var hull in cache.GetAll()) + if (!assetGuids.Contains(hull.Prefab ?? "")) + missing.Add($"{hull.Name}.Prefab = {hull.Prefab ?? "null"}"); + foreach (var design in cache.GetAll()) + { + foreach (var thruster in design.Behaviors.OfType()) + if (!assetGuids.Contains(thruster.ParticlesPrefab ?? "")) + missing.Add($"{design.Name}.ParticlesPrefab = {thruster.ParticlesPrefab ?? "null"}"); + if (!string.IsNullOrEmpty(design.Schematic) && !assetGuids.Contains(design.Schematic)) + missing.Add($"{design.Name}.Schematic = {design.Schematic}"); + } + + Assert.True(missing.Count == 0, "Dangling asset references:\n" + string.Join("\n", missing)); + } + [Theory] [InlineData("Longinus", 4)] [InlineData("Djinni", 8)] @@ -169,83 +197,82 @@ public sealed class RestoredHullsTests ship.MovementDirection = float2(0, 1); // full forward, same axis ActionGameManager.Input.Player.Move drives ship.LookDirection = float3(1, 0, 0); // off-axis target heading, so the mixer's yaw thrusters have work to do for (var i = 0; i < 10; i++) zone.Update(1f / 60f); - System.Console.WriteLine($"DEBUG end velocity {ship.Velocity} direction {ship.Direction}"); Assert.NotEqual(startVelocity, ship.Velocity); Assert.NotEqual(startDirection, ship.Direction); } - // Operator addition, 2026-09-25: "What we're testing is going to be the tutorial level... Let's drop a - // station in there." ZoneGenerator's STORY station path (galaxyZone.Locations, populated by StoryProcessor) - // is dead in the live code today -- Galaxy's tutorial constructor has that call commented out - // (Assets/Scripts/ServerShared/Galaxy.cs:242) -- so every zone's stations come from the BACKGROUND path - // (ZoneGenerator.cs:290-304): a random count near the owning faction, placed at whatever Lagrange points - // that zone's own planet generation produced. That placement is genuinely probabilistic (stationCount can - // roll 0, and a zone with no sub-zones has nowhere to put one), so this drives real generation across many - // zone names/seeds and asserts at least one produces a station with a docking bay -- proof this repo's own - // ZoneGenerator can still place a station on the restored catalog, not a claim that every zone gets one. - // - // Builds the same minimal SavedGame/Galaxy round trip the shipped AetherDb `loadout exclude-sellers` command - // and FireControlCut6cTests use, scoped to Aeronautics Unlimited (Zenith's own seller, docs probe) as the - // zone's sole owning/nearest faction so factionPresence is high and stations are not competing for the RNG - // draw with distant, uninvolved factions. + // Operator ruling, 2026-09-25 (docs/locomotion-cut.md, "Tutorial station"): "What we're testing is going to + // be the tutorial level, right? Let's drop a station in there." The tutorial's entrance zone always gets a + // generated faction station with a docking bay, deterministically -- not merely likely. This REPLACES + // TutorialZoneGenerationCanProduceADockedStation, which never used the tutorial construction path at all: it + // built an ad hoc single-zone SavedGame/Galaxy and asserted a docking bay showed up in at least one of 25 + // zone-name variants, which is a claim about the BACKGROUND station path in general, not about the entrance + // zone Galaxy.cs actually picks (lowest-influence, unowned -- the one case ZoneGenerator.cs's own stationCount + // roll produces 0 on essentially every seed, docs' own probe: 30 of 30). This test builds the real tutorial + // Galaxy exactly as Assets/Resources/Settings.asset configures it and ActionGameManager.StartGame -> + // PopulateLevel(CurrentGalaxy.Entrance) generates it, across seeds, and requires a docked station in every + // run. It must fail without ZoneGenerator's tutorial-entrance override. [Fact] - public void TutorialZoneGenerationCanProduceADockedStation() + public void EntranceZoneAlwaysGetsADockedStationAcrossSeeds() { - var gameData = Path.Combine(FindRepoRoot(), "GameData", "Aetheria.cc"); var zoneSettings = new ZoneGenerationSettings { - SunMass = 5000, - PlanetMass = 100, - SatellitePasses = 2, - SatelliteCreationProbability = 0, - BinaryCreationProbability = 0, - RosetteProbability = 0, - ZoneRadius = new ExponentialLerp { Minimum = 1000, Maximum = 1000, Exponent = 1 }, - ZoneMass = new ExponentialLerp { Minimum = 1000, Maximum = 1000, Exponent = 1 }, - SubZoneCount = new ExponentialLerp { Minimum = 4, Maximum = 4, Exponent = 1 }, - ZoneBoundaryRadius = 4, - BeltProbability = 0, - PlanetSafetyRadius = new ExponentialCurve { Multiplier = 1, Exponent = 0 }, + PlanetSafetyRadius = new ExponentialCurve { Exponent = .25f, Multiplier = 2.5f, Constant = 0 }, + MassFloor = 1, SunMass = 5000, GasGiantMass = 1000, PlanetMass = 100, + SatellitePasses = 5, SatelliteCreationMassFloor = 100, SatelliteCreationProbability = .25f, + BinaryCreationProbability = .1f, RosetteProbability = .1f, + ZoneRadius = new ExponentialLerp { Exponent = 1.5f, Minimum = 1000, Maximum = 10000 }, + ZoneMass = new ExponentialLerp { Exponent = 1.5f, Minimum = 10000, Maximum = 500000 }, + SubZoneCount = new ExponentialLerp { Exponent = 1.5f, Minimum = 0, Maximum = 8 }, + ZoneBoundaryRadius = .9f, BeltProbability = .25f, BeltMassCeiling = 500, + AsteroidBeltWidth = new ExponentialCurve { Exponent = .666f, Multiplier = 5, Constant = 50 }, + AsteroidCount = new ExponentialCurve { Exponent = .5f, Multiplier = 1, Constant = 11 }, + AsteroidRotationSpeed = new ExponentialLerp { Exponent = 2, Minimum = .1f, Maximum = .5f }, + SunColorSaturation = .85f, SunSecondaryColorDistance = .33f, SunLightSaturation = .5f, SunFogTintSaturation = .55f, + GasGiantBandCount = new ExponentialLerp { Exponent = 2, Minimum = 5, Maximum = 8 }, + GasGiantBandColorSeparation = .25f, GasGiantBandAltColorChance = .25f, + GasGiantBandSaturation = new ExponentialLerp { Exponent = .5f, Minimum = 0, Maximum = .8f }, + GasGiantBandBrightness = new ExponentialLerp { Exponent = .25f, Minimum = .25f, Maximum = 1 }, + NameData = new string[0], }; - - var found = false; - for (var seed = 0; seed < 25 && !found; seed++) + var tutorialSettings = new TutorialGenerationSettings { - var scratchRun = Path.Combine(Path.GetTempPath(), $"aetheria-restoredhulls-tutorial-{Guid.NewGuid():N}.cc"); + ProtagonistFaction = "Miss", AntagonistFaction = "Zhe", BufferFaction = "Luc", + NeutralFactions = new[] { "Aero", "Finch" }, QuestFaction = "Adras", LinkDensity = .5f, ZoneCount = 64, + }; + var background = new SectorBackgroundSettings + { + NoiseAmplitude = 1, NoiseOffset = .3f, NoiseGain = .7f, NoiseLacunarity = 2, NoiseFrequency = .1f, + NoisePosition = 536.5106f, CloudExponent = 10, CloudAmplitude = .01f, + }; + var names = new NameGeneratorSettings { NameGeneratorMinLength = 5, NameGeneratorMaxLength = 10, NameGeneratorOrder = 3 }; + var gameData = Path.Combine(FindRepoRoot(), "GameData", "Aetheria.cc"); + + // Galaxy zone-graph generation has a pre-existing, seed-dependent flakiness of its own (a disconnected + // zone graph throws inside the Galaxy constructor on roughly 1 seed in 15, confirmed unrelated to this + // cut: it reproduces identically against the pre-fix-batch catalog). That failure belongs to Galaxy.cs, + // not to ZoneGenerator's entrance-station override this test is pinning, so it is skipped rather than + // asserted on; every seed whose Galaxy actually builds must still get a docked entrance station. + var succeeded = 0; + for (uint seed = 1; seed <= 25; seed++) + { + var scratchRun = Path.Combine(Path.GetTempPath(), $"aetheria-entrance-station-{Guid.NewGuid():N}.cc"); try { - using var cache = OpenRealCatalogWithScratchRun(gameData, scratchRun); - var au = cache.GetAll().Single(f => f.ShortName == "AU"); - var auRef = cache.RefOf(au); - var game = new SavedGame - { - Background = new SectorBackgroundSettings - { - NoiseAmplitude = 1, NoiseGain = .5f, NoiseLacunarity = 2, NoiseFrequency = .1f, CloudExponent = 10, CloudAmplitude = 1, - }, - Factions = new[] { auRef }, - Relationships = new[] { FactionRelationship.Neutral }, - HomeZones = new Dictionary { { 0, 0 } }, - BossZones = new Dictionary(), - DiscoveredZones = new[] { 0 }, - ActionBarBindings = new SavedActionBarBinding[0], - Entrance = 0, - Exit = -1, - }; - var zones = new[] - { - new SavedZone { Name = $"Test Zone {seed}", Position = float2(seed, 0), AdjacentZones = Array.Empty(), Factions = new[] { 0 }, Owner = 0, Contents = null }, - }; - RunSave.Commit(cache, game, zones, new ProvenanceLedger()); - var galaxy = new Galaxy(cache, cache.GetGlobal(), _ => { }); + // Galaxy mutates Faction.InfluenceDistance in place; a fresh catalog open per seed keeps runs independent. + using var cache = OpenReadOnlyRealCatalogWithScratchRun(gameData, scratchRun); + Galaxy galaxy; + try { galaxy = new Galaxy(tutorialSettings, background, names, cache, new PlayerSettings(), new DirectoryInfo(Path.GetTempPath()), _ => { }, null, seed); } + catch (Exception) { continue; } + succeeded++; var items = new ItemManager(cache, new ProvenanceLedger(), Settings(), _ => { }); - var pack = ZoneGenerator.GenerateZone(items, zoneSettings, galaxy, galaxy.Zones[0], isTutorial: true); + var pack = ZoneGenerator.GenerateZone(items, zoneSettings, galaxy, galaxy.Entrance, isTutorial: true); - if (pack.Entities.OfType().Any(e => - (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station && e.DockingBays.Length > 0)) - found = true; + var docked = pack.Entities.OfType() + .Any(e => (cache.Get(e.Hull.Data) as HullData)?.HullType == HullType.Station && e.DockingBays.Length > 0); + Assert.True(docked, $"seed {seed}: the tutorial entrance zone generated no station with a docking bay."); } finally { @@ -253,6 +280,90 @@ public sealed class RestoredHullsTests } } - Assert.True(found, "No station with a docking bay generated in 25 zone attempts against the restored catalog."); + Assert.True(succeeded >= 15, $"only {succeeded} of 25 seeds produced a Galaxy at all; too few runs to trust this result."); + } + + // Speed cap (docs/locomotion-cut.md Cut 1 verification): Longinus's restored VelocityLimitData caps it at + // 100 (legacy TopSpeed 100..100). Runs it under straight-line full forward thrust -- LookDirection held on + // the ship's own heading, so the mixer never spends torque turning and thrust stays aligned with velocity -- + // long enough to approach its drag/thrust balance well past 100, and asserts the observed speed never + // exceeds the cap at any sampled tick. Must fail when VelocityLimitData is removed (docs' own probe: Longinus + // reaches 122 without it). + [Fact] + public void LonginusNeverExceedsItsRestoredTopSpeedUnderFullThrust() + { + using var cache = OpenCatalog(); + var hull = cache.GetByName("Longinus"); + var topSpeed = ((VelocityLimitData) hull.Behaviors.Single(b => b is VelocityLimitData)).TopSpeed.Max; + var thrusterDesigns = cache.GetAll().Where(g => g.Hardpoint == HardpointType.Thruster).ToArray(); + + var settings = Settings(); + var ledger = new ProvenanceLedger(); + for (var i = 1; i <= hull.Hardpoints.Count + 1; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = .5f }; + var items = new ItemManager(cache, ledger, settings, _ => { }); + var zone = new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test", Owner = null }, null); + var hullItem = new EquippableItem { Data = cache.RefOf(hull), Durability = hull.Durability, Lot = 1 }; + var ship = new Ship(items, zone, hullItem, settings.DefaultEntitySettings); + + var lot = 2; + foreach (var hardpoint in hull.Hardpoints.Where(h => h.Type == HardpointType.Thruster)) + { + var design = thrusterDesigns.First(d => d.Shape.FitsWithin(hardpoint.Shape, hardpoint.Rotation, out _) && d.Shape.Coordinates.Length == hardpoint.Shape.Coordinates.Length); + var gearItem = new EquippableItem { Data = cache.RefOf(design), Durability = design.Durability, Lot = lot++ }; + Assert.True(ship.TryEquip(gearItem, hardpoint.Position)); + } + var reactorHardpoint = hull.Hardpoints.First(h => h.Type == HardpointType.Reactor); + var reactorDesign = cache.GetAll().First(g => g.Hardpoint == HardpointType.Reactor && + g.Shape.FitsWithin(reactorHardpoint.Shape, reactorHardpoint.Rotation, out _) && g.Shape.Coordinates.Length == reactorHardpoint.Shape.Coordinates.Length); + Assert.True(ship.TryEquip(new EquippableItem { Data = cache.RefOf(reactorDesign), Durability = reactorDesign.Durability, Lot = lot++ }, reactorHardpoint.Position)); + + zone.Entities.Add(ship); + ship.Position = float3.zero; + ship.Activate(); + zone.Update(0f); + + ship.MovementDirection = float2(0, 1); // full forward + ship.LookDirection = float3(ship.Direction.x, 0, ship.Direction.y); // straight line: hold the ship's own heading + + for (var i = 0; i < 60 * 20; i++) + { + zone.Update(1f / 60f); + var speed = length(ship.Velocity); + // The mixer applies thrust then VelocityLimit clamps at the START of the next tick (Ship.cs's + // per-behavior execution order), so one tick's own acceleration can carry speed briefly past the + // cap before the following tick reins it in. The tolerance below is several times the base flight + // table's own measured Longinus forward acceleration (172.38 m/s^2) at dt=1/60 (~2.9 per tick). + Assert.True(speed <= topSpeed + 10f, $"tick {i}: speed {speed} exceeded the restored top speed {topSpeed} by more than one tick's acceleration."); + } + } + + // Loadout generation (docs/locomotion-cut.md Cut 1 verification): LoadoutGenerator, filtered to each + // restored hull, must fill every one of its thruster hardpoints -- the check that the restored designs and + // their FactionProductData/roles are authored correctly, not just present. + [Theory] + [InlineData("Longinus")] + [InlineData("Djinni")] + public void LoadoutGeneratorFillsEveryThrusterHardpointAcrossSeeds(string name) + { + using var cache = OpenCatalog(); + var hull = cache.GetByName(name); + var thrusterHardpoints = hull.Hardpoints.Where(h => h.Type == HardpointType.Thruster).ToArray(); + var settings = Settings(); + + for (uint seed = 1; seed <= 10; seed++) + { + var items = new ItemManager(cache, new ProvenanceLedger(), settings, _ => { }); + var random = new Random(seed); + var generator = new LoadoutGenerator(ref random, items, null, null, null, .5f); + var pack = generator.GenerateShipLoadout(candidate => candidate == hull); + Assert.True(pack != null, $"{name}: seed {seed} produced no loadout."); + + foreach (var hardpoint in thrusterHardpoints) + { + var filled = pack.Equipment.Any(e => e.position.Equals(hardpoint.Position) && + (cache.Get(e.item.Data) as GearData)?.Hardpoint == HardpointType.Thruster); + Assert.True(filled, $"{name}: seed {seed}'s {hardpoint.Transform ?? hardpoint.Type.ToString()} hardpoint at {hardpoint.Position} got no thruster."); + } + } } }