| 169 | } |
| 170 | |
| 171 | fn lift_ac(d: &Directive, id_base: &str, n: usize) -> Result<AcceptanceCriterion> { |
| 172 | // Child ids are namespaced under the intent's stable id base (its ULID for |
| 173 | // intents created via `atomic intent new`) so they are globally unique and |
| 174 | // do not inherit the human key's `::`/`-` separators. |
| 175 | let local = |
| 176 | d.id.clone() |
| 177 | .unwrap_or_else(|| format!("{}-ac-{n}", slug(id_base))); |
| 178 | // Required verification kinds: a comma-separated `requiredKinds` attr |
| 179 | // (whitespace-tolerant, empty entries dropped). Absent ⇒ empty, so an AC |
| 180 | // that declares none is unchanged. |
| 181 | let required_kinds = d |
| 182 | .attr("requiredKinds") |
| 183 | .map(|v| { |
| 184 | v.split(',') |
| 185 | .map(str::trim) |
| 186 | .filter(|s| !s.is_empty()) |
| 187 | .map(str::to_string) |
| 188 | .collect::<Vec<_>>() |
| 189 | }) |
| 190 | .unwrap_or_default(); |
| 191 | // Nested `::verification{...}` leaf children become typed records. Absent ⇒ |
| 192 | // empty, so an AC without verifications serializes exactly as before. |
| 193 | let verifications = d |
| 194 | .children |
| 195 | .iter() |
| 196 | .filter(|c| c.name == "verification") |
| 197 | .map(lift_verification) |
| 198 | .collect(); |
| 199 | Ok(AcceptanceCriterion { |
| 200 | type_: NodeType::AcceptanceCriterion.as_str().to_string(), |
| 201 | id: as_urn("ac", &local), |
| 202 | text: d.body.clone(), |
| 203 | ac_status: d.attr("status").unwrap_or("open").to_string(), |
| 204 | verified_by: d.attr("verifiedBy").map(str::to_string), |
| 205 | evidence: d.attr("evidence").map(str::to_string), |
| 206 | verifications, |
| 207 | required_kinds, |
| 208 | }) |
| 209 | } |
| 210 | |
| 211 | /// Lift a nested `::verification{kind= outcome= scope= observedAtMerkle= ref= observation=}` |
| 212 | /// leaf into a typed [`VerificationRecord`]. Attributes map straight across; |