Skip to content

Commit 63f7735

Browse files
committed
test: Pin the 512-character let identifier cap on the v1 path
openjd-model 0.6.0 carries openjd-rs#358, which enforces Template Schemas §3.6.1's 512-character cap on a `let` binding's `<UserIdentifier>`; before it a 513-character name was accepted. The v0 side has covered this since #348, in `test/openjd/model_v0/v2023_09/test_let_bindings.py`. The v1 path had nothing, so the bump brought the enforcement with no test on this side to hold it. Measured through `decode_job_template` on both implementations before writing the assertions. 512 characters is accepted and 513 rejected, identically, with `EXPR` alone and with `EXPR` plus `FEATURE_BUNDLE_1`. The accept at 512 with `EXPR` alone is the case worth having. The cap is flat, not §7.1's `<Identifier>` cap of 64 rising to 512 under `FEATURE_BUNDLE_1`, so a fix built on the wrong constant would reject a template the spec permits. A 65-character control covers the same ground from the other side: over the §7.1 cap, under §3.6.1's, and accepted. The two implementations' messages differ in wording, so the assertion is on the error path and the phrase `exceeds 512 characters`, not on the whole string. Verified: 5572 passed, 24 skipped, 3 xfailed with the 94% coverage gate; ruff, black and mypy clean. Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
1 parent e27a4fb commit 63f7735

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

‎test/openjd/model_v1/test_parse.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,69 @@ def test_template_extensions_list(template, template_type, decode_function) -> N
232232
decode_function(template=template, supported_extensions=["TASK_CHUNKING", "EXPR"])
233233

234234

235+
class TestLetIdentifierLengthCap(object):
236+
"""A ``let`` binding's ``<UserIdentifier>`` is capped at 512 characters
237+
(Template Schemas §3.6.1). Enforced by openjd-model 0.6.0 (openjd-rs#358);
238+
before that a 513-character name was accepted here. The v0 side has its own
239+
coverage in ``test/openjd/model_v0/v2023_09/test_let_bindings.py``; this is the
240+
v1 path, which had none.
241+
242+
The cap is flat, not the §7.1 ``<Identifier>`` cap of 64 rising to 512 with
243+
``FEATURE_BUNDLE_1``. The 512-character accept with ``EXPR`` alone is what makes
244+
the difference observable, and is why the fix upstream did not reuse
245+
``EffectiveLimits::max_identifier_len``.
246+
"""
247+
248+
@staticmethod
249+
def _template(name: str, extensions: list[str]) -> dict[str, Any]:
250+
return {
251+
"specificationVersion": "jobtemplate-2023-09",
252+
"name": "T",
253+
"extensions": extensions,
254+
"steps": [
255+
{
256+
"name": "Step1",
257+
"let": [f"{name} = 42"],
258+
"script": {"actions": {"onRun": {"command": "echo", "args": ["hi"]}}},
259+
}
260+
],
261+
}
262+
263+
@pytest.mark.parametrize(
264+
"extensions",
265+
[
266+
pytest.param(["EXPR"], id="EXPR only"),
267+
pytest.param(["EXPR", "FEATURE_BUNDLE_1"], id="with FEATURE_BUNDLE_1"),
268+
],
269+
)
270+
def test_512_characters_is_accepted(self, extensions: list[str]) -> None:
271+
"""Both extension sets accept the boundary. Without ``FEATURE_BUNDLE_1`` the
272+
§7.1 cap would be 64, so this is the case that pins the cap as flat."""
273+
template = self._template("a" * 512, extensions)
274+
assert decode_job_template(template=template, supported_extensions=extensions)
275+
276+
@pytest.mark.parametrize(
277+
"extensions",
278+
[
279+
pytest.param(["EXPR"], id="EXPR only"),
280+
pytest.param(["EXPR", "FEATURE_BUNDLE_1"], id="with FEATURE_BUNDLE_1"),
281+
],
282+
)
283+
def test_513_characters_is_rejected(self, extensions: list[str]) -> None:
284+
template = self._template("a" * 513, extensions)
285+
with pytest.raises(ModelValidationError) as excinfo:
286+
decode_job_template(template=template, supported_extensions=extensions)
287+
message = str(excinfo.value)
288+
assert "steps[0] -> let[0]" in message
289+
assert "exceeds 512 characters" in message
290+
291+
def test_a_short_name_is_unaffected(self) -> None:
292+
"""Control. 65 characters is over the §7.1 cap of 64 and under §3.6.1's, so it
293+
must be accepted -- a regression to the wrong constant would reject it."""
294+
template = self._template("a" * 65, ["EXPR"])
295+
assert decode_job_template(template=template, supported_extensions=["EXPR"])
296+
297+
235298
class TestDecodeJobTemplateStr:
236299
"""``decode_job_template_str`` wrapper: parses YAML or JSON
237300
directly, no intermediate dict. The wrapper lives on

0 commit comments

Comments
 (0)