diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index d72f836..ec46db7 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -30,10 +30,11 @@ jobs: # are its tests. - run: cargo test --verbose -p comline-core --features deps - # The size vectors the sizer is tested against (core/tests/spec) are the - # specification's own, at the rev `comline-catalog` is pinned to. + # The size vectors the sizer is tested against and the compiler cases the + # build is (core/tests/spec) are the specification's own, at the rev + # `comline-catalog` is pinned to. spec_vectors: - name: Vendored size vectors + name: Vendored specification files runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/core/Cargo.toml b/core/Cargo.toml index b5cf37b..dbf111e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -24,7 +24,7 @@ comline-core-stdlib = { path = "../core_stdlib", version = "0.1.0" } # The specification's catalog of shared names: guarantees, facts and their # values, the official encodings' aliases and frozen spellings. no_std and # dependency-free, so the IR-only build has it too. -comline-catalog = { git = "https://github.com/ComlineProject/specification", rev = "9a7142c395b2aefb7d4d77e9b36c74187c6f0199" } +comline-catalog = { git = "https://github.com/ComlineProject/specification", rev = "068500670debade6b004b85032924f945dbb0a2c" } # General eyre = "0.6.8" diff --git a/core/tests/package/compiler_cases.rs b/core/tests/package/compiler_cases.rs new file mode 100644 index 0000000..69f9ebd --- /dev/null +++ b/core/tests/package/compiler_cases.rs @@ -0,0 +1,304 @@ +//! The specification's compiler conformance cases (`compiler/cases/`, vendored +//! in `tests/spec/cases`, core#224): each is a schema graph as data with the +//! outcome any compiler must reproduce. For every case this writes its +//! packages side by side in a temp directory, builds the case's `build` +//! package as `comline build` resolves it (`compile_package`, dependencies +//! from the paths its config declares), and compares what the build gave with +//! the case's `expect`: +//! +//! - whether it built; +//! - for a build that did: every protocol of the package, the set it gives up +//! (what is frozen with it), and where the case states it, who acknowledged +//! a guarantee (the protocol's `@unverified` or the package's) and why; and +//! the warnings the package's own schemas and config reported, by code and +//! severity; +//! - for one that didn't: the errors that have a code, and text the others +//! contain. +//! +//! A failed build reaches the caller as one rendered error, not a list of +//! diagnostics, so the codes of its errors are the `[code]` markers the +//! renderer writes (`Error[unverified::missing-marker]` with a span, +//! `[unverified::missing-marker]` without), found in that text, and each is +//! an error. Core has no coded error that isn't rendered that way. Warnings +//! are read structured, from the schemas' own. +//! +//! Every case is run, and every mismatch reported with its case's id, before +//! the test fails. A case core disagrees with, that core is wrong about, is in +//! `CORE_DISAGREES` with the rule it breaks: its mismatch is reported but +//! doesn't fail the test, and the case passing fails it, so the entry goes +//! when the bug does. +//! +//! The dependency cases need `deps`, which resolves a package's dependencies: +//! the module is built with it. + +use std::collections::BTreeSet; +use std::path::{Path, PathBuf}; + +use comline_core::package::build::compile_package; +use comline_core::schema::ir::frozen::unit::{ConfigValue, FrozenUnit, Guarantee}; +use comline_core::schema::ir::unverified; +use serde_json::Value; + +/// Cases where core's behaviour breaks the rule the case states, and the +/// case is right: id, and what is wrong. The runner holds each to still +/// disagreeing. +const CORE_DISAGREES: &[(&str, &str)] = &[]; + +fn cases_dir() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/spec/cases") +} + +/// A diagnostic as a case states it: its code and its severity, as written. +type Diag = (String, String); + +/// What building the case's package gave, as far as a case speaks of it. +struct Outcome { + builds: bool, + /// The package's protocols: name, what it gives up, and for each guarantee + /// the scope and reason it was acknowledged with. + protocols: Vec<(String, Vec, Vec<(Guarantee, &'static str, String)>)>, + /// A build that passed: the package's own warnings. One that failed: the + /// coded errors in what it said. + diagnostics: BTreeSet, + /// A failed build's error, whole, for `error_contains`. + error: String, +} + +fn write_packages(root: &Path, case: &Value) { + for package in case["packages"].as_array().unwrap() { + let dir = root.join(package["name"].as_str().unwrap()); + std::fs::create_dir_all(&dir).unwrap(); + std::fs::write(dir.join("config.idp"), package["config"].as_str().unwrap()).unwrap(); + for schema in package["schemas"].as_array().unwrap() { + let path = dir.join(schema["path"].as_str().unwrap()); + std::fs::create_dir_all(path.parent().unwrap()).unwrap(); + std::fs::write(path, schema["text"].as_str().unwrap()).unwrap(); + } + } +} + +/// The namespace `src//.ids` is compiled under: `a::b`. +fn namespace_of(path: &str) -> String { + path.strip_prefix("src/").unwrap().strip_suffix(".ids").unwrap().replace('/', "::") +} + +/// `text` without its ANSI colour sequences, which the renderer writes when it +/// believes it is on a terminal. +fn plain(text: &str) -> String { + let mut out = String::new(); + let mut chars = text.chars().peekable(); + while let Some(c) = chars.next() { + if c == '\u{1b}' && chars.peek() == Some(&'[') { + for c in chars.by_ref() { + if c.is_ascii_alphabetic() { + break; + } + } + } else { + out.push(c); + } + } + out +} + +/// The `[namespace::code]` markers in a rendered error: a lowercase +/// `namespace::kebab-name` in brackets. +fn coded(error: &str) -> BTreeSet { + let mut codes = BTreeSet::new(); + for (start, _) in error.match_indices('[') { + let Some(end) = error[start..].find(']') else { continue }; + let inside = &error[start + 1..start + end]; + let Some((namespace, name)) = inside.split_once("::") else { continue }; + let word = |s: &str, extra: char| { + s.starts_with(|c: char| c.is_ascii_lowercase()) + && s.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == extra) + }; + if word(namespace, '_') && word(name, '-') { + codes.insert(inside.to_string()); + } + } + codes +} + +fn severity(severity: comline_core::diagnostics::Severity) -> &'static str { + use comline_core::diagnostics::Severity; + match severity { + Severity::Error => "error", + Severity::Warning => "warning", + Severity::Info => "info", + Severity::Hint => "hint", + } +} + +/// Who acknowledged `guarantee` for a protocol, and what they said: its own +/// `@unverified` (which wins where both say), else the package's. +fn acknowledgement(parameters: &[FrozenUnit], guarantee: Guarantee) -> Option<(&'static str, String)> { + let own = match unverified::marker(parameters) { + Some(ConfigValue::Str(reason)) => Some(reason), + Some(ConfigValue::Dict(entries)) => entries.iter().find_map(|(key, value)| match value { + ConfigValue::Str(reason) if key == guarantee.name() => Some(reason), + _ => None, + }), + _ => None, + }; + match own { + Some(reason) => Some(("protocol", reason.clone())), + None => unverified::package_reason_for(parameters, guarantee).map(|r| ("package", r.to_string())), + } +} + +fn build(case: &Value) -> Result { + let tmp = tempfile::tempdir().unwrap(); + write_packages(tmp.path(), case); + let name = case["build"].as_str().unwrap(); + let built = case["packages"].as_array().unwrap().iter().find(|p| p["name"] == name).unwrap(); + + let context = match compile_package(&tmp.path().join(name)) { + Ok(context) => context, + Err(error) => { + let error = plain(&format!("{error:?}")); + let diagnostics = coded(&error).into_iter().map(|code| (code, "error".to_string())).collect(); + return Ok(Outcome { builds: false, protocols: vec![], diagnostics, error }); + } + }; + + // The package's own schemas come first, then its dependencies' and the + // standard library's, which are the authors' of those to act on. + let own: Vec = built["schemas"].as_array().unwrap().iter().map(|s| namespace_of(s["path"].as_str().unwrap())).collect(); + let schemas: Vec<_> = context.schema_contexts.iter().take(own.len()).collect(); + let found: BTreeSet = schemas.iter().map(|s| s.borrow().namespace_joined()).collect(); + if found != own.iter().cloned().collect() { + return Err(format!("the first {} schemas of the build are {found:?}, not the package's own {own:?}", own.len())); + } + + let mut protocols = vec![]; + let mut diagnostics = BTreeSet::new(); + for schema in schemas { + let schema = schema.borrow(); + for warning in schema.warnings.borrow().iter() { + diagnostics.insert((warning.code.id.to_string(), severity(warning.effective_severity()).to_string())); + } + for unit in schema.frozen_schema.borrow().as_ref().unwrap() { + let FrozenUnit::Protocol { name, parameters, .. } = unit else { continue }; + let given_up = unverified::frozen_set(parameters).to_vec(); + let acknowledged = given_up + .iter() + .filter_map(|g| acknowledgement(parameters, *g).map(|(scope, reason)| (*g, scope, reason))) + .collect(); + protocols.push((name.clone(), given_up, acknowledged)); + } + } + Ok(Outcome { builds: true, protocols, diagnostics, error: String::new() }) +} + +fn diagnostics_of(expect: &Value) -> BTreeSet { + expect["diagnostics"] + .as_array() + .unwrap() + .iter() + .map(|d| (d["code"].as_str().unwrap().to_string(), d["severity"].as_str().unwrap().to_string())) + .collect() +} + +fn names(set: impl IntoIterator) -> BTreeSet<&'static str> { + set.into_iter().map(Guarantee::name).collect() +} + +/// Every way `outcome` differs from what the case expects. +fn mismatches(case: &Value, outcome: &Outcome) -> Vec { + let expect = &case["expect"]; + let mut out = vec![]; + let builds = expect["builds"].as_bool().unwrap(); + if builds != outcome.builds { + let error = if outcome.builds { String::new() } else { format!(": {}", outcome.error) }; + out.push(format!("builds: expected {builds}, got {}{error}", outcome.builds)); + return out; + } + + let expected = diagnostics_of(expect); + if expected != outcome.diagnostics { + out.push(format!("diagnostics: expected {expected:?}, got {:?}", outcome.diagnostics)); + } + if !builds { + for text in expect["error_contains"].as_array().into_iter().flatten() { + let text = text.as_str().unwrap(); + if !outcome.error.contains(text) { + out.push(format!("error_contains: expected the error to contain {text:?}, got: {}", outcome.error)); + } + } + return out; + } + + let expected: Vec<&Value> = expect["protocols"].as_array().unwrap().iter().collect(); + let expected_names: BTreeSet<&str> = expected.iter().map(|p| p["name"].as_str().unwrap()).collect(); + let got_names: BTreeSet<&str> = outcome.protocols.iter().map(|(name, ..)| name.as_str()).collect(); + if expected_names != got_names || expected.len() != outcome.protocols.len() { + out.push(format!("protocols: expected {expected_names:?}, got {got_names:?}")); + } + for protocol in expected { + let name = protocol["name"].as_str().unwrap(); + let Some((_, given_up, acknowledged)) = outcome.protocols.iter().find(|(n, ..)| n == name) else { continue }; + let want: BTreeSet<&str> = protocol["given_up"].as_array().unwrap().iter().map(|g| g.as_str().unwrap()).collect(); + let got = names(given_up.iter().copied()); + if want != got { + out.push(format!("{name}: gives up: expected {want:?}, got {got:?}")); + } + for ack in protocol["acknowledged"].as_array().into_iter().flatten() { + let guarantee = ack["guarantee"].as_str().unwrap(); + let Some((_, scope, reason)) = acknowledged.iter().find(|(g, ..)| g.name() == guarantee) else { + out.push(format!("{name}: {guarantee}: expected an acknowledgement, got none")); + continue; + }; + let want_scope = ack["scope"].as_str().unwrap(); + if want_scope != *scope { + out.push(format!("{name}: {guarantee}: scope: expected {want_scope}, got {scope}")); + } + if let Some(want_reason) = ack["reason"].as_str() { + if want_reason != reason { + out.push(format!("{name}: {guarantee}: reason: expected {want_reason:?}, got {reason:?}")); + } + } + } + } + out +} + +#[test] +fn the_specifications_compiler_cases() { + let mut files: Vec = std::fs::read_dir(cases_dir()) + .unwrap() + .map(|entry| entry.unwrap().path()) + .filter(|path| path.extension().is_some_and(|e| e == "json")) + .collect(); + files.sort(); + let mut ids = BTreeSet::new(); + let mut run = 0; + let mut failures = vec![]; + for path in &files { + let group = path.file_stem().unwrap().to_str().unwrap(); + let text = std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display())); + let file: Value = serde_json::from_str(&text).unwrap(); + assert_eq!(file["group"], group, "{}", path.display()); + for case in file["cases"].as_array().unwrap() { + let id = case["id"].as_str().unwrap(); + assert!(id.starts_with(&format!("{group}/")), "{id} is in the wrong file: {group}.json"); + run += 1; + ids.insert(id.to_string()); + let found = match build(case) { + Ok(outcome) => mismatches(case, &outcome), + Err(harness) => vec![format!("the runner: {harness}")], + }; + match (CORE_DISAGREES.iter().find(|(known, _)| *known == id), found.is_empty()) { + (None, false) => failures.push(format!("{id}\n {}", found.join("\n "))), + (Some((_, rule)), false) => eprintln!("{id}: core is known to disagree ({rule}):\n {}", found.join("\n ")), + (Some((_, rule)), true) => failures.push(format!("{id}\n core agrees now: remove it from CORE_DISAGREES ({rule})")), + (None, true) => {} + } + } + } + for (id, _) in CORE_DISAGREES { + assert!(ids.contains(&id.to_string()), "CORE_DISAGREES has {id}, which is no case's"); + } + assert!(run > 0, "no cases ran"); + assert!(failures.is_empty(), "{} of {run} cases differ:\n\n{}", failures.len(), failures.join("\n\n")); +} diff --git a/core/tests/package/mod.rs b/core/tests/package/mod.rs index 303dc53..e786767 100644 --- a/core/tests/package/mod.rs +++ b/core/tests/package/mod.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "deps")] +mod compiler_cases; mod encodings; mod from_sources; mod handshake; diff --git a/core/tests/spec/REV b/core/tests/spec/REV index bb47add..d7dee73 100644 --- a/core/tests/spec/REV +++ b/core/tests/spec/REV @@ -1 +1 @@ -9a7142c395b2aefb7d4d77e9b36c74187c6f0199 +068500670debade6b004b85032924f945dbb0a2c diff --git a/core/tests/spec/cases/acceptance.json b/core/tests/spec/cases/acceptance.json new file mode 100644 index 0000000..3a31d6c --- /dev/null +++ b/core/tests/spec/cases/acceptance.json @@ -0,0 +1,270 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "acceptance", + "cases": [ + { + "id": "acceptance/not-accepted", + "description": "an unverified protocol of a dependency has to be accepted", + "packages": [ + { + "name": "billing", + "config": "congregation billing\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \"the 2009 gateway\"\nprotocol Billing {\n function charge();\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n billing = {\n path = \"../billing\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct A {\n x: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "billing" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "protocol `Billing` is unverified, giving up schema agreement and encoding agreement", + "the 2009 gateway" + ] + } + }, + { + "id": "acceptance/accepted", + "description": "accepted for exactly what it gives up, it builds", + "packages": [ + { + "name": "billing", + "config": "congregation billing\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \"the 2009 gateway\"\nprotocol Billing {\n function charge();\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n billing = {\n path = \"../billing\"\n accept_unverified = { Billing = [\"schema_agreement\", \"encoding_agreement\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct A {\n x: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "billing", + "accept_unverified": { + "Billing": [ + "schema_agreement", + "encoding_agreement" + ] + } + } + ] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "acceptance/accepted-for-less", + "description": "accepted for less than it gives up, it stops again", + "packages": [ + { + "name": "billing", + "config": "congregation billing\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \"the 2009 gateway\"\nprotocol Billing {\n function charge();\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n billing = {\n path = \"../billing\"\n accept_unverified = { Billing = [\"schema_agreement\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct A {\n x: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "billing", + "accept_unverified": { + "Billing": [ + "schema_agreement" + ] + } + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "protocol `Billing` now gives up schema agreement and encoding agreement", + "it was accepted for schema agreement" + ] + } + }, + { + "id": "acceptance/accepted-for-more", + "description": "accepted for more than it gives up, it stops too: the set has to match exactly", + "packages": [ + { + "name": "billing", + "config": "congregation billing\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \"the 2009 gateway\"\nprotocol Billing {\n function charge();\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n billing = {\n path = \"../billing\"\n accept_unverified = { Billing = [\"schema_agreement\", \"encoding_agreement\", \"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct A {\n x: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "billing", + "accept_unverified": { + "Billing": [ + "schema_agreement", + "encoding_agreement", + "bounded_size" + ] + } + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "protocol `Billing` now gives up schema agreement and encoding agreement" + ] + } + }, + { + "id": "acceptance/package-reasons-shown", + "description": "what the package said once is what the consumer is shown to accept", + "packages": [ + { + "name": "billing", + "config": "congregation billing\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway only speaks one encoding\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol Billing {\n function charge();\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n billing = {\n path = \"../billing\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct A {\n x: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "billing" + } + ] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "protocol `Billing` is unverified, giving up schema agreement and encoding agreement", + "schema agreement \"the gateway pins schemas by contract\"", + "encoding agreement \"the gateway only speaks one encoding\"" + ] + } + }, + { + "id": "acceptance/judged-by-its-own-package", + "description": "a dependency is judged by its own package's settings and default handshake, not the consumer's", + "packages": [ + { + "name": "billing", + "config": "congregation billing\nspecification_version = 1\nhandshake = \"none\"\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@unverified = \"the 2009 gateway\"\nprotocol Billing {\n function charge();\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "app", + "config": "congregation app\nspecification_version = 1\ndependencies = {\n billing = {\n path = \"../billing\"\n accept_unverified = { Billing = [\"schema_agreement\", \"encoding_agreement\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct A {\n x: u32\n}\n" + } + ], + "dependencies": [ + { + "name": "billing", + "accept_unverified": { + "Billing": [ + "schema_agreement", + "encoding_agreement" + ] + } + } + ] + } + ], + "build": "app", + "expect": { + "protocols": [], + "builds": true, + "diagnostics": [] + } + } + ] +} diff --git a/core/tests/spec/cases/bounded.json b/core/tests/spec/cases/bounded.json new file mode 100644 index 0000000..41da32b --- /dev/null +++ b/core/tests/spec/cases/bounded.json @@ -0,0 +1,376 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "bounded", + "cases": [ + { + "id": "bounded/string-unmarked", + "description": "a string without a maximum is an error where no marker gives bounded size up", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function put(s: string);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/list-unmarked", + "description": "a list without a maximum is an error too", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function put(xs: u8[]);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/bounded", + "description": "a string and a list with maximums give nothing up", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function put(s: char[max 64], xs: u8[max 16]);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [] + } + ], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "bounded/string-marked", + "description": "a marked protocol gives bounded_size up for a string without a maximum", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@unverified = \"the uploader streams whatever it's given\"\nprotocol P {\n function put(s: string);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the uploader streams whatever it's given" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] + } + }, + { + "id": "bounded/keyed-for-something-else", + "description": "a keyed marker that doesn't list bounded_size doesn't cover a string without a maximum", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@unverified = { version_honesty = \"not this\" }\nprotocol P {\n function put(s: string);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::missing-guarantee", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/recursion-unmarked", + "description": "a type that contains itself without @max_depth is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Node {\n kids: Node[max 4]\n}\n\nprotocol P {\n function f(n: Node);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded-depth", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/recursion-marked", + "description": "a marked protocol gives bounded_size up for a type that contains itself without @max_depth", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Node {\n kids: Node[max 4]\n}\n\n@unverified = \"trees are small in practice\"\nprotocol P {\n function f(n: Node);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "trees are small in practice" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] + } + }, + { + "id": "bounded/recursion-max-depth", + "description": "a type that contains itself under @max_depth gives nothing up", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@max_depth = 4\nstruct Node {\n kids: Node[max 4]\n}\n\nprotocol P {\n function f(n: Node);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [] + } + ], + "builds": true, + "diagnostics": [] + } + }, + { + "id": "bounded/other-schema-unmarked", + "description": "a type from another schema that holds a string without a maximum is unbounded where an unmarked protocol uses it", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: string\n}\n\n@unverified = \"the uploader streams whatever it's given\"\nprotocol Upload {\n function put(b: Blob);\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models::Blob\n\nprotocol Orders {\n function send(b: Blob);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "bounded/other-schema-marked", + "description": "a marked protocol using it gives bounded_size up, as the one that declares it does", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: string\n}\n\n@unverified = \"the uploader streams whatever it's given\"\nprotocol Upload {\n function put(b: Blob);\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models::Blob\n\n@unverified = \"orders carry the upload\"\nprotocol Orders {\n function send(b: Blob);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "Upload", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the uploader streams whatever it's given" + } + ] + }, + { + "name": "Orders", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "orders carry the upload" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] + } + }, + { + "id": "bounded/other-schema-bounded", + "description": "a type bounded where it is declared is bounded where it is used", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/models.ids", + "text": "struct Blob {\n data: char[max 64]\n}\n" + }, + { + "path": "src/api.ids", + "text": "use models::Blob\n\nprotocol Orders {\n function send(b: Blob);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "Orders", + "given_up": [] + } + ], + "builds": true, + "diagnostics": [] + } + } + ] +} diff --git a/core/tests/spec/cases/chain.json b/core/tests/spec/cases/chain.json new file mode 100644 index 0000000..6a36334 --- /dev/null +++ b/core/tests/spec/cases/chain.json @@ -0,0 +1,289 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "chain", + "cases": [ + { + "id": "chain/unmarked-is-unbounded", + "description": "a type that holds another package's unbounded value, two packages away, is unbounded where an unmarked protocol uses it", + "packages": [ + { + "name": "a", + "config": "congregation a\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n data: string\n}\n\n@unverified = \"the uploader streams whatever it's given\"\nprotocol Upload {\n function put(b: Blob);\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "b", + "config": "congregation b\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\ndependencies = {\n a = {\n path = \"../a\"\n accept_unverified = { Upload = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use a::api::Blob\n\nstruct Wrapper {\n blob: Blob\n}\n\n@unverified = \"wrapping uploads\"\nprotocol Wrap {\n function wrap(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "a", + "accept_unverified": { + "Upload": [ + "bounded_size" + ] + } + } + ] + }, + { + "name": "c", + "config": "congregation c\nspecification_version = 1\ndependencies = {\n b = {\n path = \"../b\"\n accept_unverified = { Wrap = [\"bounded_size\"] Upload = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use b::api::Wrapper\n\nprotocol Orders {\n function send(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "b", + "accept_unverified": { + "Wrap": [ + "bounded_size" + ], + "Upload": [ + "bounded_size" + ] + } + } + ] + } + ], + "build": "c", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + }, + { + "id": "chain/marked-gives-up", + "description": "a marked protocol using it gives bounded_size up, for its own consumers to accept", + "packages": [ + { + "name": "a", + "config": "congregation a\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n data: string\n}\n\n@unverified = \"the uploader streams whatever it's given\"\nprotocol Upload {\n function put(b: Blob);\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "b", + "config": "congregation b\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\ndependencies = {\n a = {\n path = \"../a\"\n accept_unverified = { Upload = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use a::api::Blob\n\nstruct Wrapper {\n blob: Blob\n}\n\n@unverified = \"wrapping uploads\"\nprotocol Wrap {\n function wrap(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "a", + "accept_unverified": { + "Upload": [ + "bounded_size" + ] + } + } + ] + }, + { + "name": "c", + "config": "congregation c\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\ndependencies = {\n b = {\n path = \"../b\"\n accept_unverified = { Wrap = [\"bounded_size\"] Upload = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use b::api::Wrapper\n\n@unverified = \"orders carry the upload\"\nprotocol Orders {\n function send(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "b", + "accept_unverified": { + "Wrap": [ + "bounded_size" + ], + "Upload": [ + "bounded_size" + ] + } + } + ] + } + ], + "build": "c", + "expect": { + "protocols": [ + { + "name": "Orders", + "given_up": [ + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "orders carry the upload" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] + } + }, + { + "id": "chain/acceptance-needs-every-link", + "description": "accepting b's protocol is not enough: a's, which b's package contains, is accepted too", + "packages": [ + { + "name": "a", + "config": "congregation a\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n data: string\n}\n\n@unverified = \"the uploader streams whatever it's given\"\nprotocol Upload {\n function put(b: Blob);\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "b", + "config": "congregation b\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\ndependencies = {\n a = {\n path = \"../a\"\n accept_unverified = { Upload = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use a::api::Blob\n\nstruct Wrapper {\n blob: Blob\n}\n\n@unverified = \"wrapping uploads\"\nprotocol Wrap {\n function wrap(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "a", + "accept_unverified": { + "Upload": [ + "bounded_size" + ] + } + } + ] + }, + { + "name": "c", + "config": "congregation c\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\ndependencies = {\n b = {\n path = \"../b\"\n accept_unverified = { Wrap = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use b::api::Wrapper\n\n@unverified = \"orders carry the upload\"\nprotocol Orders {\n function send(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "b", + "accept_unverified": { + "Wrap": [ + "bounded_size" + ] + } + } + ] + } + ], + "build": "c", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "protocol `Upload` is unverified, giving up bounded size" + ] + } + }, + { + "id": "chain/middle-doesnt-accept-the-first", + "description": "b's own build fails when it doesn't accept a's protocol, so building c does", + "packages": [ + { + "name": "a", + "config": "congregation a\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "struct Blob {\n data: string\n}\n\n@unverified = \"the uploader streams whatever it's given\"\nprotocol Upload {\n function put(b: Blob);\n}\n" + } + ], + "dependencies": [] + }, + { + "name": "b", + "config": "congregation b\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\ndependencies = {\n a = {\n path = \"../a\"\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use a::api::Blob\n\nstruct Wrapper {\n blob: Blob\n}\n\n@unverified = \"wrapping uploads\"\nprotocol Wrap {\n function wrap(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "a" + } + ] + }, + { + "name": "c", + "config": "congregation c\nspecification_version = 1\ndependencies = {\n b = {\n path = \"../b\"\n accept_unverified = { Wrap = [\"bounded_size\"] Upload = [\"bounded_size\"] }\n }\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "use b::api::Wrapper\n\nprotocol Orders {\n function send(w: Wrapper);\n}\n" + } + ], + "dependencies": [ + { + "name": "b", + "accept_unverified": { + "Wrap": [ + "bounded_size" + ], + "Upload": [ + "bounded_size" + ] + } + } + ] + } + ], + "build": "c", + "expect": { + "builds": false, + "diagnostics": [], + "error_contains": [ + "protocol `Upload` is unverified, giving up bounded size" + ] + } + } + ] +} diff --git a/core/tests/spec/cases/keyed.json b/core/tests/spec/cases/keyed.json new file mode 100644 index 0000000..42e1f4f --- /dev/null +++ b/core/tests/spec/cases/keyed.json @@ -0,0 +1,183 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "keyed", + "cases": [ + { + "id": "keyed/exact-set", + "description": "a reason for each guarantee given up, and no others", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = {\n schema_agreement = \"the gateway predates Comline\",\n encoding_agreement = \"the gateway only speaks one encoding\"\n}\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "protocol", + "reason": "the gateway predates Comline" + }, + { + "guarantee": "encoding_agreement", + "scope": "protocol", + "reason": "the gateway only speaks one encoding" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "keyed/unknown-guarantee", + "description": "a key that is no guarantee's id is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = {\n schema_agreement = \"the gateway predates Comline\",\n encoding_agreement = \"the gateway only speaks one encoding\",\n bounded_sise = \"a typo\"\n}\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::unknown-guarantee", + "severity": "error" + } + ] + } + }, + { + "id": "keyed/missing-guarantee", + "description": "a guarantee given up and not listed is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = { schema_agreement = \"the gateway predates Comline\" }\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::missing-guarantee", + "severity": "error" + } + ] + } + }, + { + "id": "keyed/not-given-up", + "description": "a guarantee listed and not given up is a warning, and not frozen", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = {\n schema_agreement = \"the gateway predates Comline\",\n encoding_agreement = \"the gateway only speaks one encoding\",\n version_honesty = \"just in case\"\n}\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::not-given-up", + "severity": "warning" + }, + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "keyed/duplicate-guarantee", + "description": "a guarantee listed twice is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = {\n schema_agreement = \"the gateway predates Comline\",\n encoding_agreement = \"the gateway only speaks one encoding\",\n schema_agreement = \"again\"\n}\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::duplicate-guarantee", + "severity": "error" + } + ] + } + } + ] +} diff --git a/core/tests/spec/cases/marker.json b/core/tests/spec/cases/marker.json new file mode 100644 index 0000000..5cbbe84 --- /dev/null +++ b/core/tests/spec/cases/marker.json @@ -0,0 +1,251 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "marker", + "cases": [ + { + "id": "marker/gate-off", + "description": "@unverified is refused where the package's settings don't allow it", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \"the gateway predates Comline\"\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "settings::forbidden", + "severity": "error" + } + ] + } + }, + { + "id": "marker/missing-marker", + "description": "a protocol with no handshake gives up two guarantees and has to say why", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::missing-marker", + "severity": "error" + } + ] + } + }, + { + "id": "marker/plain-marker", + "description": "one reason covers everything a protocol gives up, and it is frozen as the set", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \"the gateway predates Comline\"\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "protocol", + "reason": "the gateway predates Comline" + }, + { + "guarantee": "encoding_agreement", + "scope": "protocol", + "reason": "the gateway predates Comline" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "marker/package-handshake-unmarked", + "description": "the package's default handshake counts: a protocol that takes none has to say why", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::missing-marker", + "severity": "error" + } + ] + } + }, + { + "id": "marker/package-handshake-marked", + "description": "the marker covers what the package's default handshake gives up", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@unverified = \"legacy\"\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "protocol", + "reason": "legacy" + }, + { + "guarantee": "encoding_agreement", + "scope": "protocol", + "reason": "legacy" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "marker/missing-reason", + "description": "a marker with a blank reason is an error", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@handshake = \"none\"\n@unverified = \" \"\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::missing-reason", + "severity": "error" + } + ] + } + }, + { + "id": "marker/nothing-given-up", + "description": "a marker where nothing is given up is a warning, and freezes nothing", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@unverified = \"just in case\"\nprotocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::nothing-given-up", + "severity": "warning" + } + ] + } + } + ] +} diff --git a/core/tests/spec/cases/package.json b/core/tests/spec/cases/package.json new file mode 100644 index 0000000..2b8d112 --- /dev/null +++ b/core/tests/spec/cases/package.json @@ -0,0 +1,384 @@ +{ + "$schema": "../../specs/gen/compiler.schema.json", + "group": "package", + "cases": [ + { + "id": "package/keyed-covers-inherited", + "description": "the package says why for a protocol that takes the package's handshake", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + }, + { + "guarantee": "encoding_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "package/plain-covers-inherited", + "description": "the plain form covers every guarantee a package setting gives up", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = \"the gateway pins schemas by contract\"\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + }, + { + "guarantee": "encoding_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "package/own-handshake-not-covered", + "description": "a protocol with its own @handshake isn't covered by the package", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n\n@handshake = \"none\"\nprotocol Q {\n function g();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::missing-marker", + "severity": "error" + } + ] + } + }, + { + "id": "package/own-handshake-marked", + "description": "a protocol with its own @handshake says why itself; the package covers the other", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n\n@handshake = \"none\"\n@unverified = \"Q talks to the gateway directly\"\nprotocol Q {\n function g();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + }, + { + "guarantee": "encoding_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + } + ] + }, + { + "name": "Q", + "given_up": [ + "schema_agreement", + "encoding_agreement" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "protocol", + "reason": "Q talks to the gateway directly" + }, + { + "guarantee": "encoding_agreement", + "scope": "protocol", + "reason": "Q talks to the gateway directly" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + } + ] + } + }, + { + "id": "package/wrong-scope", + "description": "bounded_size can't be acknowledged at package scope", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nunverified = { bounded_size = \"the gateway pins schemas by contract\" }\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "unverified::wrong-scope", + "severity": "error" + } + ] + } + }, + { + "id": "package/not-given-up", + "description": "a guarantee the package lists and no protocol gives up through it is a warning", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::not-given-up", + "severity": "warning" + } + ] + } + }, + { + "id": "package/gate-off", + "description": "the package's unverified is held to the same gate as the marker", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function f();\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "settings::forbidden", + "severity": "error" + } + ] + } + }, + { + "id": "package/adds-bounded-size", + "description": "a marker says why for bounded_size, which the package can't; the package says the rest", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "@unverified = { bounded_size = \"the uploader streams whatever it's given\" }\nprotocol P {\n function put(s: string);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "protocols": [ + { + "name": "P", + "given_up": [ + "schema_agreement", + "encoding_agreement", + "bounded_size" + ], + "acknowledged": [ + { + "guarantee": "schema_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + }, + { + "guarantee": "encoding_agreement", + "scope": "package", + "reason": "the gateway pins schemas by contract" + }, + { + "guarantee": "bounded_size", + "scope": "protocol", + "reason": "the uploader streams whatever it's given" + } + ] + } + ], + "builds": true, + "diagnostics": [ + { + "code": "unverified::schema-agreement", + "severity": "warning" + }, + { + "code": "unverified::encoding-agreement", + "severity": "warning" + }, + { + "code": "unverified::bounded-size", + "severity": "warning" + } + ] + } + }, + { + "id": "package/bounded-size-not-covered", + "description": "the package covering the handshake doesn't cover an unbounded string", + "packages": [ + { + "name": "app", + "config": "congregation app\nspecification_version = 1\nhandshake = \"none\"\nunverified = {\n schema_agreement = \"the gateway pins schemas by contract\"\n encoding_agreement = \"the gateway pins schemas by contract\"\n}\nsettings = { annotations = { unverified = { allowed = true } } }\n", + "schemas": [ + { + "path": "src/api.ids", + "text": "protocol P {\n function put(s: string);\n}\n" + } + ], + "dependencies": [] + } + ], + "build": "app", + "expect": { + "builds": false, + "diagnostics": [ + { + "code": "bounds::unbounded", + "severity": "error" + } + ] + } + } + ] +} diff --git a/core/tests/spec/vendor.sh b/core/tests/spec/vendor.sh index a42518b..1f2a6ab 100755 --- a/core/tests/spec/vendor.sh +++ b/core/tests/spec/vendor.sh @@ -1,12 +1,14 @@ #!/usr/bin/env bash -# Vendors the specification's size vectors (vectors/sizes-.json) into -# tests/spec/, at the commit `comline-catalog` is pinned to in core/Cargo.toml: -# the vectors that hold the size rules, so they must be the rules' own. +# Vendors the specification's size vectors (vectors/sizes-.json) and +# compiler conformance cases (compiler/cases/.json) into tests/spec/, +# at the commit `comline-catalog` is pinned to in core/Cargo.toml: the +# vectors that hold the size rules, and the cases the compiler's rules about +# the guarantees the catalog names, so they must be the specification's own. # # vendor.sh # vendor (and pin the catalog to it by hand) # vendor.sh --check # fail if tests/spec/ differs from tests/spec/REV's # -# The spec leads: a size rule changes in specification first, and this +# The spec leads: a size rule or a case changes in specification first, and this # repository takes it by bumping the rev and re-vendoring. A test fails when # REV and Cargo.toml disagree. set -euo pipefail @@ -23,22 +25,26 @@ fi tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT git clone --quiet --no-checkout "$repo" "$tmp/specification" -mkdir -p "$tmp/vectors" +mkdir -p "$tmp/vectors" "$tmp/cases" for format in packed msgpack json; do git -C "$tmp/specification" show "$rev:vectors/sizes-$format.json" > "$tmp/vectors/sizes-$format.json" done +for case in $(git -C "$tmp/specification" ls-tree --name-only "$rev" compiler/cases/); do + git -C "$tmp/specification" show "$rev:$case" > "$tmp/cases/$(basename "$case")" +done if [[ "${1:-}" == "--check" ]]; then - if diff -r "$tmp/vectors" "$here/vectors"; then - echo "tests/spec/vectors match $repo@$rev" + if diff -r "$tmp/vectors" "$here/vectors" && diff -r "$tmp/cases" "$here/cases"; then + echo "tests/spec/vectors and tests/spec/cases match $repo@$rev" else - echo "tests/spec/vectors differ from $repo@$rev: re-vendor with vendor.sh " >&2 + echo "tests/spec/vectors or tests/spec/cases differ from $repo@$rev: re-vendor with vendor.sh " >&2 exit 1 fi exit 0 fi -rm -rf "$here/vectors" +rm -rf "$here/vectors" "$here/cases" mv "$tmp/vectors" "$here/vectors" +mv "$tmp/cases" "$here/cases" git -C "$tmp/specification" rev-parse "$rev^{commit}" > "$here/REV" echo "vendored $repo@$(cat "$here/REV")"