Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
Closes #1251.
Every unit test needing an Apify client ended its stub with the same
as unknown ascast. That cast silently breaks whenApifyClientchanges, and it appeared in 42 places across 23 files. The issue says 32 across 16: it undercounts because it only counts theInternalToolArgs['apifyClient']spelling and not theApifyClientone. Both resolve to the same type (src/types.ts:178), so one helper covers both.What changed
mockApifyClient()intests/unit/helpers/tool_context.tsholds the cast. Call sites keep their own factories, resource behavior, and spies, so what each tool is expected to reach for stays visible in the test.tests/unitnow holds exactly one Apify client cast, inside the helper.It returns
ApifyClientrather than theInternalToolArgs['apifyClient']alias the issue names: identical type, but most consumers are not tool tests, where the derived alias only read as indirection.helpers/schedule_client.tsandhelpers/task_client.tsdelegate too. They already centralized a cast each, but leaving them meant two survived outside the shared helper, so "centralized" would not have been true.This buys no type safety at call sites. A wrong stub shape still compiles. The win is one unsafe cast to reason about instead of 42.
Notes for reviewers (human-written)
Just implementing the mock.
Proof it works
Co-written with Claude.