Files
get-shit-done/tests/bug-2544-config-get-exit-code.test.cjs
Tom Boucher 726003563a fix(#2544): config-get exits 1 on missing key (was 10, UNIX convention is 1)
Change ErrorClassification for 'Key not found' in configGet from Validation
(exit 10) to Execution (exit 1), matching git config --get. Callers using
`gsd-sdk query config-get k || fallback` need a non-zero exit to trigger the
fallback branch; 10 worked technically but was semantically wrong and noisy.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 09:53:46 -04:00

45 lines
1.6 KiB
JavaScript

'use strict';
/**
* Bug #2544: `gsd-sdk query config-get` exits 0 on missing key.
*
* Callers that use `gsd-sdk query config-get k || fallback` rely on a
* non-zero exit code when the key is absent. The fix changes the
* ErrorClassification for "Key not found" from Validation (exit 10)
* to Execution (exit 1), matching the UNIX convention of `git config --get`.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const CONFIG_QUERY_SRC = path.join(
__dirname, '..', 'sdk', 'src', 'query', 'config-query.ts',
);
describe('gsd-sdk config-get exit code for missing key (#2544)', () => {
test('config-query.ts source exists', () => {
assert.ok(fs.existsSync(CONFIG_QUERY_SRC), 'sdk/src/query/config-query.ts must exist');
});
test('"Key not found" throws with Execution classification, not Validation', () => {
const src = fs.readFileSync(CONFIG_QUERY_SRC, 'utf-8');
// Find the "Key not found" throw lines and confirm they use Execution, not Validation
const keyNotFoundLines = src
.split('\n')
.filter(line => line.includes('Key not found'));
assert.ok(keyNotFoundLines.length > 0, 'Source must contain "Key not found" throw(s)');
for (const line of keyNotFoundLines) {
assert.ok(
line.includes('Execution'),
`"Key not found" throw must use ErrorClassification.Execution (exit 1), got: ${line.trim()}`
);
assert.ok(
!line.includes('Validation'),
`"Key not found" throw must NOT use ErrorClassification.Validation (exit 10), got: ${line.trim()}`
);
}
});
});