Skip to content

Conversation

@elibosley
Copy link
Member

@elibosley elibosley commented Jul 21, 2025

Summary by CodeRabbit

  • New Features

    • Introduced UPS management capabilities, including queries and mutations for UPS device status, configuration, and live updates via GraphQL.
    • Added support for configuring UPS parameters such as service state, cable type, communication protocol, shutdown thresholds, and power control options.
    • Provided detailed UPS device information including battery, power, and operational status.
  • Tests

    • Added comprehensive tests for UPS resolver and service logic, covering configuration, event publishing, killpower functionality, and error handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 21, 2025

Walkthrough

This change introduces a new UPS (Uninterruptible Power Supply) management feature to the GraphQL API. It adds input types, models, a resolver, a service for UPS configuration and status retrieval, and comprehensive tests for both the resolver and service. The UPS module is registered in the main resolver module.

Changes

File(s) Change Summary
UPS GraphQL Inputs
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
Adds GraphQL input type UPSConfigInput and enums for UPS configuration parameters with validation and documentation.
UPS GraphQL Models
api/src/unraid-api/graph/resolvers/ups/ups.model.ts
Defines GraphQL object types for UPS battery, power, device, and configuration with detailed field descriptions.
UPS GraphQL Resolver
api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
Implements UPSResolver with queries, mutation, and subscription for UPS devices and configuration management.
UPS GraphQL Resolver Tests
api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts
Adds tests for UPSResolver covering queries, mutation, and subscription behavior with mocks for service and PubSub.
UPS Service Implementation
api/src/unraid-api/graph/resolvers/ups/ups.service.ts
Implements UPSService for UPS status retrieval via system command, configuration merging, validation, and system control.
UPS Service Tests
api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts
Adds tests for UPSService focusing on configuration merging, validation, killpower hook management, backups, and errors.
UPS Module Declaration
api/src/unraid-api/graph/resolvers/ups/ups.module.ts
Declares the UPSModule with providers for resolver, service, and PubSub instance.
Resolvers Module Update
api/src/unraid-api/graph/resolvers/resolvers.module.ts
Registers UPSModule in the main resolvers module imports array.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphQL API
    participant UPSResolver
    participant UPSService
    participant PubSub

    Client->>GraphQL API: Query upsDevices
    GraphQL API->>UPSResolver: upsDevices()
    UPSResolver->>UPSService: getUPSData()
    UPSService-->>UPSResolver: UPSData
    UPSResolver-->>GraphQL API: [UPSDevice]

    Client->>GraphQL API: Mutation configureUps(config)
    GraphQL API->>UPSResolver: configureUps(config)
    UPSResolver->>UPSService: configureUPS(config)
    UPSService-->>UPSResolver: (void)
    UPSResolver->>UPSService: getUPSData()
    UPSService-->>UPSResolver: UPSData
    UPSResolver->>PubSub: publish('upsUpdates', UPSDevice)
    UPSResolver-->>GraphQL API: true

    Client->>GraphQL API: Subscription upsUpdates
    GraphQL API->>UPSResolver: upsUpdates()
    UPSResolver->>PubSub: asyncIterator('upsUpdates')
    PubSub-->>GraphQL API: UPSDevice (on update)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • feat: code first graphql #1347: Migrates the GraphQL API to code-first approach, which is foundational for the UPS module's code-first GraphQL implementation.

Poem

🐇⚡ Hopping in with power bright,
UPS commands take flight tonight!
Models, inputs, services too,
Keeping your data safe and true.
GraphQL hums, the circuits sing,
With every test, a joyful spring!
🔋🌿

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 c1f1eb8 and a0f519c.

📒 Files selected for processing (8)
  • api/src/unraid-api/graph/resolvers/resolvers.module.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • api/src/unraid-api/graph/resolvers/resolvers.module.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
🧰 Additional context used
📓 Path-based instructions (2)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
Learnt from: pujitm
PR: unraid/api#1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (19)

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T15:34:24.715Z
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: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1252
File: api/src/environment.ts:56-56
Timestamp: 2025-03-27T13:34:53.438Z
Learning: For critical components in the Unraid API, such as retrieving version information from package.json, failing fast (allowing crashes) is preferred over graceful degradation with fallback values.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: elibosley
PR: #1063
File: api/src/unraid-api/cli/sso/validate-token.command.ts:76-81
Timestamp: 2025-01-23T21:26:17.766Z
Learning: In the unraid/api codebase, store dispatches using Redux Toolkit's unwrap() method already handle errors appropriately and don't require additional try-catch blocks.

Learnt from: pujitm
PR: #1219
File: api/src/unraid-api/main.ts:18-25
Timestamp: 2025-03-07T19:29:12.540Z
Learning: When handling type mismatches between dependencies in TypeScript (such as between NestJS and Fastify), prefer using @ts-expect-error with a detailed explanation comment instead of as any type assertions. This better documents the reason for the type bypass and makes the issue more visible for future maintenance.

Learnt from: pujitm
PR: #1352
File: api/src/unraid-api/cli/dependency.service.ts:114-117
Timestamp: 2025-04-21T18:25:16.491Z
Learning: Methods in DependencyService like npmInstall and rebuildVendorArchive intentionally propagate errors from execa calls upward rather than handling them internally, allowing callers to implement appropriate error handling. This follows the pattern documented in the rebuildVendorArchive method's docstring.

Learnt from: elibosley
PR: #1120
File: plugin/plugins/dynamix.unraid.net.plg:35-38
Timestamp: 2025-02-05T21:10:48.136Z
Learning: When providing error handling guidance for Unraid plugins, direct users to use the web GUI (Plugins > Installed Plugins) rather than suggesting command-line actions.

Learnt from: pujitm
PR: #1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.

Learnt from: pujitm
PR: #1075
File: unraid-ui/src/register.ts:15-34
Timestamp: 2025-01-30T19:38:02.478Z
Learning: In the web components registration process for unraid-ui, use a soft-fail approach (logging warnings/errors) instead of throwing errors, to ensure other components can still register successfully even if one component fails.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:33-37
Timestamp: 2025-01-29T16:36:04.777Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations. It includes try/catch blocks, detailed error logging, and safe rollback mechanisms. Individual FileModification implementations (like LogRotateModification) should allow errors to propagate to this service layer rather than handling them internally.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: elibosley
PR: #1425
File: api/dev/configs/connect.json:2-3
Timestamp: 2025-06-20T21:05:24.582Z
Learning: When reviewing configuration files in refactoring PRs, avoid suggesting field name changes that could break compatibility with existing code that references those fields, even if the naming doesn't follow ideal conventions.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:39-41
Timestamp: 2025-01-29T16:35:43.699Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations, including detailed error logging with stack traces and modification IDs. Individual FileModification implementations should focus on their core functionality without duplicating error handling.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/auth/auth.service.ts:0-0
Timestamp: 2024-11-04T20:44:46.432Z
Learning: When modifying apiKey.roles in removeRoleFromApiKey and addRoleToApiKey within api/src/unraid-api/auth/auth.service.ts, concurrency issues are not a concern because the keys are stored in the file system.

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom ConfigService implementation that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

🔇 Additional comments (14)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (14)

1-40: Well-structured imports and schema definitions.

The imports are appropriate for a NestJS service, using secure command execution with execa and proper validation with Zod schemas. The optional field definitions provide good flexibility for UPS data that may vary across different UPS models.


41-46: Proper NestJS service setup with testing considerations.

Good use of NestJS patterns with @Injectable decorator, proper Logger injection, and pragmatic approach to making rc6Path non-readonly for testing flexibility.


47-64: Excellent error handling and command execution robustness.

This method properly addresses previous review feedback with:

  • Timeout to prevent hanging on unresponsive UPS
  • Validation of command output before parsing
  • Proper logging service usage
  • Comprehensive error handling with context preservation

66-90: Well-designed configuration method with atomic operations.

Excellent breakdown into logical steps with proper error handling. The atomic operation pattern (stop → configure → conditionally start) ensures system consistency, and the comprehensive error handling provides good visibility into failures.


92-114: Sound configuration merging and validation logic.

The merging strategy with sensible defaults and the validation logic correctly handling UPS type requirements (non-USB types requiring device paths) demonstrates good understanding of UPS hardware configuration needs.


116-134: Appropriate service management with context-aware error handling.

Good differentiation in error handling: warning for stop failures (service may not be running) versus errors for start failures (indicates configuration problems). Timeouts prevent hanging operations.


136-166: Comprehensive configuration preparation with proper value preservation.

Well-handled logic for custom vs standard cables, appropriate preservation of existing configuration values, and proper handling of optional override capacity settings.


168-209: Robust backup and restore implementation with defensive error handling.

Excellent atomic write pattern with proper backup/restore mechanisms. The defensive error handling (warnings for backup failures, errors for restore failures) provides appropriate safety without blocking operations unnecessarily.


211-232: Well-designed kill power configuration with environment awareness.

Good conditional logic that only configures kill power when service is enabled, and graceful handling of missing rc.6 file for testing environments. The error handling properly distinguishes between different failure types.


234-272: Excellent RC6 file modification with idempotent operations.

Well-implemented file modification that checks if changes are needed before acting, preventing unnecessary operations. The comprehensive error handling and descriptive logging address previous review feedback effectively.


274-281: Clean utility method for optional file reading.

Simple and effective pattern for reading files that may not exist, with appropriate null return for failure cases.


283-295: Clean functional parsing with proper error tolerance.

Good use of functional programming patterns to parse UPS data with appropriate filtering of malformed lines. The approach handles the apcaccess output format well.


297-313: Robust configuration reading with appropriate fallbacks.

Good error handling that allows operation to continue with empty configuration when files don't exist, while still providing comprehensive error context for actual read failures.


315-386: Comprehensive configuration parsing and generation.

Excellent handling of apcupsd configuration format with proper comment filtering, numeric conversion, quote handling, and ordered directive generation. The methods correctly preserve existing configuration while updating specified values.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/ups-monitoring

🪧 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 generate unit tests to generate unit tests 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: 9

🧹 Nitpick comments (1)
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1)

1-1: Remove unused imports.

The Int and Float imports are not used in this file.

Apply this diff to clean up the imports:

-import { Field, InputType, Int, Float } from '@nestjs/graphql';
+import { Field, InputType } from '@nestjs/graphql';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1a8da6d and 6758778.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (7)
  • api/src/unraid-api/graph/resolvers/resolvers.module.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (8)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
api/src/unraid-api/graph/resolvers/resolvers.module.ts (10)

Learnt from: elibosley
PR: #1408
File: web/components/ApiKey/PermissionCounter.vue:6-6
Timestamp: 2025-05-23T21:59:29.632Z
Learning: This codebase uses ESM (ECMAScript Modules) and requires .js extensions in import statements, even when importing from TypeScript files, as the imports refer to the compiled JavaScript output.

Learnt from: elibosley
PR: #1308
File: unraid-ui/src/components/common/loading/Error.vue:2-2
Timestamp: 2025-04-02T21:21:29.168Z
Learning: Components in the unraid-ui folder require explicit imports and are not autoloaded, unlike other parts of the project that may use Nuxt.js autoloading features.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: Applies to web/store/**/*.{ts,js} : Ensure Vue reactivity imports are added to store files (computed, ref, watchEffect)

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

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: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:87-89
Timestamp: 2024-11-06T20:59:06.096Z
Learning: Error handling in mutations like addRoleForUser in auth.resolver.ts is performed at the service level, so additional error handling in the resolver is unnecessary.

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: All GraphQL under web/ must follow this naming convention (.query.ts for queries, .mutation.ts for mutations)

api/src/unraid-api/graph/resolvers/ups/ups.module.ts (5)

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: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to **/*.test.ts : Use factory functions for module mocks to avoid hoisting issues in test files

Learnt from: elibosley
PR: #1211
File: api/src/unraid-api/graph/connect/connect-settings.service.ts:48-53
Timestamp: 2025-03-13T16:17:55.820Z
Learning: In NestJS services, dynamic imports should be wrapped in try/catch blocks with proper error logging and fallback handling to prevent unhandled rejections from crashing the application.

Learnt from: elibosley
PR: #1408
File: web/components/ApiKey/PermissionCounter.vue:6-6
Timestamp: 2025-05-23T21:59:29.632Z
Learning: This codebase uses ESM (ECMAScript Modules) and requires .js extensions in import statements, even when importing from TypeScript files, as the imports refer to the compiled JavaScript output.

api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (2)

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (13)

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Verify state changes by updating the store in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Test getter dependencies are properly mocked in store tests

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: Applies to api/**/*.{test,spec}.{ts,js} : Test suite is VITEST, do not use jest in the API package

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/**/*.{test,spec}.{js,ts,tsx} : Test suite is VITEST, do not use jest

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Test async operations completely in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Verify state changes after actions in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Mock external dependencies appropriately in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Verify proper error handling in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Override specific action implementations when needed in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Test store interactions with other stores in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to **/*.test.ts : Mock external services and API calls in tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to **/*.test.ts : Mock external dependencies and services in tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to **/*.test.ts : Remember that vi.mock() calls are hoisted

api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (10)

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:87-89
Timestamp: 2024-11-06T20:59:06.096Z
Learning: Error handling in mutations like addRoleForUser in auth.resolver.ts is performed at the service level, so additional error handling in the resolver is unnecessary.

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: All GraphQL under web/ must follow this naming convention (.query.ts for queries, .mutation.ts for mutations)

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

Learnt from: pujitm
PR: #1352
File: packages/unraid-api-plugin-connect/src/connect.resolver.ts:14-24
Timestamp: 2025-04-21T18:04:56.755Z
Learning: Error handling in GraphQL resolvers: pujitm prefers to let errors bubble up naturally to the client rather than adding explicit try/catch blocks in each resolver method.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-graphql.mdc:0-0
Timestamp: 2025-06-30T14:51:12.348Z
Learning: Applies to web/**/*.{query.ts,mutation.ts} : All GraphQL under web/ must follow this naming convention

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-graphql.mdc:0-0
Timestamp: 2025-06-30T14:51:12.348Z
Learning: Applies to web/**/*.mutation.ts : GraphQL mutations must be placed in .mutation.ts files

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: Applies to web/**/*.mutation.ts : GraphQL mutations must be placed in .mutation.ts files under web/

api/src/unraid-api/graph/resolvers/ups/ups.model.ts (6)

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

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: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T14:50:43.946Z
Learning: All GraphQL under web/ must follow this naming convention (.query.ts for queries, .mutation.ts for mutations)

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (5)

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: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: elibosley
PR: #1211
File: api/src/unraid-api/graph/connect/connect-settings.service.ts:48-53
Timestamp: 2025-03-13T16:17:55.820Z
Learning: In NestJS services, dynamic imports should be wrapped in try/catch blocks with proper error logging and fallback handling to prevent unhandled rejections from crashing the application.

