Skip to content

refactor(frontend): remove two pieces of unreachable code - #7512

Open
Raja-Hamid wants to merge 2 commits into
apache:mainfrom
Raja-Hamid:refactor/remove-unreachable-code
Open

refactor(frontend): remove two pieces of unreachable code#7512
Raja-Hamid wants to merge 2 commits into
apache:mainfrom
Raja-Hamid:refactor/remove-unreachable-code

Conversation

@Raja-Hamid

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Removes two pieces of unreachable code, each surfaced by a surviving mutation — i.e. each was demonstrated to have no observable effect, not merely suspected. No user-facing behavior changes, hence refactor.

1. hugging-face-image-upload.component.html — an unreachable fallback

-<span>{{ displayFileName || "Selected image" }}</span>
+<span>{{ displayFileName }}</span>

The enclosing block is *ngIf="previewSrc", and previewSrc returns this.hasImage ? this.formControl.value : "" — so it is non-empty exactly when hasImage is true. displayFileName returns fileName or, failing that, "Uploaded image" whenever hasImage is true. It is therefore never empty where this renders, and the right-hand side of the || can never be evaluated.

2. drag-drop.service.ts — a guard subsumed by the next one

 const jointLink = paper.getModelById(link.linkID) as joint.dia.Link;
-if (!jointLink) {
-  continue;
-}
-
 const linkView = paper.findViewByModel(jointLink) as joint.dia.LinkView;
 if (!linkView) {
   continue;
 }

findViewByModel in jointjs 3.5.4 resolves its argument with (isString(cell) || isNumber(cell)) ? cell : (cell && cell.id) and returns this._views[id]. The cell && cell.id short-circuits on undefined, so the call returns undefined rather than throwing, and the !linkView guard already catches everything !jointLink did.

Worth noting for reviewers: this guard was not meaningless. findIntersectedLink iterates the Texera graph but resolves each link against the JointJS paper, and those two can genuinely diverge, so getModelById really can return undefined at runtime. That path is still handled, just one guard later. (The as joint.dia.Link cast is what hides the undefined case from the type checker.)

No screenshots: neither change alters rendered output or behavior, that is precisely the claim under test.

Any related issues, documentation, discussions?

Closes #7459

How was this PR tested?

Because this is a refactor with no behavior change, the removed branches cannot be driven red by definition. Instead, two regression guards were added that pass both before and after the removals, pinning the behavior the removals must preserve:

- hugging-face-image-upload.component.spec.ts, an image with no filename renders exactly Uploaded image; a known filename renders instead; and with no image the preview block does not render at all, so the label is never empty.
- drag-drop.service.spec.ts, a link present in the Texera graph but with no model in the JointJS paper is skipped: findIntersectedLink returns null and does not throw. (Removing both guards makes this fail on linkView.el, so it genuinely pins the path.)

corepack yarn ng test --watch=false \
  --include="**/hugging-face-image-upload.component.spec.ts" \
  --include="**/drag-drop.service.spec.ts"

- Against unmodified source: 2 files, 56/56 passing — the new guards are green before any code is touched.
- After both removals: 2 files, 56/56 passing, with no assertion edits.

Wider sweep, adding the specs for the formly config that registers the component:

corepack yarn ng test --watch=false \
  --include="**/formly*.spec.ts" \
  --include="**/hugging-face-image-upload.component.spec.ts" \
  --include="**/drag-drop.service.spec.ts"
→ 4 files, 83/83 passing

yarn prettier-eslint reports all four touched files unchanged.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Yes alongside Claude Code.

Both branches were shown by mutation testing to have no observable effect:
each mutation survived while the surrounding behaviour was under test.

- hugging-face-image-upload: the "Selected image" fallback rendered inside
  *ngIf="previewSrc", which is non-empty only when hasImage is true, and
  displayFileName already returns "Uploaded image" in exactly that case, so
  the right-hand side of the || could never be evaluated.
- drag-drop: the !jointLink guard was subsumed by the !linkView guard that
  follows it, since paper.findViewByModel(undefined) returns undefined
  rather than throwing.

Regression tests pin both behaviours -- the rendered preview label, and
skipping a link that exists in the Texera graph but has no model in the
JointJS paper -- and stay green across the removals.

Closes apache#7459
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for opening this pull request, @Raja-Hamid!

It looks like the pull request description doesn't quite follow our template yet:

  • The How was this PR tested? section is missing; please keep the template's headings.
  • The Was this PR authored or co-authored using generative AI tooling? section is missing; please keep the template's headings.

Filling out the template helps reviewers understand and triage your contribution faster. Please edit the description to complete it. This message will disappear automatically once the template is followed.

You can find the template prompts by editing the description, or see CONTRIBUTING.md for the full contribution flow.

@github-actions github-actions Bot added refactor Refactor the code frontend Changes related to the frontend GUI labels Aug 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @PG1204, @mengw15, @aglinxinyuan
    You can notify them by mentioning @PG1204, @mengw15, @aglinxinyuan in a comment.

@Raja-Hamid

Copy link
Copy Markdown
Contributor Author

Hey @aglinxinyuan, Need your review on this.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.40%. Comparing base (42d08a3) to head (8e13591).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #7512      +/-   ##
============================================
+ Coverage     86.38%   86.40%   +0.01%     
  Complexity     4211     4211              
============================================
  Files          1169     1169              
  Lines         46750    46748       -2     
  Branches       5203     5201       -2     
============================================
+ Hits          40387    40391       +4     
+ Misses         4641     4635       -6     
  Partials       1722     1722              
Flag Coverage Δ *Carryforward flag
access-control-service 70.00% <ø> (ø) Carriedforward from 42d08a3
agent-service 86.87% <ø> (ø) Carriedforward from 42d08a3
amber 81.87% <ø> (ø) Carriedforward from 42d08a3
computing-unit-managing-service 50.72% <ø> (ø) Carriedforward from 42d08a3
config-service 65.97% <ø> (ø) Carriedforward from 42d08a3
file-service 69.05% <ø> (ø) Carriedforward from 42d08a3
frontend 89.26% <100.00%> (+0.02%) ⬆️
notebook-migration-service 78.89% <ø> (ø) Carriedforward from 42d08a3
pyamber 97.56% <ø> (ø) Carriedforward from 42d08a3
workflow-compiling-service 26.31% <ø> (ø) Carriedforward from 42d08a3

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

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aglinxinyuan
aglinxinyuan requested a lite review from Copilot August 10, 2026 19:09

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@aglinxinyuan

Copy link
Copy Markdown
Contributor

👋 Thanks for opening this pull request, @Raja-Hamid!

It looks like the pull request description doesn't quite follow our template yet:

  • The How was this PR tested? section is missing; please keep the template's headings.
  • The Was this PR authored or co-authored using generative AI tooling? section is missing; please keep the template's headings.

Filling out the template helps reviewers understand and triage your contribution faster. Please edit the description to complete it. This message will disappear automatically once the template is followed.

You can find the template prompts by editing the description, or see CONTRIBUTING.md for the full contribution flow.

@Raja-Hamid please address this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Changes related to the frontend GUI refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants