Skip to content

fix(@angular-devkit/schematics): support delegating trees in filter and partition - #34539

Closed
Thanatos9404 wants to merge 3 commits into
angular:mainfrom
Thanatos9404:fix/schematics-filter-delegate-tree
Closed

Thanatos9404 wants to merge 3 commits into
angular:mainfrom
Thanatos9404:fix/schematics-filter-delegate-tree

Conversation

@Thanatos9404

@Thanatos9404 Thanatos9404 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Checklist

Please check to confirm your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

filter() only accepts a HostTree and throws "Tree type is not supported." for anything else. A UnitTestTree is a DelegateTree around a HostTree, so a schematic that uses filter() fails in unit tests when it runs on the tree returned by an earlier runSchematic call.

Issue Number: #26000

What is the new behavior?

filter() and partition() (behind partitionApplyMerge) call branch() on a delegating tree first, which returns a branch of the HostTree it wraps. Other tree types still throw as before.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

The new specs in base_spec.ts cover filter on a plain HostTree (it had no spec) and filter and partitionApplyMerge on a nested UnitTestTree, since runSchematic returns a UnitTestTree around another one when the schematic edits its input tree in place. Locally, the UnitTestTree specs fail on main with "Tree type is not supported." and pass with this change, and the 86 specs under src/rules and src/tree pass (run with jasmine, not Bazel).

Closes #26000

…ter` rule

`filter()` only accepted a `HostTree` and threw "Tree type is not supported." for any other tree.
A `UnitTestTree` is a `DelegateTree` around a `HostTree`, so a schematic that uses `filter()` failed
in unit tests when run on the tree returned by a previous `runSchematic` call. Unwrap delegating
trees and filter the `HostTree` they wrap.

Closes angular#26000

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the filter rule in Angular Devkit Schematics to support DelegateTree wrappers (such as UnitTestTree) by recursively unwrapping them to access the underlying HostTree. It also adds corresponding unit tests to verify this behavior. The review feedback suggests a minor improvement to type safety by using an intersection cast (DelegateTree & { _other: Tree }) instead of casting to unknown first when accessing the private _other property.

Comment thread packages/angular_devkit/schematics/src/rules/base.ts Outdated
Comment thread packages/angular_devkit/schematics/src/rules/base.ts Outdated
@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Oct 27, 2026
`partition()`, which backs the `partitionApplyMerge` rule, threw "Tree type is not supported."
for a `UnitTestTree` and other delegating trees. Branch the tree they wrap instead, as
`filter()` does.
@Thanatos9404 Thanatos9404 changed the title fix(@angular-devkit/schematics): support delegating trees in the filter rule fix(@angular-devkit/schematics): support delegating trees in filter and partition Oct 27, 2026

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Oct 27, 2026
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

alan-agius4 pushed a commit that referenced this pull request Oct 27, 2026
…ter` rule (#34539)

`filter()` only accepted a `HostTree` and threw "Tree type is not supported." for any other tree.
A `UnitTestTree` is a `DelegateTree` around a `HostTree`, so a schematic that uses `filter()` failed
in unit tests when run on the tree returned by a previous `runSchematic` call. Unwrap delegating
trees and filter the `HostTree` they wrap.

Closes #26000

PR Close #34539
alan-agius4 pushed a commit that referenced this pull request Oct 27, 2026
…on` (#34539)

`partition()`, which backs the `partitionApplyMerge` rule, threw "Tree type is not supported."
for a `UnitTestTree` and other delegating trees. Branch the tree they wrap instead, as
`filter()` does.

PR Close #34539
angular-robot pushed a commit to angular-robot/angular-cli that referenced this pull request Oct 27, 2026
…on` (angular#34539)

`partition()`, which backs the `partitionApplyMerge` rule, threw "Tree type is not supported."
for a `UnitTestTree` and other delegating trees. Branch the tree they wrap instead, as
`filter()` does.

PR Close angular#34539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular-devkit/schematics target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filter does not work in UnitTestTree

2 participants