@@ -76,35 +76,17 @@ class StubLoader {
7676 /// `name: magic_cli` (works for direct script execution).
7777 /// 3. Check common development paths as fallback.
7878 static List <String > _defaultSearchPaths () {
79- // First, check if we are in a test environment. If we are running tests,
80- // we should use the current working directory's assets/stubs if it exists.
81- // In tests, the script path is often a temp file generated by the test runner.
82- if (Platform .environment.containsKey ('FLUTTER_TEST' ) ||
83- Platform .script.path.endsWith ('.dart' ) &&
84- Platform .script.path.contains ('test' )) {
85- final possibleRoots = [
86- Directory .current.path,
87- // When running test from magic root directory
88- path.join (Directory .current.path, 'plugins' , 'magic_cli' ),
89- // When running tests from IDE, Directory.current might be the project root
90- // but magic_cli is inside plugins
91- path.join (
92- Directory .current.path, 'plugins' , 'magic' , 'plugins' , 'magic_cli' ),
93- // The actual absolute path where we know it exists during development
94- '/Users/anilcan/StudioProjects/uptizm/plugins/magic/plugins/magic_cli'
95- ];
96-
97- for (final root in possibleRoots) {
98- final stubDir = path.join (root, 'assets' , 'stubs' );
99- if (Directory (stubDir).existsSync ()) {
100- return [stubDir];
101- }
102- }
79+ // 1. Environment variable override — highest priority.
80+ // Used in tests: set MAGIC_CLI_STUBS_DIR to point at a custom stubs dir.
81+ final envDir = Platform .environment['MAGIC_CLI_STUBS_DIR' ];
82+ if (envDir != null && Directory (envDir).existsSync ()) {
83+ return [envDir];
10384 }
10485
105- // 1 . Parse .dart_tool/package_config.json — the most reliable strategy.
86+ // 2 . Parse .dart_tool/package_config.json — the most reliable strategy.
10687 // This file is generated by `dart pub get` and contains the rootUri
10788 // for every dependency, including path dependencies.
89+ // Works in all environments: local dev, CI, test, consumer projects.
10890 final packageConfigRoot = _resolveFromPackageConfig ();
10991 if (packageConfigRoot != null ) {
11092 final stubDir = path.join (packageConfigRoot, 'assets' , 'stubs' );
@@ -113,7 +95,7 @@ class StubLoader {
11395 }
11496 }
11597
116- // 2 . Walk up from Platform.script to find the magic_cli pubspec.
98+ // 3 . Walk up from Platform.script to find the magic_cli pubspec.
11799 // Works when running the CLI directly from its own directory.
118100 final scriptPath = Platform .script.toFilePath ();
119101 var current = Directory (path.dirname (scriptPath));
@@ -131,12 +113,10 @@ class StubLoader {
131113 current = parent;
132114 }
133115
134- // 3 . Fallback: check common development paths.
116+ // 4 . Fallback: check current directory and common dev paths.
135117 final possibleRoots = [
136- path.join (Directory .current.path, 'plugins' , 'magic_cli' ),
137118 Directory .current.path,
138- // For testing, since tests run in temp directories
139- '/Users/anilcan/StudioProjects/uptizm/plugins/magic/plugins/magic_cli'
119+ path.join (Directory .current.path, 'plugins' , 'magic_cli' ),
140120 ];
141121
142122 for (final root in possibleRoots) {
0 commit comments