| @@ -1,21 +1,30 @@ |
| 1 | 1 | #!/usr/bin/env python3 |
| 2 | | -"""Ingest a single DMN-TCK literal-expression test into a feel-core fixture. |
| 2 | +"""Ingest a single DMN-TCK literal-expression or boxed-context test into a feel-core fixture. |
| 3 | 3 | |
| 4 | 4 | Source: https://github.com/dmn-tck/tck |
| 5 | 5 | |
| 6 | | -Scope: this is NOT a general DMN/XML harness. It handles exactly the "literal |
| 7 | | -expression" test form, and only emits fixture cases whose expression fits |
| 8 | | -feel-core's core-language slice: arithmetic, comparison, `between`/`in`, |
| 9 | | -`instance of` (built-in/Any/Null types and inline `list<>`/`context<>`/`function<>` |
| 10 | | -generics), three-valued `and`/`or`/`not`, `if/then/else`, `for … return`, |
| 11 | | -`some/every … satisfies`, context literals, and path access. Each case's |
| 12 | | -`<inputNode>` values are captured as a `context` object and bound during |
| 13 | | -evaluation, so expressions that read input variables are now in scope. See |
| 14 | | -`fits_slice_grammar` for the exact predicate. |
| 15 | | - |
| 16 | | -Anything outside the slice — built-in functions, temporal types, filters, or |
| 17 | | -free names we could not bind — is skipped (and reported), so we never produce |
| 18 | | -false negatives for expressions the engine cannot yet evaluate. |
| 6 | +Scope: this is NOT a general DMN/XML harness. It handles two decision forms: |
| 7 | + |
| 8 | +1. **Literal-expression** decisions (`<literalExpression><text>EXPR</text>`): |
| 9 | + each decision emits one fixture case whose expression is the bare FEEL text. |
| 10 | + |
| 11 | +2. **Boxed-context** decisions (`<decision><context><contextEntry>…</context>`): |
| 12 | + each decision emits one fixture case whose expression is the assembled FEEL |
| 13 | + context literal `{k1: e1, k2: e2, …}` and whose expected value is the |
| 14 | + structured `{key: scalar, …}` context. Every individual entry expression must |
| 15 | + pass `fits_slice_grammar`; if any entry is out-of-slice the whole decision is |
| 16 | + skipped. |
| 17 | + |
| 18 | +Both forms only emit cases whose expression(s) fit feel-core's core-language |
| 19 | +slice: arithmetic, comparison, `between`/`in`, `instance of`, three-valued |
| 20 | +`and`/`or`/`not`, `if/then/else`, `for … return`, `some/every … satisfies`, |
| 21 | +context literals, path access, and the full set of built-in functions. Each |
| 22 | +case's `<inputNode>` values are captured as a `context` object and bound during |
| 23 | +evaluation. See `fits_slice_grammar` for the exact predicate. |
| 24 | + |
| 25 | +Anything outside the slice — or free names we could not bind — is skipped (and |
| 26 | +reported), so we never produce false negatives for expressions the engine cannot |
| 27 | +yet evaluate. |
| 19 | 28 | |
| 20 | 29 | It also applies a *deviation registry*: a list of rules, each pairing a |
| 21 | 30 | predicate ("does this case match?") with a transform ("rewrite the expectation / |
| @@ -660,6 +669,18 @@ |
| 660 | 669 | "0021-singleton-list:001:decision4", |
| 661 | 670 | "0021-singleton-list:001:decision5", |
| 662 | 671 | "1131-feel-function-invocation:002:decision002", |
| 672 | + # 0074 range_006-011: these boxed-context decisions express range properties |
| 673 | + # on *opaque comparison-test values* (`(<10)`, `(<=10)`, `(>10)`, `(>=10)`, |
| 674 | + # `(=10)`) — ADR-32 `Value::UnaryTestVal`. feel-core's `member_access` does |
| 675 | + # not yet implement range properties for `UnaryTestVal` (it returns |
| 676 | + # `Value::Error` → null via the lenient view). The interval-range property |
| 677 | + # cases (range_001-005, `[1..10]` etc.) are correctly ingested. Adding |
| 678 | + # `UnaryTestVal` range-property support is a separate feel-core increment. |
| 679 | + "0074-feel-properties:range_006:range_006", |
| 680 | + "0074-feel-properties:range_007:range_007", |
| 681 | + "0074-feel-properties:range_009:range_009", |
| 682 | + "0074-feel-properties:range_010:range_010", |
| 683 | + "0074-feel-properties:range_011:range_011", |
| 663 | 684 | }) |
| 664 | 685 | |
| 665 | 686 | # Named-zone literals feel-core's eager `TimeZone::get` validation rejects in the |
| @@ -725,7 +746,8 @@ |
| 725 | 746 | Only decisions whose *direct* logic child is a `<literalExpression>` are |
| 726 | 747 | kept. Decisions backed by a `<relation>`, `<context>` or `<decisionTable>` |
| 727 | 748 | are skipped — descending into them would wrongly mine an inner expression |
| 728 | | - cell (e.g. a relation row value) as if it were the decision's expression.""" |
| 749 | + cell (e.g. a relation row value) as if it were the decision's expression. |
| 750 | + Boxed-context decisions are handled by `parse_context_decisions`.""" |
| 729 | 751 | root = ET.parse(dmn_path).getroot() |
| 730 | 752 | decisions: dict[str, str] = {} |
| 731 | 753 | for elem in root.iter(): |
| @@ -739,6 +761,45 @@ |
| 739 | 761 | if text_elem is not None and text_elem.text is not None: |
| 740 | 762 | decisions[name] = text_elem.text.strip() |
| 741 | 763 | return decisions |
| 764 | + |
| 765 | + |
| 766 | +def parse_context_decisions(dmn_path: Path) -> dict[str, list[tuple[str, str]]]: |
| 767 | + """Map decision name -> ordered (key, expression) list for boxed-context decisions. |
| 768 | + |
| 769 | + Only decisions whose direct logic child is a `<context>` are returned. Each |
| 770 | + `<contextEntry>` must have both a `<variable name="…">` and a |
| 771 | + `<literalExpression><text>…</text></literalExpression>`; decisions with any |
| 772 | + malformed or missing entry are silently skipped. The assembled FEEL context |
| 773 | + literal `{k1: e1, …}` is built by `extract_cases` after every entry |
| 774 | + expression passes `fits_slice_grammar`.""" |
| 775 | + root = ET.parse(dmn_path).getroot() |
| 776 | + result: dict[str, list[tuple[str, str]]] = {} |
| 777 | + for elem in root.iter(): |
| 778 | + if _local(elem.tag) != "decision": |
| 779 | + continue |
| 780 | + name = elem.get("name") |
| 781 | + ctx = _first_child(elem, "context") |
| 782 | + if name is None or ctx is None: |
| 783 | + continue |
| 784 | + entries: list[tuple[str, str]] = [] |
| 785 | + ok = True |
| 786 | + for entry in ctx: |
| 787 | + if _local(entry.tag) != "contextEntry": |
| 788 | + continue |
| 789 | + var = _first_child(entry, "variable") |
| 790 | + lit = _first_child(entry, "literalExpression") |
| 791 | + if var is None or lit is None: |
| 792 | + ok = False |
| 793 | + break |
| 794 | + key = var.get("name", "") |
| 795 | + text_elem = _first_child(lit, "text") |
| 796 | + if text_elem is None or text_elem.text is None: |
| 797 | + ok = False |
| 798 | + break |
| 799 | + entries.append((key, text_elem.text.strip())) |
| 800 | + if ok and entries: |
| 801 | + result[name] = entries |
| 802 | + return result |
| 742 | 803 | |
| 743 | 804 | |
| 744 | 805 | _XSI = "{http://www.w3.org/2001/XMLSchema-instance}" |
| @@ -866,6 +927,7 @@ |
| 866 | 927 | def extract_cases(dmn_path: Path, test_path: Path) -> tuple[list[Case], list[tuple[str, str]]]: |
| 867 | 928 | """Return (kept cases, skipped (id, reason) pairs).""" |
| 868 | 929 | decisions = parse_decisions(dmn_path) |
| 930 | + context_decisions = parse_context_decisions(dmn_path) |
| 869 | 931 | model_stem = dmn_path.stem |
| 870 | 932 | |
| 871 | 933 | root = ET.parse(test_path).getroot() |
| @@ -897,20 +959,38 @@ |
| 897 | 959 | if _local(result_node.tag) != "resultNode": |
| 898 | 960 | continue |
| 899 | 961 | name = result_node.get("name") |
| 900 | | - if name is None or name not in decisions: |
| 901 | | - continue |
| 902 | | - # NB: `errorResult="true"` is *not* skipped wholesale. Many such cases are |
| 903 | | - # genuine expression errors feel-core reproduces (a malformed regex, a bad |
| 904 | | - # argument → error-null, collapsed to null at the lenient boundary, which |
| 905 | | - # matches the expected nil) — valuable coverage. The few where the error |
| 906 | | - # comes from DMN *decision output-type* validation rather than the |
| 907 | | - # expression (e.g. `1+1` asserted to error against a non-number output |
| 908 | | - # type, as in 0082) are handled per-case / by not ingesting that suite. |
| 909 | | - expression = decisions[name] |
| 910 | | - case_id = f"{model_stem}:{tc_id}:{name}" |
| 911 | | - |
| 912 | | - if not fits_slice_grammar(expression, input_names): |
| 913 | | - skipped.append((case_id, f"outside slice grammar: {expression!r}")) |
| 962 | + if name is None: |
| 963 | + continue |
| 964 | + |
| 965 | + # Resolve the decision to an expression. Literal-expression decisions |
| 966 | + # emit one case per entry; boxed-context decisions assemble a FEEL |
| 967 | + # context literal `{k1: e1, …}` after checking each entry individually. |
| 968 | + if name in decisions: |
| 969 | + expression = decisions[name] |
| 970 | + case_id = f"{model_stem}:{tc_id}:{name}" |
| 971 | + # NB: `errorResult="true"` is *not* skipped wholesale. Many such cases |
| 972 | + # are genuine expression errors feel-core reproduces (a malformed regex, |
| 973 | + # a bad argument → error-null, collapsed to null at the lenient boundary, |
| 974 | + # which matches the expected nil) — valuable coverage. The few where the |
| 975 | + # error comes from DMN *decision output-type* validation rather than the |
| 976 | + # expression (e.g. `1+1` asserted to error against a non-number output |
| 977 | + # type, as in 0082) are handled per-case / by not ingesting that suite. |
| 978 | + if not fits_slice_grammar(expression, input_names): |
| 979 | + skipped.append((case_id, f"outside slice grammar: {expression!r}")) |
| 980 | + continue |
| 981 | + elif name in context_decisions: |
| 982 | + entries = context_decisions[name] |
| 983 | + case_id = f"{model_stem}:{tc_id}:{name}" |
| 984 | + skip_reason: Optional[str] = None |
| 985 | + for key, entry_expr in entries: |
| 986 | + if not fits_slice_grammar(entry_expr, input_names): |
| 987 | + skip_reason = f"context entry {key!r} outside slice: {entry_expr!r}" |
| 988 | + break |
| 989 | + if skip_reason: |
| 990 | + skipped.append((case_id, skip_reason)) |
| 991 | + continue |
| 992 | + expression = "{" + ", ".join(f"{k}: {e}" for k, e in entries) + "}" |
| 993 | + else: |
| 914 | 994 | continue |
| 915 | 995 | |
| 916 | 996 | if case_id in REGEX_DIALECT_SKIPS: |