Skip to content

Config#116

Merged
utkarsh232005 merged 9 commits into
KDM-cli:mainfrom
Yuvraj-Sarathe:config
May 29, 2026
Merged

Config#116
utkarsh232005 merged 9 commits into
KDM-cli:mainfrom
Yuvraj-Sarathe:config

Conversation

@Yuvraj-Sarathe
Copy link
Copy Markdown
Member

@Yuvraj-Sarathe Yuvraj-Sarathe commented May 29, 2026

Reopening PR for #24

Summary by CodeRabbit

Release Notes

  • New Features

    • Added interactive setup flow for Discord and Email notifications with reconfiguration prompts
    • Deprecation warnings now guide users toward config setup when setting credentials via config set
    • SMTP password can now be configured directly during email setup
  • Improvements

    • Enhanced config list output formatting and clarified environment variable precedence for SMTP password
    • Simplified welcome banner display

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Warning

Review limit reached

@Yuvraj-Sarathe, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 35 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 549a0728-609e-4ed2-9d94-e452bdf9c533

📥 Commits

Reviewing files that changed from the base of the PR and between 2a1349f and b88837d.

📒 Files selected for processing (2)
  • src/__tests__/config.test.ts
  • src/commands/config.ts

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "pre_merge_checks"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • 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
📝 Walkthrough

Walkthrough

The PR refactors the config command to add structured setup handlers with reconfiguration prompts, implements value parsing and deprecation warnings for config set, improves config list output formatting and SMTP password documentation, and simplifies the welcome banner signature.

Changes

Config Command Improvements

Layer / File(s) Summary
Setup reconfiguration and handler architecture
src/commands/config.ts, src/__tests__/config.test.ts
New promptReconfigurationIfNeeded() checks if notifications are already enabled and prompts for confirmation before reconfiguring. Setup branching is replaced with dedicated none, discord, and email handlers routed through a handler map. Tests verify reconfiguration prompting (with cancel/confirm paths), skipping prompts when no prior config exists, and graceful error handling when selection or persistence fails. Email setup tests verify SMTP password is conditionally persisted and that host validation is required while password validation is permissive.
Config set value parsing and deprecation warnings
src/commands/config.ts, src/__tests__/config.test.ts
New parseConfigValue() helper centralizes numeric coercion and validation (with explicit errors for invalid numbers) for keys like alert_cooldown and email_port. New checkDeprecation() emits a warning when credential keys (discord_webhook, email_*) are set directly via config set, directing users to kdm config setup. Tests verify warnings are emitted only for credential keys, values are still persisted with proper coercion, and non-credential keys proceed silently.
List output formatting and SMTP password documentation
src/commands/config.ts
config list now displays "no configuration found" when empty, formats entries without leading spaces, and clarifies that SMTP password can be set during setup or via KDM_SMTP_PASSWORD (with environment variable precedence). Email SMTP guide step 4 text is updated accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • KDM-cli/kdm-cli#96: Aligns with config-layer changes restricting SMTP password storage to environment variable instead of persisting to config.
  • KDM-cli/kdm-cli#92: Corresponds to config-store and utility changes migrating legacy notification fields and resolving SMTP password via KDM_SMTP_PASSWORD.
  • KDM-cli/kdm-cli#23: Overlaps in refactoring kdm config setup interactive flow and adding credential guidance before prompts.

Suggested reviewers

  • utkarsh232005
  • Rishiraj-Pathak-27

Poem

🔧 Setup handlers bloom in ordered grace,
Value parsing catches edge-case place,
Deprecation whispers guide the way,
List formatting brightens config's day,
Banner sleek—clean, sharp, astray.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Config' is overly vague and generic, providing no meaningful information about the specific changes made in this substantial PR. Consider a more descriptive title like 'Refactor config setup/set commands with deprecation warnings and improved email SMTP handling' to clearly communicate the primary changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@utkarsh232005
Copy link
Copy Markdown
Member

the test are falling as well as deepscan and codescene too the code is not as per desired requirement go through your code and the reviewed changes by codescene to maintain the code quality

Removed redundant declaration of finalValue.
codescene-delta-analysis[bot]

This comment was marked as outdated.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/commands/config.ts 88.88% 5 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@Yuvraj-Sarathe
Copy link
Copy Markdown
Member Author

Yuvraj-Sarathe commented May 29, 2026

the test are falling as well as deepscan and codescene too the code is not as per desired requirement go through your code and the reviewed changes by codescene to maintain the code quality

Hey @utkarsh232005 , I fixed the GitHub tests, but Codescene and Codecov—I am not able to understand what they want me to do. I tried making an account on CodeScene to get a detailed analysis; it asked me to buy a membership. I am not buying that, as I am just a 1st-year student.

Same with Codecov, I don't even know what it is saying. It says 90.00000% and some +0.61% change or something like that. I am assuming that means if I change the thing it wants me to change, it will increase its code quality by 0.61%, but I DO NOT KNOW WHAT TO CHANGE!

My suggestion is to ignore Codecov because he himself says 90% is good and GitHub tests are running perfectly.

As for CodeScene, I am not seeing a bug but an improvement in code quality and, I guess, simplicity maybe. There is a button there that says "install it to fix." I think you have the subscription, so you should install it and try it out because I tried running this locally, and it works out. The tests were the only part that failed, but they are working now, so only these two problems remain.

I am sorry, but I cannot even understand what they are saying, let alone fix the things they want with my current skill set.

@utkarsh232005
Copy link
Copy Markdown
Member

the test are falling as well as deepscan and codescene too the code is not as per desired requirement go through your code and the reviewed changes by codescene to maintain the code quality

Hey @utkarsh232005 , I fixed the GitHub tests, but Codescene and Codecov—I am not able to understand what they want me to do. I tried making an account on CodeScene to get a detailed analysis; it asked me to buy a membership. I am not buying that, as I am just a 1st-year student.

Same with Codecov, I don't even know what it is saying. It says 90.00000% and some +0.61% change or something like that. I am assuming that means if I change the thing it wants me to change, it will increase its code quality by 0.61%, but I DO NOT KNOW WHAT TO CHANGE!

My suggestion is to ignore Codecov because he himself says 90% is good and GitHub tests are running perfectly.

As for CodeScene, I am not seeing a bug but an improvement in code quality and, I guess, simplicity maybe. There is a button there that says "install it to fix." I think you have the subscription, so you should install it and try it out because I tried running this locally, and it works out. The tests were the only part that failed, but they are working now, so only these two problems remain.

I am sorry, but I cannot even understand what they are saying, let alone fix the things they want with my current skill set.

No need to create a CodeScene account or purchase a subscription! The organization already has a premium subscription to monitor and maintain code health.

The CodeScene check is failing due to two specific architectural metrics in src/commands/config.ts:

Bumpy Road Ahead: This happens when code contains nested control structures (like deeply nested if statements inside for loops). CodeScene flags this because nesting makes the logic harder to read and maintain. You can fix this by extracting the inner logic into smaller, dedicated helper functions or using early return/continue guard clauses.

Cyclomatic Complexity: This means there are too many decision paths (branches) inside a single method. Splitting your main logic into modular, single-responsibility functions will naturally lower this score and pass the gate.

For your reference, here is the visual breakdown from CodeScene:
image

codescene-delta-analysis[bot]

This comment was marked as outdated.

@Yuvraj-Sarathe
Copy link
Copy Markdown
Member Author

@Yuvraj-Sarathe completed.

Copy link
Copy Markdown
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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/__tests__/config.test.ts (2)

239-242: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Add an error-path test for parseConfigValue.

The happy paths for numeric coercion are covered, but the throw branch (Invalid numeric value for "..." on alert_cooldown/email_port with a non-numeric value) is not exercised. Add a case asserting the failure is reported and setConfig is not called.

💚 Cover the invalid-numeric branch
   it('should parse integer for alert_cooldown', async () => {
     await program.parseAsync(['node', 'test', 'config', 'set', 'alert_cooldown', '123']);
     expect(configUtils.setConfig).toHaveBeenCalledWith('alert_cooldown', 123);
   });
+
+  it('should reject a non-numeric value for email_port', async () => {
+    await program.parseAsync(['node', 'test', 'config', 'set', 'email_port', 'not-a-number']);
+    expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Invalid numeric value'));
+    expect(configUtils.setConfig).not.toHaveBeenCalled();
+  });

As per coding guidelines: "Verify that tests cover both happy paths and error conditions."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__tests__/config.test.ts` around lines 239 - 242, Add a test that
exercises parseConfigValue's error branch by calling program.parseAsync with a
non-numeric value for a numeric key (e.g.,
['node','test','config','set','alert_cooldown','not-a-number']), then assert the
promise rejects with the "Invalid numeric value for \"alert_cooldown\"" error
and that configUtils.setConfig was not called; place this alongside the existing
happy-path test so it verifies parseConfigValue throws and prevents setConfig
from running.

35-41: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Mock state leaks across tests — getConfig return value persists.

vi.clearAllMocks() clears call history but does not reset values set via mockReturnValue. Once a test (e.g. Line 93/104) sets getConfig to { notification_service: 'discord' }, that value bleeds into every later test until another test reassigns it; the suite only passes because Line 118 happens to reset it to {}. This creates an implicit ordering dependency. Re-establish the default in beforeEach.

♻️ Reset the default each run
   beforeEach(() => {
     vi.clearAllMocks();
+    vi.mocked(configUtils.getConfig).mockReturnValue({});
     program = new Command();

As per coding guidelines: "Ensure mocks are clean and shared correctly."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/__tests__/config.test.ts` around lines 35 - 41, The test suite leaks a
mocked return value for getConfig across tests because vi.clearAllMocks()
doesn't reset mockReturnValue; update the beforeEach so after calling
vi.clearAllMocks() and before running tests (after
registerConfigCommand(program)), explicitly reset the getConfig mock's default
return (e.g., ensure getConfig.mockReturnValue({}) or equivalent) so each test
starts with a clean default; refer to getConfig, beforeEach, vi.clearAllMocks,
registerConfigCommand and the console spies to locate where to add the reset.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/config.ts`:
- Line 156: The help text incorrectly states SMTP password "can be set... in
config" while setConfig (the email_password handling in setConfig) rejects it;
update the console.log message and the guide step text (in the same module) to
state that the SMTP password must be provided via the KDM_SMTP_PASSWORD
environment variable only (not in config) and ensure any explanatory copy
references setConfig's env-only behavior so users aren't misled.
- Line 13: The console.log call is using chalk.yellow as a tagged-template
(chalk.yellow`...`) which is invalid in Chalk v5; change the call to use
chalk.yellow(...) instead and pass a regular template string so the nested
chalk.bold(serviceLabel) still interpolates correctly—update the console.log
line that references serviceLabel to call chalk.yellow with a template literal
argument rather than using tagged-template syntax.
- Around line 75-87: The code must not call setConfig('email_password',
password) because setConfig explicitly forbids the sensitive legacy key and will
throw; remove that call in src/commands/config.ts and instead treat the entered
password as transient: after reading password (variable password) call
clearNotificationCredentials() (already present) and, if you want UX,
print/inform the user to set KDM_SMTP_PASSWORD in their environment or store it
via the secure flow, but do not persist via setConfig; ensure no other code
paths in this file call setConfig with 'email_password'.

---

Outside diff comments:
In `@src/__tests__/config.test.ts`:
- Around line 239-242: Add a test that exercises parseConfigValue's error branch
by calling program.parseAsync with a non-numeric value for a numeric key (e.g.,
['node','test','config','set','alert_cooldown','not-a-number']), then assert the
promise rejects with the "Invalid numeric value for \"alert_cooldown\"" error
and that configUtils.setConfig was not called; place this alongside the existing
happy-path test so it verifies parseConfigValue throws and prevents setConfig
from running.
- Around line 35-41: The test suite leaks a mocked return value for getConfig
across tests because vi.clearAllMocks() doesn't reset mockReturnValue; update
the beforeEach so after calling vi.clearAllMocks() and before running tests
(after registerConfigCommand(program)), explicitly reset the getConfig mock's
default return (e.g., ensure getConfig.mockReturnValue({}) or equivalent) so
each test starts with a clean default; refer to getConfig, beforeEach,
vi.clearAllMocks, registerConfigCommand and the console spies to locate where to
add the reset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dc6c4a4d-0f9d-4efe-99af-13e131563274

📥 Commits

Reviewing files that changed from the base of the PR and between 2a35497 and 2a1349f.

📒 Files selected for processing (3)
  • src/__tests__/config.test.ts
  • src/commands/config.ts
  • src/ui/banner.ts

Comment thread src/commands/config.ts Outdated
Comment thread src/commands/config.ts
Comment thread src/commands/config.ts
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
codescene-delta-analysis[bot]

This comment was marked as outdated.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@utkarsh232005
Copy link
Copy Markdown
Member

@Yuvraj-Sarathe over-all code quality increased great work but some test are falling pls investigate the issue on github action logs

Refactor email setup to include optional SMTP password and improve validation messages.
Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

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

Code Health Improved (1 files improve in Code Health)

Gates Passed
3 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
config.ts 9.38 → 10.00 Complex Method

Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@Yuvraj-Sarathe
Copy link
Copy Markdown
Member Author

@utkarsh232005 merge

@utkarsh232005
Copy link
Copy Markdown
Member

overall code quality increased and all test are passed @Yuvraj-Sarathe great work.I hope you learned something new from this PR.

Moving forward, always remember to maintain code quality by breaking your logic down into simple, dedicated functions instead of creating deeply nested structures—whether you are writing the code yourself or generating it with an AI tool.

Thanks, and happy coding!

@utkarsh232005 utkarsh232005 merged commit 8b2a2ec into KDM-cli:main May 29, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants