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 -89
View File
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
import type { JsonValue } from '@opencode-manager/shared/utils'
import {
GOAL_CHANGED_EVENT_TYPE,
GOAL_COMMAND_NAME,
@@ -9,11 +10,11 @@ import {
isGoalOutcome,
readSessionGoal,
} from '@opencode-manager/shared/opencode'
import type { GoalState, OpenCodeApi } from '@opencode-manager/shared/opencode'
import type { GoalState, GoalStatus, OpenCodeApi, SessionGoalRpc } from '@opencode-manager/shared/opencode'
const SESSION_ID = 'ses_goal_1'
const baseGoal: GoalState = {
const goalFixture = {
id: 'goal_1',
objective: 'Ship the shared goal module',
status: 'active',
@@ -21,24 +22,28 @@ const baseGoal: GoalState = {
maxRounds: 50,
boot: 'boot_1',
updatedAt: 1_700_000_000_000,
} satisfies GoalState
const baseGoal: GoalState = goalFixture
function goalState(status: GoalStatus, overrides: Partial<GoalState> = {}): GoalState {
return { ...baseGoal, status, ...overrides }
}
function goalWith(overrides: Partial<GoalState>): GoalState {
return { ...baseGoal, ...overrides }
function goalPayload(overrides: Record<string, JsonValue>) {
return { ...goalFixture, ...overrides }
}
function goalWithout(key: keyof GoalState): Record<string, unknown> {
const goal: Record<string, unknown> = { ...baseGoal }
delete goal[key]
return goal
function goalWithout(key: string) {
return Object.fromEntries(Object.entries(goalFixture).filter(([name]) => name !== key))
}
function createApi(call: ReturnType<typeof vi.fn>): OpenCodeApi {
return { rpc: { call } } as unknown as OpenCodeApi
function createApi(call: OpenCodeApi['rpc']['call']): SessionGoalRpc {
return { rpc: { call } }
}
function rpcError(type: string, message: string): { _tag: 'RpcError'; type: string; message: string } {
return { _tag: 'RpcError', type, message }
function rpcError(type: string, message: string) {
return { _tag: 'RpcError' as const, type, message }
}
describe('goal contract constants', () => {
@@ -51,8 +56,9 @@ describe('goal contract constants', () => {
})
describe('readSessionGoal', () => {
it('sends the exact rpc call with the session location', async () => {
const call = vi.fn().mockResolvedValue({ output: baseGoal })
it('sends the goal get rpc scoped to the session location', async () => {
const call = vi.fn<OpenCodeApi['rpc']['call']>().mockResolvedValue({ output: baseGoal })
await readSessionGoal(createApi(call), { sessionID: SESSION_ID, directory: '/repo' })
expect(call).toHaveBeenCalledWith({
@@ -64,7 +70,8 @@ describe('readSessionGoal', () => {
})
it('omits the location when no directory is provided', async () => {
const call = vi.fn().mockResolvedValue({ output: baseGoal })
const call = vi.fn<OpenCodeApi['rpc']['call']>().mockResolvedValue({ output: baseGoal })
await readSessionGoal(createApi(call), { sessionID: SESSION_ID })
expect(call).toHaveBeenCalledWith({
@@ -76,7 +83,8 @@ describe('readSessionGoal', () => {
})
it('returns the goal reported by the server', async () => {
const call = vi.fn().mockResolvedValue({ output: baseGoal })
const call = vi.fn<OpenCodeApi['rpc']['call']>().mockResolvedValue({ output: baseGoal })
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).resolves.toEqual({
supported: true,
goal: baseGoal,
@@ -84,7 +92,8 @@ describe('readSessionGoal', () => {
})
it('returns a null goal when the session has none', async () => {
const call = vi.fn().mockResolvedValue({})
const call = vi.fn<OpenCodeApi['rpc']['call']>().mockResolvedValue({})
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).resolves.toEqual({
supported: true,
goal: null,
@@ -92,107 +101,73 @@ describe('readSessionGoal', () => {
})
it.each([
['an unknown status', goalWith({ status: 'bogus' as GoalState['status'] })],
['an unknown status', goalPayload({ status: 'bogus' })],
['a missing objective', goalWithout('objective')],
['a non-object output', 'not a goal'],
])('reports a goal with %s as unsupported', async (_label, output) => {
const call = vi.fn().mockResolvedValue({ output })
const call = vi.fn<OpenCodeApi['rpc']['call']>().mockResolvedValue({ output })
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).resolves.toEqual({ supported: false })
})
it('reports an unavailable rpc as unsupported', async () => {
const call = vi.fn().mockRejectedValue(rpcError('rpc.unavailable', 'RPC is unavailable: opencode.goal'))
const call = vi
.fn<OpenCodeApi['rpc']['call']>()
.mockRejectedValue(rpcError('rpc.unavailable', 'RPC is unavailable: opencode.goal'))
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).resolves.toEqual({ supported: false })
})
it('rethrows every other error unchanged', async () => {
const error = rpcError('rpc.failed', 'boom')
const call = vi.fn().mockRejectedValue(error)
const call = vi.fn<OpenCodeApi['rpc']['call']>().mockRejectedValue(error)
await expect(readSessionGoal(createApi(call), { sessionID: SESSION_ID })).rejects.toBe(error)
})
})
describe('goalChangeFromEvent', () => {
it('accepts the goal changed event with a goal', () => {
expect(goalChangeFromEvent({ type: 'rpc.opencode.goal.changed', data: { sessionID: SESSION_ID, goal: baseGoal } })).toEqual({
sessionID: SESSION_ID,
goal: baseGoal,
})
expect(
goalChangeFromEvent({ type: GOAL_CHANGED_EVENT_TYPE, data: { sessionID: SESSION_ID, goal: baseGoal } }),
).toEqual({ sessionID: SESSION_ID, goal: baseGoal })
})
it('accepts the goal changed event with a cleared goal', () => {
expect(goalChangeFromEvent({ type: 'rpc.opencode.goal.changed', data: { sessionID: SESSION_ID, goal: null } })).toEqual({
sessionID: SESSION_ID,
goal: null,
})
expect(
goalChangeFromEvent({ type: GOAL_CHANGED_EVENT_TYPE, data: { sessionID: SESSION_ID, goal: null } }),
).toEqual({ sessionID: SESSION_ID, goal: null })
})
it('ignores other event types', () => {
expect(goalChangeFromEvent({ type: 'session.idle', data: { sessionID: SESSION_ID, goal: baseGoal } })).toBeNull()
})
it('ignores malformed data', () => {
const eventType = 'rpc.opencode.goal.changed'
expect(goalChangeFromEvent({ type: eventType, data: null })).toBeNull()
expect(goalChangeFromEvent({ type: eventType, data: { goal: baseGoal } })).toBeNull()
expect(goalChangeFromEvent({ type: eventType, data: { sessionID: 42, goal: baseGoal } })).toBeNull()
expect(goalChangeFromEvent({ type: eventType, data: { sessionID: SESSION_ID } })).toBeNull()
expect(goalChangeFromEvent({ type: eventType, data: { sessionID: SESSION_ID, goal: 'active' } })).toBeNull()
expect(goalChangeFromEvent({ type: eventType, data: { sessionID: SESSION_ID, goal: { objective: 'no status' } } })).toBeNull()
})
it('ignores a goal with a status outside the contract', () => {
expect(
goalChangeFromEvent({
type: 'rpc.opencode.goal.changed',
data: { sessionID: SESSION_ID, goal: goalWith({ status: 'stopped' as GoalState['status'] }) },
}),
).toBeNull()
})
it('ignores a goal without an objective', () => {
expect(
goalChangeFromEvent({
type: 'rpc.opencode.goal.changed',
data: { sessionID: SESSION_ID, goal: goalWithout('objective') },
}),
).toBeNull()
})
it('ignores a goal without an id', () => {
expect(
goalChangeFromEvent({
type: 'rpc.opencode.goal.changed',
data: { sessionID: SESSION_ID, goal: goalWithout('id') },
}),
).toBeNull()
})
it('ignores a goal whose rounds or maxRounds are not numbers', () => {
const eventType = 'rpc.opencode.goal.changed'
expect(
goalChangeFromEvent({
type: eventType,
data: { sessionID: SESSION_ID, goal: { ...baseGoal, rounds: '0' } },
}),
).toBeNull()
expect(
goalChangeFromEvent({
type: eventType,
data: { sessionID: SESSION_ID, goal: { ...baseGoal, maxRounds: null } },
}),
).toBeNull()
it.each([
['null data', null],
['a missing session id', { goal: baseGoal }],
['a non-string session id', { sessionID: 42, goal: baseGoal }],
['a missing goal', { sessionID: SESSION_ID }],
['a non-object goal', { sessionID: SESSION_ID, goal: 'active' }],
['a goal without a status', { sessionID: SESSION_ID, goal: { objective: 'no status' } }],
['a goal with an unknown status', { sessionID: SESSION_ID, goal: goalPayload({ status: 'stopped' }) }],
['a goal without an objective', { sessionID: SESSION_ID, goal: goalWithout('objective') }],
['a goal without an id', { sessionID: SESSION_ID, goal: goalWithout('id') }],
['a goal with a string rounds value', { sessionID: SESSION_ID, goal: goalPayload({ rounds: '0' }) }],
['a goal with a null maxRounds', { sessionID: SESSION_ID, goal: goalPayload({ maxRounds: null }) }],
])('ignores malformed data: %s', (_label, data) => {
expect(goalChangeFromEvent({ type: GOAL_CHANGED_EVENT_TYPE, data })).toBeNull()
})
})
describe('isGoalOpen', () => {
it('is true for active and paused goals', () => {
expect(isGoalOpen(goalWith({ status: 'active' }))).toBe(true)
expect(isGoalOpen(goalWith({ status: 'paused' }))).toBe(true)
expect(isGoalOpen(goalState('active'))).toBe(true)
expect(isGoalOpen(goalState('paused'))).toBe(true)
})
it('is false for complete, missing and undefined goals', () => {
expect(isGoalOpen(goalWith({ status: 'complete' }))).toBe(false)
expect(isGoalOpen(goalState('complete'))).toBe(false)
expect(isGoalOpen(null)).toBe(false)
expect(isGoalOpen(undefined)).toBe(false)
})
@@ -200,19 +175,18 @@ describe('isGoalOpen', () => {
describe('isGoalOutcome', () => {
it('is true for a complete goal', () => {
expect(isGoalOutcome(goalWith({ status: 'complete' }))).toBe(true)
expect(isGoalOutcome(goalState('complete'))).toBe(true)
})
it('is true for a paused goal that is not paused by the user', () => {
expect(isGoalOutcome(goalWith({ status: 'paused', reason: 'Reached the limit of 50 rounds' }))).toBe(true)
expect(isGoalOutcome(goalState('paused', { reason: 'Reached the limit of 50 rounds' }))).toBe(true)
})
it('is false for a goal paused by the user', () => {
expect(isGoalOutcome(goalWith({ status: 'paused', reason: 'Paused by the user' }))).toBe(false)
expect(isGoalOutcome(goalWith({ status: 'paused', reason: 'Stopped by the user' }))).toBe(false)
it.each(GOAL_USER_PAUSE_REASONS)('is false for the user pause reason %s', (reason) => {
expect(isGoalOutcome(goalState('paused', { reason }))).toBe(false)
})
it('is false for an active goal', () => {
expect(isGoalOutcome(goalWith({ status: 'active' }))).toBe(false)
expect(isGoalOutcome(goalState('active'))).toBe(false)
})
})