fix: allow StringParam for vpc_connector typing - #301
Conversation
…besides just StringParam
…parametrized and other param-using tests don't hit duplicate registration
There was a problem hiding this comment.
Code Review
This pull request updates RuntimeOptions and set_global_options to allow vpc_connector to accept Expression[str] types (such as StringParam or ternary expressions), and adds corresponding unit tests. It also introduces pytest fixtures to clean up global options and parameters between tests. However, clearing the global params._params registry entirely in tests/conftest.py can delete module-level parameters from other test files, potentially causing test failures. It is recommended to capture and restore the registry's state instead of clearing it completely.
| @pytest.fixture(autouse=True) | ||
| def _cleanup_params(): | ||
| """Clear the global params registry so each test runs with a clean state.""" | ||
| params._params.clear() | ||
| yield | ||
| params._params.clear() |
There was a problem hiding this comment.
Clearing params._params entirely between tests will delete any parameters declared at the module level in other test files (which are instantiated and registered when those test files are imported). This can cause subsequent tests that rely on those module-level parameters to fail with missing parameter errors or duplicate parameter errors if they are re-declared.
Instead of clearing the registry completely, we should capture the state of params._params before each test runs and restore it afterward. This preserves module-level parameters while still cleaning up any parameters declared dynamically inside individual tests.
| @pytest.fixture(autouse=True) | |
| def _cleanup_params(): | |
| """Clear the global params registry so each test runs with a clean state.""" | |
| params._params.clear() | |
| yield | |
| params._params.clear() | |
| @pytest.fixture(autouse=True) | |
| def _cleanup_params(): | |
| """Reset the global params registry to its pre-test state so tests don't leak params.""" | |
| original_params = params._params.copy() | |
| yield | |
| params._params.clear() | |
| params._params.update(original_params) |
|
Closing, #269 is the vehicle for this fix. |
Description
Takes over #269 (all commits from @HassanBahati and @IzaakGough preserved). Widens the typing for the
vpc_connectoroption to match the values already supported at runtime:str | Expression[str] | Sentinel | None, soStringParamand other string-valued params are type-correct.The manifest generation logic is unchanged; it already serializes
Expression[...](including params) into CEL strings, so this is a typing alignment rather than a behavioral change.Related Issues:
Fixes #219
Supersedes #269
Changes Made
RuntimeOptions.vpc_connectorinsrc/firebase_functions/options.pyfromstr | Sentinel | Nonetostr | Expression[str] | Sentinel | None.set_global_optionssignature forvpc_connectorandvpc_connector_egress_settingswith theRuntimeOptionsfield types.tests/test_options.pycoveringStringParamand otherExpressionvalues end to end (_asdict_with_global_options()and_endpoint()both produce the CEL string).tests/conftest.pyautouse fixture clearing the global params registry between tests, needed for the new parameterized tests and a general test-isolation improvement.Testing Evidence
Validated in isolation and via the MRE.
Tests Run (if applicable)