1919
2020from __future__ import annotations
2121
22+ from typing import Any
23+
2224# ── Top-level package no longer leaks typing imports ──
2325#
2426# An earlier draft of ``openjd.model._v1`` imported ``Any``,
@@ -41,3 +43,121 @@ def test_no_internal_imports_leak_at_top_level(name: str) -> None:
4143 import openjd .model ._v1 as v1
4244
4345 assert not hasattr (v1 , name ), f"{ name } leaks as a public attribute on openjd.model._v1"
46+
47+
48+ # ── Chunked parameter spaces: two divergences from the v0 reference ──
49+ #
50+ # Found while adding `chunks_task_count_override` to
51+ # `StepParameterSpaceIterator`. Neither is caused by that argument — both
52+ # reproduce without it — so they are recorded here rather than fixed in
53+ # passing.
54+
55+
56+ def _chunked_step (constraint : str ) -> Any :
57+ from openjd .model ._v1 import create_job , decode_job_template
58+
59+ template = {
60+ "specificationVersion" : "jobtemplate-2023-09" ,
61+ "name" : "T" ,
62+ "extensions" : ["TASK_CHUNKING" ],
63+ "steps" : [
64+ {
65+ "name" : "S" ,
66+ "parameterSpace" : {
67+ "taskParameterDefinitions" : [
68+ {
69+ "name" : "Frame" ,
70+ "type" : "CHUNK[INT]" ,
71+ "range" : "1-10" ,
72+ "chunks" : {"defaultTaskCount" : 5 , "rangeConstraint" : constraint },
73+ }
74+ ]
75+ },
76+ "script" : {
77+ "actions" : {"onRun" : {"command" : "echo" , "args" : ["{{Task.Param.Frame}}" ]}}
78+ },
79+ }
80+ ],
81+ }
82+ job_template = decode_job_template (template = template , supported_extensions = ["TASK_CHUNKING" ])
83+ return create_job (job_template = job_template , job_parameter_values = {}).steps [0 ]
84+
85+
86+ @pytest .mark .xfail (
87+ reason = "v1 derives chunks_parameter_name and chunks_default_task_count from adaptive "
88+ "detection, so both are None for any non-adaptive chunked space. v0 reports them for "
89+ "any chunked space. See openjd-model step_param_space.rs: chunks_param_name and "
90+ "adaptive_chunk_size are both built from adaptive_info." ,
91+ strict = True ,
92+ )
93+ @pytest .mark .parametrize (
94+ "chunks,override,expected_count" ,
95+ [
96+ # Statically chunked: no override involved, v0 reports the template's size.
97+ ({"defaultTaskCount" : 5 , "rangeConstraint" : "CONTIGUOUS" }, None , 5 ),
98+ # Statically chunked, re-chunked by the override.
99+ ({"defaultTaskCount" : 5 , "rangeConstraint" : "CONTIGUOUS" }, 1 , 1 ),
100+ # Adaptive, turned static by the override. v0 reports the override as the size.
101+ (
102+ {"defaultTaskCount" : 5 , "targetRuntimeSeconds" : 60 , "rangeConstraint" : "CONTIGUOUS" },
103+ 1 ,
104+ 1 ,
105+ ),
106+ ],
107+ ids = ["static" , "static-overridden" , "adaptive-overridden" ],
108+ )
109+ def test_chunk_metadata_is_reported_for_a_non_adaptive_space (
110+ chunks : dict , override : int | None , expected_count : int
111+ ) -> None :
112+ """v0 returns ``"Frame"`` and the chunk size for each of these. v1 returns ``None``.
113+
114+ Neither value is unknowable — both are in the template, or are the override the caller
115+ just passed — so a consumer inspecting a non-adaptive chunked space through v1 cannot
116+ learn which parameter chunks, or at what size. One root cause, three ways to reach it:
117+ anything that leaves the space non-adaptive drops both getters.
118+ """
119+ from openjd .model ._v1 import create_job , decode_job_template
120+ from openjd .model ._v1 .job import StepParameterSpaceIterator
121+
122+ template = {
123+ "specificationVersion" : "jobtemplate-2023-09" ,
124+ "name" : "T" ,
125+ "extensions" : ["TASK_CHUNKING" ],
126+ "steps" : [
127+ {
128+ "name" : "S" ,
129+ "parameterSpace" : {
130+ "taskParameterDefinitions" : [
131+ {"name" : "Frame" , "type" : "CHUNK[INT]" , "range" : "1-10" , "chunks" : chunks }
132+ ]
133+ },
134+ "script" : {
135+ "actions" : {"onRun" : {"command" : "echo" , "args" : ["{{Task.Param.Frame}}" ]}}
136+ },
137+ }
138+ ],
139+ }
140+ job_template = decode_job_template (template = template , supported_extensions = ["TASK_CHUNKING" ])
141+ step = create_job (job_template = job_template , job_parameter_values = {}).steps [0 ]
142+
143+ it = StepParameterSpaceIterator (step = step , chunks_task_count_override = override )
144+ assert it .chunks_adaptive is False
145+ assert it .chunks_parameter_name == "Frame"
146+ assert it .chunks_default_task_count == expected_count
147+
148+
149+ @pytest .mark .xfail (
150+ reason = "v1 refuses random access whenever the space needs sequential iteration, and "
151+ "contiguous chunking always does. v0 supports indexing the same space." ,
152+ strict = True ,
153+ )
154+ def test_a_contiguous_chunked_space_supports_indexing () -> None :
155+ """v0 answers ``it[0]`` with ``1-5``. v1 raises ``IndexError``.
156+
157+ ``len()`` works on this space, so the count is known; only ``get`` declines.
158+ """
159+ from openjd .model ._v1 .job import StepParameterSpaceIterator
160+
161+ it = StepParameterSpaceIterator (step = _chunked_step ("CONTIGUOUS" ))
162+ assert len (it ) == 2
163+ assert it [0 ]["Frame" ].value == "1-5"
0 commit comments