Skip to content

Commit 00e0cf3

Browse files
committed
fix(cli): harden hook diagnostic contract
Signed-off-by: astandrik <astandrik@yandex-team.ru>
1 parent 7d4dc77 commit 00e0cf3

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎src/cli/config_toml_edit.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ typedef enum {
8282
CBM_TOML_CODEX_HOOK_FAILURE_EDIT_BUILD,
8383
CBM_TOML_CODEX_HOOK_FAILURE_CONFIG_WRITE
8484
} cbm_toml_codex_hook_failure_t;
85+
/* Returns a stable, content-free diagnostic name for a failure category. */
8586
const char *cbm_toml_codex_hook_failure_name(cbm_toml_codex_hook_failure_t failure);
87+
/* `failure` may be NULL. When non-NULL, it is reset to NONE on entry and remains
88+
* NONE on success; failure categories never contain configuration content. */
8689
int cbm_toml_reconcile_codex_hooks_detailed(const char *file_path, const char *begin_marker,
8790
const char *end_marker, const char *command,
8891
const char *command_windows,

‎tests/test_cli.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9326,12 +9326,18 @@ TEST(cli_codex_preflight_reports_heading_and_reason) {
93269326
snprintf(codex_dir, sizeof(codex_dir), "%s/.codex", tmpdir);
93279327
snprintf(config_path, sizeof(config_path), "%s/config.toml", codex_dir);
93289328
snprintf(agents_path, sizeof(agents_path), "%s/AGENTS.md", codex_dir);
9329-
test_mkdirp(codex_dir);
9329+
if (test_mkdirp(codex_dir) != 0) {
9330+
test_rmdir_r(tmpdir);
9331+
FAIL("failed to create Codex preflight fixture directory");
9332+
}
93309333
const char *ambiguous =
93319334
"[hooks]\nSessionStart = [{ matcher = 'startup|resume|clear|compact', hooks = ["
93329335
"{ type = 'command', command = 'codebase-memory-mcp hook-augment' }, "
93339336
"{ type = 'command', command = 'foreign' }] }]\n";
9334-
write_test_file(config_path, ambiguous);
9337+
if (write_test_file(config_path, ambiguous) != 0) {
9338+
test_rmdir_r(tmpdir);
9339+
FAIL("failed to write Codex preflight fixture config");
9340+
}
93359341

93369342
char *saved_home = save_test_env("HOME");
93379343
char *saved_path = save_test_env("PATH");

0 commit comments

Comments
 (0)