main.c¶
examples/headless/main.c
@file main.c @brief Headless example — scripted conversation for CI validation.
Owners: @tvanfossen
check_context_count
static void check_context_count(entropic_handle_t handle, const char *label, size_t expected, int *failures)
Validate that context_count returns the expected value.
examples/headless/main.c:107
Source · 18 lines
static void check_context_count(entropic_handle_t handle, const char* label,
size_t expected, int* failures)
{
size_t count = 0;
entropic_error_t err = entropic_context_count(handle, &count);
if (err != ENTROPIC_OK) {
fprintf(stderr, "FAIL [%s]: context_count error\n", label);
(*failures)++;
return;
}
if (count != expected) {
fprintf(stderr, "FAIL [%s]: count=%zu expected=%zu\n",
label, count, expected);
(*failures)++;
return;
}
fprintf(stderr, "PASS [%s]: count=%zu\n", label, count);
}Activity · 11 steps
Flows
main
int main(int argc, char *argv[])
Headless example entry point.
examples/headless/main.c:183
Called by none
Calls entropic_configure_dir, entropic_create, entropic_destroy, entropic_last_error, run_scenarios
Source · 25 lines
int main(int argc, char* argv[])
{
(void)argc;
(void)argv;
entropic_handle_t handle = NULL;
if (entropic_create(&handle) != ENTROPIC_OK) {
fprintf(stderr, "entropic_create failed\n");
return EXIT_FAILURE;
}
if (entropic_configure_dir(handle, ".headless") != ENTROPIC_OK) {
fprintf(stderr, "configure failed: %s\n",
entropic_last_error(handle));
entropic_destroy(handle);
return EXIT_FAILURE;
}
int failures = run_scenarios(handle);
entropic_destroy(handle);
fprintf(stderr, "\n=== headless: %s (%d failure%s) ===\n",
failures == 0 ? "PASS" : "FAIL",
failures, failures == 1 ? "" : "s");
return failures == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}Activity · 14 steps
Flows
run_scenarios
static int run_scenarios(entropic_handle_t handle)
Run the scripted validation sequence.
examples/headless/main.c:142
Called by main
Calls check_context_count, entropic_context_clear, entropic_last_error, run_step
Source · 27 lines
static int run_scenarios(entropic_handle_t handle)
{
int failures = 0;
run_step(handle, "single-turn",
"Reply with exactly the word: hello",
"hello", &failures);
run_step(handle, "multi-turn",
"What word did I just ask you to reply with?",
"hello", &failures);
check_context_count(handle, "after-2-turns", 4, &failures);
entropic_error_t err = entropic_context_clear(handle);
if (err != ENTROPIC_OK) {
fprintf(stderr, "FAIL [clear]: error %s\n",
entropic_last_error(handle));
failures++;
} else {
fprintf(stderr, "PASS [clear]\n");
}
check_context_count(handle, "after-clear", 0, &failures);
return failures;
}Activity · 12 steps
Flows
run_step
static void run_step(entropic_handle_t handle, const char *label, const char *prompt, const char *expect, int *failures)
Run a single scripted prompt and validate the response.
examples/headless/main.c:71
Source · 24 lines
static void run_step(entropic_handle_t handle, const char* label,
const char* prompt, const char* expect,
int* failures)
{
char acc[ACCUM_SIZE];
acc[0] = '\0';
fprintf(stderr, "\n=== %s ===\nPrompt: %s\nResponse: ", label, prompt);
entropic_error_t err = entropic_run_streaming(
handle, prompt, on_token, acc, NULL);
fprintf(stderr, "\n");
if (err != ENTROPIC_OK) {
fprintf(stderr, "FAIL [%s]: error %s\n",
label, entropic_last_error(handle));
(*failures)++;
return;
}
if (expect && !strstr(acc, expect)) {
fprintf(stderr, "FAIL [%s]: response missing '%s'\n",
label, expect);
(*failures)++;
return;
}
fprintf(stderr, "PASS [%s]\n", label);
}