Repository navigation
LOU-D5: scripted mockModel for deterministic agent tests - #40
Merged
Merged
Conversation
Adds `mockModel(script, options?)` to the `/testing` subpath: a typed
LLMProvider test double that replays scripted turns (string, {text},
{toolCalls}, {error}, or a function of the request) with optional usage,
finishReason and delayMs. Tool-call ids are generated deterministically
(call_1, call_2, ...). Every generate()/stream() request is recorded as a
deep-frozen snapshot on `calls` (plus `lastCall`, `reset()`,
`assertExhausted()`). Running out of turns throws an error naming the
unexpected call number and the last message, and suggesting a new turn or
`onExhausted: 'repeat-last'`. stream() emits the scripted text as chunks.
`/testing` now points at a new src/testing/index.ts barrel that re-exports
the existing repository mocks plus the new API (package.json exports and
tsup entry repointed; dist/testing/index.{js,mjs,d.ts}).
Dogfooded in DelegationTool.test.ts and sandbox-wiring.test.ts, replacing
hand-rolled scripted providers (net -78 lines). New docs/testing.md,
linked from README and docs/api-overview.md.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
What
Adds
mockModel(script, options?)to@loushy/build-ai-agent/testing: a typed, scriptedLLMProvidertest double.{ text },{ toolCalls, text? },{ error }, or(request) => turn(sync/async); optionalusage,finishReason,delayMs.call_1, ...),calls(deep-frozen snapshots),lastCall,reset(),assertExhausted().{ onExhausted: 'repeat-last' }.stream()emits scripted text as chunks, then tool-call and finish chunks./testingnow exports a newsrc/testing/index.tsbarrel (existing repo mocks +mockModel);package.jsonexports["./testing"]and the tsup entry were repointed.docs/testing.md, linked from README anddocs/api-overview.md.Why
Many tests hand-roll "scripted provider" objects; competitors ship mock models for deterministic evals. This removes that boilerplate.
How verified
npx tsc --noEmit: cleannpm run lint: 0 errors (no new warnings from my files)npm run build+ create-loushy-agent build: success;dist/testing/index.{js,mjs,d.ts}emittednpm run test:coverage: Test Files 89 passed (89), Tests 955 passed | 3 skippednpm run fallow: exit 0 (0 above threshold, maintainability 92.4)npm run docs:verify-snippets(quick-start +docs/testing.md): all snippets type-check and run (vitest-based snippets are markedno-verifysince vitest is not in the temp project; the same flow is covered bysrc/testing/mockModel.test.ts)Notes for reviewer
DelegationTool.test.ts(4 tests + the A<->B loop test) andsandbox-wiring.test.tsconverted. Net diff of those two files: 26 insertions, 104 deletions (78 lines saved). BecausemockModelrecords a snapshot at call time, assertions no longer include the assistant message the executor pushes onto the shared array after the call (the old tests had comments about this aliasing).🤖 Generated with Claude Code