Skip to content

feat(amber): reject self-loops and empty/null op-ids in LogicalLink (with test coverage) - #4956

Merged
aglinxinyuan merged 7 commits into
apache:mainfrom
aglinxinyuan:test-logical-link-spec
May 13, 2026
Merged

aglinxinyuan merged 7 commits into
apache:mainfrom
aglinxinyuan:test-logical-link-spec

Conversation

@aglinxinyuan

@aglinxinyuan aglinxinyuan commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

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 #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 #4955.
Spawns #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)

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
Copilot AI review requested due to automatic review settings May 5, 2026 22:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 LogicalLinkSpec covering 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-commenter

codecov-commenter commented May 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 43.32%. Comparing base (df23815) to head (46054e8).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...scala/org/apache/texera/workflow/LogicalLink.scala 88.88% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ *Carryforward flag
access-control-service 39.53% <ø> (ø) Carriedforward from c1a8d0f
agent-service 33.72% <ø> (ø) Carriedforward from c1a8d0f
amber 43.59% <88.88%> (+<0.01%) ⬆️
computing-unit-managing-service 0.00% <ø> (ø) Carriedforward from c1a8d0f
config-service 0.00% <ø> (ø) Carriedforward from c1a8d0f
file-service 32.18% <ø> (ø) Carriedforward from c1a8d0f
frontend 34.28% <ø> (+0.35%) ⬆️ Carriedforward from c1a8d0f
python 88.89% <ø> (+0.04%) ⬆️ Carriedforward from c1a8d0f
workflow-compiling-service 47.72% <ø> (ø) Carriedforward from c1a8d0f

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@aglinxinyuan
aglinxinyuan requested a review from Yicong-Huang May 5, 2026 23:27

@Yicong-Huang Yicong-Huang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@aglinxinyuan aglinxinyuan changed the title test(amber): add unit test coverage for LogicalLink feat(amber): reject self-loops and empty/null op-ids in LogicalLink (with test coverage) May 13, 2026
@aglinxinyuan

Copy link
Copy Markdown
Contributor Author

Thanks @Yicong-Huang — addressed all three asks in cd5bb17138:

Request Resolution
Self-loop rejection Added require(fromOpId != toOpId, …) to the primary constructor; throws IllegalArgumentException. Covered by tests on both construction paths.
Empty / null op-id rejection Added require(fromOpId != null && fromOpId.id != null && fromOpId.id.nonEmpty, …) (same for toOpId). Covered by primary-constructor and @JsonCreator tests. Jackson's missing-field path now also throws (wrapped in ValueInstantiationException).
Asymmetric serde follow-up Filed #5042 (Bug). The existing characterization test now links the issue and notes it must flip to a passing round-trip when the fix lands.

Test count went from 12 → 18 (added 6 rejection tests across both construction paths and Jackson). Updated the PR title to feat(amber): … since this no longer is test-only.

Verified:

sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.workflow.LogicalLinkSpec" # 18 pass
sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.workflow.WorkflowCompilerSpec" # 6 pass (regression)
sbt "WorkflowExecutionService/Test/testOnly org.apache.texera.amber.engine.architecture.scheduling.CostBasedScheduleGeneratorSpec" # 7 pass (regression — many LogicalLinks)
sbt "WorkflowExecutionService/Test/scalafmtCheck" "WorkflowExecutionService/scalafmtCheck" # clean

@aglinxinyuan
aglinxinyuan enabled auto-merge (squash) May 13, 2026 05:19
@aglinxinyuan
aglinxinyuan merged commit 4862b92 into apache:main May 13, 2026
13 checks passed
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…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)
@aglinxinyuan
aglinxinyuan deleted the test-logical-link-spec branch October 21, 2026 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit test coverage for LogicalLink

4 participants