Skip to content

refactor(webview): use canonical provider identifiers - #1023

Open
WebMad wants to merge 7 commits into
Zoo-Code-Org:mainfrom
WebMad:issue-959-canonical-webview-provider-identifiers
Open

refactor(webview): use canonical provider identifiers#1023
WebMad wants to merge 7 commits into
Zoo-Code-Org:mainfrom
WebMad:issue-959-canonical-webview-provider-identifiers

Conversation

@WebMad

@WebMad WebMad commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • migrate webview provider comparisons and switch branches to providerIdentifiers
  • preserve serialized values, extension-webview message payloads, and SettingsView cached-state behavior
  • keep code-index-only identifiers such as semble and openai-compatible unchanged
  • add focused regression coverage for canonical validation and selected-model dispatch

TDD

  • Red: canonical OpenRouter validation returned no API-key error
  • Green: migrated validation dispatch to the canonical registry
  • Triangulation red: canonical OpenAI selected-model dispatch fell back to the default model
  • Triangulation green: migrated selected-model dispatch and the remaining classified webview comparisons

Verification

  • npx vitest run src/utils/__tests__/validate.spec.ts src/components/ui/hooks/__tests__/useSelectedModel.spec.ts — 76 passed
  • npx vitest run src/components/settings src/components/ui/hooks src/utils — 53 files, 654 passed
  • changed-file ESLint — passed
  • npm run check-types — passed
  • repository pre-commit lint — passed
  • repository pre-push type check — passed

Closes #959.

Summary by CodeRabbit

  • Refactor
    • Improved provider recognition across model selection and configuration validation by using standardized provider identifiers instead of hardcoded provider strings.
    • Added explicit handling for specific providers to ensure consistent model resolution and provider-specific validation behavior.
  • Tests
    • Strengthened model-selection coverage with new parameterized scenarios across multiple provider types.
    • Added additional Anthropic pricing/context assertions and updated test imports to align with the shared provider model catalog.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@WebMad, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f5337e2b-1228-4c81-8c65-f2093dd6d53d

📥 Commits

Reviewing files that changed from the base of the PR and between 3af98ba and f2bda6e.

📒 Files selected for processing (1)
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
📝 Walkthrough

Walkthrough

Webview model selection and configuration validation now use shared providerIdentifiers constants instead of hardcoded provider strings. Shared provider cases are explicit, and tests cover Anthropic, Gemini CLI, Fake AI, and 1M-context model metadata.

Changes

Webview provider identifier migration

Layer / File(s) Summary
Canonical model-selection dispatch
webview-ui/src/components/ui/hooks/useSelectedModel.ts, webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
Provider-specific model resolution uses canonical identifiers, explicitly handles shared providers, and tests selected provider values, model metadata, and Anthropic 1M-context pricing.
Canonical configuration validation dispatch
webview-ui/src/utils/validate.ts, webview-ui/src/utils/__tests__/validate.spec.ts
Validation switches use canonical identifiers while preserving existing configuration checks and error behavior; the test type import syntax changes without altering assertions.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: taltas, edelauna

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: replacing webview provider comparisons with canonical identifiers.
Description check ✅ Passed The description covers the change, rationale, testing, and issue linkage, with only minor template-format omissions.
Linked Issues check ✅ Passed The validation and selected-model updates use canonical identifiers and add regression tests, matching issue #959's core requirements.
Out of Scope Changes check ✅ Passed The diff stays focused on provider-identifier migrations and matching tests, with no unrelated feature or behavioral changes evident.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@WebMad
WebMad force-pushed the issue-959-canonical-webview-provider-identifiers branch from 87080d6 to 607df7f Compare July 25, 2026 20:46
@WebMad WebMad changed the title refactor: use canonical provider identifiers in extension and webview refactor(webview): use canonical provider identifiers Jul 25, 2026
@WebMad
WebMad force-pushed the issue-959-canonical-webview-provider-identifiers branch from 607df7f to 5b1c51a Compare July 25, 2026 20:49
@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@WebMad
WebMad marked this pull request as ready for review July 26, 2026 13:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
webview-ui/src/components/ui/hooks/useSelectedModel.ts (1)

421-422: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Finish converting internal provider comparisons to providerIdentifiers.

