Cut 7: refuse a stat naming a role its design lacks
StatValidation.ValidateRoleUsage walks every PerformanceStat field on every behaviour and refuses a StatSource.Quality term whose Role is not in the design's own declared Roles -- wired into AetheriaStores.Open and CultRecordRefs.Upsert alongside the existing heat/modifier/power-supply checks. Lot.QualityForRole already falls back to workmanship for a role an old lot never rolled (forward-compat for a role added after minting); this is the other direction: a term naming a role the design never declared at all is an authoring mistake, not a lot predating the role, and must fail loudly. RoleAuthoringTests.cs pins three rules with both a positive and negative control: Upsert refuses an absent-role term but accepts a declared one, and two products of one design with different ProductRole means mint lots that resolve a role-termed stat to different, deterministic values. tests/mutation_tests_stats_power_cut8.py (this repo's own numbering follows cut7.py's brownout work) mutates ValidateRoleUsage in both directions (never-refuse, always-refuse) and QualityForRole's fallback, plus ItemManager.CreateLot's mean read -- all six behave as declared. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
d28815e8bd
commit
395494f6a7
4 changed files with 334 additions and 0 deletions
|
|
@ -37,6 +37,8 @@ public static class AetheriaStores
|
|||
StatValidation.ValidateStatModifiers(data.Name, data.Behaviors);
|
||||
// Cut 6 (docs/stats-and-power-cut.md): a power request may not depend on power supply.
|
||||
StatValidation.ValidateNoPowerSupplyOnRequest(data.Name, data.Behaviors);
|
||||
// Cut 7 (docs/stats-and-power-cut.md): a stat naming a role its design lacks is refused.
|
||||
StatValidation.ValidateRoleUsage(data.Name, data.Roles, data.Behaviors);
|
||||
}
|
||||
// Cut 2 (docs/stats-and-power-cut.md): a consumable's own StatModifierData needs the same check;
|
||||
// consumables carry no heat response, so this is not folded into the loop above.
|
||||
|
|
@ -44,6 +46,7 @@ public static class AetheriaStores
|
|||
{
|
||||
StatValidation.ValidateStatModifiers(data.Name, data.Behaviors);
|
||||
StatValidation.ValidateNoPowerSupplyOnRequest(data.Name, data.Behaviors);
|
||||
StatValidation.ValidateRoleUsage(data.Name, data.Roles, data.Behaviors);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
|
@ -81,11 +84,13 @@ public static class CultRecordRefs
|
|||
StatValidation.ValidateHeatResponse(data);
|
||||
StatValidation.ValidateStatModifiers(data.Name, data.Behaviors);
|
||||
StatValidation.ValidateNoPowerSupplyOnRequest(data.Name, data.Behaviors);
|
||||
StatValidation.ValidateRoleUsage(data.Name, data.Roles, data.Behaviors);
|
||||
}
|
||||
if (document is ConsumableItemData consumable)
|
||||
{
|
||||
StatValidation.ValidateStatModifiers(consumable.Name, consumable.Behaviors);
|
||||
StatValidation.ValidateNoPowerSupplyOnRequest(consumable.Name, consumable.Behaviors);
|
||||
StatValidation.ValidateRoleUsage(consumable.Name, consumable.Roles, consumable.Behaviors);
|
||||
}
|
||||
return new CultRecordRef<T>(cache.UpsertAsync(document).Result.Key);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -755,6 +755,34 @@ public static class StatValidation
|
|||
}
|
||||
}
|
||||
|
||||
// Cut 7 (docs/stats-and-power-cut.md): "a stat naming a role its design lacks" must be refused, not silently
|
||||
// fall back to the lot's own workmanship (Lot.QualityForRole already falls back for a role a lot never rolled
|
||||
// -- that is the intended forward-compat path for an old lot meeting a newly-authored role. This is the other
|
||||
// direction: a StatTerm naming a role the design itself never declared is an authoring mistake, not a lot
|
||||
// predating the role, and must fail loudly rather than silently reading generic quality). Every PerformanceStat
|
||||
// field on every behaviour is walked; only StatSource.Quality terms carry a Role at all (Evaluate ignores Role
|
||||
// for every other source).
|
||||
public static void ValidateRoleUsage(string ownerName, List<ItemRole> roles, IEnumerable<BehaviorData> behaviors)
|
||||
{
|
||||
var declared = new HashSet<string>((roles ?? new List<ItemRole>()).Select(r => r.Name));
|
||||
foreach (var behavior in behaviors ?? Enumerable.Empty<BehaviorData>())
|
||||
{
|
||||
if (behavior == null) continue;
|
||||
foreach (var field in behavior.GetType().GetFields().Where(f => f.FieldType == typeof(PerformanceStat)))
|
||||
{
|
||||
if (!(field.GetValue(behavior) is PerformanceStat stat) || stat.Terms == null) continue;
|
||||
foreach (var term in stat.Terms)
|
||||
{
|
||||
if (term.Source != StatSource.Quality || string.IsNullOrEmpty(term.Role)) continue;
|
||||
if (!declared.Contains(term.Role))
|
||||
throw new InvalidOperationException(
|
||||
$"{ownerName}: {behavior.GetType().Name}.{field.Name} names role \"{term.Role}\", " +
|
||||
$"which this design does not declare (declared: {(declared.Count == 0 ? "none" : string.Join(", ", declared))})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cut 6 (docs/stats-and-power-cut.md): "a stat that decides a power request may not depend on power supply,
|
||||
// directly or through a modifier chain, and no stat may depend on itself." IPowerConsumer.PowerRequest(dt)
|
||||
// never hands the bus a number it invented on the spot -- each implementation evaluates exactly one fixed
|
||||
|
|
|
|||
Loading…
Reference in a new issue