|
7 | 7 | use std::collections::BTreeSet; |
8 | 8 |
|
9 | 9 | use vm::{ |
10 | | - HostApiCatalog, HostTypeSchema, http_host_catalog, jit_host_catalog, sqlite_host_catalog, |
11 | | - standard_host_catalog, |
| 10 | + HostApiCatalog, HostStructField, HostTypeSchema, http_host_catalog, jit_host_catalog, |
| 11 | + sqlite_host_catalog, standard_host_catalog, |
12 | 12 | }; |
13 | 13 |
|
14 | | -fn assert_no_public_dynamic_schema(catalog_name: &str, catalog: &HostApiCatalog) { |
| 14 | +fn assert_no_public_dynamic_root(path: &str, schema: &HostTypeSchema) { |
15 | 15 | fn visit(path: &str, schema: &HostTypeSchema, seen: &mut BTreeSet<String>) { |
16 | 16 | match schema { |
17 | 17 | HostTypeSchema::Map(_) | HostTypeSchema::Unknown => { |
@@ -45,31 +45,53 @@ fn assert_no_public_dynamic_schema(catalog_name: &str, catalog: &HostApiCatalog) |
45 | 45 | } |
46 | 46 | } |
47 | 47 |
|
| 48 | + visit(path, schema, &mut BTreeSet::new()); |
| 49 | +} |
| 50 | + |
| 51 | +fn assert_no_public_dynamic_schema(catalog_name: &str, catalog: &HostApiCatalog) { |
48 | 52 | for schema in catalog.structs() { |
49 | 53 | for field in &schema.fields { |
50 | | - visit( |
| 54 | + assert_no_public_dynamic_root( |
51 | 55 | &format!("{catalog_name}::{}.{}", schema.name, field.name), |
52 | 56 | &field.ty, |
53 | | - &mut BTreeSet::new(), |
54 | 57 | ); |
55 | 58 | } |
56 | 59 | } |
57 | 60 | for function in catalog.functions() { |
58 | 61 | for param in &function.params { |
59 | | - visit( |
| 62 | + assert_no_public_dynamic_root( |
60 | 63 | &format!("{catalog_name}::{}({})", function.name, param.name), |
61 | 64 | ¶m.ty, |
62 | | - &mut BTreeSet::new(), |
63 | 65 | ); |
64 | 66 | } |
65 | | - visit( |
| 67 | + assert_no_public_dynamic_root( |
66 | 68 | &format!("{catalog_name}::{} return", function.name), |
67 | 69 | &function.return_type, |
68 | | - &mut BTreeSet::new(), |
69 | 70 | ); |
70 | 71 | } |
71 | 72 | } |
72 | 73 |
|
| 74 | +fn recursive_named_schema() -> HostTypeSchema { |
| 75 | + HostTypeSchema::named_struct( |
| 76 | + "RecursiveNode", |
| 77 | + vec![ |
| 78 | + HostStructField::new("value", HostTypeSchema::Int), |
| 79 | + HostStructField::new( |
| 80 | + "next", |
| 81 | + HostTypeSchema::Optional(Box::new(HostTypeSchema::named_struct( |
| 82 | + "RecursiveNode", |
| 83 | + Vec::new(), |
| 84 | + ))), |
| 85 | + ), |
| 86 | + ], |
| 87 | + ) |
| 88 | +} |
| 89 | + |
| 90 | +#[test] |
| 91 | +fn recursive_named_struct_walk_stops_at_repeated_named_type() { |
| 92 | + assert_no_public_dynamic_root("recursive::node", &recursive_named_schema()); |
| 93 | +} |
| 94 | + |
73 | 95 | #[test] |
74 | 96 | fn affected_public_host_catalogs_have_no_reachable_map_or_unknown() { |
75 | 97 | assert_no_public_dynamic_schema("http", &http_host_catalog()); |
|
0 commit comments