The answer is the answer to this post.
Basically all my tests with flows would have worked. The problem was that I wasn't applying a singleton from the repository (I also tried using a localdatasource at startup but I wanted to remove a level to make testing easier, with the same problem, of course).
So when I debugged adding new tasks it was true that the StateFlow stored the new tasks correctly, but the flow I got in getTask was a different flow from a different instance of TaskRepository.
I was using two data sources of which one was getting and the other one was updating being totally independent.
Once I added the @Singleton tag in the hilt provider of the repository everything worked correctly.
@InstallIn(SingletonComponent::class)
@Module
class DataModule() {
@Singleton // This was the fix
@Provides
fun provideTaskRepository(localDataSource: TaskLocalDataSource): TaskRepository =
TaskRepositoryImpl(localDataSource)
}
PD: ty @MichalP