test(tools): remove unsafe test assertions

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-12 14:23:05 +09:00
parent 8b093a1115
commit fb135d047c
24 changed files with 199 additions and 156 deletions
+21 -10
View File
@@ -1,7 +1,25 @@
import type { OpencodeClient } from "./types"
import { log } from "../../shared/logger"
import { isRecord } from "../../shared/record-type-guard"
import { readConnectedProvidersCache, readProviderModelsCache } from "../../shared/connected-providers-cache"
type ModelListClient = OpencodeClient & {
model: { list: () => Promise<unknown> }
}
function hasModelList(client: OpencodeClient): client is ModelListClient {
return "model" in client && isRecord(client.model) && typeof client.model.list === "function"
}
function isModelRow(value: unknown): value is { provider: string; id: string } {
return isRecord(value) && typeof value.provider === "string" && typeof value.id === "string"
}
function extractModelRows(result: unknown): Array<{ provider: string; id: string }> {
const rows = Array.isArray(result) ? result : isRecord(result) && Array.isArray(result.data) ? result.data : []
return rows.filter(isModelRow)
}
function addFromProviderModels(
out: Set<string>,
providerID: string,
@@ -35,24 +53,17 @@ export async function getAvailableModelsForDelegateTask(client: OpencodeClient):
return new Set()
}
const modelList = (client as unknown as { model?: { list?: () => Promise<unknown> } })
?.model
?.list
if (!modelList) {
if (!hasModelList(client)) {
return new Set()
}
try {
const result = await modelList()
const rows = Array.isArray(result)
? result
: ((result as { data?: unknown }).data as Array<{ provider?: string; id?: string }> | undefined) ?? []
const result = await client.model.list()
const rows = extractModelRows(result)
const connected = new Set(connectedProviders)
const out = new Set<string>()
for (const row of rows) {
if (!row?.provider || !row?.id) continue
if (!connected.has(row.provider)) continue
out.add(`${row.provider}/${row.id}`)
}
@@ -26,8 +26,8 @@ describe("resolveCategoryExecution", () => {
})
const createMockExecutorContext = (): ExecutorContext => ({
client: {} as any,
manager: {} as any,
client: testCoerce({}),
manager: testCoerce({}),
directory: "/tmp/test",
userCategories: {},
sisyphusJuniorModel: undefined,
@@ -28,7 +28,7 @@ describe("task tool metadata awaiting", () => {
subagent_type: "explore",
}
const executorCtx = {
const executorCtx = testCoerce({
manager: {
launch: async () => ({
id: "task_1",
@@ -40,7 +40,7 @@ describe("task tool metadata awaiting", () => {
}),
getTask: () => undefined,
},
} as any
})
const parentContext = {
sessionID: "ses_parent",
@@ -63,7 +63,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, {
await executeBackgroundTask(args, ctx, testCoerce({
manager: {
launch: async () => ({
id: "bg_1", description: "test", agent: "explore",
@@ -71,7 +71,7 @@ describe("metadata model unification", () => {
}),
getTask: () => undefined,
},
} as any, parentContext, "explore", MODEL, undefined)
}), parentContext, "explore", MODEL, undefined)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -92,7 +92,7 @@ describe("metadata model unification", () => {
}
await executeUnstableAgentTask(
args, ctx,
{
testCoerce({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -109,7 +109,7 @@ describe("metadata model unification", () => {
},
},
syncPollTimeoutMs: 100,
} as any,
}),
parentContext, "explore", MODEL, undefined, "anthropic/claude-sonnet-4-6",
)
@@ -126,14 +126,14 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_2", description: "continue", agent: "explore",
status: "running", sessionId: "ses_resumed", model: MODEL,
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -153,7 +153,7 @@ describe("metadata model unification", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -162,7 +162,7 @@ describe("metadata model unification", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -206,7 +206,7 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, {
await executeBackgroundTask(args, ctx, testCoerce({
manager: {
launch: async () => ({
id: "bg_1", description: "test", agent: "explore",
@@ -214,7 +214,7 @@ describe("metadata model unification", () => {
}),
getTask: () => undefined,
},
} as any, parentContext, "explore", undefined, undefined)
}), parentContext, "explore", undefined, undefined)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -236,7 +236,7 @@ describe("metadata model unification", () => {
await executeUnstableAgentTask(
args, ctx,
{
testCoerce({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -253,7 +253,7 @@ describe("metadata model unification", () => {
},
},
syncPollTimeoutMs: 100,
} as any,
}),
parentContext, "explore", undefined, undefined, "anthropic/claude-sonnet-4-6",
)
@@ -270,14 +270,14 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_2", description: "continue", agent: "explore",
status: "running", sessionId: "ses_resumed",
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -297,14 +297,14 @@ describe("metadata model unification", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({ data: [] }),
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -381,7 +381,7 @@ describe("metadata model unification", () => {
category: "visual-engineering", load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, {
await executeBackgroundTask(args, ctx, testCoerce({
manager: {
launch: async () => ({
id: "bg_variant", description: "test", agent: "explore",
@@ -389,7 +389,7 @@ describe("metadata model unification", () => {
}),
getTask: () => undefined,
},
} as any, parentContext, "explore", MODEL_WITH_VARIANT, undefined)
}), parentContext, "explore", MODEL_WITH_VARIANT, undefined)
const meta = ctx.captured.find((metadataEvent: any) => metadataEvent.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -411,7 +411,7 @@ describe("metadata model unification", () => {
await executeUnstableAgentTask(
args, ctx,
{
testCoerce({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -428,7 +428,7 @@ describe("metadata model unification", () => {
},
},
syncPollTimeoutMs: 100,
} as any,
}),
parentContext, "explore", MODEL_WITH_VARIANT, undefined, "google/gemini-3.1-pro high",
)
@@ -445,14 +445,14 @@ describe("metadata model unification", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed_variant",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_resume_variant", description: "continue", agent: "explore",
status: "running", sessionId: "ses_resumed_variant", model: MODEL_WITH_VARIANT,
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((metadataEvent: any) => metadataEvent.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -472,7 +472,7 @@ describe("metadata model unification", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -481,7 +481,7 @@ describe("metadata model unification", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((metadataEvent: any) => metadataEvent.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -64,7 +64,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, subagent_type: "explore",
}
await executeBackgroundTask(args, ctx, {
await executeBackgroundTask(args, ctx, testCoerce({
manager: {
launch: async () => ({
id: "bg_abc123", description: "test", agent: "explore",
@@ -72,7 +72,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
}),
getTask: () => undefined,
},
} as any, parentContext, "explore", MODEL, undefined)
}), parentContext, "explore", MODEL, undefined)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -98,7 +98,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
await executeUnstableAgentTask(
args, ctx,
{
testCoerce({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -115,7 +115,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
},
},
syncPollTimeoutMs: 100,
} as any,
}),
parentContext, "explore", MODEL, undefined, "anthropic/claude-sonnet-4-6",
)
@@ -136,14 +136,14 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed_x",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_resumed_y", description: "continue", agent: "explore",
status: "running", sessionId: "ses_resumed_x", model: MODEL,
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -160,14 +160,14 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, task_id: "ses_resumed_x",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_resumed_y", description: "continue", agent: "explore",
status: "running", sessionId: "ses_resumed_x", model: MODEL, category: "deep",
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -187,14 +187,14 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
task_id: "ses_resumed_x",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_resumed_y", description: "continue", agent: "explore",
status: "running", sessionId: "ses_resumed_x", model: MODEL,
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -216,7 +216,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -225,7 +225,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((m: any) => m.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -246,7 +246,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -255,7 +255,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -275,7 +275,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -284,7 +284,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -309,7 +309,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -318,7 +318,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, deps)
}), parentContext, deps)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -368,7 +368,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
run_in_background: true,
}
await executeBackgroundTask(args, ctx, {
await executeBackgroundTask(args, ctx, testCoerce({
manager: {
launch: async () => ({
id: "bg_abc123", description: "test", agent: "Sisyphus-Junior",
@@ -376,7 +376,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
}),
getTask: () => undefined,
},
} as any, parentContext, "Sisyphus-Junior", MODEL, undefined)
}), parentContext, "Sisyphus-Junior", MODEL, undefined)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -402,7 +402,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
await executeUnstableAgentTask(
args, ctx,
{
testCoerce({
manager: {
launch: async () => launchedTask,
getTask: () => launchedTask,
@@ -419,7 +419,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
},
},
syncPollTimeoutMs: 100,
} as any,
}),
parentContext, "Sisyphus-Junior", MODEL, undefined, "anthropic/claude-sonnet-4-6",
)
@@ -438,14 +438,14 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: true, task_id: "ses_resume_title",
}
await executeBackgroundContinuation(args, ctx, {
await executeBackgroundContinuation(args, ctx, testCoerce({
manager: {
resume: async () => ({
id: "bg_resume_title", description: "continue work", agent: "explore",
status: "running", sessionId: "ses_resume_title", model: MODEL,
}),
},
} as any, parentContext)
}), parentContext)
const meta = ctx.captured.find((item: any) => item.metadata?.sessionId)
expect(meta).toBeDefined()
@@ -460,7 +460,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
load_skills: [], run_in_background: false, task_id: "ses_sync_title",
}
await executeSyncContinuation(args, ctx, {
await executeSyncContinuation(args, ctx, testCoerce({
client: {
session: {
messages: async () => ({
@@ -469,7 +469,7 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
prompt: async () => ({}),
},
},
} as any, parentContext, {
}), parentContext, {
pollSyncSession: async () => null,
fetchSyncResult: async () => ({ ok: true as const, textContent: "done" }),
})
@@ -500,8 +500,8 @@ describe("taskId and backgroundTaskId metadata consistency", () => {
},
}
const bgOutput = createBackgroundOutput(manager as any, client as any)
await bgOutput.execute({ task_id: "bg_output_xyz" } as any, ctx as any)
const bgOutput = createBackgroundOutput(testCoerce(manager), testCoerce(client))
await bgOutput.execute(testCoerce({ task_id: "bg_output_xyz" }), testCoerce(ctx))
const meta = ctx.captured.find((m: any) => m.metadata?.backgroundTaskId)
expect(meta).toBeDefined()
+2 -2
View File
@@ -18,14 +18,14 @@ function createDelegateTask(...args: Parameters<typeof import("./tools").createD
const toolDefinition = createDelegateTask({ manager: {} as never, client: {} as never, directory: "/tmp/test" })
//#when
const categorySchema = toolDefinition.args.category as unknown as {
const categorySchema = testCoerce<{
def: {
type: string
innerType: {
def: { type: string }
}
}
}
}>(toolDefinition.args.category)
//#then
expect(categorySchema.def.type).toBe("optional")
@@ -33,7 +33,7 @@ describe("executeUnstableAgentTask session permission", () => {
metadata: () => {},
abort: new AbortController().signal,
} satisfies Parameters<typeof executeUnstableAgentTask>[1]
const executorContext = {
const executorContext = testCoerce<Parameters<typeof executeUnstableAgentTask>[2]>({
manager: mockManager,
client: {
session: {
@@ -41,7 +41,7 @@ describe("executeUnstableAgentTask session permission", () => {
messages: async () => ({ data: [] }),
},
},
} as unknown as Parameters<typeof executeUnstableAgentTask>[2]
})
const parentContext = {
sessionID: "parent-session",
messageID: "msg_parent",