Skip to content

refactor(cli): route assertion-stable strings through messages.ts#371

Merged
coderdan merged 1 commit intomainfrom
cli-messages-module
Apr 30, 2026
Merged

refactor(cli): route assertion-stable strings through messages.ts#371
coderdan merged 1 commit intomainfrom
cli-messages-module

Conversation

@coderdan
Copy link
Copy Markdown
Contributor

@coderdan coderdan commented Apr 30, 2026

Summary

Phase 2 of the CLI testing work (planned in docs/plans/cli-pty-integration-tests.md). Introduces a small typed message handles module so E2E test assertions and production call sites share the exact same string constants — a copy tweak only needs to land in one place.

  • New packages/cli/src/messages.ts — single as const object grouped by area (cli, auth, db). Scope is deliberately narrow: only strings the E2E suite asserts on. No i18n framework, no codegen, no runtime cost.
  • Production call sites migrated in bin/stash.ts, commands/auth/index.ts, commands/auth/login.ts. Strings tests don't touch (command names, the schema-subcommand error, full HELP bodies) stay inline.
  • Tests in tests/e2e/** import the same handles. Stable-phrase + token assertion pattern preserved (e.g. expect(out).toContain(messages.cli.unknownCommand) plus a separate toContain('definitely-not-a-command')).
  • packages/cli/AGENTS.md updated: drops the "phase 2 planned" pointer and documents the rule (add to messages.ts only when a test asserts on the string; don't hard-code wording in tests).

Test plan

  • pnpm --filter @cipherstash/cli build clean
  • pnpm --filter @cipherstash/cli test — 76 unit tests pass
  • pnpm --filter @cipherstash/cli test:e2e — 8 E2E tests pass
  • biome check clean on changed files

Summary by CodeRabbit

  • Chores
    • Refactored CLI message strings for improved maintainability and consistency.

Introduces `packages/cli/src/messages.ts` as a single typed `as const`
object grouping user-facing copy that E2E tests assert on, so a wording
tweak only needs to land in one place and tests stay green
automatically.

- New `messages.ts` covers cli-level (version banner prefix, usage
  prefix, unknown-command), auth (usage prefix, unknown-subcommand,
  region-prompt label, cancellation), and db (unknown-subcommand,
  migrate stub) handles. Scope is intentionally narrow — only strings
  the E2E suite asserts on.
- Migrated production call sites in `bin/stash.ts`, `commands/auth/index.ts`,
  and `commands/auth/login.ts` to reference the constants. Strings tests
  don't touch (e.g. command names, schema-subcommand error, full HELP
  body) stay inline.
- Migrated `tests/e2e/smoke.e2e.test.ts` and
  `tests/e2e/auth-login-cancel.e2e.test.ts` to import the same handles
  the production code uses. Stable phrase + token assertion pattern
  preserved.
- Updated `packages/cli/AGENTS.md`: drops the "phase 2 planned" pointer,
  documents the messages-module rule (extract only what tests assert on,
  add to messages.ts not the test).
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

⚠️ No Changeset found

Latest commit: d257468

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

📝 Walkthrough

Walkthrough

This PR centralizes user-facing CLI message strings into a new messages.ts module, replacing hardcoded literals throughout the codebase. All CLI command files and E2E tests are updated to import and reference these centralized constants, with AGENTS.md updated to document this testing approach.

Changes

Cohort / File(s) Summary
Documentation & Messaging Core
AGENTS.md, src/messages.ts
Documentation updated to reflect new testing pattern; new centralized messages module created with cli, auth, and db message groups defined as immutable constants.
CLI Implementation
src/bin/stash.ts, src/commands/auth/index.ts, src/commands/auth/login.ts
Updated to import and use centralized messages module for help text, usage prefixes, unknown command errors, and UI prompts instead of inline hardcoded strings.
E2E Tests
tests/e2e/auth-login-cancel.e2e.test.ts, tests/e2e/smoke.e2e.test.ts
Updated test assertions to reference messages constants for CLI output instead of hardcoded string literals, with command names retained as inline assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • auxesis

Poem

🐰 Strings once scattered, now unite,
In messages.ts, aligned just right,
Tests assert what users see,
One source of truth sets us free!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 and concisely describes the main change: introducing a messages.ts module to centralize assertion-stable strings for E2E tests and production code.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli-messages-module

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.

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.

Caution

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

⚠️ Outside diff range comments (1)
packages/cli/AGENTS.md (1)

83-84: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove stale “phase-2 messages module” wording.

This now conflicts with the current state (the module is implemented in this PR), so the plan section should reference it as existing, not planned.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/cli/AGENTS.md` around lines 83 - 84, Update the sentence in
AGENTS.md that currently calls the "phase-2 messages module" a future/planned
item so it reflects the module is implemented; locate the phrase "phase-2
messages module" and the linked docs/plans/cli-pty-integration-tests.md
reference and change wording to reference the module as existing (e.g., "and the
phase-2 messages module is documented in
docs/plans/cli-pty-integration-tests.md" or similar), removing any "planned" or
"phase-2" implication that it is not yet implemented.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/cli/AGENTS.md`:
- Around line 83-84: Update the sentence in AGENTS.md that currently calls the
"phase-2 messages module" a future/planned item so it reflects the module is
implemented; locate the phrase "phase-2 messages module" and the linked
docs/plans/cli-pty-integration-tests.md reference and change wording to
reference the module as existing (e.g., "and the phase-2 messages module is
documented in docs/plans/cli-pty-integration-tests.md" or similar), removing any
"planned" or "phase-2" implication that it is not yet implemented.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2db3f6d2-c750-45c9-855d-944a7cb078b6

📥 Commits

Reviewing files that changed from the base of the PR and between cf8ebc2 and d257468.

📒 Files selected for processing (7)
  • packages/cli/AGENTS.md
  • packages/cli/src/bin/stash.ts
  • packages/cli/src/commands/auth/index.ts
  • packages/cli/src/commands/auth/login.ts
  • packages/cli/src/messages.ts
  • packages/cli/tests/e2e/auth-login-cancel.e2e.test.ts
  • packages/cli/tests/e2e/smoke.e2e.test.ts

Copy link
Copy Markdown
Contributor

@auxesis auxesis left a comment

Choose a reason for hiding this comment

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

Smart, thanks for this @coderdan.

@coderdan coderdan merged commit 3d12510 into main Apr 30, 2026
6 checks passed
@coderdan coderdan deleted the cli-messages-module branch April 30, 2026 05:12
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