test: command — hints parsing and altimate builtin completeness#425
test: command — hints parsing and altimate builtin completeness#425anandgupta42 wants to merge 1 commit intomainfrom
Conversation
Guard against regressions in Command.hints() template placeholder extraction (used by every command for TUI argument hints) and ensure all altimate-specific builtin commands (configure-claude, configure-codex, discover-and-add-mcps) are registered — the latter would have caught the regression fixed in 528af75. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_018jF7cHcSoARmZRt6Wb7m9o
There was a problem hiding this comment.
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.
📝 WalkthroughWalkthroughTwo new Bun test suites added to validate Altimate command registration and Command.hints placeholder extraction behavior. Tests verify command metadata, template properties, and hint deduplication logic. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/opencode/test/command/altimate-commands.test.ts`:
- Around line 32-43: The test unnecessarily awaits cmd.template even though
default commands like "discover-and-add-mcps" return a plain string; update the
test in altimate-commands.test.ts to stop awaiting cmd.template (e.g., use const
template = cmd.template) so it asserts the synchronous template directly, or
alternatively normalize both sync/async by using Promise.resolve(cmd.template)
before assertions; refer to Command.get and the cmd.template property to locate
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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b0bffafc-1576-410d-8344-f5392c8b0b6c
📒 Files selected for processing (2)
packages/opencode/test/command/altimate-commands.test.tspackages/opencode/test/command/hints.test.ts
| test("discover-and-add-mcps has correct metadata and template", async () => { | ||
| await withInstance(async () => { | ||
| const cmd = await Command.get("discover-and-add-mcps") | ||
| expect(cmd).toBeDefined() | ||
| expect(cmd.name).toBe("discover-and-add-mcps") | ||
| expect(cmd.source).toBe("command") | ||
| expect(cmd.description).toBe("discover MCP servers from external AI tool configs and add them") | ||
| const template = await cmd.template | ||
| expect(template).toContain("mcp_discover") | ||
| expect(cmd.hints).toContain("$ARGUMENTS") | ||
| }) | ||
| }) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check how the template property is defined in Command
ast-grep --pattern $'template: $_'
# Also check the Command interface/type definition
rg -n -A5 'interface.*Command|type.*Command.*=' --type=ts | head -50Repository: AltimateAI/altimate-code
Length of output: 3377
🏁 Script executed:
#!/bin/bash
# Get the full Command schema definition from config.ts
rg -n -B5 -A20 'export const Command = z' packages/opencode/src/config/config.ts
# Also check if there's a Command class with template getter
rg -n -A15 'class Command|interface Command' packages/opencode/src --type=tsRepository: AltimateAI/altimate-code
Length of output: 931
🏁 Script executed:
#!/bin/bash
# Find Command.get() implementation
rg -n -A15 'static.*get.*discover-and-add-mcps|\.get\s*\(\s*name' packages/opencode/src --type=ts | head -60
# Search for Command class with get method
rg -n 'class Command|export.*Command.*get' packages/opencode/src --type=ts -B2 -A10 | head -80Repository: AltimateAI/altimate-code
Length of output: 4271
🏁 Script executed:
#!/bin/bash
# Search for Command class in opencode package
fd -t f "\.ts$" packages/opencode/src | xargs grep -l "class Command" | head -10
# Search for exports that look like Command.get
rg -n "export.*Command.*|Command\.get" packages/opencode/src --type=ts | grep -v "CommandInput\|CommandOption\|CommandData" | head -40Repository: AltimateAI/altimate-code
Length of output: 3471
🏁 Script executed:
#!/bin/bash
# Look for Command class in prompt.ts and nearby files
rg -n "class Command\|namespace Command" packages/opencode/src/session/prompt.ts -B5 -A20
# Also search in the same directory
rg -n "class Command" packages/opencode/src/session --type=ts -B2 -A15Repository: AltimateAI/altimate-code
Length of output: 50
🏁 Script executed:
#!/bin/bash
# Check imports and context around the Command.get() call in prompt.ts
sed -n '1,50p' packages/opencode/src/session/prompt.ts | head -30
# Check around line 1885
sed -n '1870,1895p' packages/opencode/src/session/prompt.tsRepository: AltimateAI/altimate-code
Length of output: 2506
🏁 Script executed:
#!/bin/bash
# Search for Command namespace/export in prompt.ts
rg -n "export.*Command\|namespace Command" packages/opencode/src/session/prompt.ts -B2 -A30 | head -100Repository: AltimateAI/altimate-code
Length of output: 50
🏁 Script executed:
#!/bin/bash
# Search for Command definition in prompt.ts more broadly
rg -n "Command" packages/opencode/src/session/prompt.ts | head -30
# Also get the file size to understand scope
wc -l packages/opencode/src/session/prompt.tsRepository: AltimateAI/altimate-code
Length of output: 850
🏁 Script executed:
#!/bin/bash
# Find the command module
fd -type f "command.*\.ts" packages/opencode/src | grep -E "^packages/opencode/src/command"
# Also check if it's a directory with index
ls -la packages/opencode/src/command/ 2>/dev/null || echo "Not a directory"Repository: AltimateAI/altimate-code
Length of output: 486
🏁 Script executed:
#!/bin/bash
# Read the command index file
cat -n packages/opencode/src/command/index.ts | head -200Repository: AltimateAI/altimate-code
Length of output: 8339
The await on cmd.template is unnecessary for the default "discover-and-add-mcps" command.
The template property is defined as Promise<string> | string (in packages/opencode/src/command/index.ts:51). Default commands like "discover-and-add-mcps" use a getter that returns a plain string directly (line 139-140), so awaiting it is harmless but redundant. This works because awaiting a non-Promise value simply returns that value. Consider removing the await on line 39 if the intent is to test only default commands, or keep it if you want to support both synchronous and asynchronous command sources (MCP commands return promises).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/opencode/test/command/altimate-commands.test.ts` around lines 32 -
43, The test unnecessarily awaits cmd.template even though default commands like
"discover-and-add-mcps" return a plain string; update the test in
altimate-commands.test.ts to stop awaiting cmd.template (e.g., use const
template = cmd.template) so it asserts the synchronous template directly, or
alternatively normalize both sync/async by using Promise.resolve(cmd.template)
before assertions; refer to Command.get and the cmd.template property to locate
the change.
|
Superseded by #439 which consolidates all 12 test PRs into one, deduplicates overlapping tests, and fixes bugs found during review. |
What does this PR do?
1.
Command.hints()—src/command/index.ts:53-61(7 new tests)This pure function extracts
$1,$2,$ARGUMENTSplaceholders from command templates and powers the TUI argument hint display for every command. Zero tests existed. New coverage includes:$ARGUMENTSextraction (alone and combined with numbered)$Nand$ARGUMENTSare recognised — rejects$OTHER,$FOO, etc.2. Altimate builtin commands completeness —
src/command/index.ts:63-144(5 new tests)The altimate-specific builtin commands (
configure-claude,configure-codex,discover-and-add-mcps,feedback) are registered alongside upstream defaults but had no dedicated test coverage. The recent regression fixed in commit 528af75 — wherediscover-and-add-mcpswasn't shipping as a builtin — would have been caught by these tests. Coverage includes:Command.list()Command.Defaultconstants match expected string valuesdiscover-and-add-mcpsmetadata: name, source, description, template content (mcp_discover), and$ARGUMENTShintconfigure-claudeandconfigure-codexmetadata: name, source, descriptionType of change
Issue for this PR
N/A — proactive test coverage. Regression guard for 528af75.
How did you verify your code works?
Note: The
withInstance-based integration tests fail locally due to a git commit signing configuration in this environment (pre-existing issue affecting alltmpdir({ git: true })tests). They will pass in CI where signing is properly configured.Checklist
https://claude.ai/code/session_018jF7cHcSoARmZRt6Wb7m9o
Summary by CodeRabbit