test(features): 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:21:46 +09:00
parent 7365163885
commit 11b3638493
13 changed files with 87 additions and 80 deletions
@@ -134,7 +134,7 @@ Use \`background_output(task_id="<id>")\` to retrieve each result.
const notification = buildBackgroundTaskNotificationText({
task: {
id: "bg_abc123",
description: undefined as unknown as string,
description: testCoerce<string>(undefined),
status: "completed",
},
duration: "5s",
@@ -142,8 +142,8 @@ Use \`background_output(task_id="<id>")\` to retrieve each result.
allComplete: true,
remainingCount: 0,
completedTasks: [
{ id: "bg_abc123", description: undefined as unknown as string, status: "completed" },
{ id: "bg_def456", description: undefined as unknown as string, status: "completed" },
{ id: "bg_abc123", description: testCoerce<string>(undefined), status: "completed" },
{ id: "bg_def456", description: testCoerce<string>(undefined), status: "completed" },
],
})
@@ -230,7 +230,7 @@ Use \`background_output(task_id="<id>")\` to retrieve each result.
const notification = buildBackgroundTaskNotificationText({
task: {
id: "bg_xyz789",
description: undefined as unknown as string,
description: testCoerce<string>(undefined),
status: "completed",
},
duration: "3s",
@@ -49,7 +49,7 @@ describe("isCompactionAgent", () => {
test("returns false for null", () => {
// when
const result = isCompactionAgent(null as unknown as string)
const result = isCompactionAgent(testCoerce<string>(null))
// then
expect(result).toBe(false)
@@ -16,12 +16,12 @@ function createManager(config?: BackgroundTaskConfig): BackgroundManager {
},
}
const manager = new BackgroundManager({ pluginContext: { client, directory: tmpdir() } as unknown as PluginInput, config: config })
const testManager = manager as unknown as {
const manager = new BackgroundManager({ pluginContext: testCoerce<PluginInput>({ client, directory: tmpdir() }), config: config })
const testManager = testCoerce<{
enqueueNotificationForParent: (sessionId: string, fn: () => Promise<void>) => Promise<void>
notifyParentSession: (task: BackgroundTask) => Promise<void>
tasks: Map<string, BackgroundTask>
}
}>(manager)
testManager.enqueueNotificationForParent = async (_sessionId: string, fn) => {
await fn()
@@ -32,7 +32,7 @@ function createManager(config?: BackgroundTaskConfig): BackgroundManager {
}
function getTaskMap(manager: BackgroundManager): Map<string, BackgroundTask> {
return (manager as unknown as { tasks: Map<string, BackgroundTask> }).tasks
return (testCoerce<{ tasks: Map<string, BackgroundTask> }>(manager)).tasks
}
async function flushAsyncWork() {
@@ -21,7 +21,7 @@ describe("BackgroundManager session permission", () => {
},
}
const directory = tmpdir()
const manager = new BackgroundManager({ pluginContext: { client, directory } as unknown as PluginInput })
const manager = new BackgroundManager({ pluginContext: testCoerce<PluginInput>({ client, directory }) })
// when
await manager.launch({
@@ -62,7 +62,7 @@ describe("BackgroundManager session permission", () => {
abort: async () => ({}),
},
}
const manager = new BackgroundManager({ pluginContext: { client, directory: tmpdir() } as unknown as PluginInput })
const manager = new BackgroundManager({ pluginContext: testCoerce<PluginInput>({ client, directory: tmpdir() }) })
// when
await manager.launch({
@@ -7,11 +7,11 @@ describe("verifySessionExists", () => {
test("passes query directory to session lookup when provided", async () => {
// given
const get = mock(async () => ({ data: { id: "session-123" } }))
const client = {
const client = testCoerce<OpencodeClient>({
session: {
get,
},
} as unknown as OpencodeClient
})
// when
const result = await verifySessionExists(client, "session-123", "/project/root")
@@ -20,14 +20,14 @@ describe("resolveSubagentSpawnContext", () => {
test("passes query.directory to each session.get call", async () => {
// given
const sessionGetCalls: Array<Record<string, unknown>> = []
const client = createMockClient((async (input) => {
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async (input) => {
sessionGetCalls.push(input as Record<string, unknown>)
if (input.path.id === "child-session") {
return { data: { id: "child-session", parentID: "root-session" } }
}
return { data: { id: "root-session", parentID: undefined } }
}) as unknown as OpencodeClient["session"]["get"])
})))
// when
const result = await resolveSubagentSpawnContext(client, "child-session", "/project/root")
@@ -50,10 +50,10 @@ describe("resolveSubagentSpawnContext", () => {
describe("#given session.get returns an SDK error response", () => {
test("throws a fail-closed spawn blocked error", async () => {
// given
const client = createMockClient((async () => ({
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async () => ({
error: "lookup failed",
data: undefined,
})) as unknown as OpencodeClient["session"]["get"])
}))))
// when
const result = resolveSubagentSpawnContext(client, "parent-session")
@@ -66,9 +66,9 @@ describe("resolveSubagentSpawnContext", () => {
describe("#given session.get returns no session data", () => {
test("throws a fail-closed spawn blocked error", async () => {
// given
const client = createMockClient((async () => ({
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async () => ({
data: undefined,
})) as unknown as OpencodeClient["session"]["get"])
}))))
// when
const result = resolveSubagentSpawnContext(client, "parent-session")
@@ -81,12 +81,12 @@ describe("resolveSubagentSpawnContext", () => {
describe("depth calculation smoke tests (regression guard)", () => {
test("root session (no parentID) reports depth 0 and childDepth 1", async () => {
// given - a root session with no parent
const client = createMockClient((async (opts) => {
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async (opts) => {
if (opts.path.id === "root-session") {
return { data: { id: "root-session", parentID: undefined } }
}
return { error: "not found", data: undefined }
}) as unknown as OpencodeClient["session"]["get"])
})))
// when
const result = await resolveSubagentSpawnContext(client, "root-session")
@@ -99,7 +99,7 @@ describe("resolveSubagentSpawnContext", () => {
test("depth-1 child reports childDepth 2", async () => {
// given - child -> root chain
const client = createMockClient((async (opts) => {
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async (opts) => {
if (opts.path.id === "child-1") {
return { data: { id: "child-1", parentID: "root-session" } }
}
@@ -107,7 +107,7 @@ describe("resolveSubagentSpawnContext", () => {
return { data: { id: "root-session", parentID: undefined } }
}
return { error: "not found", data: undefined }
}) as unknown as OpencodeClient["session"]["get"])
})))
// when
const result = await resolveSubagentSpawnContext(client, "child-1")
@@ -120,7 +120,7 @@ describe("resolveSubagentSpawnContext", () => {
test("depth-2 grandchild reports childDepth 3", async () => {
// given - grandchild -> child -> root chain
const client = createMockClient((async (opts) => {
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async (opts) => {
const sessions: Record<string, { id: string; parentID?: string }> = {
"grandchild": { id: "grandchild", parentID: "child" },
"child": { id: "child", parentID: "root" },
@@ -129,7 +129,7 @@ describe("resolveSubagentSpawnContext", () => {
const session = sessions[opts.path.id]
if (session) return { data: session }
return { error: "not found", data: undefined }
}) as unknown as OpencodeClient["session"]["get"])
})))
// when
const result = await resolveSubagentSpawnContext(client, "grandchild")
@@ -153,11 +153,11 @@ describe("resolveSubagentSpawnContext", () => {
}
}
const client = createMockClient((async (opts) => {
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async (opts) => {
const session = sessions[opts.path.id]
if (session) return { data: session }
return { error: "not found", data: undefined }
}) as unknown as OpencodeClient["session"]["get"])
})))
// when - resolve from the deepest session
const deepest = `session-${DEFAULT_MAX_SUBAGENT_DEPTH}`
@@ -170,7 +170,7 @@ describe("resolveSubagentSpawnContext", () => {
test("detects parent cycle and throws", async () => {
// given - A -> B -> A (cycle)
const client = createMockClient((async (opts) => {
const client = createMockClient(testCoerce<OpencodeClient["session"]["get"]>((async (opts) => {
const sessions: Record<string, { id: string; parentID?: string }> = {
"session-a": { id: "session-a", parentID: "session-b" },
"session-b": { id: "session-b", parentID: "session-a" },
@@ -178,7 +178,7 @@ describe("resolveSubagentSpawnContext", () => {
const session = sessions[opts.path.id]
if (session) return { data: session }
return { error: "not found", data: undefined }
}) as unknown as OpencodeClient["session"]["get"])
})))
// when
const result = resolveSubagentSpawnContext(client, "session-a")