Skip to content

test: command hints + sql_analyze tool coverage#437

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

test: command hints + sql_analyze tool coverage#437
anandgupta42 wants to merge 1 commit intomainfrom
test/hourly-20260324-0713

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 24, 2026

What does this PR do?

Adds 14 new tests across two previously untested modules, discovered via automated test-discovery reconnaissance.

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

This pure function parses $1, $2, $ARGUMENTS placeholders from command templates to generate TUI argument hints for slash commands. Zero tests existed. If broken, users invoking /review, /discover, or custom commands would see wrong or missing argument hints. New coverage includes:

  • Extraction of numbered placeholders in sorted order
  • Deduplication of repeated placeholders (e.g., $1 used twice)
  • $ARGUMENTS ordering (always appended after numbered placeholders)
  • Multi-digit placeholder lexicographic sorting ($1, $10, $2 — documents the actual behavior)
  • Empty template and no-placeholder edge cases

2. SqlAnalyzeTool.executesrc/altimate/tools/sql-analyze.ts (6 new tests)

The recent bug fix AI-5975 changed sql_analyze to report success: true when analysis completes (even when lint/semantic/safety issues are found). Previously, finding issues set success: false, causing ~4,000 false "unknown error" telemetry events per day. These regression tests lock down the corrected semantics:

  • Issues found → success: true, no error in metadata
  • Zero issues → success: true, "No anti-patterns" output
  • Parse error → success: false, error surfaced in metadata and title
  • Dispatcher crash → catch block returns "ERROR" title with error message
  • Singular/plural formatting ("1 issue" vs "2 issues")
  • Issue location, confidence annotation, and confidence factors in output

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                        # 8 pass
bun test test/altimate/tools/sql-analyze-tool.test.ts      # 6 pass

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_01VV8nsL7MbNaJtwMDKQBzdz

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suites for SQL analysis tool execution, covering success/error scenarios and output formatting.
    • Added test suite for command placeholder parsing and ordering functionality.

…ess semantics

Add 14 tests covering two untested modules:
- Command.hints() template placeholder extraction
- SqlAnalyzeTool.execute success flag and formatAnalysis output

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

https://claude.ai/code/session_01VV8nsL7MbNaJtwMDKQBzdz
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 Bun test suites are added: one for SqlAnalyzeTool.execute covering success-flag semantics, error handling, and output formatting across four scenarios, and another for Command.hints testing placeholder parsing, deduplication, and ordering behavior.

Changes

Cohort / File(s) Summary
SQL Analysis Tool Tests
packages/opencode/test/altimate/tools/sql-analyze-tool.test.ts
Tests SqlAnalyzeTool.execute with four scenarios: success with issues, success with no issues, parse errors, and dispatcher failures. Validates metadata structure (success flag, error field) and output formatting (issue counts, severity markers, confidence levels).
Command Hints Tests
packages/opencode/test/command/hints.test.ts
Tests Command.hints placeholder extraction and ordering: numbered placeholder ordering ($1, $2, etc.), multi-digit cases ($10), $ARGUMENTS inclusion, and empty/no-placeholder edge cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Hops through tests with mighty cheer,
Success flags clear, no errors here!
Placeholders parsed, in order true,
Analyze, hint—our tests shine through!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly and clearly summarizes the main change: adding test coverage for two specific modules (command hints and sql_analyze tool).
Description check ✅ Passed The PR description comprehensively covers the required template sections: Summary explains what changed and why (14 new tests across two modules with specific details), Test Plan demonstrates verification with explicit test commands and pass counts, and Checklist confirms tests added and existing tests pass.
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-0713

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/command/hints.test.ts (1)

5-38: Consider table-driven tests to reduce repetition and ease future additions.

Current tests are clear; this is a maintainability-only refinement.

