Skip to content

Commit 1d0cc51

Browse files
authored
chore(deps): Bump openjd-* Rust crates to 0.8.0 (#365)
openjd-expr 0.7.0 -> 0.8.0, openjd-model 0.7.1 -> 0.8.0, and openjd-sessions 0.5.8 -> 0.6.0 (openjd-rs release PR #395). Six upstream changes land, reconciled against a source diff of the published crates. The only new public API is two methods on openjd_expr::FormatString, segment_count and literal_segments, which the model crate's validator uses (#383). Both are now exposed on openjd.expr.FormatString, with the stub and specs/python-expr-interface.md updated. openjd-model and openjd-sessions have no public signature changes; the two [breaking] changelog entries are behavioural. Each change exercised through this package's API, v1 and v0 side by side where both apply: * openjd-rs#396 type-checks an `in`/`not in` item against the list's element type. `'a' in [1, 2]` now raises where it returned False. Int/float and path/string coercion kept; `x in []` is False for any x. * openjd-rs#383 checks resolved-value constraints at template validation. A job name resolving to 129 characters, and a chunks defaultTaskCount naming an undeclared parameter, are now rejected at decode. v0 already rejected both. The whole-field chunks expression is resolved with target type int, so a STRING value fails inside the evaluator: test_chunk_default_task_count_invalid_int's message match moves from "not a valid integer" to "Cannot convert ... to int"; the exception class it pins is unchanged. * openjd-rs#397: a single-valued allOf with one literal and one whole-field expression is now accepted at validation (0.7.1 rejected it) because the expression can null-skip, and job creation re-checks the resolved count. A control character in a resolved job name is rejected at create_job; 0.7.1 produced the job. * openjd-rs#398 renders NONCONTIGUOUS chunks like the v0 reference: [1,2,4,6] is "1,2,4,6", not "1,2-6:2". Both paths agree on all four probed shapes. * openjd-rs#384: preprocess_job_parameters accepts its own output for a LIST[PATH] parameter defaulting to []. 0.7.1 refused the second pass. * openjd-rs#359 rejects embedded filenames ".", ".." and any containing a null byte at template validation. v0 accepts all three. The sessions-side check for Windows drive anchors ("C:", "D:relative") is not reachable from this repo's tests: the model layer accepts them and the check is Windows-only. One test template was invalid and passed only because 0.7.1 did not validate chunk fields: test_chunks_with_format_string_default_task_count now declares the parameter it references. Old-pins mutant: with the three pins reverted and the two new bindings removed, 30 tests fail, all in the new or updated classes, and the whole-field allOf deferral was measured as rejected on 0.7.1. Two new cases (a tab in a literal run of an interpolated name, two certain allOf elements) were already rejected on 0.7.1 and are labelled controls. THIRD-PARTY-LICENSES.txt regenerated; only the three crate versions changed. Cargo.lock moved only those three packages. Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com>
1 parent 798d02e commit 1d0cc51

13 files changed

Lines changed: 586 additions & 15 deletions

‎Cargo.lock‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎THIRD-PARTY-LICENSES.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,9 +2534,9 @@ limitations under the License.
25342534
** itoa; version 1.0.18 -- https://crates.io/crates/itoa
25352535
** libc; version 0.2.189 -- https://crates.io/crates/libc
25362536
** manyhow-macros; version 0.11.4 -- https://crates.io/crates/manyhow-macros
2537-
** openjd-expr; version 0.7.0 -- https://crates.io/crates/openjd-expr
2538-
** openjd-model; version 0.7.1 -- https://crates.io/crates/openjd-model
2539-
** openjd-sessions; version 0.5.8 -- https://crates.io/crates/openjd-sessions
2537+
** openjd-expr; version 0.8.0 -- https://crates.io/crates/openjd-expr
2538+
** openjd-model; version 0.8.0 -- https://crates.io/crates/openjd-model
2539+
** openjd-sessions; version 0.6.0 -- https://crates.io/crates/openjd-sessions
25402540
** pin-project-lite; version 0.2.17 -- https://crates.io/crates/pin-project-lite
25412541
** portable-atomic; version 1.15.0 -- https://crates.io/crates/portable-atomic
25422542
** proc-macro2; version 1.0.107 -- https://crates.io/crates/proc-macro2

‎rust-bindings/Cargo.toml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ name = "_openjd_rs"
1212
crate-type = ["cdylib", "rlib"]
1313

1414
[dependencies]
15-
openjd-expr = "0.7.0"
16-
openjd-model = "0.7.1"
17-
openjd-sessions = "0.5.8"
15+
openjd-expr = "0.8.0"
16+
openjd-model = "0.8.0"
17+
openjd-sessions = "0.6.0"
1818
tokio = { version = "1", features = ["rt-multi-thread"] }
1919
uuid = { version = "1", features = ["v4"] }
2020
serde_json = "1"

‎rust-bindings/src/expr/format_string.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ impl PyFormatString {
8080
self.inner.is_literal()
8181
}
8282

83+
/// Number of parsed segments: literal runs and ``{{...}}`` expressions.
84+
///
85+
/// A format string with more than one segment always concatenates to
86+
/// a single string on resolution; only a whole-field single-expression
87+
/// format string can resolve to ``None`` or to a list. ``is_literal``
88+
/// distinguishes the two single-segment cases.
89+
fn segment_count(&self) -> usize {
90+
self.inner.segment_count()
91+
}
92+
93+
/// The literal (non-expression) text runs, in order.
94+
///
95+
/// Literal runs appear verbatim in every possible resolution, so a
96+
/// property that holds for one holds for every string this format
97+
/// string can resolve to. Expression source text is not included.
98+
fn literal_segments(&self) -> Vec<String> {
99+
self.inner
100+
.literal_segments()
101+
.map(|s| s.to_string())
102+
.collect()
103+
}
104+
83105
/// Copy symbol table entries referenced by this format string's expressions
84106
/// from `source` into `dest`. Only copies the actual values referenced,
85107
/// stopping at property/method access (e.g. for `Param.Name.upper()`,

‎specs/python-expr-interface.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,13 @@ fs.is_literal() # False
763763
fs.expression_names() # ["Param.Frame"]
764764
fs.has_complex_expressions() # False (simple name reference)
765765

766+
# Static shape: literal runs appear verbatim in every resolution, and a
767+
# format string with more than one segment always concatenates to a
768+
# single string (only a whole-field single expression can resolve to
769+
# None or to a list).
770+
fs.segment_count() # 2
771+
fs.literal_segments() # ["render --frame "]
772+
766773
# Resolve
767774
st = SymbolTable({"Param.Frame": 42})
768775
fs.resolve_string(st) # "render --frame 42"

‎src/openjd/_openjd_rs.pyi‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,25 @@ class FormatString:
893893
def has_complex_expressions(self) -> builtins.bool: ...
894894
def expression_names(self) -> builtins.list[builtins.str]: ...
895895
def is_literal(self) -> builtins.bool: ...
896+
def segment_count(self) -> builtins.int:
897+
r"""
898+
Number of parsed segments: literal runs and ``{{...}}`` expressions.
899+
900+
A format string with more than one segment always concatenates to
901+
a single string on resolution; only a whole-field single-expression
902+
format string can resolve to ``None`` or to a list. ``is_literal``
903+
distinguishes the two single-segment cases.
904+
"""
905+
906+
def literal_segments(self) -> builtins.list[builtins.str]:
907+
r"""
908+
The literal (non-expression) text runs, in order.
909+
910+
Literal runs appear verbatim in every possible resolution, so a
911+
property that holds for one holds for every string this format
912+
string can resolve to. Expression source text is not included.
913+
"""
914+
896915
def copy_used_symtab_values(self, source: SymbolTable, dest: typing.Any) -> None:
897916
r"""
898917
Copy symbol table entries referenced by this format string's expressions

‎test/openjd/expr/test_lists.py‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,99 @@ def test_path_not_in_list(self) -> None:
510510
)
511511

512512

513+
class TestListMembershipElementTypeCheck:
514+
"""``in`` / ``not in`` type-check the item against the list's element type
515+
(Expression Language §2.1.3: ``__contains__(list: list[T], item: T)``).
516+
517+
openjd-expr 0.8.0 (openjd-rs#396). Before it, ``'a' in [1, 2]`` evaluated to
518+
``False`` where the spec gives it no signature at all. Cases mirror the
519+
upstream ``test_comparison.rs``; the int/float and path/string coercions the
520+
equality rule already allowed are kept.
521+
"""
522+
523+
@pytest.mark.parametrize(
524+
"expr, detail",
525+
[
526+
(
527+
"'1' in [1, 2, 3]",
528+
"item of type string is not compatible with the element type int of list[int]",
529+
),
530+
(
531+
"1 in ['a', 'b']",
532+
"item of type int is not compatible with the element type string of list[string]",
533+
),
534+
(
535+
"true in [1, 2]",
536+
"item of type bool is not compatible with the element type int of list[int]",
537+
),
538+
(
539+
"null in [1, 2]",
540+
"item of type nulltype is not compatible with the element type int of list[int]",
541+
),
542+
(
543+
"['a'] in [[1], [2]]",
544+
"item of type list[string] is not compatible with the element type list[int] of list[list[int]]",
545+
),
546+
(
547+
"'a' in [x for x in [1, 2]]",
548+
"item of type string is not compatible with the element type int of list[int]",
549+
),
550+
(
551+
"[1, 2] in [1, 2]",
552+
"item of type list[int] is not compatible with the element type int of list[int]",
553+
),
554+
],
555+
)
556+
def test_incompatible_item_type_is_refused(self, expr: str, detail: str) -> None:
557+
with pytest.raises(ExpressionError) as excinfo:
558+
evaluate_expression(expr)
559+
assert f"Cannot use 'in' operator: {detail}" in str(excinfo.value)
560+
561+
def test_not_in_is_refused_the_same_way(self) -> None:
562+
with pytest.raises(ExpressionError) as excinfo:
563+
evaluate_expression("'a' not in [1, 2]")
564+
assert (
565+
"Cannot use 'not in' operator: item of type string is not compatible "
566+
"with the element type int of list[int]"
567+
) in str(excinfo.value)
568+
569+
@pytest.mark.parametrize(
570+
"expr, expected",
571+
[
572+
("1 in [1.0, 2.0]", True),
573+
("3 in [1.0, 2.0]", False),
574+
("1.0 in [1, 2]", True),
575+
("1.5 in [1, 2]", False),
576+
("[1] in [[1.0], [2.0]]", True),
577+
("[1.5] in [[1], [2]]", False),
578+
],
579+
)
580+
def test_int_float_coercion_is_kept(self, expr: str, expected: bool) -> None:
581+
assert evaluate_expression(expr).item() is expected
582+
583+
@pytest.mark.parametrize(
584+
"expr, expected",
585+
[
586+
("path(['/a']) in ['/a', '/b']", True),
587+
("'/a' in [path(['/a']), path(['/b'])]", True),
588+
("'/c' in [path(['/a']), path(['/b'])]", False),
589+
],
590+
)
591+
def test_path_string_coercion_is_kept(self, expr: str, expected: bool) -> None:
592+
assert evaluate_expression(expr, path_format=PathFormat.POSIX).item() is expected
593+
594+
@pytest.mark.parametrize(
595+
"expr",
596+
["1 in []", "'a' in []", "path(['/a']) in []", "[1] in []", "[] in []"],
597+
)
598+
def test_empty_list_accepts_any_item_type(self, expr: str) -> None:
599+
assert evaluate_expression(expr, path_format=PathFormat.POSIX).item() is False
600+
601+
def test_empty_list_item_against_nested_lists(self) -> None:
602+
assert evaluate_expression("[] in [[1]]").item() is False
603+
assert evaluate_expression("[] in [[]]").item() is True
604+
605+
513606
class TestSortedReversed:
514607
"""Tests for sorted() and reversed() functions."""
515608

‎test/openjd/expr/test_parse_expression.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,39 @@ def test_has_complex_expressions(self):
218218
assert not FormatString("{{Param.Name}}").has_complex_expressions()
219219
assert FormatString("{{Param.A + Param.B}}").has_complex_expressions()
220220

221+
@pytest.mark.parametrize(
222+
"raw, count",
223+
[
224+
("hello", 1),
225+
("{{Param.X}}", 1),
226+
("v{{Param.X}}", 2),
227+
("{{Param.X}}-{{Param.Y}}", 3),
228+
("", 0),
229+
],
230+
)
231+
def test_segment_count(self, raw: str, count: int):
232+
# Cases mirror openjd-expr's segment_count_by_shape. A single literal
233+
# run and a whole-field expression are both one segment.
234+
assert FormatString(raw).segment_count() == count
235+
236+
def test_segment_count_single_segment_disambiguated_by_is_literal(self):
237+
assert FormatString("hello").is_literal()
238+
assert not FormatString("{{Param.X}}").is_literal()
239+
assert FormatString("").is_literal()
240+
241+
@pytest.mark.parametrize(
242+
"raw, literals",
243+
[
244+
("a-{{ Param.X }}-b{{ 'y' }}", ["a-", "-b"]),
245+
("{{ Param.X }}", []),
246+
("plain", ["plain"]),
247+
("", []),
248+
],
249+
)
250+
def test_literal_segments(self, raw: str, literals: list[str]):
251+
# Expression source text is excluded, so "'y'" never appears.
252+
assert FormatString(raw).literal_segments() == literals
253+
221254
def test_literal_resolve(self):
222255
fs = FormatString("no interpolation")
223256
st = SymbolTable()

0 commit comments

Comments
 (0)