chore(lint): replace ESLint with Oxlint and clear anti-slop findings

This commit is contained in:
Chris Scott committed 2026-11-13 01:13:34 -05:00
1 parent c6c13335e5
commit b625acfc0c
1083 files changed
+67089 -80136

No files matched your search

+63 -60
View File
@@ -1,69 +1,72 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { ConfigEntry, ModelInfo } from '@opencode-manager/shared/opencode'
import type { ConfigEntry, ModelInfo, OpenCodeApi } from '@opencode-manager/shared/opencode'
import type { OpenCodeClient } from '../../src/services/opencode/client'
import {
MODEL_LOAD_POLL_MS,
MODEL_LOAD_TIMEOUT_MS,
resolveOpenCodeModel,
} from '../../src/services/opencode-models'
import { createStubOpenCodeClient, modelInfo } from '../helpers/stub-opencode-client'
const DIR = '/workspace/repos/sample-project'
const LOCATION = { directory: DIR }
function model(providerID: string, id: string, enabled: boolean = true): ModelInfo {
return { providerID, id, enabled } as ModelInfo
return modelInfo({ providerID, id, modelID: id, enabled })
}
function configEntry(model: string): ConfigEntry {
return { type: 'document', info: { model } } as ConfigEntry
function configEntry(modelRef: string): ConfigEntry {
return { type: 'document', info: { model: modelRef } }
}
function createClientStub(input: {
interface ClientStubInput {
models: ModelInfo[]
defaultModel?: ModelInfo | null
configEntries?: ConfigEntry[]
listError?: Error
defaultError?: Error
configError?: Error
}): OpenCodeClient {
return {
}
function createdClient(input: ClientStubInput): OpenCodeClient {
return createStubOpenCodeClient({
api: {
model: {
list: vi.fn(async () => {
list: vi.fn<OpenCodeApi['model']['list']>(async () => {
if (input.listError) throw input.listError
return { location: LOCATION, data: input.models }
}),
default: vi.fn(async () => {
default: vi.fn<OpenCodeApi['model']['default']>(async () => {
if (input.defaultError) throw input.defaultError
return { location: LOCATION, data: input.defaultModel ?? null }
}),
},
config: {
get: vi.fn(async () => {
get: vi.fn<OpenCodeApi['config']['get']>(async () => {
if (input.configError) throw input.configError
return input.configEntries ?? []
}),
},
},
} as unknown as OpenCodeClient
})
}
function createStalledListClient(): OpenCodeClient {
return {
return createStubOpenCodeClient({
api: {
model: {
list: vi.fn((_input: unknown, requestOptions?: { signal?: AbortSignal }) =>
list: vi.fn<OpenCodeApi['model']['list']>((_input, requestOptions) =>
new Promise((_resolve, reject) => {
const signal = requestOptions?.signal
signal?.addEventListener('abort', () => reject(signal.reason), { once: true })
})),
default: vi.fn(async () => ({ location: LOCATION, data: null })),
default: vi.fn<OpenCodeApi['model']['default']>(async () => ({ location: LOCATION, data: null })),
},
config: {
get: vi.fn(async () => []),
get: vi.fn<OpenCodeApi['config']['get']>(async () => []),
},
},
} as unknown as OpenCodeClient
})
}
describe('resolveOpenCodeModel', () => {
@@ -77,7 +80,7 @@ describe('resolveOpenCodeModel', () => {
})
it('returns the preferred model when it is available', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5'), model('openai', 'gpt-5-mini')],
defaultModel: model('openai', 'gpt-5-mini'),
})
@@ -88,7 +91,7 @@ describe('resolveOpenCodeModel', () => {
})
it('preserves the variant of a preferred model reference', async () => {
const client = createClientStub({ models: [model('openai', 'gpt-5')] })
const client = createdClient({ models: [model('openai', 'gpt-5')] })
const result = await resolveOpenCodeModel(client, DIR, { preferredModel: 'openai/gpt-5#high' })
@@ -96,7 +99,7 @@ describe('resolveOpenCodeModel', () => {
})
it('keeps slashes inside the model id when parsing the preferred model', async () => {
const client = createClientStub({ models: [model('openrouter', 'anthropic/claude-sonnet-4')] })
const client = createdClient({ models: [model('openrouter', 'anthropic/claude-sonnet-4')] })
const result = await resolveOpenCodeModel(client, DIR, {
preferredModel: 'openrouter/anthropic/claude-sonnet-4',
@@ -110,7 +113,7 @@ describe('resolveOpenCodeModel', () => {
})
it('falls back to the OpenCode default model when the preferred model is unavailable', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5'), model('openai', 'gpt-5-mini')],
defaultModel: model('openai', 'gpt-5-mini'),
})
@@ -126,7 +129,7 @@ describe('resolveOpenCodeModel', () => {
})
it('falls back to the first enabled model when the default model is unavailable', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5'), model('anthropic', 'claude-sonnet-4')],
defaultModel: model('openai', 'retired'),
})
@@ -142,7 +145,7 @@ describe('resolveOpenCodeModel', () => {
})
it('skips disabled models when choosing the first enabled entry', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5', false), model('anthropic', 'claude-sonnet-4')],
})
@@ -152,7 +155,7 @@ describe('resolveOpenCodeModel', () => {
})
it('throws when no enabled models are available', async () => {
const client = createClientStub({ models: [model('openai', 'gpt-5', false)] })
const client = createdClient({ models: [model('openai', 'gpt-5', false)] })
const promise = resolveOpenCodeModel(client, DIR)
const assertion = expect(promise).rejects.toThrow('No configured OpenCode models are available')
@@ -162,10 +165,10 @@ describe('resolveOpenCodeModel', () => {
it('waits for the preferred model while the server loads the directory catalog', async () => {
let listCalls = 0
const client = {
const client = createStubOpenCodeClient({
api: {
model: {
list: vi.fn(async () => {
list: vi.fn<OpenCodeApi['model']['list']>(async () => {
listCalls += 1
return {
location: LOCATION,
@@ -174,11 +177,11 @@ describe('resolveOpenCodeModel', () => {
: [model('opencode', 'longcat-2.5-preview-free'), model('GreatScott', 'deepseek-v4.1-flash')],
}
}),
default: vi.fn(async () => ({ location: LOCATION, data: null })),
default: vi.fn<OpenCodeApi['model']['default']>(async () => ({ location: LOCATION, data: null })),
},
config: { get: vi.fn(async () => []) },
config: { get: vi.fn<OpenCodeApi['config']['get']>(async () => []) },
},
} as unknown as OpenCodeClient
})
const promise = resolveOpenCodeModel(client, DIR, { preferredModel: 'GreatScott/deepseek-v4.1-flash' })
const assertion = expect(promise).resolves.toEqual({
@@ -193,26 +196,26 @@ describe('resolveOpenCodeModel', () => {
it('awaits the configured model while an empty then partial catalog loads', async () => {
let listCalls = 0
const client = {
const client = createStubOpenCodeClient({
api: {
model: {
list: vi.fn(async () => {
list: vi.fn<OpenCodeApi['model']['list']>(async () => {
listCalls += 1
const catalogs = [
[] as ModelInfo[],
const catalogs: ModelInfo[][] = [
[],
[model('opencode', 'longcat-2.5-preview-free')],
[model('opencode', 'longcat-2.5-preview-free'), model('GreatScott', 'deepseek-v4.1-flash')],
]
return { location: LOCATION, data: catalogs[Math.min(listCalls, catalogs.length) - 1] }
return { location: LOCATION, data: catalogs[Math.min(listCalls, catalogs.length) - 1] ?? [] }
}),
default: vi.fn(async () => ({
default: vi.fn<OpenCodeApi['model']['default']>(async () => ({
location: LOCATION,
data: model('opencode', 'longcat-2.5-preview-free'),
})),
},
config: { get: vi.fn(async () => [configEntry('GreatScott/deepseek-v4.1-flash')]) },
config: { get: vi.fn<OpenCodeApi['config']['get']>(async () => [configEntry('GreatScott/deepseek-v4.1-flash')]) },
},
} as unknown as OpenCodeClient
})
const promise = resolveOpenCodeModel(client, DIR)
const assertion = expect(promise).resolves.toEqual({
@@ -226,10 +229,10 @@ describe('resolveOpenCodeModel', () => {
})
it('resolves an object configured model and preserves its variant', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5')],
configEntries: [
{ type: 'document', info: { model: { providerID: 'openai', model: 'gpt-5', variant: 'high' } } } as ConfigEntry,
{ type: 'document', info: { model: { providerID: 'openai', model: 'gpt-5', variant: 'high' } } },
],
})
@@ -244,7 +247,7 @@ describe('resolveOpenCodeModel', () => {
})
it('does not resolve a same-provider fallback before the target model loads', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-4')],
defaultModel: model('openai', 'gpt-4'),
})
@@ -262,7 +265,7 @@ describe('resolveOpenCodeModel', () => {
})
it('falls back to the default when the configured target never loads', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5')],
defaultModel: model('openai', 'gpt-5'),
configEntries: [configEntry('missing/model')],
@@ -282,21 +285,21 @@ describe('resolveOpenCodeModel', () => {
it('waits for the catalog to populate when nothing is preferred or configured', async () => {
let listCalls = 0
const client = {
const client = createStubOpenCodeClient({
api: {
model: {
list: vi.fn(async () => {
list: vi.fn<OpenCodeApi['model']['list']>(async () => {
listCalls += 1
return {
location: LOCATION,
data: listCalls === 1 ? [] : [model('anthropic', 'claude-sonnet-4')],
}
}),
default: vi.fn(async () => ({ location: LOCATION, data: null })),
default: vi.fn<OpenCodeApi['model']['default']>(async () => ({ location: LOCATION, data: null })),
},
config: { get: vi.fn(async () => []) },
config: { get: vi.fn<OpenCodeApi['config']['get']>(async () => []) },
},
} as unknown as OpenCodeClient
})
const promise = resolveOpenCodeModel(client, DIR)
const assertion = expect(promise).resolves.toEqual({
@@ -310,10 +313,10 @@ describe('resolveOpenCodeModel', () => {
it('falls back to the cached catalog when a later poll stalls until the deadline', async () => {
let listCalls = 0
const client = {
const client = createStubOpenCodeClient({
api: {
model: {
list: vi.fn((_input: unknown, requestOptions?: { signal?: AbortSignal }) => {
list: vi.fn<OpenCodeApi['model']['list']>((_input, requestOptions) => {
listCalls += 1
if (listCalls === 1) {
return Promise.resolve({ location: LOCATION, data: [model('openai', 'gpt-5')] })
@@ -323,11 +326,11 @@ describe('resolveOpenCodeModel', () => {
signal?.addEventListener('abort', () => reject(signal.reason), { once: true })
})
}),
default: vi.fn(async () => ({ location: LOCATION, data: null })),
default: vi.fn<OpenCodeApi['model']['default']>(async () => ({ location: LOCATION, data: null })),
},
config: { get: vi.fn(async () => [configEntry('missing/model')]) },
config: { get: vi.fn<OpenCodeApi['config']['get']>(async () => [configEntry('missing/model')]) },
},
} as unknown as OpenCodeClient
})
const promise = resolveOpenCodeModel(client, DIR)
const assertion = expect(promise).resolves.toEqual({ providerID: 'openai', id: 'gpt-5', model: 'openai/gpt-5' })
@@ -360,7 +363,7 @@ describe('resolveOpenCodeModel', () => {
})
it('rejects immediately when the external signal is already aborted', async () => {
const client = createClientStub({ models: [model('openai', 'gpt-5')] })
const client = createdClient({ models: [model('openai', 'gpt-5')] })
const controller = new AbortController()
controller.abort(new Error('cancelled'))
@@ -369,18 +372,18 @@ describe('resolveOpenCodeModel', () => {
it('rejects when the external signal aborts as the default model request fulfills', async () => {
const controller = new AbortController()
const client = {
const client = createStubOpenCodeClient({
api: {
model: {
list: vi.fn(async () => ({ location: LOCATION, data: [model('openai', 'gpt-5')] })),
default: vi.fn(async () => {
list: vi.fn<OpenCodeApi['model']['list']>(async () => ({ location: LOCATION, data: [model('openai', 'gpt-5')] })),
default: vi.fn<OpenCodeApi['model']['default']>(async () => {
controller.abort(new Error('cancelled'))
return { location: LOCATION, data: model('openai', 'gpt-5') }
}),
},
config: { get: vi.fn(async () => []) },
config: { get: vi.fn<OpenCodeApi['config']['get']>(async () => []) },
},
} as unknown as OpenCodeClient
})
await expect(
resolveOpenCodeModel(client, DIR, { signal: controller.signal }),
@@ -388,13 +391,13 @@ describe('resolveOpenCodeModel', () => {
})
it('propagates a catalog list error', async () => {
const client = createClientStub({ models: [], listError: new Error('list failed') })
const client = createdClient({ models: [], listError: new Error('list failed') })
await expect(resolveOpenCodeModel(client, DIR)).rejects.toThrow('list failed')
})
it('propagates a default model error', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5')],
defaultError: new Error('default failed'),
})
@@ -403,7 +406,7 @@ describe('resolveOpenCodeModel', () => {
})
it('propagates a configured model read error', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5')],
defaultModel: model('openai', 'gpt-5'),
configError: new Error('config failed'),
@@ -413,7 +416,7 @@ describe('resolveOpenCodeModel', () => {
})
it('ignores a malformed preferred model reference and falls back to the default', async () => {
const client = createClientStub({
const client = createdClient({
models: [model('openai', 'gpt-5')],
defaultModel: model('openai', 'gpt-5'),
})