From bb67e6c03f0a2765a0e036ea8bb32a541fb3b6db Mon Sep 17 00:00:00 2001 From: Jhin Lee Date: Wed, 21 Oct 2026 20:56:30 -0400 Subject: [PATCH] Trim redundant tests and inject LiteRT-LM test timeouts Make LiteRtLmBackend's worker handshake, native free and cancel-ack timeouts injectable (defaults unchanged) so lifecycle tests pass 50 ms instead of waiting out 5 s and 1 s timers, and pin the llama.cpp 30 s startup default (#462) instead of waiting out a 5.2 s worker. Remove tests that are true by construction or covered elsewhere, and register behaviorless sources in the mirrored-structure guard. --- .../backends/litert_lm/litert_lm_backend.dart | 22 +- .../engine/tool_calling_integration_test.dart | 14 - .../template_diagnostic_integration_test.dart | 11 - test/unit/backends/backend_test.dart | 12 - .../litert_lm/litert_lm_backend_test.dart | 66 ++--- .../litert_lm/litert_lm_service_test.dart | 83 +++--- .../litert_lm/worker_messages_test.dart | 148 ----------- test/unit/backends/litert_lm/worker_test.dart | 4 - .../llama_cpp/exit_teardown_api_test.dart | 11 - .../llama_cpp/llama_cpp_backend_test.dart | 19 +- .../llama_cpp_raw_bindings_test.dart | 22 -- .../llama_cpp/llama_cpp_service_test.dart | 24 -- .../llama_cpp/multimodal_embedding_test.dart | 44 ---- .../llama_cpp/native_barrier_api_test.dart | 7 - .../llama_cpp/worker_messages_test.dart | 243 ++++-------------- test/unit/backends/llama_cpp/worker_test.dart | 4 - .../backends/webgpu/webgpu_backend_test.dart | 132 ---------- test/unit/core/engine/engine_test.dart | 123 +++------ test/unit/core/exceptions_test.dart | 57 ---- .../response_schema_validation_test.dart | 4 - .../download/model_download_manager_test.dart | 29 --- .../models/tools/tool_definition_test.dart | 48 ---- .../core/models/tools/tool_param_test.dart | 71 ----- .../core/models/tools/tool_params_test.dart | 73 +++++- .../litert_lm_speech_to_text_driver_test.dart | 28 -- .../speech/speech_platform_stub_test.dart | 18 -- .../core/speech/speech_platform_web_test.dart | 18 -- .../text_to_speech_platform_stub_test.dart | 11 - .../text_to_speech_platform_web_test.dart | 11 - .../handlers/apriel15_handler_test.dart | 6 - .../handlers/exaone_moe_handler_test.dart | 6 - .../functionary_v31_llama31_handler_test.dart | 6 - .../functionary_v32_handler_test.dart | 6 - .../template/handlers/gemma_handler_test.dart | 6 - .../handlers/granite_handler_test.dart | 6 - .../handlers/llama3_handler_test.dart | 5 - .../handlers/solar_open_handler_test.dart | 5 - .../template_internal_metadata_test.dart | 25 -- .../template_render_context_test.dart | 43 +--- .../tool_result_user_turn_render_test.dart | 10 +- .../mirrored_unit_structure_test.dart | 7 + .../tooling/high_risk_review_policy_test.dart | 3 - 42 files changed, 259 insertions(+), 1232 deletions(-) delete mode 100644 test/unit/backends/llama_cpp/llama_cpp_raw_bindings_test.dart delete mode 100644 test/unit/core/models/download/model_download_manager_test.dart delete mode 100644 test/unit/core/speech/litert_lm_speech_to_text_driver_test.dart delete mode 100644 test/unit/core/speech/speech_platform_stub_test.dart delete mode 100644 test/unit/core/speech/speech_platform_web_test.dart delete mode 100644 test/unit/core/speech/text_to_speech_platform_stub_test.dart delete mode 100644 test/unit/core/speech/text_to_speech_platform_web_test.dart diff --git a/lib/src/backends/litert_lm/litert_lm_backend.dart b/lib/src/backends/litert_lm/litert_lm_backend.dart index 569a99189..892075efe 100644 --- a/lib/src/backends/litert_lm/litert_lm_backend.dart +++ b/lib/src/backends/litert_lm/litert_lm_backend.dart @@ -54,6 +54,9 @@ class LiteRtLmBackend final Set _stalePerformanceContexts = {}; final Map> _pendingRequests = {}; final Duration _embeddingTimeout; + final Duration _workerStartupTimeout; + final Duration _freeTimeout; + final Duration _cancelAcknowledgementTimeout; final String? _preferredBackend; final void Function(SendPort) _workerEntryPoint; @@ -75,13 +78,24 @@ class LiteRtLmBackend /// Expiry cancels only that request; other queued calls keep their deadlines. /// Explicit cancellation, context/model teardown and disposal cancel all embeds. /// [workerEntryPoint] substitutes the worker only for lifecycle tests. + /// [workerStartupTimeout] bounds the worker handshake. + /// [freeTimeout] bounds native context and model frees; on expiry the worker + /// is killed and native settlement is reported as unverified. + /// [cancelAcknowledgementTimeout] bounds the wait for the worker to + /// acknowledge a cancellation, which is best-effort. LiteRtLmBackend({ SendPort? initialSendPort, Duration embeddingTimeout = const Duration(minutes: 10), @Deprecated('Use ModelParams.device. This will be removed in 1.0.') String? preferredBackend, void Function(SendPort)? workerEntryPoint, + Duration workerStartupTimeout = const Duration(seconds: 5), + Duration freeTimeout = const Duration(seconds: 5), + Duration cancelAcknowledgementTimeout = const Duration(seconds: 1), }) : _embeddingTimeout = embeddingTimeout, + _workerStartupTimeout = workerStartupTimeout, + _freeTimeout = freeTimeout, + _cancelAcknowledgementTimeout = cancelAcknowledgementTimeout, _preferredBackend = preferredBackend, _workerEntryPoint = workerEntryPoint ?? liteRtLmWorkerEntry { if (initialSendPort != null) { @@ -254,7 +268,7 @@ class LiteRtLmBackend try { await _sendRequest( (sendPort) => LiteRtLmModelFreeRequest(modelHandle, sendPort), - timeout: const Duration(seconds: 5), + timeout: _freeTimeout, ); } on TimeoutException { _nativeSettlementUnverified = true; @@ -294,7 +308,7 @@ class LiteRtLmBackend try { await _sendRequest( (sendPort) => LiteRtLmContextFreeRequest(contextHandle, sendPort), - timeout: const Duration(seconds: 5), + timeout: _freeTimeout, ); _embeddingContext = null; _stalePerformanceContexts.remove(contextHandle); @@ -957,7 +971,7 @@ class LiteRtLmBackend } _isolate = isolate; await completer.future.timeout( - const Duration(seconds: 5), + _workerStartupTimeout, onTimeout: () { throw TimeoutException('Timed out starting LiteRT-LM worker.'); }, @@ -1092,7 +1106,7 @@ class LiteRtLmBackend responsePort.sendPort, ), ); - await responsePort.first.timeout(const Duration(seconds: 1)); + await responsePort.first.timeout(_cancelAcknowledgementTimeout); } catch (_) { // Cancellation is best-effort because this method is also used by // StreamController.onCancel and dispose paths. diff --git a/test/integration/core/engine/tool_calling_integration_test.dart b/test/integration/core/engine/tool_calling_integration_test.dart index 9352f0a90..f190a75d4 100644 --- a/test/integration/core/engine/tool_calling_integration_test.dart +++ b/test/integration/core/engine/tool_calling_integration_test.dart @@ -181,20 +181,6 @@ void main() { ]; }); - group('ToolDefinition', () { - test('toJsonSchema includes tool definitions', () { - final tool = tools.first; - final schema = tool.toJsonSchema(); - expect(schema['properties'], containsPair('location', isA())); - }); - - test('invoke handles valid tool call', () async { - final tool = tools.first; - final result = await tool.invoke({'location': 'London'}); - expect(result, 'Sunny in London'); - }); - }); - group('ChatSession with Tools', () { test('tools are passed to engine.create', () async { final session = ChatSession(engine); diff --git a/test/integration/core/template/template_diagnostic_integration_test.dart b/test/integration/core/template/template_diagnostic_integration_test.dart index 0aaa0b21c..3cbdd1b2e 100644 --- a/test/integration/core/template/template_diagnostic_integration_test.dart +++ b/test/integration/core/template/template_diagnostic_integration_test.dart @@ -41,17 +41,6 @@ void main() { 'tokenizer.ggml.eos_token': '', }; - group('Format Detection', () { - for (final file in templateFiles) { - final name = file.path.split('/').last.replaceAll('.jinja', ''); - test('detects format for $name', () { - final source = file.readAsStringSync(); - final format = detectChatFormat(source); - expect(format, isNotNull); - }); - } - }); - group('Render Pipeline - Simple Messages', () { for (final file in templateFiles) { final name = file.path.split('/').last.replaceAll('.jinja', ''); diff --git a/test/unit/backends/backend_test.dart b/test/unit/backends/backend_test.dart index 12966d091..aae0ae226 100644 --- a/test/unit/backends/backend_test.dart +++ b/test/unit/backends/backend_test.dart @@ -64,16 +64,4 @@ void main() { expect(perf.speculativeAcceptanceRate, isNull); }); }); - - group('StateLoadResult', () { - test('exposes the recovered token sequence', () { - const result = StateLoadResult(tokens: [1, 2, 3]); - expect(result.tokens, [1, 2, 3]); - }); - - test('accepts an empty token list', () { - const result = StateLoadResult(tokens: []); - expect(result.tokens, isEmpty); - }); - }); } diff --git a/test/unit/backends/litert_lm/litert_lm_backend_test.dart b/test/unit/backends/litert_lm/litert_lm_backend_test.dart index 0bd65c148..cd696dcc6 100644 --- a/test/unit/backends/litert_lm/litert_lm_backend_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_backend_test.dart @@ -641,7 +641,10 @@ void main() { } // Free requests deliberately never settle, as with a blocked runtime. }); - final backend = LiteRtLmBackend(initialSendPort: port.sendPort); + final backend = LiteRtLmBackend( + initialSendPort: port.sendPort, + freeTimeout: const Duration(milliseconds: 50), + ); final pending = backend.tokenize(1, 'hello'); final failed = expectLater( pending, @@ -775,7 +778,10 @@ void main() { test( 'free fails when worker exits during generation cancellation: $freeContext', () async { - final backend = LiteRtLmBackend(workerEntryPoint: _exitOnCancelWorker); + final backend = LiteRtLmBackend( + workerEntryPoint: _exitOnCancelWorker, + cancelAcknowledgementTimeout: const Duration(milliseconds: 50), + ); final started = Completer(); final stream = freeContext ? backend.generate(1, 'hello', const GenerationParams()) @@ -1274,49 +1280,6 @@ void main() { }, ); - test('rejects concurrent generation before touching worker', () async { - final worker = _FakeLiteRtLmWorker( - tokenizeResponse: const [], - detokenizeResponse: '', - holdGeneration: true, - ); - final backend = LiteRtLmBackend(initialSendPort: worker.sendPort); - - try { - final firstDone = Completer(); - final firstSubscription = backend - .generate(1, 'first', const GenerationParams()) - .listen( - (_) {}, - onError: firstDone.completeError, - onDone: firstDone.complete, - ); - await worker.generateReceived.future; - - await expectLater( - backend.generate(1, 'second', const GenerationParams()).drain(), - throwsA( - isA().having( - (error) => error.message, - 'message', - contains('already in progress'), - ), - ), - ); - expect( - worker.requests.whereType(), - hasLength(1), - ); - - worker.releaseGeneration(); - await firstDone.future.timeout(const Duration(seconds: 1)); - await firstSubscription.cancel(); - } finally { - await backend.dispose(); - worker.close(); - } - }); - test( 'does not send generation after immediate stream cancellation', () async { @@ -2614,6 +2577,7 @@ void main() { final backend = LiteRtLmBackend( initialSendPort: worker.sendPort, workerEntryPoint: _silentWorker, + workerStartupTimeout: const Duration(milliseconds: 50), ); final mirror = reflect(backend); final owner = mirror.type.owner as LibraryMirror; @@ -2646,23 +2610,25 @@ void main() { isEmpty, ); }, - timeout: const Timeout(Duration(seconds: 15)), ); test('a worker startup timeout releases the generation slot', () async { - final backend = LiteRtLmBackend(workerEntryPoint: _silentWorker); + final backend = LiteRtLmBackend( + workerEntryPoint: _silentWorker, + workerStartupTimeout: const Duration(milliseconds: 50), + ); const params = GenerationParams(); final first = _CollectedGeneration(backend.generate(1, 'first', params)); - await first.doneWithin(const Duration(seconds: 10)); + await first.doneWithin(const Duration(seconds: 2)); expect(first.error, isA()); // The retry makes its own startup attempt instead of waiting behind the // failed one. final second = _CollectedGeneration(backend.generate(1, 'second', params)); - await second.doneWithin(const Duration(seconds: 10)); + await second.doneWithin(const Duration(seconds: 2)); expect(second.error, isA()); await backend.dispose(); - }, timeout: const Timeout(Duration(seconds: 40))); + }); test('a worker exit during startup releases the generation slot', () async { final backend = LiteRtLmBackend(workerEntryPoint: _exitBeforeHandshake); diff --git a/test/unit/backends/litert_lm/litert_lm_service_test.dart b/test/unit/backends/litert_lm/litert_lm_service_test.dart index fe80840fe..e9a20bb75 100644 --- a/test/unit/backends/litert_lm/litert_lm_service_test.dart +++ b/test/unit/backends/litert_lm/litert_lm_service_test.dart @@ -869,55 +869,42 @@ void main() { 'Qwen2.5-0.5B', ]) { for (final override in [null, '{{ messages[0].content }}', '']) { - for (final hasSetter in [false, true]) { - test( - 'main native routing $name override=$override setter=$hasSetter', - () async { - final file = File('${tempDir.path}/$name.litertlm'); - await file.writeAsBytes(_thinkingBundle(modelType: 1)); - final client = _FakeLiteRtLmRuntimeClient() - ..rendersMessages = true - ..onRenderMessage = (_) => liteRtLmContentShapeProbeText; - // A runtime without the optional setter still supports these chats. - if (!hasSetter) { - client.onCreateConversation = () { - if (client.lastPromptTemplate != null) { - throw LlamaUnsupportedException('no template setter'); - } - }; - } - final service = LiteRtLmService(clientFactory: () => client); - final params = ModelParams( - liteRtLmBackend: LiteRtLmBackendPreference.cpu, - chatTemplate: override, - ); - try { - final model = await service.loadModel(file.path, params); - expect( - await generate( - service, - client, - service.createContext(model, params), - ), - isNull, - ); - expect(client.renderMessageCount, 1); - expect(client.conversations, [ - (template: null, seeded: false), - (template: null, seeded: true), - ]); - if (override != null) { - expect( - service.getMetadata(model)['tokenizer.chat_template'], - override, - ); - } - } finally { - service.dispose(); - } - }, + test('main native routing $name override=$override', () async { + final file = File('${tempDir.path}/$name.litertlm'); + await file.writeAsBytes(_thinkingBundle(modelType: 1)); + final client = _FakeLiteRtLmRuntimeClient() + ..rendersMessages = true + ..onRenderMessage = (_) => liteRtLmContentShapeProbeText; + final service = LiteRtLmService(clientFactory: () => client); + final params = ModelParams( + liteRtLmBackend: LiteRtLmBackendPreference.cpu, + chatTemplate: override, ); - } + try { + final model = await service.loadModel(file.path, params); + expect( + await generate( + service, + client, + service.createContext(model, params), + ), + isNull, + ); + expect(client.renderMessageCount, 1); + expect(client.conversations, [ + (template: null, seeded: false), + (template: null, seeded: true), + ]); + if (override != null) { + expect( + service.getMetadata(model)['tokenizer.chat_template'], + override, + ); + } + } finally { + service.dispose(); + } + }); } } diff --git a/test/unit/backends/litert_lm/worker_messages_test.dart b/test/unit/backends/litert_lm/worker_messages_test.dart index 8ae6f99d4..f0e2d9ef1 100644 --- a/test/unit/backends/litert_lm/worker_messages_test.dart +++ b/test/unit/backends/litert_lm/worker_messages_test.dart @@ -1,113 +1,12 @@ @TestOn('vm') library; -import 'dart:isolate'; - import 'package:llamadart/src/backends/litert_lm/worker_messages.dart'; import 'package:llamadart/llamadart.dart'; import 'package:test/test.dart'; void main() { - final rp = ReceivePort(); - final sp = rp.sendPort; - group('LiteRT-LM worker messages', () { - test('requests keep request fields', () { - final modelLoad = LiteRtLmModelLoadRequest( - 'model.litertlm', - const ModelParams(), - sp, - ); - expect(modelLoad.modelPath, 'model.litertlm'); - expect(modelLoad.sendPort, sp); - - expect(LiteRtLmModelFreeRequest(1, sp).modelHandle, 1); - expect( - LiteRtLmContextCreateRequest(1, const ModelParams(), sp).modelHandle, - 1, - ); - expect(LiteRtLmContextFreeRequest(1, sp).contextHandle, 1); - - final generate = LiteRtLmGenerateRequest( - 1, - 'prompt', - const GenerationParams(), - sp, - parts: const [], - ); - expect(generate.contextHandle, 1); - expect(generate.prompt, 'prompt'); - expect(generate.parts, isEmpty); - - final generateChat = LiteRtLmGenerateChatRequest( - 1, - const [ - LlamaChatMessage.fromText(role: LlamaChatRole.user, text: 'hello'), - ], - const GenerationParams(), - sp, - tools: [ - { - 'type': 'function', - 'function': { - 'name': 'get_weather', - 'description': 'Get weather', - 'parameters': {'type': 'object'}, - }, - }, - ], - toolChoice: ToolChoice.none, - chatTemplateKwargs: const {'locale': 'en_CA'}, - ); - expect(generateChat.contextHandle, 1); - expect(generateChat.messages.single.content, 'hello'); - expect(generateChat.tools?.single['function']['name'], 'get_weather'); - expect(generateChat.toolChoice, ToolChoice.none); - expect(generateChat.chatTemplateKwargs, {'locale': 'en_CA'}); - - expect(LiteRtLmCancelGenerationRequest(sp).sendPort, sp); - expect(LiteRtLmTokenizeRequest(1, 'text', true, sp).text, 'text'); - expect( - LiteRtLmDetokenizeRequest(1, const [1, 2], false, sp).tokens, - const [1, 2], - ); - expect(LiteRtLmMetadataRequest(1, sp).modelHandle, 1); - expect( - LiteRtLmLoraRequest(1, 'set', path: 'adapter', sendPort: sp).path, - 'adapter', - ); - expect(LiteRtLmBackendInfoRequest(sp).sendPort, sp); - expect(LiteRtLmAvailableBackendsRequest(sp).sendPort, sp); - expect(LiteRtLmResolvedGpuLayersRequest(sp).sendPort, sp); - expect(LiteRtLmPerformanceContextRequest(1, sp).contextHandle, 1); - expect(LiteRtLmGpuSupportRequest(sp).sendPort, sp); - expect(LiteRtLmDisposeRequest(sp).sendPort, sp); - expect( - LiteRtLmLogLevelRequest(LlamaLogLevel.info, sp).logLevel, - LlamaLogLevel.info, - ); - expect(LiteRtLmGetContextSizeRequest(1, sp).contextHandle, 1); - expect( - LiteRtLmMultimodalContextCreateRequest(1, 'proj', sp).mmProjPath, - 'proj', - ); - expect(LiteRtLmMultimodalContextFreeRequest(1, sp).mmContextHandle, 1); - expect(LiteRtLmSupportsVisionRequest(1, sp).mmContextHandle, 1); - expect(LiteRtLmSupportsAudioRequest(1, sp).mmContextHandle, 1); - expect(LiteRtLmSystemInfoRequest(sp).sendPort, sp); - expect(LiteRtLmBundleCapabilitiesRequest(sp).sendPort, sp); - expect( - LiteRtLmChatTemplateRequest( - 1, - const >[], - null, - true, - sp, - ).addAssistant, - isTrue, - ); - }); - test('maps Dart errors into worker error responses', () { expect( LiteRtLmErrorResponse.from(UnsupportedError('nope')).kind, @@ -144,52 +43,5 @@ void main() { expect(generic.kind, 'exception'); expect(generic.message, contains('native failed')); }); - - test('responses keep response fields', () { - expect(LiteRtLmHandleResponse(1).handle, 1); - expect(LiteRtLmTokenResponse(const [1]).bytes, const [1]); - expect(LiteRtLmTokenizeResponse(const [2]).tokens, const [2]); - expect(LiteRtLmDetokenizeResponse('text').text, 'text'); - expect( - LiteRtLmMetadataResponse(const {'a': 'b'}).metadata, - const {'a': 'b'}, - ); - expect(LiteRtLmGetContextSizeResponse(4096).size, 4096); - expect( - LiteRtLmBundleCapabilitiesResponse(( - vision: true, - audio: false, - speculativeDecoding: true, - )).capabilities, - (vision: true, audio: false, speculativeDecoding: true), - ); - expect(LiteRtLmErrorResponse('bad', kind: 'state').kind, 'state'); - expect( - LiteRtLmBackendInfoResponse('LiteRT-LM gpu').name, - 'LiteRT-LM gpu', - ); - expect(LiteRtLmGpuSupportResponse(true).support, isTrue); - expect(LiteRtLmResolvedGpuLayersResponse(999).layers, 999); - final perf = LiteRtLmPerformanceContextResponse( - loadMs: 1, - promptEvalMs: 2, - evalMs: 3, - sampleMs: 4, - promptEvalTokens: 5, - evalTokens: 6, - sampleCount: 7, - reusedGraphs: 8, - ); - expect(perf.evalTokens, 6); - expect(LiteRtLmSystemInfoResponse(10, 4).freeVram, 4); - expect(LiteRtLmChatTemplateResponse('prompt').result, 'prompt'); - expect(LiteRtLmDoneResponse(), isNotNull); - expect( - LiteRtLmWorkerHandshake(LlamaLogLevel.debug).initialLogLevel, - LlamaLogLevel.debug, - ); - }); }); - - rp.close(); } diff --git a/test/unit/backends/litert_lm/worker_test.dart b/test/unit/backends/litert_lm/worker_test.dart index 26fbae9fe..99984f127 100644 --- a/test/unit/backends/litert_lm/worker_test.dart +++ b/test/unit/backends/litert_lm/worker_test.dart @@ -96,10 +96,6 @@ void main() { }, ); - test('liteRtLmWorkerEntry function is available', () { - expect(liteRtLmWorkerEntry, isA()); - }); - group('liteRtLmWorkerEntry isolate routing', () { test('handles control and info requests', () async { final worker = await _spawnWorker(); diff --git a/test/unit/backends/llama_cpp/exit_teardown_api_test.dart b/test/unit/backends/llama_cpp/exit_teardown_api_test.dart index 54a836662..8fb0d6135 100644 --- a/test/unit/backends/llama_cpp/exit_teardown_api_test.dart +++ b/test/unit/backends/llama_cpp/exit_teardown_api_test.dart @@ -80,17 +80,6 @@ void main() { ); }); - test('resolves from the pinned runtime', () { - expect( - ExitTeardownApi.tryResolve(isWindows: Platform.isWindows), - isNotNull, - ); - expect( - LlamaCppObjectCalls.resolve(isWindows: Platform.isWindows).exit, - isNotNull, - ); - }); - test('binds every function through the lookup, and resolves none when one ' 'is missing', () { final requested = []; diff --git a/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart b/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart index 6514ef83e..4533ceb5a 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_backend_test.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:ffi'; import 'dart:io'; import 'dart:isolate'; +import 'dart:mirrors'; import 'dart:typed_data'; import 'package:ffi/ffi.dart'; @@ -2100,9 +2101,23 @@ void main() { } }); - test('default startup timeout permits a slow native cold start', () async { + test('default startup timeout permits a slow native cold start', () { + final mirror = reflect(NativeLlamaBackend()); + final owner = mirror.type.owner as LibraryMirror; + expect( + mirror + .getField(MirrorSystem.getSymbol('_workerStartupTimeout', owner)) + .reflectee, + const Duration(seconds: 30), + reason: 'physical iOS cold starts exceed the former 5 s default (#462)', + ); + }); + + test('a handshake slower than instant completes within the startup ' + 'timeout', () async { final backend = NativeLlamaBackend( workerEntrypoint: _slowReusableWorkerEntry, + workerStartupTimeout: const Duration(seconds: 2), ); try { @@ -2273,7 +2288,7 @@ void _slowReusableWorkerEntry(SendPort initialSendPort) { receivePort.listen((message) async { switch (message) { case WorkerHandshake(): - await Future.delayed(const Duration(milliseconds: 5200)); + await Future.delayed(const Duration(milliseconds: 200)); message.sendPort.send(DoneResponse()); case ModelLoadRequest(): message.sendPort.send(HandleResponse(42)); diff --git a/test/unit/backends/llama_cpp/llama_cpp_raw_bindings_test.dart b/test/unit/backends/llama_cpp/llama_cpp_raw_bindings_test.dart deleted file mode 100644 index 962319ce7..000000000 --- a/test/unit/backends/llama_cpp/llama_cpp_raw_bindings_test.dart +++ /dev/null @@ -1,22 +0,0 @@ -@TestOn('vm') -library; - -import 'dart:ffi' as ffi; - -import 'package:llamadart/src/backends/llama_cpp/bindings.dart'; -import 'package:llamadart/src/backends/llama_cpp/llama_cpp_raw_bindings.dart' - as raw; -import 'package:test/test.dart'; - -void main() { - test('raw ftype binding helpers are available for forward compatibility', () { - expect( - raw.llama_model_ftype_raw, - isA)>(), - ); - expect( - raw.llama_ftype_name_raw, - isA Function(int)>(), - ); - }); -} diff --git a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart index 3f07ee99d..599d406ae 100644 --- a/test/unit/backends/llama_cpp/llama_cpp_service_test.dart +++ b/test/unit/backends/llama_cpp/llama_cpp_service_test.dart @@ -467,11 +467,6 @@ void main() { }); }); - test('LlamaCppService can be instantiated', () { - final service = LlamaCppService(); - expect(service, isA()); - }); - group('aLoRA eager-activation guard', () { final adapter = Pointer.fromAddress(1); @@ -1066,25 +1061,6 @@ void main() { }); } - test('requires draftModelPath for external draft strategies', () { - expect( - () => service.debugResolveSpeculativeTypeNamesForTesting( - const GenerationParams( - speculativeDecodingConfig: SpeculativeDecodingConfig.mixed( - strategies: [SpeculativeDecodingStrategy.draftEagle3], - ), - ), - ), - throwsA( - isA().having( - (error) => error.message, - 'message', - contains('requires SpeculativeDecodingConfig.draftModel'), - ), - ), - ); - }); - test('requires a non-empty draftModelPath for DSpark', () { expect( () => service.debugResolveSpeculativeTypeNamesForTesting( diff --git a/test/unit/backends/llama_cpp/multimodal_embedding_test.dart b/test/unit/backends/llama_cpp/multimodal_embedding_test.dart index c6b2a4e9b..40a005aee 100644 --- a/test/unit/backends/llama_cpp/multimodal_embedding_test.dart +++ b/test/unit/backends/llama_cpp/multimodal_embedding_test.dart @@ -42,50 +42,6 @@ void main() { }, ); - test( - 'worker snapshot merges text verbatim and copies every media source', - () { - final port = ReceivePort(); - addTearDown(port.close); - final bytes = Uint8List.fromList([1, 2, 3]); - final pcm = Float32List.fromList([0, 0.25]); - final request = EmbedContentBatchRequest( - 7, - [ - LlamaEmbeddingInput([ - const LlamaTextContent('a '), - const LlamaTextContent(''), - const LlamaTextContent('\nbé'), - LlamaImageContent(bytes: bytes, width: 1, height: 1), - const LlamaTextContent('c'), - const LlamaTextContent('d'), - LlamaAudioContent(samples: pcm), - LlamaAudioContent(bytes: bytes), - const LlamaImageContent(path: 'image'), - const LlamaAudioContent(path: 'audio'), - const LlamaImageContent(url: 'https://invalid.example'), - ]), - ], - false, - 123, - port.sendPort, - ); - bytes[0] = 9; - pcm[0] = 1; - final parts = request.inputs.single.parts; - expect(parts, hasLength(8)); - expect((parts[0] as LlamaTextContent).text, 'a \nbé'); - expect((parts[1] as LlamaImageContent).bytes, [1, 2, 3]); - expect((parts[1] as LlamaImageContent).width, 1); - expect((parts[2] as LlamaTextContent).text, 'cd'); - expect((parts[3] as LlamaAudioContent).samples, [0, 0.25]); - expect((parts[4] as LlamaAudioContent).bytes, [1, 2, 3]); - expect((parts[5] as LlamaImageContent).path, 'image'); - expect((parts[6] as LlamaAudioContent).path, 'audio'); - expect((parts[7] as LlamaImageContent).url, 'https://invalid.example'); - }, - ); - test( 'content RPC copies media, preserves normalization, cancels and keeps typed errors', () async { diff --git a/test/unit/backends/llama_cpp/native_barrier_api_test.dart b/test/unit/backends/llama_cpp/native_barrier_api_test.dart index 1b2277476..66a0e35ef 100644 --- a/test/unit/backends/llama_cpp/native_barrier_api_test.dart +++ b/test/unit/backends/llama_cpp/native_barrier_api_test.dart @@ -187,13 +187,6 @@ void main() { dir.deleteSync(recursive: true); }); - test('exports the exception barrier', () { - expect( - NativeBarrierApi.tryResolve(isWindows: Platform.isWindows), - isNotNull, - ); - }); - test('records the message of an exception llama.cpp throws, for the ' 'next call to clear', () { final vocab = llama_model_get_vocab(model); diff --git a/test/unit/backends/llama_cpp/worker_messages_test.dart b/test/unit/backends/llama_cpp/worker_messages_test.dart index dd636c492..eb71cdb14 100644 --- a/test/unit/backends/llama_cpp/worker_messages_test.dart +++ b/test/unit/backends/llama_cpp/worker_messages_test.dart @@ -2,207 +2,54 @@ library; import 'dart:isolate'; -import 'package:test/test.dart'; -import 'package:llamadart/src/backends/llama_cpp/worker_messages.dart'; +import 'dart:typed_data'; + import 'package:llamadart/llamadart.dart'; +import 'package:llamadart/src/backends/llama_cpp/worker_messages.dart'; +import 'package:test/test.dart'; void main() { - final rp = ReceivePort(); - final sp = rp.sendPort; - - group('WorkerMessages', () { - test('ModelLoadRequest', () { - final req = ModelLoadRequest('path', const ModelParams(), sp); - expect(req.modelPath, 'path'); - expect(req.sendPort, sp); - }); - - test('ModelFreeRequest', () { - final req = ModelFreeRequest(1, sp); - expect(req.modelHandle, 1); - }); - - test('ContextCreateRequest', () { - final req = ContextCreateRequest(1, const ModelParams(), sp); - expect(req.modelHandle, 1); - }); - - test('ContextFreeRequest', () { - final req = ContextFreeRequest(1, sp); - expect(req.contextHandle, 1); - }); - - test('GenerateRequest', () { - final req = GenerateRequest( - 1, - 'prompt', - const GenerationParams(), - 0, - sp, - parts: [], - ); - expect(req.prompt, 'prompt'); - expect(req.parts, isEmpty); - }); - - test('EmbedRequest', () { - final req = EmbedRequest(1, 'hello', true, sp); - expect(req.contextHandle, 1); - expect(req.text, 'hello'); - expect(req.normalize, isTrue); - }); - - test('EmbedBatchRequest', () { - final req = EmbedBatchRequest(1, const ['a', 'b'], false, sp); - expect(req.contextHandle, 1); - expect(req.texts, const ['a', 'b']); - expect(req.normalize, isFalse); - }); - - test('TokenizeRequest', () { - final req = TokenizeRequest(1, 'text', true, sp); - expect(req.text, 'text'); - expect(req.addSpecial, true); - }); - - test('DetokenizeRequest', () { - final req = DetokenizeRequest(1, [1, 2], false, sp); - expect(req.tokens, [1, 2]); - expect(req.special, false); - }); - - test('MetadataRequest', () { - final req = MetadataRequest(1, sp); - expect(req.modelHandle, 1); - }); - - test('LoraRequest', () { - final req = LoraRequest(1, 'set', path: 'p', scale: 1.0, sendPort: sp); - expect(req.op, 'set'); - expect(req.path, 'p'); - expect(req.scale, 1.0); - }); - - test('BackendInfoRequest', () { - final req = BackendInfoRequest(sp); - expect(req.sendPort, sp); - }); - - test('GpuSupportRequest', () { - final req = GpuSupportRequest(sp); - expect(req.sendPort, sp); - }); - - test('DisposeRequest', () { - final req = DisposeRequest(sp); - expect(req.sendPort, sp); - }); - - test('LogLevelRequest', () { - final req = LogLevelRequest(LlamaLogLevel.info, sp); - expect(req.logLevel, LlamaLogLevel.info); - }); - - test('GetContextSizeRequest', () { - final req = GetContextSizeRequest(1, sp); - expect(req.contextHandle, 1); - }); - - test('MultimodalContextCreateRequest', () { - final req = MultimodalContextCreateRequest(1, 'proj', sp); - expect(req.modelHandle, 1); - expect(req.mmProjPath, 'proj'); - }); - - test('MultimodalContextFreeRequest', () { - final req = MultimodalContextFreeRequest(1, sp); - expect(req.mmContextHandle, 1); - }); - - test('SupportsVisionRequest', () { - final req = SupportsVisionRequest(1, sp); - expect(req.mmContextHandle, 1); - }); - - test('SupportsAudioRequest', () { - final req = SupportsAudioRequest(1, sp); - expect(req.mmContextHandle, 1); - }); - - test('Responses', () { - expect(HandleResponse(1).handle, 1); - expect(TokenResponse([1]).bytes, [1]); - expect(TokenizeResponse([1]).tokens, [1]); - expect(EmbedResponse([0.1, 0.2]).embedding, [0.1, 0.2]); - expect( - EmbedBatchResponse([ - [0.1], - [0.2], - ]).embeddings, + test( + 'worker snapshot merges text verbatim and copies every media source', + () { + final port = ReceivePort(); + addTearDown(port.close); + final bytes = Uint8List.fromList([1, 2, 3]); + final pcm = Float32List.fromList([0, 0.25]); + final request = EmbedContentBatchRequest( + 7, [ - [0.1], - [0.2], + LlamaEmbeddingInput([ + const LlamaTextContent('a '), + const LlamaTextContent(''), + const LlamaTextContent('\nbé'), + LlamaImageContent(bytes: bytes, width: 1, height: 1), + const LlamaTextContent('c'), + const LlamaTextContent('d'), + LlamaAudioContent(samples: pcm), + LlamaAudioContent(bytes: bytes), + const LlamaImageContent(path: 'image'), + const LlamaAudioContent(path: 'audio'), + const LlamaImageContent(url: 'https://invalid.example'), + ]), ], - ); - expect(DetokenizeResponse('t').text, 't'); - expect(MetadataResponse({'a': 'b'}).metadata, {'a': 'b'}); - expect(GetContextSizeResponse(10).size, 10); - expect(ErrorResponse('e').message, 'e'); - expect(ErrorResponse('e').kind, WorkerErrorKind.generic); - expect( - ErrorResponse('unsupported', kind: WorkerErrorKind.unsupported).kind, - WorkerErrorKind.unsupported, - ); - expect( - ErrorResponse('inference', kind: WorkerErrorKind.inference).kind, - WorkerErrorKind.inference, - ); - expect( - ErrorResponse('audio', kind: WorkerErrorKind.audioFormat).kind, - WorkerErrorKind.audioFormat, - ); - expect( - ErrorResponse('tts', kind: WorkerErrorKind.textToSpeech).kind, - WorkerErrorKind.textToSpeech, - ); - expect(BackendInfoResponse('n').name, 'n'); - expect(GpuSupportResponse(true).support, true); - expect( - WorkerHandshake(LlamaLogLevel.debug, sp).initialLogLevel, - LlamaLogLevel.debug, - ); - expect(WorkerHandshake(LlamaLogLevel.debug, sp).sendPort, sp); - expect(DoneResponse(), isNotNull); - }); - - test('PerformanceContextResponse keeps speculative counters', () { - final res = PerformanceContextResponse( - loadMs: 1, - promptEvalMs: 2, - evalMs: 3, - sampleMs: 4, - decodeMs: 5, - promptEvalTokens: 6, - evalTokens: 7, - sampleCount: 8, - reusedGraphs: 9, - speculativeDraftTokens: 0, - speculativeAcceptedDraftTokens: 0, - speculativeDraftAttempts: 10, - speculativeVerifyTokens: 11, - speculativeReplayTokens: 12, - speculativeDraftMs: 0, - speculativeVerifyMs: 13, - ); - - expect(res.speculativeDraftTokens, 0); - expect(res.speculativeAcceptedDraftTokens, 0); - expect(res.speculativeDraftAttempts, 10); - expect(res.speculativeVerifyTokens, 11); - expect(res.speculativeReplayTokens, 12); - }); - }); - - // Close the port to avoid hanging - rp.close(); + false, + 123, + port.sendPort, + ); + bytes[0] = 9; + pcm[0] = 1; + final parts = request.inputs.single.parts; + expect(parts, hasLength(8)); + expect((parts[0] as LlamaTextContent).text, 'a \nbé'); + expect((parts[1] as LlamaImageContent).bytes, [1, 2, 3]); + expect((parts[1] as LlamaImageContent).width, 1); + expect((parts[2] as LlamaTextContent).text, 'cd'); + expect((parts[3] as LlamaAudioContent).samples, [0, 0.25]); + expect((parts[4] as LlamaAudioContent).bytes, [1, 2, 3]); + expect((parts[5] as LlamaImageContent).path, 'image'); + expect((parts[6] as LlamaAudioContent).path, 'audio'); + expect((parts[7] as LlamaImageContent).url, 'https://invalid.example'); + }, + ); } diff --git a/test/unit/backends/llama_cpp/worker_test.dart b/test/unit/backends/llama_cpp/worker_test.dart index 58c61ea11..dae71f95c 100644 --- a/test/unit/backends/llama_cpp/worker_test.dart +++ b/test/unit/backends/llama_cpp/worker_test.dart @@ -19,10 +19,6 @@ import 'package:llamadart/src/core/llama_logger.dart'; import 'package:test/test.dart'; void main() { - test('llamaWorkerEntry function is available', () { - expect(llamaWorkerEntry, isA()); - }); - group('llamaWorkerEntry isolate routing', () { test('reports and cleans up backend initialization failure', () async { final service = _FailingInitializationLlamaCppService(); diff --git a/test/unit/backends/webgpu/webgpu_backend_test.dart b/test/unit/backends/webgpu/webgpu_backend_test.dart index 1514dd045..711b23bed 100644 --- a/test/unit/backends/webgpu/webgpu_backend_test.dart +++ b/test/unit/backends/webgpu/webgpu_backend_test.dart @@ -1143,15 +1143,6 @@ void main() { }); } - test('sends no GPU layers when the CPU backend is preferred', () async { - await backend.modelLoadFromUrl( - 'https://example.com/model.gguf', - const ModelParams(gpuLayers: 99, preferredBackend: GpuBackend.cpu), - ); - - expect(lastRequestedGpuLayers, 0); - }); - test('caps default batches to a short CPU context', () async { await backend.modelLoadFromUrl( 'https://example.com/multilingual-e5-small-Q8_0.gguf', @@ -3076,79 +3067,6 @@ void main() { }); }); - test('rejects speculative decoding', () { - expect( - () => backend.generate( - 1, - 'Hello', - const GenerationParams(speculativeDecoding: true), - ), - throwsA( - isA().having( - (error) => error.message.toString(), - 'message', - contains('speculative decoding'), - ), - ), - ); - }); - - test('rejects presence penalty', () { - expect( - () => backend.generate( - 1, - 'Hello', - const GenerationParams(presencePenalty: 1.5), - ), - throwsA( - isA().having( - (error) => error.message.toString(), - 'message', - contains('presence penalty'), - ), - ), - ); - }); - - test('rejects thinking budget', () { - expect( - () => backend.generate( - 1, - 'Hello', - const GenerationParams(thinkingBudget: ThinkingBudget(maxTokens: 16)), - ), - throwsA( - isA().having( - (error) => error.message.toString(), - 'message', - contains('thinking-budget control'), - ), - ), - ); - }); - - test('rejects speculative decoding config', () { - for (final config in const [ - SpeculativeDecodingConfig.mtp(), - SpeculativeDecodingConfig.draftDspark(draftModelPath: 'draft.gguf'), - ]) { - expect( - () => backend.generate( - 1, - 'Hello', - GenerationParams(speculativeDecodingConfig: config), - ), - throwsA( - isA().having( - (error) => error.message.toString(), - 'message', - contains('speculative decoding'), - ), - ), - ); - } - }); - group('a cancelGeneration during a completion', () { late _ResultRecorder recorder; @@ -3675,34 +3593,6 @@ void main() { }); }); - test('throws clear error for unsupported runtime LoRA updates', () async { - await backend.modelLoadFromUrl( - 'https://example.com/model.gguf', - const ModelParams(), - ); - - Future expectLoraUnsupported(Future Function() action) { - return expectLater( - action, - throwsA( - isA().having( - (UnsupportedError error) => error.message, - 'message', - allOf(contains('WebGPU LoRA'), contains('native llama.cpp')), - ), - ), - ); - } - - await expectLoraUnsupported( - () => backend.setLoraAdapter(1, '/adapter.gguf', 0.7), - ); - await expectLoraUnsupported( - () => backend.removeLoraAdapter(1, '/adapter.gguf'), - ); - await expectLoraUnsupported(() => backend.clearLoraAdapters(1)); - }); - test('forwards state persistence calls to bridge', () async { expect(backend.supportsStatePersistence, isFalse); await backend.modelLoadFromUrl( @@ -5899,18 +5789,6 @@ void main() { _jsRangeError('Maximum call stack size exceeded'), 'Maximum call stack size exceeded', ), - ( - 'allocation', - _jsRangeError('Array buffer allocation failed'), - 'Array buffer allocation failed', - ), - ( - 'null dereference', - _jsTypeError( - "Cannot read properties of null (reading 'ccall')", - ), - "Cannot read properties of null (reading 'ccall')", - ), ]) { for (final operation in [ 'lora', @@ -6064,11 +5942,6 @@ void main() { ), isA(), ), - ( - 'type', - _jsTypeError('CompletionOptions.thinkingBudget must be an object.'), - isA(), - ), ( 'worker', _jsError( @@ -6081,11 +5954,6 @@ void main() { _jsError('GPU dispatch failed'), isA(), ), - ( - 'misleading text', - _jsError('TypeError: invalid argument during GPU dispatch'), - isA(), - ), ]) { for (final operation in [ 'generate', diff --git a/test/unit/core/engine/engine_test.dart b/test/unit/core/engine/engine_test.dart index bac471c3c..54dbeb1af 100644 --- a/test/unit/core/engine/engine_test.dart +++ b/test/unit/core/engine/engine_test.dart @@ -1321,11 +1321,6 @@ void main() { }); group('LlamaEngine Mock Tests', () { - test('loadModel successful', () async { - await engine.loadModel('qwen-test.gguf'); - expect(engine.isReady, true); - }); - test('loadModel log states whether engine creation is deferred', () async { final records = []; await LlamaLogging.configure( @@ -2642,6 +2637,7 @@ void main() { await engine.dispose(); expect(engine.isDisposed, isTrue); + expect(engine.isReady, isFalse); expect(backend.disposeCalls, 1); expect(backend.modelFreeCalls, 1); }); @@ -4289,36 +4285,45 @@ void main() { ), }; - for (final MapEntry(key: name, value: (format, detail)) - in cases.entries) { - for (final (label, makeBackend) - in <(String, MockLlamaBackend Function())>[ - ('grammar-capable backend', MockLlamaBackend.new), - ('no-grammar backend', NoGrammarMockLlamaBackend.new), - ('native-chat backend', NativeChatMockBackend.new), - ]) { - test('$name on $label', () async { - final testBackend = makeBackend(); - final testEngine = LlamaEngine(testBackend); - await testEngine.loadModel('gemma4-test.litertlm'); - - await expectLater( - testEngine.create(messages, responseFormat: format).drain(), - throwsA( - isA().having( - (error) => error.message, - 'message', - contains(detail), - ), + // Every shape fails in the same validator; the other backends prove + // that it runs before their own routing. + for (final (name, label, makeBackend) + in <(String, String, MockLlamaBackend Function())>[ + for (final name in cases.keys) + (name, 'grammar-capable backend', MockLlamaBackend.new), + ( + 'misspelled type', + 'no-grammar backend', + NoGrammarMockLlamaBackend.new, + ), + ( + 'misspelled type', + 'native-chat backend', + NativeChatMockBackend.new, + ), + ]) { + final (format, detail) = cases[name]!; + test('$name on $label', () async { + final testBackend = makeBackend(); + final testEngine = LlamaEngine(testBackend); + await testEngine.loadModel('gemma4-test.litertlm'); + + await expectLater( + testEngine.create(messages, responseFormat: format).drain(), + throwsA( + isA().having( + (error) => error.message, + 'message', + contains(detail), ), - ); - expect(testBackend.lastGenerationPrompt, isNull); - if (testBackend is NativeChatMockBackend) { - expect(testBackend.nativeGenerateChatCalls, 0); - } - await testEngine.dispose(); - }); - } + ), + ); + expect(testBackend.lastGenerationPrompt, isNull); + if (testBackend is NativeChatMockBackend) { + expect(testBackend.nativeGenerateChatCalls, 0); + } + await testEngine.dispose(); + }); } test('chatTemplate rejects the same shapes', () async { @@ -5013,11 +5018,6 @@ void main() { expect(backend.lastLoraPath, isNull); }); - test('cancelGeneration', () { - engine.cancelGeneration(); - // Should not throw - }); - group('cancelGeneration before the backend starts', () { late TokenCancelBackend tokenBackend; late LlamaEngine tokenEngine; @@ -5225,44 +5225,6 @@ void main() { expect(await perfEngine.getPerformanceContext(), isNotNull); }); - test( - 'embeddings after the cancelled request report their counters', - () async { - final perfEngine = LlamaEngine( - PerformanceCounterBackend(nativeChat: false), - ); - addTearDown(perfEngine.dispose); - await cancelOneEarly(perfEngine); - - await perfEngine.embed('hello'); - expect((await perfEngine.getPerformanceContext())?.evalTokens, 0); - }, - ); - - test('batch embeddings after the cancelled request report their ' - 'counters', () async { - final perfEngine = LlamaEngine( - PerformanceCounterBackend(nativeChat: false), - ); - addTearDown(perfEngine.dispose); - await cancelOneEarly(perfEngine); - - await perfEngine.embedBatch(const ['hello', 'world']); - expect((await perfEngine.getPerformanceContext())?.evalTokens, 0); - }); - - test('next-token scoring after the cancelled request reports its ' - 'counters', () async { - final perfEngine = LlamaEngine( - PerformanceCounterBackend(nativeChat: false), - ); - addTearDown(perfEngine.dispose); - await cancelOneEarly(perfEngine); - - await perfEngine.scoreNextToken('hello', topK: 1); - expect((await perfEngine.getPerformanceContext())?.evalTokens, 0); - }); - test('text-to-speech after the cancelled request reports its ' 'counters', () async { final perfEngine = LlamaEngine( @@ -5298,13 +5260,6 @@ void main() { await engine.loadModel('qwen-test.gguf'); expect(await engine.getTokenCount('test'), 3); }); - - test('dispose', () async { - await engine.loadModel('qwen-test.gguf'); - await engine.loadMultimodalProjector('proj.gguf'); - await engine.dispose(); - expect(engine.isReady, false); - }); }); group('LlamaEngine subscription cancel during prompt evaluation', () { diff --git a/test/unit/core/exceptions_test.dart b/test/unit/core/exceptions_test.dart index 33e4b7150..0240b2c45 100644 --- a/test/unit/core/exceptions_test.dart +++ b/test/unit/core/exceptions_test.dart @@ -34,68 +34,11 @@ void main() { ); }); - test('LlamaBackendInitializationException properties', () { - final ex = LlamaBackendInitializationException( - 'Backend initialization failed', - 'libllamadart missing', - ); - - expect(ex.message, 'Backend initialization failed'); - expect(ex.details, 'libllamadart missing'); - expect(ex, isA()); - }); - test('LlamaContextException properties', () { final ex = LlamaContextException('Context full'); expect(ex.message, 'Context full'); expect(ex.details, isNull); expect(ex.toString(), 'LlamaException: Context full'); }); - - test('LlamaInferenceException properties', () { - final ex = LlamaInferenceException('Gen failed'); - expect(ex.message, 'Gen failed'); - expect(ex.toString(), contains('Gen failed')); - }); - - test('LlamaSpeechException properties', () { - final ex = LlamaSpeechException('Recognition failed', 'decoder error'); - expect(ex.message, 'Recognition failed'); - expect(ex.details, 'decoder error'); - expect(ex.toString(), contains('Recognition failed')); - }); - - test('LlamaAudioFormatException is a speech exception', () { - final ex = LlamaAudioFormatException('Unsupported audio', 'stereo'); - expect(ex, isA()); - expect(ex.message, 'Unsupported audio'); - expect(ex.details, 'stereo'); - }); - - test('LlamaUnsupportedException properties', () { - final ex = LlamaUnsupportedException('No CUDA'); - expect(ex.message, 'No CUDA'); - expect(ex.toString(), contains('No CUDA')); - }); - - test('LlamaStateException properties', () { - final ex = LlamaStateException('Not loaded'); - expect(ex.message, 'Not loaded'); - expect(ex.toString(), contains('Not loaded')); - }); - - test('LlamaDecisionException properties', () { - final ex = LlamaDecisionException('Too many options', 'plan'); - expect(ex.message, 'Too many options'); - expect(ex.details, 'plan'); - expect(ex.toString(), 'LlamaException: Too many options (plan)'); - }); - - test('LlamaImageGenerationException properties', () { - final ex = LlamaImageGenerationException('width must be 64..2048', 7); - expect(ex.message, 'width must be 64..2048'); - expect(ex.details, 7); - expect(ex.toString(), 'LlamaException: width must be 64..2048 (7)'); - }); }); } diff --git a/test/unit/core/grammar/response_schema_validation_test.dart b/test/unit/core/grammar/response_schema_validation_test.dart index 1623098aa..4c5d71da5 100644 --- a/test/unit/core/grammar/response_schema_validation_test.dart +++ b/test/unit/core/grammar/response_schema_validation_test.dart @@ -451,12 +451,8 @@ void main() { for (final (keyword, bound) in [ ('minimum', '-9223372036854775808'), ('exclusiveMinimum', '-9223372036854775808'), - ('maximum', '-9223372036854775808'), ('exclusiveMaximum', '-9223372036854775808'), - ('minimum', '9223372036854775807'), ('maximum', '9223372036854775807'), - ('minimum', '-9223372036854775809'), - ('maximum', '9223372036854775808'), ('minimum', '-9.3e18'), ('minimum', '-9007199254740992'), ('maximum', '9007199254740992'), diff --git a/test/unit/core/models/download/model_download_manager_test.dart b/test/unit/core/models/download/model_download_manager_test.dart deleted file mode 100644 index 4abfc6fb7..000000000 --- a/test/unit/core/models/download/model_download_manager_test.dart +++ /dev/null @@ -1,29 +0,0 @@ -@TestOn('vm') -library; - -import 'dart:io'; - -import 'package:llamadart/llamadart.dart'; -import 'package:test/test.dart'; - -void main() { - group('model_download_manager export', () { - test('exports base API and default IO implementation', () async { - final tempDir = await Directory.systemTemp.createTemp( - 'llamadart_model_manager_export_test_', - ); - try { - final manager = DefaultModelDownloadManager( - defaultCacheDirectory: tempDir.path, - ); - - expect(manager, isA()); - expect(await manager.list(), isEmpty); - } finally { - if (await tempDir.exists()) { - await tempDir.delete(recursive: true); - } - } - }); - }); -} diff --git a/test/unit/core/models/tools/tool_definition_test.dart b/test/unit/core/models/tools/tool_definition_test.dart index 34ca7e54a..9f8e55858 100644 --- a/test/unit/core/models/tools/tool_definition_test.dart +++ b/test/unit/core/models/tools/tool_definition_test.dart @@ -2,32 +2,9 @@ import 'package:test/test.dart'; import 'package:llamadart/src/core/exceptions.dart'; import 'package:llamadart/src/core/models/tools/tool_definition.dart'; import 'package:llamadart/src/core/models/tools/tool_param.dart'; -import 'package:llamadart/src/core/models/tools/tool_params.dart'; void main() { group('Tool Models Tests', () { - test('ToolParam constructors and toJsonSchema', () { - final p1 = ToolParam.string('loc', description: 'City', required: true); - expect(p1.name, 'loc'); - expect(p1.required, true); - expect(p1.toJsonSchema(), {'type': 'string', 'description': 'City'}); - - final p2 = ToolParam.number('count'); - expect(p2.toJsonSchema(), {'type': 'number'}); - - final p3 = ToolParam.boolean('flag'); - expect(p3.toJsonSchema(), {'type': 'boolean'}); - - final p4 = ToolParam.integer('id'); - expect(p4.toJsonSchema(), {'type': 'integer'}); - - final p5 = ToolParam.enumType('unit', values: ['c', 'f']); - expect(p5.toJsonSchema(), { - 'type': 'string', - 'enum': ['c', 'f'], - }); - }); - test('ToolDefinition toJson and toJsonSchema', () { final tool = ToolDefinition( name: 'test_tool', @@ -89,30 +66,5 @@ void main() { ), ); }); - - test('ToolParams safe accessors', () { - final tp = ToolParams( - { - 's': 'val', - 'i': 123, - 'd': 45.6, - 'b': true, - 'l': [1, 2], - 'm': {'k': 'v'}, - } - as Map, - ); - - expect(tp.getString('s'), 'val'); - expect(tp.getString('missing'), isNull); - expect(tp.getRequiredString('s'), 'val'); - expect(() => tp.getRequiredString('missing'), throwsArgumentError); - - expect(tp.getInt('i'), 123); - expect(tp.getDouble('d'), 45.6); - expect(tp.getBool('b'), true); - expect(tp.getList('l'), [1, 2]); - expect(tp.getObject('m')?.raw, {'k': 'v'}); - }); }); } diff --git a/test/unit/core/models/tools/tool_param_test.dart b/test/unit/core/models/tools/tool_param_test.dart index 3167d8611..60a3b4749 100644 --- a/test/unit/core/models/tools/tool_param_test.dart +++ b/test/unit/core/models/tools/tool_param_test.dart @@ -1,6 +1,5 @@ import 'package:test/test.dart'; import 'package:llamadart/src/core/models/tools/tool_param.dart'; -import 'package:llamadart/src/core/models/tools/tool_params.dart'; void main() { group('ToolParam', () { @@ -69,74 +68,4 @@ void main() { }); }); }); - - group('ToolParams', () { - final data = { - 's': 'hello', - 'i': 42, - 'd': 3.14, - 'b': true, - 'l': [1, 2, 3], - 'o': {'x': 1}, - }; - final params = ToolParams(data); - - test('getString', () { - expect(params.getString('s'), 'hello'); - expect(params.getString('none'), isNull); - expect(() => params.getString('i'), throwsArgumentError); - expect(params.getRequiredString('s'), 'hello'); - expect(() => params.getRequiredString('none'), throwsArgumentError); - }); - - test('getInt', () { - expect(params.getInt('i'), 42); - expect(params.getInt('d'), 3); - expect(params.getInt('none'), isNull); - expect(() => params.getInt('s'), throwsArgumentError); - expect(params.getRequiredInt('i'), 42); - }); - - test('getDouble', () { - expect(params.getDouble('d'), 3.14); - expect(params.getDouble('i'), 42.0); - expect(params.getDouble('none'), isNull); - expect(() => params.getDouble('s'), throwsArgumentError); - expect(params.getRequiredDouble('d'), 3.14); - }); - - test('getBool', () { - expect(params.getBool('b'), true); - expect(params.getBool('none'), isNull); - expect(() => params.getBool('s'), throwsArgumentError); - expect(params.getRequiredBool('b'), true); - }); - - test('getList', () { - expect(params.getList('l'), [1, 2, 3]); - expect(params.getList('none'), isNull); - expect(() => params.getList('s'), throwsArgumentError); - expect(params.getRequiredList('l'), [1, 2, 3]); - }); - - test('getObject', () { - final obj = params.getObject('o'); - expect(obj, isNotNull); - expect(obj!.getInt('x'), 1); - expect(params.getObject('none'), isNull); - expect(() => params.getObject('s'), throwsArgumentError); - expect(params.getRequiredObject('o').getInt('x'), 1); - }); - - test('has and raw', () { - expect(params.has('s'), true); - expect(params.has('none'), false); - expect(params.raw, data); - expect(params['s'], 'hello'); - }); - - test('toString', () { - expect(params.toString(), contains('s: hello')); - }); - }); } diff --git a/test/unit/core/models/tools/tool_params_test.dart b/test/unit/core/models/tools/tool_params_test.dart index 7696ee18d..cf0c83ab6 100644 --- a/test/unit/core/models/tools/tool_params_test.dart +++ b/test/unit/core/models/tools/tool_params_test.dart @@ -2,12 +2,73 @@ import 'package:llamadart/src/core/models/tools/tool_params.dart'; import 'package:test/test.dart'; void main() { - test('ToolParams exposes typed value accessors', () { - const params = ToolParams({'name': 'Seoul', 'count': 3, 'enabled': true}); + group('ToolParams', () { + final data = { + 's': 'hello', + 'i': 42, + 'd': 3.14, + 'b': true, + 'l': [1, 2, 3], + 'o': {'x': 1}, + }; + final params = ToolParams(data); - expect(params.getRequiredString('name'), 'Seoul'); - expect(params.getRequiredInt('count'), 3); - expect(params.getRequiredBool('enabled'), isTrue); - expect(params.has('name'), isTrue); + test('getString', () { + expect(params.getString('s'), 'hello'); + expect(params.getString('none'), isNull); + expect(() => params.getString('i'), throwsArgumentError); + expect(params.getRequiredString('s'), 'hello'); + expect(() => params.getRequiredString('none'), throwsArgumentError); + }); + + test('getInt', () { + expect(params.getInt('i'), 42); + expect(params.getInt('d'), 3); + expect(params.getInt('none'), isNull); + expect(() => params.getInt('s'), throwsArgumentError); + expect(params.getRequiredInt('i'), 42); + }); + + test('getDouble', () { + expect(params.getDouble('d'), 3.14); + expect(params.getDouble('i'), 42.0); + expect(params.getDouble('none'), isNull); + expect(() => params.getDouble('s'), throwsArgumentError); + expect(params.getRequiredDouble('d'), 3.14); + }); + + test('getBool', () { + expect(params.getBool('b'), true); + expect(params.getBool('none'), isNull); + expect(() => params.getBool('s'), throwsArgumentError); + expect(params.getRequiredBool('b'), true); + }); + + test('getList', () { + expect(params.getList('l'), [1, 2, 3]); + expect(params.getList('none'), isNull); + expect(() => params.getList('s'), throwsArgumentError); + expect(params.getRequiredList('l'), [1, 2, 3]); + }); + + test('getObject', () { + final obj = params.getObject('o'); + expect(obj, isNotNull); + expect(obj!.getInt('x'), 1); + expect(params.getObject('none'), isNull); + expect(() => params.getObject('s'), throwsArgumentError); + expect(params.getRequiredObject('o').getInt('x'), 1); + }); + + test('has and raw', () { + expect(params.has('s'), true); + expect(params.has('none'), false); + expect(params.raw, data); + expect(params['s'], 'hello'); + }); + + test('toString', () { + expect(params.toString(), contains('s: hello')); + }); }); } diff --git a/test/unit/core/speech/litert_lm_speech_to_text_driver_test.dart b/test/unit/core/speech/litert_lm_speech_to_text_driver_test.dart deleted file mode 100644 index 758df7e03..000000000 --- a/test/unit/core/speech/litert_lm_speech_to_text_driver_test.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:llamadart/src/core/speech/litert_lm_speech_to_text_driver.dart'; -import 'package:test/test.dart'; - -void main() { - test('support result preserves capability diagnostics', () { - const support = LiteRtLmSpeechToTextSupport( - isSupported: false, - unsupportedReason: 'missing ASR ABI', - ); - - expect(support.isSupported, isFalse); - expect(support.unsupportedReason, 'missing ASR ABI'); - }); - - test('worker update preserves cumulative transcript state', () { - const update = LiteRtLmSpeechToTextUpdate( - confirmedText: 'hello', - pendingText: 'world', - isFinal: false, - acceptedSamples: 16000, - ); - - expect(update.confirmedText, 'hello'); - expect(update.pendingText, 'world'); - expect(update.isFinal, isFalse); - expect(update.acceptedSamples, 16000); - }); -} diff --git a/test/unit/core/speech/speech_platform_stub_test.dart b/test/unit/core/speech/speech_platform_stub_test.dart deleted file mode 100644 index 259e3f945..000000000 --- a/test/unit/core/speech/speech_platform_stub_test.dart +++ /dev/null @@ -1,18 +0,0 @@ -@TestOn('vm') -library; - -import 'package:llamadart/src/core/speech/speech_platform_stub.dart'; -import 'package:test/test.dart'; - -void main() { - test('native platform accepts file input and unencoded audio', () { - expect(speechToTextRequiresBackendCapability, isFalse); - expect(speechToTextUsesChatTemplate, isTrue); - expect(speechToTextSupportsFileInput, isTrue); - expect(speechToTextRequiresEncodedAudioFormat, isFalse); - expect( - speechToTextEncodedAudioFormats, - equals({'wav', 'mp3', 'flac'}), - ); - }); -} diff --git a/test/unit/core/speech/speech_platform_web_test.dart b/test/unit/core/speech/speech_platform_web_test.dart deleted file mode 100644 index 797dace85..000000000 --- a/test/unit/core/speech/speech_platform_web_test.dart +++ /dev/null @@ -1,18 +0,0 @@ -@TestOn('browser') -library; - -import 'package:llamadart/src/core/speech/speech_platform_web.dart'; -import 'package:test/test.dart'; - -void main() { - test('web platform exposes byte-only WAV, MP3 and FLAC prompt speech', () { - expect(speechToTextRequiresBackendCapability, isTrue); - expect(speechToTextUsesChatTemplate, isFalse); - expect(speechToTextSupportsFileInput, isFalse); - expect(speechToTextRequiresEncodedAudioFormat, isTrue); - expect( - speechToTextEncodedAudioFormats, - equals({'wav', 'mp3', 'flac'}), - ); - }); -} diff --git a/test/unit/core/speech/text_to_speech_platform_stub_test.dart b/test/unit/core/speech/text_to_speech_platform_stub_test.dart deleted file mode 100644 index 8b7e99a80..000000000 --- a/test/unit/core/speech/text_to_speech_platform_stub_test.dart +++ /dev/null @@ -1,11 +0,0 @@ -@TestOn('vm') -library; - -import 'package:llamadart/src/core/speech/text_to_speech_platform_stub.dart'; -import 'package:test/test.dart'; - -void main() { - test('native platform accepts speaker-reference file input', () { - expect(textToSpeechSupportsFileInput, isTrue); - }); -} diff --git a/test/unit/core/speech/text_to_speech_platform_web_test.dart b/test/unit/core/speech/text_to_speech_platform_web_test.dart deleted file mode 100644 index 65955ebef..000000000 --- a/test/unit/core/speech/text_to_speech_platform_web_test.dart +++ /dev/null @@ -1,11 +0,0 @@ -@TestOn('browser') -library; - -import 'package:llamadart/src/core/speech/text_to_speech_platform_web.dart'; -import 'package:test/test.dart'; - -void main() { - test('web platform rejects speaker-reference file input', () { - expect(textToSpeechSupportsFileInput, isFalse); - }); -} diff --git a/test/unit/core/template/handlers/apriel15_handler_test.dart b/test/unit/core/template/handlers/apriel15_handler_test.dart index bee82e5be..ff39748e7 100644 --- a/test/unit/core/template/handlers/apriel15_handler_test.dart +++ b/test/unit/core/template/handlers/apriel15_handler_test.dart @@ -3,15 +3,9 @@ import 'dart:convert'; import 'package:llamadart/src/core/template/handlers/apriel15_handler.dart'; import 'package:llamadart/src/core/models/tools/tool_definition.dart'; import 'package:llamadart/src/core/models/tools/tool_param.dart'; -import 'package:llamadart/src/core/template/chat_format.dart'; import 'package:test/test.dart'; void main() { - test('Apriel15Handler exposes chat format', () { - final handler = Apriel15Handler(); - expect(handler.format, isA()); - }); - test('Apriel15Handler emits xml-style grammar for tools', () { final handler = Apriel15Handler(); final tools = [ diff --git a/test/unit/core/template/handlers/exaone_moe_handler_test.dart b/test/unit/core/template/handlers/exaone_moe_handler_test.dart index d3ad60140..d991312b2 100644 --- a/test/unit/core/template/handlers/exaone_moe_handler_test.dart +++ b/test/unit/core/template/handlers/exaone_moe_handler_test.dart @@ -1,6 +1,5 @@ import 'dart:convert'; -import 'package:llamadart/src/core/template/chat_format.dart'; import 'package:llamadart/src/core/template/handlers/exaone_moe_handler.dart'; import 'package:test/test.dart'; @@ -11,11 +10,6 @@ void main() { expect(ExaoneMoeHandler.toolCallOpening('Use or .'), 18); }); - test('ExaoneMoeHandler exposes chat format', () { - final handler = ExaoneMoeHandler(); - expect(handler.format, isA()); - }); - test('ExaoneMoeHandler parses tool calls from tagged JSON blocks', () { final handler = ExaoneMoeHandler(); diff --git a/test/unit/core/template/handlers/functionary_v31_llama31_handler_test.dart b/test/unit/core/template/handlers/functionary_v31_llama31_handler_test.dart index 5362e5952..2e45e717e 100644 --- a/test/unit/core/template/handlers/functionary_v31_llama31_handler_test.dart +++ b/test/unit/core/template/handlers/functionary_v31_llama31_handler_test.dart @@ -1,16 +1,10 @@ import 'dart:convert'; -import 'package:llamadart/src/core/template/chat_format.dart'; import 'package:llamadart/src/core/template/handlers/functionary_v31_llama31_handler.dart'; import 'package:test/test.dart'; void main() { group('FunctionaryV31Llama31Handler', () { - test('exposes chat format', () { - final handler = FunctionaryV31Llama31Handler(); - expect(handler.format, isA()); - }); - test('parses function tags and python fallback', () { final handler = FunctionaryV31Llama31Handler(); final parsed = handler.parse( diff --git a/test/unit/core/template/handlers/functionary_v32_handler_test.dart b/test/unit/core/template/handlers/functionary_v32_handler_test.dart index 09933a0a3..f5fb10a53 100644 --- a/test/unit/core/template/handlers/functionary_v32_handler_test.dart +++ b/test/unit/core/template/handlers/functionary_v32_handler_test.dart @@ -1,14 +1,8 @@ -import 'package:llamadart/src/core/template/chat_format.dart'; import 'package:llamadart/src/core/template/handlers/functionary_v32_handler.dart'; import 'package:test/test.dart'; void main() { group('FunctionaryV32Handler', () { - test('exposes chat format', () { - final handler = FunctionaryV32Handler(); - expect(handler.format, isA()); - }); - test('parses JSON tool calls with >>>name markers', () { final handler = FunctionaryV32Handler(); final parsed = handler.parse('>>>weather\n{"city":"Seoul"}'); diff --git a/test/unit/core/template/handlers/gemma_handler_test.dart b/test/unit/core/template/handlers/gemma_handler_test.dart index 55951c683..8c51bd2a7 100644 --- a/test/unit/core/template/handlers/gemma_handler_test.dart +++ b/test/unit/core/template/handlers/gemma_handler_test.dart @@ -4,17 +4,11 @@ import 'package:llamadart/src/core/models/chat/chat_message.dart'; import 'package:llamadart/src/core/models/chat/chat_role.dart'; import 'package:llamadart/src/core/models/tools/tool_definition.dart'; import 'package:llamadart/src/core/models/tools/tool_param.dart'; -import 'package:llamadart/src/core/template/chat_format.dart'; import 'package:llamadart/src/core/template/handlers/gemma_handler.dart'; import 'package:test/test.dart'; void main() { group('GemmaHandler', () { - test('exposes chat format', () { - final handler = GemmaHandler(); - expect(handler.format, isA()); - }); - test('parses args from alias keys', () { final handler = GemmaHandler(); final parsed = handler.parse( diff --git a/test/unit/core/template/handlers/granite_handler_test.dart b/test/unit/core/template/handlers/granite_handler_test.dart index 0516f8f19..7201ee5f5 100644 --- a/test/unit/core/template/handlers/granite_handler_test.dart +++ b/test/unit/core/template/handlers/granite_handler_test.dart @@ -1,6 +1,5 @@ import 'dart:convert'; -import 'package:llamadart/src/core/template/chat_format.dart'; import 'package:llamadart/src/core/template/handlers/granite_handler.dart'; import 'package:test/test.dart'; @@ -14,11 +13,6 @@ void main() { expect(GraniteHandler.toolCallOpening('Use or [y] here.'), 20); }); - test('GraniteHandler exposes chat format', () { - final handler = GraniteHandler(); - expect(handler.format, isA()); - }); - test('parses tool-call array with whitespace after marker', () { final handler = GraniteHandler(); final parsed = handler.parse( diff --git a/test/unit/core/template/handlers/llama3_handler_test.dart b/test/unit/core/template/handlers/llama3_handler_test.dart index 4e6ce48cf..68b0c6b17 100644 --- a/test/unit/core/template/handlers/llama3_handler_test.dart +++ b/test/unit/core/template/handlers/llama3_handler_test.dart @@ -11,11 +11,6 @@ import 'package:test/test.dart'; void main() { final messages = [const LlamaChatMessage(role: 'user', content: 'hello')]; - test('Llama3Handler exposes chat format', () { - final handler = Llama3Handler(); - expect(handler.format, isA()); - }); - test('returns content-only format when no tools are provided', () { final handler = Llama3Handler(); final result = handler.render( diff --git a/test/unit/core/template/handlers/solar_open_handler_test.dart b/test/unit/core/template/handlers/solar_open_handler_test.dart index ae032e247..eb7087b55 100644 --- a/test/unit/core/template/handlers/solar_open_handler_test.dart +++ b/test/unit/core/template/handlers/solar_open_handler_test.dart @@ -10,11 +10,6 @@ import 'package:llamadart/src/core/template/handlers/solar_open_handler.dart'; import 'package:test/test.dart'; void main() { - test('SolarOpenHandler exposes chat format', () { - final handler = SolarOpenHandler(); - expect(handler.format, isA()); - }); - test('SolarOpenHandler emits parser and preserves tool tokens', () { final handler = SolarOpenHandler(); final tools = [ diff --git a/test/unit/core/template/template_internal_metadata_test.dart b/test/unit/core/template/template_internal_metadata_test.dart index dfb048ace..0f7653010 100644 --- a/test/unit/core/template/template_internal_metadata_test.dart +++ b/test/unit/core/template/template_internal_metadata_test.dart @@ -2,31 +2,6 @@ import 'package:llamadart/src/core/template/template_internal_metadata.dart'; import 'package:test/test.dart'; void main() { - group('template internal metadata keys', () { - test('expose stable key names for engine-handler coordination', () { - expect( - internalToolChoiceMetadataKey, - equals('llamadart.internal.tool_choice'), - ); - expect( - internalParallelToolCallsMetadataKey, - equals('llamadart.internal.parallel_tool_calls'), - ); - }); - - test('keys are distinct and namespaced', () { - expect( - internalToolChoiceMetadataKey, - isNot(equals(internalParallelToolCallsMetadataKey)), - ); - expect(internalToolChoiceMetadataKey, startsWith('llamadart.internal.')); - expect( - internalParallelToolCallsMetadataKey, - startsWith('llamadart.internal.'), - ); - }); - }); - group('chatTemplateKwargsFromMetadata', () { test('decodes the stored kwargs object', () { expect( diff --git a/test/unit/core/template/template_render_context_test.dart b/test/unit/core/template/template_render_context_test.dart index c583bdfde..3e0db0348 100644 --- a/test/unit/core/template/template_render_context_test.dart +++ b/test/unit/core/template/template_render_context_test.dart @@ -25,13 +25,9 @@ void main() { null, 'unchanged "text" 👋', ]) { - for (final (multimodal, typedContentOnly) in [ - (false, false), - (true, false), - (true, true), - ]) { + for (final typedContentOnly in [false, true]) { test('serializes typed tool result ${payload.runtimeType}, ' - 'multimodal=$multimodal, typedContentOnly=$typedContentOnly', () { + 'typedContentOnly=$typedContentOnly', () { final part = LlamaToolResultContent( id: 'call_0', name: 'get_weather', @@ -42,11 +38,9 @@ void main() { content: [part], ); final before = message.toJson(); - final rendered = TemplateRenderContext.messagesForTemplate( - [message], - multimodal: multimodal, - typedContentOnly: typedContentOnly, - ).single; + final rendered = TemplateRenderContext.messagesForTemplate([ + message, + ], typedContentOnly: typedContentOnly).single; final expected = payload is String ? payload : jsonEncode(payload); expect( rendered['content'], @@ -63,13 +57,9 @@ void main() { }); } } - for (final (multimodal, typedContentOnly) in [ - (false, false), - (true, false), - (true, true), - ]) { + for (final typedContentOnly in [false, true]) { test('renders one tool message per tool result, ' - 'multimodal=$multimodal, typedContentOnly=$typedContentOnly', () { + 'typedContentOnly=$typedContentOnly', () { const message = LlamaChatMessage.withContent( role: LlamaChatRole.tool, content: [ @@ -92,11 +82,9 @@ void main() { : text; expect( - TemplateRenderContext.messagesForTemplate( - [message], - multimodal: multimodal, - typedContentOnly: typedContentOnly, - ), + TemplateRenderContext.messagesForTemplate([ + message, + ], typedContentOnly: typedContentOnly), [ { 'role': 'tool', @@ -115,15 +103,9 @@ void main() { }); } - for (final (multimodal, typedContentOnly) in [ - (false, false), - (true, false), - (false, true), - (true, true), - ]) { + for (final typedContentOnly in [false, true]) { test('gives tool-call-only and reasoning-only assistant turns empty ' - 'content, multimodal=$multimodal, ' - 'typedContentOnly=$typedContentOnly', () { + 'content, typedContentOnly=$typedContentOnly', () { const messages = [ LlamaChatMessage.withContent( role: LlamaChatRole.assistant, @@ -143,7 +125,6 @@ void main() { final rendered = TemplateRenderContext.messagesForTemplate( messages, - multimodal: multimodal, typedContentOnly: typedContentOnly, ); diff --git a/test/unit/core/template/tool_result_user_turn_render_test.dart b/test/unit/core/template/tool_result_user_turn_render_test.dart index 65e04a845..aadc853c1 100644 --- a/test/unit/core/template/tool_result_user_turn_render_test.dart +++ b/test/unit/core/template/tool_result_user_turn_render_test.dart @@ -18,13 +18,14 @@ import 'package:llamadart/src/core/template/template_caps.dart'; import 'package:test/test.dart'; /// Templates whose role-alternation check rejects a `tool` message. +/// +/// `tool/litert_lm_templates/gemma{,3n}.jinja` are byte-identical to the +/// Gemma 3 fixtures here. const _rejectingTemplates = [ 'test/fixtures/templates/gemma-3-4b-it.jinja', 'test/fixtures/templates/gemma-3n-E4B-it.jinja', 'test/fixtures/templates/Mistral-7B-Instruct-v0_2.jinja', 'test/fixtures/llama_cpp_templates/google-gemma-2-2b-it.jinja', - 'tool/litert_lm_templates/gemma.jinja', - 'tool/litert_lm_templates/gemma3n.jinja', ]; /// Templates that render the `tool` role themselves. @@ -163,11 +164,6 @@ void main() { for (final path in _rejectingTemplates) { group(_name(path), () { - test('reports that it rejects the tool role', () { - final source = File(path).readAsStringSync(); - expect(TemplateCaps.detect(source).supportsToolResponses, isFalse); - }); - for (final choice in ToolChoice.values) { test('sends the result as a user turn with tool_choice ' '${choice.name}', () { diff --git a/test/unit/test_structure/mirrored_unit_structure_test.dart b/test/unit/test_structure/mirrored_unit_structure_test.dart index 61db6b101..65f0cdd6a 100644 --- a/test/unit/test_structure/mirrored_unit_structure_test.dart +++ b/test/unit/test_structure/mirrored_unit_structure_test.dart @@ -9,6 +9,7 @@ import 'package:test/test.dart'; /// Sources with no behavior of their own. The guard below requires each to /// exist under `lib/src` and to have no mirrored file under `test/unit`. const Set behaviorlessSources = { + 'backends/llama_cpp/llama_cpp_raw_bindings.dart', 'backends/webgpu/interop.dart', 'core/decision/decision_model.dart', 'core/image/image_generation_driver.dart', @@ -17,6 +18,12 @@ const Set behaviorlessSources = { 'core/models/config/compute_device.dart', 'core/models/config/flash_attention.dart', 'core/models/config/kv_cache_type.dart', + 'core/models/download/model_download_manager.dart', + 'core/speech/litert_lm_speech_to_text_driver.dart', + 'core/speech/speech_platform_stub.dart', + 'core/speech/speech_platform_web.dart', + 'core/speech/text_to_speech_platform_stub.dart', + 'core/speech/text_to_speech_platform_web.dart', }; void main() { diff --git a/test/unit/tooling/high_risk_review_policy_test.dart b/test/unit/tooling/high_risk_review_policy_test.dart index 190c58a07..3e50a6669 100644 --- a/test/unit/tooling/high_risk_review_policy_test.dart +++ b/test/unit/tooling/high_risk_review_policy_test.dart @@ -135,8 +135,6 @@ void main() { expect(evaluator, isNot(contains('LLAMADART_READINESS_APP_ID'))); expect(evaluator, isNot(contains('LLAMADART_READINESS_PRIVATE_KEY'))); expect(evaluator, isNot(contains('Platform.environment'))); - expect(workflow, contains('pull_request_target:')); - expect(workflow, contains(r'ref: ${{ github.sha }}')); expect(workflow, isNot(contains('workflow_dispatch:'))); expect( workflow, @@ -144,7 +142,6 @@ void main() { contains(r'ref: ${{ github.event.repository.default_branch }}'), ), ); - expect(workflow, contains('persist-credentials: false')); expect(workflow, contains('Read-only advisory')); expect(workflow, contains('observed_head')); expect(workflow, contains('current_head'));