Briefly.NoRootDirectoryError Fix Documentation
Problem Summary
The test suite was failing with Briefly.NoRootDirectoryError and permission errors because:
- Incorrect Root Directory Configuration: The Briefly configuration in
config/test.exswas pointing toconfig/tmpinstead of the project root'stmpdirectory. - System Temp Directory Fallback: Some code was still referencing system temp directories (
/var/folders/.../T/) instead of the project-local tmp. - Permission Issues: Potential permission problems with the tmp directory.
Fixes Applied
1. Fixed Configuration (config/test.exs)
Before:
config :briefly, root: Path.expand("tmp", Path.dirname(__ENV__.file))
This pointed to /Volumes/Storage/belmendo/Projects/codexis/config/tmp
After:
project_root = Path.dirname(Path.dirname(__ENV__.file))
tmp_dir = Path.expand("tmp", project_root)
config :briefly,
root: tmp_dir,
directory: true,
prefix: "codexis_test_"
This correctly points to /Volumes/Storage/belmendo/Projects/codexis/tmp
2. Added Robust Directory Creation and Permission Handling
The new configuration:
- Ensures the tmp directory exists with proper permissions (755)
- Verifies the directory is writable before configuring Briefly
- Sets environment variables (
TMPDIR,TMP,TEMP) as fallbacks - Includes error handling and warnings for permission issues
3. Enhanced Test Helper Functions (test/support/test_helpers.ex)
Added fallback mechanisms that:
- Wrap Briefly calls in try-catch blocks to handle errors gracefully
- Automatically fall back to manual directory/file creation in the project tmp
- Provide consistent behavior even if Briefly fails completely
4. Improved Debugging (test/test_helper.exs)
Enhanced the debug output to show:
- Briefly configuration values
- Environment variables
- Directory existence and permissions
- Test file creation attempts
- More detailed error information
Verification
Quick Test Script
Run the Briefly configuration test script:
cd /Volumes/Storage/belmendo/Projects/codexis
elixir test_briefly.exs
Permission Check Script
Run the permission verification script:
cd /Volumes/Storage/belmendo/Projects/codexis
chmod +x check_permissions.sh
./check_permissions.sh
Minimal Test Case
Run the Briefly-specific test:
cd /Volumes/Storage/belmendo/Projects/codexis
mix test test/briefly_config_test.exs --seed 0
Expected Behavior
After these fixes:
- All temporary files and directories should be created in
/Volumes/Storage/belmendo/Projects/codexis/tmp - No system temp directories should be used (
/var/folders/.../T/) - Tests should run without Briefly.NoRootDirectoryError
- Permission errors should be eliminated
Troubleshooting
If Briefly Still Fails
-
Check directory permissions:
ls -la /Volumes/Storage/belmendo/Projects/codexis/tmp -
Verify configuration is loaded:
Runmix test test/briefly_config_test.exsand check the debug output -
Check for conflicting environment variables:
echo $TMPDIR echo $TMP echo $TEMP -
Manual fallback test:
The enhanced test helpers will automatically fall back to manual file creation if Briefly fails
If Tests Still Reference System Temp
- Check for hardcoded paths in test files
- Look for direct System.tmp_dir() calls that bypass Briefly
- Search for TMPDIR environment variable usage in the codebase
Performance Notes
- The project tmp directory accumulates test files over time
- Periodically clean it with:
rm -rf /Volumes/Storage/belmendo/Projects/codexis/tmp/* - The fallback mechanisms ensure tests continue working even with cleanup issues
Files Modified
config/test.exs- Fixed Briefly root directory configurationtest/test_helper.exs- Enhanced debugging and verificationtest/support/test_helpers.ex- Added fallback mechanismstest/briefly_config_test.exs- Added verification test (new)test_briefly.exs- Standalone test script (new)check_permissions.sh- Permission verification script (new)
Key Configuration Values
- Project Root:
/Volumes/Storage/belmendo/Projects/codexis - Tmp Directory:
/Volumes/Storage/belmendo/Projects/codexis/tmp - Briefly Root: Same as tmp directory
- File Prefix:
codexis_test_ - Directory Permissions: 755 (rwxr-xr-x)
This comprehensive fix should resolve all Briefly-related issues and provide robust fallback mechanisms for any edge cases.