From 1c7779cc00fb3a4a780d85c65bb5d0563bd33f2e Mon Sep 17 00:00:00 2001 From: o-webdev Date: Sat, 28 Mar 2026 16:20:28 +0000 Subject: [PATCH] fix: defer process.exit until postSuggestions async chain resolves --- cli.ts | 12 ++++++++++-- dist/index.cjs | 8 ++++++-- package.json | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cli.ts b/cli.ts index 730acd5..bd8fa8d 100644 --- a/cli.ts +++ b/cli.ts @@ -141,6 +141,10 @@ if (values.format === 'table') { } // --- Post GitHub suggestion comments (async, fail-open) --- +// IMPORTANT: process.exit must be deferred until after async suggestion posting +// completes. Calling process.exit() synchronously would terminate the Node.js +// process before unresolved HTTP requests to the GitHub API resolve, causing +// suggestions to be silently dropped on policy violation builds. if (values['post-suggestions']) { const token = values['github-token']; const repo = values['repo']; @@ -151,6 +155,7 @@ if (values['post-suggestions']) { process.stderr.write( '[WARN] --post-suggestions requires --github-token, --repo, --pr-number, and --commit-sha. Skipping.\n' ); + process.exit(policyExitCode); } else { postSuggestions(result, { token, @@ -172,8 +177,11 @@ if (values['post-suggestions']) { process.stderr.write( `[WARN] GreenOps suggestion engine error: ${err instanceof Error ? err.message : String(err)}. Continuing.\n` ); + }).finally(() => { + // Exit only after suggestions have been posted (or failed gracefully) + process.exit(policyExitCode); }); } +} else { + process.exit(policyExitCode); } - -process.exit(policyExitCode); diff --git a/dist/index.cjs b/dist/index.cjs index 66d427b..d7d590a 100755 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -1968,7 +1968,7 @@ var factors_default = { // package.json var package_default = { name: "greenops-cli", - version: "0.5.3", + version: "0.5.4", description: "Carbon footprint linting for Terraform plans \u2014 AWS, Azure, and GCP. Analyses infrastructure changes for Scope 2, Scope 3, and water impact. Posts recommendations directly on GitHub PRs.", main: "dist/index.cjs", bin: { @@ -3170,6 +3170,7 @@ if (values["post-suggestions"]) { process.stderr.write( "[WARN] --post-suggestions requires --github-token, --repo, --pr-number, and --commit-sha. Skipping.\n" ); + process.exit(policyExitCode); } else { postSuggestions(result, { token, @@ -3193,7 +3194,10 @@ if (values["post-suggestions"]) { `[WARN] GreenOps suggestion engine error: ${err instanceof Error ? err.message : String(err)}. Continuing. ` ); + }).finally(() => { + process.exit(policyExitCode); }); } +} else { + process.exit(policyExitCode); } -process.exit(policyExitCode); diff --git a/package.json b/package.json index abe6af8..42068c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "greenops-cli", - "version": "0.5.3", + "version": "0.5.4", "description": "Carbon footprint linting for Terraform plans \u2014 AWS, Azure, and GCP. Analyses infrastructure changes for Scope 2, Scope 3, and water impact. Posts recommendations directly on GitHub PRs.", "main": "dist/index.cjs", "bin": {