♻️ Optional refactor (table-driven style)
 describe("Command.hints: template placeholder parsing", () => {
-  test("extracts numbered placeholders in order", () => {
-    expect(Command.hints("run $1 with $2")).toEqual(["$1", "$2"])
-  })
-
-  test("deduplicates repeated placeholders", () => {
-    expect(Command.hints("compare $1 to $1")).toEqual(["$1"])
-  })
-
-  test("sorts numbered placeholders lexicographically", () => {
-    // String sort: "$1" < "$2" < "$3"
-    expect(Command.hints("$3 then $1 then $2")).toEqual(["$1", "$2", "$3"])
-  })
-
-  test("$ARGUMENTS appears after numbered placeholders", () => {
-    expect(Command.hints("do $1 $ARGUMENTS")).toEqual(["$1", "$ARGUMENTS"])
-  })
-
-  test("returns only $ARGUMENTS when no numbered placeholders", () => {
-    expect(Command.hints("run $ARGUMENTS")).toEqual(["$ARGUMENTS"])
-  })
-
-  test("returns empty array when no placeholders", () => {
-    expect(Command.hints("static template with no args")).toEqual([])
-  })
-
-  test("multi-digit placeholders sort lexicographically, not numerically", () => {
-    // String sort puts "$10" before "$2" — this is the actual behavior.
-    // If a template uses $10+, the TUI hint order will be $1, $10, $2.
-    expect(Command.hints("$10 $2 $1")).toEqual(["$1", "$10", "$2"])
-  })
-
-  test("empty template returns empty array", () => {
-    expect(Command.hints("")).toEqual([])
-  })
+  const cases: Array<{ name: string; template: string; expected: string[] }> = [
+    { name: "extracts numbered placeholders in order", template: "run $1 with $2", expected: ["$1", "$2"] },
+    { name: "deduplicates repeated placeholders", template: "compare $1 to $1", expected: ["$1"] },
+    { name: "sorts numbered placeholders lexicographically", template: "$3 then $1 then $2", expected: ["$1", "$2", "$3"] },
+    { name: "$ARGUMENTS appears after numbered placeholders", template: "do $1 $ARGUMENTS", expected: ["$1", "$ARGUMENTS"] },
+    { name: "returns only $ARGUMENTS when no numbered placeholders", template: "run $ARGUMENTS", expected: ["$ARGUMENTS"] },
+    { name: "returns empty array when no placeholders", template: "static template with no args", expected: [] },
+    { name: "multi-digit placeholders sort lexicographically, not numerically", template: "$10 $2 $1", expected: ["$1", "$10", "$2"] },
+    { name: "empty template returns empty array", template: "", expected: [] },
+  ]
+
+  for (const c of cases) {
+    test(c.name, () => {
+      expect(Command.hints(c.template)).toEqual(c.expected)
+    })
+  }
 })
🤖 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 - 38, Convert
the repetitive spec blocks into a table-driven test: create an array of test
cases each with a descriptive name, an input template string, and the expected
hints array, then iterate (using test.each or cases.forEach with test) to assert
Command.hints(input) equals expected; update the existing tests in hints.test.ts
to replace the individual test(...) calls with this single data-driven loop
while preserving all original scenarios (including multi-digit, $ARGUMENTS
ordering, empty template, and no-placeholder cases).
🤖 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/tools/sql-analyze-tool.test.ts`:
- Around line 13-15: Change the test setup/teardown to preserve any pre-existing
ALTIMATE_TELEMETRY_DISABLED value: in the beforeEach that sets
process.env.ALTIMATE_TELEMETRY_DISABLED = "true", capture the original value
into a module-scoped variable (e.g., origTelemetryDisabled) and then set the env
var; in the corresponding afterEach (and the similar teardown at the second
location around lines 35-38) restore process.env.ALTIMATE_TELEMETRY_DISABLED to
origTelemetryDisabled if it is defined, otherwise delete it, rather than always
deleting it unconditionally.

---

Nitpick comments:
In `@packages/opencode/test/command/hints.test.ts`:
- Around line 5-38: Convert the repetitive spec blocks into a table-driven test:
create an array of test cases each with a descriptive name, an input template
string, and the expected hints array, then iterate (using test.each or
cases.forEach with test) to assert Command.hints(input) equals expected; update
the existing tests in hints.test.ts to replace the individual test(...) calls
with this single data-driven loop while preserving all original scenarios
(including multi-digit, $ARGUMENTS ordering, empty template, and no-placeholder
cases).
🪄 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: 99d66d13-c0d4-405a-8e8b-9067b56d7ba9

📥 Commits

Reviewing files that changed from the base of the PR and between 544903f and 02a82a3.

📒 Files selected for processing (2)
  • packages/opencode/test/altimate/tools/sql-analyze-tool.test.ts
  • packages/opencode/test/command/hints.test.ts

Comment on lines +13 to +15
beforeEach(() => {
process.env.ALTIMATE_TELEMETRY_DISABLED = "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

Preserve the original telemetry env value during teardown

Cleanup currently always deletes ALTIMATE_TELEMETRY_DISABLED, which can clobber a pre-existing test-runner/CI setting. Capture the original value and restore it in teardown instead of unconditional delete.

Suggested patch
+const originalTelemetryDisabled = process.env.ALTIMATE_TELEMETRY_DISABLED
+
 beforeEach(() => {
   process.env.ALTIMATE_TELEMETRY_DISABLED = "true"
 })
@@
 afterAll(() => {
   dispatcherSpy?.mockRestore()
-  delete process.env.ALTIMATE_TELEMETRY_DISABLED
+  if (originalTelemetryDisabled === undefined) {
+    delete process.env.ALTIMATE_TELEMETRY_DISABLED
+  } else {
+    process.env.ALTIMATE_TELEMETRY_DISABLED = originalTelemetryDisabled
+  }
 })

Also applies to: 35-38

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

In `@packages/opencode/test/altimate/tools/sql-analyze-tool.test.ts` around lines
13 - 15, Change the test setup/teardown to preserve any pre-existing
ALTIMATE_TELEMETRY_DISABLED value: in the beforeEach that sets
process.env.ALTIMATE_TELEMETRY_DISABLED = "true", capture the original value
into a module-scoped variable (e.g., origTelemetryDisabled) and then set the env
var; in the corresponding afterEach (and the similar teardown at the second
location around lines 35-38) restore process.env.ALTIMATE_TELEMETRY_DISABLED to
origTelemetryDisabled if it is defined, otherwise delete it, rather than always
deleting it unconditionally.

@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