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
@@ -2,7 +2,7 @@ const { describe, test, expect, mock, beforeEach } = require("bun:test")
const { resolveCallableAgents, clearCallableAgentsCache } = require("./agent-resolver")
const { ALLOWED_AGENTS } = require("./constants")
function createMockClient(agents = []) {
function createMockClient(agents: Array<Record<string, string>> = []) {
return {
app: {
agents: mock(() => Promise.resolve({ data: agents })),
@@ -37,12 +37,12 @@ describe("call-omo-agent createOrGetSession", () => {
}
// when
const result = await createOrGetSession(args as any, toolContext as any, ctx as any)
const result = await createOrGetSession(testCoerce(args), testCoerce(toolContext), testCoerce(ctx))
// then
expect(result).toEqual({ sessionID: "ses_child", isNew: true })
expect(createCalls).toHaveLength(1)
const createBody = (createCalls[0] as any)?.body
const createBody = (testCoerce(createCalls[0]))?.body
expect(createBody?.parentID).toBe("ses_parent")
expect(createBody?.permission).toBeUndefined()
expect(subagentSessions.has("ses_child")).toBe(true)
@@ -19,7 +19,7 @@ describe("call-omo-agent resolveOrCreateSessionId", () => {
const { parentDirectory, contextDirectory } = options
const parentSessionData = parentDirectory ? { data: { directory: parentDirectory } } : { data: {} }
const ctx = {
const ctx = testCoerce<Parameters<typeof resolveOrCreateSessionId>[0]>({
directory: contextDirectory,
client: {
session: {
@@ -31,7 +31,7 @@ describe("call-omo-agent resolveOrCreateSessionId", () => {
},
},
},
} as unknown as Parameters<typeof resolveOrCreateSessionId>[0]
})
const args = {
description: "sync test",
@@ -389,7 +389,7 @@ describe("executeSync", () => {
}
//#when
await executeSync(args, toolContext, ctx as any, deps, undefined, spawnReservation)
await executeSync(args, toolContext, testCoerce(ctx), deps, undefined, spawnReservation)
//#then
expect(spawnReservation.commit).toHaveBeenCalledTimes(1)
+9 -1
View File
@@ -14,6 +14,10 @@ type SessionWithPromptAsync = {
promptAsync: (opts: { path: { id: string }; body: Record<string, unknown> }) => Promise<unknown>
}
function hasPromptAsync(session: PluginInput["client"]["session"]): session is PluginInput["client"]["session"] & SessionWithPromptAsync {
return "promptAsync" in session && typeof session.promptAsync === "function"
}
type ExecuteSyncDeps = {
createOrGetSession: typeof createOrGetSession
waitForCompletion: typeof waitForCompletion
@@ -102,7 +106,11 @@ export async function executeSync(
const normalizedSubagentType = stripAgentListSortPrefix(args.subagent_type)
try {
await (ctx.client.session as unknown as SessionWithPromptAsync).promptAsync({
if (!hasPromptAsync(ctx.client.session)) {
return `Error: Failed to send prompt: promptAsync is not available on this OpenCode client.\n\n<task_metadata>\nsession_id: ${sessionID}\n</task_metadata>`
}
await ctx.client.session.promptAsync({
path: { id: sessionID },
body: {
agent: normalizedSubagentType,