Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Jul 14, 2025

This short-circuit causes any/all rc.unraid-api invocations to immediately fail on fresh 7.2 images (because /boot/config/dynamix.my.servers doesn't exist).

Summary by CodeRabbit

  • Refactor
    • Removed initial checks and setup for a plugin directory and default environment file in the startup script.
    • Simplified environment switching with streamlined commands and improved error handling.
    • Removed deprecated environment path references and updated related tests.
  • Documentation
    • Added descriptive comments clarifying build and environment settings.
  • Tests
    • Updated test cases by removing assertions related to deprecated environment paths.
  • Maintenance
    • Updated timestamp fixtures for consistency.

@pujitm pujitm requested a review from ljm42 July 14, 2025 18:51
@pujitm pujitm requested a review from elibosley as a code owner July 14, 2025 18:51
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

Walkthrough

Initialization lines defining a plugin directory and checking for its existence were removed from a startup script. A path constant and related test assertion for 'myservers-env' were deleted. JSDoc comments were added to environment constants. The environment switching command was refactored to simplify logic, use a restart command, and improve file existence checks. Several test fixture timestamps were updated.

Changes

File(s) Change Summary
plugin/source/dynamix.unraid.net/etc/rc.d/rc.unraid-api Removed directory variable definition and two startup checks
api/src/store/modules/paths.ts, api/src/test/store/modules/paths.test.ts Removed 'myservers-env' path constant and its test assertion
api/src/environment.ts Added JSDoc comments to NODE_ENV and ENVIRONMENT exports
api/src/unraid-api/cli/switch-env.command.ts Refactored SwitchEnvCommand: simplified environment logic, replaced stop/start with restart, added file existence checks and error handling
api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/* Updated timestamp values in multiple fixture files

Suggested reviewers

  • mdatelle

Poem

Three lines departed, neat and swift,
No more checks or env file lift.
The script now starts with lighter load,
Old guards gone from the code.
Farewell to flash, your watch is through—
The script moves on, streamlined and new!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.


flash="/boot/config/plugins/dynamix.my.servers"
[[ ! -d "${flash}" ]] && echo "Please reinstall the Unraid Connect plugin" && exit 1
[[ ! -f "${flash}/env" ]] && echo 'env=production' >"${flash}/env"
Copy link
Member Author

Choose a reason for hiding this comment

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

@elibosley @ljm42 is it preferable to still write this env file?

Copy link
Member

Choose a reason for hiding this comment

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

Is this for flash backup? I think we probably should nuke it if possible and just have flash backup work off production by default.

@pujitm
Copy link
Member Author

pujitm commented Jul 14, 2025

@CodeRabbit summary

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 14, 2025

✅ Actions performed

Summary regeneration triggered.

@pujitm pujitm requested a review from mdatelle as a code owner July 14, 2025 20:34
@pujitm pujitm requested a review from elibosley July 14, 2025 20:36
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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d08f875 and c410fc0.

⛔ Files ignored due to path filters (1)
  • api/src/__test__/store/modules/__snapshots__/paths.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (9)
  • api/src/__test__/store/modules/paths.test.ts (0 hunks)
  • api/src/environment.ts (2 hunks)
  • api/src/store/modules/paths.ts (0 hunks)
  • api/src/unraid-api/cli/switch-env.command.ts (2 hunks)
  • api/src/unraid-api/unraid-file-modifier/modifications/__test__/__fixtures__/downloaded/.login.php.last-download-time (1 hunks)
  • api/src/unraid-api/unraid-file-modifier/modifications/__test__/__fixtures__/downloaded/DefaultPageLayout.php.last-download-time (1 hunks)
  • api/src/unraid-api/unraid-file-modifier/modifications/__test__/__fixtures__/downloaded/Notifications.page.last-download-time (1 hunks)
  • api/src/unraid-api/unraid-file-modifier/modifications/__test__/__fixtures__/downloaded/auth-request.php.last-download-time (1 hunks)
  • api/src/unraid-api/unraid-file-modifier/modifications/__test__/__fixtures__/downloaded/rc.nginx.last-download-time (1 hunks)
💤 Files with no reviewable changes (2)
  • api/src/store/modules/paths.ts
  • api/src/test/store/modules/paths.test.ts
✅ Files skipped from review due to trivial changes (6)
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/.login.php.last-download-time
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/auth-request.php.last-download-time
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/Notifications.page.last-download-time
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/DefaultPageLayout.php.last-download-time
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/rc.nginx.last-download-time
  • api/src/environment.ts
🧰 Additional context used
📓 Path-based instructions (2)
api/src/unraid-api/**/*

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
  • .cursor/rules/api-rules.mdc
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • CLAUDE.md
🧠 Learnings (2)
📓 Common learnings
Learnt from: elibosley
PR: unraid/api#1151
File: plugin/builder/utils/consts.ts:6-6
Timestamp: 2025-03-04T14:55:00.903Z
Learning: The startingDir constant in plugin/builder/utils/consts.ts is defined using process.cwd(), which can cause issues if directory changes occur after importing this constant. Using __dirname.split('/builder')[0] would make it more reliable by making it relative to the file location rather than the current working directory.
Learnt from: elibosley
PR: unraid/api#1120
File: plugin/Dockerfile:1-3
Timestamp: 2025-02-05T14:25:37.316Z
Learning: The Dockerfile in the plugin directory is specifically for building artifacts during CI and is not used for production deployments. It creates a build environment with Node.js and necessary dependencies to generate plugin files.
Learnt from: pujitm
PR: unraid/api#1352
File: packages/unraid-api-plugin-connect/src/config.persistence.ts:143-149
Timestamp: 2025-04-22T14:41:19.603Z
Learning: The `demo` property in the config.persistence.ts file's migrateLegacyConfig method is used for demonstration purposes, adding a current timestamp to keep demo environments looking fresh.
Learnt from: pujitm
PR: unraid/api#1352
File: packages/unraid-api-plugin-generator/src/create-plugin.ts:91-112
Timestamp: 2025-04-21T18:27:36.482Z
Learning: For utility functions like file operations in api plugin generators, pujitm prefers minimal error handling rather than verbose try/catch blocks for each operation, as errors will propagate properly to higher level error handlers.
api/src/unraid-api/cli/switch-env.command.ts (6)
Learnt from: elibosley
PR: unraid/api#1352
File: packages/unraid-api-plugin-connect/src/config.persistence.ts:0-0
Timestamp: 2025-04-21T18:44:39.643Z
Learning: When working with file operations in Node.js, prefer using the native Promise-based APIs from the fs/promises module instead of callback-based APIs from fs or manually wrapping callbacks in Promises.
Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code
Learnt from: elibosley
PR: unraid/api#1352
File: packages/unraid-api-plugin-connect/src/config.persistence.ts:0-0
Timestamp: 2025-04-21T18:44:39.643Z
Learning: Use Promise-based file writing instead of callback-based approaches for better error handling and to allow proper propagation of success/failure states to callers.
Learnt from: pujitm
PR: unraid/api#1145
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:57-60
Timestamp: 2025-02-18T21:39:10.313Z
Learning: When using Node.js `rm` with `{ force: true }` option or Unix/Linux `rm -f`, existence checks are redundant as the command continues silently if the file doesn't exist.
Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-06-30T14:50:52.281Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the Nest repo located at api/src/unraid-api/ instead of the legacy code
Learnt from: elibosley
PR: unraid/api#1151
File: plugin/builder/utils/consts.ts:6-6
Timestamp: 2025-03-04T14:55:00.903Z
Learning: The startingDir constant in plugin/builder/utils/consts.ts is defined using process.cwd(), which can cause issues if directory changes occur after importing this constant. Using __dirname.split('/builder')[0] would make it more reliable by making it relative to the file location rather than the current working directory.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Test API
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
api/src/unraid-api/cli/switch-env.command.ts (2)

1-11: LGTM! Clean imports with proper ESM extensions.

The refactoring to use RestartCommand instead of separate stop/start commands simplifies the dependency graph. Using fs/promises aligns with best practices for async file operations.


51-57: Good validation of environment file existence.

Using fileExistsSync before attempting the copy operation provides clear error messages and prevents cryptic failures.

Comment on lines +44 to +46
// Determine target environment
const currentEnv = ENVIRONMENT;
const targetEnv = options.environment ?? 'production';
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the default environment behavior.

The command now defaults to 'production' when no environment is specified. Ensure this aligns with user expectations, as the previous implementation may have toggled between environments.


🏁 Script executed:

#!/bin/bash
# Description: Check for documentation or tests that describe the expected default behavior

# Search for documentation about switch-env command behavior
fd -e md -e txt | xargs rg -A 5 -B 5 "switch-env"

# Check for tests that validate the default behavior
fd -e test.ts -e spec.ts | xargs rg -A 10 "switch-env.*default|switch-env.*no.*argument"

Length of output: 10821


Ensure switch-env toggles by default when no environment is specified

The CLI docs and developer guide show that running
unraid-api switch-env without -e should toggle between production and staging, not always set to production. Update the default assignment in api/src/unraid-api/cli/switch-env.command.ts:

• File: api/src/unraid-api/cli/switch-env.command.ts
Lines: 44–46

Replace:

// Determine target environment
const currentEnv = ENVIRONMENT;
const targetEnv = options.environment ?? 'production';

With:

// Determine target environment (toggle if none provided)
const currentEnv = ENVIRONMENT;
const targetEnv = options.environment
  ?? (currentEnv === 'production' ? 'staging' : 'production');

This aligns the behavior with:

  • api/docs/public/cli.md: “Switch between production and staging environments”
  • api/docs/developer/development.md: step 2 runs switch-env without args to switch environments.
🤖 Prompt for AI Agents
In api/src/unraid-api/cli/switch-env.command.ts around lines 44 to 46, the code
currently defaults the target environment to 'production' when no environment
option is provided, but it should toggle between 'production' and 'staging'
instead. Update the assignment of targetEnv to check if options.environment is
set; if not, set targetEnv to 'staging' when currentEnv is 'production',
otherwise set it to 'production'. This change will make the CLI toggle
environments by default as documented.

@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1515/dynamix.unraid.net.plg

@elibosley elibosley merged commit 29dcb7d into main Jul 15, 2025
11 checks passed
@elibosley elibosley deleted the fix/config-prereq branch July 15, 2025 13:48
elibosley pushed a commit that referenced this pull request Jul 15, 2025
🤖 I have created a release *beep* *boop*
---


## [4.10.0](v4.9.5...v4.10.0)
(2025-07-15)


### Features

* trial extension allowed within 5 days of expiration
([#1490](#1490))
([f34a33b](f34a33b))


### Bug Fixes

* delay `nginx:reload` file mod effect by 10 seconds
([#1512](#1512))
([af33e99](af33e99))
* **deps:** update all non-major dependencies
([#1489](#1489))
([53b05eb](53b05eb))
* ensure no crash if emhttp state configs are missing
([#1514](#1514))
([1a7d35d](1a7d35d))
* **my.servers:** improve DNS resolution robustness for backup server
([#1518](#1518))
([eecd9b1](eecd9b1))
* over-eager cloud query from web components
([#1506](#1506))
([074370c](074370c))
* replace myservers.cfg reads in UpdateFlashBackup.php
([#1517](#1517))
([441e180](441e180))
* rm short-circuit in `rc.unraid-api` if plugin config dir is absent
([#1515](#1515))
([29dcb7d](29dcb7d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants