2026-03-31 17:05:55 -07:00
|
|
|
/// <reference types="bun-types" />
|
|
|
|
|
|
|
|
|
|
import { describe, expect, it } from "bun:test"
|
|
|
|
|
import { createSkillTool } from "./tools"
|
|
|
|
|
import type { LoadedSkill } from "../../features/opencode-skill-loader/types"
|
|
|
|
|
|
|
|
|
|
function createMockSkill(name: string): LoadedSkill {
|
|
|
|
|
return {
|
|
|
|
|
name,
|
|
|
|
|
path: `/test/skills/${name}/SKILL.md`,
|
|
|
|
|
resolvedPath: `/test/skills/${name}`,
|
|
|
|
|
definition: {
|
|
|
|
|
name,
|
|
|
|
|
description: `Test skill ${name}`,
|
|
|
|
|
template: `Test skill template for ${name}`,
|
|
|
|
|
},
|
|
|
|
|
scope: "opencode-project",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function waitForRefresh(predicate: () => boolean): Promise<void> {
|
|
|
|
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
|
|
|
if (predicate()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await new Promise<void>((resolve) => setTimeout(resolve, 0))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe("skill tool - async native skill description refresh", () => {
|
|
|
|
|
it("updates description after async native skills resolve", async () => {
|
|
|
|
|
//#given
|
|
|
|
|
let allCallCount = 0
|
|
|
|
|
const tool = createSkillTool({
|
|
|
|
|
skills: [createMockSkill("seeded-skill")],
|
|
|
|
|
commands: [],
|
|
|
|
|
nativeSkills: {
|
|
|
|
|
async all() {
|
|
|
|
|
allCallCount += 1
|
|
|
|
|
|
|
|
|
|
return [{
|
|
|
|
|
name: "async-native-skill",
|
|
|
|
|
description: "Async native skill from plugin input",
|
|
|
|
|
location: "/external/skills/async-native-skill/SKILL.md",
|
|
|
|
|
content: "Async native skill body",
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
async get() {
|
|
|
|
|
return undefined
|
|
|
|
|
},
|
|
|
|
|
async dirs() {
|
|
|
|
|
return []
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(tool.description).toContain("seeded-skill")
|
|
|
|
|
expect(tool.description).not.toContain("async-native-skill")
|
|
|
|
|
|
|
|
|
|
//#when
|
2026-04-04 01:28:01 +09:00
|
|
|
await waitForRefresh(() => tool.description.includes("async-native-skill"))
|
2026-03-31 17:05:55 -07:00
|
|
|
|
|
|
|
|
//#then
|
2026-04-04 01:28:01 +09:00
|
|
|
expect(allCallCount).toBeGreaterThanOrEqual(1)
|
2026-03-31 17:05:55 -07:00
|
|
|
expect(tool.description).toContain("seeded-skill")
|
|
|
|
|
expect(tool.description).toContain("async-native-skill")
|
|
|
|
|
})
|
|
|
|
|
})
|