From fb0e77a87ffa16c11ff6f68723f6429d6580c541 Mon Sep 17 00:00:00 2001 From: Klim Date: Sun, 3 May 2026 19:42:39 +0300 Subject: [PATCH] fix(cherrypick): fix fast-path tests to actually exercise silent observer path --- cherrypick/test/src/scope_fast_path_test.dart | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/cherrypick/test/src/scope_fast_path_test.dart b/cherrypick/test/src/scope_fast_path_test.dart index c5d092d..79b5d20 100644 --- a/cherrypick/test/src/scope_fast_path_test.dart +++ b/cherrypick/test/src/scope_fast_path_test.dart @@ -57,41 +57,47 @@ void main() { tearDown(() => CherryPick.closeRootScope()); group('SilentCherryPickObserver fast-path', () { - test('resolve with default silent observer uses fast-path', () { - final scope = CherryPick.openSafeRootScope(); - scope.installModules([_IntModule(42)]); + late Scope scope; - final result = scope.resolve(); - expect(result, 42); + setUp(() { + // Must NOT have cycle detection — otherwise _canUseDirectResolvePath is false + // and the fast-path branch is never taken. + CherryPick.disableGlobalCycleDetection(); + scope = CherryPick.openRootScope(); + }); + + test('resolve with default silent observer uses fast-path', () { + scope.installModules([_IntModule(42)]); + expect(scope.resolve(), 42); }); test('resolveAsync with default silent observer uses fast-path', () async { - final scope = CherryPick.openSafeRootScope(); scope.installModules([_IntModule(42)]); - final result = await scope.resolveAsync(); expect(result, 42); }); test('tryResolve with default silent observer uses fast-path', () { - final scope = CherryPick.openSafeRootScope(); scope.installModules([_IntModule(42)]); - - final result = scope.tryResolve(); - expect(result, 42); + expect(scope.tryResolve(), 42); }); test('tryResolveAsync with default silent observer uses fast-path', () async { - final scope = CherryPick.openSafeRootScope(); scope.installModules([_IntModule(42)]); - final result = await scope.tryResolveAsync(); expect(result, 42); }); + test('fast-path missing dependency throws', () { + expect(() => scope.resolve(), throwsStateError); + }); + + test('fast-path missing async dependency throws', () { + expect(scope.resolveAsync(), throwsA(isA())); + }); + test('installModules with silent observer skips diagnostics', () { - final scope = CherryPick.openSafeRootScope(); var buildCalls = 0; scope.installModules([_IntModule(42, onBuild: () => buildCalls++)]); expect(buildCalls, 1); @@ -99,7 +105,6 @@ void main() { }); test('Disposable is tracked even in silent observer fast-path', () async { - final scope = CherryPick.openSafeRootScope(); scope.installModules([_DisposableModule()]); final service = scope.resolve<_DisposableService>();