cdk-real-drift 0.4.1 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -333,6 +333,10 @@ CI (with `--yes`).
333
333
  is always surfaced regardless (as the `skipped=N` footer line or a loud
334
334
  `warning:`); `--strict` only decides whether it fails the build.
335
335
  - Errors always exit `2`; `revert` exits `1` when drift remains after it.
336
+ - Interrupting a run with **Ctrl-C** (or **ESC**) during the gather/read phase
337
+ exits `130` (128 + SIGINT) for every verb — never `0`, so an aborted
338
+ `check --fail` can never be mistaken for "no drift" and an aborted `record` is
339
+ never a false "written".
336
340
 
337
341
  ```yaml
338
342
  - run: npm ci # cdkrd resolves the CDK app, so its deps must be installed
@@ -379,7 +383,12 @@ the line) are errors (exit `2`): a typo'd flag never silently becomes a stack na
379
383
  Every option runs exactly the same code as the standalone commands. Prompts are
380
384
  skipped under `--json`, `--show-all`, `--pre-deploy`, and `--fail`. A non-TTY run
381
385
  never prompts: a required write decision without `--yes` errors with exit 2 (the
382
- safe side); `--yes` in a TTY skips the write confirmation AND each verb's selection
386
+ safe side). "Interactive" requires **both** a TTY stdin and a TTY stdout — so
387
+ **redirecting or piping the output** (`cdkrd check > report.txt`, `| tee`) is also
388
+ treated as non-interactive: the report is written cleanly with no prompt (which
389
+ would otherwise deadlock, waiting on stdin for a prompt written into the file) and
390
+ no spinner frames leaking into the text. `--yes` in a TTY skips the write
391
+ confirmation AND each verb's selection
383
392
  multiselect — `record` records ALL, `ignore` ignores ALL, `revert` applies the full
384
393
  plan. Only `check`'s action menu (Record / Revert / Ignore / …) still shows under
385
394
  `--yes`.
package/dist/cli.js CHANGED
@@ -71,6 +71,29 @@ async function flushAndExit(code) {
71
71
  process.exit(code);
72
72
  }
73
73
 
74
+ //#endregion
75
+ //#region src/interrupt.ts
76
+ let gatherActive = false;
77
+ function setGatherActive(active) {
78
+ gatherActive = active;
79
+ }
80
+ function interruptExitCode(code, active) {
81
+ return active && (code === void 0 || code === 0) ? 130 : code ?? 0;
82
+ }
83
+ let installed = false;
84
+ function installInterruptGuard() {
85
+ if (installed) return;
86
+ installed = true;
87
+ const realExit = process.exit.bind(process);
88
+ process.exit = (code) => realExit(interruptExitCode(code, gatherActive));
89
+ const onSignal = () => {
90
+ process.stderr.write("\x1B[?25h");
91
+ return realExit(130);
92
+ };
93
+ process.on("SIGINT", onSignal);
94
+ process.on("SIGTERM", onSignal);
95
+ }
96
+
74
97
  //#endregion
75
98
  //#region src/aws-errors.ts
76
99
  function isStackNotDeployed(e) {
@@ -304,9 +327,18 @@ const ALLOWED_FLAGS_BY_VERB = {
304
327
  * non-TTY (real CI/cron/pipes). The single source of truth — command code threads this
305
328
  * in rather than reading `process.stdin.isTTY` directly. Optional prompts skip when
306
329
  * false; required-decision prompts error (exit 2) when false.
330
+ *
331
+ * #869: gate on BOTH stdin AND stdout being a TTY — the interactive UI (the @clack
332
+ * spinner + resolve prompt) WRITES to stdout, so `cdkrd check > out.txt` (or `| tee`)
333
+ * from a terminal has a TTY stdin but a redirected stdout: gating on stdin alone RAN the
334
+ * prompt into the file, deadlocking the run on a prompt the user cannot see, and leaked
335
+ * the spinner's ANSI erase-frames into the text report (polluting the `^result:` grep
336
+ * contract). Requiring stdout too matches the color gate (`style.ts`, `process.stdout.isTTY`)
337
+ * so the two interactivity axes are consistent: a redirected/piped stdout is report-only,
338
+ * never prompts, never hangs.
307
339
  */
308
340
  function isInteractive() {
309
- return Boolean(process.stdin.isTTY);
341
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY);
310
342
  }
311
343
  function parseCommonArgs(args, verb) {
312
344
  const values = {};
@@ -9565,6 +9597,7 @@ async function regatherTouched(gathered, touched, region) {
9565
9597
  async function gatherWithProgress(show, label, run) {
9566
9598
  if (!show) return run();
9567
9599
  const s = spinner();
9600
+ setGatherActive(true);
9568
9601
  s.start(`${label}: reading live AWS state & computing drift…`);
9569
9602
  try {
9570
9603
  const gathered = await run();
@@ -9573,6 +9606,8 @@ async function gatherWithProgress(show, label, run) {
9573
9606
  } catch (e) {
9574
9607
  s.error(`${label}: read failed`);
9575
9608
  throw e;
9609
+ } finally {
9610
+ setGatherActive(false);
9576
9611
  }
9577
9612
  }
9578
9613
  function positionPrefix(idx, total) {
@@ -14694,6 +14729,7 @@ EXIT CODES
14694
14729
  record: 0 = written 2 = error/refused
14695
14730
  ignore: 0 = rule(s) written / nothing to ignore 2 = error/refused
14696
14731
  revert: 0 = converged/aborted 1 = drift remains 2 = error/apply failure
14732
+ all: 130 = interrupted (Ctrl-C / ESC) during the gather/read phase — never mistaken for clean
14697
14733
 
14698
14734
  The baseline lives at .cdkrd/baselines/<stack>.<accountId>.<region>.json — commit it; review
14699
14735
  its diff in PRs. Ignore rules live in .cdkrd/ignore.yaml — also git-committed.`;
@@ -14729,6 +14765,7 @@ async function main(argv) {
14729
14765
  return 2;
14730
14766
  }
14731
14767
  }
14768
+ installInterruptGuard();
14732
14769
  const argv = process.argv.slice(2);
14733
14770
  main(argv).then((code) => flushAndExit(code)).catch((e) => {
14734
14771
  const msg = e?.message ?? String(e);