test-plugin.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env bun
  2. // Usage: bun test-plugin.ts
  3. import { createAbilitiesPlugin } from './src/plugin.js'
  4. async function main() {
  5. console.log('🧪 Testing Abilities Plugin\n')
  6. console.log('='.repeat(50))
  7. const mockClient = {
  8. session: {
  9. get: async () => ({}),
  10. list: async () => [],
  11. command: async () => ({}),
  12. prompt: async () => ({}),
  13. todo: async () => ({})
  14. },
  15. events: {
  16. publish: async (options: unknown) => {
  17. console.log('[Event Published]', JSON.stringify(options, null, 2))
  18. }
  19. }
  20. }
  21. const mockContext = {
  22. directory: process.cwd(),
  23. worktree: process.cwd(),
  24. client: mockClient,
  25. $: () => ({ text: async () => '' })
  26. }
  27. console.log('\n📦 Initializing plugin...\n')
  28. const projectRoot = process.cwd().replace('/packages/plugin-abilities', '')
  29. const plugin = await createAbilitiesPlugin(mockContext as any, {
  30. abilities: {
  31. directories: [`${projectRoot}/.opencode/abilities`]
  32. }
  33. })
  34. console.log('\n📋 Testing ability.list tool...\n')
  35. const tools = plugin.tool
  36. const listResult = await tools['ability.list'].execute({})
  37. console.log(listResult)
  38. console.log('\n='.repeat(50))
  39. console.log('\n✅ Testing ability.validate tool...\n')
  40. const validateResult = await tools['ability.validate'].execute({ name: 'hello-world' })
  41. console.log(validateResult)
  42. console.log('\n='.repeat(50))
  43. console.log('\n🚀 Testing ability.run tool...\n')
  44. const runResult = await tools['ability.run'].execute({
  45. name: 'hello-world',
  46. inputs: { name: 'OpenAgents Control' }
  47. })
  48. console.log(JSON.stringify(runResult, null, 2))
  49. console.log('\n='.repeat(50))
  50. console.log('\n📊 Testing ability.status tool...\n')
  51. const statusResult = await tools['ability.status'].execute({})
  52. console.log(JSON.stringify(statusResult, null, 2))
  53. console.log('\n='.repeat(50))
  54. console.log('\n🔍 Testing trigger detection (chat.message hook)...\n')
  55. const mockOutput = {
  56. parts: [
  57. { type: 'text', text: 'hello can you greet me?', synthetic: false }
  58. ]
  59. }
  60. await plugin['chat.message']({}, mockOutput)
  61. if (mockOutput.parts.length > 1) {
  62. console.log('✅ Ability detected! Injected message:')
  63. console.log(mockOutput.parts[0].text)
  64. } else {
  65. console.log('❌ No ability detected')
  66. }
  67. console.log('\n='.repeat(50))
  68. console.log('\n✅ All tests completed!')
  69. }
  70. main().catch(console.error)