test(skill): fresh import skill tool factory
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -46,6 +46,11 @@ function createMockContext(sessionID: string): ToolContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createSkillTool(...args: Parameters<typeof import("./tools").createSkillTool>): ReturnType<typeof import("./tools").createSkillTool> {
|
||||||
|
const module = await import(`./tools?test=${Date.now()}-${Math.random()}`)
|
||||||
|
return module.createSkillTool(...args)
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(commandDiscovery, "discoverCommandsSync").mockImplementation(discoverCommandsSync)
|
spyOn(commandDiscovery, "discoverCommandsSync").mockImplementation(discoverCommandsSync)
|
||||||
spyOn(skillContent, "getAllSkills").mockImplementation(getAllSkills)
|
spyOn(skillContent, "getAllSkills").mockImplementation(getAllSkills)
|
||||||
@@ -63,8 +68,7 @@ describe("createSkillTool", () => {
|
|||||||
const baselineDiscoverCommandsSyncCalls = discoverCommandsSync.mock.calls.length
|
const baselineDiscoverCommandsSyncCalls = discoverCommandsSync.mock.calls.length
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const { createSkillTool } = await import("./tools")
|
const skillTool = await createSkillTool({})
|
||||||
const skillTool = createSkillTool({})
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(discoverCommandsSync.mock.calls.length).toBe(baselineDiscoverCommandsSyncCalls)
|
expect(discoverCommandsSync.mock.calls.length).toBe(baselineDiscoverCommandsSyncCalls)
|
||||||
@@ -80,8 +84,7 @@ describe("createSkillTool", () => {
|
|||||||
const baselineGetAllSkillsCalls = getAllSkills.mock.calls.length
|
const baselineGetAllSkillsCalls = getAllSkills.mock.calls.length
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const { createSkillTool } = await import("./tools")
|
const skillTool = await createSkillTool({})
|
||||||
const skillTool = createSkillTool({})
|
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(getAllSkills.mock.calls.length).toBe(baselineGetAllSkillsCalls)
|
expect(getAllSkills.mock.calls.length).toBe(baselineGetAllSkillsCalls)
|
||||||
@@ -97,8 +100,7 @@ describe("createSkillTool", () => {
|
|||||||
const sessionContext = createMockContext("session-clear-once")
|
const sessionContext = createMockContext("session-clear-once")
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const { createSkillTool } = await import("./tools")
|
const skillTool = await createSkillTool({})
|
||||||
const skillTool = createSkillTool({})
|
|
||||||
void skillTool.description
|
void skillTool.description
|
||||||
await flushMicrotasks()
|
await flushMicrotasks()
|
||||||
await skillTool.execute({ name: "lazy-skill" }, sessionContext)
|
await skillTool.execute({ name: "lazy-skill" }, sessionContext)
|
||||||
@@ -114,8 +116,7 @@ describe("createSkillTool", () => {
|
|||||||
const baselineGetAllSkillsCalls = getAllSkills.mock.calls.length
|
const baselineGetAllSkillsCalls = getAllSkills.mock.calls.length
|
||||||
const sessionAContext = createMockContext("session-a")
|
const sessionAContext = createMockContext("session-a")
|
||||||
const sessionBContext = createMockContext("session-b")
|
const sessionBContext = createMockContext("session-b")
|
||||||
const { createSkillTool } = await import("./tools")
|
const skillTool = await createSkillTool({})
|
||||||
const skillTool = createSkillTool({})
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
await skillTool.execute({ name: "lazy-skill" }, sessionAContext)
|
await skillTool.execute({ name: "lazy-skill" }, sessionAContext)
|
||||||
|
|||||||
Reference in New Issue
Block a user