Files
msd-core/tests/bug-3406-stale-sdk-shadow-detect.test.cjs
Tom Boucher 334a64168e chore(npm): rebrand packages to @opengsd scope (#127)
* chore(npm): rebrand packages to @opengsd scope

Rename:
- get-shit-done-redux → @opengsd/get-shit-done-redux
- @gsd-redux/sdk → @opengsd/gsd-sdk

Add publishConfig.access=public for first-time scoped publish.
CLI binary names (get-shit-done-redux, gsd-sdk, gsd-tools) unchanged.

Sweeps install commands, npx invocations, CI publish/version-check
workflows, tests, docs, READMEs (all translations), and the
PACKAGE_NAME constant in check-latest-version.

Bumps qs 6.15.1 → 6.15.2 to clear a moderate advisory surfaced by
the audit-clean test (GHSA-q8mj-m7cp-5q26).

Closes #126

* chore: pin 2.0.0 release + remove canary workflow

- Bump both packages 1.50.0-canary.0 → 2.0.0 for first @opengsd publish
- Remove .github/workflows/canary.yml and canary dist-tag handling in
  release.yml / release-sdk.yml
- Drop canary section from VERSIONING.md

Refs #126

* chore: address review findings + harden tarball-smoke timeout

- .changeset/opengsd-org-rename.md: match project's custom
  parse.cjs frontmatter (type: Changed / pr: 127); the scoped
  @changesets/cli keys were silently rejected.
- CONTEXT.md: drop two canary-stream policy lines and a dangling
  DEFECT.CANARY-VERSION-LEAK.cross-ref now that canary.yml is gone.
- tests/release-tarball-smoke.install.test.cjs: pass
  timeout: 600_000 for npm pack + global install; the 3-minute
  runNpm default was timing out on slower Docker hosts (cartographer).

Refs #126

* fix(sdk): add missing type/runtime devDependencies for build

prepublishOnly invokes tsc which couldn't resolve @types/node,
@types/ws, or synckit. They had been hoisted from root but were
not declared in sdk/'s own package.json — first publish from a
clean SDK tree failed.

Refs #126

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ci): use npm pack stdout instead of glob to find tarball

`npm pack --silent` for a scoped package (@opengsd/get-shit-done-redux)
produces `opengsd-get-shit-done-redux-*.tgz`, not `get-shit-done-redux-*.tgz`.
Capture the filename from stdout instead of a hardcoded glob so the step
works regardless of package name format.

Fixes smoke (ubuntu-latest, 22, false) CI failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* ci: treat workflow-file changes as test-skip eligible

`.github/workflows/install-smoke.yml` (and other workflow files)
were in neither `test.yml` paths nor `test-skip.yml` paths-ignore,
so neither workflow ran on a workflow-only commit — leaving the
required test-skip check perpetually missing.

Refs #126

* chore: reset version to 1.0.0 for first @opengsd publish

Nothing has been published yet under the @opengsd scope, so the
inaugural release uses 1.0.0 rather than 2.0.0. The "major bump"
in the changeset reflects the breaking install-command change for
users migrating from the prior unscoped `get-shit-done-redux`, not
a numeric continuation from a 1.x line under the new identity.

Refs #126

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-22 16:22:41 -04:00

170 lines
7.1 KiB
JavaScript

