Phase 2 of the CJS↔SDK hard-seam migration (parent #3524). Eliminates the structural drift surface that produced bug class After this phase, neither bin/lib/ nor sdk/src/ defines CONFIG_DEFAULTS, VALID_CONFIG_KEYS, DYNAMIC_KEY_PATTERNS, or the four legacy-key normalizations inline. All come from one canonical source: the Configuration Module (sdk/src/configuration/index.ts) + two JSON manifests (sdk/shared/config-{defaults,schema}.manifest.json). The CJS mirror is generator-emitted (get-shit-done/bin/lib/configuration.generated.cjs) with a CI freshness check (sdk/scripts/check-configuration-fresh.mjs). - sdk/shared/config-defaults.manifest.json — canonical nested defaults, union of CJS + SDK keys (includes security_*, post_planning_gaps, agent_skills, mode, every git/workflow/hooks sub-section). - sdk/shared/config-schema.manifest.json — VALID_CONFIG_KEYS array, RUNTIME_STATE_KEYS array, DYNAMIC_KEY_PATTERNS array with source strings (regex reconstructed at runtime). - sdk/src/configuration/index.ts — source of truth. Exports loadConfig (pure read), normalizeLegacyKeys (pure, idempotent, returns Normalization[]), mergeDefaults (deep-merge), migrateOnDisk (explicit opt-in disk writeback), plus CONFIG_DEFAULTS, VALID_CONFIG_KEYS, RUNTIME_STATE_KEYS, DYNAMIC_KEY_PATTERNS. - sdk/src/configuration/index.test.ts — 29 vitest pinning tests. - sdk/scripts/gen-configuration.mjs — generator (Function.prototype.toString() inspection of compiled SDK dist, plus brace-balanced text scan for internal helpers, matching the Phase 1 pattern). - sdk/scripts/check-configuration-fresh.mjs — CI freshness gate. - tests/configuration-generator.test.cjs — 27 parity assertions (CJS-generated == SDK source). - tests/configuration-migrate-config.test.cjs — 3 cases for the new gsd-tools migrate-config subcommand. - bin/lib/core.cjs: CONFIG_DEFAULTS literal now sources values from CANONICAL_CONFIG_DEFAULTS (the manifest), with a thin flat projection at the load boundary to preserve the existing flat-shape return contract for the ~21 CJS test files and 100+ consumers. All four legacy-key migration blocks (branching_strategy, sub_repos, multiRepo, depth — historically lines 351-358, 388-397, 401-408, 416-423) collapse to a single normalizeLegacyKeys call in each code path. The inline platformWriteSync writeback stays for now to preserve sync loadConfig semantics; the new async migrateOnDisk is reachable via gsd-tools migrate-config. - bin/lib/config-schema.cjs: 135 → 31 lines. Re-exports from the generated Module. - bin/lib/config.cjs: adds cmdMigrateConfig handler (calls migrateOnDisk on the explicit user-driven path). - bin/gsd-tools.cjs: wires migrate-config into command dispatch. - sdk/src/config.ts: re-exports CONFIG_DEFAULTS and mergeDefaults from the Module. loadConfig now calls normalizeLegacyKeys before mergeDefaults (replaces the inline branching_strategy graft). - sdk/src/query/config-schema.ts: 160 → 36 lines. Re-exports from the Module. - tests/config-schema-sdk-parity.test.cjs: refactored from "CJS Set equals SDK Set" (trivially true post-migration) to "both sides source from the manifest" — structural plus runtime invariant. - Four other tests that text-grepped source files for valid keys (plan-review-convergence, bug-3212, bug-2492, feat-3210) are updated to use runtime VALID_CONFIG_KEYS.has() or manifest JSON lookups. - CONTEXT.md: new Configuration Module entry with full Interface contract. - Root package.json: check:configuration-fresh proxy script. - sdk/package.json: gen:configuration + check:configuration-fresh. - .githooks/pre-commit: configuration drift block. - .github/workflows/test.yml: configuration drift step after the alias drift check. - 9201 CJS tests pass (baseline pre-cycle: 9195; +6 net new tests across migrate-config + parity refactor) - 1872 SDK vitest tests pass - 29 Configuration Module vitest fixtures - 27 CJS/SDK parity fixtures - Net diff: +388 / −519 = 131-line reduction across the seven cycles, despite adding the new Module, manifests, generator, freshness check, and two new test files. 1. SDK CONFIG_DEFAULTS now includes manifest-canonical keys (resolve_model_ids: false, context_window: 200000, phase_naming, claude_md_path, git.create_tag, workflow.security_*, workflow.code_review_*, planning.*, hooks.workflow_guard, ship.*). Consumers accessing via [key: string]: unknown index get the manifest default instead of undefined. 2. SDK mergeDefaults is now proper recursive deep-merge instead of spread-per-section. Overlay { workflow: { research: false } } now preserves sibling workflow keys; previously it replaced the entire workflow section with only research + the section's defaults. Semantically identical for the common case; strictly better for partial nested overrides. 3. New gsd-tools migrate-config CLI subcommand for the explicit, opt-in on-disk migration path. Closes #3536.
141 lines
5.8 KiB
JavaScript
141 lines
5.8 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Manifest-as-source-of-truth guard (Phase 2, Cycle 5, #3536).
|
|
*
|
|
* Prior to Cycle 5, the CJS and SDK schema files each had independent inline
|
|
* literals. This test existed to prevent drift between them. After Cycle 5,
|
|
* BOTH sides derive their data from sdk/shared/config-schema.manifest.json,
|
|
* so there is nothing to drift — but the guard still serves a purpose:
|
|
*
|
|
* 1. Confirm that VALID_CONFIG_KEYS loaded at runtime from config-schema.cjs
|
|
* exactly matches the manifest's validKeys array.
|
|
* 2. Confirm that VALID_CONFIG_KEYS exported from sdk/src/query/config-schema.ts
|
|
* (via sdk/dist/) equals the same manifest.
|
|
* 3. Confirm that DYNAMIC_KEY_PATTERNS from config-schema.cjs have .source
|
|
* fields matching the manifest's dynamicKeyPatterns.
|
|
* 4. Confirm RUNTIME_STATE_KEYS from config-schema.cjs matches the manifest.
|
|
*
|
|
* This ensures neither side has accidentally disconnected from the manifest
|
|
* (e.g. reverted to inline literals or switched to a different data source).
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const ROOT = path.resolve(__dirname, '..');
|
|
const MANIFEST_PATH = path.join(ROOT, 'sdk', 'shared', 'config-schema.manifest.json');
|
|
|
|
const manifest = JSON.parse(fs.readFileSync(MANIFEST_PATH, 'utf8'));
|
|
const manifestValidKeys = new Set(manifest.validKeys);
|
|
const manifestRuntimeKeys = new Set(manifest.runtimeStateKeys);
|
|
const manifestPatternSources = manifest.dynamicKeyPatterns.map((p) => p.source);
|
|
|
|
const {
|
|
VALID_CONFIG_KEYS: CJS_KEYS,
|
|
RUNTIME_STATE_KEYS: CJS_RUNTIME_KEYS,
|
|
DYNAMIC_KEY_PATTERNS: CJS_PATTERNS,
|
|
} = require('../get-shit-done/bin/lib/config-schema.cjs');
|
|
|
|
// ─── CJS side: verify manifest-sourced values ─────────────────────────────
|
|
|
|
test('CJS VALID_CONFIG_KEYS matches manifest validKeys exactly', () => {
|
|
const missingInCjs = [...manifestValidKeys].filter((k) => !CJS_KEYS.has(k));
|
|
const extraInCjs = [...CJS_KEYS].filter((k) => !manifestValidKeys.has(k));
|
|
assert.deepStrictEqual(
|
|
missingInCjs,
|
|
[],
|
|
'Manifest keys missing from CJS VALID_CONFIG_KEYS:\n' +
|
|
missingInCjs.map((k) => ' ' + k).join('\n'),
|
|
);
|
|
assert.deepStrictEqual(
|
|
extraInCjs,
|
|
[],
|
|
'CJS VALID_CONFIG_KEYS has keys not in manifest:\n' +
|
|
extraInCjs.map((k) => ' ' + k).join('\n'),
|
|
);
|
|
});
|
|
|
|
test('CJS RUNTIME_STATE_KEYS matches manifest runtimeStateKeys exactly', () => {
|
|
const missingInCjs = [...manifestRuntimeKeys].filter((k) => !CJS_RUNTIME_KEYS.has(k));
|
|
const extraInCjs = [...CJS_RUNTIME_KEYS].filter((k) => !manifestRuntimeKeys.has(k));
|
|
assert.deepStrictEqual(missingInCjs, [], 'Manifest runtime keys missing from CJS RUNTIME_STATE_KEYS');
|
|
assert.deepStrictEqual(extraInCjs, [], 'CJS RUNTIME_STATE_KEYS has keys not in manifest');
|
|
});
|
|
|
|
test('CJS DYNAMIC_KEY_PATTERNS .source fields match manifest dynamicKeyPatterns', () => {
|
|
assert.strictEqual(
|
|
CJS_PATTERNS.length,
|
|
manifestPatternSources.length,
|
|
`CJS has ${CJS_PATTERNS.length} patterns but manifest has ${manifestPatternSources.length}`,
|
|
);
|
|
for (let i = 0; i < manifestPatternSources.length; i++) {
|
|
const expected = manifestPatternSources[i];
|
|
const actual = CJS_PATTERNS[i].source;
|
|
assert.strictEqual(
|
|
actual,
|
|
expected,
|
|
`CJS pattern[${i}].source mismatch: expected "${expected}", got "${actual}"`,
|
|
);
|
|
}
|
|
});
|
|
|
|
// ─── SDK side: verify config-schema.ts re-exports from configuration module ─
|
|
|
|
test('SDK config-schema.ts re-exports from configuration module (not inline literals)', () => {
|
|
const SDK_SCHEMA_PATH = path.join(ROOT, 'sdk', 'src', 'query', 'config-schema.ts');
|
|
const src = fs.readFileSync(SDK_SCHEMA_PATH, 'utf8');
|
|
|
|
// After Cycle 5, the file must NOT contain inline key literals.
|
|
// It should import/re-export from '../configuration/index.js'.
|
|
assert.ok(
|
|
src.includes("from '../configuration/index.js'"),
|
|
'sdk/src/query/config-schema.ts must re-export from ../configuration/index.js (not inline literals)',
|
|
);
|
|
|
|
// Must NOT contain a standalone new Set([...]) block with key literals.
|
|
// A minimal check: the file should not define VALID_CONFIG_KEYS as a Set literal.
|
|
assert.ok(
|
|
!src.includes("new Set([\n 'mode'") && !src.includes("new Set(['mode'"),
|
|
'sdk/src/query/config-schema.ts must not contain an inline VALID_CONFIG_KEYS Set literal',
|
|
);
|
|
});
|
|
|
|
// ─── Cross-check: CJS equals SDK via manifest ─────────────────────────────
|
|
|
|
test('#2653 — CJS and SDK both source from the same manifest (set equality via manifest)', () => {
|
|
// Since both sides derive from sdk/shared/config-schema.manifest.json,
|
|
// the CJS runtime set must equal the manifest set (verified above).
|
|
// This test is the explicit statement of the invariant for audit purposes.
|
|
const cjsKeysSorted = [...CJS_KEYS].sort();
|
|
const manifestKeysSorted = [...manifestValidKeys].sort();
|
|
assert.deepStrictEqual(
|
|
cjsKeysSorted,
|
|
manifestKeysSorted,
|
|
'CJS VALID_CONFIG_KEYS must equal manifest validKeys — both sides source from the manifest',
|
|
);
|
|
});
|
|
|
|
test('#2653 — CJS DYNAMIC_KEY_PATTERNS test functions work correctly', () => {
|
|
// Verify that each pattern's test() function (reconstructed from manifest source)
|
|
// correctly accepts sample keys and rejects non-matching ones.
|
|
const samples = [
|
|
['agent_skills.gsd-planner', 0],
|
|
['review.models.claude', 1],
|
|
['features.some_feature', 2],
|
|
['claude_md_assembly.blocks.intro', 3],
|
|
['model_profile_overrides.codex.opus', 4],
|
|
['models.planning', 5],
|
|
['dynamic_routing.enabled', 6],
|
|
['model_overrides.my-agent', 7],
|
|
];
|
|
for (const [key, idx] of samples) {
|
|
assert.ok(
|
|
CJS_PATTERNS[idx].test(key),
|
|
`CJS pattern[${idx}] must accept "${key}"`,
|
|
);
|
|
}
|
|
});
|