Skip to content

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

Open
WebMad wants to merge 10 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 10 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 switching to standardized provider identifiers rather than hardcoded provider strings.
    • Added stricter handling to ensure unsupported providers are detected via an explicit exhaustiveness guard, while preserving provider-specific model and validation behavior.
  • Tests
    • Expanded model-selection tests with parameterized cases covering multiple providers and updated imports to match the shared provider catalog.
    • Added Anthropic “1M context” pricing/context assertions and verified provider/model resolution consistency.

@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Webview model selection and configuration validation now use shared providerIdentifiers constants instead of hardcoded provider strings. Shared provider cases are explicit, unsupported providers are guarded, 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, throws for unsupported 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 and provider checks use canonical identifiers while preserving existing configuration checks, sign-in conditions, 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: navedmerchant

🚥 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 is concise and accurately summarizes the main change: migrating webview code to canonical provider identifiers.
Description check ✅ Passed The description covers the issue, implementation summary, TDD, and verification, and it links the PR to the issue.
Linked Issues check ✅ Passed The validation and selected-model updates align with the canonical-identifier objective, and focused regression tests were added.
Out of Scope Changes check ✅ Passed The diff stays focused on provider-identifier refactors and tests, with no clear unrelated functional changes.
✨ 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

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
webview-ui/src/utils/validate.ts 50.00% 0 Missing and 1 partial ⚠️

📢 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?

Comment thread webview-ui/src/utils/validate.ts
Comment thread webview-ui/src/components/ui/hooks/useSelectedModel.ts
@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
@WebMad
WebMad requested a review from edelauna July 29, 2026 15:54
@WebMad
WebMad force-pushed the issue-959-canonical-webview-provider-identifiers branch from b7a20db to 650c515 Compare July 29, 2026 16:44
@github-actions github-actions Bot added awaiting-review PR changes are ready and waiting for maintainer re-review and removed awaiting-author PR is waiting for the author to address requested changes labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR changes are ready and waiting for maintainer re-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT] Migrate webview provider comparisons to canonical identifiers

2 participants