test(call-omo-agent): align background task fixtures with normalized field names
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -7,13 +7,13 @@ import { executeBackgroundAgent } from "./background-agent-executor"
|
|||||||
describe("executeBackgroundAgent", () => {
|
describe("executeBackgroundAgent", () => {
|
||||||
const launchMock = mock(async (): Promise<{
|
const launchMock = mock(async (): Promise<{
|
||||||
id: string
|
id: string
|
||||||
sessionID: string | null
|
sessionId: string | null
|
||||||
description: string
|
description: string
|
||||||
agent: string
|
agent: string
|
||||||
status: string
|
status: string
|
||||||
}> => ({
|
}> => ({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -23,7 +23,7 @@ describe("executeBackgroundAgent", () => {
|
|||||||
const mockManager = {
|
const mockManager = {
|
||||||
launch: launchMock,
|
launch: launchMock,
|
||||||
getTask: getTaskMock,
|
getTask: getTaskMock,
|
||||||
} as unknown as BackgroundManager
|
} as BackgroundManager
|
||||||
|
|
||||||
const testContext = {
|
const testContext = {
|
||||||
sessionID: "test-session",
|
sessionID: "test-session",
|
||||||
@@ -43,20 +43,20 @@ describe("executeBackgroundAgent", () => {
|
|||||||
session: {
|
session: {
|
||||||
messages: mock(() => Promise.resolve({ data: [] })),
|
messages: mock(() => Promise.resolve({ data: [] })),
|
||||||
},
|
},
|
||||||
} as unknown as PluginInput["client"]
|
} as PluginInput["client"]
|
||||||
|
|
||||||
test("detects interrupted task as failure", async () => {
|
test("detects interrupted task as failure", async () => {
|
||||||
//#given
|
//#given
|
||||||
launchMock.mockResolvedValueOnce({
|
launchMock.mockResolvedValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})
|
})
|
||||||
getTaskMock.mockReturnValueOnce({
|
getTaskMock.mockReturnValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "interrupt",
|
status: "interrupt",
|
||||||
@@ -76,14 +76,14 @@ describe("executeBackgroundAgent", () => {
|
|||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
launchMock.mockResolvedValueOnce({
|
launchMock.mockResolvedValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})
|
})
|
||||||
getTaskMock.mockImplementationOnce(() => {
|
getTaskMock.mockImplementationOnce(() => {
|
||||||
abortController.abort()
|
abortController.abort()
|
||||||
return { id: "test-task-id", sessionID: null, description: "Test task", agent: "test-agent", status: "pending" }
|
return { id: "test-task-id", sessionId: null, description: "Test task", agent: "test-agent", status: "pending" }
|
||||||
})
|
})
|
||||||
|
|
||||||
//#when
|
//#when
|
||||||
@@ -108,15 +108,15 @@ describe("executeBackgroundAgent", () => {
|
|||||||
const firstAbortController = new AbortController()
|
const firstAbortController = new AbortController()
|
||||||
const secondAbortController = new AbortController()
|
const secondAbortController = new AbortController()
|
||||||
const states = new Map([
|
const states = new Map([
|
||||||
["task-1", { reads: 0, abortOnFirstRead: true, sessionID: "ses-1" }],
|
["task-1", { reads: 0, abortOnFirstRead: true, sessionId: "ses-1" }],
|
||||||
["task-2", { reads: 0, abortOnFirstRead: false, sessionID: "ses-2" }],
|
["task-2", { reads: 0, abortOnFirstRead: false, sessionId: "ses-2" }],
|
||||||
])
|
])
|
||||||
let launchCount = 0
|
let launchCount = 0
|
||||||
launchMock.mockImplementation(async () => {
|
launchMock.mockImplementation(async () => {
|
||||||
launchCount += 1
|
launchCount += 1
|
||||||
return launchCount === 1
|
return launchCount === 1
|
||||||
? { id: "task-1", sessionID: null, description: "Task 1", agent: "test-agent", status: "pending" }
|
? { id: "task-1", sessionId: null, description: "Task 1", agent: "test-agent", status: "pending" }
|
||||||
: { id: "task-2", sessionID: null, description: "Task 2", agent: "test-agent", status: "pending" }
|
: { id: "task-2", sessionId: null, description: "Task 2", agent: "test-agent", status: "pending" }
|
||||||
})
|
})
|
||||||
getTaskMock.mockImplementation((taskID: string) => {
|
getTaskMock.mockImplementation((taskID: string) => {
|
||||||
const state = states.get(taskID)
|
const state = states.get(taskID)
|
||||||
@@ -126,8 +126,8 @@ describe("executeBackgroundAgent", () => {
|
|||||||
firstAbortController.abort()
|
firstAbortController.abort()
|
||||||
}
|
}
|
||||||
return state.reads >= 2
|
return state.reads >= 2
|
||||||
? { id: taskID, sessionID: state.sessionID, description: "Task", agent: "test-agent", status: "pending" }
|
? { id: taskID, sessionId: state.sessionId, description: "Task", agent: "test-agent", status: "pending" }
|
||||||
: { id: taskID, sessionID: null, description: "Task", agent: "test-agent", status: "pending" }
|
: { id: taskID, sessionId: null, description: "Task", agent: "test-agent", status: "pending" }
|
||||||
})
|
})
|
||||||
|
|
||||||
//#when
|
//#when
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ import { executeBackground } from "./background-executor"
|
|||||||
describe("executeBackground", () => {
|
describe("executeBackground", () => {
|
||||||
const launchMock = mock(async (_input?: { fallbackChain?: unknown }): Promise<{
|
const launchMock = mock(async (_input?: { fallbackChain?: unknown }): Promise<{
|
||||||
id: string
|
id: string
|
||||||
sessionID: string | null
|
sessionId: string | null
|
||||||
description: string
|
description: string
|
||||||
agent: string
|
agent: string
|
||||||
status: string
|
status: string
|
||||||
}> => ({
|
}> => ({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -23,7 +23,7 @@ describe("executeBackground", () => {
|
|||||||
const mockManager = {
|
const mockManager = {
|
||||||
launch: launchMock,
|
launch: launchMock,
|
||||||
getTask: getTaskMock,
|
getTask: getTaskMock,
|
||||||
} as unknown as BackgroundManager
|
} as BackgroundManager
|
||||||
|
|
||||||
const testContext = {
|
const testContext = {
|
||||||
sessionID: "test-session",
|
sessionID: "test-session",
|
||||||
@@ -43,20 +43,20 @@ describe("executeBackground", () => {
|
|||||||
session: {
|
session: {
|
||||||
messages: mock(() => Promise.resolve({ data: [] })),
|
messages: mock(() => Promise.resolve({ data: [] })),
|
||||||
},
|
},
|
||||||
} as unknown as PluginInput["client"]
|
} as PluginInput["client"]
|
||||||
|
|
||||||
test("detects interrupted task as failure", async () => {
|
test("detects interrupted task as failure", async () => {
|
||||||
//#given
|
//#given
|
||||||
launchMock.mockResolvedValueOnce({
|
launchMock.mockResolvedValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})
|
})
|
||||||
getTaskMock.mockReturnValueOnce({
|
getTaskMock.mockReturnValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "interrupt",
|
status: "interrupt",
|
||||||
@@ -79,7 +79,7 @@ describe("executeBackground", () => {
|
|||||||
]
|
]
|
||||||
launchMock.mockResolvedValueOnce({
|
launchMock.mockResolvedValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: "sub-session",
|
sessionId: "sub-session",
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -105,14 +105,14 @@ describe("executeBackground", () => {
|
|||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
launchMock.mockResolvedValueOnce({
|
launchMock.mockResolvedValueOnce({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})
|
})
|
||||||
getTaskMock.mockImplementationOnce(() => {
|
getTaskMock.mockImplementationOnce(() => {
|
||||||
abortController.abort()
|
abortController.abort()
|
||||||
return { id: "test-task-id", sessionID: null, description: "Test task", agent: "test-agent", status: "pending" }
|
return { id: "test-task-id", sessionId: null, description: "Test task", agent: "test-agent", status: "pending" }
|
||||||
})
|
})
|
||||||
|
|
||||||
//#when
|
//#when
|
||||||
@@ -137,15 +137,15 @@ describe("executeBackground", () => {
|
|||||||
const firstAbortController = new AbortController()
|
const firstAbortController = new AbortController()
|
||||||
const secondAbortController = new AbortController()
|
const secondAbortController = new AbortController()
|
||||||
const states = new Map([
|
const states = new Map([
|
||||||
["task-1", { reads: 0, abortOnFirstRead: true, sessionID: "ses-1" }],
|
["task-1", { reads: 0, abortOnFirstRead: true, sessionId: "ses-1" }],
|
||||||
["task-2", { reads: 0, abortOnFirstRead: false, sessionID: "ses-2" }],
|
["task-2", { reads: 0, abortOnFirstRead: false, sessionId: "ses-2" }],
|
||||||
])
|
])
|
||||||
let launchCount = 0
|
let launchCount = 0
|
||||||
launchMock.mockImplementation(async () => {
|
launchMock.mockImplementation(async () => {
|
||||||
launchCount += 1
|
launchCount += 1
|
||||||
return launchCount === 1
|
return launchCount === 1
|
||||||
? { id: "task-1", sessionID: null, description: "Task 1", agent: "test-agent", status: "pending" }
|
? { id: "task-1", sessionId: null, description: "Task 1", agent: "test-agent", status: "pending" }
|
||||||
: { id: "task-2", sessionID: null, description: "Task 2", agent: "test-agent", status: "pending" }
|
: { id: "task-2", sessionId: null, description: "Task 2", agent: "test-agent", status: "pending" }
|
||||||
})
|
})
|
||||||
getTaskMock.mockImplementation((taskID: string) => {
|
getTaskMock.mockImplementation((taskID: string) => {
|
||||||
const state = states.get(taskID)
|
const state = states.get(taskID)
|
||||||
@@ -155,8 +155,8 @@ describe("executeBackground", () => {
|
|||||||
firstAbortController.abort()
|
firstAbortController.abort()
|
||||||
}
|
}
|
||||||
return state.reads >= 2
|
return state.reads >= 2
|
||||||
? { id: taskID, sessionID: state.sessionID, description: "Task", agent: "test-agent", status: "pending" }
|
? { id: taskID, sessionId: state.sessionId, description: "Task", agent: "test-agent", status: "pending" }
|
||||||
: { id: taskID, sessionID: null, description: "Task", agent: "test-agent", status: "pending" }
|
: { id: taskID, sessionId: null, description: "Task", agent: "test-agent", status: "pending" }
|
||||||
})
|
})
|
||||||
|
|
||||||
//#when
|
//#when
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ function createMockCtx(agents: Array<{ name: string; mode?: string }> = []): Plu
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
directory: "/test",
|
directory: "/test",
|
||||||
} as unknown as PluginInput
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_AGENTS = [
|
const DEFAULT_AGENTS = [
|
||||||
@@ -103,12 +103,12 @@ describe("createCallOmoAgent edge cases", () => {
|
|||||||
reserveSubagentSpawn: reserveSubagentSpawnMock,
|
reserveSubagentSpawn: reserveSubagentSpawnMock,
|
||||||
launch: mock(() => Promise.resolve({
|
launch: mock(() => Promise.resolve({
|
||||||
id: "task-id",
|
id: "task-id",
|
||||||
sessionID: "ses-1",
|
sessionId: "ses-1",
|
||||||
description: "Test",
|
description: "Test",
|
||||||
agent: "bug-fixer",
|
agent: "bug-fixer",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})),
|
})),
|
||||||
getTask: mock(() => ({ status: "pending", sessionID: "ses-1" })),
|
getTask: mock(() => ({ status: "pending", sessionId: "ses-1" })),
|
||||||
}
|
}
|
||||||
const toolDef = createCallOmoAgent(mockCtx, mockManager, [])
|
const toolDef = createCallOmoAgent(mockCtx, mockManager, [])
|
||||||
const executeFunc = toolDef.execute as Function
|
const executeFunc = toolDef.execute as Function
|
||||||
@@ -139,12 +139,12 @@ describe("createCallOmoAgent edge cases", () => {
|
|||||||
reserveSubagentSpawn: reserveSubagentSpawnMock,
|
reserveSubagentSpawn: reserveSubagentSpawnMock,
|
||||||
launch: mock(() => Promise.resolve({
|
launch: mock(() => Promise.resolve({
|
||||||
id: "task-id",
|
id: "task-id",
|
||||||
sessionID: "ses-1",
|
sessionId: "ses-1",
|
||||||
description: "Test",
|
description: "Test",
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})),
|
})),
|
||||||
getTask: mock(() => ({ status: "pending", sessionID: "ses-1" })),
|
getTask: mock(() => ({ status: "pending", sessionId: "ses-1" })),
|
||||||
}
|
}
|
||||||
const toolDef = createCallOmoAgent(mockCtx, mockManager, [])
|
const toolDef = createCallOmoAgent(mockCtx, mockManager, [])
|
||||||
const executeFunc = toolDef.execute as Function
|
const executeFunc = toolDef.execute as Function
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ function createMockCtx(agents: Array<{ name: string; mode?: string }> = []): Plu
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
directory: "/test",
|
directory: "/test",
|
||||||
} as unknown as PluginInput
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFailingMockCtx(error: Error = new Error("API unavailable")): PluginInput {
|
function createFailingMockCtx(error: Error = new Error("API unavailable")): PluginInput {
|
||||||
@@ -29,7 +29,7 @@ function createFailingMockCtx(error: Error = new Error("API unavailable")): Plug
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
directory: "/test",
|
directory: "/test",
|
||||||
} as unknown as PluginInput
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_AGENTS = [
|
const DEFAULT_AGENTS = [
|
||||||
@@ -57,13 +57,13 @@ const mockBackgroundManager = {
|
|||||||
reserveSubagentSpawn: reserveSubagentSpawnMock,
|
reserveSubagentSpawn: reserveSubagentSpawnMock,
|
||||||
launch: mock(() => Promise.resolve({
|
launch: mock(() => Promise.resolve({
|
||||||
id: "test-task-id",
|
id: "test-task-id",
|
||||||
sessionID: null,
|
sessionId: null,
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "test-agent",
|
agent: "test-agent",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
})),
|
})),
|
||||||
getTask: mock(() => ({ status: "pending", sessionID: "ses-123" })),
|
getTask: mock(() => ({ status: "pending", sessionId: "ses-123" })),
|
||||||
} as unknown as BackgroundManager
|
} as BackgroundManager
|
||||||
|
|
||||||
const toolCtx = {
|
const toolCtx = {
|
||||||
sessionID: "test",
|
sessionID: "test",
|
||||||
@@ -240,7 +240,7 @@ describe("createCallOmoAgent", () => {
|
|||||||
//#given
|
//#given
|
||||||
const launch = mock((_input: { fallbackChain?: Array<{ providers: string[]; model: string; variant?: string }> }) => Promise.resolve({
|
const launch = mock((_input: { fallbackChain?: Array<{ providers: string[]; model: string; variant?: string }> }) => Promise.resolve({
|
||||||
id: "task-fallback",
|
id: "task-fallback",
|
||||||
sessionID: "sub-session",
|
sessionId: "sub-session",
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -290,7 +290,7 @@ describe("createCallOmoAgent", () => {
|
|||||||
//#given
|
//#given
|
||||||
const launch = mock((_input: { model?: { providerID: string; modelID: string }; fallbackChain?: unknown[] }) => Promise.resolve({
|
const launch = mock((_input: { model?: { providerID: string; modelID: string }; fallbackChain?: unknown[] }) => Promise.resolve({
|
||||||
id: "task-model",
|
id: "task-model",
|
||||||
sessionID: "sub-session",
|
sessionId: "sub-session",
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -339,7 +339,7 @@ describe("createCallOmoAgent", () => {
|
|||||||
//#given
|
//#given
|
||||||
const launch = mock((_input: { model?: { providerID: string; modelID: string; variant?: string } }) => Promise.resolve({
|
const launch = mock((_input: { model?: { providerID: string; modelID: string; variant?: string } }) => Promise.resolve({
|
||||||
id: "task-variant",
|
id: "task-variant",
|
||||||
sessionID: "sub-session",
|
sessionId: "sub-session",
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -390,7 +390,7 @@ describe("createCallOmoAgent", () => {
|
|||||||
//#given
|
//#given
|
||||||
const launch = mock((_input: { model?: { providerID: string; modelID: string; variant?: string } }) => Promise.resolve({
|
const launch = mock((_input: { model?: { providerID: string; modelID: string; variant?: string } }) => Promise.resolve({
|
||||||
id: "task-inline-variant",
|
id: "task-inline-variant",
|
||||||
sessionID: "sub-session",
|
sessionId: "sub-session",
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
@@ -440,7 +440,7 @@ describe("createCallOmoAgent", () => {
|
|||||||
//#given
|
//#given
|
||||||
const launch = mock((_input: { model?: { providerID: string; modelID: string } }) => Promise.resolve({
|
const launch = mock((_input: { model?: { providerID: string; modelID: string } }) => Promise.resolve({
|
||||||
id: "task-category-model",
|
id: "task-category-model",
|
||||||
sessionID: "sub-session",
|
sessionId: "sub-session",
|
||||||
description: "Test task",
|
description: "Test task",
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
status: "pending",
|
status: "pending",
|
||||||
|
|||||||
Reference in New Issue
Block a user