enh(#2876): retire the dead and pass-through exports from bin/install.js (#3615)

* enh(#2876): retire the dead and pass-through exports from bin/install.js

The installer exported 197 names and had zero production consumers - every
non-test require of it repo-wide sits inside a comment. Its interface was
shaped by test access, not by callers.

Removes 9 dead exports and 61 pass-throughs, repointing their tests onto the
extracted modules' own interfaces. 197 down to 127.

Every count in the issue was wrong: 197 exports not 188, 9 dead not 12, 61
pass-throughs not 49, 44 test files not 42 - and the audit itself then missed
7 more consumer files. restoreUserArtifacts was on the dead list but ceased to
exist in phase 6, and two _GSD_EFFORT_MANIFEST_* names listed as dead are now
genuinely asserted, so acting on that list would have deleted live exports.

7 of the 9 dead names collide with an independent declaration that install.js
delegates TO. Each removal was justified by which declaration a reference
resolves to, never by whether the name appears somewhere.

Coverage parity was the gate rather than test greenness: per-file counts were
captured before any edit and diffed after. 44 of 45 files are byte-identical;
the single delta is one added assertion, not a loss.

The sweep for scattered require sites found two forms static grep misses -
require(VARIABLE) and multi-line require() - plus tests asserting that
install.js re-exports the SAME object, which now assert retirement instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(#2876): close review findings — restore the duplicate-body guard, sweep orphaned code

Both review engines found real defects in the first cut.

The DEFECT.GENERATIVE-FIX single-owner guard from #1511 had been repointed
from a reference-identity check to install.X === undefined. Those are not
equivalent: the guard exists to catch a duplicate function body reintroduced
into install.js, and the replacement passes cleanly if that duplicate is used
internally and never exported. It now walks bin/install.js's real top-level
bindings, so it catches a duplicate under either shape, exported or not -
strictly stronger than the check it replaced. Proved by injecting a duplicate
and watching it go red.

That weakening survived the coverage-parity gate because the assertion count
never moved. The gate compares counts, so an assertion that changes meaning
rather than number is invisible to it.

Removing the exports had orphaned their wrapper bodies: 14 dead wrappers, 9
consts and 9 destructure entries, several pre-existing and found by the same
sweep. Dead code left in the file this phase exists to shrink.

Three more comments claimed re-exports this phase removed, and tests were
reading Cursor and Windsurf hook constants from install.js's local copy while
calling functions from the hooks surface - equal today, with nothing holding
them equal. The local consts now reference the owning module.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore(#2876): backfill changeset pr number

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: sim <sim@local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-08-18 09:23:44 -04:00
committed by GitHub
parent bcefffc132
commit 682eaae3f0
31 changed files with 501 additions and 627 deletions

View File

@@ -37,7 +37,6 @@ const pkg = require('../package.json');
const { PROBE_TIMEOUT_MS } = require('./helpers/timeouts.cjs');
const {
getDirName,
getConfigDirFromHome,
install,
uninstall,
@@ -48,12 +47,14 @@ const {
resolveKiloConfigPath,
configureKiloPermissions,
selectRuntimesFromArgs,
normalizeNodePath,
GSD_CHANGESET_FILES,
GSD_SCRIPTS_LIB_FILES,
installRuntimeArtifacts,
} = require('../bin/install.js');
const { getDirName } = require('../gsd-core/bin/lib/runtime-name-policy.cjs');
const { normalizeNodePath } = require('../gsd-core/bin/lib/runtime-hooks-surface.cjs');
const { installRuntimeArtifacts } = require('../gsd-core/bin/lib/install-engine.cjs');
const { getGlobalConfigDir } = require('../gsd-core/bin/lib/runtime-homes.cjs');
// #2874 AC3 exemplar (see the qwen install/uninstall group below): resolves
// the SAME 'full' profile install(false, <runtime>) resolves by default
@@ -2031,11 +2032,11 @@ const path = require('path');
const isWindows = process.platform === 'win32';
const {
readGsdEffectiveModelOverrides,
generateCodexAgentToml,
convertClaudeToOpencodeFrontmatter,
getCodexSkillAdapterHeader,
} = require('../bin/install.js');
const { readGsdEffectiveModelOverrides } = require('../gsd-core/bin/lib/install-model-override-resolver.cjs');
const { createTempDir, cleanup } = require('./helpers.cjs');
const makeTmp = (prefix) => createTempDir(`gsd-2256-${prefix}-`);
@@ -2203,8 +2204,8 @@ const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const INSTALL = require(path.join(__dirname, '..', 'bin', 'install.js'));
const { normalizeNodePath, resolveNodeRunner, rewriteLegacyManagedNodeHookCommands } = INSTALL;
const HOOKS_SURFACE = require(path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'runtime-hooks-surface.cjs'));
const { normalizeNodePath, resolveNodeRunner, rewriteLegacyManagedNodeHookCommands } = HOOKS_SURFACE;
// ─── normalizeNodePath ────────────────────────────────────────────────────────
@@ -2499,8 +2500,7 @@ const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const INSTALL = require(path.join(__dirname, '..', 'bin', 'install.js'));
const { normalizeNodePath, resolveNodeRunner } = INSTALL;
const { normalizeNodePath, resolveNodeRunner } = require(path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'runtime-hooks-surface.cjs'));
// ─── Synthetic paths used across tests ───────────────────────────────────────
@@ -2709,8 +2709,7 @@ const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const path = require('node:path');
const INSTALL = require(path.join(__dirname, '..', 'bin', 'install.js'));
const { buildHookCommand, resolveNodeRunner } = INSTALL;
const { buildHookCommand, resolveNodeRunner, rewriteLegacyManagedNodeHookCommands } = require(path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'runtime-hooks-surface.cjs'));
/**
* Parse a hook command string into { runner, hookPath } structured
@@ -2876,8 +2875,6 @@ describe('Bug #2979: buildHookCommand for .sh hooks still uses bare "bash" (POSI
// ─── #3002 CR follow-up: legacy-bare-node migration ─────────────────────────
const { rewriteLegacyManagedNodeHookCommands } = INSTALL;
describe('Bug #2979 (#3002 CR): rewriteLegacyManagedNodeHookCommands rewrites bare-node managed hooks on reinstall', () => {
test('exported as a function', () => {
assert.equal(typeof rewriteLegacyManagedNodeHookCommands, 'function');
@@ -3146,7 +3143,7 @@ describe('Bug #2979 (#3002 CR): resolveNodeRunner returns null when execPath una
// ─── #3002 CR follow-up #2: null-command guards in settings.json ──────────
const { validateHookFields } = INSTALL;
const { validateHookFields } = require('../bin/install.js');
describe('Bug #2979 (#3002 CR follow-up): no command:null hook entries survive serialization', () => {
// CR feedback: assert structurally on the resulting settings object, not by
@@ -3369,13 +3366,12 @@ before(() => {
conversion = require('../gsd-core/bin/lib/runtime-artifact-conversion.cjs');
});
describe('bin/install.js compatibility export audit (#1559)', () => {
test('retains audited compatibility relays for shared rewrite helpers', () => {
assert.strictEqual(installer.processAttribution, conversion.processAttribution);
assert.strictEqual(
installer.applyRuntimeContentRewritesForCommandsInPlace,
conversion.applyRuntimeContentRewritesForCommandsInPlace,
);
describe('bin/install.js compatibility export audit (#1559, retired by #2876)', () => {
test('the two previously-audited compatibility relays are retired — test consumers now import runtime-artifact-conversion.cjs directly', () => {
assert.equal(typeof conversion.processAttribution, 'function', 'processAttribution remains available from the conversion module');
assert.equal(installer.processAttribution, undefined, 'processAttribution is no longer re-exported by bin/install.js (#2876)');
assert.equal(typeof conversion.applyRuntimeContentRewritesForCommandsInPlace, 'function', 'applyRuntimeContentRewritesForCommandsInPlace remains available from the conversion module');
assert.equal(installer.applyRuntimeContentRewritesForCommandsInPlace, undefined, 'applyRuntimeContentRewritesForCommandsInPlace is no longer re-exported by bin/install.js (#2876)');
});
test('does not leak unaudited conversion-module helpers through the installer', () => {
@@ -3759,25 +3755,29 @@ describe('#2771: legacy manifest entries for USER_OWNED_ARTIFACTS are normalized
// ─── Test 4: shared constant exists and is used by both call sites ────────────
describe('#2771: USER_OWNED_ARTIFACTS is a single source of truth', () => {
test('install.js exports USER_OWNED_ARTIFACTS containing USER-PROFILE.md', () => {
test('install-engine.cjs exports USER_OWNED_ARTIFACTS containing USER-PROFILE.md; bin/install.js no longer re-exports it (#2876)', () => {
const origMode = process.env.GSD_TEST_MODE;
process.env.GSD_TEST_MODE = '1';
let mod;
let engine;
try {
delete require.cache[require.resolve(INSTALL_SCRIPT)];
mod = require(INSTALL_SCRIPT);
engine = require('../gsd-core/bin/lib/install-engine.cjs');
} finally {
if (origMode === undefined) delete process.env.GSD_TEST_MODE;
else process.env.GSD_TEST_MODE = origMode;
}
assert.strictEqual(mod.USER_OWNED_ARTIFACTS, undefined, 'bin/install.js must no longer export USER_OWNED_ARTIFACTS (#2876)');
assert.ok(
Array.isArray(mod.USER_OWNED_ARTIFACTS) || mod.USER_OWNED_ARTIFACTS instanceof Set,
'install.js must export USER_OWNED_ARTIFACTS as a single source of truth'
Array.isArray(engine.USER_OWNED_ARTIFACTS) || engine.USER_OWNED_ARTIFACTS instanceof Set,
'install-engine.cjs must export USER_OWNED_ARTIFACTS as a single source of truth'
);
const list = Array.isArray(mod.USER_OWNED_ARTIFACTS)
? mod.USER_OWNED_ARTIFACTS
: Array.from(mod.USER_OWNED_ARTIFACTS);
const list = Array.isArray(engine.USER_OWNED_ARTIFACTS)
? engine.USER_OWNED_ARTIFACTS
: Array.from(engine.USER_OWNED_ARTIFACTS);
assert.ok(
list.includes('USER-PROFILE.md'),
'USER_OWNED_ARTIFACTS must include USER-PROFILE.md'
@@ -6001,52 +6001,63 @@ const manifestPath = path.join(
);
const manifest = require(manifestPath);
// Load install.js exported values (executes the module, not text inspection)
// Load install-effort-resolver.cjs's catalog (executes the module, not text
// inspection). #2876 (epic #2866 Phase 7) retired bin/install.js's
// `_GSD_EFFORT_MANIFEST_TIER_DEFAULTS` / `_GSD_EFFORT_MANIFEST_DEFAULT`
// getter re-exports — install-effort-resolver.cjs's `_getGsdEffortCatalog()`
// was always the single source; bin/install.js's getters merely relayed it.
const installPath = path.join(__dirname, '..', 'bin', 'install.js');
const {
_GSD_EFFORT_MANIFEST_TIER_DEFAULTS,
_GSD_EFFORT_MANIFEST_DEFAULT,
} = require(installPath);
const { _getGsdEffortCatalog } = require(
path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'install-effort-resolver.cjs')
);
const _GSD_EFFORT_MANIFEST_TIER_DEFAULTS = _getGsdEffortCatalog().EFFORT_MANIFEST_TIER_DEFAULTS;
const _GSD_EFFORT_MANIFEST_DEFAULT = _getGsdEffortCatalog().EFFORT_MANIFEST_DEFAULT;
test('install.js _GSD_EFFORT_MANIFEST_TIER_DEFAULTS.light matches manifest effort.routing_tier_defaults.light', () => {
test('bin/install.js no longer re-exports _GSD_EFFORT_MANIFEST_TIER_DEFAULTS / _GSD_EFFORT_MANIFEST_DEFAULT (#2876)', () => {
const installExports = require(installPath);
assert.strictEqual(installExports._GSD_EFFORT_MANIFEST_TIER_DEFAULTS, undefined);
assert.strictEqual(installExports._GSD_EFFORT_MANIFEST_DEFAULT, undefined);
});
test('install-effort-resolver.cjs _GSD_EFFORT_MANIFEST_TIER_DEFAULTS.light matches manifest effort.routing_tier_defaults.light', () => {
assert.strictEqual(
_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.light,
manifest.effort.routing_tier_defaults.light,
`install.js tier default for "light" (${_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.light}) differs from manifest (${manifest.effort.routing_tier_defaults.light})`
`install-effort-resolver.cjs tier default for "light" (${_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.light}) differs from manifest (${manifest.effort.routing_tier_defaults.light})`
);
});
test('install.js _GSD_EFFORT_MANIFEST_TIER_DEFAULTS.standard matches manifest effort.routing_tier_defaults.standard', () => {
test('install-effort-resolver.cjs _GSD_EFFORT_MANIFEST_TIER_DEFAULTS.standard matches manifest effort.routing_tier_defaults.standard', () => {
assert.strictEqual(
_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.standard,
manifest.effort.routing_tier_defaults.standard,
`install.js tier default for "standard" (${_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.standard}) differs from manifest (${manifest.effort.routing_tier_defaults.standard})`
`install-effort-resolver.cjs tier default for "standard" (${_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.standard}) differs from manifest (${manifest.effort.routing_tier_defaults.standard})`
);
});
test('install.js _GSD_EFFORT_MANIFEST_TIER_DEFAULTS.heavy matches manifest effort.routing_tier_defaults.heavy', () => {
test('install-effort-resolver.cjs _GSD_EFFORT_MANIFEST_TIER_DEFAULTS.heavy matches manifest effort.routing_tier_defaults.heavy', () => {
assert.strictEqual(
_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.heavy,
manifest.effort.routing_tier_defaults.heavy,
`install.js tier default for "heavy" (${_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.heavy}) differs from manifest (${manifest.effort.routing_tier_defaults.heavy})`
`install-effort-resolver.cjs tier default for "heavy" (${_GSD_EFFORT_MANIFEST_TIER_DEFAULTS.heavy}) differs from manifest (${manifest.effort.routing_tier_defaults.heavy})`
);
});
test('install.js _GSD_EFFORT_MANIFEST_DEFAULT matches manifest effort.default', () => {
test('install-effort-resolver.cjs _GSD_EFFORT_MANIFEST_DEFAULT matches manifest effort.default', () => {
assert.strictEqual(
_GSD_EFFORT_MANIFEST_DEFAULT,
manifest.effort.default,
`install.js effort default (${_GSD_EFFORT_MANIFEST_DEFAULT}) differs from manifest (${manifest.effort.default})`
`install-effort-resolver.cjs effort default (${_GSD_EFFORT_MANIFEST_DEFAULT}) differs from manifest (${manifest.effort.default})`
);
});
test('install.js tier-defaults object has exactly the same keys as manifest effort.routing_tier_defaults', () => {
test('install-effort-resolver.cjs tier-defaults object has exactly the same keys as manifest effort.routing_tier_defaults', () => {
const installKeys = Object.keys(_GSD_EFFORT_MANIFEST_TIER_DEFAULTS).sort();
const manifestKeys = Object.keys(manifest.effort.routing_tier_defaults).sort();
assert.deepStrictEqual(
installKeys,
manifestKeys,
`Key mismatch — install.js: [${installKeys.join(', ')}], manifest: [${manifestKeys.join(', ')}]`
`Key mismatch — install-effort-resolver.cjs: [${installKeys.join(', ')}], manifest: [${manifestKeys.join(', ')}]`
);
});
});