pub fn parse_policy_block(
header_name: Option<&str>,
content: &str,
) -> Result<PolicyDef, ConfigError>Expand description
Parses a policy YAML block from a Markdown fence into a PolicyDef.
The function deserializes content as YAML into a PolicyConfig, applies name precedence
(the fence header_name is used when present; an explicit payload name conflicts with the
header; an absent name in both locations is an error), converts each policy rule into the
AST via parse_policy_rule, and returns a PolicyDef with the resolved name and rules.
§Errors
Returns a ConfigError::YamlParse if YAML deserialization fails, ConfigError::NameConflict
if both header and payload provide different names, ConfigError::MissingName if no name is
supplied, or any ConfigError produced while parsing policy rules.
§Examples
use cellstate_pipeline::parse_policy_block;
let yaml = r#"
name: example-policy
rules:
- trigger: task_end
actions:
- type: summarize
target: "summary-target"
"#;
let def = parse_policy_block(None, yaml).unwrap();
assert_eq!(def.name, "example-policy");
assert_eq!(def.rules.len(), 1);