use flow_abi_testing::catalog as common;
use flow_abi_testing::describing;
use common::*;
use describing as d;
use flow_abi::description::CallTypes;
use flow_abi::wire::{Declared as _, Wire as _};
use flow_abi::{
Catalog, DecodeError, DecodeErrorKind, Limits, Mode, ResultType, Signature, ToolDecl, TypeSpec,
ValidatedTypes, call_bindings, call_views, decode_bytes, description, read_listing,
write_listing, write_value,
};
use flow_types::{Body, Decl, DeclId, ModulePath, Segments, Tree, Type};
fn not_a_description(kind: DecodeErrorKind) -> bool {
matches!(
kind,
DecodeErrorKind::Mismatch | DecodeErrorKind::Syntax { .. }
)
}
#[test]
fn a_result_type_is_its_term_and_the_templates_it_reaches() {
let catalog = catalog();
let plan = ResultType::from_catalog(&catalog, &Type::list(named(PLAN))).unwrap();
assert_eq!(plan.result(), &Type::list(Type::Named(DeclId(0), vec![])));
let Body::Record(shape, _) = &plan.catalog().decl(DeclId(0)).body else {
panic!("Plan is a record");
};
assert_eq!(
shape.fields().collect::<Vec<_>>(),
["steps", "owner", "title"]
);
assert_eq!(ResultType::read(plan.bytes()).unwrap(), plan);
let text = ResultType::read(&d::result_type(d::TEXT, &[])).unwrap();
assert_eq!(
(text.result(), text.bytes()),
(&Type::Text, &d::result_type(d::TEXT, &[])[..])
);
assert_ne!(text, plan);
assert!(ResultType::from_catalog(&catalog, &Type::Param(0)).is_err());
for refused in [
d::result_type(&d::tool_param(0), &[]),
d::result_type(d::TEXT, &[key().bytes()]),
[d::result_type(d::TEXT, &[]), vec![0]].concat(),
] {
assert_eq!(
kind_of(ResultType::read(&refused)),
DecodeErrorKind::Mismatch,
"{refused:?}"
);
}
}
fn served() -> TypeSpec {
TypeSpec::read(&d::spec(
&["T"],
&[("items", &d::set_of(&d::tool_param(0)))],
d::TEXT,
&[],
))
.expect("a valid description")
}
fn key() -> d::Template<'static> {
d::Template::local(
"Key",
d::record(&[
d::field("z", &d::option_of(d::INT)),
d::field("a", &d::option_of(d::INT)),
]),
)
}
fn private_call(template: &d::Template<'_>) -> Vec<u8> {
d::call_types(
&[("T", &d::named(0, &[]))],
&[("items", &d::set_of(&d::named(0, &[])))],
d::TEXT,
&[template.bytes()],
)
}
fn validate(spec: &TypeSpec, types: &[u8]) -> Result<Option<ValidatedTypes>, DecodeError> {
spec.validate_call(Some(&CallTypes::decode(types)?))
}
fn bindings_of(types: &[u8]) -> Result<(Catalog, Vec<(String, Type)>), DecodeError> {
call_bindings(&CallTypes::decode(types)?)
}
fn refused(spec: &TypeSpec, types: &[u8]) -> String {
validate(spec, types)
.expect_err("the call's types are refused")
.problem
}
#[test]
fn generic_call_metadata_preserves_private_record_order() {
let catalog = catalog();
let signature = Signature {
generic: vec!["T".into()],
params: vec![("items".into(), Type::set(Type::Param(0)))],
result: Type::Text,
};
let served = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[named(PLAN)]).unwrap();
let validated = served.validate_call(Some(&views)).unwrap().unwrap();
assert_eq!(
validated.binding("T"),
Some(&Type::Named(DeclId(0), vec![]))
);
let Body::Record(shape, fields) = &validated.catalog().decl(DeclId(0)).body else {
panic!("Plan is a record");
};
assert_eq!(
shape.fields().collect::<Vec<_>>(),
["steps", "owner", "title"]
);
assert_eq!(
fields,
&[
Type::list(Type::Named(DeclId(1), vec![])),
Type::option(Type::Text),
Type::Text
]
);
let written = d::record(&[
d::field("steps", &d::list_of(&d::named(1, &[]))),
d::field("owner", &d::option_of(d::TEXT)),
d::field("title", d::TEXT),
]);
assert_eq!(d::count(&views.bytes(), &written), 1);
assert_eq!(TypeSpec::read(served.bytes()).unwrap(), served);
}
#[test]
fn generic_call_requires_both_views_and_nongeneric_refuses_either() {
let signature = Signature {
generic: vec!["T".into()],
params: vec![],
result: Type::Text,
};
let served = TypeSpec::from_catalog(&catalog(), &signature).unwrap();
let views = call_views(&catalog(), &signature, &[Type::Int]).unwrap();
assert_eq!(
kind_of(served.validate_call(None)),
DecodeErrorKind::Mismatch
);
assert_eq!(
kind_of(validate(&served, &Vec::new())),
DecodeErrorKind::Syntax { at: 0 }
);
assert!(served.validate_call(Some(&views)).unwrap().is_some());
let fixed = TypeSpec::from_catalog(
&catalog(),
&Signature {
generic: vec![],
..signature
},
)
.unwrap();
assert!(fixed.validate_call(None).unwrap().is_none());
assert_eq!(
kind_of(fixed.validate_call(Some(&views))),
DecodeErrorKind::Mismatch
);
}
#[test]
fn private_record_field_order_is_literal() {
let types = private_call(&key());
let validated = served()
.validate_call(Some(&d::views(&types)))
.unwrap()
.unwrap();
let Type::Named(id, _) = validated.binding("T").unwrap() else {
panic!("nominal binding");
};
let Body::Record(shape, fields) = &validated.catalog().decl(*id).body else {
panic!("record");
};
assert_eq!(shape.fields().collect::<Vec<_>>(), ["z", "a"]);
assert_eq!(fields, &[Type::option(Type::Int), Type::option(Type::Int)]);
assert_eq!(validated.types(), types);
}
fn raw_key(opaque: u8, doc: &[u8]) -> Vec<u8> {
[
d::string("Key"),
d::identity(None, "main", "Key"),
d::signed(1),
d::list(&[]),
vec![opaque],
doc.to_vec(),
key().body,
]
.concat()
}
#[test]
fn malformed_call_templates_refuse_before_catalog_or_partial_view() {
let served = served();
let bound = d::named(0, &[]);
let items = d::set_of(&bound);
let call = |bindings: &[(&str, &[u8])], params: &[(&str, &[u8])], result: &[u8]| {
d::call_types(bindings, params, result, &[key().bytes()])
};
let with_template = |template: Vec<u8>| {
d::call_types(&[("T", &bound)], &[("items", &items)], d::TEXT, &[template])
};
let variants = [
private_call(&d::Template {
ordinal: 0,
..key()
}),
private_call(&d::Template {
body: vec![5],
..key()
}),
with_template(raw_key(0, &[2])),
private_call(&d::Template {
body: d::record(&[
d::field("z", &d::option_of(d::INT)),
d::field("z", &d::option_of(d::INT)),
]),
..key()
}),
call(
&[("T", &d::named(0, &[d::INT]))],
&[("items", &items)],
d::TEXT,
),
call(&[("T", &d::named(1, &[]))], &[("items", &items)], d::TEXT),
call(&[("T", &bound)], &[("wrong", &items)], d::TEXT),
call(&[("wrong", &bound)], &[("items", &items)], d::TEXT),
call(&[("T", &bound)], &[("items", &items)], d::INT),
call(
&[("T", &bound)],
&[("items", &items)],
&d::tuple_of(&[d::TEXT]),
),
private_call(&d::Template {
body: d::record(&[
d::field("z", &d::tool_param(0)),
d::field("a", &d::option_of(d::INT)),
]),
..key()
}),
[private_call(&key()), vec![0]].concat(),
];
for malformed in variants {
assert_eq!(
kind_of(validate(&served, &malformed.clone())),
DecodeErrorKind::Mismatch,
"{malformed:?}"
);
}
assert_eq!(
kind_of(validate(&served, &with_template(raw_key(2, &[0])))),
DecodeErrorKind::Syntax { at: 35 },
"a Bool byte that is neither 0 nor 1 is refused where it stands"
);
}
#[test]
fn owners_and_exact_term_shapes_are_checked_in_static_specs() {
let items = |param: &[u8]| d::spec(&["T"], &[("items", &d::set_of(param))], d::TEXT, &[]);
let result = |result: &[u8]| d::spec(&["T"], &[], result, &[]);
for malformed in [
items(&[18, 2, 0]),
items(&d::owned_param(0, 0)),
items(&d::tool_param(1)),
items(&d::tool_param(-1)),
items(&d::tool_param(1 << 32)),
d::spec(&["T", "T"], &[], d::TEXT, &[]),
result(&[19]),
result(&[14, 3]),
result(&d::function_of(&[], &[19])),
[items(&d::tool_param(0)), vec![0]].concat(),
] {
assert!(
not_a_description(kind_of(TypeSpec::read(&malformed))),
"{malformed:?}"
);
}
}
fn known_box() -> d::Template<'static> {
d::Template {
library: Some(("std", Some("v1"))),
module: "example",
..d::Template::local(
"Box",
d::record(&[d::field("z", &d::owned_param(0, 0)), d::field("a", d::TEXT)]),
)
.generic(&["Item"])
}
}
fn known() -> TypeSpec {
let documented = d::Template {
doc: Some("provider documentation"),
body: d::record(&[
d::field_doc("z", &d::owned_param(0, 0), Some("first")),
d::field("a", d::TEXT),
]),
..known_box()
};
TypeSpec::read(&d::spec(
&["T"],
&[("value", &d::named(0, &[&d::tool_param(0)]))],
d::TEXT,
&[documented.bytes()],
))
.expect("a valid description")
}
fn known_call(template: &d::Template<'_>, arg: &[u8]) -> Vec<u8> {
d::call_types(
&[("T", d::INT)],
&[("value", &d::named(0, &[arg]))],
d::TEXT,
&[template.bytes()],
)
}
#[test]
fn known_templates_map_ids_ignore_docs_and_preserve_order_and_substitution() {
let served = known();
let views = d::views(&known_call(&known_box(), d::INT));
assert!(served.validate_call(Some(&views)).is_ok());
for malformed in [
known_call(&known_box(), d::TEXT),
known_call(
&d::Template {
ordinal: 2,
..known_box()
},
d::INT,
),
known_call(&known_box().generic(&["Item", "Other"]), d::INT),
known_call(
&d::Template {
body: d::record(&[d::field("b", &d::owned_param(0, 0)), d::field("a", d::TEXT)]),
..known_box()
},
d::INT,
),
known_call(
&d::Template {
body: d::record(&[d::field("z", &d::owned_param(0, 0)), d::field("a", d::INT)]),
..known_box()
},
d::INT,
),
known_call(
&d::Template {
opaque: true,
..known_box()
},
d::INT,
),
] {
assert_eq!(
kind_of(validate(&served, &malformed.clone())),
DecodeErrorKind::Mismatch,
"{malformed:?}"
);
}
}
fn recursive(a: &[&[u8]], b_generic: &'static [&'static str], b: &[&[u8]]) -> Vec<u8> {
let first = d::Template::local(
"A",
d::record(&[d::field("next", &d::option_of(&d::named(1, a)))]),
)
.generic(&["T", "U"]);
let second = d::Template::local(
"B",
d::record(&[d::field("next", &d::option_of(&d::named(0, b)))]),
)
.generic(b_generic);
d::spec(
&["T", "U"],
&[],
&d::named(0, &[&d::tool_param(0), &d::tool_param(1)]),
&[first.bytes(), second.bytes()],
)
}
#[test]
fn regular_mutual_permutations_are_finite_and_changing_arguments_refuse() {
let (a0, a1) = (d::owned_param(0, 0), d::owned_param(0, 1));
let (b0, b1) = (d::owned_param(1, 0), d::owned_param(1, 1));
assert!(TypeSpec::read(&recursive(&[&a1, &a0], &["X", "Y"], &[&b1, &b0])).is_ok());
for malformed in [
recursive(&[&d::list_of(&a1), &a0], &["X", "Y"], &[&b1, &b0]),
recursive(&[&a0, &a0], &["X", "Y"], &[&b1, &b0]),
recursive(&[&a1, &a0], &["X", "Y"], &[&b0, &b0]),
recursive(&[&a1, &a0], &["X", "Y"], &[&b1, &a0]),
] {
assert_eq!(
kind_of(TypeSpec::read(&malformed)),
DecodeErrorKind::Mismatch,
"{malformed:?}"
);
}
}
#[test]
fn recursive_components_require_equal_arity_and_identity_cycle_composition() {
let (a0, a1) = (d::owned_param(0, 0), d::owned_param(0, 1));
let (b0, b1) = (d::owned_param(1, 0), d::owned_param(1, 1));
assert_eq!(
TypeSpec::read(&recursive(&[&a0], &["X"], &[&b0, &b0]))
.unwrap_err()
.problem,
"recursive declaration arities differ"
);
assert_eq!(
TypeSpec::read(&recursive(&[&a1, &a0], &["X", "Y"], &[&b0, &b1]))
.unwrap_err()
.problem,
"recursive substitutions do not compose to identity"
);
}
fn phantom_call(n: &[u8]) -> Vec<u8> {
let argument = d::function_of(&[&d::named(1, &[])], d::INT);
let bound = d::named(0, &[&argument]);
d::call_types(
&[("T", &bound)],
&[("items", &d::set_of(&bound))],
d::TEXT,
&[
d::Template::local("Phantom", d::record(&[d::field("n", n)]))
.generic(&["T"])
.bytes(),
d::Template::local(
"Callback",
d::record(&[d::field("run", &d::function_of(&[d::INT], d::TEXT))]),
)
.bytes(),
],
)
}
#[test]
fn descriptive_function_arguments_retain_nondata_templates_without_value_crossing() {
let served = served();
let validated = served
.validate_call(Some(&d::views(&phantom_call(d::INT))))
.unwrap()
.unwrap();
assert_eq!(validated.catalog().decls().len(), 2);
let Type::Named(id, args) = validated.binding("T").unwrap() else {
panic!("phantom binding");
};
assert!(matches!(&args[0], Type::Function { .. }));
assert_eq!(validated.catalog().decl(*id).identity.name, "Phantom");
assert_eq!(
kind_of(validate(&served, &phantom_call(&d::owned_param(0, 0)))),
DecodeErrorKind::Mismatch
);
for actual in [d::function_of(&[d::INT], d::TEXT), d::task_of(d::INT)] {
let types = d::call_types(
&[("T", &actual)],
&[("items", &d::set_of(&actual))],
d::TEXT,
&[],
);
assert_eq!(
kind_of(validate(&served, &types)),
DecodeErrorKind::Mismatch
);
}
}
#[test]
fn disconnected_and_conflicting_private_declarations_are_refused() {
let served = served();
let conflicting = d::call_types(
&[("T", &d::named(0, &[]))],
&[("items", &d::set_of(&d::named(1, &[])))],
d::TEXT,
&[key().bytes(), key().bytes()],
);
assert_eq!(
refused(&served, &conflicting),
"two templates have one identity and lexical ordinal"
);
let disconnected = d::call_types(
&[("T", &d::named(0, &[]))],
&[("items", &d::set_of(&d::named(0, &[])))],
d::TEXT,
&[
key().bytes(),
d::Template {
ordinal: 2,
..key()
}
.bytes(),
],
);
assert_eq!(
refused(&served, &disconnected),
"template 1 is one nothing in the description reaches"
);
}
fn choice(constructors: &[Vec<u8>]) -> Vec<u8> {
d::spec(
&["T"],
&[],
&d::named(0, &[&d::tool_param(0)]),
&[d::Template::local("Choice", d::enumeration(constructors))
.generic(&["T"])
.bytes()],
)
}
fn choices() -> Vec<Vec<u8>> {
vec![
d::empty("None"),
d::positional("Pair", &[&d::owned_param(0, 0), d::TEXT]),
d::named_payload(
"Left",
&[d::field_doc(
"value",
&d::option_of(&d::owned_param(0, 0)),
Some("left"),
)],
),
d::named_payload("Right", &[d::field_doc("value", d::INT, Some("right"))]),
]
}
#[test]
fn enum_payload_kinds_and_constructor_scopes_are_preserved_and_strict() {
let bytes = choice(&choices());
let served = TypeSpec::read(&bytes).unwrap();
let rewritten = TypeSpec::from_catalog(served.catalog(), served.signature()).unwrap();
assert_eq!(rewritten.bytes(), bytes);
let mut renamed = choices();
renamed[3] = d::named_payload("Left", &[d::field("value", d::INT)]);
let mut unknown = choices();
unknown[0] = [d::string("None"), d::doc(None), vec![3]].concat();
let mut repeated = choices();
repeated[3] = d::named_payload(
"Right",
&[d::field("value", d::INT), d::field("value", d::TEXT)],
);
let mut undocumented = choices();
undocumented[0] = [d::string("None"), vec![2], vec![0]].concat();
for malformed in [renamed, unknown, repeated, undocumented] {
assert_eq!(
kind_of(TypeSpec::read(&choice(&malformed))),
DecodeErrorKind::Mismatch,
"{malformed:?}"
);
}
}
#[test]
fn a_local_identity_is_its_module_path_from_the_tree_root() {
let validated = served()
.validate_call(Some(&d::views(&private_call(&d::Template {
module: "private/main",
..key()
}))))
.unwrap()
.unwrap();
let Type::Named(id, _) = validated.binding("T").unwrap() else {
panic!("named binding");
};
let identity = &validated.catalog().decl(*id).identity;
assert_eq!(
identity.origin,
ModulePath::new(
Tree::Local,
None,
"private/main"
.parse::<Segments>()
.expect("a test path is a path")
)
);
assert_eq!(description::Identity::of(identity).module, "private/main");
}
#[test]
fn a_remote_identity_is_read_back_exactly_as_it_is_written() {
for (library, version, module) in [
("github.com/acme/plans", "v1", ""),
("github.com/acme/plans", "v1", "x"),
("github.com/acme/plans/ledger", "v1.2", "a/b"),
] {
let types = private_call(&d::Template {
library: Some((library, Some(version))),
module,
..key()
});
let validated = served()
.validate_call(Some(&d::views(&types)))
.expect("a valid call")
.expect("a view");
let Type::Named(id, _) = validated.binding("T").unwrap() else {
panic!("named binding");
};
assert_eq!(
description::Identity::of(&validated.catalog().decl(*id).identity),
description::Identity {
library: Some(description::Library {
address: library.into(),
version: Some(version.into()),
}),
module: module.into(),
name: "Key".into(),
}
);
}
}
#[test]
fn unused_ambiguous_binding_is_descriptive_while_required_roots_are_concrete() {
let served = TypeSpec::read(&d::spec(&["T"], &[("n", d::INT)], d::TEXT, &[])).unwrap();
let types = d::call_types(
&[("T", &d::option_of(d::JSON_VALUE))],
&[("n", d::INT)],
d::TEXT,
&[],
);
let validated = served
.validate_call(Some(&d::views(&types)))
.unwrap()
.unwrap();
assert_eq!(validated.binding("T"), Some(&Type::option(Type::Json)));
assert_eq!(validated.argument("n"), Some(&Type::Int));
assert_eq!(validated.argument("absent"), None);
assert_eq!(validated.binding("absent"), None);
assert_eq!(validated.result(), &Type::Text);
}
#[test]
fn known_template_local_generic_names_do_not_change_owner_index_meaning() {
let renamed = known_box().generic(&["Other"]);
assert!(
known()
.validate_call(Some(&d::views(&known_call(&renamed, d::INT))))
.is_ok()
);
}
#[test]
fn generic_binding_data_requirement_is_independent_of_actual_root_use() {
let served = TypeSpec::read(&d::spec(&["T"], &[("n", d::INT)], d::TEXT, &[])).unwrap();
let call = |binding: &[u8], templates: &[Vec<u8>]| {
d::call_types(&[("T", binding)], &[("n", d::INT)], d::TEXT, templates)
};
for binding in [d::function_of(&[d::INT], d::INT), d::task_of(d::INT)] {
assert_eq!(
refused(&served, &call(&binding, &[])),
"has a type with no encoding"
);
}
let secret = d::Template {
opaque: true,
..d::Template::local("Secret", d::record(&[d::field("n", d::INT)]))
};
assert_eq!(
refused(&served, &call(&d::named(0, &[]), &[secret.bytes()])),
"has the type main.Secret, which is opaque, so it can't be decoded"
);
}
#[test]
fn shared_writer_publishes_all_terms_and_reuses_declarations_across_signatures() {
let catalog = catalog();
let signature = Signature {
generic: vec!["T".into()],
params: vec![
("decimal".into(), Type::Decimal),
("bytes".into(), Type::Bytes),
("duration".into(), Type::Duration),
("instant".into(), Type::Instant),
("bool".into(), Type::Bool),
("unit".into(), Type::Unit),
("never".into(), Type::Never),
("json".into(), Type::Json),
("dictionary".into(), Type::dict(Type::Text, Type::Param(0))),
("tuple".into(), Type::Tuple(vec![Type::Int, Type::Text])),
("task".into(), Type::Task(Box::new(Type::Int))),
(
"callback".into(),
Type::Function {
params: vec![named(PAGE)],
result: Box::new(named(STATUS)),
},
),
],
result: tree(Type::Param(0)),
};
let spec = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let names: Vec<_> = spec
.catalog()
.decls()
.map(|(_, decl)| decl.identity.name.as_str())
.collect();
assert_eq!(names, ["Page", "Status", "Tree"]);
assert!(matches!(spec.catalog().decl(DeclId(0)).body, Body::Host));
let Body::Enum(shape, payloads) = &spec.catalog().decl(DeclId(1)).body else {
panic!("Status is an enum");
};
let payload = |at: usize| {
shape
.constructor(at)
.expect("a constructor")
.payload()
.clone()
};
assert_eq!(payload(0), flow_types::Payload::None);
assert_eq!(payload(1), flow_types::Payload::Positional(1));
assert_eq!(payload(3), flow_types::Payload::named(["index", "reply"]));
assert_eq!(payloads[3], [Type::Int, Type::option(Type::Text)]);
assert_eq!(TypeSpec::read(spec.bytes()).unwrap(), spec);
let tool = |name: &str| ToolDecl {
identity: local(name),
signature: signature.clone(),
};
let (first, second) = (tool("first"), tool("second"));
let listing = write_listing("./main", &catalog, &[&first, &second]).unwrap();
for constructor in ["Arrived", "Leaf"] {
assert_eq!(
d::count(&listing, &d::string(constructor)),
1,
"a template the two Tools share is written once"
);
}
let [program] = <[_; 1]>::try_from(read_listing(&listing).unwrap()).unwrap();
for (_, listed) in &program.tools {
assert_eq!(listed, &spec);
}
}
#[test]
fn template_writer_refuses_unpublishable_or_unbound_public_types() {
let catalog = catalog();
for (ty, reason) in [
(Type::NotData, "a type that has no description"),
(
Type::Tuple(vec![Type::Int]),
"a type that has no description",
),
(
Type::Named(DeclId(999), vec![]),
"a type names a declaration the catalog lacks",
),
(
Type::Named(BOXED, vec![]),
"a declaration's argument count differs",
),
(
Type::Param(1),
"a type parameter's index exceeds its owner's",
),
] {
let signature = Signature {
generic: vec!["T".into()],
params: vec![],
result: ty,
};
assert_eq!(
TypeSpec::from_catalog(&catalog, &signature)
.unwrap_err()
.problem,
reason
);
}
let signature = Signature {
generic: vec!["T".into()],
params: vec![],
result: Type::Text,
};
assert_eq!(
call_views(&catalog, &signature, &[]).unwrap_err().problem,
"a generic call's argument count differs"
);
assert_eq!(
call_views(&catalog, &signature, &[Type::Param(0)])
.unwrap_err()
.problem,
"a concrete type names a parameter"
);
}
#[test]
fn generic_enum_and_option_field_substitution_validate_and_decode_at_actual_roots() {
let catalog = catalog();
let signature = Signature {
generic: vec!["T".into()],
params: vec![
(
"items".into(),
Type::dict(Type::Text, Type::Tuple(vec![Type::Param(0), Type::Bool])),
),
("status".into(), named(STATUS)),
],
result: Type::Named(BOXED, vec![Type::Param(0)]),
};
let served = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[Type::option(Type::Int)]).unwrap();
let validated = served.validate_call(Some(&views)).unwrap().unwrap();
assert_eq!(validated.binding("T"), Some(&Type::option(Type::Int)));
assert_eq!(
validated.argument("items"),
Some(&Type::dict(
Type::Text,
Type::Tuple(vec![Type::option(Type::Int), Type::Bool])
))
);
for input in ["{}", r#"{"value":null}"#] {
let value = flow_abi::decode(
validated.catalog(),
validated.result(),
&json(input),
flow_abi::Mode::Reply,
&flow_abi::Limits::default(),
)
.unwrap();
assert_eq!(
flow_abi::encode(validated.catalog(), validated.result(), &value)
.unwrap()
.canonical(),
"{}"
);
}
let renamed = d::replace(&views.bytes(), &d::string("Arrived"), &d::string("Renamed"));
let pair = [d::string("Pair"), vec![0, 1, 2]].concat();
let swapped = d::replace(
&views.bytes(),
&[pair.clone(), [d::INT, d::TEXT].concat()].concat(),
&[pair, [d::TEXT, d::INT].concat()].concat(),
);
for malformed in [renamed, swapped] {
assert_eq!(
kind_of(validate(&served, &malformed)),
DecodeErrorKind::Mismatch
);
}
}
#[test]
fn metadata_container_and_scalar_shapes_have_no_permissive_defaults() {
let valid = choice(&choices());
assert!(TypeSpec::read(&valid).is_ok());
for end in 0..valid.len() {
assert!(
not_a_description(kind_of(TypeSpec::read(&valid[..end]))),
"the first {end} bytes"
);
}
let misnamed = [
d::string("Key"),
d::identity(None, "main", "Other"),
d::signed(1),
d::list(&[]),
vec![0, 0],
key().body,
]
.concat();
assert_eq!(
kind_of(validate(
&served(),
&d::call_types(
&[("T", &d::named(0, &[]))],
&[("items", &d::set_of(&d::named(0, &[])))],
d::TEXT,
&[misnamed],
)
)),
DecodeErrorKind::Mismatch
);
}
fn handle(body: &[u8]) -> Vec<u8> {
d::Template::local("Handle", body.to_vec()).bytes()
}
fn descriptive(body: &Body) -> Option<&'static [u8]> {
match body {
Body::Host => Some(d::HOST),
Body::NonData => Some(d::NONDATA),
Body::Record(..) | Body::Enum(..) | Body::Newtype(_) => None,
}
}
#[test]
fn host_and_nondata_templates_are_descriptive_in_phantom_slots_only() {
let served = served();
for body in [d::HOST, d::NONDATA] {
let bound = d::named(0, &[&d::named(1, &[])]);
let phantom = d::call_types(
&[("T", &bound)],
&[("items", &d::set_of(&bound))],
d::TEXT,
&[
d::Template::local("Phantom", d::record(&[d::field("n", d::INT)]))
.generic(&["T"])
.bytes(),
handle(body),
],
);
let validated = served
.validate_call(Some(&d::views(&phantom)))
.unwrap()
.unwrap();
let Type::Named(_, arguments) = validated.binding("T").unwrap() else {
panic!("phantom")
};
let Type::Named(id, _) = arguments[0] else {
panic!("handle")
};
assert_eq!(descriptive(&validated.catalog().decl(id).body), Some(body));
let concrete = d::call_types(
&[("T", &d::named(0, &[]))],
&[("items", &d::set_of(&d::named(0, &[])))],
d::TEXT,
&[handle(body)],
);
assert_eq!(
kind_of(validate(&served, &concrete)),
DecodeErrorKind::Mismatch
);
let signature = Signature {
generic: vec!["Unused".into()],
params: vec![("phantom".into(), validated.binding("T").unwrap().clone())],
result: Type::Text,
};
let republished = TypeSpec::from_catalog(validated.catalog(), &signature).unwrap();
let views = call_views(validated.catalog(), &signature, &[Type::Int]).unwrap();
assert!(republished.validate_call(Some(&views)).is_ok());
assert!(
republished
.catalog()
.decls()
.any(|(_, decl)| descriptive(&decl.body) == Some(body))
);
}
}
#[test]
fn recursive_enum_call_validation_memoizes_known_template_pairs() {
let catalog = catalog();
let signature = Signature {
generic: vec!["T".into()],
params: vec![("tree".into(), tree(Type::Param(0)))],
result: tree(Type::Param(0)),
};
let served = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[Type::Int]).unwrap();
let validated = served.validate_call(Some(&views)).unwrap().unwrap();
let value = flow_abi::decode(
validated.catalog(),
validated.result(),
&json(r#"{"Node":[{"Leaf":1},{"Node":[{"Leaf":2}]}]}"#),
flow_abi::Mode::Reply,
&flow_abi::Limits::default(),
)
.unwrap();
assert_eq!(
flow_abi::encode(validated.catalog(), validated.result(), &value)
.unwrap()
.canonical(),
r#"{"Node":[{"Leaf":1},{"Node":[{"Leaf":2}]}]}"#
);
for malformed in [
d::replace(&views.bytes(), &d::string("Leaf"), &d::string("Wrong")),
d::replace(&views.bytes(), &d::string("trees"), &d::string("different")),
] {
assert_eq!(
kind_of(validate(&served, &malformed.clone())),
DecodeErrorKind::Mismatch,
"{malformed:?}"
);
}
}
#[test]
fn generic_metadata_accepts_existing_opaque_arguments_but_refuses_opaque_replies() {
let catalog = catalog();
let signature = Signature {
generic: vec!["Unused".into()],
params: vec![
("approved".into(), named(APPROVED)),
("page".into(), named(PAGE)),
],
result: Type::Text,
};
let served = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[Type::Int]).unwrap();
assert!(
served.validate_call(Some(&views)).is_ok(),
"arguments carry existing opaque values and host tokens"
);
for result in [named(APPROVED), Type::option(named(APPROVED))] {
let signature = Signature {
params: vec![],
result,
..signature.clone()
};
let served = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[Type::Int]).unwrap();
assert_eq!(
kind_of(served.validate_call(Some(&views))),
DecodeErrorKind::Mismatch,
"reply decoding cannot construct opaque values"
);
}
let page = call_views(&catalog, &signature, &[named(PAGE)]).unwrap();
assert_eq!(
kind_of(served.validate_call(Some(&page))),
DecodeErrorKind::Mismatch,
"generic binding is data even when unused"
);
}
#[derive(Clone, Copy, Debug)]
enum Root {
Param,
Result,
}
#[test]
fn actual_boundary_roots_refuse_ambiguous_options_and_nondata_even_when_empty() {
let catalog = catalog();
for ty in [
Type::option(Type::Json),
Type::list(Type::option(Type::Json)),
Type::Task(Box::new(Type::Int)),
Type::Function {
params: vec![Type::Int],
result: Box::new(Type::Text),
},
] {
for root in [Root::Param, Root::Result] {
let (params, result) = match root {
Root::Param => (vec![("value".into(), ty.clone())], Type::Text),
Root::Result => (vec![], ty.clone()),
};
let signature = Signature {
generic: vec!["Unused".into()],
params,
result,
};
let served = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[Type::Int]).unwrap();
assert_eq!(
kind_of(served.validate_call(Some(&views))),
DecodeErrorKind::Mismatch,
"{root:?}: {ty:?}"
);
}
}
}
#[test]
fn crossing_judgment_follows_used_fields_and_preserves_checkpoint_rebuilding() {
let catalog = catalog();
assert!(flow_abi::crossable(&catalog, &named(APPROVED)).is_ok());
assert!(flow_abi::crossable(&catalog, &named(PAGE)).is_ok());
let ambiguous = Type::option(Type::Json);
assert!(
flow_abi::decodable(&catalog, &ambiguous, flow_abi::BINDING).is_ok(),
"unused binding remains descriptive"
);
assert_eq!(
kind_of(flow_abi::crossable(
&catalog,
&Type::Named(BOXED, vec![ambiguous.clone()])
)),
DecodeErrorKind::Mismatch
);
assert_eq!(
kind_of(flow_abi::crossable(&catalog, &tree(ambiguous.clone()))),
DecodeErrorKind::Mismatch,
"recursive fields reach their parameter"
);
let function = Type::Function {
params: vec![],
result: Box::new(Type::Unit),
};
assert_eq!(
kind_of(flow_abi::crossable(&catalog, &Type::list(function.clone()))),
DecodeErrorKind::Mismatch
);
let empty = flow_abi::decode(
&catalog,
&Type::list(function),
&json("[]"),
flow_abi::Mode::Rebuild,
&flow_abi::Limits::default(),
)
.unwrap();
assert!(
matches!(empty, flow_value::Value::List(_)),
"checkpoint rebuilding still admits an empty function list"
);
assert_eq!(
kind_of(flow_abi::crossable(&catalog, &Type::Param(0))),
DecodeErrorKind::Mismatch
);
let phantom = served()
.validate_call(Some(&d::views(&phantom_call(d::INT))))
.unwrap()
.unwrap();
let Type::Named(id, _) = phantom.binding("T").unwrap() else {
panic!("phantom")
};
let unused = Type::Named(*id, vec![ambiguous]);
assert!(flow_abi::crossable(phantom.catalog(), &unused).is_ok());
let signature = Signature {
generic: vec!["T".into()],
params: vec![("phantom".into(), unused)],
result: Type::Text,
};
let spec = TypeSpec::from_catalog(phantom.catalog(), &signature).unwrap();
let views = call_views(phantom.catalog(), &signature, &[Type::Int]).unwrap();
assert!(spec.validate_call(Some(&views)).is_ok());
}
#[test]
fn crossing_checks_option_parameters_after_nominal_and_recursive_substitution() {
let declaration = |name: &str, fields: Vec<(&str, Type)>| Decl {
lexical_ordinal: 1,
identity: local(name),
doc: None,
members: vec![],
params: vec!["T".into()],
opaque: false,
body: Body::Record(
flow_types::RecordShape::new(name, fields.iter().map(|(name, _)| *name)),
fields.into_iter().map(|(_, ty)| ty).collect(),
),
};
let named = |index, arg| Type::Named(DeclId(index), vec![arg]);
let catalog = Catalog::new(
vec![
declaration("Optional", vec![("value", Type::option(Type::Param(0)))]),
declaration("ListBox", vec![("value", Type::list(Type::Param(0)))]),
declaration("A", vec![("next", Type::list(named(3, Type::Param(0))))]),
declaration(
"B",
vec![
("again", Type::list(named(2, Type::Param(0)))),
("item", named(0, Type::Param(0))),
],
),
declaration("Phantom", vec![("n", Type::Int)]),
],
option_shape(),
Some(json_shape()),
)
.unwrap();
for id in [0, 2, 3] {
let signature = Signature {
generic: vec!["T".into()],
params: vec![("value".into(), named(id, Type::Param(0)))],
result: Type::Text,
};
let spec = TypeSpec::from_catalog(&catalog, &signature).unwrap();
let views = call_views(&catalog, &signature, &[Type::Json]).unwrap();
assert_eq!(
kind_of(flow_abi::crossable(&catalog, &named(id, Type::Json))),
DecodeErrorKind::Mismatch,
"declaration {id} reaches Option<T>"
);
assert_eq!(
kind_of(spec.validate_call(Some(&views))),
DecodeErrorKind::Mismatch
);
assert!(flow_abi::crossable(&catalog, &named(id, Type::Int)).is_ok());
}
assert!(
flow_abi::crossable(&catalog, &named(1, Type::Json)).is_ok(),
"List<T> is distinct from Option<T>"
);
assert!(
flow_abi::crossable(&catalog, &named(4, Type::option(Type::Json))).is_ok(),
"phantom arguments remain descriptive"
);
}
#[test]
fn concrete_roots_refuse_free_parameters_and_inconsistent_tuple_arity() {
let free = d::call_types(
&[("T", &d::tool_param(0))],
&[("items", &d::set_of(&d::tool_param(0)))],
d::TEXT,
&[],
);
assert_eq!(
refused(&served(), &free),
"a concrete root names a type parameter"
);
let spec = TypeSpec::read(&d::spec(
&["T"],
&[("value", &d::tuple_of(&[d::INT, d::TEXT]))],
d::TEXT,
&[],
))
.unwrap();
let concrete = d::call_types(
&[("T", d::INT)],
&[("value", &d::tuple_of(&[d::INT, d::TEXT, d::BOOL]))],
d::TEXT,
&[],
);
assert_eq!(refused(&spec, &concrete), "concrete type arity differs");
}
#[test]
fn a_served_template_mapped_to_two_caller_templates_is_refused() {
let documented = d::Template {
doc: Some("provider documentation"),
..known_box()
};
let boxed = d::named(0, &[&d::tool_param(0)]);
let served = TypeSpec::read(&d::spec(
&["T"],
&[("value", &boxed), ("second", &boxed)],
d::TEXT,
&[documented.bytes()],
))
.unwrap();
let call = d::call_types(
&[("T", d::INT)],
&[
("value", &d::named(0, &[d::INT])),
("second", &d::named(1, &[d::INT])),
],
d::TEXT,
&[
known_box().bytes(),
d::Template {
ordinal: 2,
body: d::record(&[d::field("z", &d::owned_param(1, 0)), d::field("a", d::TEXT)]),
..known_box()
}
.bytes(),
],
);
assert_eq!(
refused(&served, &call),
"known declaration maps to conflicting caller templates"
);
}
#[test]
fn writer_propagates_nested_invalid_terms_without_partial_metadata() {
let catalog = catalog();
for ty in [
Type::Tuple(vec![Type::Int, Type::Param(1)]),
Type::Function {
params: vec![Type::Param(1)],
result: Box::new(Type::Int),
},
Type::Named(BOXED, vec![Type::Param(1)]),
] {
let signature = Signature {
generic: vec!["T".into()],
params: vec![],
result: ty,
};
assert_eq!(
TypeSpec::from_catalog(&catalog, &signature)
.unwrap_err()
.problem,
"a type parameter's index exceeds its owner's"
);
}
}
#[test]
fn malformed_declared_members_never_publish_a_partial_template_graph() {
for (id, member) in [(PLAN, 0), (STATUS, 1), (STATUS, 3)] {
let mut declarations: Vec<_> = catalog()
.decls()
.map(|(_, declaration)| declaration.clone())
.collect();
match &mut declarations[usize::try_from(id.0).expect("a small id")].body {
Body::Record(_, fields) => fields[member] = Type::NotData,
Body::Enum(_, constructors) => constructors[member][0] = Type::NotData,
Body::Newtype(_) | Body::Host | Body::NonData => panic!("member-bearing declaration"),
}
let catalog = Catalog::new(declarations, option_shape(), Some(json_shape())).unwrap();
let signature = Signature {
generic: vec![],
params: vec![],
result: named(id),
};
assert_eq!(
TypeSpec::from_catalog(&catalog, &signature)
.unwrap_err()
.problem,
"a type that has no description"
);
}
let mut misowned = choices();
misowned[1] = d::positional("Pair", &[&d::owned_param(0, 1), d::TEXT]);
assert_eq!(
TypeSpec::read(&choice(&misowned)).unwrap_err().problem,
"a type parameter's index exceeds its owner's"
);
}
fn template_names(spec: &TypeSpec) -> Vec<String> {
spec.catalog()
.decls()
.map(|(_, decl)| decl.identity.name.clone())
.collect()
}
#[test]
fn dictionary_key_and_value_templates_keep_their_reachable_declarations() {
let catalog = catalog();
for (key, value, names) in [
(named(STEP), Type::Text, vec!["Step"]),
(Type::Text, named(PLAN), vec!["Plan", "Step"]),
(named(STEP), named(PLAN), vec!["Step", "Plan"]),
] {
let signature = Signature {
generic: vec![],
params: vec![("lookup".into(), Type::dict(key, value))],
result: Type::Text,
};
let published = TypeSpec::from_catalog(&catalog, &signature).unwrap();
assert_eq!(template_names(&published), names);
let read = TypeSpec::read(published.bytes())
.expect("dictionary declarations are reachable through their key and value types");
assert_eq!(read, published);
}
}
#[test]
fn tuple_templates_keep_direct_and_transitive_reachable_declarations() {
let catalog = catalog();
for (parts, names) in [
(vec![named(STEP), Type::Text], vec!["Step"]),
(vec![Type::Text, named(PLAN)], vec!["Plan", "Step"]),
(vec![named(STEP), named(PLAN)], vec!["Step", "Plan"]),
] {
let signature = Signature {
generic: vec![],
params: vec![("parts".into(), Type::Tuple(parts))],
result: Type::Text,
};
let published = TypeSpec::from_catalog(&catalog, &signature).unwrap();
assert_eq!(template_names(&published), names);
let read = TypeSpec::read(published.bytes())
.expect("tuple declarations are reachable through every component");
assert_eq!(read, published);
}
}
#[test]
fn acyclic_declaration_edges_allow_different_arities_and_concrete_arguments() {
let declaration = |name: &str, params: Vec<String>, ty: Type| Decl {
lexical_ordinal: 1,
identity: local(name),
doc: None,
members: vec![],
params,
opaque: false,
body: Body::Record(flow_types::RecordShape::new(name, ["value"]), vec![ty]),
};
for (parameters, argument) in [(vec![], Type::Int), (vec!["T".into()], Type::Param(0))] {
let catalog = Catalog::new(
vec![
declaration(
"Outer",
parameters.clone(),
Type::Named(DeclId(1), vec![argument]),
),
declaration("Inner", vec!["U".into()], Type::Param(0)),
],
option_shape(),
Some(json_shape()),
)
.unwrap();
let signature = Signature {
generic: parameters.clone(),
params: vec![],
result: Type::Named(
DeclId(0),
(0..parameters.len())
.map(|index| Type::Param(u32::try_from(index).unwrap()))
.collect(),
),
};
let spec = TypeSpec::from_catalog(&catalog, &signature).unwrap();
assert_eq!(TypeSpec::read(spec.bytes()).unwrap(), spec);
}
}
#[test]
fn a_call_s_bindings_read_back_as_the_same_types_and_no_others() {
let catalog = catalog();
let signature = Signature {
generic: vec!["T".into(), "U".into()],
params: vec![],
result: Type::Param(0),
};
let types = [
Type::Int,
Type::Decimal,
Type::Bool,
Type::Text,
Type::Bytes,
Type::Duration,
Type::Instant,
Type::Unit,
Type::Never,
Type::Json,
Type::list(Type::Int),
Type::set(Type::Int),
Type::option(Type::Int),
Type::Task(Box::new(Type::Int)),
Type::dict(Type::Text, Type::Int),
Type::Tuple(vec![Type::Int, Type::Text]),
Type::Function {
params: vec![Type::Int],
result: Box::new(Type::Text),
},
named(PLAN),
tree(Type::Int),
tree(Type::Text),
];
let read: Vec<_> = types
.iter()
.map(|ty| {
let views = call_views(&catalog, &signature, &[ty.clone(), Type::Int]).unwrap();
let (viewed, bindings) = call_bindings(&views).unwrap();
let [(name, bound), (other, _)] = <[_; 2]>::try_from(bindings).unwrap();
assert_eq!((name.as_str(), other.as_str()), ("T", "U"));
(viewed, bound)
})
.collect();
for (left, ty) in types.iter().enumerate() {
for (right, (viewed, bound)) in read.iter().enumerate() {
assert_eq!(
catalog.same(ty, viewed, bound),
left == right,
"{ty:?} against {bound:?}"
);
}
}
assert!(catalog.same(&Type::Param(0), &catalog, &Type::Param(0)));
assert!(!catalog.same(&Type::Param(0), &catalog, &Type::Param(1)));
assert!(!catalog.same(&Type::NotData, &catalog, &Type::NotData));
}
#[test]
fn fixing_matches_a_type_parameter_to_one_type_wherever_it_appears() {
let catalog = catalog();
let fits = |declared: &Type, given: &Type| {
catalog.matches(declared, &catalog, given, &mut flow_abi::Fixing::default())
};
let function = |params, result| Type::Function {
params,
result: Box::new(result),
};
let pair = |left, right| Type::Tuple(vec![left, right]);
for (declared, given) in [
(Type::set(Type::Param(0)), Type::set(Type::Int)),
(Type::option(Type::Param(0)), Type::option(Type::Int)),
(
Type::Task(Box::new(Type::Param(0))),
Type::Task(Box::new(Type::Int)),
),
(
Type::dict(Type::Text, Type::Param(0)),
Type::dict(Type::Text, Type::Int),
),
(
function(vec![Type::Param(0)], Type::Param(0)),
function(vec![Type::Int], Type::Int),
),
] {
assert!(fits(
&pair(declared.clone(), Type::Param(0)),
&pair(given.clone(), Type::Int)
));
assert!(
!fits(&pair(declared, Type::Param(0)), &pair(given, Type::Text)),
"fixed inconsistently"
);
}
assert!(!fits(
&function(vec![Type::Param(0)], Type::Param(0)),
&function(vec![Type::Int, Type::Int], Type::Int),
));
assert!(
!fits(&named(PLAN), &tree(Type::Int)),
"declared types stay nominal"
);
assert!(fits(&tree(Type::Param(0)), &tree(Type::Int)));
assert!(!fits(&tree(Type::Param(0)), &named(PLAN)));
let mut exact = flow_abi::Exact;
assert!(!catalog.matches(&Type::Param(0), &catalog, &Type::Int, &mut exact));
assert!(catalog.matches(&Type::Param(0), &catalog, &Type::Param(0), &mut exact));
}
#[test]
fn a_binding_nested_beyond_the_former_schema_bound_is_accepted() {
let mut deep = d::INT.to_vec();
let mut item_schema = r#"{"type":"integer"}"#.to_owned();
for _ in 0..150 {
deep = d::list_of(&deep);
item_schema = format!(r#"{{"items":{item_schema},"type":"array"}}"#);
}
let types = d::call_types(
&[("T", &deep)],
&[("items", &d::set_of(&deep))],
d::TEXT,
&[],
);
validate(&served(), &types).unwrap();
}
#[test]
fn deep_malformed_type_descriptions_never_admit_a_partial_graph() {
let wrap = |mut term: Vec<u8>| {
for _ in 0..300 {
term = d::list_of(&term);
}
d::call_types(&[("T", &term)], &[], d::TEXT, &[])
};
let valid = wrap(d::INT.to_vec());
bindings_of(&valid).unwrap();
for end in 0..valid.len() {
assert!(
not_a_description(kind_of(bindings_of(&valid[..end]))),
"prefix {end}"
);
}
for term in [
d::number(255),
d::named(99, &[]),
d::tool_param(0),
[d::number(15), d::number(u64::MAX)].concat(),
[d::number(16), d::number(u64::MAX)].concat(),
[d::number(17), d::signed(0), d::number(u64::MAX)].concat(),
] {
assert!(not_a_description(kind_of(bindings_of(&wrap(term)))));
}
}
#[test]
fn type_descriptions_are_not_bounded_by_value_nesting() {
let catalog = catalog();
let mut deep = Type::Int;
for _ in 0..300 {
deep = Type::list(deep);
}
let signature = Signature {
generic: vec![],
params: vec![("value".into(), deep.clone())],
result: deep.clone(),
};
let spec = TypeSpec::from_catalog(&catalog, &signature).unwrap();
assert_eq!(TypeSpec::read(spec.bytes()).unwrap(), spec);
let generic = Signature {
generic: vec!["T".into()],
params: vec![("value".into(), Type::Param(0))],
result: Type::Param(0),
};
let spec = TypeSpec::from_catalog(&catalog, &generic).unwrap();
let views = call_views(&catalog, &generic, &[deep]).unwrap();
assert_eq!(
spec.validate_call(Some(&views)).unwrap().unwrap().types(),
views.bytes()
);
}
fn call_types_written() -> Vec<Vec<u8>> {
let catalog = catalog();
let signature = Signature {
generic: vec!["T".into()],
params: vec![("item".into(), Type::Param(0))],
result: Type::list(Type::Param(0)),
};
let mut written: Vec<Vec<u8>> = catalog
.decls()
.filter_map(|(id, decl)| {
let bound = Type::Named(id, vec![Type::Int; decl.params.len()]);
call_views(&catalog, &signature, &[bound]).ok()
})
.map(|views| views.bytes())
.collect();
written.push(private_call(&key()));
written.extend(
include_str!("../../../toolkits/conformance/descriptions/vectors.txt")
.lines()
.filter_map(|line| match line.split(' ').collect::<Vec<_>>()[..] {
[_, "calltypes", hex, "valid"] => Some(d::unhex(hex)),
_ => None,
}),
);
written
}
#[test]
fn a_call_s_types_are_the_value_encoding_of_a_call_types_value() {
let (catalog, call_types) = CallTypes::shape()
.project(&catalog())
.expect("a CallTypes has a Flow type");
let written = call_types_written();
assert!(written.len() > 3, "{} descriptions", written.len());
for bytes in written {
let value = decode_bytes(
&catalog,
&call_types,
&bytes,
Mode::Rebuild,
&Limits::default(),
)
.unwrap_or_else(|error| panic!("a CallTypes value: {}", error.problem));
let mut again = Vec::new();
write_value(&mut again, &catalog, &call_types, &value).expect("a value of its type");
assert_eq!(again, bytes, "written again as a value, the same bytes");
}
}