Schema→decision core of the stdin gate, split out so every schema shape * stays TESTED whatever the shipped tool table holds. * no properties -> never: stdin cannot carry anything the tool accepts. * optional only -> a regular file only. The bare call is already complete * with `{}`, so blocking on a stream for optional extras * is the #1359 d
| 14153 | * the documented `echo '<json>' | cli <tool>` channel is |
| 14154 | * the only way this invocation can carry its arguments. */ |
| 14155 | static bool cli_stdin_allowed_for_schema(const char *schema_str, cbm_cli_stdin_kind_t stdin_kind) { |
| 14156 | if (stdin_kind == CBM_CLI_STDIN_TERMINAL) { |
| 14157 | return false; |
| 14158 | } |
| 14159 | yyjson_doc *schema_doc = yyjson_read(schema_str, strlen(schema_str), 0); |
| 14160 | if (!schema_doc) { |
| 14161 | /* The schemas are compile-time constants, so a parse failure means a |
| 14162 | * malformed literal rather than caller input. Keep the documented stdin |
| 14163 | * channel rather than silently narrowing it on a schema we could not |
| 14164 | * read — the gate must only ever fire on positive evidence about the |
| 14165 | * tool's arguments. */ |
| 14166 | return true; |
| 14167 | } |
| 14168 | yyjson_val *root = yyjson_doc_get_root(schema_doc); |
| 14169 | yyjson_val *props = yyjson_obj_get(root, "properties"); |
| 14170 | yyjson_val *required = yyjson_obj_get(root, "required"); |
| 14171 | bool accepts_arguments = props && yyjson_is_obj(props) && yyjson_obj_size(props) > 0; |
| 14172 | bool requires_arguments = required && yyjson_is_arr(required) && yyjson_arr_size(required) > 0; |
| 14173 | yyjson_doc_free(schema_doc); |
| 14174 | if (!accepts_arguments) { |
| 14175 | return false; |
| 14176 | } |
| 14177 | return requires_arguments || stdin_kind == CBM_CLI_STDIN_FILE; |
| 14178 | } |
| 14179 | |
| 14180 | #ifdef CBM_CLI_ENABLE_TEST_API |
| 14181 | bool cbm_cli_stdin_allowed_for_schema_for_test(const char *schema_str, |
no outgoing calls
no test coverage detected