🧬 Code Graph Analysis (2)
api/src/unraid-api/graph/resolvers/ups/ups.module.ts (1)
api/src/unraid-api/graph/resolvers/resolvers.module.ts (1)
  • Module (39-80)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1)
api/src/unraid-api/cli/log.service.ts (1)
  • error (46-50)
⏰ 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 (6)
api/src/unraid-api/graph/resolvers/resolvers.module.ts (1)

30-30: LGTM! Proper module integration.

The UPS module is correctly imported and added to the imports array, maintaining alphabetical order and using proper ESM .js extensions.

Also applies to: 50-50

api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1)

3-13: Well-structured GraphQL input type.

The UPS configuration input type is properly defined with clear field mappings.

api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1)

20-35: Good test setup with proper mocking.

The test module configuration correctly mocks the UPS service while maintaining proper dependency injection.

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (2)

8-18: Good use of Zod schema validation.

The schema definition properly validates UPS data structure with optional fields, which is appropriate for potentially missing UPS metrics.


33-43: Parsing logic handles apcaccess format correctly.

The line-by-line parsing with colon splitting properly handles the key-value format output by apcaccess.

api/src/unraid-api/graph/resolvers/ups/ups.model.ts (1)

1-46: Well-structured GraphQL models for UPS monitoring.

The object type definitions are clean and appropriately typed. The nested structure with UPSBattery and UPSPower provides good data organization for UPS device information.

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

♻️ Duplicate comments (1)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1)

23-32: Duplicate of previous review concerns.

The issues with timeout handling, logging service usage, and error handling robustness have already been identified in previous reviews and remain unaddressed.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6758778 and 36f48d4.

📒 Files selected for processing (4)
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (3)

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (16)

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

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: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Verify proper error handling in store tests

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1252
File: api/src/environment.ts:56-56
Timestamp: 2025-03-27T13:34:53.438Z
Learning: For critical components in the Unraid API, such as retrieving version information from package.json, failing fast (allowing crashes) is preferred over graceful degradation with fallback values.

Learnt from: elibosley
PR: #1063
File: api/src/unraid-api/cli/sso/validate-token.command.ts:76-81
Timestamp: 2025-01-23T21:26:17.766Z
Learning: In the unraid/api codebase, store dispatches using Redux Toolkit's unwrap() method already handle errors appropriately and don't require additional try-catch blocks.

Learnt from: pujitm
PR: #1219
File: api/src/unraid-api/main.ts:18-25
Timestamp: 2025-03-07T19:29:12.540Z
Learning: When handling type mismatches between dependencies in TypeScript (such as between NestJS and Fastify), prefer using @ts-expect-error with a detailed explanation comment instead of as any type assertions. This better documents the reason for the type bypass and makes the issue more visible for future maintenance.

Learnt from: pujitm
PR: #1352
File: api/src/unraid-api/cli/dependency.service.ts:114-117
Timestamp: 2025-04-21T18:25:16.491Z
Learning: Methods in DependencyService like npmInstall and rebuildVendorArchive intentionally propagate errors from execa calls upward rather than handling them internally, allowing callers to implement appropriate error handling. This follows the pattern documented in the rebuildVendorArchive method's docstring.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to **/*.test.ts : Always await async operations before making assertions in tests

Learnt from: elibosley
PR: #1211
File: api/src/unraid-api/graph/connect/connect-settings.service.ts:48-53
Timestamp: 2025-03-13T16:17:55.820Z
Learning: In NestJS services, dynamic imports should be wrapped in try/catch blocks with proper error logging and fallback handling to prevent unhandled rejections from crashing the application.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-06-30T14:52:37.535Z
Learning: Applies to /test/store//*.ts : Test async operations completely in store tests

Learnt from: pujitm
PR: #1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.

Learnt from: pujitm
PR: #1075
File: unraid-ui/src/register.ts:15-34
Timestamp: 2025-01-30T19:38:02.478Z
Learning: In the web components registration process for unraid-ui, use a soft-fail approach (logging warnings/errors) instead of throwing errors, to ensure other components can still register successfully even if one component fails.

Learnt from: elibosley
PR: #1120
File: plugin/plugins/dynamix.unraid.net.plg:35-38
Timestamp: 2025-02-05T21:10:48.136Z
Learning: When providing error handling guidance for Unraid plugins, direct users to use the web GUI (Plugins > Installed Plugins) rather than suggesting command-line actions.

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom ConfigService implementation that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

⏰ 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: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1)

3-34: Well-structured GraphQL input type with proper field definitions.

The implementation correctly uses GraphQL decorators and appropriate type definitions. The uppercase field naming convention appears intentional, likely for compatibility with UPS configuration systems.

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (3)

1-7: Clean import structure with appropriate dependencies.

The imports are well-organized and include all necessary dependencies for UPS service functionality.


9-19: Appropriate Zod schema design for UPS data validation.

The schema correctly defines optional string fields for UPS status data, which aligns with the variable nature of UPS device responses.


58-68: Effective parsing implementation for UPS data format.

The method correctly handles the key-value pair format from apcaccess output with appropriate validation checks.

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d3a4f8d and eb1ccdf.

📒 Files selected for processing (7)
  • .claude/settings.local.json (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .claude/settings.local.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts
🧰 Additional context used
📓 Path-based instructions (2)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (10)

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:87-89
Timestamp: 2024-11-06T20:59:06.096Z
Learning: Error handling in mutations like addRoleForUser in auth.resolver.ts is performed at the service level, so additional error handling in the resolver is unnecessary.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T13:59:55.481Z
Learning: Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T13:59:55.481Z
Learning: All GraphQL under web/ must follow this naming convention (.query.ts for queries, .mutation.ts for mutations)

Learnt from: pujitm
PR: #1352
File: packages/unraid-api-plugin-connect/src/connect.resolver.ts:14-24
Timestamp: 2025-04-21T18:04:56.755Z
Learning: Error handling in GraphQL resolvers: pujitm prefers to let errors bubble up naturally to the client rather than adding explicit try/catch blocks in each resolver method.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-graphql.mdc:0-0
Timestamp: 2025-07-21T14:00:25.140Z
Learning: Applies to web/**/*.{query,mutation}.ts : All GraphQL under web/ must follow this naming convention

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (18)

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T13:59:55.481Z
Learning: Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom ConfigService implementation that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1252
File: api/src/environment.ts:56-56
Timestamp: 2025-03-27T13:34:53.438Z
Learning: For critical components in the Unraid API, such as retrieving version information from package.json, failing fast (allowing crashes) is preferred over graceful degradation with fallback values.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: elibosley
PR: #1063
File: api/src/unraid-api/cli/sso/validate-token.command.ts:76-81
Timestamp: 2025-01-23T21:26:17.766Z
Learning: In the unraid/api codebase, store dispatches using Redux Toolkit's unwrap() method already handle errors appropriately and don't require additional try-catch blocks.

Learnt from: pujitm
PR: #1219
File: api/src/unraid-api/main.ts:18-25
Timestamp: 2025-03-07T19:29:12.540Z
Learning: When handling type mismatches between dependencies in TypeScript (such as between NestJS and Fastify), prefer using @ts-expect-error with a detailed explanation comment instead of as any type assertions. This better documents the reason for the type bypass and makes the issue more visible for future maintenance.

Learnt from: pujitm
PR: #1352
File: api/src/unraid-api/cli/dependency.service.ts:114-117
Timestamp: 2025-04-21T18:25:16.491Z
Learning: Methods in DependencyService like npmInstall and rebuildVendorArchive intentionally propagate errors from execa calls upward rather than handling them internally, allowing callers to implement appropriate error handling. This follows the pattern documented in the rebuildVendorArchive method's docstring.

Learnt from: elibosley
PR: #1120
File: plugin/plugins/dynamix.unraid.net.plg:35-38
Timestamp: 2025-02-05T21:10:48.136Z
Learning: When providing error handling guidance for Unraid plugins, direct users to use the web GUI (Plugins > Installed Plugins) rather than suggesting command-line actions.

Learnt from: pujitm
PR: #1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.

Learnt from: pujitm
PR: #1075
File: unraid-ui/src/register.ts:15-34
Timestamp: 2025-01-30T19:38:02.478Z
Learning: In the web components registration process for unraid-ui, use a soft-fail approach (logging warnings/errors) instead of throwing errors, to ensure other components can still register successfully even if one component fails.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:33-37
Timestamp: 2025-01-29T16:36:04.777Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations. It includes try/catch blocks, detailed error logging, and safe rollback mechanisms. Individual FileModification implementations (like LogRotateModification) should allow errors to propagate to this service layer rather than handling them internally.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: elibosley
PR: #1425
File: api/dev/configs/connect.json:2-3
Timestamp: 2025-06-20T21:05:24.582Z
Learning: When reviewing configuration files in refactoring PRs, avoid suggesting field name changes that could break compatibility with existing code that references those fields, even if the naming doesn't follow ideal conventions.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:39-41
Timestamp: 2025-01-29T16:35:43.699Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations, including detailed error logging with stack traces and modification IDs. Individual FileModification implementations should focus on their core functionality without duplicating error handling.

🧬 Code Graph Analysis (1)
api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (1)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1)
  • UPSData (23-23)
⏰ 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). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (13)
api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (5)

1-14: LGTM: Clean imports and proper dependency injection.

The resolver follows NestJS patterns correctly with proper dependency injection of both the service and PubSub instance.


16-33: LGTM: Well-extracted helper method with proper type safety.

The createUPSDevice helper method effectively eliminates code duplication and provides consistent fallback values for missing UPS data fields.


35-50: LGTM: Dynamic device ID implementation.

Good improvement using upsData.MODEL as the device ID instead of hardcoded values, making the system more flexible for different UPS models.


52-71: LGTM: Straightforward configuration query.

The configuration mapping follows GraphQL best practices with direct field mapping from the service layer.


73-80: LGTM: Proper mutation with subscription publishing.

The mutation correctly publishes updates to subscribers after configuration changes, following the established pattern with injected PubSub.

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (8)

1-11: LGTM: Proper imports and promisified exec.

Clean imports with appropriate NestJS decorators and utility functions.


13-43: LGTM: Well-defined Zod schemas for type safety.

The schemas provide proper validation for both UPS data and configuration with optional fields appropriately marked.


44-63: LGTM: Robust data retrieval with proper error handling.

The method includes timeout, output validation, and proper error logging with the NestJS logger as suggested in previous reviews.


65-154: LGTM: Comprehensive configuration method with atomic operations.

Excellent implementation addressing previous feedback:

  • Input validation for required fields
  • Configuration backup and restore on failure
  • Proper timeout handling
  • Service lifecycle management
  • Detailed error logging

The method handles critical system modifications safely with rollback capabilities.


156-166: LGTM: Simple and effective parsing logic.

The UPS data parsing correctly handles the key-value format from apcaccess output.


168-184: LGTM: Proper configuration file handling.

Good error handling with file existence checks and proper fallback behavior.


186-219: LGTM: Robust configuration parsing.

The parser correctly handles comments, quotes, and type conversion for numeric values.


221-264: LGTM: Well-structured configuration generation.

The method maintains proper directive ordering and handles string quoting appropriately for the configuration file format.

@elibosley elibosley force-pushed the feature/ups-monitoring branch from eb1ccdf to 865e3df Compare July 22, 2025 13:27
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)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1)

65-206: Comprehensive UPS configuration with proper safeguards.

The method implements atomic operations with backup/restore, input validation, and comprehensive error handling. Consider breaking this into smaller methods for better maintainability.

Consider extracting logical steps into separate methods:

private async stopUpsService(): Promise<void> { /* ... */ }
private async backupConfiguration(): Promise<string> { /* ... */ }
private async writeConfiguration(content: string, backupPath: string): Promise<void> { /* ... */ }
private async updateShutdownScript(config: UPSConfigInput): Promise<void> { /* ... */ }
private async startUpsService(): Promise<void> { /* ... */ }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 865e3df and 4a0959b.

📒 Files selected for processing (7)
  • .claude/settings.local.json (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 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)
📓 Path-based instructions (2)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
Learnt from: pujitm
PR: unraid/api#1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.
Learnt from: pujitm
PR: unraid/api#1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (21)

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T13:59:55.481Z
Learning: Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom ConfigService implementation that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1252
File: api/src/environment.ts:56-56
Timestamp: 2025-03-27T13:34:53.438Z
Learning: For critical components in the Unraid API, such as retrieving version information from package.json, failing fast (allowing crashes) is preferred over graceful degradation with fallback values.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: elibosley
PR: #1063
File: api/src/unraid-api/cli/sso/validate-token.command.ts:76-81
Timestamp: 2025-01-23T21:26:17.766Z
Learning: In the unraid/api codebase, store dispatches using Redux Toolkit's unwrap() method already handle errors appropriately and don't require additional try-catch blocks.

Learnt from: pujitm
PR: #1219
File: api/src/unraid-api/main.ts:18-25
Timestamp: 2025-03-07T19:29:12.540Z
Learning: When handling type mismatches between dependencies in TypeScript (such as between NestJS and Fastify), prefer using @ts-expect-error with a detailed explanation comment instead of as any type assertions. This better documents the reason for the type bypass and makes the issue more visible for future maintenance.

Learnt from: pujitm
PR: #1352
File: api/src/unraid-api/cli/dependency.service.ts:114-117
Timestamp: 2025-04-21T18:25:16.491Z
Learning: Methods in DependencyService like npmInstall and rebuildVendorArchive intentionally propagate errors from execa calls upward rather than handling them internally, allowing callers to implement appropriate error handling. This follows the pattern documented in the rebuildVendorArchive method's docstring.

Learnt from: elibosley
PR: #1120
File: plugin/plugins/dynamix.unraid.net.plg:35-38
Timestamp: 2025-02-05T21:10:48.136Z
Learning: When providing error handling guidance for Unraid plugins, direct users to use the web GUI (Plugins > Installed Plugins) rather than suggesting command-line actions.

Learnt from: pujitm
PR: #1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.

