Repository navigation
feat(amber): reject self-loops and empty/null op-ids in LogicalLink (with test coverage) - #4956
Conversation
Pin both construction paths and the production Jackson behavior: - Primary case-class constructor: four fields exposed as constructed. - Secondary @jsoncreator constructor: wraps raw String op ids in OperatorIdentity (the Jackson deserialization path used for user-saved workflow JSON). - Case-class equals / hashCode across the four fields, including field-discriminating tests (fromOpId, toPortId.internal) and acceptance of self-loop links (same fromOpId / toOpId, distinct ports — higher layers reject cycles, the data type does not). - @jsoncreator path accepts dashes / dots / digits and the empty string without normalization (no validation in the data type). - Production-mapper Jackson coverage via JSONUtils.objectMapper: - treeToValue with raw String op-id JSON dispatches to the @jsoncreator string overload and produces the expected fields. - @JsonProperty pins the on-the-wire key names (`fromOpId` / `toOpId` / `fromPortId` / `toPortId`). - writeValueAsString → readValue is NOT round-trippable: the string overload can't accept the object-shape OperatorIdentity that writeValueAsString emits. Asymmetry pinned so a future fix (object @jsoncreator overload or custom @JsonDeserialize) flips this on purpose. - Missing string op-id fields silently default to OperatorIdentity(null) — no validation in the @jsoncreator path; future hardening should fail this on purpose. Closes apache#4955
There was a problem hiding this comment.
Pull request overview
Adds a new ScalaTest spec to cover org.apache.texera.workflow.LogicalLink behaviors that are important for workflow graph correctness and JSON (de)serialization compatibility, without changing production code.
Changes:
- Introduces
LogicalLinkSpeccovering primary/secondary construction paths and case-class equality/hashCode semantics. - Adds Jackson-focused tests using
JSONUtils.objectMapper, including explicit coverage for current (non-)round-trip behavior and missing-field defaults.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4956 +/- ##
============================================
+ Coverage 42.75% 43.32% +0.56%
- Complexity 2197 2203 +6
============================================
Files 1045 1031 -14
Lines 40094 38221 -1873
Branches 4232 4018 -214
============================================
- Hits 17143 16560 -583
+ Misses 21887 20614 -1273
+ Partials 1064 1047 -17
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…eview Address Copilot feedback on apache#4956: - Replace the brittle `json.contains(...)` raw-string check on the writeValueAsString output with `objectMapper.readTree(json)` parse + structural assertions (`tree.path("fromOpId").isObject` / `path("id").asText() == "op-A"`). No longer depends on exact key ordering or escaping. - Drop the `node.set[ObjectNode](..., objectMapper.valueToTree(...))` pattern. The `[ObjectNode]` type parameter forces a runtime cast that assumes PortIdentity always serializes to an ObjectNode, which could throw ClassCastException if PortIdentity's serialization changes. Use `node.set("fromPortId", objectMapper.valueToTree[ JsonNode](...))` instead. - Replace `OperatorIdentity(null.asInstanceOf[String])` with the cleaner `link.fromOpId.id == null` assertion. Same intent (verify the op-id field is null after deserialization with missing JSON field), no `null.asInstanceOf[String]` noise.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot follow-up on apache#4956: - The @JsonProperty pin previously claimed "all four fields" but only fromOpId/toOpId actually carry the annotation. Split into two tests: one pinning the @JsonProperty-annotated op-id keys, and a separate one explicitly pinning that fromPortId/toPortId derive from Scala parameter names (no annotation). The second test makes the parameter-rename failure mode visible: a parameter rename without an accompanying @JsonProperty annotation would silently break saved workflows. The "writeValueAsString does NOT round-trip" thread is reconciled by updating the linked issue (apache#4955) body to clarify that the spec characterizes the current asymmetry rather than asserting a passing round-trip; the follow-up fix that adds a custom JsonDeserialize for fromOpId/toOpId would flip the characterization-pin into a real round-trip.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Yicong-Huang
left a comment
There was a problem hiding this comment.
Let's perform two easy fixes:
- self loop rejection
- empty/null opid rejection.
And create an issue to track the harder fix: asymmetrical serde.
Address PR review feedback: validate in the LogicalLink primary constructor that fromOpId / toOpId are non-null, non-empty, and distinct. Both construction paths (primary case-class + secondary @jsoncreator) now reject the three classes the reviewer flagged: - self-loop (fromOpId == toOpId) - null OperatorIdentity or OperatorIdentity wrapping null id - OperatorIdentity wrapping the empty string LogicalLinkSpec now asserts the new rejections instead of pinning them as "intentionally permissive" characterization tests. The harder writeValueAsString / readValue asymmetry is tracked separately in apache#5042; the existing characterization test now links the issue.
|
Thanks @Yicong-Huang — addressed all three asks in cd5bb17138:
Test count went from 12 → 18 (added 6 rejection tests across both construction paths and Jackson). Updated the PR title to Verified: |
…with test coverage) (apache#4956) ### What changes were proposed in this PR? Originally a test-only PR pinning `LogicalLink` behavior. Per review feedback from @Yicong-Huang, this PR now also tightens validation in `amber/src/main/scala/org/apache/texera/workflow/LogicalLink.scala`: | Surface | Behavior | | --- | --- | | Primary `LogicalLink` constructor | Rejects `null` `OperatorIdentity`, `OperatorIdentity(null)`, `OperatorIdentity("")`, and self-loops (`fromOpId == toOpId`). Throws `IllegalArgumentException`. | | Secondary `@JsonCreator` `(String, …, String, …)` overload | Same three rejections via the primary constructor's `require`. | | Jackson deserialization with missing `fromOpId` / `toOpId` | Wraps the `IllegalArgumentException` in `ValueInstantiationException` — no longer silently produces `OperatorIdentity(null)`. | ### Test surface pinned in `LogicalLinkSpec` | Surface | Pinned | | --- | --- | | Primary constructor | Four fields exposed as constructed. | | Secondary `@JsonCreator` constructor | Wraps raw `String` op-ids in `OperatorIdentity`; equal to a primary-constructor link with the same content. | | Case-class `equals` / `hashCode` | Structural equality across the four fields, plus distinguishing field-by-field (`fromOpId` mismatch, `toPortId.internal` mismatch). | | Identifier acceptance | Dashes, dots, digits accepted without normalization. | | **Self-loop rejection** | `fromOpId == toOpId` is now rejected from both construction paths (was previously characterized as "structurally allowed"). | | **Empty / null op-id rejection** | Empty string and null are now rejected from both paths (primary and `@JsonCreator`). | | **Missing-field rejection on Jackson read** | A JSON object with missing `fromOpId` / `toOpId` now throws `ValueInstantiationException` whose cause is `IllegalArgumentException` (was previously characterized as "silently defaults to `OperatorIdentity(null)`"). | | Jackson deserialization (`JSONUtils.objectMapper`) | `treeToValue` from a JSON object with raw-string op-ids dispatches to the `@JsonCreator` string overload and produces the expected fields. | | `@JsonProperty` JSON field names | `fromOpId` / `toOpId` pinned by `@JsonProperty`; `fromPortId` / `toPortId` derive from Scala parameter names (no annotation). Both pinned so a Scala-side rename can't silently break saved workflows. | | `writeValueAsString` ↔ `readValue` asymmetry | Now linked to follow-up issue apache#5042 (out of scope for this PR — a real fix requires either an additional `@JsonCreator` object overload or a custom `@JsonDeserialize`). When that fix lands, the existing characterization test flips to assert a passing round-trip alongside the fix. | ### Any related issues, documentation, discussions? Closes apache#4955. Spawns apache#5042 for the harder follow-up (asymmetric serde). ### How was this PR tested? ``` sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.workflow.LogicalLinkSpec" # → 18 tests, all pass sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.workflow.WorkflowCompilerSpec" # → 6 tests, all pass (regression check for callers constructing LogicalLink directly) sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.amber.engine.architecture.scheduling.CostBasedScheduleGeneratorSpec" # → 7 tests, all pass (regression check; this spec constructs many LogicalLinks) sbt "WorkflowExecutionService/Test/scalafmtCheck" "WorkflowExecutionService/scalafmtCheck" # → clean ``` ### Was this PR authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 4.7)
What changes were proposed in this PR?
Originally a test-only PR pinning
LogicalLinkbehavior. Per review feedback from @Yicong-Huang, this PR now also tightens validation inamber/src/main/scala/org/apache/texera/workflow/LogicalLink.scala:LogicalLinkconstructornullOperatorIdentity,OperatorIdentity(null),OperatorIdentity(""), and self-loops (fromOpId == toOpId). ThrowsIllegalArgumentException.@JsonCreator(String, …, String, …)overloadrequire.fromOpId/toOpIdIllegalArgumentExceptioninValueInstantiationException— no longer silently producesOperatorIdentity(null).Test surface pinned in
LogicalLinkSpec@JsonCreatorconstructorStringop-ids inOperatorIdentity; equal to a primary-constructor link with the same content.equals/hashCodefromOpIdmismatch,toPortId.internalmismatch).fromOpId == toOpIdis now rejected from both construction paths (was previously characterized as "structurally allowed").@JsonCreator).fromOpId/toOpIdnow throwsValueInstantiationExceptionwhose cause isIllegalArgumentException(was previously characterized as "silently defaults toOperatorIdentity(null)").JSONUtils.objectMapper)treeToValuefrom a JSON object with raw-string op-ids dispatches to the@JsonCreatorstring overload and produces the expected fields.@JsonPropertyJSON field namesfromOpId/toOpIdpinned by@JsonProperty;fromPortId/toPortIdderive from Scala parameter names (no annotation). Both pinned so a Scala-side rename can't silently break saved workflows.writeValueAsString↔readValueasymmetry@JsonCreatorobject overload or a custom@JsonDeserialize). When that fix lands, the existing characterization test flips to assert a passing round-trip alongside the fix.Any related issues, documentation, discussions?
Closes #4955.
Spawns #5042 for the harder follow-up (asymmetric serde).
How was this PR tested?
Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.7)