From 30ba5a4aad862a8e9f340f74489e73fdf9e08181 Mon Sep 17 00:00:00 2001 From: Luik Date: Tue, 27 Oct 2026 17:29:07 +0100 Subject: [PATCH 1/2] Cover existing feature gates at initialization and result import --- tests/test_remote_shallower.py | 18 ++++++ tests/test_returned_zarr_inspection.py | 22 +++++++ .../test_slurm_image_initialization_status.py | 60 +++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/tests/test_remote_shallower.py b/tests/test_remote_shallower.py index 74dc192..58c46e0 100644 --- a/tests/test_remote_shallower.py +++ b/tests/test_remote_shallower.py @@ -41,6 +41,24 @@ def test_absent_flag_is_a_noop(): client.shallow_results_on_slurm.assert_not_called() +@pytest.mark.parametrize("disabled_gate", [ + "IMPORTER_ENABLED", "SHALLOW_ZARR_ENABLED", + "SHALLOW_ZARR_OPERATION_AVAILABLE", "IMPORTER_ORDER_API_AVAILABLE", +]) +def test_disabled_shallow_path_does_not_read_canonical_or_contact_hpc(disabled_gate): + function = load() + snapshot = Mock(side_effect=AssertionError("canonical inputs accessed")) + function.__globals__.update({ + disabled_gate: False, "load_canonical_input_snapshot": snapshot, + }) + client = SimpleNamespace(remote_shallow_zarr=True, shallow_results_on_slurm=Mock()) + + function(client, "/data", "workflow") + + snapshot.assert_not_called() + client.shallow_results_on_slurm.assert_not_called() + + def test_shallower_receives_workflow_connection(): function = load() if 'omero_conn' not in function.__code__.co_varnames and not os.environ.get('BIOMERO_TEST_REMOTE_SHALLOWER'): diff --git a/tests/test_returned_zarr_inspection.py b/tests/test_returned_zarr_inspection.py index 303f745..4631751 100644 --- a/tests/test_returned_zarr_inspection.py +++ b/tests/test_returned_zarr_inspection.py @@ -4,6 +4,8 @@ from types import SimpleNamespace from uuid import UUID +import pytest + SOURCE_ROOT = Path(os.environ.get( "BIOMERO_SCRIPTS_ROOT", Path(__file__).parents[1] @@ -113,6 +115,26 @@ def test_missing_snapshot_preserves_legacy_import(): assert "no canonical" in logger.info_calls[-1][0][0] +@pytest.mark.parametrize("disabled_gate", [ + "IMPORTER_ENABLED", "SHALLOW_ZARR_ENABLED", + "IMPORTER_ORDER_API_AVAILABLE", "SHALLOW_ZARR_OPERATION_AVAILABLE", +]) +def test_disabled_shallow_path_does_not_request_importer_operation(disabled_gate): + namespace = { + "IMPORTER_ENABLED": True, + "SHALLOW_ZARR_ENABLED": True, + "IMPORTER_ORDER_API_AVAILABLE": True, + "SHALLOW_ZARR_OPERATION_AVAILABLE": True, + disabled_gate: False, + } + (build_options,) = _load_functions( + ("build_shallow_import_options",), namespace + ) + + # No constructors or canonical-store access should be needed on this path. + assert build_options(None) is None + + def test_lifecycle_path_selection_prunes_nested_label_zarrs(tmp_path): result = tmp_path / "result.ome.zarr" label = result / "labels" / "nuclei.zarr" diff --git a/tests/test_slurm_image_initialization_status.py b/tests/test_slurm_image_initialization_status.py index f7dd0b1..c9c35c8 100644 --- a/tests/test_slurm_image_initialization_status.py +++ b/tests/test_slurm_image_initialization_status.py @@ -128,6 +128,66 @@ def test_initializer_adds_configured_remote_shallower_to_image_array(): assert "converter_specs.append(image_spec(slurmClient))" in source +@pytest.mark.skipif( + 'os.getenv("BIOMERO_SHALLOW_ZARR", "false")' not in + INIT_SCRIPT.read_text(encoding="utf-8"), + reason="initializer feature gates are not present on this source revision", +) +@pytest.mark.parametrize( + "importer,shallow,remote,image,expected", + [ + (None, None, True, "shallower.sif", False), + ("false", "true", True, "shallower.sif", False), + ("true", "false", True, "shallower.sif", False), + ("true", "", True, "shallower.sif", False), + ("true", "true", False, "shallower.sif", False), + ("true", "true", True, None, False), + ("true", "true", True, "shallower.sif", True), + ("TRUE", "TRUE", True, "shallower.sif", True), + ], +) +def test_initializer_only_acquires_enabled_remote_shallower( + monkeypatch, importer, shallow, remote, image, expected, +): + source = INIT_SCRIPT.read_text(encoding="utf-8") + tree = ast.parse(source) + # Exercise the actual image-acquisition branch without booting OMERO. + branch = next( + node for node in ast.walk(tree) + if isinstance(node, ast.If) + and any( + isinstance(statement, ast.ImportFrom) + and statement.module == "biomero.remote_shallower" + for statement in node.body + ) + ) + for name, value in (("IMPORTER_ENABLED", importer), + ("BIOMERO_SHALLOW_ZARR", shallow)): + if value is None: + monkeypatch.delenv(name, raising=False) + else: + monkeypatch.setenv(name, value) + client = SimpleNamespace( + remote_shallow_zarr=remote, remote_shallower_image=image, + ) + helper = ModuleType("biomero.remote_shallower") + spec = {"kind": "shallower", "destination": image} + helper.image_spec = Mock(return_value=spec) + converter_spec = {"kind": "converter", "destination": "converter.sif"} + specs = [converter_spec] + namespace = {"os": os, "slurmClient": client, "converter_specs": specs} + + with patch.dict(sys.modules, {"biomero.remote_shallower": helper}): + exec(compile(ast.Module(body=[branch], type_ignores=[]), + str(INIT_SCRIPT), "exec"), namespace) + + assert specs == [converter_spec] + ([spec] if expected else []) + if expected: + helper.image_spec.assert_called_once_with(client) + else: + helper.image_spec.assert_not_called() + + def test_workflow_preflight_accepts_ready_remote_shallower(): validator = load_function(RUN_SCRIPT, "validate_remote_shallower_ready") destination = "/images/shallower.sif" From 4a8054eaaa4447140617bd3ec4dc6b13b1faf093 Mon Sep 17 00:00:00 2001 From: Luik Date: Tue, 27 Oct 2026 17:32:25 +0100 Subject: [PATCH 2/2] Check disabled shallow gates with a populated canonical manifest --- tests/test_returned_zarr_inspection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_returned_zarr_inspection.py b/tests/test_returned_zarr_inspection.py index 4631751..5a857f4 100644 --- a/tests/test_returned_zarr_inspection.py +++ b/tests/test_returned_zarr_inspection.py @@ -132,7 +132,8 @@ def test_disabled_shallow_path_does_not_request_importer_operation(disabled_gate ) # No constructors or canonical-store access should be needed on this path. - assert build_options(None) is None + manifest = SimpleNamespace(inputs=(object(),)) + assert build_options(manifest) is None def test_lifecycle_path_selection_prunes_nested_label_zarrs(tmp_path):