From eb7bde775735e09c32c323f58ab4a47256198e26 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 13:23:34 -0600 Subject: [PATCH] fix(id): reject duplicate cli.commands and padded list entries in app manifests parse_app_manifest now applies one consistent list-entry rule to interfaces.cli.commands and capabilities.request: entries must be non-blank with no leading/trailing whitespace and no repeats. Whitespace padding can neither evade the duplicate gate nor be stored verbatim. Rejections name the field. Fixes #4085. --- pkgs/id/src/app_manifest.rs | 97 +++++++++++++++++++++++++++---------- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/pkgs/id/src/app_manifest.rs b/pkgs/id/src/app_manifest.rs index 935ce93e0a..8eec7d39e1 100644 --- a/pkgs/id/src/app_manifest.rs +++ b/pkgs/id/src/app_manifest.rs @@ -133,33 +133,10 @@ pub fn parse_app_manifest(source: &str, folder_name: &str) -> Result) -> AppDiscovery { discovery } +/// One consistent list-entry rule for manifest string lists +/// (`interfaces.cli.commands`, `capabilities.request`): every entry must be +/// non-blank with no leading or trailing whitespace, and no entry may +/// repeat. Duplicate and blank comparisons use the trimmed form, so a +/// whitespace-padded entry can neither evade the duplicate gate nor be +/// stored verbatim — padded entries are rejected, not silently trimmed. +/// Rejections name the field: like the #4082 duplicate gate this extends, a +/// repeated or padded entry is an authoring mistake the gate should name +/// rather than silently absorb. +fn ensure_distinct_entries(entries: &[String], field: &str) -> Result<()> { + let mut seen = std::collections::HashSet::new(); + for entry in entries { + let trimmed = entry.trim(); + ensure!( + !trimmed.is_empty(), + "{field} must not contain empty entries" + ); + ensure!( + entry.as_str() == trimmed, + "{field} must not contain entries with leading or trailing whitespace: {entry:?}" + ); + ensure!( + seen.insert(trimmed.to_owned()), + "{field} must not contain duplicates" + ); + } + Ok(()) +} + fn is_kebab_id(id: &str) -> bool { !id.is_empty() && !id.starts_with('-') @@ -401,6 +407,47 @@ commands = ["play"] assert!(parse_app_manifest(&blank_command, "tic-tac-toe").is_err()); } + #[test] + fn rejects_duplicate_and_padded_cli_commands() { + // Exact duplicate commands are rejected, naming the field. + let duplicate = + CLI_MANIFEST.replace("commands = [\"play\"]", "commands = [\"play\", \"play\"]"); + let error = parse_app_manifest(&duplicate, "tic-tac-toe").unwrap_err(); + assert!( + error.to_string().contains("interfaces.cli.commands"), + "duplicate error names the field: {error:#}" + ); + // A whitespace-padded entry cannot evade the duplicate gate. + let padded_duplicate = + CLI_MANIFEST.replace("commands = [\"play\"]", "commands = [\"play\", \" play \"]"); + let error = parse_app_manifest(&padded_duplicate, "tic-tac-toe").unwrap_err(); + assert!( + error.to_string().contains("interfaces.cli.commands"), + "padded-duplicate error names the field: {error:#}" + ); + // A lone padded entry is rejected rather than stored verbatim. + let padded = CLI_MANIFEST.replace("commands = [\"play\"]", "commands = [\" play \"]"); + assert!(parse_app_manifest(&padded, "tic-tac-toe").is_err()); + } + + #[test] + fn rejects_padded_capability_requests() { + // A padded duplicate cannot evade the #4082 duplicate gate. + let padded_duplicate = + format!("{MANIFEST}\n[capabilities]\nrequest = [\"store.read\", \" store.read \"]\n"); + let error = parse_app_manifest(&padded_duplicate, "tic-tac-toe").unwrap_err(); + assert!( + error.to_string().contains("capabilities.request"), + "padded-duplicate error names the field: {error:#}" + ); + // A lone padded entry is rejected rather than stored untrimmed. + let padded = format!("{MANIFEST}\n[capabilities]\nrequest = [\" store.read \"]\n"); + assert!(parse_app_manifest(&padded, "tic-tac-toe").is_err()); + // The unpadded baseline still parses. + let valid = format!("{MANIFEST}\n[capabilities]\nrequest = [\"store.read\"]\n"); + assert!(parse_app_manifest(&valid, "tic-tac-toe").is_ok()); + } + #[test] fn rejects_blank_and_duplicate_capability_requests() { // Duplicate rule: duplicates are REJECTED, not deduplicated — a