Skip to content

fix(cli): enforce LiteLLM integration in setup when project has one configured - #429

Merged
yanaSelin merged 8 commits into
codemie-ai:mainfrom
SleepySML:EPMCDME-11733
Jul 31, 2026
Merged

fix(cli): enforce LiteLLM integration in setup when project has one configured#429
yanaSelin merged 8 commits into
codemie-ai:mainfrom
SleepySML:EPMCDME-11733

Conversation

@SleepySML

Copy link
Copy Markdown
Contributor

Summary

Implements EPMCDME-11733: when a CodeMie project already has a LiteLLM integration, codemie setup now detects it before the provider-selection prompt and forces the user through the LiteLLM path — they cannot complete setup without providing the required API key.

Changes

  • src/providers/core/types.ts — adds SetupContext interface (enforcedIntegration?: { id, alias, codeMieUrl }) and threads it into ProviderSetupSteps.getCredentials
  • src/providers/plugins/litellm/litellm.setup-steps.ts — enforces non-empty API key when context.enforcedIntegration is set; suppresses 'not-required' fallback
  • src/cli/commands/setup.ts — adds detectLiteLLMEnforcement() gate (SSO auth → project select → fetch integrations → filter by project_name and credential_type === 'LiteLLM') that runs before provider selection; graceful fallback on any SSO error; update flows skip the gate (isUpdate guard)
  • src/cli/commands/__tests__/setup.enforcement.test.ts — new; 7 tests covering the enforcement gate and its wiring into the wizard
  • src/providers/plugins/litellm/__tests__/litellm.setup-steps.test.ts — new; 5 tests covering enforcement and normal modes

Testing

  • Unit tests added (npm run test:unit — 2329/2330 pass; 1 pre-existing unrelated failure)
  • Lint clean (npm run lint — zero warnings)
  • TypeScript clean (npm run typecheck)
  • Build passes (npm run build)
  • Manual staging verification (enforcement gate against a real CodeMie project with LiteLLM integration)

Checklist

  • Code follows project standards
  • CI gates pass (npm run ci — pre-existing self-update.test.ts failure unrelated to this change)
  • No merge conflicts with main

Closes EPMCDME-11733

EvgeniiKurdakov and others added 6 commits July 20, 2026 14:46
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ePluginSetup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Filter integrations by credential_type === 'LiteLLM' (CR-001)
- Warn when multiple LiteLLM integrations match, use first (CR-002)
- Skip SSO enforcement gate when isUpdate is true (CR-003)
- Guard answers.apiKey with optional chain in enforcement mode (CR-004)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Includes spec, plan, technical-analysis, code-review reports,
decisions/events audit logs, and .state.json (phase: maintenance).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@yanaSelin yanaSelin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code review via SDLC Factory — 2 critical findings, 4 major findings. Full machine verdict: docs/superpowers/reviews/2026-07-28-pr-429/code-review-final.json

Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/setup.ts
Comment thread src/providers/plugins/litellm/litellm.setup-steps.ts Outdated
- CR-001: Remove isUpdate guard; enforcement runs on all flows per spec
- CR-002: Add "Please reinstall codemie-cli." to provider-unavailable error
- CR-003: Fix banner to use 📌 emoji and spec-exact message text
- CR-004: Thread portal URL through LiteLLMEnforcementContext.codeMieUrl
  instead of using authResult.apiUrl (REST API URL, not portal)
- CR-005: Re-throw ExitPromptError/AbortPromptError in catch block so
  Ctrl+C cannot silently bypass enforcement
- CR-006: Add post-prompt guard in litellm.setup-steps.ts to reject empty
  API key in enforcement mode regardless of TTY context

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/setup.ts Outdated
Comment thread src/cli/commands/__tests__/setup.enforcement.test.ts Outdated
Comment thread src/providers/plugins/litellm/litellm.setup-steps.ts Outdated
Addresses reviewer feedback on commit 72d3d82.

setup.ts:
- Replace `(error as any)?.name` with `error instanceof Error` narrowing
  via isPromptAbortError() helper — complies with the no-any policy in
  AGENTS.md.
- Wrap detectLiteLLMEnforcement() at the wizard call site in a try/catch
  that handles ExitPromptError cleanly (`Setup cancelled.` + return)
  instead of surfacing a raw stack trace through the Commander action.
- Load the selected profile on update flows and thread its stored
  codeMieUrl to detectLiteLLMEnforcement() as existingCodeMieUrl, so
  `codemie setup --update` does not re-prompt for a portal URL the user
  already configured.
- Drop the runSetupWizardForTest alias — tests now drive through the
  createSetupCommand() module boundary via Commander parseAsync.

litellm.setup-steps.ts:
- Remove the duplicate LiteLLM banner from getCredentials(); the
  spec-mandated banner already prints once from setup.ts before this
  step runs.
- Interpolate enforced.codeMieUrl directly into the API-key prompt
  message and validator hint so the threaded portal URL actually
  reaches the user.
- Simplify the return: with the pre-return guard in place, `key ?? ''`
  is dead code; use `key` directly in the enforced branch.

setup.enforcement.test.ts:
- Rewrite the second describe block to invoke createSetupCommand and
  parseAsync instead of the removed runSetupWizardForTest export.
- Strengthen the SetupContext assertion to check codeMieUrl explicitly
  so a regression to authResult.apiUrl fails the test.
- Add three new detectLiteLLMEnforcement tests: threads existingCodeMieUrl
  through to promptForCodeMieUrl, treats non-LiteLLM credential_type as
  not enforced, and re-throws ExitPromptError from both promptForCodeMieUrl
  and selectCodeMieProject.
- Add a wizard-level test proving the setup wizard swallows ExitPromptError
  cleanly (no getCredentials call, no thrown stack trace).

EPMCDME-11733
@yanaSelin
yanaSelin merged commit 12f0981 into codemie-ai:main Jul 31, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants