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

@@ -38,13 +38,19 @@ try {
else process.env.GSD_TEST_MODE = savedTestMode;
}
const { install, mergeClaudePermissions, GSD_CLAUDE_ALLOW_PERMISSIONS, GSD_CLAUDE_LEGACY_ALLOW_PERMISSIONS, GSD_CLAUDE_DENY_PERMISSIONS, rewriteLegacyManagedNodeHookCommands, resolveNodeRunner, copyWithPathReplacement } = installExports || {};
const { install, mergeClaudePermissions, GSD_CLAUDE_ALLOW_PERMISSIONS, GSD_CLAUDE_LEGACY_ALLOW_PERMISSIONS, GSD_CLAUDE_DENY_PERMISSIONS, copyWithPathReplacement } = installExports || {};
const {
installRuntimeArtifacts,
uninstallRuntimeArtifacts,
} = require('../gsd-core/bin/lib/install-engine.cjs');
const {
rewriteLegacyManagedNodeHookCommands,
resolveNodeRunner,
reconcileManagedShellHookCommands,
} = require('../gsd-core/bin/lib/runtime-hooks-surface.cjs');
const INSTALL_SCRIPT = path.join(__dirname, '..', 'bin', 'install.js');
// #3145: class-norm timeout, not a per-suite value — see helpers/timeouts.cjs.
const { INSTALL_TIMEOUT_MS } = require('./helpers/timeouts.cjs');
@@ -120,7 +126,7 @@ describe('Defect #1 regression (#3664 reversed by #947): bare-stem dirs removed,
t.after(() => cleanup(configDir));
assert.strictEqual(typeof installRuntimeArtifacts, 'function',
'installRuntimeArtifacts must be exported from bin/install.js');
'installRuntimeArtifacts must be exported from install-engine.cjs');
// Pre-create #3664-era bare-stem Hermes layout (no gsd- prefix, now stale).
// Use real GSD command stems (help, quick) that readGsdCommandNames() knows about.
@@ -307,7 +313,7 @@ describe('U1 (#2973): uninstallRuntimeArtifacts qwen migrates dev-preferences
t.after(() => cleanup(configDir));
assert.strictEqual(typeof uninstallRuntimeArtifacts, 'function',
'uninstallRuntimeArtifacts must be exported from bin/install.js');
'uninstallRuntimeArtifacts must be exported from install-engine.cjs');
const legacyDir = path.join(configDir, 'commands', 'gsd');
fs.mkdirSync(legacyDir, { recursive: true });
@@ -925,7 +931,7 @@ describe('#976 regression: installer does not duplicate managed hooks when regis
test('rewriteLegacyManagedNodeHookCommands leaves args-form launcher entries unchanged', () => {
assert.strictEqual(typeof rewriteLegacyManagedNodeHookCommands, 'function',
'rewriteLegacyManagedNodeHookCommands must be exported from bin/install.js');
'rewriteLegacyManagedNodeHookCommands must be exported from runtime-hooks-surface.cjs');
const launcherCommand = '/usr/local/bin/node-launcher';
const hookPath = '/Users/user/.claude/hooks/gsd-check-update.js';
@@ -1343,27 +1349,15 @@ describe('#1924: profile-user.md backup path must be outside gsd-core/', () => {
// guarantee than the retired helper ever gave, and one a plain in-process
// round-trip would not prove.
describe('#1924: user artifacts survive a wipe via the durable staging path (install.js exports)', () => {
test('install.js exports the staging primitives, and content staged through them survives a destDir wipe + crash', (t) => {
// Set GSD_TEST_MODE so require() reaches the module.exports block
const origMode = process.env.GSD_TEST_MODE;
process.env.GSD_TEST_MODE = '1';
let mod;
try {
mod = require(INSTALL_SCRIPT);
} finally {
if (origMode === undefined) {
delete process.env.GSD_TEST_MODE;
} else {
process.env.GSD_TEST_MODE = origMode;
}
}
describe('#1924: user artifacts survive a wipe via the durable staging path (user-artifact-staging.cjs exports)', () => {
test('user-artifact-staging.cjs exports the staging primitives, and content staged through them survives a destDir wipe + crash', (t) => {
const mod = require('../gsd-core/bin/lib/user-artifact-staging.cjs');
for (const name of ['stageUserArtifacts', 'restoreStagedUserArtifacts', 'discardStagedUserArtifacts', 'recoverOrphanedUserArtifacts']) {
assert.strictEqual(
typeof mod[name],
'function',
`install.js must export ${name} — the mechanism that now makes the #1924 durability property testable`,
`user-artifact-staging.cjs must export ${name} — the mechanism that now makes the #1924 durability property testable`,
);
}
@@ -1519,8 +1513,6 @@ describe('#3333 regression: copyWithPathReplacement tolerates a source file vani
// user-authored hooks are untouched.
describe('#3329 regression: stale managed .sh hook commands are reconciled on install/update', () => {
const { reconcileManagedShellHookCommands } = installExports || {};
const GLOBAL_EXPECTED = {
'gsd-validate-commit.sh': '"C:/Users/u/.claude/hooks/gsd-validate-commit.sh"',
'gsd-graphify-update.sh': '"C:/Users/u/.claude/hooks/gsd-graphify-update.sh"',
@@ -1555,9 +1547,9 @@ describe('#3329 regression: stale managed .sh hook commands are reconciled on in
return out;
}
test('reconcileManagedShellHookCommands is exported from bin/install.js', () => {
test('reconcileManagedShellHookCommands is exported from runtime-hooks-surface.cjs', () => {
assert.strictEqual(typeof reconcileManagedShellHookCommands, 'function',
'reconcileManagedShellHookCommands must be exported from bin/install.js (#3329)');
'reconcileManagedShellHookCommands must be exported from runtime-hooks-surface.cjs (#3329)');
});
test('win32+claude: bare `bash`-prefixed global entries are rewritten to the bare script path', () => {