Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix config for default data dir #4535

Merged
merged 4 commits into from
Mar 4, 2025

Conversation

lelemm
Copy link
Contributor

@lelemm lelemm commented Mar 4, 2025

When transitioning from old to new load-config we lost some default values for user data. This fix it

@actual-github-bot actual-github-bot bot changed the title 🐛 Fix config for default data dir [WIP] 🐛 Fix config for default data dir Mar 4, 2025
Copy link

netlify bot commented Mar 4, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit c896d14
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67c73da061917f00082752a7
😎 Deploy Preview https://deploy-preview-4535.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@lelemm lelemm changed the title [WIP] 🐛 Fix config for default data dir 🐛 Fix config for default data dir Mar 4, 2025
matt-fidd
matt-fidd previously approved these changes Mar 4, 2025
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

The changes modify the configuration loading process in the application. The logic determining the default data directory now first checks for the environment variable ACTUAL_DATA_DIR. If this variable is set, its value is used; if not, the code checks for the existence of the /data directory. If neither condition is met, the fallback is the project root directory. Additionally, the default configuration for dataDir, serverFiles, and userFiles in the configuration schema has been updated to utilize the newly defined default data directory instead of directly referencing the project root.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0043111 and c896d14.

📒 Files selected for processing (1)
  • packages/sync-server/src/load-config.js (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/sync-server/src/load-config.js
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Visual regression
  • GitHub Check: Functional
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Build Docker image (alpine)
  • GitHub Check: Build Docker image (ubuntu)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/sync-server/src/load-config.js (1)

14-18: Consider platform compatibility for the hardcoded /data path.

The hardcoded /data path might cause issues on Windows systems where absolute paths are formatted differently. Consider using a platform-agnostic approach or path.join with appropriate components for cross-platform compatibility.

const defaultDataDir = process.env.ACTUAL_DATA_DIR
  ? process.env.ACTUAL_DATA_DIR
-  : fs.existsSync('/data')
-    ? '/data'
+  : fs.existsSync(path.resolve('/data'))
+    ? path.resolve('/data')
     : projectRoot;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90af046 and 7f608a3.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4535.md is excluded by !**/*.md
📒 Files selected for processing (1)
  • packages/sync-server/src/load-config.js (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Build Docker image (alpine)
  • GitHub Check: Build Docker image (ubuntu)
🔇 Additional comments (3)
packages/sync-server/src/load-config.js (3)

272-274: Consistent use of the new default data directory for config.json.

This existing code correctly uses the defaultDataDir for locating the config.json file if it's not found in the project root. This aligns with the changes made to the defaultDataDir variable and ensures consistency across the application.


14-18:

✅ Verification successful

Improved configuration hierarchy for default data directory.

The new logic provides a clearer hierarchy for determining the default data directory:

  1. First, use the ACTUAL_DATA_DIR environment variable if set
  2. Check if /data directory exists and use it as fallback
  3. Ultimately default to projectRoot if neither option is available

This enhancement increases flexibility while maintaining backward compatibility.


🏁 Script executed:

#!/bin/bash
# Description: Check if these changes properly address the issue of missing default values

# Verify that this module is used wherever configuration is loaded
rg -A 3 "load-config|defaultDataDir" --type js

# Check if the ACTUAL_DATA_DIR env var is referenced elsewhere
rg "ACTUAL_DATA_DIR" --type js

Length of output: 4905


Default Data Directory Configuration Verified

The new logic in packages/sync-server/src/load-config.js (lines 14–18) correctly implements the intended hierarchy:

  • Use the ACTUAL_DATA_DIR environment variable if available
  • Fall back to /data if it exists
  • Default to projectRoot otherwise

Search results confirm that the configuration is referenced consistently across the codebase, ensuring backward compatibility and flexibility.


82-82:

✅ Verification successful

Fixed configuration paths to use the correct data directory.

This change properly directs server and user files to the determined data directory rather than always using the project root. This ensures consistent file storage location based on the configured data directory.

Also applies to: 91-91


🏁 Script executed:

#!/bin/bash
# Description: Verify the impact of these path changes on the application

# Check where serverFiles and userFiles are accessed
rg "serverFiles|userFiles" --type js

# Verify if there are any hardcoded paths that might need to be updated
rg -A 1 "server-files|user-files" --type js

Length of output: 2400


Configuration Paths Update Confirmed

The changes in packages/sync-server/src/load-config.js for both lines 82 and 91 now correctly use defaultDataDir rather than falling back to the project root. The search results confirm that all references to serverFiles and userFiles across the codebase correctly use the new configuration values, ensuring that file operations (including those in migrations and utility functions) point to the intended data directory.

  • Files verified:
    • packages/sync-server/src/load-config.js (both server and user file paths)
    • Related usages in migrations and utility functions

The update properly addresses the hardcoded paths and aligns with our goal for consistent file storage based on the configured data directory.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/sync-server/src/load-config.js (1)

14-18: Consider formatting the ternary operators for better readability.

The nested ternary operators could benefit from consistent indentation as flagged by the linter.

const defaultDataDir = process.env.ACTUAL_DATA_DIR
  ? process.env.ACTUAL_DATA_DIR
-  : fs.existsSync('/data')
-  ? '/data'
-  : projectRoot;
+  : fs.existsSync('/data')
+    ? '/data'
+    : projectRoot;
🧰 Tools
🪛 ESLint

[error] 17-17: Insert ··

(prettier/prettier)


[error] 18-18: Insert ··

(prettier/prettier)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f608a3 and 0043111.

📒 Files selected for processing (1)
  • packages/sync-server/src/load-config.js (4 hunks)
🧰 Additional context used
🪛 ESLint
packages/sync-server/src/load-config.js

[error] 17-17: Insert ··

(prettier/prettier)


[error] 18-18: Insert ··

(prettier/prettier)

🔇 Additional comments (5)
packages/sync-server/src/load-config.js (5)

14-18: Enhanced default data directory logic with environment variable support.

The updated approach for determining the default data directory now follows a clear priority order:

  1. Use ACTUAL_DATA_DIR environment variable if set
  2. Use /data directory if it exists
  3. Fall back to projectRoot if neither of the above is available

This change improves configurability while maintaining backward compatibility.

Consider adding write permission verification to ensure the selected directory is writable:

const defaultDataDir = process.env.ACTUAL_DATA_DIR
  ? process.env.ACTUAL_DATA_DIR
  : fs.existsSync('/data')
  ? '/data'
  : projectRoot;
+
+// Verify the directory is writable
+try {
+  fs.accessSync(defaultDataDir, fs.constants.W_OK);
+  debug(`Verified write access to data directory: ${defaultDataDir}`);
+} catch (err) {
+  console.warn(`Warning: Selected data directory "${defaultDataDir}" is not writable. This may cause problems when writing data.`);
+}

This addresses the previous review comment about directory write permission verification.

🧰 Tools
🪛 ESLint

[error] 17-17: Insert ··

(prettier/prettier)


[error] 18-18: Insert ··

(prettier/prettier)


61-61: Updated default data directory for configuration consistency.

The config schema now correctly uses the newly defined defaultDataDir when not in test mode, ensuring consistency with the data directory logic defined earlier.


82-82: Updated server files path to use the same data directory.

Server files are now correctly stored in the configured data directory instead of the project root, which aligns with the fix for data directory defaults.


91-91: Updated user files path to use the same data directory.

User files are now correctly stored in the configured data directory instead of the project root, which aligns with the fix for data directory defaults.


14-18:

❓ Verification inconclusive

Verify config file path resolution works correctly with the new data directory logic.

The code now checks for a config file in defaultDataDir if not found in the project root. Let's ensure this works as expected with the updated defaultDataDir determination logic.

Also applies to: 272-274


🏁 Script executed:

#!/bin/bash
# Description: Verify config file path resolution with the new data directory logic

# 1. Check for any other places in the codebase that might use the config path
echo "Looking for other locations that use config paths:"
rg "config\.json|configPath" --type js

# 2. Check if there are any tests that might need to be updated
echo "Checking tests that might need to be updated:"
rg "config\.json|configPath" --type js --glob "**/test/**"

# 3. Look for places where directories are created to ensure the data directory exists
echo "Checking if data directories are created elsewhere:"
rg "mkdir|mkdirSync" --type js | grep -E "serverFiles|userFiles|dataDir"

Length of output: 1451


Action Required: Manually Verify Config File Resolution Logic

The updated config resolution in packages/sync-server/src/load-config.js appears to use the new defaultDataDir logic correctly (i.e. using process.env.ACTUAL_DATA_DIR, then /data if available, otherwise defaulting to projectRoot). However, note that our automated test search returned no matching test files and no evidence of data directory creation elsewhere. Please manually verify that:

  • The logic in lines 14–18 (and the similar logic in lines 272–274) correctly falls back to loading the config file from defaultDataDir when it’s not found in projectRoot.
  • Existing tests (if any) or manual test scenarios cover this fallback behavior, especially when switching between the various configuration scenarios.
  • The absence of test file matches from the automated search is expected and does not hide needed adjustments in test cases.
🧰 Tools
🪛 ESLint

[error] 17-17: Insert ··

(prettier/prettier)


[error] 18-18: Insert ··

(prettier/prettier)

@matt-fidd matt-fidd merged commit cfc8186 into actualbudget:master Mar 4, 2025
22 checks passed
@lelemm lelemm deleted the bugfix/dataDir_new_config branch March 4, 2025 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants