Skip to content

test: command hints, discover-and-add-mcps, sql.analyze success semantics#440

Open
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260324-1500
Open

test: command hints, discover-and-add-mcps, sql.analyze success semantics#440
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260324-1500

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 24, 2026

Summary

What does this PR do?

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

This pure function extracts $1, $2, $ARGUMENTS placeholders from command templates and is used by the TUI to display argument hints. Zero tests existed. New coverage includes:

  • Lexicographic sort ordering (documents that $10 sorts before $2 — the actual contract)
  • $ARGUMENTS extraction, combined numbered + $ARGUMENTS extraction
  • Deduplication of repeated placeholders
  • Empty template edge case
  • $0 as a valid placeholder

2. discover-and-add-mcps builtin command — src/command/index.ts (5 new tests)

PR #409 shipped this as a builtin command (previously only existed as a project-level .opencode/command/ file). Zero tests verified it was registered. New coverage includes:

  • Command.Default.DISCOVER_MCPS constant is set
  • Command appears in Command.list() and Command.get()
  • Correct metadata (name, source, description mentions MCP)
  • Template references mcp_discover tool
  • Not marked as a subtask

3. sql.analyze Dispatcher method — src/altimate/native/sql/register.ts (5 new tests)

The AI-5975 fix changed success semantics: finding lint/semantic/safety issues IS a successful analysis (success: true). Previously it returned success: false when issues were found, causing ~4,000 false "unknown error" telemetry entries per day. New coverage includes:

  • Regression guard: query with lint issues still returns success: true
  • issue_count matches issues array length (with non-vacuous guard)
  • Lint issues have all required fields (severity, message, recommendation, confidence)
  • Issue types are constrained to lint, semantic, safety
  • Result shape validation

Infrastructure fix: Added git config commit.gpgsign false to test/fixture/fixture.ts tmpdir helper to prevent git signing failures in CI/Codespace environments.

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-discover-mcps.test.ts   # 11 pass
bun test test/altimate/sql-analyze-format.test.ts   #  5 pass
bun test test/command/                              # 46 pass (all existing + new)

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_01BUHCukhUhWNtR82r8iedHG

Summary by CodeRabbit

Release Notes

  • Tests
    • Added comprehensive validation tests for SQL analysis output format, ensuring proper issue reporting and confidence levels.
    • Added tests for command hints discovery and MCP integration functionality.
    • Improved test infrastructure for Git-backed environments.

…tics

Guard against AI-5975 regression (sql.analyze success:false on issues) and
verify the new discover-and-add-mcps builtin command (#409) is registered.

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

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

Three new test files have been added to validate SQL analyzer output shapes via Dispatcher.call("sql.analyze", ...), command hint extraction and ordering, and the built-in MCP discovery command. A fixture modification disables Git GPG signing for temporary test repositories.

Changes

Cohort / File(s) Summary
SQL Analyzer Tests
packages/opencode/test/altimate/sql-analyze-format.test.ts
Validates Dispatcher.call("sql.analyze", ...) returns success: true, non-zero issue_count for lint violations, and lint issues include required fields (severity, message, recommendation as string, confidence as "high"). Asserts issue_count matches issues.length, issue type is one of lint, semantic, or safety, and response includes top-level properties (success, issues, issue_count, confidence, confidence_factors).
Command Hints & MCP Discovery Tests
packages/opencode/test/command/hints-discover-mcps.test.ts
Tests Command.hints() placeholder extraction/ordering (lexicographic sorting, $ARGUMENTS combination, deduplication, handling $0). Validates built-in discover-and-add-mcps command matches Command.Default.DISCOVER_MCPS, appears in Command.list(), has expected metadata, includes mcp_discover tool, and subtask is undefined. Uses withInstance helper with git-backed temporary Instance.
Test Fixture Configuration
packages/opencode/test/fixture/fixture.ts
Disables Git GPG signing (git config commit.gpgsign false) when options.git is enabled in temporary test repositories.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • #426: Directly tests the same sql.analyze dispatcher success/metadata behavior and registration.
  • #352: Overlapping test coverage for sql.analyze and altimate_core_validate dispatcher behavior.

Suggested labels

contributor

Poem

🐰 Whiskers twitch with testing glee,
SQL shapes now verified with precision fine,
Commands hint and MCPs align,
Git signs off (no GPG keys, you see!)—
Quality hops through the test design! 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the three main additions: Command.hints() tests, discover-and-add-mcps tests, and sql.analyze success semantics tests.
Description check ✅ Passed The description comprehensively covers all required sections: detailed summary explaining what changed and why, explicit test plan with passing test results, and completed checklist confirming tests were added and verified.

✏️ 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-1500

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

🤖 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/altimate/sql-analyze-format.test.ts`:
- Around line 72-83: The test "successful result has all required properties"
currently only checks the shape of SqlAnalyzeResult returned by
Dispatcher.call("sql.analyze") but doesn't assert the success path; update the
test to explicitly assert that result.success is true (e.g.,
expect(result.success).toBe(true)) after the call so the test actually enforces
a successful result rather than merely the response shape; keep the existing
shape checks for result.issues and result.confidence_factors.
🪄 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: 0f53220e-b69c-4a7f-8f1b-a9f6127aa113

📥 Commits

Reviewing files that changed from the base of the PR and between 544903f and 23bd8fc.

📒 Files selected for processing (3)
  • packages/opencode/test/altimate/sql-analyze-format.test.ts
  • packages/opencode/test/command/hints-discover-mcps.test.ts
  • packages/opencode/test/fixture/fixture.ts

Comment on lines +72 to +83
test("successful result has all required properties", async () => {
const result = await Dispatcher.call("sql.analyze", {
sql: "SELECT 1 LIMIT 1",
}) as SqlAnalyzeResult
expect(result).toHaveProperty("success")
expect(result).toHaveProperty("issues")
expect(result).toHaveProperty("issue_count")
expect(result).toHaveProperty("confidence")
expect(result).toHaveProperty("confidence_factors")
expect(Array.isArray(result.issues)).toBe(true)
expect(Array.isArray(result.confidence_factors)).toBe(true)
})
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

Assert success-path explicitly in the “successful result” test.

The current assertions validate shape only; the failure path also has the same top-level shape. Add an explicit success assertion so this test enforces what its name promises.

✅ Suggested patch
   test("successful result has all required properties", async () => {
     const result = await Dispatcher.call("sql.analyze", {
       sql: "SELECT 1 LIMIT 1",
     }) as SqlAnalyzeResult
+    expect(result.success).toBe(true)
+    expect(result.error).toBeUndefined()
     expect(result).toHaveProperty("success")
     expect(result).toHaveProperty("issues")
     expect(result).toHaveProperty("issue_count")
     expect(result).toHaveProperty("confidence")
     expect(result).toHaveProperty("confidence_factors")
     expect(Array.isArray(result.issues)).toBe(true)
     expect(Array.isArray(result.confidence_factors)).toBe(true)
   })
📝 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("successful result has all required properties", async () => {
const result = await Dispatcher.call("sql.analyze", {
sql: "SELECT 1 LIMIT 1",
}) as SqlAnalyzeResult
expect(result).toHaveProperty("success")
expect(result).toHaveProperty("issues")
expect(result).toHaveProperty("issue_count")
expect(result).toHaveProperty("confidence")
expect(result).toHaveProperty("confidence_factors")
expect(Array.isArray(result.issues)).toBe(true)
expect(Array.isArray(result.confidence_factors)).toBe(true)
})
test("successful result has all required properties", async () => {
const result = await Dispatcher.call("sql.analyze", {
sql: "SELECT 1 LIMIT 1",
}) as SqlAnalyzeResult
expect(result.success).toBe(true)
expect(result.error).toBeUndefined()
expect(result).toHaveProperty("success")
expect(result).toHaveProperty("issues")
expect(result).toHaveProperty("issue_count")
expect(result).toHaveProperty("confidence")
expect(result).toHaveProperty("confidence_factors")
expect(Array.isArray(result.issues)).toBe(true)
expect(Array.isArray(result.confidence_factors)).toBe(true)
})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/opencode/test/altimate/sql-analyze-format.test.ts` around lines 72 -
83, The test "successful result has all required properties" currently only
checks the shape of SqlAnalyzeResult returned by Dispatcher.call("sql.analyze")
but doesn't assert the success path; update the test to explicitly assert that
result.success is true (e.g., expect(result.success).toBe(true)) after the call
so the test actually enforces a successful result rather than merely the
response shape; keep the existing shape checks for result.issues and
result.confidence_factors.

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