fix: include * where predicate#2858
Conversation
🦋 Changeset detectedLatest commit: 75e306a The changes in this PR will be included in the next version bump. This PR includes changesets to release 21 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughFixes wildcard predicate evaluation so Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/core/src/compute-view/deployment-view/predicates/utils.ts (1)
205-217:⚠️ Potential issue | 🔴 CriticalRemove cast and align implementation return type with overload promise.
The overload at line 205 advertises
(data: readonly E[]) => E[], but the implementation at line 214 returns((data: readonly E[]) => readonly E[])with a cast. Line 217 usesas readonly E[], which violates the "avoidascasts" guideline. Implement the promised mutable return directly:Suggested fix
): | boolean | readonly E[] - | ((data: readonly E[]) => readonly E[]) + | ((data: readonly E[]) => E[]) { if (args.length === 1) { - return x => applyElementPredicate(x, args[0]) as readonly E[] + const where = args[0] + return (x: readonly E[]) => x.filter(el => applyElementPredicate(el, where)) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/compute-view/deployment-view/predicates/utils.ts` around lines 205 - 217, The overload promises a mutable "(data: readonly E[]) => E[]" but the implementation returns a readonly array with an "as" cast; in applyElementPredicate change the args.length === 1 branch to return a function that converts the result into a mutable array instead of casting (e.g. return x => Array.from(applyElementPredicate(x, args[0])) ), so the returned type is E[] without using "as" casts and aligns with the declared overload for applyElementPredicate.
🧹 Nitpick comments (4)
packages/core/src/builder/_types.ts (1)
69-69: Extract and reuse a sharedtagstype alias across exported props.The same
tags?: [Tag, ...Tag[]]shape is duplicated in four exported prop types. Please centralize it into a single alias to avoid drift and keep the API surface easier to maintain.Proposed refactor
+type TagsProp<Tag> = [Tag, ...Tag[]] export type NewElementProps<Tag, Metadata> = { title?: string summary?: MarkdownOrString | string description?: MarkdownOrString | string technology?: string - tags?: [Tag, ...Tag[]] + tags?: TagsProp<Tag> metadata?: Metadata icon?: string ... } export type NewDeploymentNodeProps<Tag, Metadata> = { title?: string summary?: MarkdownOrString | string description?: MarkdownOrString | string technology?: string - tags?: [Tag, ...Tag[]] + tags?: TagsProp<Tag> metadata?: Metadata ... } export type NewViewProps<Tag> = { title?: string description?: MarkdownOrString | string - tags?: [Tag, ...Tag[]] + tags?: TagsProp<Tag> links?: Array<string | { title?: string; url: string }> } export type NewRelationProps<Kind, Tag, Metadata> = { kind?: Kind title?: string description?: MarkdownOrString | string technology?: string notes?: MarkdownOrString | string - tags?: [Tag, ...Tag[]] + tags?: TagsProp<Tag> metadata?: Metadata ... }As per coding guidelines, "Agent types and interfaces should be defined separately and reused across the codebase".
Also applies to: 94-94, 117-117, 127-127
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/builder/_types.ts` at line 69, Create a shared exported type alias like `Tags = [Tag, ...Tag[]]` and replace the duplicated inline `tags?: [Tag, ...Tag[]]` occurrences in the four exported prop types with `tags?: Tags`; update the four prop type declarations that currently use the inline tuple to reference `Tags` instead, and export the new `Tags` alias so other modules can reuse it (ensure the alias is declared near the other type definitions in _types.ts and run type checks to confirm no breaking changes).packages/core/src/compute-view/element-view/predicates/__test__/wildcard.spec.ts (2)
74-114: Add an imported-elementwhereregression.The changed unscoped
include * wherepath now walksmodel.elements()and splits imported vs. project elements, but this spec still covers imports only for bare*. A tagged imported descendant would exercise different logic, so it’s worth pinning with a dedicated case.Based on learnings, "Applies to **/*.spec.ts : Aim to cover new features with relevant tests; keep test names descriptive".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/compute-view/element-view/predicates/__test__/wildcard.spec.ts` around lines 74 - 114, The test suite lacks a case for an imported-element matched by an unscoped include '*' with a where clause; add a new spec similar to the existing "include * where" that uses TestHelper.from(builder.clone()) and t.processPredicates($rules($include('*', { where: 'tag is `#ui`' }))) but targets an imported descendant (e.g., an imported element with a tag) to exercise the split logic in the unscoped include implementation; ensure the new test asserts the expected elements and connections via t.expect(...).toHaveElements(...) and t.expect(...).toHaveNoConnections() and give it a descriptive name like "include * where imported element".
159-175: Rename theno matchescase.There is still a
#mobiledescendant undercloud, so the current title reads like a data contradiction. Calling out “no matching direct children” or the fallback behavior would make failures easier to interpret.Based on learnings, "Applies to **/*.spec.ts : Aim to cover new features with relevant tests; keep test names descriptive".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/compute-view/element-view/predicates/__test__/wildcard.spec.ts` around lines 159 - 175, Rename the test case description to accurately reflect that there are no matching direct children under 'cloud' rather than no matches at all; update the it(...) string currently reading "include * in cloud where tag is `#mobile` (no matches)" to something like "include * in cloud where tag is `#mobile` (no matching direct children; matches descendants/fallback)" so the behavior exercised by TestHelper.from(builder.clone()), processPredicatesWithScope('cloud', $include('*', { where: 'tag is `#mobile`' })) and the subsequent expectations (t.expect(...).toHaveElements / toHaveConnections) is clearly documented.packages/core/src/compute-view/deployment-view/predicates/__test__/wildcard.filter.spec.ts (1)
85-93: Also assert edges forkind is nd.This case exercises the new root-only
whereconnection path, but it currently locks in nodes only. Adding the expected edges would protect the behavioral change inWildcardPredicate.include, not just the selection set.Based on learnings, "Applies to **/*.spec.ts : Aim to cover new features with relevant tests; keep test names descriptive".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/compute-view/deployment-view/predicates/__test__/wildcard.filter.spec.ts` around lines 85 - 93, The test currently asserts only nodes for the $include('*', { where: 'kind is nd' }) case via t.expectComputedView(...).toHaveNodes(...); add a complementary assertion that checks the edges produced by this root-only where connection path by calling t.expectComputedView($include('*', { where: 'kind is nd' })).toHaveEdges(...) and list the expected connections (e.g. edges showing prod->prod.infra, prod->prod.z1 and root-level connections to customer and global) so the spec for WildcardPredicate.include verifies both the selection set and the resulting edges.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@devops/vitest.ts`:
- Around line 10-14: The ssr.resolve.conditions setting is placed under ssr and
thus only affects SSR mode; move the array from ssr.resolve.conditions into the
top-level resolve.conditions in the shared defineVitest() config so module
resolution applies to all test runs (e.g., change the config to use resolve: {
conditions: ['sources'], ... } and remove the nested ssr.resolve.conditions
entry).
---
Outside diff comments:
In `@packages/core/src/compute-view/deployment-view/predicates/utils.ts`:
- Around line 205-217: The overload promises a mutable "(data: readonly E[]) =>
E[]" but the implementation returns a readonly array with an "as" cast; in
applyElementPredicate change the args.length === 1 branch to return a function
that converts the result into a mutable array instead of casting (e.g. return x
=> Array.from(applyElementPredicate(x, args[0])) ), so the returned type is E[]
without using "as" casts and aligns with the declared overload for
applyElementPredicate.
---
Nitpick comments:
In `@packages/core/src/builder/_types.ts`:
- Line 69: Create a shared exported type alias like `Tags = [Tag, ...Tag[]]` and
replace the duplicated inline `tags?: [Tag, ...Tag[]]` occurrences in the four
exported prop types with `tags?: Tags`; update the four prop type declarations
that currently use the inline tuple to reference `Tags` instead, and export the
new `Tags` alias so other modules can reuse it (ensure the alias is declared
near the other type definitions in _types.ts and run type checks to confirm no
breaking changes).
In
`@packages/core/src/compute-view/deployment-view/predicates/__test__/wildcard.filter.spec.ts`:
- Around line 85-93: The test currently asserts only nodes for the $include('*',
{ where: 'kind is nd' }) case via t.expectComputedView(...).toHaveNodes(...);
add a complementary assertion that checks the edges produced by this root-only
where connection path by calling t.expectComputedView($include('*', { where:
'kind is nd' })).toHaveEdges(...) and list the expected connections (e.g. edges
showing prod->prod.infra, prod->prod.z1 and root-level connections to customer
and global) so the spec for WildcardPredicate.include verifies both the
selection set and the resulting edges.
In
`@packages/core/src/compute-view/element-view/predicates/__test__/wildcard.spec.ts`:
- Around line 74-114: The test suite lacks a case for an imported-element
matched by an unscoped include '*' with a where clause; add a new spec similar
to the existing "include * where" that uses TestHelper.from(builder.clone()) and
t.processPredicates($rules($include('*', { where: 'tag is `#ui`' }))) but targets
an imported descendant (e.g., an imported element with a tag) to exercise the
split logic in the unscoped include implementation; ensure the new test asserts
the expected elements and connections via t.expect(...).toHaveElements(...) and
t.expect(...).toHaveNoConnections() and give it a descriptive name like "include
* where imported element".
- Around line 159-175: Rename the test case description to accurately reflect
that there are no matching direct children under 'cloud' rather than no matches
at all; update the it(...) string currently reading "include * in cloud where
tag is `#mobile` (no matches)" to something like "include * in cloud where tag is
`#mobile` (no matching direct children; matches descendants/fallback)" so the
behavior exercised by TestHelper.from(builder.clone()),
processPredicatesWithScope('cloud', $include('*', { where: 'tag is `#mobile`' }))
and the subsequent expectations (t.expect(...).toHaveElements /
toHaveConnections) is clearly documented.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6cac8767-6e92-4b60-bf7d-f0eac321f8f4
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (16)
.changeset/fix-wildcard-predicate.md.oxlintrc.jsondevops/vitest.tspackage.jsonpackages/config/scripts/tsconfig.jsonpackages/core/src/builder/_types.tspackages/core/src/compute-view/deployment-view/predicates/__test__/wildcard.filter.spec.tspackages/core/src/compute-view/deployment-view/predicates/deploymentRefs-where.tspackages/core/src/compute-view/deployment-view/predicates/utils.tspackages/core/src/compute-view/deployment-view/predicates/wildcard.tspackages/core/src/compute-view/element-view/__test__/TestHelper.tspackages/core/src/compute-view/element-view/__test__/wildcard-expr.spec.tspackages/core/src/compute-view/element-view/predicates/__test__/wildcard.spec.tspackages/core/src/compute-view/element-view/predicates/wildcard.tspnpm-workspace.yamlvitest.config.ts
💤 Files with no reviewable changes (1)
- vitest.config.ts
Fix predicate evaluation for wildcard expressions with
where.Previously,
include * wherewas applying filter to the root elements (or children inside scoped view).Now it applies the filter to all elements, to match the wildcard semantics.
Fixes #2837