Skip to content

test(cli-tools): add tests for formatters, prompts, and updateEnvFile#71

Open
ak68a wants to merge 3 commits intoagentcommercekit:mainfrom
ak68a:test/cli-tools
Open

test(cli-tools): add tests for formatters, prompts, and updateEnvFile#71
ak68a wants to merge 3 commits intoagentcommercekit:mainfrom
ak68a:test/cli-tools

Conversation

@ak68a
Copy link
Copy Markdown

@ak68a ak68a commented Mar 25, 2026

Summary

  • Add tests for all utility functions in tools/cli-tools/ which previously had zero test coverage
  • 20 tests across 3 files: formatters (10), update-env-file (6), prompts (4)

What's tested

formatters — sectionHeader divider width and step numbering, successMessage/errorMessage prefixes, wordWrap at custom and default widths, link URL preservation

update-env-file — create new .env, update existing keys in-place, append new keys, preserve comments/blank lines, multiple keys at once, values containing equals signs. Uses real temp directories, not mocks.

prompts — log with default wrapping, log with wrap disabled, logJson formatted output

Test plan

  • pnpm --filter ./tools/cli-tools test — 20 tests pass
  • pnpm run check — clean

AI Disclosure: This PR was developed with assistance from Claude Code (Claude Opus).

Summary by CodeRabbit

  • Tests
    • Added tests for CLI formatting (headers, success/error markers, wrapping, demo snippets, and link output).
    • Added tests for CLI logging and JSON logging (wrapping behavior, multi-argument logging, width control).
    • Added tests for updating .env files (creating, updating keys, preserving comments/blank lines, and handling values with =).

ak68a added 2 commits March 25, 2026 17:02
Cover all utility functions that previously had zero tests:

formatters: sectionHeader divider width and step numbering,
successMessage/errorMessage prefixes, wordWrap at custom and
default widths, demoHeader/demoFooter non-empty output, link
URL preservation.

update-env-file: create new file, update existing keys in-place,
append new keys, preserve comments and blank lines, multiple keys,
values containing equals signs. Uses real temp directories.

prompts: log with default wrapping, log with wrap disabled,
logJson formatted output.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 84a14e9c-efec-4028-a3f0-2c59ff2e9bf5

📥 Commits

Reviewing files that changed from the base of the PR and between df57655 and b33eb51.

📒 Files selected for processing (3)
  • tools/cli-tools/src/formatters.test.ts
  • tools/cli-tools/src/prompts.test.ts
  • tools/cli-tools/src/update-env-file.test.ts
✅ Files skipped from review due to trivial changes (2)
  • tools/cli-tools/src/formatters.test.ts
  • tools/cli-tools/src/prompts.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • tools/cli-tools/src/update-env-file.test.ts

Walkthrough

Three new Vitest test suites were added under tools/cli-tools/src/ to validate formatting utilities, logging/prompt behavior, and environment-file update logic; tests cover ANSI handling, wrapping, console interception, and filesystem-based key updates and preservation.

Changes

Cohort / File(s) Summary
Formatting & Logging Tests
tools/cli-tools/src/formatters.test.ts, tools/cli-tools/src/prompts.test.ts
Adds tests for formatting utilities (headers, success/error markers, word wrapping, demo header/footer, link output) and prompt logging (console interception, wrapping/width options, multi-arg logging, JSON logging). Assertions strip ANSI codes and verify line lengths and contents.
Env-file Update Tests
tools/cli-tools/src/update-env-file.test.ts
Adds filesystem-focused tests for updateEnvFile: creating .env when missing, updating existing keys while preserving unrelated keys/comments/blank lines, adding multiple keys, and handling values containing =. Uses temp dirs and stubs console output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: adding tests for three utility modules (formatters, prompts, updateEnvFile) in cli-tools, which aligns perfectly with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

@venables
Copy link
Copy Markdown
Contributor

venables commented Apr 1, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

✅ 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
Copy Markdown

