chore(lint): reduce warning debt across core adapters and model clients
This commit is contained in:
+20
-15
@@ -20,6 +20,11 @@ export interface DoctorContext {
|
||||
}
|
||||
|
||||
type Check = (ctx: DoctorContext) => Promise<CheckResult>;
|
||||
type UnknownRecord = Record<string, unknown>;
|
||||
|
||||
const asRecord = (value: unknown): UnknownRecord | undefined => (
|
||||
value && typeof value === 'object' ? value as UnknownRecord : undefined
|
||||
);
|
||||
|
||||
const checkConfigExists: Check = async (ctx) => {
|
||||
if (existsSync(ctx.configPath)) {
|
||||
@@ -78,8 +83,9 @@ const checkDeprecatedConfigKeys: Check = async (ctx) => {
|
||||
|
||||
try {
|
||||
const raw = readFileSync(ctx.configPath, 'utf-8');
|
||||
const parsed = parse(raw) as any;
|
||||
const tailscaleOnly = Boolean(parsed?.server && typeof parsed.server === 'object' && 'tailscale_only' in parsed.server);
|
||||
const parsed = asRecord(parse(raw));
|
||||
const server = asRecord(parsed?.server);
|
||||
const tailscaleOnly = Boolean(server && 'tailscale_only' in server);
|
||||
|
||||
if (tailscaleOnly) {
|
||||
return {
|
||||
@@ -198,11 +204,11 @@ const checkModelConnectivity: Check = async (ctx) => {
|
||||
return true;
|
||||
}
|
||||
const oauth = o.oauth;
|
||||
const oauthRecord = asRecord(oauth);
|
||||
return Boolean(
|
||||
oauth
|
||||
&& typeof oauth === 'object'
|
||||
&& typeof (oauth as any).access_token === 'string'
|
||||
&& typeof (oauth as any).refresh_token === 'string',
|
||||
oauthRecord
|
||||
&& typeof oauthRecord.access_token === 'string'
|
||||
&& typeof oauthRecord.refresh_token === 'string',
|
||||
);
|
||||
};
|
||||
|
||||
@@ -213,22 +219,21 @@ const checkModelConnectivity: Check = async (ctx) => {
|
||||
}
|
||||
const o = openai as Record<string, unknown>;
|
||||
const apiKey = o.api_key;
|
||||
const apiKeyRecord = asRecord(apiKey);
|
||||
return Boolean(
|
||||
apiKey
|
||||
&& typeof apiKey === 'object'
|
||||
&& typeof (apiKey as any).api_key === 'string'
|
||||
&& (apiKey as any).api_key.length > 0,
|
||||
typeof apiKeyRecord?.api_key === 'string'
|
||||
&& apiKeyRecord.api_key.length > 0,
|
||||
);
|
||||
};
|
||||
|
||||
const storeAnthropicApiKeyPresent = (): boolean => {
|
||||
const anthropic = store.anthropic as any;
|
||||
return Boolean(anthropic && typeof anthropic.api_key === 'string' && anthropic.api_key.length > 0);
|
||||
const anthropic = asRecord(store.anthropic);
|
||||
return Boolean(typeof anthropic?.api_key === 'string' && anthropic.api_key.length > 0);
|
||||
};
|
||||
|
||||
const storeAnthropicAuthTokenPresent = (): boolean => {
|
||||
const anthropic = store.anthropic as any;
|
||||
return Boolean(anthropic && typeof anthropic.auth_token === 'string' && anthropic.auth_token.length > 0);
|
||||
const anthropic = asRecord(store.anthropic);
|
||||
return Boolean(typeof anthropic?.auth_token === 'string' && anthropic.auth_token.length > 0);
|
||||
};
|
||||
|
||||
const formatSources = (sources: { config: boolean; env: boolean; store: boolean }): string => {
|
||||
@@ -318,7 +323,7 @@ const checkModelConnectivity: Check = async (ctx) => {
|
||||
const envVar = envVarMap[provider];
|
||||
const sources = {
|
||||
config: typeof cfg.api_key === 'string' && (cfg.api_key as string).length > 0,
|
||||
env: Boolean(envVar && process.env[envVar] && process.env[envVar]!.length > 0),
|
||||
env: Boolean(envVar && typeof process.env[envVar] === 'string' && process.env[envVar].length > 0),
|
||||
store: false,
|
||||
};
|
||||
const ok = sources.config || sources.env;
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { createInterface } from 'readline/promises';
|
||||
import { EventEmitter } from 'events';
|
||||
import type { Interface as ReadlineInterface } from 'readline/promises';
|
||||
import { createPrompter } from './prompts.js';
|
||||
import { ConfigBuilder } from './config.js';
|
||||
import { setupProviders } from './providers.js';
|
||||
|
||||
function mockReadline(inputs: string[]) {
|
||||
let questionIdx = 0;
|
||||
const emitter = new EventEmitter();
|
||||
|
||||
return {
|
||||
async question(query: string) {
|
||||
async question(_query: string) {
|
||||
const answer = inputs[questionIdx++];
|
||||
return answer ?? '';
|
||||
},
|
||||
@@ -26,7 +24,7 @@ function mockReadline(inputs: string[]) {
|
||||
async next() {
|
||||
return { done: true };
|
||||
},
|
||||
} as any;
|
||||
} as unknown as ReadlineInterface;
|
||||
}
|
||||
|
||||
describe('setupProviders', () => {
|
||||
|
||||
Reference in New Issue
Block a user