@@ -283,6 +283,53 @@ pub export fn boj_cartridge_version() [*:0]const u8 {
283283 return "0.1.0" ;
284284}
285285
286+ // ═══════════════════════════════════════════════════════════════════════
287+ // ADR-0006 dispatch (boj_cartridge_invoke, 5th standard symbol)
288+ // ═══════════════════════════════════════════════════════════════════════
289+
290+ const shim = @import ("cartridge_shim" );
291+
292+ /// Dispatch the cartridge.json MCP tools. Grade D Alpha — each arm
293+ /// returns a stub JSON body shaped to the tool's intended response.
294+ export fn boj_cartridge_invoke (
295+ tool_name : [* c ]const u8 ,
296+ json_args : [* c ]const u8 ,
297+ out_buf : [* c ]u8 ,
298+ in_out_len : [* c ]usize ,
299+ ) callconv (.c ) i32 {
300+ _ = json_args ;
301+ if (shim .invokeArgsNull (tool_name , out_buf , in_out_len )) return shim .RC_BAD_ARGS ;
302+
303+ const body : []const u8 = if (shim .toolIs (tool_name , "dap_start" ))
304+ "{\" result\" :{\" status\" :\" stub\" }}"
305+ else if (shim .toolIs (tool_name , "dap_initialize" ))
306+ "{\" result\" :{\" status\" :\" stub\" }}"
307+ else if (shim .toolIs (tool_name , "dap_launch" ))
308+ "{\" result\" :{\" status\" :\" stub\" }}"
309+ else if (shim .toolIs (tool_name , "dap_attach" ))
310+ "{\" result\" :{\" status\" :\" stub\" }}"
311+ else if (shim .toolIs (tool_name , "dap_set_breakpoints" ))
312+ "{\" result\" :{\" status\" :\" stub\" }}"
313+ else if (shim .toolIs (tool_name , "dap_continue" ))
314+ "{\" result\" :{\" status\" :\" stub\" }}"
315+ else if (shim .toolIs (tool_name , "dap_step_over" ))
316+ "{\" result\" :{\" status\" :\" stub\" }}"
317+ else if (shim .toolIs (tool_name , "dap_step_in" ))
318+ "{\" result\" :{\" status\" :\" stub\" }}"
319+ else if (shim .toolIs (tool_name , "dap_step_out" ))
320+ "{\" result\" :{\" status\" :\" stub\" }}"
321+ else if (shim .toolIs (tool_name , "dap_stack_trace" ))
322+ "{\" result\" :{\" status\" :\" stub\" }}"
323+ else if (shim .toolIs (tool_name , "dap_variables" ))
324+ "{\" result\" :{\" status\" :\" stub\" }}"
325+ else if (shim .toolIs (tool_name , "dap_stop" ))
326+ "{\" result\" :{\" status\" :\" stub\" }}"
327+ else
328+ return shim .RC_UNKNOWN_TOOL ;
329+
330+ return shim .writeResult (out_buf , in_out_len , body );
331+ }
332+
286333// ═══════════════════════════════════════════════════════════════════════
287334// Tests
288335// ═══════════════════════════════════════════════════════════════════════
@@ -346,3 +393,46 @@ test "breakpoint management" {
346393 const bp = dap_add_breakpoint (slot , @intFromEnum (BreakpointKind .function ));
347394 try std .testing .expect (bp >= 0 );
348395}
396+
397+ // ═══════════════════════════════════════════════════════════════════════
398+ // ADR-0006 invoke dispatch tests
399+ // ═══════════════════════════════════════════════════════════════════════
400+
401+ test "invoke: each declared tool succeeds" {
402+ var buf : [256 ]u8 = undefined ;
403+ const tools = [_ ][]const u8 {
404+ "dap_start" ,
405+ "dap_initialize" ,
406+ "dap_launch" ,
407+ "dap_attach" ,
408+ "dap_set_breakpoints" ,
409+ "dap_continue" ,
410+ "dap_step_over" ,
411+ "dap_step_in" ,
412+ "dap_step_out" ,
413+ "dap_stack_trace" ,
414+ "dap_variables" ,
415+ "dap_stop" ,
416+ };
417+ for (tools ) | t | {
418+ var len : usize = buf .len ;
419+ const rc = boj_cartridge_invoke (t .ptr , "{}" , & buf , & len );
420+ try std .testing .expectEqual (@as (i32 , 0 ), rc );
421+ try std .testing .expect (std .mem .indexOf (u8 , buf [0.. len ], "result" ) != null );
422+ }
423+ }
424+
425+ test "invoke: unknown tool returns -1" {
426+ var buf : [64 ]u8 = undefined ;
427+ var len : usize = buf .len ;
428+ const rc = boj_cartridge_invoke ("nope" , "{}" , & buf , & len );
429+ try std .testing .expectEqual (@as (i32 , -1 ), rc );
430+ }
431+
432+ test "invoke: buffer too small returns -3" {
433+ var buf : [4 ]u8 = undefined ;
434+ var len : usize = buf .len ;
435+ const rc = boj_cartridge_invoke ("dap_start" , "{}" , & buf , & len );
436+ try std .testing .expectEqual (@as (i32 , -3 ), rc );
437+ try std .testing .expect (len > 4 );
438+ }
0 commit comments