From 062e4897981a10937402d968db9f917daf7746a1 Mon Sep 17 00:00:00 2001 From: Dan Wolfson Date: Sun, 8 Nov 2026 22:46:30 +0000 Subject: [PATCH] feat(spec-resolver): warn when a spec carried a dropped analytic_binders key RS-W2-4 PR-0, owner decision O1-a (2026-11-08). The PR-B shim drops a non-empty analytic_binders key with a DeprecationWarning, but nothing recorded it, so callers could not tell a spec had carried it. - The shim (now a wrap validator) notes the dropped parameter names on the ActionParameter as the private attribute _dropped_binders. - resolve() adds a warning with the stable prefix "deprecated: analytic_binders ignored (binders for: )" (spec_resolver.BINDERS_DEPRECATED_PREFIX), for loaded specs and for plain dict specs alike, on both ResolvedSpec and Unrunnable. - Empty keys stay silent; no registered spec carries the warning. Signed-off-by: Dan Wolfson --- pyegeria/view/_output_format_models.py | 21 ++++-- pyegeria/view/spec_resolver.py | 17 +++++ ...test_rs_w2_4_binder_deprecation_warning.py | 65 +++++++++++++++++++ 3 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 tests/micro-tests/test_rs_w2_4_binder_deprecation_warning.py diff --git a/pyegeria/view/_output_format_models.py b/pyegeria/view/_output_format_models.py index ee861a09..8c44dacf 100644 --- a/pyegeria/view/_output_format_models.py +++ b/pyegeria/view/_output_format_models.py @@ -69,7 +69,7 @@ import warnings from pathlib import Path from typing import Dict, List, Optional, Union, Any -from pydantic import BaseModel, Field, field_validator, model_validator +from pydantic import BaseModel, Field, PrivateAttr, field_validator, model_validator from loguru import logger __all__ = [ 'Column', @@ -262,28 +262,35 @@ class ActionParameter(BaseModel): analytic_function: Optional[str] = None analytic_spec_params: Dict[str, Any] = Field(default_factory=dict) - @model_validator(mode="before") + _dropped_binders: List[str] = PrivateAttr(default_factory=list) + + @model_validator(mode="wrap") @classmethod - def _drop_deprecated_binders(cls, values): + def _drop_deprecated_binders(cls, values, handler): """Accept and ignore the removed `analytic_binders` key for one release (RS-W2-3 PR-B). An empty mapping (what older generated specs serialise) is dropped silently. A non-empty one is dropped with a DeprecationWarning and a log warning naming the parameters: the - routine must declare them as `inputs` instead, or its call will lack them. + routine must declare them as `inputs` instead, or its call will lack them. The names are + kept on the model (`_dropped_binders`) so the spec resolver can report them as a warning. """ + names: List[str] = [] if isinstance(values, dict) and "analytic_binders" in values: values = dict(values) binders = values.pop("analytic_binders") if binders: - names = ", ".join(sorted(binders)) if isinstance(binders, dict) else repr(binders) + names = sorted(binders) if isinstance(binders, dict) else [repr(binders)] message = ( - f"analytic_binders is no longer supported and is ignored (binders for: {names}). " + f"analytic_binders is no longer supported and is ignored (binders for: {', '.join(names)}). " f"Declare these arguments as the routine's inputs (reader:, viewer, subject, " f"egeria_client:); the environment's role supply provides them. " f"The key will be refused in a later release.") warnings.warn(message, DeprecationWarning, stacklevel=2) logger.warning(message) - return values + model = handler(values) + if names: + model._dropped_binders = names + return model @model_validator(mode="before") @classmethod diff --git a/pyegeria/view/spec_resolver.py b/pyegeria/view/spec_resolver.py index c7cc1bc5..7f5ecbc5 100644 --- a/pyegeria/view/spec_resolver.py +++ b/pyegeria/view/spec_resolver.py @@ -241,6 +241,19 @@ def _as_dict(spec: Any) -> Dict[str, Any]: return dict(spec or {}) +BINDERS_DEPRECATED_PREFIX = "deprecated: analytic_binders ignored" + + +def _dropped_binders(spec: Any, action: Dict[str, Any]) -> List[str]: + """The parameter names of a non-empty `analytic_binders` the spec carried: noted on the loaded + ActionParameter by its shim, or still in the action when `spec` is a plain dict.""" + names = list(getattr(getattr(spec, "action", None), "_dropped_binders", None) or []) + binders = action.get("analytic_binders") + if binders and not names: + names = sorted(binders) if isinstance(binders, dict) else [repr(binders)] + return names + + def _target_type_name(data: Dict[str, Any]) -> Optional[str]: """Egeria's property name (`target_type_name`), with `target_type` read as its alias.""" return data.get("target_type_name") or data.get("target_type") @@ -413,6 +426,10 @@ def fail(check: int, sentence: str) -> None: f"Spec '{name}' cannot run on its own: it has no action, so it formats elements another call " f"fetched (it is a detail or a command's output format)."]) + dropped = _dropped_binders(spec, action) + if dropped: + warns.append(f"{BINDERS_DEPRECATED_PREFIX} (binders for: {', '.join(dropped)}); declare these " + f"arguments as the routine's inputs, which the environment's role supply provides") out: Dict[str, Any] = {"stages": [], "params": [], "seeds": [], "role_inputs": [], "tile_safe": None, "admission": {}} has_find = bool(action.get("function")) diff --git a/tests/micro-tests/test_rs_w2_4_binder_deprecation_warning.py b/tests/micro-tests/test_rs_w2_4_binder_deprecation_warning.py new file mode 100644 index 00000000..84fa9ec1 --- /dev/null +++ b/tests/micro-tests/test_rs_w2_4_binder_deprecation_warning.py @@ -0,0 +1,65 @@ +"""RS-W2-4 PR-0 (owner decision O1-a, 2026-11-08): a spec that still carries a non-empty +`analytic_binders` key reports it among the resolver's warnings, with a stable prefix the +Portal tags on. The PR-B shim still drops the key; an empty key stays silent. +""" +import warnings + +import pytest + +from pyegeria.view import spec_resolver as sr +from pyegeria.view._output_format_models import FormatSet + +PREFIX = "deprecated: analytic_binders ignored (binders for: " + + +def _spec_dict(binders): + return {"heading": "W24-Binder", "description": "probe", "target_type": "Referenceable", + "action": {"analytic_function": "count_elements", "analytic_binders": binders}, + "formats": [{"types": ["DICT"], "attributes": []}]} + + +def _binder_warnings(result): + return [w for w in result.warnings if w.startswith(sr.BINDERS_DEPRECATED_PREFIX)] + + +def test_the_prefix_is_the_stable_one_the_portal_matches(): + assert sr.BINDERS_DEPRECATED_PREFIX == "deprecated: analytic_binders ignored" + + +def test_a_loaded_spec_with_a_non_empty_binder_carries_the_warning(): + with pytest.warns(DeprecationWarning): + spec = FormatSet.model_validate(_spec_dict({"reader": "x.Reader", "mgr": "os.getcwd"})) + assert "analytic_binders" not in spec.model_dump()["action"] + found = _binder_warnings(sr.resolve(spec, "W24-Binder", registry_names=set())) + assert len(found) == 1 + assert found[0].startswith(PREFIX + "mgr, reader)") + + +def test_the_note_survives_a_copy_of_the_spec(): + with pytest.warns(DeprecationWarning): + spec = FormatSet.model_validate(_spec_dict({"ods": "x.OdsReader"})) + copied = spec.model_copy(deep=True) + assert _binder_warnings(sr.resolve(copied, "W24-Binder", registry_names=set()))[0].startswith( + PREFIX + "ods)") + + +def test_a_plain_dict_spec_with_a_binder_carries_the_warning(): + found = _binder_warnings(sr.resolve(_spec_dict({"ods": "x.OdsReader"}), "W24-Binder", registry_names=set())) + assert len(found) == 1 and found[0].startswith(PREFIX + "ods)") + + +@pytest.mark.parametrize("empty", [{}, None, []]) +def test_an_empty_binder_gives_no_warning(empty): + with warnings.catch_warnings(): + warnings.simplefilter("error") + spec = FormatSet.model_validate(_spec_dict(empty)) + assert spec.action._dropped_binders == [] + assert _binder_warnings(sr.resolve(spec, "W24-Binder", registry_names=set())) == [] + assert _binder_warnings(sr.resolve(_spec_dict(empty), "W24-Binder", registry_names=set())) == [] + + +def test_no_registered_spec_carries_the_warning(): + """No built-in, demo or generated spec sets a non-empty binder (the 274 empty keys stay silent).""" + results = sr.resolve_all(refresh=True) + assert results + assert {label for label, r in results.items() if _binder_warnings(r)} == set()