@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: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tools/cli-tools/src/formatters.test.ts`:
- Around line 15-93: Several tests use non-assertive titles; update each it(...)
description to follow the mandated assertive prefixes
(creates|throws|requires|returns). For tests referencing sectionHeader, change
"creates a header with dividers matching the message width" to "creates a header
with dividers matching the message width" (already correct) and change "includes
a step number when provided" → "creates a header that includes a step number",
"omits step prefix when no step is given" → "creates a header that omits the
step prefix", for successMessage/errorMessage change "prefixes with a check
mark" → "returns a message prefixed with a check mark" and "prefixes with an X"
→ "returns a message prefixed with an X", for wordWrap change "wraps long text
to the specified width" → "wraps long text to the specified width" (keep) and
"defaults to 80 characters" → "wraps text defaulting to 80 characters", and for
demoHeader/demoFooter/link rename their titles to start with "returns" (e.g.,
"returns a non-empty demo header", "returns a non-empty demo footer", "returns
the URL with formatting applied") so all it(...) descriptions for sectionHeader,
successMessage, errorMessage, wordWrap, demoHeader, demoFooter, and link follow
the required assertive naming convention.

In `@tools/cli-tools/src/prompts.test.ts`:
- Around line 17-69: Rename the non-assertive test titles for the log and
logJson specs to start with the required assertive prefixes
(creates|throws|requires|returns); specifically, update the it(...) descriptions
that currently read "prints a message to the console", "wraps text by default",
"skips wrapping when wrap is false", "accepts multiple messages", "respects
custom width", and "prints formatted JSON" to assertive forms like "creates a
log that prints a message to the console", "returns wrapped text by default",
"returns unwrapped text when wrap is false", "creates a log that accepts
multiple messages", "returns lines within custom width", and "creates formatted
JSON output" respectively so tests for the log and logJson behaviors
(references: log(), logJson()) conform to the naming pattern.
- Around line 8-10: The test currently installs a persistent global spy via
vi.spyOn(console, "log") that mutates the shared logged array; move that spy
setup into a beforeEach hook (create/reset logged there and call
vi.spyOn(console, "log").mockImplementation(...)) and add an afterEach hook that
calls vi.restoreAllMocks() (and optionally clears logged) to ensure the
console.log spy is restored between tests; update references to the logged array
to rely on the per-test reset.

In `@tools/cli-tools/src/update-env-file.test.ts`:
- Around line 26-78: Rename the test descriptions so they start with one of the
required assertive verbs (creates|throws|requires|returns) and fix the "dont"
typo; specifically update the it(...) titles that mention "updates an existing
key in-place", "appends new keys that dont exist yet", "preserves comments and
blank lines", "handles multiple keys at once", and "handles values containing
equals signs" to begin with a valid verb (e.g., "creates/returns updates...",
"creates appends...", or "preserves" -> "returns preserved..." depending on
intent) and change "dont" to "don't" (or "do not") where applicable; locate
these tests in this file around the it(...) blocks that call updateEnvFile and
reference envPath and adjust only the string descriptions.
- Around line 21-23: The global spies on console.log and console.error (created
with vi.spyOn) are set once and never restored; move those vi.spyOn calls into a
beforeEach hook so each test gets fresh spies and remove the top-level spies,
and in the existing afterEach add vi.restoreAllMocks() to restore the spies
after each test; reference the console.log/console.error spies and the vi.spyOn,
beforeEach, afterEach, and vi.restoreAllMocks symbols when making the change.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 088bf0ba-b529-4951-bfec-0f28f1798a34

📥 Commits

Reviewing files that changed from the base of the PR and between f0e8c6c and df57655.

📒 Files selected for processing (3)
  • tools/cli-tools/src/formatters.test.ts
  • tools/cli-tools/src/prompts.test.ts
  • tools/cli-tools/src/update-env-file.test.ts

…ycle

Rename all it() descriptions to start with creates/throws/requires/returns.
Move vi.spyOn(console, ...) from top-level into beforeEach and add
afterEach(() => vi.restoreAllMocks()) in prompts.test.ts and
update-env-file.test.ts. Fix "dont" typo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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