* Add KiloCode as a first-class provider with HTTP-based model catalog Implements KiloCode (kilo.ai gateway) support following repo design principles, independently of the OpenCode implementation. Key changes: - Add 'kilocode' to CliProviderId, TeamProviderId, MemberWorkSyncProviderId - Create kilocode-model-catalog feature: HTTP client fetching models from kilo.ai /models endpoint (not /v1/models — different gateway path) - Add KILO_API_KEY env var for authentication - Wire kilocode into provider routing, capabilities, and UI labels - Add 'kilo' brand icon alias in providerBrandIcons (auto-fetches from models.dev) - KiloCode status is managed via the HTTP gateway, not the multimodel bridge * Fix: preserve non-bridge providers (kilocode) when updating provider status The multimodel bridge only returns status for anthropic/codex/gemini/opencode. When checkAuthStatus replaced result.providers with the bridge response, kilocode was lost from the provider list and never appeared in the UI. Now merge bridge providers with the initial list, keeping any provider not covered by the bridge so kilocode shows up in the Extensions panel. * Fix: resolve KiloCode status after bridge merge, skip bridge refresh for non-bridge providers - resolveKilocodeStatus() gives kilocode a settled verificationState:'verified' status so isHydratedMultimodelProviderStatus() returns true and the loading spinner stops - Status reflects KILO_API_KEY presence: authenticated+supported when set, else clear message - fetchCliStatus() now skips fetchCliProviderStatus for non-bridge providers (kilocode) so the Claude Code CLI is not queried for kilocode, preventing error status overwrites * Add KiloCode to API key provider system in settings dialog isApiKeyProviderId now includes kilocode, so the API key form renders in the Provider Settings dialog instead of showing an empty modal. Adds KILO_API_KEY config with placeholder and description. * Fix KiloCode models endpoint: /api/gateway/models per docs * Fix: short-circuit getProviderStatus/verifyProviderModels for kilocode The Claude Code CLI only accepts anthropic and codex for --provider. Calling it with kilocode caused the blinking modal error. resolveKilocodeProviderStatus() returns status directly from env without touching the CLI binary — no bridge, no --provider flag. * Fix: resolveKilocodeProviderStatus reads from app key store via enrichProviderStatus process.env.KILO_API_KEY was only set for users who configured it in their shell environment. The UI stores the key in the app's encrypted key store (ApiKeyService), which enrichProviderStatus checks via hasStoredProviderApiKey. Now resolveKilocodeProviderStatus() calls providerConnectionService.enrichProviderStatus() so both the app key store and env var are checked — the same way anthropic/gemini work. * Wire KiloCode model catalog into provider status — models now load from gateway - ProviderConnectionService: add setKilocodeModelCatalogFeature() and enrichKilocodeProviderStatus() which fetches models from the gateway API and populates provider.models when the API key is configured - main/index.ts: create KilocodeModelCatalogFeature at startup and inject it into ProviderConnectionService, same lifecycle as Codex catalog * Fix: skip Claude CLI probe for kilocode in prepareForProvisioning The generic probe path calls probeClaudeRuntime with CLAUDE_CODE_ENTRY_PROVIDER=kilocode which causes the CLI to hang — freezing the Create Team dialog until timeout. Add an explicit kilocode case that short-circuits to an API key presence check (via providerConnectionService.getConnectionInfo) without touching the Claude binary, same pattern as the opencode adapter bypass. * Fix vitest localStorage fallback * test(kilocode): update provider visibility expectations --------- Co-authored-by: 777genius <quantjumppro@gmail.com>
162 lines
4.5 KiB
TypeScript
162 lines
4.5 KiB
TypeScript
/**
|
|
* Vitest setup file.
|
|
* Runs before each test file.
|
|
*/
|
|
|
|
import * as fs from 'fs';
|
|
import * as os from 'os';
|
|
import * as path from 'path';
|
|
import { afterAll, afterEach, beforeEach, expect, vi } from 'vitest';
|
|
|
|
const TEST_HOME_PREFIX = 'agent-teams-vitest-home-';
|
|
const DEFAULT_STALE_TEST_HOME_MAX_AGE_MS = 24 * 60 * 60 * 1000;
|
|
|
|
function getStaleTestHomeMaxAgeMs(): number {
|
|
const value = Number(process.env.AGENT_TEAMS_VITEST_STALE_HOME_MAX_AGE_MS);
|
|
return Number.isFinite(value) && value > 0 ? value : DEFAULT_STALE_TEST_HOME_MAX_AGE_MS;
|
|
}
|
|
|
|
function cleanupStaleTestHomeDirs(): void {
|
|
const cutoff = Date.now() - getStaleTestHomeMaxAgeMs();
|
|
|
|
for (const entry of fs.readdirSync(os.tmpdir(), { withFileTypes: true })) {
|
|
if (!entry.isDirectory() || !entry.name.startsWith(TEST_HOME_PREFIX)) {
|
|
continue;
|
|
}
|
|
|
|
const dir = path.join(os.tmpdir(), entry.name);
|
|
try {
|
|
const stat = fs.statSync(dir);
|
|
if (stat.mtimeMs < cutoff) {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
} catch {
|
|
// Best effort cleanup only.
|
|
}
|
|
}
|
|
}
|
|
|
|
if (process.env.AGENT_TEAMS_VITEST_TEMP_CLEANUP_DONE !== '1') {
|
|
process.env.AGENT_TEAMS_VITEST_TEMP_CLEANUP_DONE = '1';
|
|
cleanupStaleTestHomeDirs();
|
|
}
|
|
|
|
// Mock Sentry Electron SDK - it requires the real `electron` package at import
|
|
// time which is unavailable in the vitest/happy-dom environment.
|
|
const sentryNoOp = {
|
|
init: vi.fn(),
|
|
addBreadcrumb: vi.fn(),
|
|
captureException: vi.fn(),
|
|
setUser: vi.fn(),
|
|
setTags: vi.fn(),
|
|
close: vi.fn(() => Promise.resolve(true)),
|
|
startSpan: vi.fn((_opts: unknown, fn: () => unknown) => fn()),
|
|
withScope: vi.fn((fn: (scope: unknown) => void) => fn({ setContext: vi.fn() })),
|
|
browserTracingIntegration: vi.fn(() => ({
|
|
name: 'BrowserTracing',
|
|
setup: vi.fn(),
|
|
afterAllSetup: vi.fn(),
|
|
})),
|
|
};
|
|
vi.mock('@sentry/electron/main', () => sentryNoOp);
|
|
vi.mock('@sentry/electron/renderer', () => sentryNoOp);
|
|
vi.mock('@sentry/react', () => sentryNoOp);
|
|
|
|
function createInMemoryStorage(): Storage {
|
|
const values = new Map<string, string>();
|
|
|
|
return {
|
|
get length() {
|
|
return values.size;
|
|
},
|
|
clear() {
|
|
values.clear();
|
|
},
|
|
getItem(key: string) {
|
|
return values.get(key) ?? null;
|
|
},
|
|
key(index: number) {
|
|
return Array.from(values.keys())[index] ?? null;
|
|
},
|
|
removeItem(key: string) {
|
|
values.delete(key);
|
|
},
|
|
setItem(key: string, value: string) {
|
|
values.set(key, String(value));
|
|
},
|
|
};
|
|
}
|
|
|
|
function hasStorageApi(value: unknown): value is Storage {
|
|
return (
|
|
typeof value === 'object' &&
|
|
value !== null &&
|
|
typeof (value as Storage).getItem === 'function' &&
|
|
typeof (value as Storage).setItem === 'function' &&
|
|
typeof (value as Storage).removeItem === 'function' &&
|
|
typeof (value as Storage).clear === 'function'
|
|
);
|
|
}
|
|
|
|
if (!hasStorageApi(globalThis.localStorage)) {
|
|
Object.defineProperty(globalThis, 'localStorage', {
|
|
configurable: true,
|
|
value: createInMemoryStorage(),
|
|
});
|
|
}
|
|
|
|
// Mock HOME for tests that need a predictable home path. It must be writable:
|
|
// some services persist state in best-effort background writes after a test has
|
|
// already reset path overrides.
|
|
const testHomeDir = fs.mkdtempSync(path.join(os.tmpdir(), TEST_HOME_PREFIX));
|
|
vi.stubEnv('HOME', testHomeDir);
|
|
let testHomeDirRemoved = false;
|
|
function removeTestHomeDir(): void {
|
|
if (testHomeDirRemoved) {
|
|
return;
|
|
}
|
|
testHomeDirRemoved = true;
|
|
try {
|
|
fs.rmSync(testHomeDir, { recursive: true, force: true });
|
|
} catch {
|
|
// Best effort cleanup only.
|
|
}
|
|
}
|
|
afterAll(removeTestHomeDir);
|
|
process.once('exit', removeTestHomeDir);
|
|
|
|
let errorSpy: ReturnType<typeof vi.spyOn>;
|
|
let warnSpy: ReturnType<typeof vi.spyOn>;
|
|
|
|
function formatConsoleCall(args: unknown[]): string {
|
|
return args
|
|
.map((arg) => {
|
|
if (arg instanceof Error) {
|
|
return arg.message;
|
|
}
|
|
return String(arg);
|
|
})
|
|
.join(' ');
|
|
}
|
|
|
|
beforeEach(() => {
|
|
errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
});
|
|
|
|
afterEach(() => {
|
|
const unexpectedErrors = errorSpy.mock.calls.map(formatConsoleCall);
|
|
const unexpectedWarnings = warnSpy.mock.calls.map(formatConsoleCall);
|
|
|
|
errorSpy.mockRestore();
|
|
warnSpy.mockRestore();
|
|
|
|
expect(
|
|
unexpectedErrors,
|
|
`Unexpected console.error calls:\n${unexpectedErrors.join('\n')}`
|
|
).toEqual([]);
|
|
expect(
|
|
unexpectedWarnings,
|
|
`Unexpected console.warn calls:\n${unexpectedWarnings.join('\n')}`
|
|
).toEqual([]);
|
|
});
|