* refactor(#1294): T-final — delete the core.cjs re-export spine (epic #1267 complete) After T0–T6 nothing imports core, so retire the spine and its scaffolding: - delete src/core.cts (and the gitignored gsd-core/bin/lib/core.cjs artifact; remove its .gitignore + eslint-ignore entries) - delete scripts/lint-core-spine-imports.cjs + its allowlist; drop it from the package.json lint:ci chain - regenerate docs/INVENTORY-MANIFEST.json (drops the core.cjs surface) - sweep stale references: CONTEXT.md glossary back-compat clauses (spine retired, callers import the leaf directly), planning-config.md CONFIG_DEFAULTS owner, and false present-tense core.cjs claims in leaf-module docstrings The ADR-857 decomposition is complete: the former Core god-module is fully dissolved into its leaf modules; no re-export spine remains. No behaviour change. Closes #1294 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#1294): migrate the computed-path core.cjs importers the literal grep missed bin/install.js used require(path.join(_gsdLibDir, 'core.cjs')) (a computed path, and bin/install.js was never in the convergence lint's scan roots), and ~8 test files referenced core.cjs via path.join/readFileSync/existsSync/FILE_ARG forms the literal-string migration grep missed. Route install.js's symbols to their leaves (RUNTIME_PROFILE_MAP->model-catalog, resolveTierEntry/EFFORT_SET-> model-resolver) and repoint/adjust the test references to the leaves. Recovers the 161 'Cannot find module core.cjs' failures from the spine deletion. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
147 lines
5.7 KiB
JavaScript
147 lines
5.7 KiB
JavaScript
/**
|
||
* Regression test for bug #2943
|
||
*
|
||
* `gsd-tools.cjs config-get context_window` (and the SDK equivalent) threw
|
||
* "Key not found: context_window" when the key was absent from config.json,
|
||
* even though context_window has a documented schema default of 200000.
|
||
*
|
||
* Fix: `cmdConfigGet` in bin/lib/config.cjs now consults a SCHEMA_DEFAULTS map
|
||
* before emitting "Key not found", so schema-defaulted keys always return the
|
||
* default value (exit 0) when not explicitly set in the project config.
|
||
*/
|
||
|
||
'use strict';
|
||
|
||
// Migrated to typed-IR (#2974): the previous shape grepped stderr/stdout for
|
||
// "Key not found"; now the test passes `--json-errors` to gsd-tools and
|
||
// asserts on the structured `reason` code (a frozen-enum value from
|
||
// `core.cjs::ERROR_REASON`). Exit code is also a typed signal — together
|
||
// they fully discriminate the failure class.
|
||
|
||
const { describe, test, beforeEach, afterEach } = require('node:test');
|
||
const assert = require('node:assert/strict');
|
||
const fs = require('node:fs');
|
||
const path = require('node:path');
|
||
const os = require('node:os');
|
||
const { execFileSync } = require('node:child_process');
|
||
|
||
const GSD_TOOLS = path.join(__dirname, '..', 'gsd-core', 'bin', 'gsd-tools.cjs');
|
||
const { ERROR_REASON } = require(path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'io.cjs'));
|
||
const { cleanup } = require('./helpers.cjs');
|
||
|
||
describe('bug-2943: config-get returns schema default for context_window', () => {
|
||
let tmpDir;
|
||
let planningDir;
|
||
|
||
beforeEach(() => {
|
||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-test-2943-'));
|
||
planningDir = path.join(tmpDir, '.planning');
|
||
fs.mkdirSync(planningDir, { recursive: true });
|
||
});
|
||
|
||
afterEach(() => {
|
||
cleanup(tmpDir);
|
||
});
|
||
|
||
/**
|
||
* Run config-get with optional extra args. Returns { exitCode, stdout, stderr }.
|
||
* Uses --raw so we get the plain scalar value, not JSON-wrapped.
|
||
*/
|
||
function runConfigGet(keyPath, extraArgs = []) {
|
||
const args = [GSD_TOOLS, 'config-get', keyPath, '--raw', '--cwd', tmpDir, ...extraArgs];
|
||
let stdout = '';
|
||
let stderr = '';
|
||
let exitCode = 0;
|
||
try {
|
||
// Windows/Node 22 under --test-concurrency=4 can starve subprocess slots when
|
||
// sharing a wave with bug-2760-codex-install (8–15s install subtests). 15s covers
|
||
// observed worst case (13.5s) with headroom.
|
||
stdout = execFileSync(process.execPath, args, {
|
||
encoding: 'utf-8',
|
||
stdio: ['pipe', 'pipe', 'pipe'],
|
||
timeout: 15000,
|
||
});
|
||
} catch (err) {
|
||
exitCode = err.status ?? 1;
|
||
stdout = err.stdout?.toString() ?? '';
|
||
stderr = err.stderr?.toString() ?? '';
|
||
}
|
||
return { exitCode, stdout: stdout.trim(), stderr: stderr.trim() };
|
||
}
|
||
|
||
test('returns "200000" (exit 0) when context_window absent from config.json', () => {
|
||
// Fixture A: config with unrelated keys, no context_window
|
||
fs.writeFileSync(
|
||
path.join(planningDir, 'config.json'),
|
||
JSON.stringify({ workflow: { auto_advance: false } })
|
||
);
|
||
|
||
const result = runConfigGet('context_window');
|
||
|
||
assert.strictEqual(result.exitCode, 0, 'should exit 0 (schema default applied)');
|
||
assert.strictEqual(result.stdout, '200000', 'should return schema default of 200000');
|
||
});
|
||
|
||
test('returns configured value when context_window is explicitly set', () => {
|
||
// Fixture B: config has context_window: 1000000
|
||
fs.writeFileSync(
|
||
path.join(planningDir, 'config.json'),
|
||
JSON.stringify({ context_window: 1000000 })
|
||
);
|
||
|
||
const result = runConfigGet('context_window');
|
||
|
||
assert.strictEqual(result.exitCode, 0, 'should exit 0 for found key');
|
||
assert.strictEqual(result.stdout, '1000000', 'should return configured value not schema default');
|
||
});
|
||
|
||
test('--default flag overrides schema default', () => {
|
||
// config has context_window but we pass --default with a different value —
|
||
// when key IS present, real value wins over any default
|
||
fs.writeFileSync(
|
||
path.join(planningDir, 'config.json'),
|
||
JSON.stringify({ workflow: { auto_advance: false } })
|
||
);
|
||
|
||
const result = runConfigGet('context_window', ['--default', '123456']);
|
||
|
||
assert.strictEqual(result.exitCode, 0, 'should exit 0 when --default provided');
|
||
assert.strictEqual(result.stdout, '123456', 'should return the --default value, not schema default');
|
||
});
|
||
|
||
test('errors with reason=CONFIG_KEY_NOT_FOUND (exit 1) for an unknown absent key — no regression', () => {
|
||
// An unrecognised key with no schema default still errors as before.
|
||
// Migrated #2974: assert on the structured reason code from --json-errors,
|
||
// not on substring presence in stderr/stdout text.
|
||
fs.writeFileSync(
|
||
path.join(planningDir, 'config.json'),
|
||
JSON.stringify({ workflow: { auto_advance: false } })
|
||
);
|
||
|
||
const result = runConfigGet('totally_unknown_key_xyz', ['--json-errors']);
|
||
|
||
assert.strictEqual(result.exitCode, 1, 'should exit 1 for unknown absent key');
|
||
let parsed;
|
||
try {
|
||
parsed = JSON.parse(result.stderr);
|
||
} catch (err) {
|
||
assert.fail(`expected JSON-shaped stderr from --json-errors; got: ${JSON.stringify(result.stderr)}`);
|
||
}
|
||
assert.strictEqual(parsed.ok, false);
|
||
assert.strictEqual(parsed.reason, ERROR_REASON.CONFIG_KEY_NOT_FOUND,
|
||
`expected reason=${ERROR_REASON.CONFIG_KEY_NOT_FOUND}, got=${parsed.reason}`);
|
||
});
|
||
|
||
test('--default flag still works for arbitrary absent keys', () => {
|
||
fs.writeFileSync(
|
||
path.join(planningDir, 'config.json'),
|
||
JSON.stringify({})
|
||
);
|
||
|
||
const result = runConfigGet('some.missing.key', ['--default', '200000']);
|
||
|
||
assert.strictEqual(result.exitCode, 0, 'should exit 0 when --default supplied');
|
||
assert.strictEqual(result.stdout, '200000', 'should return the explicit --default value');
|
||
});
|
||
});
|