-
Notifications
You must be signed in to change notification settings - Fork 23
fix(deps): Accept a stepEnvironment name reused across steps on the v1 path #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import pytest | ||
|
|
||
| from openjd.model._v1 import ( | ||
| CallerLimits, | ||
| decode_environment_template, | ||
| decode_environment_template_str, | ||
| decode_job_template, | ||
|
|
@@ -405,3 +406,101 @@ def test_json_explicit(self) -> None: | |
| def test_invalid_yaml_raises(self) -> None: | ||
| with pytest.raises(DecodeValidationError): | ||
| decode_environment_template_str(": not a mapping") | ||
|
|
||
|
|
||
| class TestStepEnvironmentNameScope(object): | ||
| """A Step Environment's ``name`` is scoped to the Step that defines it (Template | ||
| Schemas §3 StepTemplate, §4 Environment): unique within that Step's list, and | ||
| distinct from every Job Environment. Different Steps may reuse a name. | ||
|
|
||
| openjd-model 0.7.1 (openjd-rs#381) relaxed an over-strict check that held every | ||
| environment name in the template in one set, so the second Step to declare | ||
| ``StepEnv`` was rejected. The v0 path always accepted this; this is the v1 path, | ||
| which had no coverage. | ||
|
|
||
| The error-text assertions below pin the v1 wording as it stands. It differs from | ||
| v0 on purpose-of-record, not by design: v0 reports the step-vs-job rule as | ||
| ``Name X must differ from the names of Environments defined at the root of the | ||
| template.`` at ``step[i] -> stepEnvironments[j] -> name``, while v1 reports both | ||
| the per-Step and the step-vs-job rule as ``duplicate environment name: 'X'`` at | ||
| ``steps[i] -> stepEnvironments[j]``. Aligning the two is an openjd-rs concern; | ||
| these assertions only guard against the relaxation dropping a rule. | ||
| """ | ||
|
|
||
| @staticmethod | ||
| def _environment(name: str) -> dict[str, Any]: | ||
| return { | ||
| "name": name, | ||
| "script": {"actions": {"onEnter": {"command": "echo", "args": [name]}}}, | ||
| } | ||
|
|
||
| @classmethod | ||
| def _step(cls, name: str, environment_names: list[str]) -> dict[str, Any]: | ||
| return { | ||
| "name": name, | ||
| "stepEnvironments": [cls._environment(n) for n in environment_names], | ||
| "script": {"actions": {"onRun": {"command": "echo", "args": [name]}}}, | ||
| } | ||
|
|
||
| @classmethod | ||
| def _template(cls, steps: list[dict[str, Any]]) -> dict[str, Any]: | ||
| return { | ||
| "specificationVersion": "jobtemplate-2023-09", | ||
| "name": "T", | ||
| "jobEnvironments": [cls._environment("JobEnv")], | ||
| "steps": steps, | ||
| } | ||
|
|
||
| def test_same_name_across_steps_is_accepted(self) -> None: | ||
|
leongdl marked this conversation as resolved.
|
||
| """Four Steps each declare ``StepEnv``. Only one Step's environments are ever | ||
| active in a Session, so these names never collide.""" | ||
| template = self._template([self._step(f"Step{i}", ["StepEnv"]) for i in range(4)]) | ||
| job_template = decode_job_template(template=template, supported_extensions=[]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The relaxation is only exercised at
That instantiation path is a second place a name set could be held.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked the instantiation path in openjd-rs 0.7.1 for the hypothesized name-keyed collection; there is none. |
||
| names = [[e.name for e in (s.step_environments or [])] for s in job_template.steps] | ||
| assert names == [["StepEnv"]] * 4 | ||
|
leongdl marked this conversation as resolved.
|
||
|
|
||
| def test_duplicate_within_one_step_is_rejected(self) -> None: | ||
| """Control for §3 rule 1: the per-Step uniqueness check must survive the relaxation.""" | ||
| template = self._template( | ||
| [self._step("Step0", ["StepEnv"]), self._step("Step1", ["StepEnv", "StepEnv"])] | ||
| ) | ||
| with pytest.raises(ModelValidationError) as excinfo: | ||
| decode_job_template(template=template, supported_extensions=[]) | ||
| message = str(excinfo.value) | ||
| assert "steps[1] -> stepEnvironments[1]" in message | ||
| assert "duplicate environment name: 'StepEnv'" in message | ||
|
leongdl marked this conversation as resolved.
|
||
|
|
||
| def test_step_env_named_like_job_env_is_rejected(self) -> None: | ||
| """Control for §3 rule 2: a Step Environment may not reuse a Job Environment name.""" | ||
| template = self._template( | ||
| [self._step("Step0", ["StepEnv"]), self._step("Step1", ["JobEnv"])] | ||
| ) | ||
| with pytest.raises(ModelValidationError) as excinfo: | ||
| decode_job_template(template=template, supported_extensions=[]) | ||
| message = str(excinfo.value) | ||
| assert "steps[1] -> stepEnvironments[0]" in message | ||
| assert "duplicate environment name: 'JobEnv'" in message | ||
|
leongdl marked this conversation as resolved.
|
||
|
|
||
| def test_duplicate_job_env_names_is_rejected(self) -> None: | ||
| """Control for §4 uniqueness within ``jobEnvironments``. The relaxation split one | ||
| template-wide set into a job set plus a per-Step set; this pins the job set.""" | ||
| template = self._template([self._step("Step0", ["StepEnv"])]) | ||
| template["jobEnvironments"] = [self._environment("JobEnv"), self._environment("JobEnv")] | ||
| with pytest.raises(ModelValidationError) as excinfo: | ||
| decode_job_template(template=template, supported_extensions=[]) | ||
| message = str(excinfo.value) | ||
| assert "jobEnvironments[1]" in message | ||
| assert "duplicate environment name: 'JobEnv'" in message | ||
|
|
||
| def test_max_env_count_counts_repeated_names_separately(self) -> None: | ||
| """``max_env_count`` bounds the number of environments, not the number of distinct | ||
| names. Four Steps each declaring ``StepEnv`` plus ``JobEnv`` is 5 environments | ||
| under 2 names, so a limit of 4 must reject; counting distinct names would not.""" | ||
| template = self._template([self._step(f"Step{i}", ["StepEnv"]) for i in range(4)]) | ||
| with pytest.raises(ModelValidationError) as excinfo: | ||
| decode_job_template( | ||
| template=template, | ||
| supported_extensions=[], | ||
| caller_limits=CallerLimits(max_env_count=4), | ||
| ) | ||
| assert "total environments (5) exceeds caller limit of 4" in str(excinfo.value) | ||
Uh oh!
There was an error while loading. Please reload this page.