Add expectCovariantWorkflow for expecting via workflow classes that have generics #1329
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.
Recently we removed the
in PropsTandout OutputTdeclaration site variance specifications due to theUnsafeVarianceusage we had withinRenderContextand the fact that Kotlin 2+ no longer allowed this (see #1320 && #1328).However, any
expectWorkflow( workflowType = SomeWorkflowType::class)calls whereSomeWorkflowTypewas an interface or class that still contained generics (rather than fully specified types), was failing to compile. It simply reported an expectation ofNothing- which is not a helpful compiler error really that I could find. The problem though, was that these types could no longer be covariant through theOutputThierarchy. As such, I have added anexpectCovariantWorkflowwhere the class can be a supertype that includes generics, but thechildOutputTypeandchildRenderingTypemust be specified directly withKTypeand then these are verified against the workflow invocations.So far, we have mainly seen this be a problem when there is a factory constructing child workflow instances and the tests do not have access to those instances (or a good class type) in order to expect them.
So this adds a new testing API -
expectCovariantWorkflowwhere the base class, and theOutputTKTypeandRenderingTKTypeare all specified explicitly so they can be matched.There are still scenarios where the type system can't keep up - namely if you have nested generics in your generic types. I still do not totally understand when the
RenderTesterChildRenderInvocationwill successfully and won't successfully determine these types (I have seen both). I have not gotten to the bottom of that, but instead preferred to provide an 'opt-out' of nested generic verification as is needed.To make it easier to work with these edge cases I added a parameter to specify the levels of recursive verification to do on generics.