test(plugin): 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:22:30 +09:00
parent 0787867384
commit f05aeaa63a
10 changed files with 186 additions and 186 deletions
+4 -4
View File
@@ -56,13 +56,13 @@ function createMockHandlerArgs(overrides?: {
}) {
const appliedSessions: string[] = []
return {
ctx: { client: { tui: { showToast: async () => {} } } } as any,
pluginConfig: (overrides?.pluginConfig ?? {}) as any,
ctx: testCoerce({ client: { tui: { showToast: async () => {} } } }),
pluginConfig: testCoerce((overrides?.pluginConfig ?? {})),
firstMessageVariantGate: {
shouldOverride: () => overrides?.shouldOverride ?? false,
markApplied: (sessionID: string) => { appliedSessions.push(sessionID) },
},
hooks: {
hooks: testCoerce({
stopContinuationGuard: null,
backgroundNotificationHook: null,
keywordDetector: null,
@@ -70,7 +70,7 @@ function createMockHandlerArgs(overrides?: {
autoSlashCommand: null,
startWork: null,
ralphLoop: null,
} as any,
}),
_appliedSessions: appliedSessions,
}
}
+11 -11
View File
@@ -13,27 +13,27 @@ type EventHandlerInput = Parameters<ReturnType<typeof createEventHandler>>[0]
type ChatMessageHandlerArgs = Parameters<typeof createChatMessageHandler>[0]
function asEventHandlerInput(input: EventInput): EventHandlerInput {
return input as unknown as EventHandlerInput
return testCoerce<EventHandlerInput>(input)
}
function asEventHandlerContext(ctx: unknown): EventHandlerArgs["ctx"] {
return ctx as unknown as EventHandlerArgs["ctx"]
return testCoerce<EventHandlerArgs["ctx"]>(ctx)
}
function asPluginConfig(config: unknown): EventHandlerArgs["pluginConfig"] {
return config as unknown as EventHandlerArgs["pluginConfig"]
return testCoerce<EventHandlerArgs["pluginConfig"]>(config)
}
function asChatMessageHandlerContext(ctx: unknown): ChatMessageHandlerArgs["ctx"] {
return ctx as unknown as ChatMessageHandlerArgs["ctx"]
return testCoerce<ChatMessageHandlerArgs["ctx"]>(ctx)
}
function asChatPluginConfig(config: unknown): ChatMessageHandlerArgs["pluginConfig"] {
return config as unknown as ChatMessageHandlerArgs["pluginConfig"]
return testCoerce<ChatMessageHandlerArgs["pluginConfig"]>(config)
}
function createEventHandlerManagers(): EventHandlerArgs["managers"] {
return {
return testCoerce<EventHandlerArgs["managers"]>({
tmuxSessionManager: {
onSessionCreated: async () => {},
onSessionDeleted: async () => {},
@@ -41,17 +41,17 @@ function createEventHandlerManagers(): EventHandlerArgs["managers"] {
skillMcpManager: {
disconnectSession: async () => {},
},
} as unknown as EventHandlerArgs["managers"]
})
}
function createEventHandlerHooks(modelFallback: ReturnType<typeof createModelFallbackHook>): EventHandlerArgs["hooks"] {
return {
return testCoerce<EventHandlerArgs["hooks"]>({
modelFallback,
} as unknown as EventHandlerArgs["hooks"]
})
}
function createChatMessageHandlerHooks(modelFallback: ReturnType<typeof createModelFallbackHook>): ChatMessageHandlerArgs["hooks"] {
return {
return testCoerce<ChatMessageHandlerArgs["hooks"]>({
modelFallback,
stopContinuationGuard: null,
keywordDetector: null,
@@ -59,7 +59,7 @@ function createChatMessageHandlerHooks(modelFallback: ReturnType<typeof createMo
autoSlashCommand: null,
startWork: null,
ralphLoop: null,
} as unknown as ChatMessageHandlerArgs["hooks"]
})
}
let readConnectedProvidersCacheSpy: { mockRestore: () => void } | undefined
@@ -50,16 +50,16 @@ describe("createEventHandler - model-fallback auto-continuation pins agent/model
}
const handler = createEventHandler({
ctx: {
ctx: testCoerce({
directory: "/tmp",
client: { session: sessionClient },
} as any,
pluginConfig: (args?.pluginConfig ?? {}) as any,
}),
pluginConfig: testCoerce((args?.pluginConfig ?? {})),
firstMessageVariantGate: {
markSessionCreated: () => {},
clear: () => {},
},
managers: {
managers: testCoerce({
tmuxSessionManager: {
onSessionCreated: async () => {},
onSessionDeleted: async () => {},
@@ -67,8 +67,8 @@ describe("createEventHandler - model-fallback auto-continuation pins agent/model
skillMcpManager: {
disconnectSession: async () => {},
},
} as any,
hooks: args?.hooks ?? ({} as any),
}),
hooks: args?.hooks ?? (testCoerce({})),
})
return { handler, promptAsyncBodies, promptBodies }
+28 -28
View File
@@ -22,7 +22,7 @@ describe("createEventHandler - model fallback", () => {
const promptCalls: string[] = []
const handler = createEventHandler({
ctx: {
ctx: testCoerce({
directory: "/tmp",
client: {
session: {
@@ -36,13 +36,13 @@ describe("createEventHandler - model fallback", () => {
},
},
},
} as any,
pluginConfig: (args?.pluginConfig ?? {}) as any,
}),
pluginConfig: testCoerce((args?.pluginConfig ?? {})),
firstMessageVariantGate: {
markSessionCreated: () => {},
clear: () => {},
},
managers: {
managers: testCoerce({
tmuxSessionManager: {
onSessionCreated: async () => {},
onSessionDeleted: async () => {},
@@ -50,8 +50,8 @@ describe("createEventHandler - model fallback", () => {
skillMcpManager: {
disconnectSession: async () => {},
},
} as any,
hooks: args?.hooks ?? ({} as any),
}),
hooks: args?.hooks ?? (testCoerce({})),
})
return { handler, abortCalls, promptCalls }
@@ -148,19 +148,19 @@ describe("createEventHandler - model fallback", () => {
const { handler, abortCalls, promptCalls } = createHandler({ hooks: { modelFallback } })
const chatMessageHandler = createChatMessageHandler({
ctx: {
ctx: testCoerce({
client: {
tui: {
showToast: async () => ({}),
},
},
} as any,
pluginConfig: {} as any,
}),
pluginConfig: testCoerce({}),
firstMessageVariantGate: {
shouldOverride: () => false,
markApplied: () => {},
},
hooks: {
hooks: testCoerce({
modelFallback,
stopContinuationGuard: null,
keywordDetector: null,
@@ -168,7 +168,7 @@ describe("createEventHandler - model fallback", () => {
autoSlashCommand: null,
startWork: null,
ralphLoop: null,
} as any,
}),
})
await handler({
@@ -358,19 +358,19 @@ describe("createEventHandler - model fallback", () => {
const { handler, abortCalls, promptCalls } = createHandler({ hooks: { modelFallback }, pluginConfig })
const chatMessageHandler = createChatMessageHandler({
ctx: {
ctx: testCoerce({
client: {
tui: {
showToast: async () => ({}),
},
},
} as any,
pluginConfig: {} as any,
}),
pluginConfig: testCoerce({}),
firstMessageVariantGate: {
shouldOverride: () => false,
markApplied: () => {},
},
hooks: {
hooks: testCoerce({
modelFallback,
stopContinuationGuard: null,
keywordDetector: null,
@@ -378,7 +378,7 @@ describe("createEventHandler - model fallback", () => {
autoSlashCommand: null,
startWork: null,
ralphLoop: null,
} as any,
}),
})
await handler({
@@ -449,7 +449,7 @@ describe("createEventHandler - model fallback", () => {
setupConnectedProviderCacheMocks()
const eventHandler = createEventHandler({
ctx: {
ctx: testCoerce({
directory: "/tmp",
client: {
session: {
@@ -463,13 +463,13 @@ describe("createEventHandler - model fallback", () => {
},
},
},
} as any,
pluginConfig: {} as any,
}),
pluginConfig: testCoerce({}),
firstMessageVariantGate: {
markSessionCreated: () => {},
clear: () => {},
},
managers: {
managers: testCoerce({
tmuxSessionManager: {
onSessionCreated: async () => {},
onSessionDeleted: async () => {},
@@ -477,14 +477,14 @@ describe("createEventHandler - model fallback", () => {
skillMcpManager: {
disconnectSession: async () => {},
},
} as any,
hooks: {
}),
hooks: testCoerce({
modelFallback,
} as any,
}),
})
const chatMessageHandler = createChatMessageHandler({
ctx: {
ctx: testCoerce({
client: {
tui: {
showToast: async ({ body }: { body: { title?: string } }) => {
@@ -493,13 +493,13 @@ describe("createEventHandler - model fallback", () => {
},
},
},
} as any,
pluginConfig: {} as any,
}),
pluginConfig: testCoerce({}),
firstMessageVariantGate: {
shouldOverride: () => false,
markApplied: () => {},
},
hooks: {
hooks: testCoerce({
modelFallback,
stopContinuationGuard: null,
keywordDetector: null,
@@ -507,7 +507,7 @@ describe("createEventHandler - model fallback", () => {
autoSlashCommand: null,
startWork: null,
ralphLoop: null,
} as any,
}),
})
const triggerRetryCycle = async () => {
+13 -13
View File
@@ -18,42 +18,42 @@ type HarnessContext = EventHandlerArgs["ctx"] & RuntimeFallbackPluginInput
type HarnessEventInput = Parameters<ReturnType<typeof createHarness>["eventHandler"]>[0]
function asHarnessEventInput(input: unknown): HarnessEventInput {
return input as unknown as HarnessEventInput
return testCoerce<HarnessEventInput>(input)
}
function asHarnessContext(ctx: unknown): HarnessContext {
return ctx as unknown as HarnessContext
return testCoerce<HarnessContext>(ctx)
}
function createEventHandlerManagers(
overrides: Record<string, unknown> = {},
): EventHandlerArgs["managers"] {
return {
return testCoerce<EventHandlerArgs["managers"]>({
...({} as EventHandlerArgs["managers"]),
tmuxSessionManager: {
onSessionCreated: async () => {},
onSessionDeleted: async () => {},
},
...overrides,
} as unknown as EventHandlerArgs["managers"]
})
}
function createEventHandlerHooks(
overrides: Record<string, unknown>,
): EventHandlerArgs["hooks"] {
return {
return testCoerce<EventHandlerArgs["hooks"]>({
...({} as EventHandlerArgs["hooks"]),
...overrides,
} as unknown as EventHandlerArgs["hooks"]
})
}
function createChatMessageHandlerHooks(
overrides: Record<string, unknown>,
): ChatMessageHandlerArgs["hooks"] {
return {
return testCoerce<ChatMessageHandlerArgs["hooks"]>({
...({} as ChatMessageHandlerArgs["hooks"]),
...overrides,
} as unknown as ChatMessageHandlerArgs["hooks"]
})
}
const PRIMARY_MODEL = {
@@ -87,7 +87,7 @@ let readConnectedProvidersCacheSpy: { mockRestore: () => void } | undefined
let readProviderModelsCacheSpy: { mockRestore: () => void } | undefined
function createPluginConfig(mode: HarnessMode) {
return {
return testCoerce<EventHandlerArgs["pluginConfig"]>({
agents: {
sisyphus: {
fallback_models: CLIPROXYAPI_FALLBACKS,
@@ -100,7 +100,7 @@ function createPluginConfig(mode: HarnessMode) {
},
}
: {}),
} as unknown as EventHandlerArgs["pluginConfig"]
})
}
function createHarness(args: {
@@ -187,14 +187,14 @@ function createHarness(args: {
timeout_seconds: args.sessionTimeoutMs ? 30 : 0,
notify_on_fallback: false,
},
pluginConfig: pluginConfig as unknown as EventHandlerArgs["pluginConfig"],
pluginConfig: testCoerce<EventHandlerArgs["pluginConfig"]>(pluginConfig),
...(args.sessionTimeoutMs ? { session_timeout_ms: args.sessionTimeoutMs } : {}),
})
}
const eventHandler = createEventHandler({
ctx,
pluginConfig: pluginConfig as unknown as EventHandlerArgs["pluginConfig"],
pluginConfig: testCoerce<EventHandlerArgs["pluginConfig"]>(pluginConfig),
firstMessageVariantGate: {
markSessionCreated: () => {},
clear: () => {},
@@ -209,7 +209,7 @@ function createHarness(args: {
const chatMessageHandler = createChatMessageHandler({
ctx,
pluginConfig: pluginConfig as unknown as ChatMessageHandlerArgs["pluginConfig"],
pluginConfig: testCoerce<ChatMessageHandlerArgs["pluginConfig"]>(pluginConfig),
firstMessageVariantGate: {
shouldOverride: () => false,
markApplied: () => {},
@@ -4,7 +4,7 @@ import type { ModelCacheState } from "../../plugin-state"
import type { PluginContext } from "../types"
import { createSessionHooks } from "./create-session-hooks"
const mockContext = {
const mockContext = testCoerce<PluginContext>({
directory: "/tmp",
client: {
tui: {
@@ -15,7 +15,7 @@ const mockContext = {
update: async () => ({}),
},
},
} as unknown as PluginContext
})
const mockModelCacheState = {} as ModelCacheState
+11 -11
View File
@@ -56,7 +56,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
})
const handler = createToolExecuteBeforeHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteBeforeHandler>[0]["hooks"],
})
const output = { args: createOracleTaskArgs("Check it") }
@@ -78,7 +78,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
const directory = join(tmpdir(), `tool-before-ulw-${Date.now()}-plain`)
mkdirSync(directory, { recursive: true })
const handler = createToolExecuteBeforeHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteBeforeHandler>[0]["hooks"],
})
const output = { args: createOracleTaskArgs("Check it") }
@@ -96,8 +96,8 @@ describe("tool.execute.before ultrawork oracle verification", () => {
mkdirSync(directory, { recursive: true })
const startLoopCalls: Array<{ sessionID: string; prompt: string; options: Record<string, unknown> }> = []
const handler = createToolExecuteBeforeHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"],
hooks: {
ctx: testCoerce<Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"]>(createCtx(directory)),
hooks: testCoerce<Parameters<typeof createToolExecuteBeforeHandler>[0]["hooks"]>({
ralphLoop: {
startLoop: (sessionID: string, prompt: string, options?: Record<string, unknown>) => {
startLoopCalls.push({ sessionID, prompt, options: options ?? {} })
@@ -106,7 +106,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
cancelLoop: () => true,
getState: () => null,
},
} as unknown as Parameters<typeof createToolExecuteBeforeHandler>[0]["hooks"],
}),
})
const output = {
args: {
@@ -148,7 +148,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
})
const beforeHandler = createToolExecuteBeforeHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteBeforeHandler>[0]["hooks"],
})
const beforeOutput = { args: createOracleTaskArgs("Check it") }
@@ -156,7 +156,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
const metadataFromSyncTask = createSyncTaskMetadata(beforeOutput.args, "ses-oracle")
const handler = createToolExecuteAfterHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteAfterHandler>[0]["hooks"],
})
@@ -191,7 +191,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
})
const handler = createToolExecuteAfterHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteAfterHandler>[0]["hooks"],
})
@@ -230,7 +230,7 @@ describe("tool.execute.before ultrawork oracle verification", () => {
})
const handler = createToolExecuteAfterHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteAfterHandler>[0]["hooks"],
})
@@ -269,11 +269,11 @@ describe("tool.execute.before ultrawork oracle verification", () => {
})
const beforeHandler = createToolExecuteBeforeHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteBeforeHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteBeforeHandler>[0]["hooks"],
})
const afterHandler = createToolExecuteAfterHandler({
ctx: createCtx(directory) as unknown as Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"],
ctx: testCoerce<Parameters<typeof createToolExecuteAfterHandler>[0]["ctx"]>(createCtx(directory)),
hooks: {} as Parameters<typeof createToolExecuteAfterHandler>[0]["hooks"],
})
+6 -6
View File
@@ -70,11 +70,11 @@ describe("resolveUltraworkOverride", () => {
}
function createConfig(agentName: string, ultrawork: { model?: string; variant?: string }) {
return {
return testCoerce<Parameters<typeof resolveUltraworkOverride>[0]>({
agents: {
[agentName]: { ultrawork },
},
} as unknown as Parameters<typeof resolveUltraworkOverride>[0]
})
}
test("should resolve override when ultrawork keyword detected", () => {
@@ -139,9 +139,9 @@ describe("resolveUltraworkOverride", () => {
test("should return null when agent has no ultrawork config", () => {
//#given
const config = {
const config = testCoerce<Parameters<typeof resolveUltraworkOverride>[0]>({
agents: { sisyphus: { model: "anthropic/claude-sonnet-4-6" } },
} as unknown as Parameters<typeof resolveUltraworkOverride>[0]
})
const output = createOutput("ultrawork do something")
//#when
@@ -278,11 +278,11 @@ describe("applyUltraworkModelOverrideOnMessage", () => {
}
function createConfig(agentName: string, ultrawork: { model?: string; variant?: string }) {
return {
return testCoerce<Parameters<typeof applyUltraworkModelOverrideOnMessage>[0]>({
agents: {
[agentName]: { ultrawork },
},
} as unknown as Parameters<typeof applyUltraworkModelOverrideOnMessage>[0]
})
}
test("should schedule deferred DB override without variant when SDK unavailable", () => {