feat(xce-test-cli-ux): build destructive-command confirmation gate

confirm_destructive() prompts on stderr and blocking-reads a y/n answer
via a single, non-looping fgets() call (not libedit) -- the mechanism
that makes a real Ctrl-C during the prompt return EINTR and be treated
as a decline (Requirement 9.9), same as an explicit "n" or EOF.
confirm_set_skip()/confirm_is_skip_set() add a session-scoped toggle
mirroring cmd_set's existing -e/+e style. Auto-skips when input is not
interactive, via a new xcetest_is_interactive() accessor over the
existing g_interactive global. Destructive-command enumeration and
per-command wiring (Requirement 9.5) is task 3.3, not this task.
Proven with a real fork+SIGINT test. 1297/1297 controller suite
passing (+7).

Task 2.1 of .kiro/specs/xce-test-cli-ux/tasks.md.
Requirements: 9.1, 9.2, 9.3, 9.4, 9.6, 9.7, 9.8, 9.9

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jaMf9QEwpugH2W9KAuc7f
This commit is contained in:
Rongsong Shen 2026-09-09 11:41:05 +00:00
parent 7d0ac6f6eb
commit a2686516f7
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
7 changed files with 580 additions and 2 deletions

View file

@ -30,6 +30,7 @@
#include "snapdiff.h" /* byte-level checkpoint-file comparator (cmd_snapdiff) */
#include "snapverify.h" /* offline checkpoint-file structural validator (cmd_snapverify) */
#include "configcompare.h" /* cross-member active-config comparator (cmd_configcompare) */
#include "confirm.h" /* destructive-command confirmation gate (xce-test-cli-ux task 2.1) */
#include "rcfile.h" /* startup rc-file path resolution + loading (xce-test-rc-file task 2.2) */
#include "resval_typeresolve.h" /* resval_resolve_type (resource-value-verification task 2.1) */
#include "xce/cluster.h" /* xce_parse_peers, xce_cluster_config_t */
@ -734,6 +735,19 @@ void sigbreak(int signo) { break_out = 1; }
* test.c-private). */
int xcetest_interrupted(void) { return break_out; }
/* xce-test-cli-ux task 2.1, Requirement 9.4/9.6/13.7: read-only accessor
* over `g_interactive` (this file's top-level-session TTY flag, set once
* in main() from isatty(STDIN_FILENO) and never changed after that) for
* code outside this file (confirm.c) to consult -- mirrors
* xcetest_interrupted()'s accessor pattern immediately above. Pure read;
* declared in confirm.h rather than xcetest_interrupt.h since confirm.c
* is its only consumer and g_interactive is unrelated to that header's
* SIGINT/EINTR concern. Deliberately the TOP-LEVEL session's stdin, not
* "is this line from a sourced file" -- that distinction is Requirement
* 13.7, a later task; this accessor's contract must already be correct
* for it, per design.md's Confirmation Gate invariant. */
int xcetest_is_interactive(void) { return g_interactive; }
static char* get_setting(char* key)
{
int i;