'use strict';
/**
* Regression tests for #3406 — stale globally-installed `@opengsd/gsd-sdk@0.1.0`
* shadows the `gsd-sdk` shim that `get-shit-done-redux` installs. The standalone
* 0.1.0 binary only knows `run | auto | init` (no `query` subcommand), so
* every workflow that calls `gsd-sdk query <command>` fails until the user
* runs `npm uninstall -g @opengsd/gsd-sdk`.
*
* Maintainer decision (per triage): option 2 — detect-and-warn during
* install. This test pins the pure detection helper so the install-time
* warning fires on the right input and stays silent otherwise.
*
* Test surface is the exported helper `detectStaleStandaloneSdk(runNpmLs)`.
* `runNpmLs` is an injected executor: in production it spawns
* `npm ls -g @opengsd/gsd-sdk --json --depth=0`; in tests we hand it a stub
* that returns canned stdout / throws, so the test never touches the host
* npm state.
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
process.env.GSD_TEST_MODE = '1';
const installer = require('../bin/install.js');
const { detectStaleStandaloneSdk } = installer;
describe('#3406: detectStaleStandaloneSdk', () => {
test('is exported from bin/install.js under GSD_TEST_MODE', () => {
assert.strictEqual(
typeof detectStaleStandaloneSdk,
'function',
'detectStaleStandaloneSdk must be exported for install-time wiring + tests'
);
});
test('returns { stale: false } when npm ls reports the package is not installed', () => {
// `npm ls -g @opengsd/gsd-sdk --json --depth=0` exit code 1 with this
// JSON shape is the standard "not present" signal.
const stub = () => JSON.stringify({
name: 'lib',
dependencies: {},
});
const result = detectStaleStandaloneSdk(stub);
assert.deepStrictEqual(result, { stale: false });
});
test('returns { stale: true, version, path? } when @opengsd/gsd-sdk is present', () => {
const stub = () => JSON.stringify({
name: 'lib',
dependencies: {
'@opengsd/gsd-sdk': {
version: '0.1.0',
resolved: 'file:/Users/REDACTED/.nvm/versions/node/v24.15.0/lib/node_modules/@opengsd/gsd-sdk',
},
},
});
const result = detectStaleStandaloneSdk(stub);
assert.strictEqual(result.stale, true);
assert.strictEqual(result.version, '0.1.0');
});
test('returns { stale: false } when runNpmLs throws (npm missing / EACCES)', () => {
const stub = () => { throw new Error('npm: command not found'); };
const result = detectStaleStandaloneSdk(stub);
assert.deepStrictEqual(result, { stale: false });
});
test('returns { stale: false } when runNpmLs returns malformed JSON', () => {
const stub = () => 'not-json-at-all';
const result = detectStaleStandaloneSdk(stub);
assert.deepStrictEqual(result, { stale: false });
});
test('returns { stale: false } when the JSON has no dependencies field', () => {
const stub = () => JSON.stringify({ name: 'lib' });
const result = detectStaleStandaloneSdk(stub);
assert.deepStrictEqual(result, { stale: false });
});
test('returns { stale: false } when runNpmLs returns null/undefined', () => {
const resultNull = detectStaleStandaloneSdk(() => null);
const resultUndef = detectStaleStandaloneSdk(() => undefined);
assert.deepStrictEqual(resultNull, { stale: false });
assert.deepStrictEqual(resultUndef, { stale: false });
});
test('returns { stale: false } for non-0.1.0 versions (CR #3406)', () => {
// Only 0.1.0 is the known-bad shadow. Any newer or unrelated published
// version is an intentional install (or a future republish) and must
// NOT be flagged. Without this gate, every maintainer with a local-link
// or any future publish would trigger a misleading warning on install.
const stubNewer = () => JSON.stringify({ dependencies: { '@opengsd/gsd-sdk': { version: '1.50.0-canary.0' } } });
const stubFuture = () => JSON.stringify({ dependencies: { '@opengsd/gsd-sdk': { version: '2.0.0' } } });
assert.deepStrictEqual(detectStaleStandaloneSdk(stubNewer), { stale: false });
assert.deepStrictEqual(detectStaleStandaloneSdk(stubFuture), { stale: false });
});
});
describe('#3406: install-time wiring stays silent when no stale package is found', () => {
// We can't easily stub npm inside a spawned install subprocess without
// shelling around it, so the install-side coverage here verifies the
// negative case: when @opengsd/gsd-sdk is NOT installed globally (the npm
// dependency tree on CI is irrelevant — we use a doctored PATH that points
// npm at an empty prefix), the install run prints NO #3406 warning. The
// positive case is exhaustively covered by detectStaleStandaloneSdk above.
const path = require('node:path');
const fs = require('node:fs');
const os = require('node:os');
const { execFileSync } = require('node:child_process');
test('install does not emit the stale-SDK warning on a clean npm prefix', () => {
const installScript = path.resolve(__dirname, '..', 'bin', 'install.js');
const tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3406-home-'));
const tmpPrefix = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-3406-npm-'));
try {
const stdout = execFileSync(
process.execPath,
[installScript, '--claude', '--global', '--yes', '--no-sdk'],
{
encoding: 'utf-8',
stdio: ['ignore', 'pipe', 'pipe'],
env: {
...process.env,
CLAUDE_CONFIG_DIR: tmpHome,
npm_config_prefix: tmpPrefix,
// Detect-and-warn must execute, just find nothing — so do NOT set
// GSD_SKIP_STALE_SDK_CHECK here.
},
timeout: 60_000,
}
);
assert.ok(
!stdout.includes('@opengsd/gsd-sdk'),
'install output must not mention @opengsd/gsd-sdk when the package is absent'
);
assert.ok(
!stdout.includes('#3406'),
'install output must not reference #3406 when no stale shadow is present'
);
} finally {
try { fs.rmSync(tmpHome, { recursive: true, force: true }); } catch { /* ignore */ }
try { fs.rmSync(tmpPrefix, { recursive: true, force: true }); } catch { /* ignore */ }
}
});
});
describe('#3406: formatStaleStandaloneSdkWarning', () => {
const { formatStaleStandaloneSdkWarning } = installer;
test('is exported from bin/install.js under GSD_TEST_MODE', () => {
assert.strictEqual(
typeof formatStaleStandaloneSdkWarning,
'function',
'formatStaleStandaloneSdkWarning must be exported for tests'
);
});
test('message names the stale package, the version, and the uninstall command', () => {
const out = formatStaleStandaloneSdkWarning({ stale: true, version: '0.1.0' });
assert.ok(out.includes('@opengsd/gsd-sdk'), 'must name the shadowing package');
assert.ok(out.includes('0.1.0'), 'must show the stale version');
assert.ok(
out.includes('npm uninstall -g @opengsd/gsd-sdk'),
'must include the remediation command verbatim'
);
assert.ok(out.includes('#3406'), 'must reference the issue for traceability');
});
});