Skip to content

refactor(cli): add IaC sync/generate commands, centralize config loading, improve auth check#69

Merged
weroperking merged 1 commit intomainfrom
codex/cli-iac-and-config-refactor
Apr 29, 2026
Merged

refactor(cli): add IaC sync/generate commands, centralize config loading, improve auth check#69
weroperking merged 1 commit intomainfrom
codex/cli-iac-and-config-refactor

Conversation

@weroperking
Copy link
Copy Markdown
Owner

@weroperking weroperking commented Apr 29, 2026

Summary

  • Added iac sync and iac generate CLI commands
  • Centralized config file discovery and loading into a shared config.ts utility
  • Improved auth check hook to skip for empty/flag-only invocations and public commands
  • Refactored migrate command handlers to accept projectRoot parameter
  • Replaced schema-scanner.ts with config.ts
  • Added testing documentation

Changes

  • New: packages/cli/src/utils/config.ts — centralized BetterBase config loading
  • New: docs/testing/test-suite-upgrade.md — testing upgrade guide
  • Removed: packages/cli/src/utils/schema-scanner.ts
  • Modified: 13 CLI and test files for IaC commands, config refactoring, and auth improvements

Summary by CodeRabbit

  • New Features

    • Added iac sync and iac generate commands for infrastructure management.
    • Introduced configuration utilities for improved config file discovery and loading.
  • Bug Fixes

    • Improved error handling across branch, RLS, webhook, and migrate commands—now properly propagate errors instead of abruptly terminating.
    • Enhanced output formatting with consistent styling across multiple CLI commands.
  • Documentation

    • Added comprehensive test suite upgrade plan documentation for the CLI.
  • Refactor

    • Consolidated internal schema scanning imports and utility paths.
    • Simplified config loading logic by extracting shared utilities.
    • Removed legacy login command registration code.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

Comprehensive CLI refactoring to replace direct process termination with error throwing for proper error propagation, consolidate config loading into shared utilities, migrate schema scanner imports to a new location, standardize output formatting with logger/chalk helpers, add new IAC sync/generate commands, and remove legacy login command registration. Includes extensive test suite upgrade documentation.

Changes

Cohort / File(s) Summary
Schema Scanner Import Migration
packages/cli/src/commands/generate.ts, packages/cli/src/commands/graphql.ts, packages/cli/src/utils/context-generator.ts, packages/cli/src/utils/schema-scanner.ts, packages/cli/test/error-messages.test.ts
Updated imports and re-exports: SchemaScanner and TableInfo now imported from ./scanner instead of ./schema-scanner; schema-scanner.ts re-exports removed.
Error Handling & Control Flow Refactoring
packages/cli/src/commands/branch.ts, packages/cli/src/commands/rls-test.ts, packages/cli/src/commands/rls.ts, packages/cli/src/commands/migrate.ts
Replaced process.exit(1) calls with thrown Error instances for failures (arg validation, operation failures); callers now handle exceptions. Branch output refactored to use logger.section/logger.keyValue and chalk coloring; rls-test now logs test summary before throwing; rls list output switched to logger helpers.
Config Loading Consolidation
packages/cli/src/utils/config.ts, packages/cli/src/commands/storage.ts, packages/cli/src/commands/webhook.ts
New config.ts utilities: findConfigFile, loadConfig, readConfigFile for centralized config discovery/loading. Storage and webhook commands now delegate config loading to these shared utilities instead of local implementations.
Output Formatting & Logger Standardization
packages/cli/src/commands/auth.ts, packages/cli/src/commands/webhook.ts, packages/cli/src/commands/migrate.ts
String formatting updated: Unicode escapes for checkmarks, template literals for separators; ANSI escape sequences replaced with chalk styling; header/footer printing moved from console.log to logger.section/logger.info/logger.keyValue.
Command Registration & Entry Point
packages/cli/src/commands/login.ts, packages/cli/src/index.ts
Removed registerLoginCommand and runLoginCommandLegacy from login.ts; added iac sync and iac generate subcommands in index.ts; refactored auth pre-check using extractCommandName helper and PUBLIC_COMMANDS list; updated migrate handlers to pass projectRoot.
Migrate Command Major Refactor
packages/cli/src/commands/migrate.ts
Threaded projectRoot through migration generation, backup, drizzle-kit execution, and SQL discovery; introduced runMigrateCommand with explicit diff preview, production confirmation prompts, backup/restore, connection/conflict/generic error differentiation, and post-push GraphQL schema regeneration. Removed process.chdir side effects and converted error paths from process.exit to thrown errors.
Documentation & Test Plan
docs/testing/test-suite-upgrade.md
Added comprehensive 946-line test suite upgrade documentation: health metrics, untargeted modules, missing test categories, phased implementation plan, shared test fixtures/harness modules, snapshot testing patterns, target folder structure, acceptance criteria, risk register, and effort estimates.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~70 minutes

Possibly related PRs

Suggested labels

codex

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main changes: adding IaC sync/generate commands, centralizing config loading, and improving the auth check mechanism.
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
  • Commit unit tests in branch codex/cli-iac-and-config-refactor

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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@weroperking weroperking merged commit b6f0a6a into main Apr 29, 2026
3 of 4 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.

1 participant