Validate templated actions against the page pattern
resolve_question returns a clone with a concrete id, so is_dynamic() on it was always false and every templated action failed lint. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
243b6a5704
commit
7bc59a65e0
+27
-6
@@ -1119,13 +1119,18 @@ pub fn validate_questions(
|
|||||||
a
|
a
|
||||||
};
|
};
|
||||||
let _ = probe;
|
let _ = probe;
|
||||||
match resolve_question(questions, &filled) {
|
// Match the pattern itself: resolve_question would
|
||||||
Some(target) if target.is_dynamic() => continue,
|
// hand back a clone whose id is already concrete.
|
||||||
_ => anyhow::bail!(
|
let lands = questions
|
||||||
"question {:?} alternative {:?}: templated action {:?} must land on a dynamic page ([name].yaml)",
|
.values()
|
||||||
question.id, alternative.name, action
|
.any(|q| q.is_dynamic() && path_matches(&q.id, &filled).is_some());
|
||||||
),
|
if lands {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
anyhow::bail!(
|
||||||
|
"question {:?} alternative {:?}: templated action {:?} must land on a dynamic page ([name].yaml)",
|
||||||
|
question.id, alternative.name, action
|
||||||
|
);
|
||||||
}
|
}
|
||||||
match questions.get(action) {
|
match questions.get(action) {
|
||||||
None => anyhow::bail!(
|
None => anyhow::bail!(
|
||||||
@@ -2025,6 +2030,22 @@ alternatives:
|
|||||||
assert_eq!(render_inline_markdown("[mail](mailto:bl@uhhm.no)"), "<a href=\"mailto:bl@uhhm.no\">mail</a>");
|
assert_eq!(render_inline_markdown("[mail](mailto:bl@uhhm.no)"), "<a href=\"mailto:bl@uhhm.no\">mail</a>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn templated_action_validates_against_the_dynamic_page() {
|
||||||
|
let landing: Question = serde_yaml::from_str(
|
||||||
|
"id: /\nname: L\nalternatives:\n - name: A\n action: /shape/{curve.key}\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let place: Question = serde_yaml::from_str("id: /shape/[key]\nname: P\n").unwrap();
|
||||||
|
let mut qs = std::collections::HashMap::new();
|
||||||
|
qs.insert(landing.id.clone(), landing.clone());
|
||||||
|
qs.insert(place.id.clone(), place);
|
||||||
|
validate_questions(&qs, &Default::default()).unwrap();
|
||||||
|
let mut only_landing = std::collections::HashMap::new();
|
||||||
|
only_landing.insert(landing.id.clone(), landing);
|
||||||
|
assert!(validate_questions(&only_landing, &Default::default()).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn action_templates_from_responses() {
|
fn action_templates_from_responses() {
|
||||||
let r = serde_json::json!({"curve": {"key": "20aa98", "points": [[0,0]]}, "n": 3});
|
let r = serde_json::json!({"curve": {"key": "20aa98", "points": [[0,0]]}, "n": 3});
|
||||||
|
|||||||
Reference in New Issue
Block a user