xonecas.io
64875
Mc

mini-coder / commit 0dcc730

chore: fix lint complexity and add missing AppState fields in tests

Extract parseCustomProvider() to reduce cognitive complexity of
sanitizeCustomProviders(). Add customModels and startupWarnings to
test state factories.

Andy Nutter-Upham2026-04-10 0dcc7300e138c8b9121ecf5dce2327ee5eca4166 parent 2b2fa4d

5 files changed

src/headless.test.ts+2−0
@@ -56,6 +56,8 @@ function createTestState(): AppState {
5656 activeTurnPromise: null,
5757 showReasoning: true,
5858 verbose: false,
59+ customModels: [],
60+ startupWarnings: [],
5961 };
6062 states.push(state);
6163 return state;
src/settings.ts+25−22
@@ -192,6 +192,28 @@ function sanitizeSettings(value: unknown): UserSettings {
192192 return settings;
193193 }
194194
195+/** Try to parse a single custom provider entry, returning null on failure. */
196+function parseCustomProvider(item: unknown): CustomProvider | null {
197+ if (item == null || typeof item !== "object" || Array.isArray(item)) {
198+ return null;
199+ }
200+
201+ const candidate = item as Record<string, unknown>;
202+ const name = typeof candidate.name === "string" ? candidate.name.trim() : "";
203+ const baseUrl =
204+ typeof candidate.baseUrl === "string" ? candidate.baseUrl.trim() : "";
205+
206+ if (!name || !baseUrl) {
207+ return null;
208+ }
209+
210+ const entry: CustomProvider = { name, baseUrl };
211+ if (typeof candidate.apiKey === "string") {
212+ entry.apiKey = candidate.apiKey;
213+ }
214+ return entry;
215+}
216+
195217 /**
196218 * Validate and normalize custom provider entries.
197219 *
@@ -207,30 +229,11 @@ function sanitizeCustomProviders(value: unknown): CustomProvider[] | undefined {
207229 const seen = new Set<string>();
208230
209231 for (const item of value) {
210- if (item == null || typeof item !== "object" || Array.isArray(item)) {
211- continue;
212- }
213-
214- const candidate = item as Record<string, unknown>;
215- const name =
216- typeof candidate.name === "string" ? candidate.name.trim() : "";
217- const baseUrl =
218- typeof candidate.baseUrl === "string" ? candidate.baseUrl.trim() : "";
219-
220- if (!name || !baseUrl) {
232+ const entry = parseCustomProvider(item);
233+ if (!entry || seen.has(entry.name)) {
221234 continue;
222235 }
223-
224- if (seen.has(name)) {
225- continue;
226- }
227- seen.add(name);
228-
229- const entry: CustomProvider = { name, baseUrl };
230- if (typeof candidate.apiKey === "string") {
231- entry.apiKey = candidate.apiKey;
232- }
233-
236+ seen.add(entry.name);
234237 result.push(entry);
235238 }
236239
src/ui.test.ts+2−0
@@ -186,6 +186,8 @@ function createTestState(): AppState {
186186 activeTurnPromise: null,
187187 showReasoning: DEFAULT_SHOW_REASONING,
188188 verbose: DEFAULT_VERBOSE,
189+ customModels: [],
190+ startupWarnings: [],
189191 };
190192 }
191193
src/ui/commands.test.ts+2−0
@@ -91,6 +91,8 @@ function createTestState(): AppState {
9191 activeTurnPromise: null,
9292 showReasoning: true,
9393 verbose: false,
94+ customModels: [],
95+ startupWarnings: [],
9496 };
9597 }
9698
src/ui/status.test.ts+2−0
@@ -103,6 +103,8 @@ function createTestState(): AppState {
103103 activeTurnPromise: null,
104104 showReasoning: DEFAULT_SHOW_REASONING,
105105 verbose: DEFAULT_VERBOSE,
106+ customModels: [],
107+ startupWarnings: [],
106108 };
107109 }