test: command hints + sql_analyze tool coverage#437
test: command hints + sql_analyze tool coverage#437anandgupta42 wants to merge 1 commit intomainfrom
Conversation
…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
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 are added: one for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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
🧹 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
📒 Files selected for processing (2)
packages/opencode/test/altimate/tools/sql-analyze-tool.test.tspackages/opencode/test/command/hints.test.ts
| beforeEach(() => { | ||
| process.env.ALTIMATE_TELEMETRY_DISABLED = "true" | ||
| }) |
There was a problem hiding this comment.
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.
|
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?
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,$ARGUMENTSplaceholders 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:$1used twice)$ARGUMENTSordering (always appended after numbered placeholders)$1, $10, $2— documents the actual behavior)2.
SqlAnalyzeTool.execute—src/altimate/tools/sql-analyze.ts(6 new tests)The recent bug fix AI-5975 changed
sql_analyzeto reportsuccess: truewhen analysis completes (even when lint/semantic/safety issues are found). Previously, finding issues setsuccess: false, causing ~4,000 false "unknown error" telemetry events per day. These regression tests lock down the corrected semantics:success: true, noerrorin metadatasuccess: true, "No anti-patterns" outputsuccess: false, error surfaced in metadata and title"1 issue"vs"2 issues")Type of change
Issue for this PR
N/A — proactive test coverage
How did you verify your code works?
Checklist
https://claude.ai/code/session_01VV8nsL7MbNaJtwMDKQBzdz
Summary by CodeRabbit