Skip to content

test(ai): cover composer slash commands - #1067

Open
mydd7 wants to merge 1 commit into
crynta:mainfrom
mydd7:test/coverage-12
Open

test(ai): cover composer slash commands#1067
mydd7 wants to merge 1 commit into
crynta:mainfrom
mydd7:test/coverage-12

Conversation

@mydd7

@mydd7 mydd7 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

Adds unit tests for the composer slash-command helpers in
ai/lib/slashCommands.ts. Test-only.

Why

wrapWithCommandMarker, TERAX_CMD_RE and tryRunSlashCommand drive the
composer's / and #handle commands but had no tests.

How

Pure logic tested directly; the plan store is mocked so the /plan branch can be
exercised without touching global state.

Locked behavior:

  • wrapWithCommandMarker / TERAX_CMD_RE: the marker wrap and its round-trip
    through the regex, including the optional state attribute.
  • tryRunSlashCommand: none for plain text, /init and /claude-code
    expansion (with the usage message when no request follows), acceptance of a
    known # command, rejection of an unknown one, and /plan off vs a bare
    /plan toggle.

Testing

Ran the full suite plus type-check and lint locally on Windows.

  • pnpm lint clean (unchanged: 103 pre-existing warnings, none introduced)
  • pnpm check-types clean
  • pnpm test clean (the new suite passes; see reviewer note on one
    pre-existing suite)
  • Manual smoke-test of the affected feature - N/A, test-only, no runtime change
  • (If you touched src-tauri/) cargo clippy - N/A, no Rust changes
  • (If you touched src-tauri/) cargo nextest - N/A, no Rust changes
  • (If you changed a #[tauri::command] signature) - N/A
  • (If UI) tested in pnpm tauri dev - N/A, no UI change
  • Platforms tested: Windows
  • Shells tested (if relevant): N/A

Screenshots / GIFs

N/A - no UI change.

Notes for reviewer

  • Test-only. No public API, behavior, dependency, or config change.
  • Branched a couple of commits behind current main on purpose (my token lacks
    the workflow scope). Only adds a new file; should merge cleanly.
  • Same unrelated pre-existing failure noted before: src/app/eager-budget.test.ts
    fails locally under Windows with git core.autocrlf=true; the committed blob is
    LF and it passes on CI.

Summary by CodeRabbit

  • Tests
    • Added coverage for slash command handling, including /init, /claude-code, /plan, and #init.
    • Verified command markers are generated and parsed correctly, including optional state information.
    • Confirmed appropriate responses for invalid, unknown, and incomplete commands.

wrapWithCommandMarker, TERAX_CMD_RE and tryRunSlashCommand drive the composer's slash and #handle commands but had no tests. Lock the marker wrap and its round-trip through the regex including the optional state attribute, the none outcome for plain text, /init and /claude-code expansion (with the usage message when no request is given), acceptance of a known # command, rejection of an unknown one, and /plan off vs bare /plan toggling.
@mydd7
mydd7 requested a review from crynta as a code owner July 28, 2026 22:04
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Vitest coverage for slash command marker generation and command handling, including init, Claude Code, hash commands, and plan mode toggling.

Changes

Slash command test coverage

Layer / File(s) Summary
Command behavior validation
src/modules/ai/lib/slashCommands.test.ts
Mocks planStore and verifies marker parsing, command expansion, usage toasts, unknown command handling, and plan mode enable/disable actions.

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

🚥 Pre-merge checks | ✅ 4
✅ 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 follows Conventional Commits and accurately summarizes the test coverage for AI slash commands.
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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modules/ai/lib/slashCommands.test.ts`:
- Line 9: Update the imports in slashCommands.test.ts, including the planStore
mock and the imports on lines 19–23, to use the frontend `@/` alias instead of
relative module paths. Preserve the existing imported modules and test behavior.
- Around line 90-94: Update the `/plan` toggle test around `planMock.active`,
`planMock.toggle`, and `tryRunSlashCommand` to start with plan mode inactive and
mock `toggle` so it changes `active` to true. Keep the existing handled result
and toggle-call assertions, ensuring the test verifies the command performs the
transition rather than merely reading a preloaded post-toggle state.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ef5faeb-3394-4473-b469-a6cd05476f7d

📥 Commits

Reviewing files that changed from the base of the PR and between 2141d16 and 7fca143.

📒 Files selected for processing (1)
  • src/modules/ai/lib/slashCommands.test.ts

toggle: vi.fn(),
}));

vi.mock("../store/planStore", () => ({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the frontend import alias.

These relative imports violate the frontend import rule.

Proposed fix
-vi.mock("../store/planStore", () => ({
+vi.mock("`@/modules/ai/store/planStore`", () => ({
@@
-} from "./slashCommands";
+} from "`@/modules/ai/lib/slashCommands`";

As per coding guidelines, “Frontend imports must use the @/... alias and must not use relative imports across modules.”

Also applies to: 19-23

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modules/ai/lib/slashCommands.test.ts` at line 9, Update the imports in
slashCommands.test.ts, including the planStore mock and the imports on lines
19–23, to use the frontend `@/` alias instead of relative module paths. Preserve
the existing imported modules and test behavior.

Source: Coding guidelines

Comment on lines +90 to +94
it("toggles plan mode with a bare /plan", () => {
planMock.active = true; // reflects the state after toggle()
const out = tryRunSlashCommand("/plan");
expect(out).toEqual({ kind: "handled", toast: "Plan mode on" });
expect(planMock.toggle).toHaveBeenCalled();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Model the /plan state transition in the toggle test.

toggle is a no-op mock, while Line 91 preloads its expected post-toggle value. This passes even if the command reads state before toggling. Start inactive and make this test's toggle mock activate the state.

Proposed fix
-    planMock.active = true; // reflects the state after toggle()
+    planMock.toggle.mockImplementationOnce(() => {
+      planMock.active = true;
+    });

As per coding guidelines, “Changes to ... AI tool surfaces must include a test locking the relevant invariant.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("toggles plan mode with a bare /plan", () => {
planMock.active = true; // reflects the state after toggle()
const out = tryRunSlashCommand("/plan");
expect(out).toEqual({ kind: "handled", toast: "Plan mode on" });
expect(planMock.toggle).toHaveBeenCalled();
it("toggles plan mode with a bare /plan", () => {
planMock.toggle.mockImplementationOnce(() => {
planMock.active = true;
});
const out = tryRunSlashCommand("/plan");
expect(out).toEqual({ kind: "handled", toast: "Plan mode on" });
expect(planMock.toggle).toHaveBeenCalled();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modules/ai/lib/slashCommands.test.ts` around lines 90 - 94, Update the
`/plan` toggle test around `planMock.active`, `planMock.toggle`, and
`tryRunSlashCommand` to start with plan mode inactive and mock `toggle` so it
changes `active` to true. Keep the existing handled result and toggle-call
assertions, ensuring the test verifies the command performs the transition
rather than merely reading a preloaded post-toggle state.

Source: Coding guidelines

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