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.
This commit is contained in:
Austin Pickett 2026-06-19 09:32:45 -04:00 committed by Teknium
parent ee0de638d7
commit d91b8d8368

View file

@ -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<OAuthProvider> =
}
}
// 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> = {}): 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: [] })