* fix(#505): remove dead SDK-shim verification subsystem from bin/install.js Post-ADR-0174 the @opengsd/gsd-sdk package was retired; sdk/ no longer ships. installSdkIfNeeded had no callers in the live install flow and its entire transitive call graph (classifySdkInstall, buildSdkFailFastReport, renderSdkFailFastReport, buildGsdSdkVersionMismatchReport, readGsdSdkVersion, parseGsdSdkVersion, findGsdSdkOnPath, isGsdSdkOnPath, isLegacyGsdSdkShim, filterNpxFromPath, getUserShellPath, getUserShellWindowsPersistentPath, trySelfLinkGsdSdk, trySelfLinkGsdSdkWindows, buildWindowsShimTriple, formatSdkPathDiagnostic, renderGsdSdkVersionMismatchReport) was dead code. Also removed two now-empty test files (no-unconditional-win32-skip.test.cjs, bug-3020-install-shell-path-probe.test.cjs) that exercised the removed functions, and added a regression guard (bug-505-remove-dead-sdk-verification.test.cjs). detectStaleStandaloneSdk and formatStaleStandaloneSdkWarning are deliberately KEPT — they handle a real leftover-global-SDK condition (#3406). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore: add changeset for #505 dead SDK-shim removal Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(#505): restore buildWindowsShimTriple/formatSdkPathDiagnostic projection surfaces The dead-code removal also deleted buildWindowsShimTriple and formatSdkPathDiagnostic (plus their imports/exports). These have no production caller, but they are the install.js side of a projection-contract drift guard: tests/bug-3441 and tests/bug-3442 assert install.js delegates to shell-command-projection.cjs rather than hand-rolling the projection. Removing them broke those tests (TypeError: ... is not a function) — surfaced by the full/coverage CI matrix, which runs suites the local scoped run skipped. Restore the two thin wrappers, their `*FromProjection` import aliases, and their exports. Update the bug-505 guard test to assert they remain exported as contract surfaces (moved out of the dead-symbol list). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,169 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #3020.
|
||||
*
|
||||
* The installer prints `✓ GSD SDK ready (sdk/dist/cli.js)` whenever
|
||||
* isGsdSdkOnPath() — which reads process.env.PATH from the install
|
||||
* subprocess — finds the shim. That set is not the same as the user's
|
||||
* later interactive shell PATH:
|
||||
*
|
||||
* - Windows cross-shell: gsd-sdk.cmd resolves under PowerShell/cmd
|
||||
* (PATHEXT) but bare `gsd-sdk` does not resolve under Git Bash /
|
||||
* MSYS / WSL bash.
|
||||
* - POSIX ~/.local/bin: install subprocess inherits npm/npx-injected
|
||||
* PATH containing ~/.local/bin; user's login shell may not.
|
||||
* - Node version managers (nvm/fnm/volta) shim PATH per-shell.
|
||||
*
|
||||
* Result: green ✓ at install time, "command not found" at workflow
|
||||
* runtime (#3011 originals + @x0rk + @stefanoginella).
|
||||
*
|
||||
* Fix: introduce two helpers and use them at install time.
|
||||
*
|
||||
* isGsdSdkOnPath(pathString?: string)
|
||||
* - Now accepts an optional explicit PATH string. When omitted,
|
||||
* falls back to process.env.PATH (preserves existing behavior).
|
||||
* - Pure: no spawn, no I/O beyond fs.statSync on candidates.
|
||||
*
|
||||
* getUserShellPath() → string | null
|
||||
* - Probes the user's login shell ($SHELL -lc 'printf %s "$PATH"') on
|
||||
* POSIX so we can predict the runtime shell PATH.
|
||||
* - Returns null on Windows or when the probe fails (caller falls
|
||||
* back to process.env.PATH).
|
||||
*
|
||||
* Tests are typed-IR / structural — no console capture, no source grep.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
const { test, describe } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
|
||||
const INSTALL = require(path.join(__dirname, '..', 'bin', 'install.js'));
|
||||
const { isGsdSdkOnPath, getUserShellPath } = INSTALL;
|
||||
|
||||
describe('bug #3020: isGsdSdkOnPath accepts an explicit PATH string', () => {
|
||||
test('exported as a function', () => {
|
||||
assert.equal(typeof isGsdSdkOnPath, 'function');
|
||||
});
|
||||
|
||||
test('returns true when an executable gsd-sdk exists in the supplied PATH', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3020-'));
|
||||
try {
|
||||
// Create a fake `gsd-sdk` shim with the executable bit set.
|
||||
const shimName = process.platform === 'win32' ? 'gsd-sdk.cmd' : 'gsd-sdk';
|
||||
const shimPath = path.join(tmp, shimName);
|
||||
fs.writeFileSync(shimPath, process.platform === 'win32' ? '@echo off\nexit 0\n' : '#!/bin/sh\nexit 0\n');
|
||||
if (process.platform !== 'win32') fs.chmodSync(shimPath, 0o755);
|
||||
const result = isGsdSdkOnPath(tmp);
|
||||
assert.equal(result, true, `expected true for PATH=${tmp}, got ${result}`);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('returns false when the supplied PATH has no gsd-sdk', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3020-'));
|
||||
try {
|
||||
const result = isGsdSdkOnPath(tmp);
|
||||
assert.equal(result, false);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('zero-arg form preserves existing behavior (reads process.env.PATH)', () => {
|
||||
// Just call it — it shouldn't throw and should return a boolean.
|
||||
const result = isGsdSdkOnPath();
|
||||
assert.equal(typeof result, 'boolean');
|
||||
});
|
||||
|
||||
test('treats an empty PATH string as no segments to scan', () => {
|
||||
const result = isGsdSdkOnPath('');
|
||||
assert.equal(result, false);
|
||||
});
|
||||
|
||||
test('null pathString is type-guarded — falls back to process.env.PATH (#3028 CR)', () => {
|
||||
// Pre-fix: isGsdSdkOnPath(null) threw "Cannot read properties of null
|
||||
// (reading 'split')". Post-fix: typeof check falls back to process.env.PATH.
|
||||
let threw = null;
|
||||
let result;
|
||||
try {
|
||||
result = isGsdSdkOnPath(null);
|
||||
} catch (e) {
|
||||
threw = e;
|
||||
}
|
||||
assert.equal(threw, null, `must not throw on null input, got: ${threw && threw.message}`);
|
||||
assert.equal(typeof result, 'boolean', 'must return a boolean');
|
||||
});
|
||||
|
||||
test('non-string pathString (number, object) falls back to process.env.PATH (#3028 CR)', () => {
|
||||
// Defensive: any non-string argument should fall back, not throw.
|
||||
assert.equal(typeof isGsdSdkOnPath(0), 'boolean');
|
||||
assert.equal(typeof isGsdSdkOnPath({}), 'boolean');
|
||||
assert.equal(typeof isGsdSdkOnPath([]), 'boolean');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bug #3020: getUserShellPath probes the user login shell PATH', () => {
|
||||
test('exported as a function', () => {
|
||||
assert.equal(typeof getUserShellPath, 'function');
|
||||
});
|
||||
|
||||
test('returns a string with at least one segment OR null', () => {
|
||||
const result = getUserShellPath();
|
||||
if (result === null) {
|
||||
// Acceptable on Windows or when probing fails — caller must fall back.
|
||||
return;
|
||||
}
|
||||
assert.equal(typeof result, 'string');
|
||||
// PATH must have segments separated by the platform delimiter.
|
||||
assert.ok(result.length > 0, 'non-null result must be non-empty');
|
||||
});
|
||||
|
||||
test('returns null on Windows (POSIX shell probe is not portable)', () => {
|
||||
if (process.platform !== 'win32') return;
|
||||
const result = getUserShellPath();
|
||||
assert.equal(result, null);
|
||||
});
|
||||
|
||||
test('returns null when SHELL env var is unset', () => {
|
||||
if (process.platform === 'win32') return;
|
||||
const original = process.env.SHELL;
|
||||
delete process.env.SHELL;
|
||||
try {
|
||||
const result = getUserShellPath();
|
||||
assert.equal(result, null, 'must return null when $SHELL is unset (POSIX caller falls back to process.env.PATH)');
|
||||
} finally {
|
||||
if (original !== undefined) process.env.SHELL = original;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('bug #3020: cross-shell PATH mismatch is detectable via the new helpers', () => {
|
||||
test('install-time PATH has shim, user-shell PATH does not → mismatch detected', () => {
|
||||
const installDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3020-install-'));
|
||||
const userDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3020-user-'));
|
||||
try {
|
||||
const shimName = process.platform === 'win32' ? 'gsd-sdk.cmd' : 'gsd-sdk';
|
||||
const shimPath = path.join(installDir, shimName);
|
||||
fs.writeFileSync(shimPath, process.platform === 'win32' ? '@echo off\nexit 0\n' : '#!/bin/sh\nexit 0\n');
|
||||
if (process.platform !== 'win32') fs.chmodSync(shimPath, 0o755);
|
||||
|
||||
const installSees = isGsdSdkOnPath(installDir);
|
||||
const userSees = isGsdSdkOnPath(userDir);
|
||||
|
||||
assert.equal(installSees, true, 'install-time PATH sees the shim');
|
||||
assert.equal(userSees, false, 'user-shell PATH does not see the shim');
|
||||
// The mismatch is what the post-install check must detect to avoid
|
||||
// the false ✓.
|
||||
assert.notEqual(installSees, userSees, 'shim presence differs between install-time PATH and user-shell PATH');
|
||||
} finally {
|
||||
fs.rmSync(installDir, { recursive: true, force: true });
|
||||
fs.rmSync(userDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
86
tests/bug-505-remove-dead-sdk-verification.test.cjs
Normal file
86
tests/bug-505-remove-dead-sdk-verification.test.cjs
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Regression guard for #505: dead SDK-shim verification subsystem removed.
|
||||
*
|
||||
* Post-ADR-0174 the `@opengsd/gsd-sdk` package was retired; `sdk/` no longer
|
||||
* ships. `installSdkIfNeeded` and all functions it transitively called are
|
||||
* dead code with no live callers. This test asserts:
|
||||
*
|
||||
* 1. All removed symbols are NO LONGER exported from bin/install.js.
|
||||
* 2. The two live stale-standalone-SDK helpers (detectStaleStandaloneSdk,
|
||||
* formatStaleStandaloneSdkWarning) are STILL exported as functions — they
|
||||
* handle a real user-facing condition (#3406) and MUST NOT be removed.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const inst = require('../bin/install.js');
|
||||
|
||||
describe('bug #505: dead SDK verification subsystem removed from bin/install.js', () => {
|
||||
// ----------------------------------------------------------------
|
||||
// Dead symbols — must NOT be exported after removal
|
||||
// ----------------------------------------------------------------
|
||||
const deadSymbols = [
|
||||
'installSdkIfNeeded',
|
||||
'classifySdkInstall',
|
||||
'buildSdkFailFastReport',
|
||||
'renderSdkFailFastReport',
|
||||
'buildGsdSdkVersionMismatchReport',
|
||||
'renderGsdSdkVersionMismatchReport',
|
||||
'readGsdSdkVersion',
|
||||
'parseGsdSdkVersion',
|
||||
'findGsdSdkOnPath',
|
||||
'isGsdSdkOnPath',
|
||||
'isLegacyGsdSdkShim',
|
||||
'trySelfLinkGsdSdk',
|
||||
'trySelfLinkGsdSdkWindows',
|
||||
'filterNpxFromPath',
|
||||
'getUserShellPath',
|
||||
'getUserShellWindowsPersistentPath',
|
||||
];
|
||||
|
||||
for (const sym of deadSymbols) {
|
||||
test(`dead symbol '${sym}' is not exported`, () => {
|
||||
assert.equal(
|
||||
typeof inst[sym],
|
||||
'undefined',
|
||||
`'${sym}' should have been removed (post #505 dead-code removal) but is still exported as ${typeof inst[sym]}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Live symbols — MUST still be exported as functions
|
||||
// ----------------------------------------------------------------
|
||||
test('live function detectStaleStandaloneSdk is still exported', () => {
|
||||
assert.equal(
|
||||
typeof inst.detectStaleStandaloneSdk,
|
||||
'function',
|
||||
'detectStaleStandaloneSdk handles real stale-SDK condition (#3406) and must not be removed',
|
||||
);
|
||||
});
|
||||
|
||||
test('live function formatStaleStandaloneSdkWarning is still exported', () => {
|
||||
assert.equal(
|
||||
typeof inst.formatStaleStandaloneSdkWarning,
|
||||
'function',
|
||||
'formatStaleStandaloneSdkWarning handles real stale-SDK condition (#3406) and must not be removed',
|
||||
);
|
||||
});
|
||||
|
||||
// buildWindowsShimTriple / formatSdkPathDiagnostic have no production caller
|
||||
// after this removal, but they are the install.js side of a projection-contract
|
||||
// drift guard (tests/bug-3441, tests/bug-3442) that assert install.js delegates
|
||||
// to shell-command-projection.cjs. They are deliberately kept exported.
|
||||
test('contract surface buildWindowsShimTriple is still exported', () => {
|
||||
assert.equal(typeof inst.buildWindowsShimTriple, 'function');
|
||||
});
|
||||
|
||||
test('contract surface formatSdkPathDiagnostic is still exported', () => {
|
||||
assert.equal(typeof inst.formatSdkPathDiagnostic, 'function');
|
||||
});
|
||||
});
|
||||
@@ -1,70 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
process.env.GSD_TEST_MODE = '1';
|
||||
|
||||
/**
|
||||
* Behavior-based regression guard for #2962-class bugs.
|
||||
*
|
||||
* "Nothing for Windows should be deferred — if it wasn't in, it was missed
|
||||
* not deferred." (maintainer guidance, 2026-05-01.)
|
||||
*
|
||||
* Specifically guards against trySelfLinkGsdSdk silently no-op'ing on
|
||||
* Windows. Rather than regex-scanning bin/install.js source (which would
|
||||
* fail on harmless refactors and conflicts with the repo's no-source-grep
|
||||
* testing standard), this test exercises the function under a simulated
|
||||
* `process.platform === 'win32'` and asserts shim files actually land on
|
||||
* disk — i.e., the Windows branch dispatches, doesn't early-return null.
|
||||
*/
|
||||
|
||||
const { test, describe, before, after } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const cp = require('node:child_process');
|
||||
|
||||
const ROOT = path.join(__dirname, '..');
|
||||
const installModule = require(path.join(ROOT, 'bin', 'install.js'));
|
||||
|
||||
describe('Windows parity guard for trySelfLinkGsdSdk (#2962)', () => {
|
||||
let tmpDir;
|
||||
let origPlatform;
|
||||
let origExecSync;
|
||||
|
||||
before(() => {
|
||||
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-win32-guard-'));
|
||||
origPlatform = process.platform;
|
||||
origExecSync = cp.execSync;
|
||||
// Override process.platform to simulate Windows. process.platform is a
|
||||
// configurable property in Node — Object.defineProperty can swap it.
|
||||
Object.defineProperty(process, 'platform', { value: 'win32', configurable: true });
|
||||
cp.execSync = (cmd) => {
|
||||
if (typeof cmd === 'string' && cmd.trim() === 'npm prefix -g') {
|
||||
return tmpDir + '\n';
|
||||
}
|
||||
throw new Error(`unexpected execSync: ${cmd}`);
|
||||
};
|
||||
});
|
||||
|
||||
after(() => {
|
||||
Object.defineProperty(process, 'platform', { value: origPlatform, configurable: true });
|
||||
cp.execSync = origExecSync;
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('trySelfLinkGsdSdk dispatches to the Windows handler and writes shims (does NOT silently return null)', () => {
|
||||
const shimSrc = path.join(ROOT, 'bin', 'gsd-sdk.js');
|
||||
const result = installModule.trySelfLinkGsdSdk(shimSrc);
|
||||
|
||||
assert.notEqual(
|
||||
result,
|
||||
null,
|
||||
'trySelfLinkGsdSdk must not silently return null on Windows; ' +
|
||||
'a no-op skip is a missed-parity regression (see #2962, #2775).',
|
||||
);
|
||||
assert.ok(
|
||||
fs.existsSync(path.join(tmpDir, 'gsd-sdk.cmd')),
|
||||
'Windows dispatch must materialize gsd-sdk.cmd in the npm global bin',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user