-
Notifications
You must be signed in to change notification settings - Fork 304
[TV] Fix search failing on unknown combined-search result types #5745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sztomek
wants to merge
2
commits into
main
Choose a base branch
from
fix/tv-search-network-crash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...src/test/kotlin/au/com/shiftyjelly/pocketcasts/servers/search/AutoCompleteResponseTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package au.com.shiftyjelly.pocketcasts.servers.search | ||
|
|
||
| import com.squareup.moshi.Moshi | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
|
|
||
| class AutoCompleteResponseTest { | ||
| private val adapter = Moshi.Builder() | ||
| .add(AutoCompleteResult.jsonAdapter) | ||
| .build() | ||
| .adapter(AutoCompleteResponse::class.java) | ||
|
|
||
| @Test | ||
| fun `unknown result types map to Unknown without failing the whole response`() { | ||
| val response = adapter.fromJson( | ||
| """ | ||
| {"results":[ | ||
| {"value":"freakonomics","type":"term"}, | ||
| {"value":{"uuid":"p1","title":"Freakonomics Radio"},"type":"podcast"}, | ||
| {"value":"anything","type":"network"} | ||
| ]} | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val types = response?.results?.map { it::class.simpleName } | ||
| assertEquals(listOf("TermResult", "PodcastResult", "Unknown"), types) | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
...c/test/kotlin/au/com/shiftyjelly/pocketcasts/servers/search/CombinedSearchResponseTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package au.com.shiftyjelly.pocketcasts.servers.search | ||
|
|
||
| import com.squareup.moshi.Moshi | ||
| import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter | ||
| import java.util.Date | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
|
|
||
| class CombinedSearchResponseTest { | ||
| private val adapter = Moshi.Builder() | ||
| .add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe()) | ||
| .add(CombinedResult.jsonAdapter) | ||
| .build() | ||
| .adapter(CombinedSearchResponse::class.java) | ||
|
|
||
| @Test | ||
| fun `unknown result types map to Unknown without failing the whole response`() { | ||
| val response = adapter.fromJson( | ||
| """ | ||
| {"results":[ | ||
| {"uuid":"p1","title":"Freakonomics Radio","slug":"freakonomics-radio","type":"podcast"}, | ||
| {"uuid":"n1","title":"Some Network","type":"network"}, | ||
| {"uuid":"p2","title":"Another Show","slug":"another-show","type":"podcast"} | ||
| ]} | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val types = response?.results?.map { it::class.simpleName } | ||
| assertEquals(listOf("PodcastResult", "Unknown", "PodcastResult"), types) | ||
| } | ||
|
sztomek marked this conversation as resolved.
sztomek marked this conversation as resolved.
|
||
|
|
||
| @Test | ||
| fun `registered podcast and episode subtypes decode alongside the fallback`() { | ||
| val response = adapter.fromJson( | ||
| """ | ||
| {"results":[ | ||
| {"uuid":"p1","title":"Freakonomics Radio","slug":"freakonomics-radio","type":"podcast"}, | ||
| {"uuid":"e1","title":"Ep 1","url":"https://example.com/1.mp3","published_date":"2024-01-02T03:04:05Z","podcast_uuid":"p1","podcast_title":"Freakonomics Radio","podcast_slug":"freakonomics-radio","type":"episode"}, | ||
| {"uuid":"n1","title":"Some Network","type":"network"} | ||
| ]} | ||
| """.trimIndent(), | ||
| ) | ||
|
|
||
| val types = response?.results?.map { it::class.simpleName } | ||
| assertEquals(listOf("PodcastResult", "EpisodeResult", "Unknown"), types) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change —
slugandpodcastSlugare read by nobody (ImprovedSearchManagerImpl.kt:37-61ignores both, and there are no other consumers ofCombinedResult), so requiring them was pure downside.One caveat on how far a Kotlin default actually protects you: Moshi's generated adapter uses the default only when the key is absent. If the server sends
"slug": nullexplicitly, codegen still hitsUtil.unexpectedNull(...)and throwsJsonDataException: Non-null value 'slug' was null at $.results[N], which aborts the whole response exactly like the old bug.String? = nullcovers both the absent and explicit-null cases;String = ""covers only the first. Given the motivation here is "one weird result shouldn't wipe out the search", nullable is the stronger guarantee.Related, and the same argument as
slug:url(line 29) is still non-null-required and is likewise never read by any consumer.title/podcastUuid/podcastTitleare at least consumed, though it's a bit asymmetric thatPodcastResult.titleis nullable-and-filtered (ImprovedSearchManagerImpl.kt:40) whileEpisodeResult.titlehard-fails the response.Not blocking — the PR's stated bug is fixed either way.
Fix this →