From 7c8649a3ffbf32f6468718da096fbf48f96b04f5 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Sun, 25 Oct 2026 06:24:51 +0800 Subject: [PATCH 1/2] generate: the package's wire format; default_framing moved to config.idp - Each generated version gets its own `wire.format`: the working tree's config, or the config a built version was stored with. - `default_framing` in comline.toml is an error that hands back the `wire = { framing = ... }` line for config.idp. - `comline build` checks the declared `wire.format` against each declared target, as it does the schemas' features. - The async-unused warning names the cases left: lockstep framings. - `comline new` writes a commented `wire` line with the defaults. - The end-to-end drivers serve through the package's `serve`/`connect`. - Pins core 2ba38df, generation dfd3bdb, comline-rust 5927244, comline-typescript 52c004f. --- Cargo.lock | 10 +-- Cargo.toml | 8 +-- src/commands/generate.rs | 22 +++++-- src/commands/new.rs | 4 +- src/gen_config.rs | 128 +++++++++++++-------------------------- src/history.rs | 19 ++++++ src/lang_targets.rs | 12 ++-- tests/cli/end_to_end.rs | 48 +++++++-------- tests/cli/generate.rs | 112 ++++++++++++++++++++-------------- 9 files changed, 185 insertions(+), 178 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d330b42..bdca4cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,7 +399,7 @@ dependencies = [ [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=9b101080133da8f26747c1322dd8959e6cd973ff#9b101080133da8f26747c1322dd8959e6cd973ff" +source = "git+https://github.com/ComlineProject/generation?rev=dfd3bdbc9933ac87e880efa86455f8da84a05120#dfd3bdbc9933ac87e880efa86455f8da84a05120" dependencies = [ "comline-core", "eyre", @@ -409,7 +409,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=562084f595a8f529210f0169c4e3f6855cfdd8c3#562084f595a8f529210f0169c4e3f6855cfdd8c3" +source = "git+https://github.com/ComlineProject/comline-rust?rev=59272442945f71b8f2b338a2147ef1c8aa52fc50#59272442945f71b8f2b338a2147ef1c8aa52fc50" dependencies = [ "comline-codegen", "comline-core", @@ -419,7 +419,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=a5a8800dd1c3d245ae53e7862b4ee218f36eadfd#a5a8800dd1c3d245ae53e7862b4ee218f36eadfd" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=52c004f0f8b835fe5412444d41cd927ada00aec9#52c004f0f8b835fe5412444d41cd927ada00aec9" dependencies = [ "comline-codegen", "comline-core", @@ -429,7 +429,7 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=a5d6f8597c8c2f4ac44ae9feabfdfbb4bb671e82#a5d6f8597c8c2f4ac44ae9feabfdfbb4bb671e82" +source = "git+https://github.com/ComlineProject/core?rev=2ba38df6f16759aae83f1b295621691d84e8c332#2ba38df6f16759aae83f1b295621691d84e8c332" dependencies = [ "ariadne", "blake3", @@ -456,7 +456,7 @@ dependencies = [ [[package]] name = "comline-core-stdlib" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=a5d6f8597c8c2f4ac44ae9feabfdfbb4bb671e82#a5d6f8597c8c2f4ac44ae9feabfdfbb4bb671e82" +source = "git+https://github.com/ComlineProject/core?rev=2ba38df6f16759aae83f1b295621691d84e8c332#2ba38df6f16759aae83f1b295621691d84e8c332" [[package]] name = "concolor" diff --git a/Cargo.toml b/Cargo.toml index 963b409..0dcb71a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,15 +32,15 @@ eyre = "0.6.8" # needs real I/O (git fetch, filesystem), so it's off by default for # `comline-core`'s wasm32 consumers (the playground editor, the language # server); the CLI is the one consumer that actually runs `comline build`. -comline-core = { git = "https://github.com/ComlineProject/core", rev = "a5d6f8597c8c2f4ac44ae9feabfdfbb4bb671e82", features = ["deps"] } +comline-core = { git = "https://github.com/ComlineProject/core", rev = "2ba38df6f16759aae83f1b295621691d84e8c332", features = ["deps"] } # All three pinned to revs that agree on one `comline-codegen`, and bumped # together: comline-rust and comline-typescript's codegen crates consume # `comline-codegen`'s types, so the rev below must be byte-identical to the # one *they* pin - Cargo only unifies a git dependency across identical rev # strings, and two copies of `GenRequest` are two incompatible types. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "9b101080133da8f26747c1322dd8959e6cd973ff" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "562084f595a8f529210f0169c4e3f6855cfdd8c3", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "a5a8800dd1c3d245ae53e7862b4ee218f36eadfd", optional = true } +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "dfd3bdbc9933ac87e880efa86455f8da84a05120" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "59272442945f71b8f2b338a2147ef1c8aa52fc50", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "52c004f0f8b835fe5412444d41cd927ada00aec9", optional = true } [features] # Which language generators are compiled in. Drop one to shed its whole diff --git a/src/commands/generate.rs b/src/commands/generate.rs index 6d7224d..5433390 100644 --- a/src/commands/generate.rs +++ b/src/commands/generate.rs @@ -14,7 +14,7 @@ use std::path::{Path, PathBuf}; use comline_codegen::{features, GenRequest, Mode, PackageMeta, Registry, Resolved, Unresolved}; use comline_core::package::build::{self, cas::ObjectStore}; -use comline_core::package::config::ir::frozen::FrozenUnit as ConfigUnit; +use comline_core::package::config::ir::frozen::{self, FrozenUnit as ConfigUnit}; use comline_core::schema::idl::constants::SCHEMA_EXTENSION; use comline_core::schema::ir::frozen::unit::{schema_namespace_as_path, FrozenUnit}; use miette::{miette, IntoDiagnostic, Result, WrapErr}; @@ -60,6 +60,9 @@ pub fn run( struct GenVersion { package_version: String, schemas: Vec<(String, Vec)>, // (namespace path, frozen units) + /// The version's own `wire.format`: a built version keeps the format it + /// was built with. + wire_format: String, } fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bool) -> Result<()> { @@ -179,7 +182,7 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo } let (generator, ext) = (resolved.generator.generate, resolved.generator.ext); - let versions = expand_versions(&t.versions, work_dir, &live_schemas)?; + let versions = expand_versions(&t.versions, work_dir, &live_schemas, config_units)?; if mode == Mode::Lib && versions.len() > 1 { return Err(miette!( "target `{}`: `lib` mode does not support multiple package versions yet", @@ -221,7 +224,7 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo }, }, lang_version: t.lang_version.clone(), - default_framing: t.default_framing.clone(), + wire_format: gv.wire_format.clone(), external_std: t.external_std, async_api: t.async_api, validate_on_decode: t.validate_on_decode, @@ -336,6 +339,7 @@ fn expand_versions( spec: &VersionSpec, work_dir: &Path, live: &[(String, Vec)], + live_config: &[ConfigUnit], ) -> Result> { match spec { VersionSpec::Latest => { @@ -346,6 +350,7 @@ fn expand_versions( Ok(vec![GenVersion { package_version, schemas: live.to_vec(), + wire_format: frozen::wire_format(live_config).to_string(), }]) } VersionSpec::All => { @@ -391,14 +396,19 @@ fn gen_version_from_commit( (ns, units) }) .collect(); + let config = history::load_config(store, commit)?; Ok(GenVersion { package_version: version.to_owned(), schemas, + wire_format: frozen::wire_format(&config).to_string(), }) } /// `async = true` changes only protocols on a connection; with none, the /// output is the same as without it, which looks like the setting did nothing. +/// Every protocol is on one by default, so that's a package whose protocols +/// are all lockstep: on the `datagram` framing, or on JSON-RPC with none of +/// them client-provided. fn warn_async_unused(language: &str, request: &GenRequest) { if !request.async_api { return; @@ -409,9 +419,9 @@ fn warn_async_unused(language: &str, request: &GenRequest) { } ui::warn(format!( "`{language}`: `async = true`, but no protocol runs on a connection, so the output \ - is the same as without it - a protocol is on one with `@provider = Client` or \ - `Multiple`, a `datagram@2` framing, or JSON-RPC once any of the package's JSON-RPC \ - protocols is client-provided" + is the same as without it - every protocol here is lockstep: on the `datagram` \ + framing (the default, `datagram@2`, is a connection), or on JSON-RPC with none of \ + the package's JSON-RPC protocols client-provided" )); } diff --git a/src/commands/new.rs b/src/commands/new.rs index cc6b67a..4406f0b 100644 --- a/src/commands/new.rs +++ b/src/commands/new.rs @@ -45,7 +45,6 @@ const COMLINE_TOML: &str = "\ # mode = \"code\" # code (loose source) | lib (a buildable package); dylib not built yet # external_std = false # reference `comline_std` rather than inlining std; defaults on in `lib` # package_versions = \"latest\" # latest | all | [\"0.3.0\", \"0.4.0\"] -# default_framing = \"jsonrpc\" # wire framing for protocols with no `@framing` (else datagram) # validate_on_decode = \"off\" # run `@validators` while decoding: off | collect | first # async = false # protocols on a connection get async handlers and senders # @@ -137,6 +136,9 @@ code_generation = {{ {language} = {{}} }} }} + +// The wire both ends speak; these are the defaults. +// wire = {{ format = \"packed@1\" framing = \"datagram@2\" }} " ) } diff --git a/src/gen_config.rs b/src/gen_config.rs index 5b6bae1..b8db029 100644 --- a/src/gen_config.rs +++ b/src/gen_config.rs @@ -15,7 +15,6 @@ use comline_codegen::validation::ValidateOnDecode; use comline_codegen::versions::LangVersion; use comline_core::schema::idl::annotations; use comline_core::utils::templating::recurse_render; -use comline_core::utils::text::closest; use miette::{miette, IntoDiagnostic, Result, WrapErr}; use serde::{Deserialize, Serialize}; @@ -105,10 +104,8 @@ pub struct Generate { pub mode: Option, /// Version selection shared by every target unless overridden. pub package_versions: Option, - /// Fallback wire framing for protocols that do not pick one with `@framing`, - /// shared by every target unless overridden. One of `@framing`'s accepted - /// spellings (`"jsonrpc"`, `"datagram"`, …), folded onto its canonical - /// form; an unknown one is an error. + /// Moved to config.idp's `wire = { framing = "..." }`: the framing is part + /// of the schema, which both ends must agree on. Read only to say so. pub default_framing: Option, /// `true`: reference `comline_std` as its own crate instead of inlining /// it, shared by every target unless overridden. Only a generator that @@ -221,8 +218,6 @@ pub struct ResolvedTarget { pub layout: String, pub mode: String, pub versions: VersionSpec, - /// Fallback framing handed to the generator; `None` ⇒ its built-in default. - pub default_framing: Option, /// `lib` mode only — see [`Target::flatten`]. pub flatten: bool, /// See [`Generate::external_std`]. @@ -304,6 +299,12 @@ pub fn resolve( work_dir: &Path, ov: &Overrides, ) -> Result> { + let moved = std::iter::once(&cfg.generate.default_framing) + .chain(cfg.generate.targets.iter().map(|t| &t.default_framing)); + if let Some(written) = moved.flatten().next() { + return Err(moved_default_framing(written)); + } + let declares = |language: &str| { declared .iter() @@ -527,16 +528,6 @@ pub fn resolve( .or_else(|| cfg.generate.package_versions.clone()) .unwrap_or_default(); - // `[[target]]` wins over `[generate]`; `None` at both ⇒ the generator's - // built-in default. No flag / env override — schema-shaping config, not - // a per-run knob. - let default_framing = t - .default_framing - .as_deref() - .or(cfg.generate.default_framing.as_deref()) - .map(|written| canonical_framing(written, &t.language)) - .transpose()?; - resolved.push(ResolvedTarget { language: t.language.clone(), lang_version, @@ -544,7 +535,6 @@ pub fn resolve( layout, mode, versions, - default_framing, flatten: t.flatten, external_std, validate_on_decode, @@ -555,27 +545,16 @@ pub fn resolve( Ok(resolved) } -/// Fold a `default_framing` onto the canonical spelling `@framing` uses, the -/// same table core checks `@framing` against. An unknown name is an error: -/// each generator falls back to datagram for a name it doesn't recognise, so -/// a typo would otherwise generate the wrong framing and only surface as a -/// refused handshake. -fn canonical_framing(written: &str, language: &str) -> Result { - if let Some(canonical) = annotations::canonical_value("framing", written) { - return Ok(canonical.to_string()); - } - let spellings = annotations::value_spellings("framing"); - let hint = closest(written, spellings.iter().copied()) - .map(|s| format!(" - did you mean `{s}`?")) - .unwrap_or_default(); - Err(miette!( - "`default_framing = \"{written}\"` for target `{language}` - expected one of {}{hint}", - spellings - .iter() - .map(|n| format!("`{n}`")) - .collect::>() - .join(", ") - )) +/// `default_framing` left `comline.toml`: the framing is part of the schema, +/// which both ends of a connection must agree on, so the package declares it. +fn moved_default_framing(written: &str) -> miette::Report { + let framing = annotations::canonical_value("framing", written).unwrap_or(written); + miette!( + "`default_framing` moved from {FILE_NAME} to config.idp\n \ + help: drop it here, and declare the package's framing in config.idp:\n \ + wire = {{ framing = \"{framing}\" }}\n \ + Protocols with no `@framing` default to `datagram@2` without it." + ) } #[cfg(test)] @@ -745,29 +724,6 @@ mod tests { assert_eq!(resolved[0].out, Path::new("/x/here")); } - #[test] - fn default_framing_section_reaches_a_declared_target() { - let cfg = parse("[generate]\ndefault_framing = \"jsonrpc\"\n"); - let declared = [DeclaredLang { - language: "rust".into(), - lang_version: "1.80".into(), - }]; - let resolved = resolve(&cfg, &declared, Path::new("/x"), &Overrides::default()).unwrap(); - assert_eq!(resolved[0].default_framing.as_deref(), Some("jsonrpc")); - } - - #[test] - fn target_default_framing_wins_over_section() { - let cfg = parse( - "[generate]\ndefault_framing = \"jsonrpc\"\n\n\ - [[generate.target]]\nlanguage = \"rust\"\nlang_version = \"1.85.0\"\n\ - default_framing = \"datagram\"\n", - ); - let declared = []; - let resolved = resolve(&cfg, &declared, Path::new("/x"), &Overrides::default()).unwrap(); - assert_eq!(resolved[0].default_framing.as_deref(), Some("datagram")); - } - /// `lib` writes the package manifest, so the generator can add /// `comline_std` to it; `code` emits loose files with nowhere to put a /// dependency, so inlining stays the honest default there. @@ -850,17 +806,6 @@ mod tests { assert!(message.contains("never lower it"), "{message}"); } - #[test] - fn default_framing_absent_is_none() { - let cfg = parse("[generate]\n"); - let declared = [DeclaredLang { - language: "rust".into(), - lang_version: "1.80".into(), - }]; - let resolved = resolve(&cfg, &declared, Path::new("/x"), &Overrides::default()).unwrap(); - assert_eq!(resolved[0].default_framing, None); - } - #[test] fn flatten_defaults_to_false_and_is_target_only() { let cfg = parse( @@ -990,26 +935,37 @@ mod tests { } #[test] - fn default_framing_is_folded_onto_its_canonical_spelling() { - let cfg = parse( - "[generate]\ndefault_framing = \"json-rpc\"\n\n\ - [[generate.target]]\nlanguage = \"rust\"\nlang_version = \"1.85.0\"\n", + fn default_framing_says_it_moved_to_config_idp() { + let cfg = parse("[generate]\ndefault_framing = \"json-rpc\"\n"); + let declared = [DeclaredLang { + language: "rust".into(), + lang_version: "1.80".into(), + }]; + let error = resolve(&cfg, &declared, Path::new("/x"), &Overrides::default()).unwrap_err(); + let message = error.to_string(); + assert!( + message.contains("moved from comline.toml to config.idp"), + "{message}" + ); + // The hint is ready to paste, in the canonical spelling. + assert!( + message.contains("wire = { framing = \"jsonrpc\" }"), + "{message}" ); - let resolved = resolve(&cfg, &[], Path::new("/x"), &Overrides::default()).unwrap(); - assert_eq!(resolved[0].default_framing.as_deref(), Some("jsonrpc")); } #[test] - fn an_unknown_default_framing_names_the_accepted_values_and_a_near_miss() { + fn a_target_default_framing_says_it_moved_too() { let cfg = parse( - "[generate]\ndefault_framing = \"jsonrcp\"\n\n\ - [[generate.target]]\nlanguage = \"rust\"\nlang_version = \"1.85.0\"\n", + "[[generate.target]]\nlanguage = \"rust\"\nlang_version = \"1.85.0\"\n\ + default_framing = \"datagram\"\n", ); let error = resolve(&cfg, &[], Path::new("/x"), &Overrides::default()).unwrap_err(); - assert_eq!( - error.to_string(), - "`default_framing = \"jsonrcp\"` for target `rust` - expected one of `jsonrpc`, \ - `datagram`, `datagram@2` - did you mean `jsonrpc`?" + assert!( + error + .to_string() + .contains("wire = { framing = \"datagram\" }"), + "{error}" ); } diff --git a/src/history.rs b/src/history.rs index 0159f8c..908e544 100644 --- a/src/history.rs +++ b/src/history.rs @@ -8,6 +8,8 @@ use std::path::Path; use comline_core::package::build::cas::objects::{Commit, EntryMode, Tree}; use comline_core::package::build::cas::storage::Hash; use comline_core::package::build::cas::{refs, ObjectStore}; +use comline_core::package::config::ir::frozen::cas::blob::read_config; +use comline_core::package::config::ir::frozen::FrozenUnit as ConfigUnit; use comline_core::schema::ir::frozen::cas::blob::load_schema_from_tree; use comline_core::schema::ir::frozen::unit::FrozenUnit; use miette::Result; @@ -78,6 +80,23 @@ pub fn resolve<'a>(history: &'a [Entry], spec: &str) -> Result<&'a Commit> { )) } +/// The package config `commit` was built with; empty for a commit made +/// before config was stored. +pub fn load_config(store: &ObjectStore, commit: &Commit) -> Result> { + let root_bytes = store + .read(&commit.tree) + .map_err(|e| miette::miette!("failed to read root tree: {e:#}"))?; + let root = + Tree::from_bytes(&root_bytes).map_err(|e| miette::miette!("corrupt root tree: {e:#}"))?; + root.entries + .iter() + .find(|e| e.name == "config" && e.mode == EntryMode::Blob) + .map(|e| read_config(store, &e.hash)) + .transpose() + .map(Option::unwrap_or_default) + .map_err(|e| miette::miette!("failed to read the package config: {e:#}")) +} + /// Load every local schema's frozen units from a commit's root tree, in tree /// order. Vendored dependencies (`dep_` trees) aren't this package's /// schemas and are skipped. diff --git a/src/lang_targets.rs b/src/lang_targets.rs index b61391a..f47e6ff 100644 --- a/src/lang_targets.rs +++ b/src/lang_targets.rs @@ -23,7 +23,7 @@ use comline_codegen::versions::LangVersion; use comline_codegen::{Registry, Resolved, Unresolved}; use comline_core::diagnostics::{Diagnostic, DiagnosticCode}; use comline_core::package::config::ir::context::ProjectContext; -use comline_core::package::config::ir::frozen::FrozenUnit as ConfigUnit; +use comline_core::package::config::ir::frozen::{self, FrozenUnit as ConfigUnit}; use comline_core::schema::ir::compiler::settings::severity::resolve_diagnostic_overrides; use comline_core::schema::ir::frozen::unit::FrozenUnit; use comline_core::settings::effective::package_settings; @@ -201,8 +201,12 @@ pub fn check_declared(context: &ProjectContext, registry: &Registry) -> eyre::Re } }; // Options a consumer picks in `comline.toml` aren't the package's - // promise, so only what the schemas themselves use is checked. - if let Some(refusal) = unsupported(&d.language, &resolved, &schemas, &Options::default()) { + // promise, so only what the schemas and config.idp use is checked. + let options = Options { + wire_format: Some(frozen::wire_format(config).to_string()), + ..Options::default() + }; + if let Some(refusal) = unsupported(&d.language, &resolved, &schemas, &options) { problems.push(format!("`{}#{}`: {refusal}", d.language, d.lang_version)); } match unverified(context, &d.language, &resolved) { @@ -214,7 +218,7 @@ pub fn check_declared(context: &ProjectContext, registry: &Registry) -> eyre::Re // JSON-RPC protocols on one connection whose bare method names a side // couldn't tell apart: no generator can emit them. - for clash in comline_codegen::connections::bare_name_clashes(&schemas, None) { + for clash in comline_codegen::connections::bare_name_clashes(&schemas) { problems.push(format!("every target: {clash}")); } diff --git a/tests/cli/end_to_end.rs b/tests/cli/end_to_end.rs index 57f70ff..0da4a09 100644 --- a/tests/cli/end_to_end.rs +++ b/tests/cli/end_to_end.rs @@ -1,7 +1,8 @@ //! The whole pipeline, for real: a `.comline` schema with a `protocol` → //! `comline generate --mode lib` → the emitted crate is compiled against //! `comline-runtime` and a hand-written driver runs a client ⇆ provider -//! round-trip over an in-memory transport (a request/response call, a raised +//! round-trip over an in-memory transport, through the package's `serve` and +//! `connect` (a request/response call, a raised //! typed error, the *second* of two declared errors, a provider fault, a //! one-way notify). //! @@ -18,11 +19,9 @@ const DRIVER: &str = r#" use std::sync::{Arc, Mutex}; use std::thread; -use chat_e2e::chat::{ - Chat, ChatClient, ChatDispatcher, ChatSendError, Message, Rejected, TooLong, -}; -use comline_runtime::contract::{CallError, Fault, RuntimeError}; -use comline_runtime::format::MsgPack; +use chat_e2e::chat::{Chat, ChatSendError, ChatSender, Message, Rejected, TooLong}; +use chat_e2e::{connect, serve, Services}; +use comline_runtime::contract::{CallError, Fault, Peer, RuntimeError}; use comline_runtime::transport::duplex; struct Svc { @@ -30,7 +29,7 @@ struct Svc { } impl Chat for Svc { - fn send(&self, text: &str) -> Result> { + fn send(&self, _peer: &mut impl Peer, text: &str) -> Result> { if text.is_empty() { // A declared error: `From for Fault` means `?`/`.into()` // works, but spell it out here so the test pins the shape. @@ -49,7 +48,7 @@ impl Chat for Svc { } Ok(Message { body: format!("echo: {text}"), seq: 1 }) } - fn note(&self, text: &str) { + fn note(&self, _peer: &mut impl Peer, text: &str) { self.notes.lock().unwrap().push(text.to_string()); } } @@ -60,17 +59,16 @@ fn client_and_provider_over_duplex() { let notes = Arc::new(Mutex::new(Vec::new())); let notes_for_svc = notes.clone(); - // Provider: the generated `serve` helper runs the connection handshake - // (IR_HASH + format and framing names) before serving. + // Provider: the package's `serve` runs the connection handshake + // (the connection hash + format and framing names), then serves every + // protocol in `Services`, over the package format (`packed@1`). let provider = thread::spawn(move || { - let mut provider_side = provider_side; - ChatDispatcher(Svc { notes: notes_for_svc }) - .serve(&mut provider_side, MsgPack) - .unwrap(); + serve(provider_side, Services { chat: Svc { notes: notes_for_svc } }).unwrap(); }); - // Client: the generated `connect` helper does the matching handshake. - let mut client = ChatClient::connect(client_side, MsgPack).expect("handshake"); + // Client: the package's `connect` does the matching handshake. + let mut conn = connect(client_side).expect("handshake"); + let mut client = ChatSender::new(&mut conn); assert_eq!(client.send("hi").unwrap().body, "echo: hi"); @@ -108,7 +106,7 @@ fn client_and_provider_over_duplex() { client.note("saved").unwrap(); // one-way - drop(client); + drop(conn); provider.join().unwrap(); assert_eq!(&*notes.lock().unwrap(), &["saved".to_string()]); @@ -157,16 +155,16 @@ fn a_generated_protocol_crate_runs_a_real_round_trip() { const VALIDATED_DRIVER: &str = r#" use std::thread; -use comline_runtime::contract::{CallError, Fault, RuntimeError}; -use comline_runtime::format::MsgPack; +use comline_runtime::contract::{CallError, Fault, Peer, RuntimeError}; use comline_runtime::transport::duplex; use comline_runtime::validation::Validate; -use validated_e2e::accounts::{Account, Accounts, AccountsClient, AccountsDispatcher, AccountsRenameError}; +use validated_e2e::accounts::{Account, Accounts, AccountsRenameError, AccountsSender}; +use validated_e2e::{connect, serve, Services}; struct Svc; impl Accounts for Svc { - fn rename(&self, to: String) -> Result> { + fn rename(&self, _peer: &mut impl Peer, to: String) -> Result> { Ok(Account { handle: to, nickname: None, friends: vec![] }) } } @@ -194,10 +192,10 @@ fn std_validators_run_through_an_alias() { fn a_call_with_arguments_failing_their_checks_is_refused() { let (client_side, provider_side) = duplex(); let provider = thread::spawn(move || { - let mut provider_side = provider_side; - AccountsDispatcher(Svc).serve(&mut provider_side, MsgPack).unwrap(); + serve(provider_side, Services { accounts: Svc }).unwrap(); }); - let mut client = AccountsClient::connect(client_side, MsgPack).expect("handshake"); + let mut conn = connect(client_side).expect("handshake"); + let mut client = AccountsSender::new(&mut conn); assert_eq!(client.rename("ada".into()).unwrap().handle, "ada"); match client.rename("x".into()).unwrap_err() { @@ -207,7 +205,7 @@ fn a_call_with_arguments_failing_their_checks_is_refused() { // and the connection survives it assert_eq!(client.rename("bob".into()).unwrap().handle, "bob"); - drop(client); + drop(conn); provider.join().unwrap(); } "#; diff --git a/tests/cli/generate.rs b/tests/cli/generate.rs index 848d5ec..fc3dbe5 100644 --- a/tests/cli/generate.rs +++ b/tests/cli/generate.rs @@ -189,15 +189,18 @@ fn rejects_an_unconfigured_target() { // -------- lib mode -------- +/// Appends `line` to the project's `config.idp`. +fn add_to_config(project: &std::path::Path, line: &str) { + let path = project.join("config.idp"); + let config = fs::read_to_string(&path).unwrap(); + fs::write(&path, format!("{config}\n{line}\n")).unwrap(); +} + #[test] -fn comline_toml_default_framing_reaches_the_rust_generator() { +fn config_idp_wire_framing_reaches_the_rust_generator() { let temp = tempfile::tempdir().unwrap(); let project = copy_fixture("chat_project", temp.path()); - fs::write( - project.join("comline.toml"), - "[generate]\ndefault_framing = \"jsonrpc\"\n", - ) - .unwrap(); + add_to_config(&project, "wire = { framing = \"jsonrpc\" }"); comline_cmd() .current_dir(&project) @@ -206,17 +209,20 @@ fn comline_toml_default_framing_reaches_the_rust_generator() { .success(); // `protocol Chat` has no `@framing` of its own, so it picks up the - // package default: the JSON-RPC stack, not the datagram one. + // package's: the JSON-RPC stack, not the datagram one. let chat = fs::read_to_string(project.join("generated/rust/chat.rs")).unwrap(); - assert!(chat.contains("comline_runtime::framing::JsonRpcFraming")); - assert!(chat.contains("Client::connect_with_framing")); - assert!(!chat.contains("Client::connect(transport, format, IR_HASH)")); + assert!( + chat.contains("comline_runtime::framing::JsonRpcFraming"), + "{chat}" + ); + assert!(chat.contains("Client::connect_with_framing"), "{chat}"); } #[test] -fn without_comline_toml_a_protocol_stays_on_datagram_framing() { +fn config_idp_wire_format_reaches_the_rust_generator() { let temp = tempfile::tempdir().unwrap(); let project = copy_fixture("chat_project", temp.path()); + add_to_config(&project, "wire = { format = \"json@1\" }"); comline_cmd() .current_dir(&project) @@ -225,35 +231,57 @@ fn without_comline_toml_a_protocol_stays_on_datagram_framing() { .success(); let chat = fs::read_to_string(project.join("generated/rust/chat.rs")).unwrap(); - assert!(chat.contains("Client::connect(transport, format, IR_HASH)")); - assert!(!chat.contains("JsonRpcFraming")); + assert!( + chat.contains("pub type Format = comline_runtime::format::Json;"), + "{chat}" + ); } #[test] -fn lib_mode_emits_a_crate() { +fn without_a_wire_key_a_protocol_is_on_a_packed_connection() { let temp = tempfile::tempdir().unwrap(); - let project = fixture_project(temp.path()); + let project = copy_fixture("chat_project", temp.path()); comline_cmd() .current_dir(&project) - .args(["generate", "--target", "rust", "--mode", "lib"]) + .args(["generate", "--target", "rust"]) .assert() .success(); - let crate_dir = project.join("generated/rust"); - let cargo = fs::read_to_string(crate_dir.join("Cargo.toml")).unwrap(); - assert!(cargo.contains("name = \"simple_project\"")); - assert!(cargo.contains("edition = \"2024\"")); - assert!(cargo.contains("serde = { version = \"1\"")); + let chat = fs::read_to_string(project.join("generated/rust/chat.rs")).unwrap(); + assert!( + chat.contains("pub type Format = comline_runtime::format::Packed;"), + "{chat}" + ); + assert!( + chat.contains("pub struct ChatDispatcher(pub S);"), + "{chat}" + ); + assert!(!chat.contains("JsonRpcFraming"), "{chat}"); + // The package's `Services` and `serve`, beside the schemas. + let connection = fs::read_to_string(project.join("generated/rust/connection.rs")).unwrap(); + assert!(connection.contains("pub struct Services<"), "{connection}"); +} - let lib = fs::read_to_string(crate_dir.join("src/lib.rs")).unwrap(); - assert!(lib.contains("pub mod api;")); - assert!(lib.contains("pub mod other;")); +#[test] +fn comline_toml_default_framing_says_it_moved() { + let temp = tempfile::tempdir().unwrap(); + let project = copy_fixture("chat_project", temp.path()); + fs::write( + project.join("comline.toml"), + "[generate]\ndefault_framing = \"jsonrpc\"\n", + ) + .unwrap(); - assert!(crate_dir.join("src/api.rs").exists()); - assert!(crate_dir.join("src/other.rs").exists()); - // no bare files at the target root - assert!(!crate_dir.join("api.rs").exists()); + comline_cmd() + .current_dir(&project) + .args(["generate", "--target", "rust"]) + .assert() + .failure() + .stderr(predicate::str::contains( + "`default_framing` moved from comline.toml to config.idp", + )) + .stderr(predicate::str::contains("wire = { framing = \"jsonrpc\" }")); } #[test] @@ -790,13 +818,7 @@ fn async_generates_connection_protocols_for_the_async_driver() { "protocol Link {\n function send(n: u32) -> u32;\n}\n", ) .unwrap(); - // On a connection by the package default rather than `@framing`, which - // settings forbid by default. - fs::write( - project.join("comline.toml"), - "[generate]\ndefault_framing = \"datagram@2\"\n", - ) - .unwrap(); + // On a connection by default. let generate = |project: &std::path::Path| { comline_cmd() .current_dir(project) @@ -813,11 +835,7 @@ fn async_generates_connection_protocols_for_the_async_driver() { ); assert!(!blocking.contains("Async"), "{blocking}"); - fs::write( - project.join("comline.toml"), - "[generate]\ndefault_framing = \"datagram@2\"\nasync = true\n", - ) - .unwrap(); + fs::write(project.join("comline.toml"), "[generate]\nasync = true\n").unwrap(); let asynchronous = generate(&project); assert!( asynchronous.contains("pub struct LinkAsyncDispatcher(pub S);"), @@ -834,7 +852,7 @@ fn async_generates_connection_protocols_for_the_async_driver() { } /// `async = true` with no protocol on a connection changes nothing, so -/// generate says so; with one, it doesn't. +/// generate says so; with one (the default), it doesn't. #[test] fn async_without_a_connection_protocol_warns() { let temp = tempfile::tempdir().unwrap(); @@ -845,8 +863,11 @@ fn async_without_a_connection_protocol_warns() { ) .unwrap(); let warning = "`async = true`, but no protocol runs on a connection"; - fs::write(project.join("comline.toml"), "[generate]\nasync = true\n").unwrap(); + let config = fs::read_to_string(project.join("config.idp")).unwrap(); + + // Every protocol lockstep: nothing for `async` to change. + add_to_config(&project, "wire = { framing = \"datagram\" }"); comline_cmd() .current_dir(&project) .args(["generate", "--target", "rust"]) @@ -854,11 +875,8 @@ fn async_without_a_connection_protocol_warns() { .success() .stderr(predicate::str::contains(warning)); - fs::write( - project.join("comline.toml"), - "[generate]\ndefault_framing = \"datagram@2\"\nasync = true\n", - ) - .unwrap(); + // The default: on a connection. + fs::write(project.join("config.idp"), config).unwrap(); comline_cmd() .current_dir(&project) .args(["generate", "--target", "rust"]) From 7b106fe66aabbf1cb48489faad448a13449b26a5 Mon Sep 17 00:00:00 2001 From: Kinflou Date: Sun, 25 Oct 2026 06:36:13 +0800 Subject: [PATCH 2/2] deps: pin the generators to their merges (comline-rust#75, comline-typescript#71) --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdca4cb..cdaf594 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -409,7 +409,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=59272442945f71b8f2b338a2147ef1c8aa52fc50#59272442945f71b8f2b338a2147ef1c8aa52fc50" +source = "git+https://github.com/ComlineProject/comline-rust?rev=e1a290f154387d9e32cb2d35b0ed522ef9f88d52#e1a290f154387d9e32cb2d35b0ed522ef9f88d52" dependencies = [ "comline-codegen", "comline-core", @@ -419,7 +419,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=52c004f0f8b835fe5412444d41cd927ada00aec9#52c004f0f8b835fe5412444d41cd927ada00aec9" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=72da96a6f55d4598355973d0fccc33480af00c64#72da96a6f55d4598355973d0fccc33480af00c64" dependencies = [ "comline-codegen", "comline-core", diff --git a/Cargo.toml b/Cargo.toml index 0dcb71a..caf9967 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,8 +39,8 @@ comline-core = { git = "https://github.com/ComlineProject/core", rev = "2ba38df6 # one *they* pin - Cargo only unifies a git dependency across identical rev # strings, and two copies of `GenRequest` are two incompatible types. comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "dfd3bdbc9933ac87e880efa86455f8da84a05120" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "59272442945f71b8f2b338a2147ef1c8aa52fc50", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "52c004f0f8b835fe5412444d41cd927ada00aec9", optional = true } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "e1a290f154387d9e32cb2d35b0ed522ef9f88d52", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "72da96a6f55d4598355973d0fccc33480af00c64", optional = true } [features] # Which language generators are compiled in. Drop one to shed its whole