feat(core): expose read-only views of function group filters - #2147
Conversation
Signed-off-by: David Hyde <DABH@users.noreply.github.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
I get your point, but at the same time, we intentionally don't want to expose |
Description
FunctionGroupis part of the public plugin-authoring contract: third-party plugin packages import it from the stablenat.plugin_apifacade (perdocs/source/extend/third-party-plugins.md, symbols exported fromnat.plugin_apiare the public contract for external plugin packages) and build provider tool groups throughregister_function_group. A group's composition can be shaped by two kinds of filter callbacks: a group-levelfilter_fn(constructor argument, orset_filter_fn) and per-function filter callbacks (add_function(..., filter_fn=...), orset_per_function_filter_fn). Today both are write-only from the outside: a plugin package that wants to validate, document, or instrument how a group is composed (for example, asserting in its own tests that the expected filters were wired up, or logging which functions are dynamically gated) has to reach into the private_filter_fnand_per_function_filter_fnattributes, which is exactly the kind of implementation-module reliance the third-party plugin guide tells authors to avoid.This change adds two minimal read-only properties to
FunctionGroup, mirroring the existinginstance_nameandmiddlewareproperties:filter_fnreturns the configured group-level filter callback, orNonewhen no group-level filter has been set.per_function_filter_fnsreturns an immutabletypes.MappingProxyTypeview of the per-function filter callbacks keyed by function name. The view rejects mutation withTypeErrorand stays live: filter callbacks registered later (throughadd_functionorset_per_function_filter_fn) appear in a previously obtained view.The change is purely additive: no existing behavior changes, and no new module-level symbols are added to
nat.plugin_api(the properties ride along on the already-exportedFunctionGroupclass, so the pinned export test and the plugin API surface documentation are unaffected).No tracking issue exists for this yet; happy to file one if the team prefers.
Testing
uv run pytest packages/nvidia_nat_core/tests/nat/builder/test_function_group.py— 28 passed (includes two new tests covering groups constructed with and without filters, filters set after construction, read-only enforcement on the mapping view, and the view reflecting later additions).uv run pytest packages/nvidia_nat_core/tests/nat/builder— 319 passed.uv run pre-commit run yapf --files packages/nvidia_nat_core/src/nat/builder/function.py packages/nvidia_nat_core/tests/nat/builder/test_function_group.py— passed.uv run pre-commit run ruff-check --files packages/nvidia_nat_core/src/nat/builder/function.py packages/nvidia_nat_core/tests/nat/builder/test_function_group.py— passed.uv run python ci/scripts/copyright.py --verify-apache-v2— passed.By Submitting this PR I confirm: