From 927085b7b507fa612bc78de01be1e4b286d17b94 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 01:22:18 +0100 Subject: [PATCH] Tests: validate::size grows its own stack; no owned contract list; written-by-ts.cc --- crates/thing-core/tests/resolve.rs | 31 ++++++++++++++++++ .../ReadOnlyListTests.cs | 29 ++++++++++++++++ tests/thing-contract-parity/written-by-ts.cc | Bin 12999 -> 13023 bytes 3 files changed, 60 insertions(+) diff --git a/crates/thing-core/tests/resolve.rs b/crates/thing-core/tests/resolve.rs index 2eb9cb2..9f3fdf1 100644 --- a/crates/thing-core/tests/resolve.rs +++ b/crates/thing-core/tests/resolve.rs @@ -994,6 +994,37 @@ fn the_stack_bound_counts_a_slot_argument() { stack_bound_counts(Through::SlotArgument); } +/// Runs `work` with only about `left` bytes of stack remaining: the stack is burned first, so a +/// recursion that does not grow its own stack runs out inside it. +#[inline(never)] +fn with_stack_left(left: usize, work: &mut dyn FnMut()) { + let remaining = stacker::remaining_stack().expect("the thread's stack limit is known"); + if remaining > left { + let burn = [0u8; 4096]; + std::hint::black_box(&burn); + with_stack_left(left, work); + std::hint::black_box(&burn); + } else { + work(); + } +} + +#[test] +fn counting_a_deep_slot_argument_grows_its_own_stack() { + // The body places a 900-level slot argument; the node limit refuses it where it is counted + // (validate::size, a recursion over the argument), before anything clones it. Run with little + // stack left, the count must move to a fresh segment to finish. + let limits = limited(1500); + let body = composition("c", &[("body", ParamKind::Slot)], boxed("b", vec![slot("body")])); + let state = state_with(&[body]); + let document = surface(boxed("root", vec![use_of("u", "c", vec![slot_arg("body", vec![chain(900, false)])])]), &[]); + let mut resolution = None; + with_stack_left(600 * 1024, &mut || resolution = Some(resolve(&document, &state, &limits))); + let resolution = resolution.unwrap(); + refused_for_limit(&resolution); + assert!(!too_deep_to_resolve(&resolution), "{:?}", resolution.diagnostics); +} + #[test] fn a_slot_naming_a_param_of_another_kind_is_invalid() { let body = composition("c", &[("x", ParamKind::Text)], boxed("b", vec![slot("x")])); diff --git a/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs b/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs index a964edd..5345c60 100644 --- a/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs +++ b/tests/GameCult.Thing.Contract.Tests/ReadOnlyListTests.cs @@ -38,6 +38,35 @@ public sealed class ReadOnlyListTests Assert.That(checkedProperties, Is.GreaterThan(200)); } + /// + /// CultLib's element-id walk owns the elements of a list held as a class or interface of + /// [MessagePackObject] or [Union] elements, and demands an id on each. A list held as an ImmutableArray is one + /// whole value the walk never enters, so the contract holds every list that way. + /// + [Test] + public void NoKeyMemberIsAnOwnedListOfContractObjects() + { + bool IsContractObject(Type type) => + type.GetCustomAttribute() != null || type.GetCustomAttributes(false).Any(); + var offenders = new List(); + var checkedMembers = 0; + foreach (var type in typeof(CommandResult).Assembly.GetExportedTypes()) + foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) + { + if (property.GetCustomAttribute() is null) continue; + checkedMembers++; + var t = property.PropertyType; + if (t.IsValueType) continue; + var element = t.GetInterfaces().Concat(new[] { t }) + .Where(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IEnumerable<>)) + .Select(i => i.GetGenericArguments()[0]).FirstOrDefault(); + if (element != null && IsContractObject(element)) offenders.Add($"{type.Name}.{property.Name}: {t.Name}"); + } + + Assert.That(offenders, Is.Empty); + Assert.That(checkedMembers, Is.GreaterThan(100)); + } + [Test] public void EveryListParameterIsCopiedAndTheCopyCannotGrow() { diff --git a/tests/thing-contract-parity/written-by-ts.cc b/tests/thing-contract-parity/written-by-ts.cc index 10b3dafd6b0d6134ea5d464fcbbdb5c4f9dbd695..ccfb6390f066eb411bf5ebb77e26078b824685e8 100644 GIT binary patch delta 505 zcmX?}dOvkSKjV{)6TFxtJacnPOA?cEQuW|0$D*Rd%E^r!l9M@@-|F}WR~DC~=IS}; z=j5a&mt^MW6(f`)SO`t#EQ=U#PMjb&c|MEKW-itwW}J3xZsd?))(Ilb0`1vY4@%!R7`z6GjmvttQ3> dQAdm?-&C2bD5o;{jl2)C2185p&29>fLIB5xuVDZH delta 426 zcmcbgdOUSPKjXuV6TFy2-Ba^Yi!zh-JcCjbQ~dLCDt$7GOC}45NKUq8;hrqU{D{$K zvY>=8UUiEYuWf$7GKm?FqUYRvn>TWNWMcHkZ`x*{LKepS$q!f*C!gi#*eov~j@ymO zn+t`C85zCt8o8PA$HWP8lNX4vZ+@X{fvJ_D zv7Whs*<>TBHON9{rskX9NX=swLQ-aCZWwjs^32Ki