testing library
Test doubles for an app built on local_inference_flutter: local_inference's own (ScriptedEngine,
scriptedAssistant, InMemoryPrefixStateStore, the delivery fakes), so a test needs no other dependency. No
dependency on flutter_test; import it from tests only.
Classes
- FakeDeviceProbe
- A device probe the test sets: caps is what capabilities reports; sha256 answers from hashes (by path), else from hashOf, else with the file's real SHA-256; the paths it was asked to hash or exclude are recorded.
- FakeDownloadStart
- One call of FakeModelDownloader.start.
- FakeModelDownloader
- A downloader the test drives: it records every call and sends the updates the test emits. start reports the download queued, pause paused, resume running and cancel canceled (unless echoCancel is false), as a background downloader does; finish writes the file and reports it complete. Like a downloader that keeps the partial data of a failed download, canResume is true after a failed update of an id until it is started, resumed, discarded, canceled or finished; canResumeResult fixes the answer instead.
- GbnfRecognizer
- Parses a GBNF grammar with llama.cpp's syntax (llama-grammar.cpp at llama.cpp v0.4.0) and tells whether it admits a string.
- InMemoryPrefixStateStore
- A PrefixStateStore that keeps its index in memory and records every call, for tests.
- ScriptedEngine
- An engine that answers each generation with the next string of outputs, in chunkSize-character deltas, and records what it was asked.
- ScriptedText
- ScriptedTurn.text.
- ScriptedToolCall
- ScriptedTurn.toolCall.
- ScriptedTurn
- What the scripted model answers to one generation.
- TestToolkit
- Wraps inner: records every call it runs, and holds back the answers of gatedTool until gate completes (the call itself starts at once, so it reads its list items when it is made).
Constants
- qwen35ChatTemplate → const String
-
The template text. With
enable_thinkingfalse the generation prompt ends with an empty think block.
Properties
-
testModelBytes
→ Map<
String, List< int> > -
The model files of testManifestJson, by id:
test-4b(960 bytes) andtest-2b(480 bytes).final
Functions
-
fixedClock(
DateTime at) → DateTime Function() -
A clock that always answers
at. -
scriptedAssistant(
AssistantConfig config, {List< ScriptedTurn> script = const [], bool validateAgainstGrammar = true, String chatTemplate = qwen35ChatTemplate, PrefixStateStore? prefixStore, DateTime wallClock()?}) → Future<(Assistant, ScriptedEngine)> -
An Assistant with
configon a ScriptedEngine whose outputs arescript, its model loaded (from no file:ModelIdentity.fixed('scripted.gguf')). Add more outputs to the engine'soutputsas the test goes. -
testManifestJson(
{bool withSmall = true, String manifestVersion = '2026-09-17'}) → String -
A schema-1 manifest of two small models whose files are testModelBytes:
test-4b(recommended, 7000 MB of RAM, 3800 available) and, withwithSmall,test-2b(5500 and 2000). Each needs 100 MB of free disk; the display name is the id.
Exceptions / Errors
- ScriptExhausted
- A generation found no output left in ScriptedEngine.outputs: the test script is too short.
- ScriptRejectedByGrammar
- A scripted output the generation's grammar does not admit: the real model could not have written it. It fails the generation and is reported to the zone of the generate call, so the test fails.