fix(frontend, v1.2): reject null payloads in dashboard type predicates - #7010
Open
Yicong-Huang wants to merge 1 commit into
Open
Conversation
…che#6443) ### What changes were proposed in this PR? The five type guards in `dashboard/type/type-predicates.ts` checked their nested payload with `typeof value.<field> === "object"`, which also accepts null because `typeof null === "object"` in JavaScript, so an entry like `{workflow: null}` passed `isDashboardWorkflow` and the `DashboardEntry` constructor then crashed with an unrelated `TypeError: Cannot read properties of null` while dereferencing the payload, instead of reaching its intentional `"Unexpected type in DashboardEntry."` error path. The guards also returned the falsy input itself rather than `false` for null/undefined input, violating their declared boolean type-guard signatures. This PR adds an `isNonNullObject` type guard (`typeof x === "object" && x !== null`) to the shared predicate utility (`common/util/predicate.ts`, next to `isDefined`) so the correct non-null object check is discoverable and reusable, uses it in the four object-payload guards, and switches all five guards to `!!value && ...` so they return strict booleans in every path. `isDashboardProject`'s `!value.workflow` exclusion is deliberately unchanged: a null `workflow` field means "no workflow data", so an object with a string `name` still classifies as a project and no valid entry changes classification. ### Any related issues, documentation, discussions? Fixes apache#6439. The buggy behavior was pinned by the five "(current behavior)" tests added in apache#6425 (issue apache#6400), which this PR flips to assert the corrected behavior. ### How was this PR tested? Added `predicate.spec.ts` (8 tests) covering `isNonNullObject` and the previously untested `isDefined`. Updated `type-predicates.spec.ts`: the four null-payload pins now assert `toBe(false)`, the null/undefined input cases are tightened from `toBeFalsy()` to `toBe(false)`, and the `isDashboardProject` null-workflow case keeps asserting `true` with a comment marking it as an intentional decision; the 5x5 cross-classification matrix and all of its 25 expected values are untouched, confirming that classification of realistic entries is unaffected. Ran locally via `yarn ng test --watch=false --include='**/common/util/predicate.spec.ts' --include='**/dashboard/type/type-predicates.spec.ts'` (61/61 pass), plus the full frontend suite whose failure set is identical to the unmodified main baseline (pre-existing, environment-related failures only), and `tsc --noEmit` with zero errors. ### Was this PR authored or co-authored using generative AI tooling? Co-authored using Claude Code(Fable 5). --------- (backported from commit a4e03e4) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Automated Reviewer SuggestionsBased on the
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release/v1.2 #7010 +/- ##
==================================================
+ Coverage 53.95% 53.99% +0.04%
Complexity 1441 1441
==================================================
Files 809 809
Lines 34144 34146 +2
Branches 3448 3449 +1
==================================================
+ Hits 18421 18438 +17
+ Misses 14815 14801 -14
+ Partials 908 907 -1
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this PR?
Backport of #6443 to
release/v1.2, cherry-picked from a4e03e4.Source fix only. Test changes from #6443 were omitted (the touched specs do not exist on
release/v1.2or depend on main-only test infrastructure); only the source fix is carried over, per maintainer guidance.Any related issues, documentation, discussions?
Backport of #6443. Originally linked #6439.
How was this PR tested?
Release-branch CI runs on this PR. Source change cherry-picked cleanly; test changes intentionally dropped.
Was this PR authored or co-authored using generative AI tooling?
Yes — backport prepared with Claude Code (mechanical cherry-pick + conflict resolution; the change itself is #6443 by its original author).
🤖 Generated with Claude Code