fix(frontend): reject null payloads in dashboard type predicates#6443
Open
eugenegujing wants to merge 1 commit into
Open
fix(frontend): reject null payloads in dashboard type predicates#6443eugenegujing wants to merge 1 commit into
eugenegujing wants to merge 1 commit into
Conversation
Add an `isNonNullObject` guard to `common/util/predicate.ts` (with a new predicate.spec.ts, which also covers the previously untested `isDefined`), use it in the four object-payload guards, and switch all five guards to `!!value` so they always return strict booleans. `isDashboardProject`'s `!value.workflow` exclusion is deliberately unchanged. Spec updated: the four "(current behavior)" null-payload pins now assert false; the 5x5 cross-classification matrix and its 25 expected values are untouched, so no realistic entry changes classification. Fixes apache#6439
Contributor
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6443 +/- ##
============================================
- Coverage 70.17% 70.17% -0.01%
Complexity 3388 3388
============================================
Files 1142 1142
Lines 44844 44846 +2
Branches 4949 4950 +1
============================================
+ Hits 31471 31472 +1
Misses 11739 11739
- Partials 1634 1635 +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?
The five type guards in
dashboard/type/type-predicates.tschecked their nested payload withtypeof value.<field> === "object", which also accepts null becausetypeof null === "object"in JavaScript, so an entry like{workflow: null}passedisDashboardWorkflowand theDashboardEntryconstructor then crashed with an unrelatedTypeError: Cannot read properties of nullwhile dereferencing the payload, instead of reaching its intentional"Unexpected type in DashboardEntry."error path. The guards also returned the falsy input itself rather thanfalsefor null/undefined input, violating their declared boolean type-guard signatures.This PR adds an
isNonNullObjecttype guard (typeof x === "object" && x !== null) to the shared predicate utility (common/util/predicate.ts, next toisDefined) 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.workflowexclusion is deliberately unchanged: a nullworkflowfield means "no workflow data", so an object with a stringnamestill classifies as a project and no valid entry changes classification.Any related issues, documentation, discussions?
Fixes #6439. The buggy behavior was pinned by the five "(current behavior)" tests added in #6425 (issue #6400), which this PR flips to assert the corrected behavior.
How was this PR tested?
Added
predicate.spec.ts(8 tests) coveringisNonNullObjectand the previously untestedisDefined. Updatedtype-predicates.spec.ts: the four null-payload pins now asserttoBe(false), the null/undefined input cases are tightened fromtoBeFalsy()totoBe(false), and theisDashboardProjectnull-workflow case keeps assertingtruewith 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 viayarn 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), andtsc --noEmitwith zero errors.Was this PR authored or co-authored using generative AI tooling?
Co-authored using Claude Code(Fable 5).