feat: asked-field envelope, standalone form components, branched forms

This commit is contained in:
Jonas Miederer 2026-09-28 14:07:09 +02:00
parent 0d43b0e8fb
commit f27be044b4
26 changed files with 3651 additions and 104 deletions

View file

@ -347,3 +347,64 @@ def test_no_markers_no_allof():
schema = parser.extract_form_schema(doc)["json_schema"]
assert "allOf" not in schema
assert set(schema["properties"]) == {"a"}
def test_custom_component_form_display_match():
"""User-built * Form components parse without a kirche base class."""
doc = _doc(
_field("mitarbeiter_name", "StrInput", info="Vor- und Nachname"),
_dropdown("rolle", ["Assistenz", "Pfarrer:in"]),
node_type="CustomComponent",
display="Mitarbeiter Einstellen Form",
)
schema = parser.extract_form_schema(doc)
assert "fallback" not in schema
props = schema["json_schema"]["properties"]
assert set(props) == {"mitarbeiter_name", "rolle"}
assert props["rolle"]["enum"] == ["Assistenz", "Pfarrer:in"]
assert props["mitarbeiter_name"]["description"] == "Vor- und Nachname"
def test_custom_component_non_form_falls_back():
doc = _doc(
_field("payload", "StrInput"),
node_type="CustomComponent",
display="Rule Check",
)
assert parser.extract_form_schema(doc)["fallback"] == "textarea"
def test_real_mitarbeiter_file_parses():
path = Path(__file__).parent.parent / "flows" / "mitarbeiter_einstellen.json"
doc = json.loads(path.read_text(encoding="utf-8"))
schema = parser.extract_form_schema(doc)
assert "fallback" not in schema
props = schema["json_schema"]["properties"]
assert set(props) == {"rolle", "mitarbeiter_name", "geburtsdatum"}
assert schema["json_schema"]["required"] == ["rolle", "mitarbeiter_name"]
# Einstufung is branched (visible only for Pfarrer:in).
assert len(schema["json_schema"]["allOf"]) == 1
rule = schema["json_schema"]["allOf"][0]
assert rule["if"]["properties"] == {"rolle": {"const": "Pfarrer:in"}}
assert set(rule["then"]["properties"]) == {"einstufung"}
def test_schema_field_names_covers_branches():
doc = _doc(
_dropdown("a", ["x", "y"]),
_dropdown("b", ["p", "q"], info="[visible_if a=x]"),
_field("c", "IntInput", info="[visible_if b=p]"),
)
cached = parser.extract_form_schema(doc)
assert parser.schema_field_names(cached) == ["a", "b", "c"]
plain = parser.extract_form_schema(
{
"data": {
"nodes": [{"data": {"type": "ChatInput", "node": {"template": {}}}}],
"edges": [],
}
}
)
assert parser.schema_field_names(plain) == []
assert parser.schema_field_names({}) == []
assert parser.schema_field_names({"json_schema": None}) == []