Thing 2.0 cut 4a: cultcache-rs pin 4c9af401, contract names its members, stacker in resolve (pre-bless)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
edeeee2129
commit
81f0d1bf3d
19 changed files with 968 additions and 756 deletions
146
Cargo.lock
generated
146
Cargo.lock
generated
|
|
@ -17,12 +17,30 @@ version = "1.0.104"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "ar_archive_writer"
|
||||
version = "0.5.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "523e5e187fff36fcb8d1d19ccf0ca4ca43ec3d158316057f66dc6f72716bc5ec"
|
||||
dependencies = [
|
||||
"object",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
|
|
@ -65,10 +83,29 @@ version = "0.8.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cultcache-rs"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/GameCult/CultLib.git?rev=b3bd8dd5e5b208b2012392e9c5d6dfee2441aaa7#b3bd8dd5e5b208b2012392e9c5d6dfee2441aaa7"
|
||||
version = "0.3.1"
|
||||
source = "git+https://github.com/GameCult/CultLib.git?rev=4c9af401ae33812d862dde4ff3131433fc73c7dc#4c9af401ae33812d862dde4ff3131433fc73c7dc"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
|
@ -79,20 +116,33 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_bytes",
|
||||
"serde_json",
|
||||
"serde_stacker",
|
||||
"sha2",
|
||||
"stacker",
|
||||
"uuid",
|
||||
"windows-sys",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cultcache-rs-derive"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/GameCult/CultLib.git?rev=b3bd8dd5e5b208b2012392e9c5d6dfee2441aaa7#b3bd8dd5e5b208b2012392e9c5d6dfee2441aaa7"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/GameCult/CultLib.git?rev=4c9af401ae33812d862dde4ff3131433fc73c7dc#4c9af401ae33812d862dde4ff3131433fc73c7dc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.14"
|
||||
|
|
@ -133,6 +183,16 @@ dependencies = [
|
|||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
|
|
@ -212,6 +272,15 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "object"
|
||||
version = "0.39.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
|
|
@ -233,6 +302,16 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "psm"
|
||||
version = "0.1.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dcd034599e63b970727f70d79e02d62390a4a84f7c6b827c27c46d5ac3fa622"
|
||||
dependencies = [
|
||||
"ar_archive_writer",
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
|
|
@ -335,6 +414,28 @@ dependencies = [
|
|||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_stacker"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4936375d50c4be7eff22293a9344f8e46f323ed2b3c243e52f89138d9bb0f4a"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_core",
|
||||
"stacker",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
|
|
@ -347,6 +448,19 @@ version = "0.4.12"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "stacker"
|
||||
version = "0.1.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "707f49d46706bacf8a2b00d51dace3f9de527c13eec3778f570c411f89e69967"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"psm",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
|
|
@ -385,6 +499,7 @@ dependencies = [
|
|||
name = "thing-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"stacker",
|
||||
"thing-contract",
|
||||
"thing-testkit",
|
||||
]
|
||||
|
|
@ -400,6 +515,12 @@ dependencies = [
|
|||
"thing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.26"
|
||||
|
|
@ -417,6 +538,12 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.129"
|
||||
|
|
@ -552,6 +679,15 @@ dependencies = [
|
|||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ resolver = "2"
|
|||
|
||||
[workspace.dependencies]
|
||||
anyhow = "1"
|
||||
cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "b3bd8dd5e5b208b2012392e9c5d6dfee2441aaa7", package = "cultcache-rs" }
|
||||
cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "4c9af401ae33812d862dde4ff3131433fc73c7dc", package = "cultcache-rs" }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
rmp-serde = "1.3"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ pub struct AssetCatalog {
|
|||
pub catalog_id: Segment,
|
||||
#[cultcache(key = 2)]
|
||||
pub version: Version,
|
||||
#[cultcache(key = 3)]
|
||||
#[cultcache(key = 3, type_name = "System.Collections.Generic.IReadOnlyList<GameCult.Thing.Contract.AssetEntry>")]
|
||||
pub assets: Vec<AssetEntry>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub enum CommandRef {
|
|||
|
||||
/// A typed record of the declared `payload_schema`, as its MessagePack bytes.
|
||||
#[derive(Clone, Debug, PartialEq, CultSlots)]
|
||||
#[cultcache(type_name = "GameCult.Thing.Contract.RecordPayload")]
|
||||
pub struct RecordPayload {
|
||||
#[cultcache(key = 0)]
|
||||
pub schema: SchemaId,
|
||||
|
|
@ -105,7 +106,7 @@ pub struct CommandInvocation {
|
|||
pub command: CommandId,
|
||||
#[cultcache(key = 4)]
|
||||
pub payload: RecordPayload,
|
||||
#[cultcache(key = 5)]
|
||||
#[cultcache(key = 5, type_name = "System.Collections.Generic.IReadOnlyList<GameCult.Thing.Contract.CapturedInput>")]
|
||||
pub captured: Vec<CapturedInput>,
|
||||
#[cultcache(key = 6)]
|
||||
pub client: String,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
use cultcache_rs::CultTypeName;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
|
||||
|
||||
/// A value was outside its domain. Names the domain and its bound, never the value.
|
||||
|
|
@ -72,6 +73,13 @@ impl std::error::Error for DomainError {}
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Seq(i32);
|
||||
|
||||
impl CultTypeName for Seq {
|
||||
fn cult_type_name() -> String {
|
||||
"System.Int32".to_string()
|
||||
}
|
||||
const VALUE_TYPE: bool = true;
|
||||
}
|
||||
|
||||
impl Seq {
|
||||
pub const FIRST: Seq = Seq(1);
|
||||
|
||||
|
|
@ -108,6 +116,13 @@ impl Seq {
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Version(i64);
|
||||
|
||||
impl CultTypeName for Version {
|
||||
fn cult_type_name() -> String {
|
||||
"System.Int64".to_string()
|
||||
}
|
||||
const VALUE_TYPE: bool = true;
|
||||
}
|
||||
|
||||
impl Version {
|
||||
pub fn new(value: i64) -> Result<Self, DomainError> {
|
||||
if value >= 0 { Ok(Self(value)) } else { Err(DomainError::new("Version", "at least 0")) }
|
||||
|
|
@ -166,6 +181,12 @@ impl Count {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Segment(String);
|
||||
|
||||
impl CultTypeName for Segment {
|
||||
fn cult_type_name() -> String {
|
||||
"System.String".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Segment {
|
||||
pub fn new(value: impl Into<String>) -> Result<Self, DomainError> {
|
||||
let value = value.into();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! Identifier newtypes and the record key of each kind. No caller spells a key as a free string.
|
||||
|
||||
use cultcache_rs::CultTypeName;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::domain::{Segment, Seq, Version};
|
||||
|
|
@ -20,6 +21,12 @@ macro_rules! id_type {
|
|||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl CultTypeName for $name {
|
||||
fn cult_type_name() -> String {
|
||||
"System.String".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,6 @@
|
|||
//! `Deserialize` (CultCache's `DatabaseEntry` requires it). The domains therefore live in the
|
||||
//! field types (`Seq`, `Version`, `Count`, `Segment`), whose `Deserialize` calls the same
|
||||
//! `new` the constructors call, so no door skips a check.
|
||||
//!
|
||||
//! Hazard: decoding these kinds from untrusted bytes on a default-size thread can abort the
|
||||
//! process inside CultCache's nesting bound before the bound refuses (the stack is not
|
||||
//! bounded by nesting depth). The owner is `cultlib-gaps:follow_up:decode-stack-safety`; the
|
||||
//! tests decode on a 16 MiB thread until it lands.
|
||||
|
||||
mod asset;
|
||||
mod command;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ pub struct NodeCommon {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, CultUnion)]
|
||||
#[cultcache(type_name = "GameCult.Thing.Contract.Node")]
|
||||
pub enum Node {
|
||||
#[cultcache(key = 0)]
|
||||
Box(BoxNode),
|
||||
|
|
@ -444,7 +445,7 @@ pub struct SurfaceDocument {
|
|||
pub title: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub root: Node,
|
||||
#[cultcache(key = 5)]
|
||||
#[cultcache(key = 5, type_name = "System.Collections.Generic.IReadOnlyList<GameCult.Thing.Contract.CommandDecl>")]
|
||||
pub commands: Vec<CommandDecl>,
|
||||
}
|
||||
|
||||
|
|
@ -464,7 +465,7 @@ pub struct CompositionDocument {
|
|||
pub name: Segment,
|
||||
#[cultcache(key = 2)]
|
||||
pub version: Version,
|
||||
#[cultcache(key = 3)]
|
||||
#[cultcache(key = 3, type_name = "System.Collections.Generic.IReadOnlyList<GameCult.Thing.Contract.ParamDecl>")]
|
||||
pub params: Vec<ParamDecl>,
|
||||
#[cultcache(key = 4)]
|
||||
pub body: Node,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ pub struct FailedOutcome {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, CultUnion)]
|
||||
#[cultcache(type_name = "GameCult.Thing.Contract.Outcome")]
|
||||
pub enum Outcome {
|
||||
#[cultcache(key = 0)]
|
||||
Pending(PendingOutcome),
|
||||
|
|
|
|||
60
crates/thing-contract/tests/catalog_members.rs
Normal file
60
crates/thing-contract/tests/catalog_members.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
//! The catalog rows the five document kinds publish are the rows the C# package declares:
|
||||
//! `tests/thing-contract-parity/catalog-members.tsv`, which NameSetTests (C#) and parity.test.ts
|
||||
//! (TypeScript) are held to as well. Schema ids differ by writer, so the comparison is by group,
|
||||
//! as `catalogGroups` in parity.test.ts makes it.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use cultcache_rs::{DatabaseEntry, SchemaCatalogMember, SingleFileMessagePackBackingStore};
|
||||
use thing_contract::*;
|
||||
|
||||
fn tsv_groups() -> Vec<String> {
|
||||
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/thing-contract-parity/catalog-members.tsv");
|
||||
let text = std::fs::read_to_string(path).unwrap();
|
||||
let mut groups: Vec<(String, Vec<String>)> = Vec::new();
|
||||
for row in text.lines().filter(|line| !line.trim().is_empty()) {
|
||||
let (schema, rest) = row.split_once('\t').unwrap();
|
||||
match groups.iter_mut().find(|(id, _)| id == schema) {
|
||||
Some((_, rows)) => rows.push(rest.to_string()),
|
||||
None => groups.push((schema.to_string(), vec![rest.to_string()])),
|
||||
}
|
||||
}
|
||||
sorted(groups.into_iter().map(|(_, rows)| rows.join("\n")).collect())
|
||||
}
|
||||
|
||||
fn group(members: &[SchemaCatalogMember]) -> String {
|
||||
members.iter().map(|m| format!("{}\t{}\t{}", m.slot, m.member_name, m.type_name)).collect::<Vec<_>>().join("\n")
|
||||
}
|
||||
|
||||
fn sorted(mut groups: Vec<String>) -> Vec<String> {
|
||||
groups.sort();
|
||||
groups
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_equal_the_csharp_file() {
|
||||
let mine = sorted(vec![
|
||||
group(&SurfaceDocument::schema_members()),
|
||||
group(&CompositionDocument::schema_members()),
|
||||
group(&CommandInvocation::schema_members()),
|
||||
group(&CommandResult::schema_members()),
|
||||
group(&AssetCatalog::schema_members()),
|
||||
]);
|
||||
assert_eq!(mine, tsv_groups());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_written_store_carries_the_rows() {
|
||||
// goldens.rs writes a store of one record per kind and compares it byte for byte with the
|
||||
// committed surface.cc, so the committed file's catalog is the catalog the crate writes. It is
|
||||
// copied first: reading a store creates a lock file beside it.
|
||||
let committed = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/goldens/surface.cc");
|
||||
let work = PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("catalog-members");
|
||||
std::fs::create_dir_all(&work).unwrap();
|
||||
let copy = work.join("surface.cc");
|
||||
std::fs::copy(committed, ©).unwrap();
|
||||
let catalog = SingleFileMessagePackBackingStore::new(©).pull_schema_catalog().unwrap();
|
||||
let from_store = sorted(catalog.iter().map(|entry| group(&entry.members)).collect());
|
||||
assert_eq!(from_store, tsv_groups());
|
||||
let _ = std::fs::remove_dir_all(&work);
|
||||
}
|
||||
|
|
@ -642,13 +642,6 @@ fn refusal_cases() {
|
|||
|
||||
#[test]
|
||||
fn deep_tree() {
|
||||
// Decoding a Node costs tens of KiB of debug stack per nesting level, so the chain runs on a
|
||||
// thread that has the room; the 2 MiB default does not. The hazard is CultCache's, owned by
|
||||
// cultlib-gaps:follow_up:decode-stack-safety; the test stays on the big thread until it lands.
|
||||
std::thread::Builder::new().stack_size(16 * 1024 * 1024).spawn(deep_tree_body).unwrap().join().unwrap();
|
||||
}
|
||||
|
||||
fn deep_tree_body() {
|
||||
// A 64-deep Box chain.
|
||||
let mut chain = text("leaf", "bottom");
|
||||
for depth in (0..64).rev() {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ publish = false
|
|||
|
||||
[dependencies]
|
||||
thing-contract = { path = "../thing-contract" }
|
||||
stacker = "0.1.25"
|
||||
|
||||
[dev-dependencies]
|
||||
thing-testkit = { path = "../thing-testkit" }
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ use super::{Limits, std as thing_std, validate};
|
|||
/// rule (`Limits::max_tree_depth`) is judged by validate on the finished tree, where a slot argument
|
||||
/// the body never places does not count. It exists because an in-memory tree from a Rust caller can
|
||||
/// be deeper than any decoded document (CultCache bounds decoded nesting at 256), and recursion
|
||||
/// over it would overflow the stack. A level costs a few tens of KiB of stack in a debug build, so a
|
||||
/// caller resolving untrusted in-memory trees needs a stack sized for this many levels.
|
||||
/// over it would overflow the stack. The recursion grows its own stack (`super::grow`), so the bound
|
||||
/// holds on any thread.
|
||||
const STACK_BOUND: usize = 1024;
|
||||
|
||||
/// A fault the nearest enclosing Use turns into a placeholder (`Invalid`), or one that ends the
|
||||
|
|
@ -305,6 +305,10 @@ impl<'a> Expander<'a> {
|
|||
}
|
||||
|
||||
fn node(&mut self, node: &Node, scope: Option<&Scope>, depth: usize, root: bool) -> Res<Node> {
|
||||
super::grow(|| self.node_at(node, scope, depth, root))
|
||||
}
|
||||
|
||||
fn node_at(&mut self, node: &Node, scope: Option<&Scope>, depth: usize, root: bool) -> Res<Node> {
|
||||
if depth > STACK_BOUND {
|
||||
return Err(Fault::Stack(format!("the input nests deeper than {STACK_BOUND} levels")));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,17 @@ use thing_contract::SurfaceDocument;
|
|||
use crate::diagnostic::{Code, Diagnostic};
|
||||
use crate::port::{Address, StatePort};
|
||||
|
||||
/// Stack left below which recursion moves to a fresh segment, and the segment's size: the values
|
||||
/// cultcache-rs uses for decode. Every recursion over a tree runs through `grow`, so a tree as deep
|
||||
/// as `STACK_BOUND` resolves on a default thread.
|
||||
const RED_ZONE: usize = 512 * 1024;
|
||||
const SEGMENT: usize = 2 * 1024 * 1024;
|
||||
|
||||
/// Runs one recursive step with room for the next, growing the stack when it is nearly spent.
|
||||
fn grow<R>(step: impl FnOnce() -> R) -> R {
|
||||
stacker::maybe_grow(RED_ZONE, SEGMENT, step)
|
||||
}
|
||||
|
||||
/// The bounds of one expansion.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct Limits {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ fn id(node: &Node) -> Option<&NodeId> {
|
|||
|
||||
/// Nodes in the subtree, the node itself included.
|
||||
pub(super) fn size(node: &Node) -> usize {
|
||||
1 + children(node).iter().map(size).sum::<usize>()
|
||||
super::grow(|| 1 + children(node).iter().map(size).sum::<usize>())
|
||||
}
|
||||
|
||||
/// Faults of the finished tree, in pre-order: duplicate ids, then depth. A tree deeper than the limit is not walked further.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -194,7 +194,7 @@ fn swarm_ref(key: &str) -> StateSource {
|
|||
fn swarm_dashboard() -> SurfaceDocument {
|
||||
let load = Bind {
|
||||
source: swarm_ref("summary"),
|
||||
member: path(&["load"]),
|
||||
member: path(&["Load"]),
|
||||
format: Some(Format::Number(NumberFormat { precision: count(1), percent: true, unit: None })),
|
||||
};
|
||||
let load_text = Node::Text(TextNode {
|
||||
|
|
@ -212,10 +212,10 @@ fn swarm_dashboard() -> SurfaceDocument {
|
|||
schema: SchemaId::new(SWARM_SCHEMA),
|
||||
key_prefix: "mind-".into(),
|
||||
}),
|
||||
key_member: path(&["id"]),
|
||||
key_member: path(&["Id"]),
|
||||
template: std::boxed::Box::new(Node::Text(TextNode {
|
||||
common: common("mind-name"),
|
||||
content: TextSource::Bound(item_bind(path(&["name"]))),
|
||||
content: TextSource::Bound(item_bind(path(&["Name"]))),
|
||||
style_token: "body".into(),
|
||||
wrap: false,
|
||||
max_lines: Some(count(1)),
|
||||
|
|
@ -258,7 +258,7 @@ const STACK: &str = "provider.stack";
|
|||
|
||||
/// A Use of the publisher's card with one argument of each arm and the given slot children.
|
||||
fn card_use(id: &str, slot: Vec<Node>) -> Node {
|
||||
let source = Bind { source: swarm_ref("summary"), member: path(&["load"]), format: None };
|
||||
let source = Bind { source: swarm_ref("summary"), member: path(&["Load"]), format: None };
|
||||
let rows = CollectionSource::Records(RecordsSource {
|
||||
provider: None,
|
||||
schema: SchemaId::new(SWARM_SCHEMA),
|
||||
|
|
@ -292,7 +292,7 @@ fn composition_stack() -> SurfaceDocument {
|
|||
Arg { name: "label".into(), value: ArgValue::Text(TextArg { value: "Load".into() }) },
|
||||
Arg {
|
||||
name: "value".into(),
|
||||
value: ArgValue::Bind(Bind { source: swarm_ref("summary"), member: path(&["load"]), format: None }),
|
||||
value: ArgValue::Bind(Bind { source: swarm_ref("summary"), member: path(&["Load"]), format: None }),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
|
@ -323,10 +323,10 @@ fn stack_card() -> CompositionDocument {
|
|||
let rows = Node::Repeat(RepeatNode {
|
||||
common: common("card-rows"),
|
||||
collection: CollectionSource::Param(param("rows")),
|
||||
key_member: path(&["id"]),
|
||||
key_member: path(&["Id"]),
|
||||
template: std::boxed::Box::new(Node::Text(TextNode {
|
||||
common: common("card-row"),
|
||||
content: TextSource::Bound(item_bind(path(&["name"]))),
|
||||
content: TextSource::Bound(item_bind(path(&["Name"]))),
|
||||
style_token: "body".into(),
|
||||
wrap: false,
|
||||
max_lines: None,
|
||||
|
|
@ -398,7 +398,7 @@ fn hostile() -> Vec<SurfaceDocument> {
|
|||
schema: SchemaId::new("gamecult.thing.test.nowhere.v1"),
|
||||
key: RecordKey::new("row-1"),
|
||||
}),
|
||||
member: path(&["name"]),
|
||||
member: path(&["Name"]),
|
||||
format: None,
|
||||
}),
|
||||
style_token: "body".into(),
|
||||
|
|
@ -557,7 +557,7 @@ fn input_target() -> FixtureSet {
|
|||
});
|
||||
let label = Node::Text(TextNode {
|
||||
common: common("target-label"),
|
||||
content: TextSource::Bound(record_member(provider, "target", "cursor", &["label"])),
|
||||
content: TextSource::Bound(record_member(provider, "target", "cursor", &["Label"])),
|
||||
style_token: "body".into(),
|
||||
wrap: false,
|
||||
max_lines: Some(count(1)),
|
||||
|
|
@ -608,7 +608,7 @@ fn form() -> FixtureSet {
|
|||
let provider = "provider.settings";
|
||||
let toggle = Node::Toggle(ToggleNode {
|
||||
common: common("enabled"),
|
||||
checked: BoolSource::Bound(record_member(provider, "settings", "current", &["enabled"])),
|
||||
checked: BoolSource::Bound(record_member(provider, "settings", "current", &["Enabled"])),
|
||||
on_change: command("save"),
|
||||
});
|
||||
let slider = Node::Slider(SliderNode {
|
||||
|
|
@ -616,7 +616,7 @@ fn form() -> FixtureSet {
|
|||
min: 0.0,
|
||||
max: 1.0,
|
||||
step: 0.05,
|
||||
value: NumberSource::Bound(record_member(provider, "settings", "current", &["volume"])),
|
||||
value: NumberSource::Bound(record_member(provider, "settings", "current", &["Volume"])),
|
||||
commit: command("save"),
|
||||
});
|
||||
let select = Node::Select(SelectNode {
|
||||
|
|
@ -627,7 +627,7 @@ fn form() -> FixtureSet {
|
|||
SelectOption { value: "light".into(), label: "Light".into() },
|
||||
],
|
||||
}),
|
||||
value: record_member(provider, "settings", "current", &["theme"]),
|
||||
value: record_member(provider, "settings", "current", &["Theme"]),
|
||||
on_change: command("save"),
|
||||
});
|
||||
let port = text_input("port", InputKind::Number, "8080", command("save"));
|
||||
|
|
@ -686,7 +686,7 @@ fn scroll_list() -> SurfaceDocument {
|
|||
role: Role::ListItem,
|
||||
children: vec![Node::Text(TextNode {
|
||||
common: common("item-title"),
|
||||
content: TextSource::Bound(item_bind(path(&["title"]))),
|
||||
content: TextSource::Bound(item_bind(path(&["Title"]))),
|
||||
style_token: "body".into(),
|
||||
wrap: false,
|
||||
max_lines: Some(count(1)),
|
||||
|
|
@ -700,7 +700,7 @@ fn scroll_list() -> SurfaceDocument {
|
|||
schema: SchemaId::new(format!("{TEST_SCHEMA_ROOT}.item.v1")),
|
||||
key_prefix: "item-".into(),
|
||||
}),
|
||||
key_member: path(&["id"]),
|
||||
key_member: path(&["Id"]),
|
||||
template: std::boxed::Box::new(row),
|
||||
});
|
||||
let mut list = style();
|
||||
|
|
@ -718,7 +718,7 @@ fn scroll_list() -> SurfaceDocument {
|
|||
|
||||
fn plot() -> SurfaceDocument {
|
||||
let provider = "provider.market";
|
||||
let series = || record_member(provider, "series", "prices", &["values"]);
|
||||
let series = || record_member(provider, "series", "prices", &["Values"]);
|
||||
let mark = |id: &str, mark: PlotMark, x: (Option<f64>, Option<f64>), y: (Option<f64>, Option<f64>)| {
|
||||
Node::Plot(PlotNode {
|
||||
common: common(id),
|
||||
|
|
|
|||
|
|
@ -10,61 +10,53 @@ use thing_testkit::mem_state::MemState;
|
|||
use thing_testkit::store;
|
||||
use thing_core::port::{Address, Lookup, StatePort};
|
||||
|
||||
/// Decoding runs on a 16 MiB thread until the workspace pin of cultcache-rs carries
|
||||
/// decode-stack-safety.
|
||||
fn on_big_stack<T: Send + 'static>(work: impl FnOnce() -> T + Send + 'static) -> T {
|
||||
std::thread::Builder::new().stack_size(16 * 1024 * 1024).spawn(work).unwrap().join().unwrap()
|
||||
}
|
||||
|
||||
fn load(fixture: Fixture) -> FixtureSet {
|
||||
on_big_stack(move || fixture.load())
|
||||
fixture.load()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_fixture_round_trips_through_the_contract() {
|
||||
on_big_stack(|| {
|
||||
for fixture in Fixture::ALL {
|
||||
// The builders reproduce the committed file byte for byte (or bless it).
|
||||
let committed = fixture.write();
|
||||
assert_eq!(committed, std::fs::read(Fixture::dir().join(fixture.file_name())).unwrap());
|
||||
assert!(!committed.is_empty());
|
||||
let built = fixture.build();
|
||||
let loaded = fixture.load();
|
||||
assert_eq!(loaded, built, "{}: the store decodes to the built documents", fixture.file_name());
|
||||
for fixture in Fixture::ALL {
|
||||
// The builders reproduce the committed file byte for byte (or bless it).
|
||||
let committed = fixture.write();
|
||||
assert_eq!(committed, std::fs::read(Fixture::dir().join(fixture.file_name())).unwrap());
|
||||
assert!(!committed.is_empty());
|
||||
let built = fixture.build();
|
||||
let loaded = fixture.load();
|
||||
assert_eq!(loaded, built, "{}: the store decodes to the built documents", fixture.file_name());
|
||||
|
||||
// Each record re-encodes to its stored payload.
|
||||
let cache = fixture.open();
|
||||
let stored = cache.snapshot_envelopes();
|
||||
let payload = |kind: &str, key: String| {
|
||||
stored.iter().find(|envelope| envelope.r#type == kind && envelope.key == key).unwrap().payload.clone()
|
||||
};
|
||||
for surface in &loaded.surfaces {
|
||||
assert_eq!(rmp_serde::to_vec(surface).unwrap(), payload("gamecult.thing.surface", surface.record_key()));
|
||||
}
|
||||
for composition in &loaded.compositions {
|
||||
let key = composition.record_key();
|
||||
assert_eq!(rmp_serde::to_vec(composition).unwrap(), payload("gamecult.thing.composition", key));
|
||||
}
|
||||
for catalog in &loaded.catalogs {
|
||||
assert_eq!(rmp_serde::to_vec(catalog).unwrap(), payload("gamecult.thing.asset_catalog", catalog.record_key()));
|
||||
}
|
||||
for invocation in &loaded.invocations {
|
||||
let key = invocation.record_key();
|
||||
assert_eq!(rmp_serde::to_vec(invocation).unwrap(), payload("gamecult.thing.command_invocation", key));
|
||||
}
|
||||
for result in &loaded.results {
|
||||
assert_eq!(rmp_serde::to_vec(result).unwrap(), payload("gamecult.thing.command_result", result.record_key()));
|
||||
}
|
||||
assert_eq!(
|
||||
stored.len(),
|
||||
loaded.document_count(),
|
||||
"{}: the store holds the documents and nothing else",
|
||||
fixture.file_name()
|
||||
);
|
||||
// Each record re-encodes to its stored payload.
|
||||
let cache = fixture.open();
|
||||
let stored = cache.snapshot_envelopes();
|
||||
let payload = |kind: &str, key: String| {
|
||||
stored.iter().find(|envelope| envelope.r#type == kind && envelope.key == key).unwrap().payload.clone()
|
||||
};
|
||||
for surface in &loaded.surfaces {
|
||||
assert_eq!(rmp_serde::to_vec(surface).unwrap(), payload("gamecult.thing.surface", surface.record_key()));
|
||||
}
|
||||
// The payload one Box level past f11's chain is a raw file, not a store.
|
||||
assert_eq!(Fixture::write_deep_refused(), Fixture::deep_refused_payload());
|
||||
});
|
||||
for composition in &loaded.compositions {
|
||||
let key = composition.record_key();
|
||||
assert_eq!(rmp_serde::to_vec(composition).unwrap(), payload("gamecult.thing.composition", key));
|
||||
}
|
||||
for catalog in &loaded.catalogs {
|
||||
assert_eq!(rmp_serde::to_vec(catalog).unwrap(), payload("gamecult.thing.asset_catalog", catalog.record_key()));
|
||||
}
|
||||
for invocation in &loaded.invocations {
|
||||
let key = invocation.record_key();
|
||||
assert_eq!(rmp_serde::to_vec(invocation).unwrap(), payload("gamecult.thing.command_invocation", key));
|
||||
}
|
||||
for result in &loaded.results {
|
||||
assert_eq!(rmp_serde::to_vec(result).unwrap(), payload("gamecult.thing.command_result", result.record_key()));
|
||||
}
|
||||
assert_eq!(
|
||||
stored.len(),
|
||||
loaded.document_count(),
|
||||
"{}: the store holds the documents and nothing else",
|
||||
fixture.file_name()
|
||||
);
|
||||
}
|
||||
// The payload one Box level past f11's chain is a raw file, not a store.
|
||||
assert_eq!(Fixture::write_deep_refused(), Fixture::deep_refused_payload());
|
||||
}
|
||||
|
||||
fn commands_declared(surface: &SurfaceDocument) -> Vec<&str> {
|
||||
|
|
@ -171,7 +163,7 @@ fn f10_holds_exactly_the_four_hostile_surfaces() {
|
|||
|
||||
#[test]
|
||||
fn a_state_holds_every_fixture_document_under_its_publisher() {
|
||||
let state = on_big_stack(|| MemState::from_fixture(Fixture::F09CompositionStack));
|
||||
let state = MemState::from_fixture(Fixture::F09CompositionStack);
|
||||
let set = load(Fixture::F09CompositionStack);
|
||||
let at = Address {
|
||||
provider: ProviderId::new(set.compositions[0].publisher.clone()),
|
||||
|
|
@ -393,7 +385,7 @@ fn f06_scrolls_a_repeat_over_a_records_prefix() {
|
|||
assert_eq!(root.style.overflow, Overflow::Scroll);
|
||||
let [Node::Repeat(items)] = &root.children[..] else { panic!("one Repeat expected") };
|
||||
assert!(matches!(&items.collection, CollectionSource::Records(records) if !records.key_prefix.is_empty()));
|
||||
assert_eq!(items.key_member, thing_testkit::build::path(&["id"]));
|
||||
assert_eq!(items.key_member, thing_testkit::build::path(&["Id"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -424,45 +416,43 @@ fn f08_embeds_a_fixed_size_leaf_among_siblings() {
|
|||
|
||||
#[test]
|
||||
fn f11_is_the_deepest_chain_the_bound_admits_and_one_more_level_is_refused() {
|
||||
on_big_stack(|| {
|
||||
let (set, surface) = single_surface(Fixture::F11Deep);
|
||||
let cache = Fixture::F11Deep.open();
|
||||
let stored = cache.snapshot_envelopes();
|
||||
assert_eq!(stored.len(), 1);
|
||||
// The committed surface passes CultCache's own check and decodes to the built chain.
|
||||
assert_eq!(check_payload_depth(&stored[0].payload), Ok(()));
|
||||
assert_eq!(rmp_serde::to_vec(&surface).unwrap(), stored[0].payload);
|
||||
let levels = {
|
||||
let mut levels = 0;
|
||||
let mut node = &surface.root;
|
||||
while let Node::Box(boxed) = node {
|
||||
levels += 1;
|
||||
match boxed.children.first() {
|
||||
Some(child) => node = child,
|
||||
None => break,
|
||||
}
|
||||
let (set, surface) = single_surface(Fixture::F11Deep);
|
||||
let cache = Fixture::F11Deep.open();
|
||||
let stored = cache.snapshot_envelopes();
|
||||
assert_eq!(stored.len(), 1);
|
||||
// The committed surface passes CultCache's own check and decodes to the built chain.
|
||||
assert_eq!(check_payload_depth(&stored[0].payload), Ok(()));
|
||||
assert_eq!(rmp_serde::to_vec(&surface).unwrap(), stored[0].payload);
|
||||
let levels = {
|
||||
let mut levels = 0;
|
||||
let mut node = &surface.root;
|
||||
while let Node::Box(boxed) = node {
|
||||
levels += 1;
|
||||
match boxed.children.first() {
|
||||
Some(child) => node = child,
|
||||
None => break,
|
||||
}
|
||||
levels
|
||||
};
|
||||
assert!(levels > 1, "a chain, not one Box");
|
||||
assert_eq!(set.surfaces.len(), 1);
|
||||
}
|
||||
levels
|
||||
};
|
||||
assert!(levels > 1, "a chain, not one Box");
|
||||
assert_eq!(set.surfaces.len(), 1);
|
||||
|
||||
// One Box level deeper is refused by the check, naming depth 257, and by CultCache.
|
||||
let refused = golden::read(&Fixture::dir(), Fixture::DEEP_REFUSED);
|
||||
assert_eq!(refused, Fixture::deep_refused_payload());
|
||||
assert_eq!(check_payload_depth(&refused), Err(PayloadTooDeep { depth: 257, limit: 256 }));
|
||||
let mut cache = store::memory();
|
||||
let envelope = CultCacheEnvelope {
|
||||
key: surface.record_key(),
|
||||
r#type: "gamecult.thing.surface".into(),
|
||||
payload: refused,
|
||||
stored_at: store::PINNED_CLOCK.into(),
|
||||
schema_id: Some("gamecult.thing.surface.v1".into()),
|
||||
};
|
||||
let error = cache.put_raw_envelope(envelope).unwrap_err();
|
||||
assert!(error.downcast_ref::<PayloadTooDeep>().is_some(), "{error:#}");
|
||||
assert!(cache.get::<SurfaceDocument>(&surface.record_key()).unwrap().is_none());
|
||||
});
|
||||
// One Box level deeper is refused by the check, naming depth 257, and by CultCache.
|
||||
let refused = golden::read(&Fixture::dir(), Fixture::DEEP_REFUSED);
|
||||
assert_eq!(refused, Fixture::deep_refused_payload());
|
||||
assert_eq!(check_payload_depth(&refused), Err(PayloadTooDeep { depth: 257, limit: 256 }));
|
||||
let mut cache = store::memory();
|
||||
let envelope = CultCacheEnvelope {
|
||||
key: surface.record_key(),
|
||||
r#type: "gamecult.thing.surface".into(),
|
||||
payload: refused,
|
||||
stored_at: store::PINNED_CLOCK.into(),
|
||||
schema_id: Some("gamecult.thing.surface.v1".into()),
|
||||
};
|
||||
let error = cache.put_raw_envelope(envelope).unwrap_err();
|
||||
assert!(error.downcast_ref::<PayloadTooDeep>().is_some(), "{error:#}");
|
||||
assert!(cache.get::<SurfaceDocument>(&surface.record_key()).unwrap().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -17,15 +17,8 @@ fn scratch_entries() -> Vec<String> {
|
|||
#[test]
|
||||
fn writing_a_fixture_leaves_no_scratch_file_or_lock_behind() {
|
||||
let before = scratch_entries();
|
||||
let stack = std::thread::Builder::new().stack_size(16 * 1024 * 1024);
|
||||
stack
|
||||
.spawn(|| {
|
||||
for fixture in Fixture::ALL {
|
||||
fixture.write();
|
||||
}
|
||||
})
|
||||
.unwrap()
|
||||
.join()
|
||||
.unwrap();
|
||||
for fixture in Fixture::ALL {
|
||||
fixture.write();
|
||||
}
|
||||
assert_eq!(scratch_entries(), before);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue