Skip to content

fix(cli): do not shadow settings.json with the defaults - #1200

Merged
Priyanshubhartistm merged 2 commits into
cameri:mainfrom
Priyanshubhartistm:fix/cli-bootstrap-keeps-legacy-settings
Nov 22, 2026
Merged

Priyanshubhartistm merged 2 commits into
cameri:mainfrom
Priyanshubhartistm:fix/cli-bootstrap-keeps-legacy-settings

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

ensureConfigBootstrap() runs at the start of nostream start and nostream setup. When .nostr/settings.yaml did not exist it copied resources/default-settings.yaml there. The relay loads settings with settings.yaml first and falls back to the deprecated settings.json only when no yaml exists (loadUserSettings). So on a deployment that still had only a settings.json, the first nostream start created a yaml full of defaults, and from then on the whole settings.json was ignored. Overrides such as nip43.enabled (admission restrictions), payment settings or limits stopped applying without any message, and the relay accepted what it had been configured to refuse (for example events from non-members).

  • the defaults are now copied only when neither settings.yaml nor settings.json exists;
  • a deployment with only a settings.json keeps working on it, as it did before the CLI touched it; the admin console and nostream config write settings.yaml themselves on the first save, and that file is built from the merged settings, so the overrides carry over;
  • getLegacySettingsFilePath is re-exported from src/cli/utils/paths.ts, next to the other path helpers the CLI uses.

I did not make the bootstrap convert settings.json into a yaml. The suggestion in the issue offered that as a second option, but not shadowing is enough to stop the silent loss, and a conversion would have to reproduce how the loader merges the two files.

Related Issue

Partly addresses #1021 (finding F-042). That issue groups seven findings; this PR only does F-042, so it does not close the issue.

Motivation and Context

Starting the relay through the CLI should not change which settings apply.

How Has This Been Tested?

New test/unit/cli/bootstrap.spec.ts, on a temporary config directory: with no settings the directory is created and the defaults are copied; an existing settings.yaml is left alone, also when a settings.json is there too; a settings.json without a yaml gets no settings.yaml and is not modified; and loadMergedSettings() still returns the settings.json override (nip43.enabled: true) after bootstrapping. Without the fix, the two tests about settings.json fail.

pnpm lint, pnpm check:deps, pnpm run build:check, pnpm run test:unit pass.

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Summary by CodeRabbit

  • Bug Fixes
    • CLI setup now preserves existing settings, including legacy JSON overrides, instead of copying default settings over them.
    • Default settings are copied only when neither YAML nor legacy JSON settings exist.
    • When both formats are present, existing YAML settings remain unchanged, and legacy JSON overrides continue to apply until YAML settings are written.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a6462cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

CLI bootstrap creates default settings.yaml only when neither YAML settings nor legacy settings.json exists. Tests cover existing settings files and legacy JSON overrides.

Changes: Settings bootstrap

Layer / File(s) Summary
Settings file precedence
src/cli/utils/bootstrap.ts, src/cli/utils/paths.ts, test/unit/cli/bootstrap.spec.ts, .changeset/cli-bootstrap-keeps-legacy-settings.md
Bootstrap checks for legacy JSON settings before copying defaults. The path helper re-exports the legacy settings path. Tests cover default creation, existing files, and legacy JSON overrides. The changeset records the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • cameri/nostream issue 1021: This change addresses the cited bootstrap finding about default YAML overriding legacy JSON settings. The issue includes other findings that this PR does not address.
Merge Risk: Minimal · up to a6462

This change stops CLI startup from creating a default settings.yaml that would hide an existing legacy settings.json. Users with JSON overrides keep them. The change is small, covered by new unit tests, and shows no merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(cli): do not shadow settings.json with the defaults" matches the main change. ensureConfigBootstrap now copies default settings only when neither settings.yaml nor the legacy settings.j…
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.
Full details: Title check

Explanation

The title "fix(cli): do not shadow settings.json with the defaults" matches the main change. ensureConfigBootstrap now copies default settings only when neither settings.yaml nor the legacy settings.json exists, so legacy JSON overrides stay effective. The title names the CLI scope, the fix type, and the affected file. It is specific and concise. The supporting paths.ts re-export and the unit tests are secondary and need no mention in the title.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the settings files with care
If YAML or JSON waits, defaults stay there
No legacy rule is brushed aside
Tests keep each settings path supplied
The rabbit hops, with config safe inside

Recent review info

Automatic approval policy

Commit: a6462cb52505.

Setting Effective value Source
Automatic approvals Enabled Global configuration
Merge risk Minimal Global configuration
Security risk Not set Global configuration

Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c0adedbc-158c-4122-bea3-ddc921c03550
Commits

Reviewing files that changed from the base of the PR and between 49dd6f8 and a6462cb.

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

The CLI now copies default settings only when neither settings.yaml nor settings.json exists.

  • CLI setup keeps legacy settings available to the relay.

Reviews (2) · Last reviewed commit: "Merge branch 'main' into fix/cli-bootstr..." · Reviewed by Greptile

@coveralls

coveralls commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 45035607095

Coverage increased (+0.002%) to 79.612%

Details

  • Coverage increased (+0.002%) from the base build.
  • Patch coverage: 4 of 4 lines across 2 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 14447
Covered Lines: 11994
Line Coverage: 83.02%
Relevant Branches: 7846
Covered Branches: 5754
Branch Coverage: 73.34%
Branches in Coverage %: Yes
Coverage Strength: 657.92 hits per line

💛 - Coveralls

@Priyanshubhartistm
Priyanshubhartistm merged commit 9ab9017 into cameri:main Nov 22, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants