@@ -151,7 +151,8 @@ abstract contract CredibleTestWithBacktesting is CredibleTest, Test {
151151 }
152152
153153 /// @notice Find the transaction_fetcher.sh script path
154- /// @dev Checks environment variable first, then searches common locations
154+ /// @dev Checks environment variable first, then searches common locations,
155+ /// and finally uses `find` to auto-detect the script location.
155156 /// Override _getScriptSearchPaths() to customize search locations
156157 /// @return The path to transaction_fetcher.sh
157158 function _findScriptPath () internal virtual returns (string memory ) {
@@ -188,14 +189,65 @@ abstract contract CredibleTestWithBacktesting is CredibleTest, Test {
188189 }
189190 }
190191
192+ // Auto-detect using find command as fallback
193+ string memory autoDetectedPath = _autoDetectScriptPath ();
194+ if (bytes (autoDetectedPath).length > 0 ) {
195+ _cachedScriptPath = autoDetectedPath;
196+ return _cachedScriptPath;
197+ }
198+
191199 // No valid path found - provide helpful error message
192200 revert (
193201 "transaction_fetcher.sh not found. "
194202 "Set CREDIBLE_STD_PATH environment variable or override _getScriptSearchPaths(). "
195- "Standard locations checked: lib/credible-std/..., dependencies/credible-std/..., ../ credible-std/.. . "
203+ "Auto-detection also failed. Ensure credible-std is installed in your project . "
196204 );
197205 }
198206
207+ /// @notice Auto-detect the script path using find command
208+ /// @dev Searches the project directory for transaction_fetcher.sh
209+ /// @return The detected path, or empty string if not found
210+ function _autoDetectScriptPath () internal virtual returns (string memory ) {
211+ // Use find to locate the script, searching common dependency directories
212+ // Limit depth to avoid searching too deep and improve performance
213+ string [] memory findCmd = new string [](3 );
214+ findCmd[0 ] = "bash " ;
215+ findCmd[1 ] = "-c " ;
216+ findCmd[2 ] = "find . -maxdepth 6 -type f -name 'transaction_fetcher.sh' -path '*/credible-std/*' 2>/dev/null | head -1 " ;
217+
218+ try vm.ffi (findCmd) returns (bytes memory result ) {
219+ string memory foundPath = string (result);
220+ // Trim whitespace/newlines
221+ bytes memory pathBytes = bytes (foundPath);
222+ uint256 len = pathBytes.length ;
223+ while (len > 0 && (pathBytes[len - 1 ] == 0x0a || pathBytes[len - 1 ] == 0x0d || pathBytes[len - 1 ] == 0x20 )) {
224+ len-- ;
225+ }
226+ if (len == 0 ) {
227+ return "" ;
228+ }
229+ bytes memory trimmed = new bytes (len);
230+ for (uint256 i = 0 ; i < len; i++ ) {
231+ trimmed[i] = pathBytes[i];
232+ }
233+ foundPath = string (trimmed);
234+
235+ // Verify the found path exists
236+ string [] memory testCmd = new string [](3 );
237+ testCmd[0 ] = "test " ;
238+ testCmd[1 ] = "-f " ;
239+ testCmd[2 ] = foundPath;
240+
241+ try vm.ffi (testCmd) {
242+ return foundPath;
243+ } catch {
244+ return "" ;
245+ }
246+ } catch {
247+ return "" ;
248+ }
249+ }
250+
199251 /// @notice Fetch transactions using FFI
200252 function _fetchTransactions (
201253 address targetContract ,
0 commit comments