From 30eb9a31ec7e4cf0ef683c86edb28ffc6fa3d54e Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 1 Dec 2026 00:52:20 +0000 Subject: enstate: --pack warns of an entry from text with placeholders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Text loses its trailing line breaks, which a key or a certificate rarely should; a whole-value source (cmd:…, file:…, or a table) takes an entry byte-exact. The warning says so, and the entry goes in as asked. --- src/main.rs | 4 +++- src/pack.rs | 15 ++++++++++++--- tests/receptor.rs | 4 +++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8d3830b..5ae94e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -229,7 +229,9 @@ fn run() -> Result { if command == "pack" { let out = out.context("--pack needs --out DIR")?; let schema = settings.schema.as_deref().map(Schema::load).transpose()?; - enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())?; + for warning in enstate::pack::pack(path.as_deref().unwrap(), &out, schema.as_ref())? { + eprintln!("enstate: warning: {warning}"); + } return Ok(ExitCode::SUCCESS); } let store = Store::new( diff --git a/src/pack.rs b/src/pack.rs index 67603d6..dda4f6a 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -78,8 +78,9 @@ impl SourceList { } /// Packs the source list at `path` into a submission in `out` (which must not exist, -/// or be empty), checked against `schema` if one is given. -pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> { +/// or be empty), checked against `schema` if one is given. Returns warnings: an +/// entry whose source is text with placeholders loses its trailing line breaks. +pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result> { let list = SourceList::load(path)?; let dir = path .parent() @@ -104,10 +105,18 @@ pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> { let mut entries: BTreeMap> = BTreeMap::new(); let mut records: BTreeMap> = BTreeMap::new(); let mut specs = Vec::new(); + let mut warnings = Vec::new(); for (address, item) in &items { if let Some(source) = &item.source { let importer = importer(source, &dir, address.key.is_none()) .with_context(|| format!("item {address}"))?; + if address.key.is_none() && importer.is_interpolation() { + warnings.push(format!( + "item {address}: its source is text with placeholders, which loses \ + trailing line breaks; for the entry as it is, a whole-value source \ + (cmd:…, file:…, or a table) takes it byte-exact" + )); + } let imported = importer .fetch() .with_context(|| format!("item {address}: {}", importer.describe()))?; @@ -169,7 +178,7 @@ pub fn pack(path: &Path, out: &Path, schema: Option<&Schema>) -> Result<()> { content::write_file(&out.join(submission::MANIFEST), &manifest_bytes, 0o600)?; // What was written is a submission the receptor reads. submission::Submission::load(out)?; - Ok(()) + Ok(warnings) } /// The importer `source` describes, in `dir`: raw for an entry, JSON for a record. diff --git a/tests/receptor.rs b/tests/receptor.rs index 8bbadf4..56a1666 100644 --- a/tests/receptor.rs +++ b/tests/receptor.rs @@ -435,7 +435,9 @@ fn pack_from_sources() { let path = host.root.join("sources.json"); std::fs::write(&path, list.to_string()).unwrap(); let out = host.root.join("packed"); - enstate::pack::pack(&path, &out, Some(&schema.0)).unwrap(); + let warnings = enstate::pack::pack(&path, &out, Some(&schema.0)).unwrap(); + assert_eq!(warnings.len(), 1, "{warnings:?}"); + assert!(warnings[0].starts_with("item secrets/extra: its source is text with placeholders")); // Byte-exact entries: trailing line breaks stay. assert_eq!( std::fs::read(out.join("channels/secrets/a.key")).unwrap(), -- cgit v1.3.1