Skip to content

test: command hints + skill formatting coverage#430

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

test: command hints + skill formatting coverage#430
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260324-0306

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 24, 2026

What does this PR do?

Adds 9 new tests across 2 previously untested pure functions that power user-facing UI elements.

1. Command.hints()src/command/index.ts (5 new tests)

This function extracts placeholder tokens ($1, $2, $ARGUMENTS) from command templates and feeds them to the TUI command dialog so users know what arguments to provide. Zero tests existed. New coverage includes:

  • Empty template and no-placeholder cases return empty array
  • Numbered placeholders are extracted and sorted (lexicographic order)
  • Duplicate placeholders are deduplicated via Set
  • $ARGUMENTS is appended independently of numbered placeholders
  • Multi-digit placeholders ($10) sort lexicographically ($1, $10, $2) — documents the actual behavior so future refactors don't assume numeric ordering

2. Skill.fmt()src/skill/skill.ts (4 new tests)

This function formats the skill listing shown in both the TUI skill browser and the system prompt injected into LLM context. Zero tests existed. New coverage includes:

  • Empty skill list returns "No skills are currently available." for both modes
  • Verbose mode produces correct XML structure with <available_skills>, <skill>, <name>, <description>, <location> tags
  • Non-verbose mode produces markdown with ## Available Skills header and **name**: description bullets
  • builtin: protocol locations are preserved as-is (no file:// conversion) — this is an altimate-specific change that protects embedded skill paths from being mangled by pathToFileURL()

Type of change

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

Issue for this PR

N/A — proactive test coverage from test-discovery rotation (Week 1: skills + tools)

How did you verify your code works?

bun test test/command/hints.test.ts    # 5 pass, 6 expect() calls
bun test test/skill/fmt.test.ts        # 4 pass, 14 expect() calls

Test quality review

Tests were reviewed by a critic agent before committing:

  • Approved (9): All tests exercise distinct code paths with real user-facing risk
  • Rejected (2): "Returns both numbered and $ARGUMENTS together" (composition of two other tests, no new path) and "Multiple skills are all listed" (no new branch vs. single-skill tests)
  • Revised/Skipped (2): Skill.available() permission filtering was too integration-heavy for a unit test run and delegates to already-tested PermissionNext.evaluate()

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_011MEvdFUnKtEEi18HBQcJz5

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for command hints functionality to validate placeholder extraction and handling.
    • Added test suites for skill formatting output across different display modes and configurations.

…rendering

Command.hints() and Skill.fmt() are user-facing pure functions with zero test
coverage. These 9 tests prevent regressions in command argument hint extraction
and skill listing output (both verbose XML and markdown formats).

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

https://claude.ai/code/session_011MEvdFUnKtEEi18HBQcJz5
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

Two new test suites were added: one for Command.hints validating template placeholder extraction with deduplication and proper ordering semantics, and another for Skill.fmt verifying skill list formatting across verbose and non-verbose modes with XML and markdown output.

Changes

Cohort / File(s) Summary
Test Suites
packages/opencode/test/command/hints.test.ts, packages/opencode/test/skill/fmt.test.ts
Added test coverage for Command.hints placeholder extraction and deduplication behavior, and Skill.fmt output formatting in both verbose and non-verbose modes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

contributor

Poem

🐰 Whiskers twitching with delight,
New tests are shining, clear and bright!
Hints extracted, skills displayed,
Quality checked in the format made!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding test coverage for command hints and skill formatting.
Description check ✅ Passed The description is comprehensive and well-structured, covering what changed, how it was tested, and including a detailed checklist.
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-0306

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/opencode/test/skill/fmt.test.ts (1)

19-33: Consider asserting URL conversion for both listed skills.

This test validates conversion for analyze; adding a check for deploy would make the multi-item verbose branch coverage tighter.

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

In `@packages/opencode/test/skill/fmt.test.ts` around lines 19 - 33, The test
currently asserts that Skill.fmt converts the analyze skill location to a
file:// URL but misses asserting the same for the deploy entry; update the test
that calls Skill.fmt(skills, { verbose: true }) to also assert that the output
contains "file:///path/to/deploy/SKILL.md" so both skills’ paths are validated;
locate the test block in packages/opencode/test/skill/fmt.test.ts (the test
named "verbose mode returns XML with skill tags") and add an
expect(output).toContain for the deploy file URL next to the existing analyze
URL assertion.
🤖 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/hints.test.ts`:
- Around line 18-20: Add a test to verify that Command.hints correctly extracts
numbered placeholders along with the $ARGUMENTS token in the same template:
update the test suite in hints.test.ts to include a case calling Command.hints
with a string containing mixed numbered placeholders and $ARGUMENTS (e.g., "$1
$2 $ARGUMENTS" or mixed-case variants) and assert the returned array preserves
the expected ordering/append contract (contains "$1", "$2", and "$ARGUMENTS" in
the correct order). This ensures Command.hints handles combined placeholders and
the special $ARGUMENTS token together.

---

Nitpick comments:
In `@packages/opencode/test/skill/fmt.test.ts`:
- Around line 19-33: The test currently asserts that Skill.fmt converts the
analyze skill location to a file:// URL but misses asserting the same for the
deploy entry; update the test that calls Skill.fmt(skills, { verbose: true }) to
also assert that the output contains "file:///path/to/deploy/SKILL.md" so both
skills’ paths are validated; locate the test block in
packages/opencode/test/skill/fmt.test.ts (the test named "verbose mode returns
XML with skill tags") and add an expect(output).toContain for the deploy file
URL next to the existing analyze URL assertion.
🪄 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: 67d9eb11-bbc5-470a-b3b6-b43819c5d92b

📥 Commits

Reviewing files that changed from the base of the PR and between 966f43c and bb13e28.

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

Comment on lines +18 to +20
test("appends $ARGUMENTS when present", () => {
expect(Command.hints("Do something with $ARGUMENTS")).toEqual(["$ARGUMENTS"])
})
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Add a mixed-case assertion for numbered placeholders + $ARGUMENTS.

Line 18 currently verifies $ARGUMENTS alone, but it does not assert combined behavior in the same template (e.g., $1, $2, and $ARGUMENTS together), which is the higher-value ordering/append contract.

Suggested test addition
   test("appends $ARGUMENTS when present", () => {
     expect(Command.hints("Do something with $ARGUMENTS")).toEqual(["$ARGUMENTS"])
+    expect(Command.hints("Use $2 with $ARGUMENTS and $1")).toEqual(["$1", "$2", "$ARGUMENTS"])
   })
📝 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
test("appends $ARGUMENTS when present", () => {
expect(Command.hints("Do something with $ARGUMENTS")).toEqual(["$ARGUMENTS"])
})
test("appends $ARGUMENTS when present", () => {
expect(Command.hints("Do something with $ARGUMENTS")).toEqual(["$ARGUMENTS"])
expect(Command.hints("Use $2 with $ARGUMENTS and $1")).toEqual(["$1", "$2", "$ARGUMENTS"])
})
🤖 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 18 - 20, Add a
test to verify that Command.hints correctly extracts numbered placeholders along
with the $ARGUMENTS token in the same template: update the test suite in
hints.test.ts to include a case calling Command.hints with a string containing
mixed numbered placeholders and $ARGUMENTS (e.g., "$1 $2 $ARGUMENTS" or
mixed-case variants) and assert the returned array preserves the expected
ordering/append contract (contains "$1", "$2", and "$ARGUMENTS" in the correct
order). This ensures Command.hints handles combined placeholders and the special
$ARGUMENTS token together.

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

@anandgupta42 anandgupta42 deleted the test/hourly-20260324-0306 branch March 25, 2026 02:14
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