Skip to content

test: command — hints extraction and altimate builtin registration#431

Closed
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260324-0409
Closed

test: command — hints extraction and altimate builtin registration#431
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260324-0409

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 24, 2026

What does this PR do?

1. Command.hints()src/command/index.ts:53-61 (7 new tests)

This pure function parses template strings to extract placeholder variables ($1, $2, $ARGUMENTS) that determine what argument hints the TUI shows for each command. Zero tests existed. Every command definition relies on this function — if it breaks, users see no argument hints when invoking /commands.

New coverage includes:

  • Sorted numbered placeholder extraction ($1, $2, $3)
  • $ARGUMENTS extraction
  • Mixed numbered + $ARGUMENTS in same template
  • Deduplication of repeated numbered placeholders
  • Empty template and no-placeholder edge cases
  • Non-sequential numbering ($3, $7)

2. Altimate-specific builtin commands — src/command/index.ts (6 new tests)

Three altimate-specific commands (discover-and-add-mcps, configure-claude, configure-codex) were shipped in recent PRs (#409 for discover-and-add-mcps) but had zero registration tests. The TUI toast directs users to run /discover-and-add-mcps — if this command isn't registered properly, users hit "command not found" after being told to run it.

New coverage includes:

  • All 7 default commands are present (previously only 3 were checked)
  • discover-and-add-mcps registration with correct name, source, and description
  • configure-claude registration with correct metadata
  • configure-codex registration with correct metadata
  • discover-and-add-mcps template content pins --scope and mcp_discover references

Type of change

  • New feature (non-breaking change which adds functionality)

Issue for this PR

N/A — proactive test coverage

How did you verify your code works?

bun test test/command/hints.test.ts              # 7 pass
bun test test/command/command-resilience.test.ts  # 6 pass (resilience pattern tests;
                                                  #   withInstance tests require
                                                  #   commit.gpgsign=false in CI)

Note: The command-resilience.test.ts tests that use tmpdir({ git: true }) require commit.gpgsign=false to run in CI environments with mandatory commit signing. This is a pre-existing infrastructure issue affecting all tests in this file, not introduced by this PR.

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

https://claude.ai/code/session_0135nT8sg3re3D2Zgvo6ipc2

Summary by CodeRabbit

  • Tests
    • Enhanced test coverage for command registration and metadata validation, including new command discovery and configuration functionality.
    • Added test suite for placeholder extraction functionality to validate template parsing behavior.

Command.hints() parses template placeholders for TUI argument hints;
zero tests existed. The 3 altimate-specific builtin commands (discover-and-add-mcps,
configure-claude, configure-codex) shipped in recent PRs with no registration tests.

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

https://claude.ai/code/session_0135nT8sg3re3D2Zgvo6ipc2
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

These changes add test coverage for command functionality, including validation of default command registration, metadata properties, and template placeholder extraction logic.

Changes

Cohort / File(s) Summary
Command test coverage
packages/opencode/test/command/command-resilience.test.ts, packages/opencode/test/command/hints.test.ts
Added 57 new assertions to verify default command registration (feedback, configure-claude, configure-codex, discover-and-add-mcps) with metadata validation including name, source, and description. Introduced 32 new test cases validating Command.hints() placeholder extraction, sorted ordering, deduplication, and handling of special $ARGUMENTS placeholder.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

contributor

Poem

🐰 Whiskers twitch with testing glee,
New assertions hop and bound so free,
Commands registered, hints extracted bright,
Placeholders sorted, everything just right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main changes: addition of tests for Command.hints() extraction and altimate builtin command registration.
Description check ✅ Passed The description is comprehensive, covering what changed, why it matters, test coverage details, and verification steps. It follows the template structure with clear sections.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/hourly-20260324-0409

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.

Copy link

@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.

🧹 Nitpick comments (2)
packages/opencode/test/command/command-resilience.test.ts (1)

142-146: Add an explicit existence assertion before dereferencing cmd.template.

Line 145 reads cmd.template directly; adding expect(cmd).toBeDefined() in this test gives a clearer failure mode if registration breaks.

✅ Small robustness tweak
 test("discover-and-add-mcps template references --scope for scope selection", async () => {
   await withInstance(async () => {
     const cmd = await Command.get("discover-and-add-mcps")
+    expect(cmd).toBeDefined()
     const template = await cmd.template
     expect(template).toContain("--scope")
     expect(template).toContain("mcp_discover")
   })
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/command/command-resilience.test.ts` around lines 142 -
146, In the "discover-and-add-mcps template references --scope for scope
selection" test, assert the Command.get result exists before accessing its
template: after obtaining cmd via Command.get("discover-and-add-mcps") add an
existence assertion (e.g., expect(cmd).toBeDefined()) so that dereferencing
cmd.template is protected and yields a clear failure if Command registration
fails; locate the test and insert this assertion before the line that reads
const template = await cmd.template.
packages/opencode/test/command/hints.test.ts (1)

5-7: Add a multi-digit placeholder ordering test to lock expected sort semantics.

Current cases only use single-digit placeholders. Add one case like $10 + $2 so ordering behavior is explicit and protected against regressions.

💡 Proposed test addition
 describe("Command.hints: template placeholder extraction", () => {
@@
   test("handles non-sequential numbering", () => {
     expect(Command.hints("$3 then $7")).toEqual(["$3", "$7"])
   })
+
+  test("handles multi-digit numbered placeholders with numeric order", () => {
+    expect(Command.hints("$10 then $2 then $1")).toEqual(["$1", "$2", "$10"])
+  })
 })

Also applies to: 29-31

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

In `@packages/opencode/test/command/hints.test.ts` around lines 5 - 7, Add a test
to lock down sorting semantics for multi-digit placeholders: in the
hints.test.ts suite add a case that includes both multi-digit and single-digit
placeholders (e.g., call Command.hints("Do $10 then $2 and $1") and assert it
returns ["$1","$2","$10"]) so ordering is numeric rather than lexicographic;
also update the similar test group that mirrors the single-digit case to include
a corresponding multi-digit example to prevent regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/opencode/test/command/command-resilience.test.ts`:
- Around line 142-146: In the "discover-and-add-mcps template references --scope
for scope selection" test, assert the Command.get result exists before accessing
its template: after obtaining cmd via Command.get("discover-and-add-mcps") add
an existence assertion (e.g., expect(cmd).toBeDefined()) so that dereferencing
cmd.template is protected and yields a clear failure if Command registration
fails; locate the test and insert this assertion before the line that reads
const template = await cmd.template.

In `@packages/opencode/test/command/hints.test.ts`:
- Around line 5-7: Add a test to lock down sorting semantics for multi-digit
placeholders: in the hints.test.ts suite add a case that includes both
multi-digit and single-digit placeholders (e.g., call Command.hints("Do $10 then
$2 and $1") and assert it returns ["$1","$2","$10"]) so ordering is numeric
rather than lexicographic; also update the similar test group that mirrors the
single-digit case to include a corresponding multi-digit example to prevent
regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ebfc7a34-a71e-4e7a-af8f-431c199cef45

📥 Commits

Reviewing files that changed from the base of the PR and between 544903f and 658e630.

📒 Files selected for processing (2)
  • packages/opencode/test/command/command-resilience.test.ts
  • packages/opencode/test/command/hints.test.ts

@anandgupta42
Copy link
Contributor Author

Superseded by #439 which consolidates all 12 test PRs into one, deduplicates overlapping tests, and fixes bugs found during review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants