fix: better hardening of tool calls
This commit is contained in:
10
src/a2ui.rs
10
src/a2ui.rs
@@ -1179,7 +1179,10 @@ fn validate_enum(
|
||||
.as_str()
|
||||
.ok_or_else(|| format!("component `{id}` {field} must be a string"))?;
|
||||
if !allowed.contains(&value) {
|
||||
return Err(format!("component `{id}` has invalid {field} `{value}`"));
|
||||
return Err(format!(
|
||||
"component `{id}` has invalid {field} `{value}`; expected one of: {}",
|
||||
allowed.join(", ")
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -2245,7 +2248,10 @@ mod tests {
|
||||
json!({"version":VERSION,"createSurface":{"surfaceId":"s","catalogId":CATALOG_ID}}),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(apply(&mut store, json!({"version":VERSION,"updateComponents":{"surfaceId":"s","components":[{"id":"root","component":"Text","text":"x","variant":"h1"}]}})).is_err());
|
||||
assert_eq!(
|
||||
apply(&mut store, json!({"version":VERSION,"updateComponents":{"surfaceId":"s","components":[{"id":"root","component":"Text","text":"x","variant":"h1"}]}})).unwrap_err(),
|
||||
"component `root` has invalid variant `h1`; expected one of: caption, body"
|
||||
);
|
||||
assert!(apply(&mut store, json!({"version":VERSION,"updateComponents":{"surfaceId":"s","components":[{"id":"root","component":"Text","text":{"call":"formatDate","args":{"value":"2026-01-01T00:00:00Z"}}}]}})).is_err());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user