MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / test_count_exec_hook

Function test_count_exec_hook

tests/test_cli.c:544–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542}
543
544static size_t test_count_exec_hook(yyjson_val *root, const char *event_name,
545 const char *matcher_value, const char *expected_command,
546 const char *expected_arg) {
547 yyjson_val *hooks = root ? yyjson_obj_get(root, "hooks") : NULL;
548 yyjson_val *entries = hooks && yyjson_is_obj(hooks) ? yyjson_obj_get(hooks, event_name) : NULL;
549 if (!entries || !yyjson_is_arr(entries)) {
550 return 0U;
551 }
552 size_t matches = 0U;
553 size_t entry_index;
554 size_t entry_count;
555 yyjson_val *entry;
556 yyjson_arr_foreach(entries, entry_index, entry_count, entry) {
557 yyjson_val *matcher = yyjson_is_obj(entry) ? yyjson_obj_get(entry, "matcher") : NULL;
558 if ((matcher_value && (!matcher || !yyjson_is_str(matcher) ||
559 strcmp(yyjson_get_str(matcher), matcher_value) != 0)) ||
560 (!matcher_value && matcher)) {
561 continue;
562 }
563 yyjson_val *entry_hooks = yyjson_obj_get(entry, "hooks");
564 if (!entry_hooks || !yyjson_is_arr(entry_hooks)) {
565 continue;
566 }
567 size_t hook_index;
568 size_t hook_count;
569 yyjson_val *hook;
570 yyjson_arr_foreach(entry_hooks, hook_index, hook_count, hook) {
571 yyjson_val *type = yyjson_is_obj(hook) ? yyjson_obj_get(hook, "type") : NULL;
572 yyjson_val *command = yyjson_is_obj(hook) ? yyjson_obj_get(hook, "command") : NULL;
573 yyjson_val *args = yyjson_is_obj(hook) ? yyjson_obj_get(hook, "args") : NULL;
574 yyjson_val *first_arg = args && yyjson_is_arr(args) ? yyjson_arr_get(args, 0U) : NULL;
575 if (type && yyjson_is_str(type) && strcmp(yyjson_get_str(type), "command") == 0 &&
576 command && yyjson_is_str(command) &&
577 strcmp(yyjson_get_str(command), expected_command) == 0 && args &&
578 yyjson_is_arr(args) && yyjson_arr_size(args) == 1U && first_arg &&
579 yyjson_is_str(first_arg) && strcmp(yyjson_get_str(first_arg), expected_arg) == 0 &&
580 !yyjson_obj_get(hook, "shell") && !yyjson_obj_get(hook, "command_windows")) {
581 matches++;
582 }
583 }
584 }
585 return matches;
586}
587
588#ifdef _WIN32
589static bool test_append_command_hook(yyjson_mut_doc *doc, yyjson_mut_val *event_entries,

Callers 1

test_cli.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected