From a28a9ea2b45e19d11e9bc66db1ad71230b0eafa4 Mon Sep 17 00:00:00 2001 From: vitaliytv Date: Sat, 29 Aug 2026 18:23:03 +0300 Subject: [PATCH 1/2] fix: drain JSON stdout before exit --- .github/workflows/npm-publish.yml | 2 +- .github/workflows/test.yml | 2 +- bin/cli.mjs | 8 ++++++-- test/json-output-contract.test.mjs | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/json-output-contract.test.mjs diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 21ec9b9..2893f35 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -39,7 +39,7 @@ jobs: - run: npm ci - - run: node --test test/cli.test.mjs + - run: npm test - name: Verify tag matches package.json version run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15916ef..05107b7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: - run: npm ci - - run: node --test test/cli.test.mjs + - run: npm test - name: Smoke test via node bin/cli.mjs --help run: node bin/cli.mjs --help diff --git a/bin/cli.mjs b/bin/cli.mjs index 1bf0a59..4e780fd 100755 --- a/bin/cli.mjs +++ b/bin/cli.mjs @@ -43,9 +43,13 @@ async function main(argv) { } main(process.argv.slice(2)).then( - (code) => process.exit(code), + // Не викликаємо process.exit(): він примусово обриває pending stdout + // writes. Для великого `kcc-inventory --json | jq ...` це давало + // неповний JSON, хоча scan уже завершився. exitCode зберігає статус, + // але дає Node дописати pipe перед природним завершенням процесу. + (code) => { process.exitCode = code; }, (err) => { console.error(`✗ ${err.message || err}`); - process.exit(1); + process.exitCode = 1; }, ); diff --git a/test/json-output-contract.test.mjs b/test/json-output-contract.test.mjs new file mode 100644 index 0000000..f2c4a66 --- /dev/null +++ b/test/json-output-contract.test.mjs @@ -0,0 +1,14 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const here = dirname(fileURLToPath(import.meta.url)); +const cli = readFileSync(join(here, '..', 'bin', 'cli.mjs'), 'utf8'); +const executable = cli.split('\n').filter((line) => !line.trimStart().startsWith('//')).join('\n'); + +test('CLI lets JSON stdout drain instead of force-exiting the process', () => { + assert.doesNotMatch(executable, /process\.exit\s*\(/); + assert.match(executable, /process\.exitCode\s*=\s*code/); +}); From 3466b8b7f6a3b4bf439aafcbe51a79b3e73b0142 Mon Sep 17 00:00:00 2001 From: vitaliytv Date: Sat, 29 Aug 2026 22:11:56 +0300 Subject: [PATCH 2/2] chore: release v0.6.1 --- CHANGELOG.md | 9 +++++++++ package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e93b7cf..5c81e83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.6.1] - 2026-08-29 + +### Fixed + +- `kcc-inventory --json` now drains its complete stdout payload before the + process exits, so piping a full inventory into `jq` cannot receive a + truncated JSON document. + ## [0.6.0] - 2026-08-29 ### Added @@ -123,6 +131,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 directory is listed in `kustomization.yaml`'s explicit `resources:` (and vice versa) — catches files Flux silently ignores. +[0.6.1]: https://github.com/nitra/cfr/compare/v0.6.0...v0.6.1 [0.6.0]: https://github.com/nitra/cfr/compare/v0.5.0...v0.6.0 [0.5.0]: https://github.com/nitra/cfr/compare/v0.4.0...v0.5.0 [0.4.0]: https://github.com/nitra/cfr/compare/v0.3.0...v0.4.0 diff --git a/package.json b/package.json index 0a20f06..ff839e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nitra/cfr", - "version": "0.6.0", + "version": "0.6.1", "description": "A handful of small k8s/GitOps CLI utilities: `check` verifies every YAML file in a Kustomize directory is listed in kustomization.yaml's explicit resources: (and vice versa); `kcc-inventory` diffs a GCP Config Connector namespace against the live project to find drift; `get-resources` is that same scan without the diff.", "keywords": [ "kustomize",