ahoy icon indicating copy to clipboard operation
ahoy copied to clipboard

Feature: Added config file feature detection and schema validation

Open ocean opened this issue 5 months ago • 5 comments

This is done using the new ahoy config ... top level command, including the ahoy config validate command for the config file schema validation and system configuration report.

Summary by CodeRabbit

  • New Features

    • Added config init and config validate commands with detailed reports, recommendations and a backward-compatible notice when using the old init alias.
    • Improved path expansion so env/import file paths and home-directory (~) handling work across platforms and subdirectories.
  • Bug Fixes

    • Prevented crashes for missing imports and improved diagnostics for import-related errors.
  • Documentation

    • Updated CI badge to GitHub Actions, refreshed contributors list (now 14) including a new contributor, and updated sponsor image.
  • Tests

    • Added comprehensive tests for config init, validate, path handling and various config scenarios.
  • Chores

    • Updated an indirect dependency and added formatting/modernisation targets.

ocean avatar Jul 21 '25 03:07 ocean

[!WARNING]

Rate limit exceeded

@ocean has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 30 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 61d1ba9a7b93ced7f6981a7324c1cdd6047ac996 and d0789d27fe422562f744e57a02893a8b9d3cbe66.

📒 Files selected for processing (1)
  • v2/ahoy.go (14 hunks)

Walkthrough

Adds a contributor and README badge updates; introduces path expansion and a hidden simulate-version flag; changes getConfig signature; adds config init and config validate commands with comprehensive validation/reporting, tests, testdata, Makefile targets, and an indirect dependency bump.

Changes

Cohort / File(s) Summary
Contributors & README
/.all-contributorsrc, README.md
Add contributor jnsalsa; update badges (CircleCI→GitHub Actions, contributors count/style); move badges; replace sponsor image; add contributor row in README.
Core CLI & path handling
v2/ahoy.go, v2/flag.go
Add expandPath(path, baseDir string) and var simulateVersion string; add hidden --simulate-version flag; change getConfig(file, skipValidation bool) signature and update callers; resolve import/env paths via expandPath; improve import error diagnostics; avoid duplicate default commands; update setupApp to call getConfig with skipValidation.
Config init feature
v2/config_init.go, v2/config_init_test.go, v2/tests/config-init.bats
Implement ahoy config init (download example, prompts, --force, custom URL); add InitArgs, RunConfigInit, CLI handler and unit + Bats tests; deprecation notice for legacy ahoy init.
Config validate & reporting
v2/config_validation.go, v2/config.go, v2/config_validation_test.go, v2/tests/config-validate.bats
Implement version-aware validation framework, issue types, semantic version checks, file existence validations, RunConfigValidate and PrintConfigReport; add CLI handler validateCommandAction; extensive Go + Bats tests.
Tests & small test fixes
v2/tests/missing-cmd.bats, v2/tests/no-ahoy-file.bats, v2/ahoy_test.go, v2/windows_test.go, v2/description_test.go
Update expected messages/lines in Bats tests; adapt tests to new getConfig signature; add TestExpandPath.
Testdata
v2/testdata/*.ahoy.yml, v2/testdata/.env.test
Add fixtures: invalid-yaml.ahoy.yml, missing-api-version.ahoy.yml, with-imports.ahoy.yml, wrong-api-version.ahoy.yml, and .env.test.
Bats test suites
v2/tests/config-init.bats, v2/tests/config-validate.bats
Add Bats suites exercising config init and config validate flows and edge cases.
Build tooling
v2/Makefile
Add fmt, modernize, modernize-check targets and update .PHONY.
Dependencies / vendor
v2/go.mod, v2/vendor/modules.txt
Bump github.com/cpuguy83/go-md2man/v2 v2.0.2 → v2.0.7; vendor metadata updated.
CI workflow
.github/workflows/release.yml
Pin goreleaser-action to ~> v2 instead of latest.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as Ahoy CLI
  participant FS as Filesystem
  participant Net as HTTP

  User->>CLI: ahoy config init [--force] [URL]
  CLI->>FS: Check for .ahoy.yml
  alt exists and not --force
    CLI->>User: Prompt overwrite?
    User-->>CLI: yes/no
    opt no
      CLI-->>User: Abort without changes
    end
  end
  CLI->>Net: GET example config (URL or default)
  Net-->>CLI: Response body / error
  CLI->>FS: Write .ahoy.yml
  CLI-->>User: Success or error message
sequenceDiagram
  participant User
  participant CLI as Ahoy CLI
  participant FS as Filesystem

  User->>CLI: ahoy config validate
  CLI->>FS: Locate .ahoy.yml
  alt not found
    CLI-->>User: Warn and exit
  else found
    CLI->>CLI: Load config (getConfig with skipValidation)
    CLI->>CLI: ValidateConfig (versions, imports, envs)
    CLI->>FS: Check import/env file existence (expandPath)
    CLI-->>User: PrintConfigReport with recommendations
  end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

  • ahoy-cli/ahoy#143: Adjusts the same Bats test for the missing-imports fatal message; this PR updates that test expectation and likely resolves the same assertion drift.

Possibly related PRs

  • ahoy-cli/ahoy#159: Modifies the GoReleaser-related release workflow; related to this PR's change pinning goreleaser-action to ~> v2.
  • ahoy-cli/ahoy#157: Touches v2 command-loading/handling (getCommands/setupApp); closely related to the CLI and command-setup changes in this PR.

Suggested labels

ready-for-merging

Poem

I’m a rabbit at keys with a keen little hop,
Paths expand neat as I nibble and crop.
Init fetches a file, validate gives a wink,
Badges refreshed—give the repo a blink.
Thump-thump, code checks—now off for a hop! 🐇

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch schema-validation

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
🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

coderabbitai[bot] avatar Jul 22 '25 01:07 coderabbitai[bot]

@ocean Currently, the only reserved command is init. This PR adds a second command doctor. It may already be used by consumer projects for their own functionality.

Can doctor be renamed to config validate to avoid clashes? config would be a high-level reserved word and validate would be a sub-command. This will future-proof the implementation to support additional actions like config process (to compile a full config from all included files - what Docker Compose does) or config migrate (to migrate from Ahoy 2 to Ahoy 3) etc.

AlexSkrypnyk avatar Jul 22 '25 06:07 AlexSkrypnyk

@AlexSkrypnyk Yep cool, good idea. I didn't want to add a new top level command at all, but that is a good suggestion to use "config" as a reserved word and then we can have sub-commands under it in future.

ocean avatar Jul 22 '25 06:07 ocean

Also given this a new top level command, it's probably a breaking change that we should release as Ahoy v3 rather than another v2 release 🤔

ocean avatar Jul 22 '25 06:07 ocean

Also given this a new top level command, it's probably a breaking change that we should release as Ahoy v3 rather than another v2 release 🤔

I think adding a new reserved word is not changing API much to have it as a new major version. But leaving this with you to decide.

Thank you for working on this

AlexSkrypnyk avatar Jul 23 '25 12:07 AlexSkrypnyk