some more ops

could we make subgraphs as ops or patterns like this?
This commit is contained in:
lda
2026-05-29 22:19:55 +07:00 Verified
parent c3ce74dd7b
commit 4211d1b7fa
7 changed files with 225 additions and 1 deletions
+78
View File
@@ -8,6 +8,10 @@ from wf_authoring import (
coalesce,
constant,
default_if_none,
concat,
extract_field,
filter_items,
filter_items_present,
first_item,
first_item_maybe,
first_item_or_none,
@@ -303,6 +307,80 @@ def test_rename_fields_remaps_existing_keys() -> None:
}
def test_filter_items_selects_mapping_items_by_exact_match() -> None:
registry = build_registry(filter_items)
result = registry["authoring.filter_items"](
{
"items": [
{"type": "text", "text": "a"},
{"type": "image", "url": "img://1"},
{"type": "text", "text": "b"},
],
"key": "type",
"value": "text",
},
RuntimeContext(current_node_id="filter_items"),
)
output = result["output"]
assert result["outcome"] == "ok"
assert output["items"][0]["text"] == "a"
assert output["items"][1]["text"] == "b"
def test_filter_items_present_selects_mapping_items_containing_key() -> None:
registry = build_registry(filter_items_present)
result = registry["authoring.filter_items_present"](
{
"items": [
{"text": "a"},
{"url": "img://1"},
{"text": None},
],
"key": "text",
},
RuntimeContext(current_node_id="filter_items_present"),
)
output = result["output"]
assert result["outcome"] == "ok"
assert output["items"][0]["text"] == "a"
assert output["items"][1]["text"] is None
def test_extract_field_returns_existing_field_values() -> None:
registry = build_registry(extract_field)
result = registry["authoring.extract_field"](
{
"items": [
{"text": "a"},
{"url": "img://1"},
{"text": "b"},
],
"field": "text",
},
RuntimeContext(current_node_id="extract_field"),
)
assert result["outcome"] == "ok"
assert result["output"]["values"] == ["a", "b"]
def test_concat_joins_strings_with_separator() -> None:
registry = build_registry(concat)
result = registry["authoring.concat"](
{"items": ["a", "b", "c"], "separator": "\n"},
RuntimeContext(current_node_id="concat"),
)
assert result["outcome"] == "ok"
assert result["output"]["text"] == "a\nb\nc"
def test_truthy_routes_truthy_and_falsey_outcomes() -> None:
registry = build_registry(truthy)
ctx = RuntimeContext(current_node_id="truthy")
+4
View File
@@ -237,6 +237,10 @@ def test_wf_std_source_contains_authoring_ops() -> None:
"wf.std.last_item_or_none",
"wf.std.length",
"wf.std.is_empty",
"wf.std.filter_items",
"wf.std.filter_items_present",
"wf.std.extract_field",
"wf.std.concat",
}
assert set(specs) == expected