Files
msd-core/tests/bug-2829-local-install-sdk-path.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

143 lines
5.6 KiB
JavaScript

/**
* Regression test for #2829: `command not found: gsd-sdk` with local-mode install.
*
* Repro: a fresh `npx @opengsd/get-shit-done-redux@latest` install with the runtime set
* to local mode left every `gsd-sdk query …` call site unable to resolve the
* binary because the installer's previous behavior was to skip SDK linking
* entirely for local installs (#2678 over-corrected). The published tarball
* actually carries `sdk/dist/cli.js` and `bin/gsd-sdk.js` regardless of mode,
* and the shim resolves the CLI relative to its own __dirname — so the same
* self-link strategy that powers npx-cache global installs (#2775) also works
* for local installs.
*
* Fix: when `installSdkIfNeeded({ isLocal: true })` runs and `sdk/dist/cli.js`
* is present, the installer must NOT silently skip — it must verify
* `gsd-sdk` is on PATH and self-link the shim into a user-writable PATH dir
* if not, so `/gsd-plan` and friends can call `gsd-sdk query …` directly.
*
* Pre-existing #2678 contract preserved: when the dist is missing in local
* mode, the installer warns and returns instead of process.exit(1).
*/
'use strict';
process.env.GSD_TEST_MODE = '1';
const { describe, test, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const { installSdkIfNeeded } = require('../bin/install.js');
const { createTempDir, cleanup, captureConsole } = require('./helpers.cjs');
const isWindows = process.platform === 'win32';
describe('bug #2829: local-mode install must materialize gsd-sdk on PATH',
{ skip: isWindows ? 'POSIX-only: asserts ~/.local/bin shebang shim; Windows uses gsd-sdk.cmd + USERPROFILE + PATHEXT' : false },
() => {
let tmpRoot;
let sdkDir;
let pathDir;
let homeDir;
let savedEnv;
beforeEach(() => {
tmpRoot = createTempDir('gsd-2829-');
sdkDir = path.join(tmpRoot, 'sdk');
fs.mkdirSync(path.join(sdkDir, 'dist'), { recursive: true });
fs.writeFileSync(
path.join(sdkDir, 'dist', 'cli.js'),
'#!/usr/bin/env node\nconsole.log("0.0.0-test");\n',
{ mode: 0o755 },
);
pathDir = path.join(tmpRoot, 'somebin');
fs.mkdirSync(pathDir, { recursive: true });
homeDir = path.join(tmpRoot, 'home');
fs.mkdirSync(homeDir, { recursive: true });
savedEnv = { PATH: process.env.PATH, HOME: process.env.HOME };
process.env.PATH = pathDir;
process.env.HOME = homeDir;
});
afterEach(() => {
if (savedEnv.PATH == null) delete process.env.PATH;
else process.env.PATH = savedEnv.PATH;
if (savedEnv.HOME == null) delete process.env.HOME;
else process.env.HOME = savedEnv.HOME;
cleanup(tmpRoot);
});
test('isLocal=true with sdk/dist/cli.js present self-links gsd-sdk into an on-PATH HOME bin dir', () => {
const localBin = path.join(homeDir, '.local', 'bin');
fs.mkdirSync(localBin, { recursive: true });
process.env.PATH = `${localBin}${path.delimiter}${pathDir}`;
const { stdout, stderr } = captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true });
});
const combined = `${stdout}\n${stderr}`;
// The shim must be materialized so `gsd-sdk query …` resolves.
const linkPath = path.join(localBin, 'gsd-sdk');
assert.ok(
fs.existsSync(linkPath),
`local install must self-link gsd-sdk into ${linkPath}. Output:\n${combined}`,
);
// And the installer must report ready (matches the global-mode UX).
assert.ok(
/GSD SDK ready/.test(combined),
`local install must print "GSD SDK ready" once gsd-sdk is on PATH. Output:\n${combined}`,
);
// It must NOT print the legacy "Skipping SDK check for local install" line —
// that's exactly the regression #2829 reports.
assert.ok(
!/Skipping SDK check for local install/.test(combined),
`local install must NOT silently skip when the dist is present (#2829). Output:\n${combined}`,
);
});
test('isLocal=true preserves #2678 contract when sdk/dist/cli.js is missing — warn, do not exit', () => {
// Wipe the staged dist to simulate a missing-SDK shape.
fs.rmSync(path.join(sdkDir, 'dist'), { recursive: true, force: true });
let exitCalled = false;
const origExit = process.exit;
process.exit = (code) => {
exitCalled = true;
throw new Error(`process.exit(${code}) — local install must not exit on missing SDK (#2678)`);
};
try {
const { stderr } = captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true });
});
assert.strictEqual(exitCalled, false, 'must not call process.exit in local mode');
assert.ok(
/Skipping SDK check for local install/.test(stderr),
`installer must surface a local-install warning when dist is missing. stderr:\n${stderr}`,
);
} finally {
process.exit = origExit;
}
});
test('isLocal=true with dist present and no on-PATH HOME bin still warns rather than lying about readiness', () => {
// PATH stays as a single non-HOME dir; any HOME bin candidate remains off-PATH.
// Mirrors the #2775 invariant: do not print "ready" when the post-link
// probe still cannot find gsd-sdk on PATH.
const { stdout, stderr } = captureConsole(() => {
installSdkIfNeeded({ sdkDir, isLocal: true });
});
const combined = `${stdout}\n${stderr}`;
assert.ok(
!/GSD SDK ready/.test(combined),
`installer must not falsely claim ready when gsd-sdk is not callable. Output:\n${combined}`,
);
assert.ok(
/not on (your )?PATH/i.test(combined),
`installer must surface a PATH warning. Output:\n${combined}`,
);
});
});