Learnt from: pujitm
PR: #1075
File: unraid-ui/src/register.ts:15-34
Timestamp: 2025-01-30T19:38:02.478Z
Learning: In the web components registration process for unraid-ui, use a soft-fail approach (logging warnings/errors) instead of throwing errors, to ensure other components can still register successfully even if one component fails.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:33-37
Timestamp: 2025-01-29T16:36:04.777Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations. It includes try/catch blocks, detailed error logging, and safe rollback mechanisms. Individual FileModification implementations (like LogRotateModification) should allow errors to propagate to this service layer rather than handling them internally.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: elibosley
PR: #1425
File: api/dev/configs/connect.json:2-3
Timestamp: 2025-06-20T21:05:24.582Z
Learning: When reviewing configuration files in refactoring PRs, avoid suggesting field name changes that could break compatibility with existing code that references those fields, even if the naming doesn't follow ideal conventions.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:39-41
Timestamp: 2025-01-29T16:35:43.699Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations, including detailed error logging with stack traces and modification IDs. Individual FileModification implementations should focus on their core functionality without duplicating error handling.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/auth/auth.service.ts:0-0
Timestamp: 2024-11-04T20:44:46.432Z
Learning: When modifying apiKey.roles in removeRoleFromApiKey and addRoleToApiKey within api/src/unraid-api/auth/auth.service.ts, concurrency issues are not a concern because the keys are stored in the file system.

Learnt from: elibosley
PR: #1211
File: api/src/unraid-api/graph/connect/connect-settings.service.ts:48-53
Timestamp: 2025-03-13T16:17:55.820Z
Learning: In NestJS services, dynamic imports should be wrapped in try/catch blocks with proper error logging and fallback handling to prevent unhandled rejections from crashing the application.

Learnt from: elibosley
PR: #1120
File: plugin/package.json:0-0
Timestamp: 2025-02-05T14:43:48.568Z
Learning: In Node.js projects, npm scripts should be organized with clear namespacing (e.g., build:, docker:, env:*) and include proper environment validation and error handling. Each script should follow the single responsibility principle.

✅ Files skipped from review due to trivial changes (5)
  • 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/rc.nginx.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/.login.php.last-download-time
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/DefaultPageLayout.php.last-download-time
🚧 Files skipped from review as they are similar to previous changes (1)
  • .claude/settings.local.json
🧰 Additional context used
📓 Path-based instructions (2)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
Learnt from: pujitm
PR: unraid/api#1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.
Learnt from: pujitm
PR: unraid/api#1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (21)

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T13:59:55.481Z
Learning: Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom ConfigService implementation that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1252
File: api/src/environment.ts:56-56
Timestamp: 2025-03-27T13:34:53.438Z
Learning: For critical components in the Unraid API, such as retrieving version information from package.json, failing fast (allowing crashes) is preferred over graceful degradation with fallback values.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: elibosley
PR: #1063
File: api/src/unraid-api/cli/sso/validate-token.command.ts:76-81
Timestamp: 2025-01-23T21:26:17.766Z
Learning: In the unraid/api codebase, store dispatches using Redux Toolkit's unwrap() method already handle errors appropriately and don't require additional try-catch blocks.

Learnt from: pujitm
PR: #1219
File: api/src/unraid-api/main.ts:18-25
Timestamp: 2025-03-07T19:29:12.540Z
Learning: When handling type mismatches between dependencies in TypeScript (such as between NestJS and Fastify), prefer using @ts-expect-error with a detailed explanation comment instead of as any type assertions. This better documents the reason for the type bypass and makes the issue more visible for future maintenance.

Learnt from: pujitm
PR: #1352
File: api/src/unraid-api/cli/dependency.service.ts:114-117
Timestamp: 2025-04-21T18:25:16.491Z
Learning: Methods in DependencyService like npmInstall and rebuildVendorArchive intentionally propagate errors from execa calls upward rather than handling them internally, allowing callers to implement appropriate error handling. This follows the pattern documented in the rebuildVendorArchive method's docstring.

Learnt from: elibosley
PR: #1120
File: plugin/plugins/dynamix.unraid.net.plg:35-38
Timestamp: 2025-02-05T21:10:48.136Z
Learning: When providing error handling guidance for Unraid plugins, direct users to use the web GUI (Plugins > Installed Plugins) rather than suggesting command-line actions.

Learnt from: pujitm
PR: #1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.

Learnt from: pujitm
PR: #1075
File: unraid-ui/src/register.ts:15-34
Timestamp: 2025-01-30T19:38:02.478Z
Learning: In the web components registration process for unraid-ui, use a soft-fail approach (logging warnings/errors) instead of throwing errors, to ensure other components can still register successfully even if one component fails.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:33-37
Timestamp: 2025-01-29T16:36:04.777Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations. It includes try/catch blocks, detailed error logging, and safe rollback mechanisms. Individual FileModification implementations (like LogRotateModification) should allow errors to propagate to this service layer rather than handling them internally.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: elibosley
PR: #1425
File: api/dev/configs/connect.json:2-3
Timestamp: 2025-06-20T21:05:24.582Z
Learning: When reviewing configuration files in refactoring PRs, avoid suggesting field name changes that could break compatibility with existing code that references those fields, even if the naming doesn't follow ideal conventions.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:39-41
Timestamp: 2025-01-29T16:35:43.699Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations, including detailed error logging with stack traces and modification IDs. Individual FileModification implementations should focus on their core functionality without duplicating error handling.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/auth/auth.service.ts:0-0
Timestamp: 2024-11-04T20:44:46.432Z
Learning: When modifying apiKey.roles in removeRoleFromApiKey and addRoleToApiKey within api/src/unraid-api/auth/auth.service.ts, concurrency issues are not a concern because the keys are stored in the file system.

Learnt from: elibosley
PR: #1211
File: api/src/unraid-api/graph/connect/connect-settings.service.ts:48-53
Timestamp: 2025-03-13T16:17:55.820Z
Learning: In NestJS services, dynamic imports should be wrapped in try/catch blocks with proper error logging and fallback handling to prevent unhandled rejections from crashing the application.

Learnt from: elibosley
PR: #1120
File: plugin/package.json:0-0
Timestamp: 2025-02-05T14:43:48.568Z
Learning: In Node.js projects, npm scripts should be organized with clear namespacing (e.g., build:, docker:, env:*) and include proper environment validation and error handling. Each script should follow the single responsibility principle.

⏰ 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: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (7)

1-39: Well-structured imports and schema definitions.

The imports are clean and the Zod schemas provide good type safety. The mixed optional schema approach allows flexibility for partial configurations.


41-44: Standard NestJS service implementation.

Clean service setup with proper logging initialization.


46-63: Robust UPS data retrieval with proper safeguards.

The implementation includes timeout protection, output validation, and comprehensive error handling. Good use of Zod schema validation for type safety.


208-218: Simple and effective data parsing.

The parsing logic handles the key-value format appropriately. The 'any' return type is acceptable given the Zod validation in the caller.


220-236: Well-implemented configuration reading with proper error handling.

Good use of file existence checks and graceful handling of missing configurations.


238-271: Robust configuration file parsing.

The parsing logic properly handles comments, quotes, and type conversion. The regex pattern appropriately matches the directive format.


273-317: Well-structured configuration generation.

The method properly merges configurations, maintains directive ordering, and handles value formatting correctly.

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: 2

🧹 Nitpick comments (1)
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1)

103-104: Consider validation for UPS capacity override.

Since this represents watts, it should likely be a positive number when specified.

Add minimum validation:

@Field(() => Int, { nullable: true })
+@Min(1, { message: 'UPS capacity must be positive' })
overrideUpsCapacity?: number;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a0959b and 7fa943c.

📒 Files selected for processing (5)
  • .claude/settings.local.json (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 hunks)
📓 Path-based instructions (2)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
Learnt from: pujitm
PR: unraid/api#1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.
Learnt from: pujitm
PR: unraid/api#1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (4)

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

