grada-run 0.40.9 → 0.40.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grada-run",
3
- "version": "0.40.9",
3
+ "version": "0.40.11",
4
4
  "description": "Provision production-ready AWS infrastructure and CI/CD pipelines in seconds.",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
@@ -423,4 +423,18 @@ async function runDoctorMain(input = {}) {
423
423
  } catch {
424
424
  // The checks already printed; losing one event beats crashing.
425
425
  }
426
+
427
+ // Red verdicts fail the command: runCommand maps {ok:false, exitCode}
428
+ // to the process exit, so `doctor && apply` gates correctly. The
429
+ // reason mirrors the telemetry failure props; failedChecks names the
430
+ // red cells for programmatic callers. Green (and warn-grade) runs
431
+ // intentionally return undefined, as before.
432
+ if (!success) {
433
+ return {
434
+ ok: false,
435
+ exitCode: 1,
436
+ reason: failureProps.reason,
437
+ failedChecks,
438
+ };
439
+ }
426
440
  }
@@ -92,12 +92,34 @@ export async function resolveSecretsRegion(options = {}) {
92
92
  return 'us-east-2';
93
93
  }
94
94
 
95
- function escapeEnvValue(value) {
96
- return String(value ?? '').replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n');
95
+ // Quote one value so `dotenv.parse` reads it back byte-identical. Plain
96
+ // values keep the legacy double-quote style; values holding a double
97
+ // quote switch to a literal style (single or backtick) because dotenv
98
+ // keeps `\"` verbatim instead of unescaping it. Returns null when no
99
+ // style round-trips — the caller must refuse to write rather than
100
+ // corrupt the file.
101
+ export function quoteEnvValue(value) {
102
+ const text = String(value ?? '');
103
+ const hasSingle = text.includes("'");
104
+ const hasDouble = text.includes('"');
105
+ const hasBacktick = text.includes('`');
106
+ if (hasDouble) {
107
+ if (hasSingle && hasBacktick) return null;
108
+ if (hasSingle) return `\`${text}\``;
109
+ return `'${text}'`;
110
+ }
111
+ if (hasSingle) {
112
+ // Literal backslash-n/r sequences are indistinguishable from escaped
113
+ // newlines inside double quotes, so they force the literal styles.
114
+ if (/\\[nr]/.test(text)) return hasBacktick ? null : `\`${text}\``;
115
+ return `"${text.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}"`;
116
+ }
117
+ if (text.includes('\\')) return `'${text}'`;
118
+ return `"${text.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}"`;
97
119
  }
98
120
 
99
121
  function serializeEnv(orderedKeys, values) {
100
- return orderedKeys.map((key) => `${key}="${escapeEnvValue(values[key])}"`).join('\n') + '\n';
122
+ return orderedKeys.map((key) => `${key}=${quoteEnvValue(values[key])}`).join('\n') + '\n';
101
123
  }
102
124
 
103
125
  function normalizeSecretsArgs(projectName, options) {
@@ -117,10 +139,12 @@ function resolvePullAuditArgs(projectName, options) {
117
139
  }
118
140
 
119
141
  export function diffSecretsEnvs(localSecrets = {}, remoteSecrets = {}) {
120
- const missingLocally = Object.keys(remoteSecrets).filter((k) => !(k in localSecrets));
121
- const untrackedLocally = Object.keys(localSecrets).filter((k) => !(k in remoteSecrets));
142
+ // Own-property checks: `in` matches inherited names (toString,
143
+ // __proto__), which would misclassify real vault keys.
144
+ const missingLocally = Object.keys(remoteSecrets).filter((k) => !Object.hasOwn(localSecrets, k));
145
+ const untrackedLocally = Object.keys(localSecrets).filter((k) => !Object.hasOwn(remoteSecrets, k));
122
146
  const mismatched = Object.keys(remoteSecrets).filter(
123
- (k) => k in localSecrets && String(localSecrets[k]) !== String(remoteSecrets[k])
147
+ (k) => Object.hasOwn(localSecrets, k) && String(localSecrets[k]) !== String(remoteSecrets[k])
124
148
  );
125
149
  return { missingLocally, mismatched, untrackedLocally };
126
150
  }
@@ -298,6 +322,19 @@ async function pushSecretsMain(envFilePath, projectName, options = {}) {
298
322
  });
299
323
  return { keysChanged: false, restarted: false };
300
324
  }
