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

Function sp_stdin_check_rejection

tests/test_subprocess.c:2178–2224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2176} sp_stdin_rejection_t;
2177
2178static sp_stdin_rejection_t sp_stdin_check_rejection(const char *binary, const char *input,
2179 const char *out, const char *log,
2180 const char *marker,
2181 const char *valid_empty_input) {
2182 sp_stdin_rejection_t check = {.safe_cleanup = true};
2183 (void)cbm_unlink(marker);
2184 check.prepared =
2185 sp_stdin_write(out, sp_stdin_out_sentinel, sizeof(sp_stdin_out_sentinel) - 1) &&
2186 sp_stdin_write(log, sp_stdin_log_sentinel, sizeof(sp_stdin_log_sentinel) - 1) &&
2187 sp_stdout_file_equals(valid_empty_input, "", 0) && !cbm_file_exists(marker);
2188 if (!check.prepared)
2189 return check;
2190 const char *argv[] = {binary, "__cbm_subprocess_stdin_probe", "stamp", marker, NULL};
2191 cbm_proc_opts_t opts = {.bin = binary,
2192 .argv = argv,
2193 .stdin_file = input,
2194 .stdout_file = out,
2195 .log_file = log,
2196 .quiet_timeout_ms = 10000};
2197 cbm_subprocess_t *process = NULL;
2198 int rc = cbm_subprocess_spawn(&opts, &process);
2199 check.rejected = rc == -1;
2200 check.no_handle = process == NULL;
2201 if (process) {
2202 cbm_proc_result_t result = {0};
2203 check.safe_cleanup = sp_stdin_finish(process, &result);
2204 }
2205 if (!check.safe_cleanup)
2206 return check;
2207 check.outputs_unchanged =
2208 sp_stdout_file_equals(out, sp_stdin_out_sentinel, sizeof(sp_stdin_out_sentinel) - 1) &&
2209 sp_stdout_file_equals(log, sp_stdin_log_sentinel, sizeof(sp_stdin_log_sentinel) - 1);
2210 check.no_child_marker = !cbm_file_exists(marker);
2211
2212 /* A real empty regular file remains a usable input after each rejection.
2213 * This control also passes when the API-only baseline ignores stdin_file. */
2214 const char *valid_argv[] = {binary, "__cbm_subprocess_stdin_probe", "echo", "", NULL};
2215 opts.argv = valid_argv;
2216 opts.stdin_file = valid_empty_input;
2217 cbm_proc_result_t result = {0};
2218 rc = cbm_subprocess_run(&opts, &result);
2219 check.safe_cleanup = sp_stdin_safe_run(rc, &result);
2220 check.reusable = sp_stdin_clean(rc, &result) && sp_stdout_file_equals(out, "", 0) &&
2221 sp_stdout_file_equals(log, sp_stderr_text, sizeof(sp_stderr_text) - 1) &&
2222 sp_stdout_file_equals(valid_empty_input, "", 0);
2223 return check;
2224}
2225
2226/* Dispatched through the existing early native probe entry, before harness setup. */
2227static int sp_stdin_probe(int argc, char **argv) {

Callers 2

sp_stdin_probeFunction · 0.85
test_subprocess.cFile · 0.85

Calls 9

cbm_unlinkFunction · 0.85
sp_stdin_writeFunction · 0.85
sp_stdout_file_equalsFunction · 0.85
cbm_file_existsFunction · 0.85
cbm_subprocess_spawnFunction · 0.85
sp_stdin_finishFunction · 0.85
cbm_subprocess_runFunction · 0.85
sp_stdin_safe_runFunction · 0.85
sp_stdin_cleanFunction · 0.85

Tested by

no test coverage detected