fix: resolve strict typecheck fallout in setup, routing, and tests

This commit is contained in:
William Valentin
2026-02-15 23:22:05 -08:00
parent 948d4ac6d8
commit ae70818ec1
18 changed files with 182 additions and 134 deletions
+4 -4
View File
@@ -44,8 +44,8 @@ describe('setupChannels', () => {
const builder = new ConfigBuilder();
await setupChannels(p, builder);
const config = builder.build();
expect(config.telegram.bot_token).toBe('123:ABC');
expect(config.telegram.allowed_chat_ids).toEqual([12345, 67890]);
expect(config.telegram!.bot_token).toBe('123:ABC');
expect(config.telegram!.allowed_chat_ids).toEqual([12345, 67890]);
});
it('configures discord channel', async () => {
@@ -54,7 +54,7 @@ describe('setupChannels', () => {
const builder = new ConfigBuilder();
await setupChannels(p, builder);
const config = builder.build();
expect(config.discord.bot_token).toBe('MTIz.token');
expect(config.discord.allowed_guild_ids).toEqual(['guild1', 'guild2']);
expect(config.discord!.bot_token).toBe('MTIz.token');
expect(config.discord!.allowed_guild_ids).toEqual(['guild1', 'guild2']);
});
});
+9 -9
View File
@@ -17,8 +17,8 @@ describe('ConfigBuilder', () => {
builder.setProvider('default', { provider: 'anthropic', model: 'test', api_key: 'k' });
builder.setTelegram('123:ABC', [12345]);
const obj = builder.build();
expect(obj.telegram.bot_token).toBe('123:ABC');
expect(obj.telegram.allowed_chat_ids).toEqual([12345]);
expect(obj.telegram!.bot_token).toBe('123:ABC');
expect(obj.telegram!.allowed_chat_ids).toEqual([12345]);
});
it('adds discord channel', () => {
@@ -26,8 +26,8 @@ describe('ConfigBuilder', () => {
builder.setProvider('default', { provider: 'anthropic', model: 'test', api_key: 'k' });
builder.setDiscord('MTIz.test', ['guild1']);
const obj = builder.build();
expect(obj.discord.bot_token).toBe('MTIz.test');
expect(obj.discord.allowed_guild_ids).toEqual(['guild1']);
expect(obj.discord!.bot_token).toBe('MTIz.test');
expect(obj.discord!.allowed_guild_ids).toEqual(['guild1']);
});
it('adds fast tier', () => {
@@ -58,7 +58,7 @@ describe('ConfigBuilder', () => {
const obj = builder.build();
expect(obj.models.default.provider).toBe('openai');
expect(obj.server.port).toBe(9999);
expect(obj.telegram.bot_token).toBe('123:ABC');
expect(obj.telegram!.bot_token).toBe('123:ABC');
});
it('sets memory embedding config', () => {
@@ -66,16 +66,16 @@ describe('ConfigBuilder', () => {
builder.setProvider('default', { provider: 'anthropic', model: 'test', api_key: 'k' });
builder.setMemoryEmbedding({ provider: 'openai', api_key: 'sk-emb' });
const obj = builder.build();
expect(obj.memory.embedding.enabled).toBe(true);
expect(obj.memory.embedding.provider).toBe('openai');
expect(obj.memory.embedding.api_key).toBe('sk-emb');
expect(obj.memory!.embedding!.enabled).toBe(true);
expect(obj.memory!.embedding!.provider).toBe('openai');
expect(obj.memory!.embedding!.api_key).toBe('sk-emb');
});
it('sets sandbox enabled', () => {
const builder = new ConfigBuilder();
builder.setSandboxEnabled(true);
const obj = builder.build();
expect(obj.sandbox.enabled).toBe(true);
expect(obj.sandbox!.enabled).toBe(true);
});
it('sets gateway auth token', () => {
+38 -6
View File
@@ -14,8 +14,40 @@ interface EmbeddingConfig {
endpoint?: string;
}
export interface SetupConfig {
log_level?: string;
models: Record<string, ProviderConfig & Record<string, unknown>>;
server: {
port?: number;
localhost?: boolean;
token?: string;
lock?: boolean;
tailscale?: { serve?: boolean };
} & Record<string, unknown>;
hooks?: Record<string, unknown>;
telegram?: { bot_token: string; allowed_chat_ids: number[] };
discord?: { bot_token: string; allowed_guild_ids: string[] };
slack?: { bot_token: string; app_token: string; signing_secret: string; allowed_channel_ids: string[] };
whatsapp?: { allowed_numbers: string[] };
memory?: { embedding?: { enabled?: boolean; provider?: string; api_key?: string; endpoint?: string } };
sandbox?: { enabled?: boolean };
pairing?: { enabled?: boolean };
tools?: { profile?: string };
automation?: {
cron?: Array<Record<string, unknown>>;
webhooks?: Array<Record<string, unknown>>;
gmail?: { enabled?: boolean };
gcal?: { enabled?: boolean };
gdocs?: { enabled?: boolean };
gdrive?: { enabled?: boolean };
gtasks?: { enabled?: boolean };
heartbeat?: { enabled?: boolean };
} & Record<string, unknown>;
[key: string]: unknown;
}
export class ConfigBuilder {
private config: Record<string, unknown>;
private config: SetupConfig;
constructor() {
this.config = {
@@ -32,13 +64,13 @@ export class ConfigBuilder {
static fromObject(obj: Record<string, unknown>): ConfigBuilder {
const builder = new ConfigBuilder();
builder.config = structuredClone(obj);
builder.config = structuredClone(obj) as SetupConfig;
return builder;
}
setProvider(tier: 'default' | 'fast' | 'complex' | 'local', cfg: ProviderConfig): void {
const models = (this.config.models ?? {}) as Record<string, unknown>;
const entry: Record<string, unknown> = { provider: cfg.provider, model: cfg.model };
const models = (this.config.models ?? {}) as SetupConfig['models'];
const entry: ProviderConfig & Record<string, unknown> = { provider: cfg.provider, model: cfg.model };
if (cfg.api_key) {entry.api_key = cfg.api_key;}
if (cfg.auth_token) {entry.auth_token = cfg.auth_token;}
if (cfg.endpoint) {entry.endpoint = cfg.endpoint;}
@@ -155,8 +187,8 @@ export class ConfigBuilder {
this.config.automation = automation;
}
build(): Record<string, unknown> {
return structuredClone(this.config) as Record<string, unknown>;
build(): SetupConfig {
return structuredClone(this.config) as SetupConfig;
}
toYaml(): string {
+4 -4
View File
@@ -37,8 +37,8 @@ describe('first-run wizard integration', () => {
expect(config.models.default.api_key).toBe('sk-ant-key');
expect(config.server.port).toBeDefined();
const reparsed = parse(yaml);
expect(reparsed.models.default.provider).toBe('anthropic');
const reparsed = parse(yaml) as { models?: { default?: { provider?: string } } };
expect(reparsed.models!.default!.provider).toBe('anthropic');
});
it('produces valid config with ollama + telegram', async () => {
@@ -60,7 +60,7 @@ describe('first-run wizard integration', () => {
const config = builder.build();
expect(config.models.default.provider).toBe('ollama');
expect(config.telegram.bot_token).toBe('123:ABCdef');
expect(config.telegram.allowed_chat_ids).toEqual([12345678]);
expect(config.telegram!.bot_token).toBe('123:ABCdef');
expect(config.telegram!.allowed_chat_ids).toEqual([12345678]);
});
});
+4 -4
View File
@@ -37,8 +37,8 @@ describe('setupMemory', () => {
builder.setProvider('default', { provider: 'openai', model: 'gpt-4.1', api_key: 'sk-test' });
await setupMemory(p, builder);
const config = builder.build();
expect(config.memory.embedding.enabled).toBe(true);
expect(config.memory.embedding.provider).toBe('openai');
expect(config.memory!.embedding!.enabled).toBe(true);
expect(config.memory!.embedding!.provider).toBe('openai');
});
it('skips vector search when declined', async () => {
@@ -58,8 +58,8 @@ describe('setupSecurity', () => {
const builder = new ConfigBuilder();
await setupSecurity(p, builder);
const config = builder.build();
expect(config.sandbox.enabled).toBe(true);
expect(config.pairing.enabled).toBe(true);
expect(config.sandbox!.enabled).toBe(true);
expect(config.pairing!.enabled).toBe(true);
});
});
+5 -3
View File
@@ -1,4 +1,6 @@
export function renderSummary(config: Record<string, unknown>): string {
import type { SetupConfig } from './config.js';
export function renderSummary(config: SetupConfig): string {
const lines: string[] = [];
const models = config.models ?? {};
@@ -22,8 +24,8 @@ export function renderSummary(config: Record<string, unknown>): string {
const auto = config.automation ?? {};
const autoFeatures: string[] = [];
if (auto.cron?.length > 0) {autoFeatures.push(`${auto.cron.length} cron jobs`);}
if (auto.webhooks?.length > 0) {autoFeatures.push('webhooks');}
if (Array.isArray(auto.cron) && auto.cron.length > 0) {autoFeatures.push(`${auto.cron.length} cron jobs`);}
if (Array.isArray(auto.webhooks) && auto.webhooks.length > 0) {autoFeatures.push('webhooks');}
if (auto.gmail?.enabled) {autoFeatures.push('gmail');}
if (auto.gcal?.enabled) {autoFeatures.push('gcal');}
if (auto.gdocs?.enabled) {autoFeatures.push('gdocs');}