From d91b8d8368bb5cd3bd8d9e3079d93810c32e32d2 Mon Sep 17 00:00:00 2001 From: Austin Pickett Date: Fri, 19 Jun 2026 09:32:45 -0400 Subject: [PATCH] test(desktop): make keyVar a typed EnvVarInfo factory Address review feedback on the keyVar test helper: it mocks one /api/env row (an EnvVarInfo), so type it as such and mirror the sibling provider() factory's base-plus-Partial-override shape instead of hardcoding positional args and fabricated fields (description='X direct API', url=''). Route the WidgetAI test through it too, removing the inline duplicate of the same object shape. --- .../app/settings/providers-settings.test.tsx | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/app/settings/providers-settings.test.tsx b/apps/desktop/src/app/settings/providers-settings.test.tsx index 1f1851932fc..1909604a07a 100644 --- a/apps/desktop/src/app/settings/providers-settings.test.tsx +++ b/apps/desktop/src/app/settings/providers-settings.test.tsx @@ -2,7 +2,7 @@ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/re import { atom } from 'nanostores' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type { OAuthProvider } from '@/types/hermes' +import type { EnvVarInfo, OAuthProvider } from '@/types/hermes' const listOAuthProviders = vi.fn() const disconnectOAuthProvider = vi.fn() @@ -36,19 +36,22 @@ function provider(id: string, loggedIn: boolean, patch: Partial = } } -// A backend-tagged provider env var (category=provider) for the API-keys view. -function keyVar(label: string, slug: string) { +// One `/api/env` row (an EnvVarInfo) for the API-keys view. Mirrors the +// `provider()` factory above: a valid base + per-test overrides, typed against +// the real response shape so it can't drift from EnvVarInfo. +function keyVar(patch: Partial = {}): EnvVarInfo { return { advanced: false, category: 'provider', - description: `${label} direct API`, + description: '', is_password: true, is_set: false, - provider: slug, - provider_label: label, + provider: '', + provider_label: '', redacted_value: null, tools: [], - url: '' + url: '', + ...patch } } @@ -120,18 +123,11 @@ describe('ProvidersSettings', () => { // this is the GUI/CLI drift fix: membership comes from the backend, not // from the hand-maintained prefix list. getEnvVars.mockResolvedValue({ - WIDGETAI_API_KEY: { - advanced: false, - category: 'provider', - description: 'WidgetAI direct API', - is_password: true, - is_set: false, + WIDGETAI_API_KEY: keyVar({ provider: 'widgetai', provider_label: 'WidgetAI', - redacted_value: null, - tools: [], url: 'https://widgetai.example/keys' - } + }) }) listOAuthProviders.mockResolvedValue({ providers: [] }) @@ -146,9 +142,9 @@ describe('ProvidersSettings', () => { // share the default priority and fall back to alphabetical among themselves // (Acme, Middle, Zebra) — exercising the name tiebreak of the priority sort. getEnvVars.mockResolvedValue({ - ZEBRA_API_KEY: keyVar('Zebra', 'zebra'), - ACME_API_KEY: keyVar('Acme', 'acme'), - MIDDLE_API_KEY: keyVar('Middle', 'middle') + ZEBRA_API_KEY: keyVar({ provider: 'zebra', provider_label: 'Zebra' }), + ACME_API_KEY: keyVar({ provider: 'acme', provider_label: 'Acme' }), + MIDDLE_API_KEY: keyVar({ provider: 'middle', provider_label: 'Middle' }) }) listOAuthProviders.mockResolvedValue({ providers: [] })