Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using CultMath;
|
|
|
|
|
using GameCult.Caching;
|
|
|
|
|
using GameCult.Caching.MessagePack;
|
|
|
|
|
using MessagePack;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Each test gets its own temp directory holding a catalog built through Open(catalogWritable: true).
|
|
|
|
|
public sealed class AetheriaStoresTests : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-stores-" + Guid.NewGuid().ToString("N"));
|
|
|
|
|
private string Catalog => Path.Combine(_root, "Aetheria.cc");
|
|
|
|
|
private string Run => Path.Combine(_root, "run.cc");
|
|
|
|
|
private string Player => Path.Combine(_root, "player.cc");
|
|
|
|
|
|
|
|
|
|
public AetheriaStoresTests()
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(_root);
|
|
|
|
|
using var cache = AetheriaStores.Open(Catalog, catalogWritable: true);
|
2026-10-10 07:18:00 +02:00
|
|
|
cache.Upsert(new VerseGrammar { Revision = 1 });
|
Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
var faction = new Faction { Name = "Adrasteia", ShortName = "ADR", PrimaryColor = new float3(1, .5f, .25f) };
|
|
|
|
|
faction.Allegiance[cache.Upsert(faction)] = 1;
|
|
|
|
|
cache.Upsert(faction);
|
2026-09-17 12:03:15 +02:00
|
|
|
var lance = cache.Upsert(new WeaponItemData { Name = "Lance" });
|
|
|
|
|
cache.Upsert(new FactionProductData { Name = "Lance", Design = new CultRecordRef<CraftedItemData>(lance.Key), Manufacturer = cache.RefOf(faction) });
|
Import the legacy catalog into GameData/Aetheria.cc (Cut 9)
AetherDb gains legacy-census and a one-shot import (tools/AetherDb/Import.cs,
deleted by Cut 10). The import rewrites each legacy [tag, payload] record by
the target type's [Key] shape: slot 0 Guid becomes the record key and nil,
CultRecordRef members and DatabaseLink wrappers become D strings, the all-zero
Guid becomes nil, StatModifierData.RequireBehavior keeps the simple type name.
All 180 records land in one Commit; a second import refuses.
InputLayout moves to the catalog (Q9-1 A), with the test fixture seeding it
while the catalog is writable. GameData/*.cc is LFS, GameData/*.lock ignored.
The legacy msgpack and ansi104.json sources are removed.
Imported: SimpleCommodityData 13, CompoundCommodityData 51, GearData 25,
HullData 3, NameFile 12, Faction 12, PersonalityAttribute 3, CargoBayData 4,
DockingBayData 1, WeaponItemData 18, FactionProductData 37, InputLayout 1.
Six refs dangled already in the legacy data and are preserved as authored.
The Key(0) precondition checks only the Guid-slotted tagged types; InputLayout
is imported bare and keeps its Key(0).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 21:11:06 +02:00
|
|
|
cache.Upsert(new InputLayout { Rows = new InputLayoutRow[] { new InputLayoutRowSpacer { Height = 1 } } });
|
Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
cache.FlushAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() => Directory.Delete(_root, true);
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void OpenThenFlushLeavesEveryFileByteIdentical()
|
|
|
|
|
{
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, Run, Player))
|
|
|
|
|
{
|
|
|
|
|
var zone = cache.Upsert(new SavedZone { Name = "Entrance", Position = new float2(1, 2), Contents = new ZonePack() });
|
|
|
|
|
cache.Upsert(new SavedGame { Zones = new[] { zone }, Factions = new[] { cache.RefOf(cache.GetAll<Faction>().Single()) } });
|
|
|
|
|
cache.Upsert(new PlayerSettings());
|
|
|
|
|
cache.FlushAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var before = new[] { Catalog, Run, Player }.Select(Hash).ToArray();
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, Run, Player))
|
|
|
|
|
{
|
|
|
|
|
Assert.NotNull(cache.GetGlobal<SavedGame>());
|
|
|
|
|
Assert.NotNull(cache.GetGlobal<PlayerSettings>());
|
|
|
|
|
cache.FlushAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Equal(before, new[] { Catalog, Run, Player }.Select(Hash).ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void WeaponWrittenThroughGearHandleReloadsAsWeapon()
|
|
|
|
|
{
|
|
|
|
|
CultRecordHandle<GearData> handle;
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, catalogWritable: true))
|
|
|
|
|
{
|
|
|
|
|
handle = cache.UpsertAsync<GearData>(new WeaponItemData { Name = "Pike" }).Result;
|
|
|
|
|
cache.FlushAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog))
|
|
|
|
|
Assert.Equal("Pike", Assert.IsType<WeaponItemData>(cache.Get(handle.Key)).Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CatalogRefusesWrites()
|
|
|
|
|
{
|
|
|
|
|
var before = Hash(Catalog);
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog))
|
|
|
|
|
{
|
|
|
|
|
Assert.Throws<InvalidOperationException>(() => cache.Upsert(new Faction { Name = "Usurper" }));
|
|
|
|
|
cache.FlushAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Equal(before, Hash(Catalog));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SavedZoneNeverLandsInCatalog()
|
|
|
|
|
{
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, catalogWritable: true))
|
|
|
|
|
Assert.Throws<InvalidOperationException>(() => cache.Upsert(new SavedZone { Name = "Stray" }));
|
|
|
|
|
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, Run, catalogWritable: true))
|
|
|
|
|
{
|
|
|
|
|
cache.Upsert(new SavedZone { Name = "Home" });
|
|
|
|
|
cache.FlushAsync().Wait();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.DoesNotContain(SchemaNames(Catalog), name => name == "aetheria.savedzone");
|
|
|
|
|
Assert.Contains("aetheria.savedzone", SchemaNames(Run));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FactionIsASingletonInstance()
|
|
|
|
|
{
|
|
|
|
|
using var cache = AetheriaStores.Open(Catalog);
|
|
|
|
|
var faction = cache.GetAll<Faction>().Single();
|
2026-09-17 12:03:15 +02:00
|
|
|
Assert.Same(faction, cache.Get(cache.GetAll<FactionProductData>().Single().Manufacturer));
|
Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
Assert.Same(faction, cache.Get(faction.Allegiance.Keys.Single()));
|
|
|
|
|
Assert.Same(faction, cache.GetByName<Faction>("Adrasteia"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MissingCatalogGlobalIsLoud()
|
|
|
|
|
{
|
|
|
|
|
var empty = Path.Combine(_root, "empty.cc");
|
2026-10-10 08:10:12 +02:00
|
|
|
// A catalog file that exists but lacks the global: the read-only open reaches the global check.
|
|
|
|
|
File.Copy(Catalog, empty);
|
|
|
|
|
using (var seed = AetheriaStores.Open(empty, catalogWritable: true))
|
2026-10-10 14:00:03 +02:00
|
|
|
Assert.True(seed.Commit(batch => batch.Remove(seed.RefOf(seed.GetGlobal<VerseGrammar>()).Key)));
|
Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(empty));
|
2026-10-10 07:18:00 +02:00
|
|
|
Assert.Contains("aetheria.verse_grammar", error.Message);
|
Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
using (AetheriaStores.Open(Catalog)) { }
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-14 23:13:22 +02:00
|
|
|
// Writability exempts only an empty seed catalog: a populated catalog missing a global is loud even when writable.
|
|
|
|
|
[Fact]
|
|
|
|
|
public void WritablePopulatedCatalogMissingGlobalIsLoud()
|
|
|
|
|
{
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, catalogWritable: true))
|
|
|
|
|
{
|
2026-10-10 07:18:00 +02:00
|
|
|
var global = cache.GetGlobal<VerseGrammar>();
|
2026-09-14 23:13:22 +02:00
|
|
|
var key = cache.RefOf(global).Key;
|
|
|
|
|
Assert.True(cache.Commit(batch => batch.Remove(key)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(Catalog, catalogWritable: true));
|
2026-10-10 07:18:00 +02:00
|
|
|
Assert.Contains("aetheria.verse_grammar", error.Message);
|
2026-09-14 23:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
Capture presets through their own cache; keep the catalog read-only
Opening the process cache's catalog writable in the editor was the wrong cut.
It made catalog read-only only by convention, so a stray catalog write in play
succeeded and a later flush could land play-mutated instances in Aetheria.cc.
- The process cache opens the catalog read-only in every build again, so the
missing-global check runs for it as it did before db83cd29. The writable
empty-seed exemption from ab4ced0f stays for AetherDb and fixtures.
- Loadouts.Commit(catalogPath, loadout, replace) is the only preset writer. It
opens its own short-lived cache over the catalog, writable, commits the one
preset conditionally on its key and disposes it. No other cache or instance
is touched. The running game sees the preset only after the catalog reloads.
CultLib at a0813c6 allows this: a read-only single-file store takes no lock
and holds no handle, and the writer's commit takes the exclusive sidecar
<path>.lock and replaces the file atomically.
- Capture refuses, writing nothing, when Aetheria.cc is missing (it never
creates the catalog), when a preset of that name exists under another key
(CultCache does not reject duplicate names on write), or when the key holds a
preset and replace is not given.
- The console refuses a command with any character outside letters, digits,
spaces and hyphens instead of stripping it, so "Mk.II" can no longer become
"MkII". capturepreset refuses a second argument other than replace, so an
unquoted capturepreset My Ship refuses instead of saving "My".
- The capture log line says the session sees the preset after a reload, and
that a Studio session opened earlier overwrites captured presets on save.
- Tests: capture while the process cache holds the catalog read-only leaves it
unchanged; a missing catalog refuses and creates nothing; a same name under a
Studio-minted key refuses, with or without replace; a game-shaped read-only
open missing a global throws. The existing preset tests now commit through
the catalog path.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 23:32:52 +02:00
|
|
|
// The game opens the catalog read-only with its run and player stores, in the editor as in a build: a populated
|
|
|
|
|
// catalog missing a global refuses to open.
|
|
|
|
|
[Fact]
|
|
|
|
|
public void GameShapedOpenMissingGlobalIsLoud()
|
|
|
|
|
{
|
|
|
|
|
using (var cache = AetheriaStores.Open(Catalog, catalogWritable: true))
|
2026-10-10 07:18:00 +02:00
|
|
|
Assert.True(cache.Commit(batch => batch.Remove(cache.RefOf(cache.GetGlobal<VerseGrammar>()).Key)));
|
Capture presets through their own cache; keep the catalog read-only
Opening the process cache's catalog writable in the editor was the wrong cut.
It made catalog read-only only by convention, so a stray catalog write in play
succeeded and a later flush could land play-mutated instances in Aetheria.cc.
- The process cache opens the catalog read-only in every build again, so the
missing-global check runs for it as it did before db83cd29. The writable
empty-seed exemption from ab4ced0f stays for AetherDb and fixtures.
- Loadouts.Commit(catalogPath, loadout, replace) is the only preset writer. It
opens its own short-lived cache over the catalog, writable, commits the one
preset conditionally on its key and disposes it. No other cache or instance
is touched. The running game sees the preset only after the catalog reloads.
CultLib at a0813c6 allows this: a read-only single-file store takes no lock
and holds no handle, and the writer's commit takes the exclusive sidecar
<path>.lock and replaces the file atomically.
- Capture refuses, writing nothing, when Aetheria.cc is missing (it never
creates the catalog), when a preset of that name exists under another key
(CultCache does not reject duplicate names on write), or when the key holds a
preset and replace is not given.
- The console refuses a command with any character outside letters, digits,
spaces and hyphens instead of stripping it, so "Mk.II" can no longer become
"MkII". capturepreset refuses a second argument other than replace, so an
unquoted capturepreset My Ship refuses instead of saving "My".
- The capture log line says the session sees the preset after a reload, and
that a Studio session opened earlier overwrites captured presets on save.
- Tests: capture while the process cache holds the catalog read-only leaves it
unchanged; a missing catalog refuses and creates nothing; a same name under a
Studio-minted key refuses, with or without replace; a game-shaped read-only
open missing a global throws. The existing preset tests now commit through
the catalog path.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 23:32:52 +02:00
|
|
|
|
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => AetheriaStores.Open(Catalog, Run, Player));
|
2026-10-10 07:18:00 +02:00
|
|
|
Assert.Contains("aetheria.verse_grammar", error.Message);
|
Capture presets through their own cache; keep the catalog read-only
Opening the process cache's catalog writable in the editor was the wrong cut.
It made catalog read-only only by convention, so a stray catalog write in play
succeeded and a later flush could land play-mutated instances in Aetheria.cc.
- The process cache opens the catalog read-only in every build again, so the
missing-global check runs for it as it did before db83cd29. The writable
empty-seed exemption from ab4ced0f stays for AetherDb and fixtures.
- Loadouts.Commit(catalogPath, loadout, replace) is the only preset writer. It
opens its own short-lived cache over the catalog, writable, commits the one
preset conditionally on its key and disposes it. No other cache or instance
is touched. The running game sees the preset only after the catalog reloads.
CultLib at a0813c6 allows this: a read-only single-file store takes no lock
and holds no handle, and the writer's commit takes the exclusive sidecar
<path>.lock and replaces the file atomically.
- Capture refuses, writing nothing, when Aetheria.cc is missing (it never
creates the catalog), when a preset of that name exists under another key
(CultCache does not reject duplicate names on write), or when the key holds a
preset and replace is not given.
- The console refuses a command with any character outside letters, digits,
spaces and hyphens instead of stripping it, so "Mk.II" can no longer become
"MkII". capturepreset refuses a second argument other than replace, so an
unquoted capturepreset My Ship refuses instead of saving "My".
- The capture log line says the session sees the preset after a reload, and
that a Studio session opened earlier overwrites captured presets on save.
- Tests: capture while the process cache holds the catalog read-only leaves it
unchanged; a missing catalog refuses and creates nothing; a same name under a
Studio-minted key refuses, with or without replace; a game-shaped read-only
open missing a global throws. The existing preset tests now commit through
the catalog path.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 23:32:52 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-19 05:47:31 +02:00
|
|
|
// --- F7 (docs/stats-and-power-cut.md, Soul pass 2026-09-19): "there are at least four [write bypasses]."
|
|
|
|
|
// --- tools/AetherDb/Program.cs's Dangling, ShieldMigrate and BrownoutMigrate commands repair an existing
|
|
|
|
|
// --- record in place through `cache.Commit(batch => batch.Upsert(document.GetType(), document, key))` --
|
|
|
|
|
// --- CultCache's own batch API, keyed explicitly to preserve identity -- because CultRecordRefs.Upsert's own
|
|
|
|
|
// --- cache.UpsertAsync(document) cannot take a caller-supplied key. That is real, not an excuse to skip
|
|
|
|
|
// --- validation: all three now call CultRecordRefs.Validate(document) directly, immediately before their own
|
|
|
|
|
// --- commit. This pins that the extracted method actually refuses what Upsert would have, proving the tools'
|
|
|
|
|
// --- direct call is wired to the same rule rather than a hollow copy. ---
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ValidateRefusesAnEquippableItemWithAZeroSpanHeatRangeTheSameWayUpsertWould()
|
|
|
|
|
{
|
|
|
|
|
var badDesign = new GearData
|
|
|
|
|
{
|
|
|
|
|
Name = "BadDangling", Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 10,
|
|
|
|
|
MinimumTemperature = 100, MaximumTemperature = 100, OptimalTemperature = 100, PlateauWidth = 0
|
|
|
|
|
};
|
|
|
|
|
var error = Assert.Throws<InvalidOperationException>(() => CultRecordRefs.Validate(badDesign));
|
|
|
|
|
Assert.Contains("BadDangling", error.Message);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-19 06:58:57 +02:00
|
|
|
// Nominal-request ruling (docs/stats-and-power-cut.md, operator ruling 2026-09-19), superseding F6: this
|
|
|
|
|
// direct-call path used to also catch F6's static rule (a power request stat may not carry a PowerSupply
|
|
|
|
|
// term at all -- StatValidation.ValidateNoPowerSupplyOnRequest, since deleted). PowerRequest now reads a
|
|
|
|
|
// request field through EquippedItem.EvaluateNominalPower, which pins that stat's own PowerSupplyFactor to 1
|
|
|
|
|
// regardless of its Terms, so the term can no longer make the request depend on its own answer -- a repair
|
|
|
|
|
// tool landing a curved ThrusterData.EnergyUsage is no longer any more dangerous than R-heat's own check,
|
|
|
|
|
// which this still runs (see the sibling test above).
|
2026-09-19 05:47:31 +02:00
|
|
|
[Fact]
|
2026-09-19 06:58:57 +02:00
|
|
|
public void ValidateAcceptsAPowerRequestCarryingAPowerSupplyTermTheSameWayUpsertWould()
|
2026-09-19 05:47:31 +02:00
|
|
|
{
|
2026-09-19 06:58:57 +02:00
|
|
|
var curvedEnergy = new PerformanceStat { Min = 1, Max = 1, Terms = { new StatTerm { Source = StatSource.PowerSupply, Exponent = 1 } } };
|
|
|
|
|
var goodDesign = new GearData
|
2026-09-19 05:47:31 +02:00
|
|
|
{
|
2026-09-19 06:58:57 +02:00
|
|
|
Name = "CurvedMigratedThruster", Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 10,
|
2026-09-19 05:47:31 +02:00
|
|
|
MinimumTemperature = 0, MaximumTemperature = 1000, OptimalTemperature = 280, PlateauWidth = 400,
|
2026-09-19 06:58:57 +02:00
|
|
|
Behaviors = { new ThrusterData { EnergyUsage = curvedEnergy } }
|
2026-09-19 05:47:31 +02:00
|
|
|
};
|
2026-09-19 06:58:57 +02:00
|
|
|
var record = Record.Exception(() => CultRecordRefs.Validate(goodDesign));
|
|
|
|
|
Assert.Null(record);
|
2026-09-19 05:47:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A document type Validate has no opinion about (neither EquippableItemData nor ConsumableItemData) must be
|
|
|
|
|
// a pure no-op, not a crash -- the three tools' change lists carry `object`, and not every migration touches
|
|
|
|
|
// an equippable design (e.g. a future repair over FactionProductData).
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ValidateIsANoOpForADocumentTypeItDoesNotGovern()
|
|
|
|
|
{
|
|
|
|
|
var record = Record.Exception(() => CultRecordRefs.Validate(new Faction { Name = "Unrelated" }));
|
|
|
|
|
Assert.Null(record);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-10 06:52:06 +02:00
|
|
|
// A shipped player with no catalog must not boot into an empty game: a read-only open of a missing path throws
|
|
|
|
|
// naming the path, and does not create the file. A writable open still seeds an empty catalog.
|
|
|
|
|
[Fact]
|
|
|
|
|
public void AStoreRefusesAMissingCatalog()
|
|
|
|
|
{
|
|
|
|
|
var missing = Path.Combine(_root, "absent", "Aetheria.cc");
|
|
|
|
|
|
2026-10-10 07:28:04 +02:00
|
|
|
// FileNotFoundException, not the catalog-global check: that one also throws on a missing file whenever a global is registered.
|
|
|
|
|
var error = Assert.Throws<FileNotFoundException>(() => AetheriaStores.Open(missing));
|
2026-10-10 06:52:06 +02:00
|
|
|
Assert.Contains(missing, error.Message);
|
|
|
|
|
Assert.False(File.Exists(missing));
|
|
|
|
|
Assert.False(Directory.Exists(Path.GetDirectoryName(missing)));
|
|
|
|
|
|
|
|
|
|
using (var seeded = AetheriaStores.Open(missing, catalogWritable: true))
|
|
|
|
|
Assert.Empty(seeded.GetAll<Faction>());
|
|
|
|
|
}
|
|
|
|
|
|
Pin AetheriaStores routing with tests; make PlayerSettings readable
Cut 8b. tests/Aetheria.Shared.Tests (xunit, net10.0) builds a temp-directory
catalog through AetheriaStores.Open(catalogWritable: true) per test:
- OpenThenFlushLeavesEveryFileByteIdentical: the catalog, plus run and
player stores seeded with their globals, a SavedZone and an InputLayout.
- WeaponWrittenThroughGearHandleReloadsAsWeapon
- CatalogRefusesWrites: bytes unchanged too.
- SavedZoneNeverLandsInCatalog: no home without a run store; the snapshot
schemas show where it landed.
- FactionIsASingletonInstance: through a ref, a ref-keyed map key, and the
name index.
- MissingCatalogGlobalIsLoud: uses a test-only [CultGlobal] routed to the
catalog. The game has no catalog globals yet.
The first test found a real defect. PlayerInputSettings.InputActionMap was
keyed by (string, int), and CultLib's untrusted-data MessagePack security
has no hash-resistant comparer for a tuple, so a player store could never
be read back. It is now action name to binding index to path; its two
Unity readers change in the Unity commit.
Each test was checked to fail with the rule it pins removed; see the
report.
Builds: Aetheria.Shared, AetherDb, Aetheria.Shared.Tests (6/6 pass).
Unity does not build yet.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 19:12:54 +02:00
|
|
|
private static string Hash(string path) => Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(path)));
|
|
|
|
|
|
|
|
|
|
private static string[] SchemaNames(string path)
|
|
|
|
|
{
|
|
|
|
|
var snapshot = CultDocumentMessagePackSerialization.DeserializeSnapshot(File.ReadAllBytes(path));
|
|
|
|
|
return snapshot.Records
|
|
|
|
|
.Select(record => snapshot.SchemaCatalog.Single(entry => entry.SchemaId == record.SchemaId).SchemaName)
|
|
|
|
|
.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|