|
4 | 4 | import pytest |
5 | 5 | from pydantic import ValidationError |
6 | 6 |
|
7 | | -from openjd.model import create_job |
| 7 | +from openjd.model import create_job, decode_job_template |
8 | 8 | from openjd.model._parse import _parse_model |
9 | 9 | from openjd.model.v2023_09 import ( |
10 | 10 | Action, |
@@ -57,6 +57,59 @@ def test_extension_not_supported(self) -> None: |
57 | 57 | assert "FEATURE_BUNDLE_1" in str(excinfo.value) |
58 | 58 |
|
59 | 59 |
|
| 60 | +class TestExtensionFieldEnablement: |
| 61 | + """Tests for extension enablement based on template's extensions field and supported_extensions.""" |
| 62 | + |
| 63 | + @pytest.mark.parametrize( |
| 64 | + "template_declares_ext,supported_extensions,param_count,should_pass", |
| 65 | + [ |
| 66 | + # Template declares extension, supported includes it - passes with 51 params |
| 67 | + (True, ["FEATURE_BUNDLE_1"], 51, True), |
| 68 | + # Template declares extension, supported excludes it - fails (unsupported ext) |
| 69 | + (True, ["TASK_CHUNKING"], 51, False), |
| 70 | + # Template declares extension, supported is None - fails (unsupported ext) |
| 71 | + (True, None, 51, False), |
| 72 | + # Template omits extension, supported includes it - fails (50 param limit) |
| 73 | + (False, ["FEATURE_BUNDLE_1"], 51, False), |
| 74 | + # Template omits extension, all supported - fails (50 param limit) |
| 75 | + (False, ["TASK_CHUNKING", "REDACTED_ENV_VARS", "FEATURE_BUNDLE_1"], 51, False), |
| 76 | + # Template omits extension, none supported - fails (50 param limit) |
| 77 | + (False, [], 51, False), |
| 78 | + # Template omits extension, supported is None - fails (50 param limit) |
| 79 | + (False, None, 51, False), |
| 80 | + # Template within default limit - passes regardless |
| 81 | + (False, ["FEATURE_BUNDLE_1"], 50, True), |
| 82 | + # Template omits extension, supported is None, within limit - passes |
| 83 | + (False, None, 50, True), |
| 84 | + ], |
| 85 | + ) |
| 86 | + def test_extension_enablement( |
| 87 | + self, |
| 88 | + template_declares_ext: bool, |
| 89 | + supported_extensions: list[str], |
| 90 | + param_count: int, |
| 91 | + should_pass: bool, |
| 92 | + ) -> None: |
| 93 | + """Test that extension features require explicit declaration in template.""" |
| 94 | + params = [{"name": f"P{i}", "type": "INT", "default": i} for i in range(param_count)] |
| 95 | + data: dict = { |
| 96 | + "specificationVersion": "jobtemplate-2023-09", |
| 97 | + "name": "Test", |
| 98 | + "parameterDefinitions": params, |
| 99 | + "steps": [{"name": "s", "script": STEP_SCRIPT}], |
| 100 | + } |
| 101 | + if template_declares_ext: |
| 102 | + data["extensions"] = ["FEATURE_BUNDLE_1"] |
| 103 | + |
| 104 | + if should_pass: |
| 105 | + result = decode_job_template(template=data, supported_extensions=supported_extensions) |
| 106 | + assert result.parameterDefinitions is not None |
| 107 | + assert len(result.parameterDefinitions) == param_count |
| 108 | + else: |
| 109 | + with pytest.raises(Exception): |
| 110 | + decode_job_template(template=data, supported_extensions=supported_extensions) |
| 111 | + |
| 112 | + |
60 | 113 | class TestActionTimeoutFormatString: |
61 | 114 | """Tests for timeout format string support in Action.""" |
62 | 115 |
|
|
0 commit comments