325
+ // Automated runs cannot answer prompts: skip the restart (fresh
326
+ // deploys pick up the values) instead of hanging on confirm.
327
+ if (opts.isHeadless || process.env.CI) {
328
+ console.log(color.dim('Headless environment detected: skipping the ECS restart prompt — new values apply on the next deployment or restart.'));
329
+ console.log(color.blue(`\n📘 Learn how secrets reach your app: ${color.underline('https://github.com/grada-run/grada/blob/main/apps/docs/src/content/docs/guides/secrets-management.md')}`));
330
+ await trackSuccess('secrets_pushed', {
331
+ projectName: resolvedProjectName,
332
+ secret_count: Object.keys(parsedSecrets).length,
333
+ keys_changed: false,
334
+ ecs_restart: false
335
+ });
336
+ return { keysChanged: false, restarted: false };
337
+ }
301
338
  const shouldRestart = await confirm({
302
339
  message: 'Keys are unchanged. Trigger a rolling ECS restart to apply new values immediately?',
303
340
  initialValue: false,
@@ -436,17 +473,31 @@ async function pullSecretsMain(envFilePath, projectName, options = {}) {
436
473
  }
437
474
  }
438
475
 
439
- const merged = { ...localSecrets };
476
+ // Null-prototype map: a `__proto__` vault key lands as an own data
477
+ // property instead of mutating the merge target's prototype.
478
+ const merged = Object.assign(Object.create(null), localSecrets);
440
479
  for (const [key, value] of Object.entries(remoteSecrets)) {
441
- if (!(key in merged) || overwrite) {
480
+ if (!Object.hasOwn(merged, key) || overwrite) {
442
481
  merged[key] = String(value);
443
482
  }
444
483
  }
445
484
 
446
485
  const orderedKeys = [
447
486
  ...Object.keys(localSecrets),
448
- ...remoteKeys.filter((k) => !(k in localSecrets)),
487
+ ...remoteKeys.filter((k) => !Object.hasOwn(localSecrets, k)),
449
488
  ];
489
+ const unrepresentable = orderedKeys.filter((key) =>
490
+ key === '__proto__' || quoteEnvValue(merged[key]) === null
491
+ );
492
+ if (unrepresentable.length > 0) {
493
+ const abort = new Error(
494
+ `Refusing to write ${resolvedFilePath}: ${unrepresentable.length} entr${unrepresentable.length === 1 ? 'y' : 'ies'} ` +
495
+ `cannot round-trip through .env quoting (${unrepresentable.join(', ')}). ` +
496
+ 'Rename or re-encode them in the vault and retry.'
497
+ );
498
+ abort.code = 'SECRETS_PULL_UNREPRESENTABLE_VALUE';
499
+ throw abort;
500
+ }
450
501
  await fs.writeFile(envPath, serializeEnv(orderedKeys, merged));
451
502
 
452
503
  outro(`Successfully synced ${remoteKeys.length} secrets to ${resolvedFilePath}`);
@@ -17,7 +17,10 @@ export const ISSUES_URL = 'https://github.com/grada-run/grada/issues';
17
17
  // shape) prints guidance without a stack; everything else prints a
18
18
  // one-liner, the stack (or String(reason) when there is none), and
19
19
  // the report pointer. JSON mode puts the envelope on stdout and the
20
- // human text on stderr so parsers stay safe.
20
+ // human text on stderr so parsers stay safe. Standing requirement:
21
+ // never start a spinner on a --json/MCP path — the handler exits 1,
22
+ // and clack's exit listener prints "Canceled" to stdout for any
23
+ // spinner still active.
21
24
 
22
25
  function firstLine(text) {
23
26
  return String(text).split('\n')[0];
@@ -53,7 +56,7 @@ export function formatLastResortOutput({ kind, reason, isJson }) {
53
56
  if (kind === 'unhandledRejection' && isSmithyHomelessRejection(reason)) {
54
57
  oneLiner = HOMELESS_GUIDANCE;
55
58
  stderrText = `✖ ${HOMELESS_GUIDANCE}\n`
56
- + ' Set the HOME environment variable, or provide credentials via AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.\n';
59
+ + ' Set the HOME environment variable to any directory (it is only used to locate optional config files), then configure credentials.\n';
57
60
  } else if (kind === 'uncaughtException') {
58
61
  oneLiner = `Grada crashed unexpectedly: ${first}`;
59
62
  stderrText = `✖ ${oneLiner}\n${detail}\n Please report this: ${ISSUES_URL}\n`;
@@ -101,7 +104,17 @@ export function createLastResortHandlers({
101
104
  // fall through to the exit below no matter what.
102
105
  }
103
106
  }
104
- exitFn(1);
107
+ try {
108
+ exitFn(1);
109
+ } catch (error) {
110
+ // MCP tool calls stub process.exit to throw InterceptedExit
111
+ // (duck-typed by name: this module must stay dependency-free):
112
+ // the tool's own error path carries the failure, so the
113
+ // backstop's job ends with the printed report. Anything else
114
+ // propagates — swallowing an unknown exit failure could let
115
+ // the loop drain to a silent exit 0.
116
+ if (error?.name !== 'InterceptedExit') throw error;
117
+ }
105
118
  };
106
119
  return {
107
120
  unhandledRejection: handle('unhandledRejection'),