🚧 Files skipped from review as they are similar to previous changes (4)
  • .claude/settings.local.json
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
🧰 Additional context used
📓 Path-based instructions (2)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
🧠 Learnings (2)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
Learnt from: pujitm
PR: unraid/api#1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.
Learnt from: pujitm
PR: unraid/api#1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (4)

Learnt from: pujitm
PR: #1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

⏰ 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: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (2)

1-42: Enum definitions look solid with clear documentation.

The enum values are well-defined and descriptive. The documentation provides good context for each enum's purpose.


43-62: GraphQL enum registrations are properly configured.

All enums are correctly registered with GraphQL using appropriate names and descriptions that match the TypeScript enum documentation.

@elibosley elibosley requested a review from pujitm July 22, 2025 14:20
@elibosley
Copy link
Member Author

This will close #1410

@elibosley elibosley force-pushed the feature/ups-monitoring branch from 5fa79ad to a389a8a Compare July 23, 2025 18:33
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)
api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts (1)

303-306: Consider using dependency injection for more robust error testing.

Temporarily overriding methods on the service instance is fragile. Consider injecting dependencies that can be mocked more cleanly, or using test-specific error scenarios that don't require method replacement.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a389a8a and 9a63830.

📒 Files selected for processing (3)
  • .claude/settings.local.json (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .claude/settings.local.json
🧰 Additional context used
📓 Path-based instructions (3)
api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*: Use pnpm as the only package manager
Always run scripts from api/package.json unless specifically requested otherwise

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
api/src/unraid-api/**/*

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts
api/**/*.{test,spec}.{js,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/api-rules.mdc)

api/**/*.{test,spec}.{js,ts,tsx}: Use Vitest as the test suite; do not use Jest
Prefer not to mock simple dependencies in tests

Files:

  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: mdatelle
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in `api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts`, methods like `removeRoleFromApiKey` rely on service-level error handling.
Learnt from: elibosley
PR: unraid/api#942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:41-47
Timestamp: 2024-11-05T14:48:56.949Z
Learning: Input types for GraphQL mutations can be pulled from the GraphQL codegen types, as they are generated into the API files. Therefore, explicit typing in the resolver files may be unnecessary.
Learnt from: pujitm
PR: unraid/api#1211
File: web/composables/gql/gql.ts:17-18
Timestamp: 2025-03-12T13:48:14.850Z
Learning: In the Unraid API project, the duplicate GraphQL query and mutation strings in gql.ts files are intentionally generated by GraphQL CodeGen tool and are necessary for the type system to function properly.
Learnt from: pujitm
PR: unraid/api#1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.
api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts (19)

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify state changes by updating the store in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Test async operations completely in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify state changes after actions in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Override specific action implementations when needed in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Mock external dependencies appropriately in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Test action side effects and state changes in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Mock external dependencies and services in tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Test getter dependencies are properly mocked in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify actions are called with correct parameters in store tests

Learnt from: elibosley
PR: #1101
File: api/src/unraid-api/unraid-file-modifier/modifications/test/generic-modification.spec.ts:55-56
Timestamp: 2025-02-03T18:57:28.442Z
Learning: Using console.log is acceptable in test files, especially for debugging test execution. The logger instances in test files are often used as mocks/dependencies for the classes being tested, not for actual logging.

Learnt from: elibosley
PR: #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: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Test action side effects if not stubbed in store tests

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Specify return values for component methods with vi.spyOn()

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Do not mock the store being tested in the test file

Learnt from: elibosley
PR: #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-07-21T13:59:55.481Z
Learning: Test suite is VITEST, do not use jest in the API codebase

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Remember that vi.mock() calls are hoisted

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/{components,store,mocks}/**/*.ts : Clear mocks between tests to ensure isolation

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (19)

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom or extended implementation of NestJS ConfigService that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/api-rules.mdc:0-0
Timestamp: 2025-07-21T14:00:06.258Z
Learning: Applies to api/src/unraid-api/**/* : Prefer adding new files to the NestJS repository located at api/src/unraid-api/ instead of the legacy code

Learnt from: CR
PR: unraid/api#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T13:59:55.481Z
Learning: Prefer adding new files to the NestJS repo located at api/src/unraid-api/ instead of the legacy code

Learnt from: pujitm
PR: #1367
File: packages/unraid-api-plugin-connect/src/pubsub/user.service.ts:44-52
Timestamp: 2025-04-23T20:19:42.542Z
Learning: The project uses a custom ConfigService implementation that includes a set() method for runtime configuration mutation, unlike the standard @nestjs/config package which only provides getter methods.

Learnt from: elibosley
PR: #942
File: api/src/unraid-api/auth/api-key.service.ts:62-70
Timestamp: 2024-11-05T14:49:07.308Z
Learning: In api/src/unraid-api/auth/api-key.service.ts, when handling read errors in the findById method, throw a GraphQLError instead of an InternalServerErrorException.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts:111-113
Timestamp: 2024-11-06T20:59:25.809Z
Learning: In the Unraid API project, error handling for mutations is handled at the service level rather than in the GraphQL resolvers. Specifically, in api/src/unraid-api/graph/resolvers/auth/auth.resolver.ts, methods like removeRoleFromApiKey rely on service-level error handling.

Learnt from: pujitm
PR: #1252
File: api/src/environment.ts:56-56
Timestamp: 2025-03-27T13:34:53.438Z
Learning: For critical components in the Unraid API, such as retrieving version information from package.json, failing fast (allowing crashes) is preferred over graceful degradation with fallback values.

Learnt from: CR
PR: unraid/api#0
File: .cursor/rules/web-testing-rules.mdc:0-0
Timestamp: 2025-07-21T14:01:04.139Z
Learning: Applies to web/test/store/**/*.ts : Verify proper error handling in store tests

Learnt from: elibosley
PR: #1063
File: api/src/unraid-api/cli/sso/validate-token.command.ts:76-81
Timestamp: 2025-01-23T21:26:17.766Z
Learning: In the unraid/api codebase, store dispatches using Redux Toolkit's unwrap() method already handle errors appropriately and don't require additional try-catch blocks.

Learnt from: pujitm
PR: #1219
File: api/src/unraid-api/main.ts:18-25
Timestamp: 2025-03-07T19:29:12.540Z
Learning: When handling type mismatches between dependencies in TypeScript (such as between NestJS and Fastify), prefer using @ts-expect-error with a detailed explanation comment instead of as any type assertions. This better documents the reason for the type bypass and makes the issue more visible for future maintenance.

Learnt from: pujitm
PR: #1352
File: api/src/unraid-api/cli/dependency.service.ts:114-117
Timestamp: 2025-04-21T18:25:16.491Z
Learning: Methods in DependencyService like npmInstall and rebuildVendorArchive intentionally propagate errors from execa calls upward rather than handling them internally, allowing callers to implement appropriate error handling. This follows the pattern documented in the rebuildVendorArchive method's docstring.

Learnt from: elibosley
PR: #1120
File: plugin/plugins/dynamix.unraid.net.plg:35-38
Timestamp: 2025-02-05T21:10:48.136Z
Learning: When providing error handling guidance for Unraid plugins, direct users to use the web GUI (Plugins > Installed Plugins) rather than suggesting command-line actions.

Learnt from: pujitm
PR: #1075
File: web/components/Notifications/Sidebar.vue:41-58
Timestamp: 2025-01-31T14:42:06.752Z
Learning: When handling errors in code that uses toast notifications, avoid using toast in the error handler itself since toast functionality might be the source of the error. Use console.error or other reliable logging mechanisms instead.

Learnt from: pujitm
PR: #1075
File: unraid-ui/src/register.ts:15-34
Timestamp: 2025-01-30T19:38:02.478Z
Learning: In the web components registration process for unraid-ui, use a soft-fail approach (logging warnings/errors) instead of throwing errors, to ensure other components can still register successfully even if one component fails.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:33-37
Timestamp: 2025-01-29T16:36:04.777Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations. It includes try/catch blocks, detailed error logging, and safe rollback mechanisms. Individual FileModification implementations (like LogRotateModification) should allow errors to propagate to this service layer rather than handling them internally.

Learnt from: pujitm
PR: #1211
File: api/src/graphql/schema/types/connect/connect.graphql:142-146
Timestamp: 2025-03-14T16:10:38.562Z
Learning: The updateApiSettings mutation in api/src/unraid-api/graph/connect/connect.resolver.ts is protected with the @UsePermissions decorator that requires UPDATE permission on the CONFIG resource.

Learnt from: elibosley
PR: #1425
File: api/dev/configs/connect.json:2-3
Timestamp: 2025-06-20T21:05:24.582Z
Learning: When reviewing configuration files in refactoring PRs, avoid suggesting field name changes that could break compatibility with existing code that references those fields, even if the naming doesn't follow ideal conventions.

Learnt from: elibosley
PR: #1082
File: api/src/unraid-api/unraid-file-modifier/modifications/log-rotate.modification.ts:39-41
Timestamp: 2025-01-29T16:35:43.699Z
Learning: The UnraidFileModifierService in the Unraid API provides comprehensive error handling for all FileModification implementations, including detailed error logging with stack traces and modification IDs. Individual FileModification implementations should focus on their core functionality without duplicating error handling.

Learnt from: mdatelle
PR: #942
File: api/src/unraid-api/auth/auth.service.ts:0-0
Timestamp: 2024-11-04T20:44:46.432Z
Learning: When modifying apiKey.roles in removeRoleFromApiKey and addRoleToApiKey within api/src/unraid-api/auth/auth.service.ts, concurrency issues are not a concern because the keys are stored in the file system.

⏰ 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). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts (1)