The switch labels are canonical now, but this hook still uses literal equality checks at Lines 63–65, 80–82, 108, and 430. That leaves readiness and fallback dispatch on a separate contract from getSelectedModel; use providerIdentifiers.* for internal comparisons while retaining serialized/router-map literals where required.

Proposed fix
-				provider === "anthropic" &&
+				provider === providerIdentifiers.anthropic &&
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts` around lines 421 -
422, Replace the remaining literal provider equality checks in useSelectedModel
at the readiness, fallback-dispatch, and related branches (including the checks
around lines 63–65, 80–82, 108, and 430) with the corresponding
providerIdentifiers.* constants. Keep serialized values and router-map keys as
literals where their external contract requires them, and preserve the existing
switch behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts`:
- Around line 421-422: Replace the remaining literal provider equality checks in
useSelectedModel at the readiness, fallback-dispatch, and related branches
(including the checks around lines 63–65, 80–82, 108, and 430) with the
corresponding providerIdentifiers.* constants. Keep serialized values and
router-map keys as literals where their external contract requires them, and
preserve the existing switch behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c9baa5b-47db-4ebc-add6-8c5cce143a56

📥 Commits

Reviewing files that changed from the base of the PR and between e479b7e and 68f6226.

📒 Files selected for processing (3)
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts
  • webview-ui/src/utils/__tests__/validate.spec.ts
  • webview-ui/src/utils/validate.ts

@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 26, 2026
Comment thread webview-ui/src/components/ui/hooks/useSelectedModel.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@webview-ui/src/components/ui/hooks/useSelectedModel.ts`:
- Around line 421-423: Update the Anthropic-only condition within the grouped
branch of useSelectedModel to compare provider against
providerIdentifiers.anthropic rather than the hardcoded "anthropic" string,
preserving the 1M-context tier override when the registry identifier changes.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 996ce2b7-1d39-454f-b5da-46ffffa37b85

📥 Commits

Reviewing files that changed from the base of the PR and between 68f6226 and d5bd771.

📒 Files selected for processing (2)
  • webview-ui/src/components/ui/hooks/__tests__/useSelectedModel.spec.ts
  • webview-ui/src/components/ui/hooks/useSelectedModel.ts

Comment thread webview-ui/src/components/ui/hooks/useSelectedModel.ts
@github-actions github-actions Bot removed the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 26, 2026
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 26, 2026

@edelauna edelauna left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good - had a comment on preventing returning undefined, and if we should up date some other locations?

case providerIdentifiers.baseten:
if (!apiConfiguration.basetenApiKey) {
return i18next.t("settings:validation.apiKey")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The switch was fully migrated here, but two if-condition comparisons lower in the same file were missed:

  • Line 210: if (provider === "vscode-lm") → should use providerIdentifiers.vscodeLm
  • Line 321: if (apiConfiguration.apiProvider !== "zoo-gateway") → should use providerIdentifiers.zooGateway

Those lines aren't in the diff, but they're in functions that live in the same file and have the same staleness risk if the identifier values ever change.

// case "fake-ai":
default: {
provider satisfies "anthropic" | "gemini-cli" | "fake-ai"
case providerIdentifiers.anthropic:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The three explicit cases correctly replace the old default:, but the exhaustiveness guard is now gone. With noImplicitReturns absent from tsconfig, a new provider added to ProviderName without a case here would silently return undefined at runtime. Worth adding after the last case:

Suggested change
case providerIdentifiers.anthropic:
case providerIdentifiers.anthropic:
case providerIdentifiers.geminiCli:
case providerIdentifiers.fakeAi: {

(And after the closing } of this block, before the final switch }):

default: {
    provider satisfies never
    throw new Error(`Unsupported provider: ${provider}`)
}

const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.id).toBe("claude-opus-4-6")
expect(result.current.info?.contextWindow).toBe(1_000_000)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The Sonnet 4.6 test just above also asserts inputPrice and outputPrice from the same tier-override path. Could this test do the same?

Suggested change
expect(result.current.info?.contextWindow).toBe(1_000_000)
expect(result.current.info?.contextWindow).toBe(1_000_000)
expect(result.current.info?.inputPrice).toBe(10.0)
expect(result.current.info?.outputPrice).toBe(37.5)

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Migrate webview provider comparisons to canonical identifiers

2 participants