fix(ai): correct off-by-one in array form of mock model helpers#15143
Closed
serhiizghama wants to merge 2 commits into
Closed
fix(ai): correct off-by-one in array form of mock model helpers#15143serhiizghama wants to merge 2 commits into
serhiizghama wants to merge 2 commits into
Conversation
When MockLanguageModelV3/V4 and MockEmbeddingModelV3/V4 are constructed with an array of results, the indexer used doCalls.length after the push, so the first scripted call returned the second entry and the last call returned undefined. Use length - 1 so calls return entries in declaration order.
Add tests confirming that MockLanguageModelV3/V4 and MockEmbeddingModelV3/V4 return scripted results in declaration order when constructed with an array. These would have failed against the previous off-by-one indexer.
Collaborator
|
Fixed via #15154 |
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.
Problem
MockLanguageModelV3/MockLanguageModelV4andMockEmbeddingModelV3/MockEmbeddingModelV4accept an array of results to script multi-call test scenarios (e.g. tool-call → tool-result → final text forToolLoopAgent). The array form silently misbehaved: the first call returned the second entry, and the last call returnedundefined.The cause is the indexer running after the call has already been pushed onto the call list:
The same off-by-one is in
doStreamfor both V3 and V4 and indoEmbedfor both embedding mocks.Fixes #15141.
Solution
Index with
length - 1after the push so the n-th call returns the n-th array entry, matching the obvious user expectation.Testing
Added
mock-language-model-v3.test.ts,mock-language-model-v4.test.ts,mock-embedding-model-v3.test.ts,mock-embedding-model-v4.test.tscovering bothdoGenerate/doStream/doEmbedarray forms. Verified the new tests fail againstmainand pass with the fix. Existingwrap-language-modelandwrap-embedding-modeltests continue to pass (they use empty arrays, so behavior is unchanged for that path).