Skip to content

Conversation

@steve-the-edwards
Copy link
Contributor

@steve-the-edwards steve-the-edwards commented May 28, 2025

Recently we removed the in PropsT and out OutputT declaration site variance specifications due to the UnsafeVariance usage we had within RenderContext and the fact that Kotlin 2+ no longer allowed this (see #1320 && #1328).

However, any expectWorkflow( workflowType = SomeWorkflowType::class) calls where SomeWorkflowType was an interface or class that still contained generics (rather than fully specified types), was failing to compile. It simply reported an expectation of Nothing - 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 the OutputT hierarchy. As such, I have added an expectCovariantWorkflow where the class can be a supertype that includes generics, but the childOutputType and childRenderingType must be specified directly with KType and 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 - expectCovariantWorkflow where the base class, and the OutputT KType and RenderingT KType are 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 RenderTester ChildRenderInvocation will 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.

@steve-the-edwards steve-the-edwards force-pushed the sedwards/expect-workflow branch 3 times, most recently from 1b767b0 to d4e710c Compare May 28, 2025 18:31
@steve-the-edwards steve-the-edwards force-pushed the sedwards/expect-workflow branch from d4e710c to 2a405c5 Compare May 29, 2025 18:25
@steve-the-edwards steve-the-edwards marked this pull request as ready for review May 29, 2025 18:30
@steve-the-edwards steve-the-edwards changed the title Add expectCovariantWorkflow for generic type specification Add expectCovariantWorkflow for expecting via workflow classes that have generics May 29, 2025
Updating grammar in the kdoc.

Co-authored-by: Ray Ryan <[email protected]>
@steve-the-edwards steve-the-edwards merged commit f21e91c into main May 29, 2025
44 checks passed
@steve-the-edwards steve-the-edwards deleted the sedwards/expect-workflow branch May 29, 2025 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants