@@ -3,39 +3,66 @@ import type { PluginInput } from "@opencode-ai/plugin"
33import { OpenCoderPlugin } from "../src/plugin"
44
55describe ( "OpenCoderPlugin" , ( ) => {
6- it ( "should be an async function" , ( ) => {
7- expect ( OpenCoderPlugin ) . toBeInstanceOf ( Function )
8- } )
9-
10- it ( "should return a hooks object when called" , async ( ) => {
11- // Create a mock context (minimal implementation for testing)
12- const mockContext = {
6+ // Create a mock context (minimal implementation for testing)
7+ const createMockContext = ( ) =>
8+ ( {
139 project : { } ,
1410 client : { } ,
1511 $ : ( ) => { } ,
16- directory : "/tmp" ,
17- worktree : "/tmp" ,
12+ directory : "/tmp/test-project " ,
13+ worktree : "/tmp/test-project " ,
1814 serverUrl : new URL ( "http://localhost:3000" ) ,
19- } as unknown as PluginInput
15+ } ) as unknown as PluginInput
16+
17+ it ( "should be an async function" , ( ) => {
18+ expect ( OpenCoderPlugin ) . toBeInstanceOf ( Function )
19+ } )
2020
21- const result = await OpenCoderPlugin ( mockContext )
21+ it ( "should return a hooks object when called" , async ( ) => {
22+ const result = await OpenCoderPlugin ( createMockContext ( ) )
2223
2324 expect ( result ) . toBeDefined ( )
2425 expect ( typeof result ) . toBe ( "object" )
2526 } )
2627
27- it ( "should return an empty hooks object (minimal implementation)" , async ( ) => {
28- const mockContext = {
29- project : { } ,
30- client : { } ,
31- $ : ( ) => { } ,
32- directory : "/tmp" ,
33- worktree : "/tmp" ,
34- serverUrl : new URL ( "http://localhost:3000" ) ,
35- } as unknown as PluginInput
28+ it ( "should return hooks object with lifecycle callbacks" , async ( ) => {
29+ const result = await OpenCoderPlugin ( createMockContext ( ) )
30+
31+ // Verify expected hooks are present
32+ expect ( result . event ) . toBeDefined ( )
33+ expect ( typeof result . event ) . toBe ( "function" )
34+ expect ( result [ "tool.execute.before" ] ) . toBeDefined ( )
35+ expect ( typeof result [ "tool.execute.before" ] ) . toBe ( "function" )
36+ expect ( result [ "tool.execute.after" ] ) . toBeDefined ( )
37+ expect ( typeof result [ "tool.execute.after" ] ) . toBe ( "function" )
38+ } )
39+
40+ it ( "should have callable event hook" , async ( ) => {
41+ const result = await OpenCoderPlugin ( createMockContext ( ) )
42+
43+ // Event hook should be callable without throwing
44+ const mockEvent = {
45+ type : "session.created" as const ,
46+ properties : { sessionID : "test-123" } ,
47+ }
48+ await expect ( result . event ?.( { event : mockEvent as any } ) ) . resolves . toBeUndefined ( )
49+ } )
50+
51+ it ( "should have callable tool.execute.before hook" , async ( ) => {
52+ const result = await OpenCoderPlugin ( createMockContext ( ) )
53+
54+ const input = { tool : "bash" , sessionID : "test-123" , callID : "call-456" }
55+ const output = { args : { command : "ls" } }
56+
57+ await expect ( result [ "tool.execute.before" ] ?.( input , output ) ) . resolves . toBeUndefined ( )
58+ } )
59+
60+ it ( "should have callable tool.execute.after hook" , async ( ) => {
61+ const result = await OpenCoderPlugin ( createMockContext ( ) )
3662
37- const result = await OpenCoderPlugin ( mockContext )
63+ const input = { tool : "bash" , sessionID : "test-123" , callID : "call-456" }
64+ const output = { title : "Command executed" , output : "file1.txt\nfile2.txt" , metadata : { } }
3865
39- expect ( Object . keys ( result ) ) . toHaveLength ( 0 )
66+ await expect ( result [ "tool.execute.after" ] ?. ( input , output ) ) . resolves . toBeUndefined ( )
4067 } )
4168} )
0 commit comments