58-100: Good test isolation with temporary directories.

Using temporary directories for each test avoids the brittleness of mocking file system operations and provides better test reliability. The cleanup in afterEach ensures tests don't interfere with each other.

api/src/unraid-api/graph/resolvers/ups/ups.service.ts (8)

1-40: Good use of type-safe schemas and appropriate dependencies.

The imports are well-chosen with proper NestJS patterns, and the Zod schemas provide excellent type safety for UPS data validation. The optional fields in both schemas appropriately handle cases where UPS data may be incomplete.


41-64: Excellent error handling and validation improvements.

The getUPSData method properly addresses previous review concerns with timeout configuration, output validation, proper logging service usage, and comprehensive error handling. The use of reject: false with manual error handling is a good pattern.


66-90: Well-structured configuration method with proper error handling.

The configureUPS method demonstrates good separation of concerns by breaking down the complex configuration process into logical, sequential steps. The comprehensive error handling and use of private helper methods makes this maintainable despite its complexity.


92-114: Clean configuration merging with appropriate validation.

The configuration merging uses proper nullish coalescing operators and provides sensible defaults. The validation logic is clear and provides helpful error messages for required fields.


116-134: Thoughtful error handling for service control operations.

The differentiated error handling between stopUPSService (warns on failure since service may not be running) and startUPSService (throws on failure since it's critical) shows good understanding of operational requirements.


136-209: Robust configuration backup and restore mechanism.

The backup/restore functionality provides excellent safety for configuration changes. The prepareConfigObject method correctly handles the cable selection logic, and the error handling ensures proper rollback if writing fails.


211-272: Well-implemented kill power configuration with proper safety checks.

The kill power configuration logic properly validates existing state before making changes and handles missing files gracefully. The error handling distinguishes between expected scenarios (like missing files in tests) and actual failures.


274-387: Clean utility methods with comprehensive parsing logic.

The parsing and generation methods demonstrate good functional programming practices. The configuration parsing properly handles comments, quotes, and numeric conversion, while the generation method maintains appropriate formatting and ordering.

@elibosley elibosley force-pushed the feature/ups-monitoring branch from 9a63830 to fd2231a Compare July 23, 2025 20:17
@elibosley elibosley requested a review from pujitm July 25, 2025 14:56
@elibosley
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (2)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (2)

107-114: Configuration validation could be more comprehensive.

While the basic validation is present, consider adding validation for numeric ranges (e.g., batteryLevel should be 0-100, timeout should be non-negative) and string format validation for device paths.

 private validateConfiguration(config: ReturnType<typeof this.mergeConfigurations>): void {
     if (!config.upsType) {
         throw new Error('upsType is required');
     }
     if (!config.device && config.upsType !== 'usb') {
         throw new Error('device is required for non-USB UPS types');
     }
+    if (config.batteryLevel < 0 || config.batteryLevel > 100) {
+        throw new Error('batteryLevel must be between 0 and 100');
+    }
+    if (config.minutes < 0) {
+        throw new Error('minutes must be non-negative');
+    }
+    if (config.timeout < 0) {
+        throw new Error('timeout must be non-negative');
+    }
 }

283-295: Consider using more functional approach for data parsing.

The parsing logic works correctly but could benefit from the functional programming approach suggested in previous reviews.

 private parseUPSData(data: string): any {
     return data
         .split('\n')
-        .map((line) => line.split(': '))
-        .filter((parts) => parts.length === 2 && parts[0] && parts[1])
+        .map((line) => line.split(': '))
+        .filter(([key, value]) => key && value)
         .reduce(
-            (upsData, [key, value]) => {
-                upsData[key.trim()] = value.trim();
-                return upsData;
-            },
+            (upsData, [key, value]) => ({
+                ...upsData,
+                [key.trim()]: value.trim()
+            }),
             {} as Record<string, string>
         );
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a63830 and fd2231a.

📒 Files selected for processing (14)
  • .claude/settings.local.json (1 hunks)
  • api/src/unraid-api/graph/resolvers/resolvers.module.ts (2 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts (1 hunks)
  • api/src/unraid-api/graph/resolvers/ups/ups.service.ts (1 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 skipped from review as they are similar to previous changes (13)
  • 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/rc.nginx.last-download-time
  • api/src/unraid-api/graph/resolvers/resolvers.module.ts
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/DefaultPageLayout.php.last-download-time
  • api/src/unraid-api/graph/resolvers/ups/ups.module.ts
  • api/src/unraid-api/unraid-file-modifier/modifications/test/fixtures/downloaded/.login.php.last-download-time
  • .claude/settings.local.json
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.resolver.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.service.spec.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.model.ts
  • api/src/unraid-api/graph/resolvers/ups/ups.inputs.ts
🔇 Additional comments (7)
api/src/unraid-api/graph/resolvers/ups/ups.service.ts (7)

1-40: Well-structured schema definitions and imports.

The imports are clean and the Zod schemas provide good type safety for UPS data and configuration validation. The optional fields in both schemas appropriately reflect the variable nature of UPS data.


47-64: Robust UPS data retrieval with proper error handling.

The implementation correctly addresses previous feedback with timeout handling, output validation, and proper error propagation. The use of reject: false with manual error handling is appropriate for this system command execution.


66-90: Well-orchestrated configuration flow with comprehensive error handling.

The main configuration method properly coordinates all the necessary steps: merging configurations, validation, service management, backup creation, and kill power setup. The error handling ensures any failures are properly logged and re-thrown with context.


188-209: Excellent backup and restore pattern.

The backup creation and restoration logic is well-implemented with appropriate error handling. The pattern of creating backups before modifications and restoring on failure provides good safety for critical system configuration changes.


234-272: Robust file modification with safety checks.

The rc.6 file modification logic properly checks current state before making changes and includes comprehensive error handling. The approach of reading, modifying, and writing the entire file content is safer than using sed commands directly.


315-341: Configuration parsing logic is solid.

The apcupsd configuration parsing correctly handles comments, quotes, and numeric conversion. The regex pattern and filtering logic properly extract directive-value pairs from the configuration format.


343-387: Well-structured configuration generation.

The config generation method maintains proper ordering of directives and handles both string and numeric values appropriately. The approach of merging existing and new configurations ensures no data loss during updates.

Copy link
Member

@pujitm pujitm left a comment

Choose a reason for hiding this comment

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

lgtm after this!

@elibosley elibosley force-pushed the feature/ups-monitoring branch from fd2231a to 45cc781 Compare July 25, 2025 19:05
@claude
Copy link

claude bot commented Jul 25, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@elibosley elibosley force-pushed the feature/ups-monitoring branch from 45cc781 to c1f1eb8 Compare July 25, 2025 19:12
@claude
Copy link

claude bot commented Jul 25, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

google-labs-jules bot and others added 11 commits July 30, 2025 13:43
- Updated UPS input types to use non-nullable fields for better validation.
- Introduced UPSConfiguration type to encapsulate UPS settings.
- Enhanced UPS service to include configuration backup and restoration.
- Improved error handling and logging during UPS configuration.
- Added new test cases for UPS resolver and service methods.
- Updated local settings to include new test commands for UPS API.

This commit improves the robustness and usability of the UPS monitoring feature in the API.
…d enhance error handling; update settings for additional test commands
…t types; update resolver and service to utilize new structure
…ig updates; enhance input validation and service handling
…and improved config validation; update settings for test command consistency
…handling and refactor for better testability; update settings for additional test commands
@elibosley elibosley force-pushed the feature/ups-monitoring branch from c1f1eb8 to a0f519c Compare July 30, 2025 17:43
@claude
Copy link

claude bot commented Jul 30, 2025

Claude finished @elibosley's task —— View job


UPS Monitoring PR Review

Comprehensive review of the UPS monitoring GraphQL API implementation.

Todo List

  • Read repository setup instructions (CLAUDE.md)
  • Review UPS service implementation
  • Review UPS resolver implementation
  • Review UPS models and input types
  • Review UPS module configuration
  • Analyze test coverage and quality
  • Check for security concerns
  • Evaluate performance considerations
  • Provide comprehensive feedback summary

📋 Review Summary

This PR implements a comprehensive UPS monitoring system with GraphQL integration. The code demonstrates high quality overall with good architecture, comprehensive testing, and proper error handling.

🟢 Strengths

Architecture & Code Quality

  • Excellent use of NestJS patterns and dependency injection
  • Proper separation of concerns with well-structured modules
  • Comprehensive Zod schemas for type safety and validation
  • Good use of GraphQL decorators and schema-first approach
  • Clean resolver implementation with proper query/mutation/subscription separation

Error Handling & Reliability

  • Atomic configuration updates with backup/restore functionality
  • Comprehensive error handling with proper logging throughout
  • Robust file system operations with failure recovery
  • Good use of timeouts and error boundaries

Testing

  • Excellent service test coverage (462 lines) with real file system testing
  • Tests cover happy path, error scenarios, and edge cases
  • Good use of temporary directories instead of brittle mocking
  • Comprehensive coverage of configuration merging and killpower functionality

🟡 Areas for Improvement

Security Concerns (Medium Priority)

  1. System Command Execution: Direct execution of system commands via execa poses potential risks:

    // Potentially risky - consider additional input validation
    const { stdout } = await execa('/sbin/apcaccess', [], { timeout: 10000 });
    await execa('/etc/rc.d/rc.apcupsd', ['start'], { timeout: 10000 });
  2. Critical File Modifications: Service modifies sensitive system files:

    • /etc/apcupsd/apcupsd.conf - UPS configuration
    • /etc/rc.d/rc.6 - System shutdown script (!)

    Recommendation: Add additional validation for device paths and consider file permission checks.

Performance Issues (Medium Priority)

  1. No Caching: Every GraphQL query triggers system command execution

    // ups.resolver.ts:37 - Called on every query
    const upsData = await this.upsService.getUPSData();
  2. Double Service Calls: Mutations trigger both configureUPS and getUPSData

    // ups.resolver.ts:75-76 - Two service calls per mutation
    await this.upsService.configureUPS(config);
    const updatedData = await this.upsService.getUPSData();

Code Quality (Low Priority)

  1. Long Method: configureUPS method handles multiple concerns (24 lines)
  2. Hardcoded Values: Fallback values in createUPSDevice could be configuration-driven
  3. Type Safety: Missing NaN handling in parseInt/parseFloat operations

🔴 Critical Issues

None identified - This is well-implemented code that follows best practices.

📊 Test Coverage Assessment

  • Service Tests: ✅ Excellent (90%+ coverage estimated)
  • Resolver Tests: 🟡 Good but could be expanded (70% coverage estimated)
  • Integration Tests: ❌ Missing (consider adding E2E tests)

💡 Recommendations

Short Term (Pre-merge)

  1. Add caching to getUPSData() with 30-second TTL
  2. Add input validation for device paths (regex validation)
  3. Expand resolver tests to cover error scenarios

Long Term (Future PRs)

  1. Consider breaking configureUPS into smaller methods
  2. Add integration tests for full UPS workflow
  3. Consider making PubSub a global singleton
  4. Add metrics/monitoring for UPS command execution times

✅ Overall Assessment

Rating: 8.5/10 - This is high-quality, production-ready code with excellent error handling, comprehensive testing, and good architecture. The security and performance concerns are manageable and don't block merging, but should be addressed in follow-up work.

The implementation correctly follows the repository's coding guidelines and NestJS best practices. The test coverage is impressive and demonstrates thorough consideration of edge cases.

Recommendation: ✅ APPROVED - Ready to merge with the minor improvements noted above.


@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/PR1526/dynamix.unraid.net.plg

@elibosley elibosley requested a review from pujitm July 30, 2025 18:52
@elibosley elibosley merged commit 6ea94f0 into main Jul 30, 2025
13 checks passed
@elibosley elibosley deleted the feature/ups-monitoring branch July 30, 2025 18:52
elibosley pushed a commit that referenced this pull request Jul 30, 2025
🤖 I have created a release *beep* *boop*
---


## [4.12.0](v4.11.0...v4.12.0)
(2025-07-30)


### Features

* add ups monitoring to graphql api
([#1526](#1526))
([6ea94f0](6ea94f0))


### Bug Fixes

* enhance plugin management with interactive removal prompts
([#1549](#1549))
([23ef760](23ef760))
* remove connect api plugin upon removal of Connect Unraid plugin
([#1548](#1548))
([782d5eb](782d5eb))
* SSO not being detected
([#1546](#1546))
([6b3b951](6b3b951))

---
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>
@coderabbitai coderabbitai bot mentioned this pull request Jul 31, 2025
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.

2 participants